AI:AIInfo

From OpenTTD
(Difference between revisions)
Jump to: navigation, search
((ab)use <code> tag for inline code fragments, some formatting)
Line 1: Line 1:
{{NoAI}}
+
#REDIRECT [[AI:Development milestones#20_May_2008_-_main.nut_is_split_in_two]]
 
+
As of 2008-05-20 (r13194), a new method of registering your AI is in place. This method solves many of the old problems. Like if you have a compile-problem now in your <code>main.nut</code>, at start-up this no longer gives an error. The error shows up when the AI wants to start, and this way we can redirect it to the AI Debug window. This solves the problem where the user had no idea why the AI didn't show up (as many (Windows) users never look at the console). The only thing important now, is that at start-up your <code>info.nut</code> is correct. Which should not be too difficult for most people.
+
 
+
===Upgrading from the old system===
+
 
+
Basically, what you should do, is move a small part of your <code>main.nut</code> to <code>info.nut</code>. Example:
+
 
+
class FWrightAI extends '''AIFactory''' {
+
function GetAuthor()      { return "OpenTTD Dev Team"; }
+
function GetName()        { return "WrightAI"; }
+
function GetDescription() { return "A simple AI that tries to beat you with only aircrafts"; }
+
function GetVersion()    { return 1.1; }
+
function GetDate()        { return "2008-02-24"; }
+
function CreateInstance() { return "WrightAI"; }
+
}
+
+
/* Tell the core we are an AI */
+
'''iFWrightAI <- FWrightAI();'''
+
 
+
Should be removed and <code>info.nut</code> should get:
+
 
+
class WrightAI extends '''AIInfo''' {
+
function GetAuthor()      { return "OpenTTD Dev Team"; }
+
function GetName()        { return "WrightAI"; }
+
function GetDescription() { return "A simple AI that tries to beat you with only aircrafts"; }
+
function GetVersion()    { return 1.1; }
+
function GetDate()        { return "2008-02-24"; }
+
function CreateInstance() { return "WrightAI"; }
+
}
+
+
'''RegisterAI(WrightAI());'''
+
 
+
Things to remember:
+
* the <code><-</code> line becomes <code>RegisterAI</code>
+
* <code>AIFactory</code> becomes <code>AIInfo</code>.
+
 
+
 
+
===New User===
+
 
+
Create an <code>info.nut</code> and give it this content:
+
 
+
class WrightAI extends AIInfo {
+
function GetAuthor()      { return "OpenTTD Dev Team"; }
+
function GetName()        { return "WrightAI"; }
+
function GetDescription() { return "A simple AI that tries to beat you with only aircrafts"; }
+
function GetVersion()    { return 1.1; }
+
function GetDate()        { return "2008-02-24"; }
+
function CreateInstance() { return "WrightAI"; }
+
}
+
+
RegisterAI(WrightAI());
+
 
+
Where of course you should change the names how ever you like to call everything. Just don't forget the <code>RegisterAI()</code>, and don't forget to extend <code>AIInfo</code>. If something goes wrong, check if you did: <code>RegisterAI(WrightAI())</code>. Mind the <code>()</code> after <code>WrightAI</code>!
+

Revision as of 12:40, 12 June 2008

  1. REDIRECT AI:Development milestones#20_May_2008_-_main.nut_is_split_in_two
Personal tools