author | truebrain |
Thu, 12 Jun 2008 19:47:02 +0000 | |
branch | noai |
changeset 10942 | cd3f2d07199f |
parent 10889 | ecb77cfc4a10 |
permissions | -rw-r--r-- |
10649
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
1 |
/* $Id$ */ |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
2 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
3 |
/** @file ai_info.cpp Implementation of AIFileInfo */ |
10649
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
4 |
|
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
5 |
#include "../stdafx.h" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
6 |
#include "../core/alloc_func.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
7 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
8 |
#include <squirrel.h> |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
9 |
#include "../squirrel.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
10 |
#include "../squirrel_helper.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
11 |
#include "../squirrel_class.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
12 |
#include "../squirrel_std.hpp" |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
13 |
#include "ai.h" |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
14 |
#include "ai_info.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
15 |
#include "ai_squirrel.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
16 |
#include "api/ai_controller.hpp" |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
17 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
18 |
AIFileInfo::~AIFileInfo() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
19 |
{ |
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
20 |
this->engine->ReleaseObject(this->SQ_instance); |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
21 |
free((void *)this->author); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
22 |
free((void *)this->name); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
23 |
free((void *)this->description); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
24 |
free((void *)this->date); |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
25 |
free((void *)this->instance_name); |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
26 |
free(this->script_name); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
27 |
free(this->dir_name); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
28 |
free(this->SQ_instance); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
29 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
30 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
31 |
const char *AIFileInfo::GetAuthor() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
32 |
{ |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
33 |
if (this->author == NULL) this->author = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetAuthor"); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
34 |
return this->author; |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
35 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
36 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
37 |
const char *AIFileInfo::GetName() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
38 |
{ |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
39 |
if (this->name == NULL) this->name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetName"); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
40 |
return this->name; |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
41 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
42 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
43 |
const char *AIFileInfo::GetDescription() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
44 |
{ |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
45 |
if (this->description == NULL) this->description = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetDescription"); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
46 |
return this->description; |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
47 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
48 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
49 |
int AIFileInfo::GetVersion() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
50 |
{ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
51 |
return this->engine->CallIntegerMethod(*this->SQ_instance, "GetVersion"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
52 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
53 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
54 |
const char *AIFileInfo::GetDate() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
55 |
{ |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
56 |
if (this->date == NULL) this->date = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetDate"); |
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
57 |
return this->date; |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
58 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
59 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
60 |
const char *AIFileInfo::GetInstanceName() |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
61 |
{ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
62 |
if (this->instance_name == NULL) this->instance_name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "CreateInstance"); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
63 |
return this->instance_name; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
64 |
} |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
65 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
66 |
bool AIFileInfo::AllowStartup() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
67 |
{ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
68 |
return true; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
69 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
70 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
71 |
AIController *AIFileInfo::CreateInstance() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
72 |
{ |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
73 |
AIController *ai_controller = new AIController(this->script_name, this->GetInstanceName()); |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
74 |
return ai_controller; |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
75 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
76 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
77 |
const char *AIFileInfo::GetDirName() |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
78 |
{ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
79 |
return this->dir_name; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
80 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
81 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
82 |
const char *AIFileInfo::GetScriptName() |
10649
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
83 |
{ |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
84 |
return this->script_name; |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
85 |
} |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
10643
diff
changeset
|
86 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
87 |
void AIFileInfo::CheckMethods(SQInteger *res, const char *name) |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
88 |
{ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
89 |
if (!this->engine->MethodExists(*this->SQ_instance, name)) { |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
90 |
char error[1024]; |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
91 |
snprintf(error, sizeof(error), "your AIFileInfo doesn't have the method '%s'", name); |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
92 |
this->engine->ThrowError(error); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
93 |
*res = SQ_ERROR; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
94 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
95 |
} |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
96 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
97 |
/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info) |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
98 |
{ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
99 |
SQInteger res = 0; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
100 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
101 |
/* Set some basic info from the parent */ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
102 |
info->SQ_instance = MallocT<SQObject>(sizeof(SQObject)); |
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
103 |
Squirrel::GetInstance(vm, info->SQ_instance, 2); |
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
104 |
/* Make sure the instance stays alive over time */ |
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
105 |
sq_addref(vm, info->SQ_instance); |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
106 |
info->base = ((AISquirrel *)Squirrel::GetGlobalPointer(vm)); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
107 |
info->engine = info->base->GetEngine(); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
108 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
109 |
/* Check if all needed fields are there */ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
110 |
info->CheckMethods(&res, "GetAuthor"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
111 |
info->CheckMethods(&res, "GetName"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
112 |
info->CheckMethods(&res, "GetDescription"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
113 |
info->CheckMethods(&res, "GetVersion"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
114 |
info->CheckMethods(&res, "GetDate"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
115 |
info->CheckMethods(&res, "CreateInstance"); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
116 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
117 |
/* Abort if one method was missing */ |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
118 |
if (res != 0) return res; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
119 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
120 |
info->script_name = strdup(info->base->GetCurrentScript()); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
121 |
info->dir_name = strdup(info->base->GetCurrentDirName()); |
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
122 |
|
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
123 |
return 0; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
124 |
} |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
125 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
126 |
/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm) |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
127 |
{ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
128 |
/* Create a new AIFileInfo */ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
129 |
AIInfo *info = new AIInfo(); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
130 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
131 |
SQInteger res = AIFileInfo::Constructor(vm, info); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
132 |
if (res != 0) return res; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
133 |
|
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
134 |
/* Register the AI to the base system */ |
10643
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
135 |
info->base->RegisterAI(info); |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
136 |
|
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
137 |
return 0; |
970417eef395
(svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents:
diff
changeset
|
138 |
} |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
139 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
140 |
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm) |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
141 |
{ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
142 |
/* Create a new AIFileInfo */ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
143 |
AILibrary *library = new AILibrary(); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
144 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
145 |
SQInteger res = AIFileInfo::Constructor(vm, library); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
146 |
if (res != 0) return res; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
147 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
148 |
/* Register the Library to the base system */ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
149 |
library->base->RegisterLibrary(library); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
150 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
151 |
return 0; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
152 |
} |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
153 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
154 |
/* static */ SQInteger AILibrary::Import(HSQUIRRELVM vm) |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
155 |
{ |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
156 |
SQConvert::SQAutoFreePointers ptr; |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
157 |
const char *library = GetParam(SQConvert::ForceType<const char *>(), vm, 2, &ptr); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
158 |
const char *class_name = GetParam(SQConvert::ForceType<const char *>(), vm, 3, &ptr); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
159 |
int version = GetParam(SQConvert::ForceType<int>(), vm, 4, &ptr); |
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
160 |
|
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
161 |
if (!AI_ImportLibrary(library, class_name, version, vm)) return -1; |
10942
cd3f2d07199f
(svn r13496) [NoAI] -Fix: if a library depends on an other library, the import became globally known, which defeats the idea of imports. They are now restricted to their scope, and 'import' returns the class of import (if any)
truebrain
parents:
10889
diff
changeset
|
162 |
return 1; |
10889
ecb77cfc4a10
(svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents:
10873
diff
changeset
|
163 |
} |