AI:AIInfo

From OpenTTD
(Difference between revisions)
Jump to: navigation, search
(+categories)
Line 49: Line 49:
  
 
Where of course you should change the names how ever you like to call everything. Just don't forget the RegisterAI(), and don't forget to extend AIInfo. If something goes wrong, check if you did: RegisterAI(WrightAI()). Mind the () after WrightAI!
 
Where of course you should change the names how ever you like to call everything. Just don't forget the RegisterAI(), and don't forget to extend AIInfo. If something goes wrong, check if you did: RegisterAI(WrightAI()). Mind the () after WrightAI!
 +
 +
[[Category:Development]]
 +
[[Category:NoAI]]

Revision as of 18:11, 20 May 2008

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 main.nut, 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 info.nut 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 main.nut to info.nut. 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 info.nut 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 <- line becomes RegisterAI. AIFactory becomes AIInfo.


New User

Create an info.nut 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 RegisterAI(), and don't forget to extend AIInfo. If something goes wrong, check if you did: RegisterAI(WrightAI()). Mind the () after WrightAI!

Personal tools