Mercurial > hg > openttd
annotate src/ai/ai_scanner.cpp @ 14396:4de60292e2a6 draft
(svn r18953) -Feature: [NoAI] allow editing AI settings while an AI is running
Only settings with the AICONFIG_INGAME flag can be editted in this way
author | yexo <yexo@openttd.org> |
---|---|
date | Fri, 29 Jan 2010 21:38:55 +0000 |
parents | 564d4bfbb911 |
children | 5f128be91f59 |
rev | line source |
---|---|
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12777
diff
changeset
|
9 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
10 /** @file ai_scanner.cpp allows scanning AI scripts */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
11 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
12 #include "../stdafx.h" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
13 #include "../debug.h" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
14 #include "../fileio_func.h" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
15 #include "../network/network.h" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
16 #include "../core/random_func.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
17 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
18 #include <squirrel.h> |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
19 #include "../script/squirrel.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
20 #include "../script/squirrel_helper.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
21 #include "../script/squirrel_class.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
22 #include "ai_info.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
23 #include "ai_scanner.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
24 #include "api/ai_controller.hpp" |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
25 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
26 void AIScanner::RescanAIDir() |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
27 { |
11385
ea7a290c75a5
(svn r15736) -Codechange: Split AIScanner/AIFileInfo to the more generic classes ScriptScanner/ScriptFileInfo.
yexo <yexo@openttd.org>
parents:
11368
diff
changeset
|
28 this->ScanScriptDir("info.nut", AI_DIR); |
ea7a290c75a5
(svn r15736) -Codechange: Split AIScanner/AIFileInfo to the more generic classes ScriptScanner/ScriptFileInfo.
yexo <yexo@openttd.org>
parents:
11368
diff
changeset
|
29 this->ScanScriptDir("library.nut", AI_LIBRARY_DIR); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
30 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
31 |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
32 AIScanner::AIScanner() : |
11385
ea7a290c75a5
(svn r15736) -Codechange: Split AIScanner/AIFileInfo to the more generic classes ScriptScanner/ScriptFileInfo.
yexo <yexo@openttd.org>
parents:
11368
diff
changeset
|
33 ScriptScanner(), |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
34 info_dummy(NULL) |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
35 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
36 /* Create the AIInfo class, and add the RegisterAI function */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
37 DefSQClass <AIInfo> SQAIInfo("AIInfo"); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
38 SQAIInfo.PreRegister(engine); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
39 SQAIInfo.AddConstructor<void (AIInfo::*)(), 1>(engine, "x"); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
40 SQAIInfo.DefSQAdvancedMethod(this->engine, &AIInfo::AddSetting, "AddSetting"); |
11026
2e46cdff4e8b
(svn r15366) -Add [NoAI]: Add AddLabels() where you can define labels for the values of the settings in info.nut
Yexo <Yexo@openttd.org>
parents:
10960
diff
changeset
|
41 SQAIInfo.DefSQAdvancedMethod(this->engine, &AIInfo::AddLabels, "AddLabels"); |
14396
4de60292e2a6
(svn r18953) -Feature: [NoAI] allow editing AI settings while an AI is running
yexo <yexo@openttd.org>
parents:
14387
diff
changeset
|
42 SQAIInfo.DefSQConst(engine, AICONFIG_NONE, "AICONFIG_NONE"); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
43 SQAIInfo.DefSQConst(engine, AICONFIG_RANDOM, "AICONFIG_RANDOM"); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
44 SQAIInfo.DefSQConst(engine, AICONFIG_BOOLEAN, "AICONFIG_BOOLEAN"); |
14396
4de60292e2a6
(svn r18953) -Feature: [NoAI] allow editing AI settings while an AI is running
yexo <yexo@openttd.org>
parents:
14387
diff
changeset
|
45 SQAIInfo.DefSQConst(engine, AICONFIG_INGAME, "AICONFIG_INGAME"); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
46 SQAIInfo.PostRegister(engine); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
47 this->engine->AddMethod("RegisterAI", &AIInfo::Constructor, 2, "tx"); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
48 this->engine->AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, 2, "tx"); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
49 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
50 /* Create the AILibrary class, and add the RegisterLibrary function */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
51 this->engine->AddClassBegin("AILibrary"); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
52 this->engine->AddClassEnd(); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
53 this->engine->AddMethod("RegisterLibrary", &AILibrary::Constructor, 2, "tx"); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
54 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
55 /* Scan the AI dir for scripts */ |
11385
ea7a290c75a5
(svn r15736) -Codechange: Split AIScanner/AIFileInfo to the more generic classes ScriptScanner/ScriptFileInfo.
yexo <yexo@openttd.org>
parents:
11368
diff
changeset
|
56 this->RescanAIDir(); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
57 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
58 /* Create the dummy AI */ |
11121
c44c1e011090
(svn r15467) -Fix [NoAI]: AIs with an error in their info.nut are no longer available in-game.
yexo <yexo@openttd.org>
parents:
11118
diff
changeset
|
59 this->engine->ResetCrashed(); |
11644
7980a47b17cb
(svn r16024) -Codechange: harden string copying on places where it's possible
rubidium <rubidium@openttd.org>
parents:
11385
diff
changeset
|
60 strecpy(this->main_script, "%_dummy", lastof(this->main_script)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
61 extern void AI_CreateAIInfoDummy(HSQUIRRELVM vm); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
62 AI_CreateAIInfoDummy(this->engine->GetVM()); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
63 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
64 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
65 AIScanner::~AIScanner() |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
66 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
67 AIInfoList::iterator it = this->info_list.begin(); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
68 for (; it != this->info_list.end(); it++) { |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
69 free((void *)(*it).first); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
70 delete (*it).second; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
71 } |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
72 it = this->info_single_list.begin(); |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
73 for (; it != this->info_single_list.end(); it++) { |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
74 free((void *)(*it).first); |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
75 } |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
76 AILibraryList::iterator lit = this->library_list.begin(); |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
77 for (; lit != this->library_list.end(); lit++) { |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
78 free((void *)(*lit).first); |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
79 delete (*lit).second; |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
80 } |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
81 |
10788
689e9e617727
(svn r15121) -Fix: more mem-leak fixes (this should make SmatZ so happy ;) :p)
truebrain <truebrain@openttd.org>
parents:
10787
diff
changeset
|
82 delete this->info_dummy; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
83 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
84 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
85 bool AIScanner::ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm, AIController *controller) |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
86 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
87 /* Internally we store libraries as 'library.version' */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
88 char library_name[1024]; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
89 snprintf(library_name, sizeof(library_name), "%s.%d", library, version); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
90 strtolower(library_name); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
91 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
92 /* Check if the library + version exists */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
93 AILibraryList::iterator iter = this->library_list.find(library_name); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
94 if (iter == this->library_list.end()) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
95 char error[1024]; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
96 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
97 /* Now see if the version doesn't exist, or the library */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
98 iter = this->library_list.find(library); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
99 if (iter == this->library_list.end()) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
100 snprintf(error, sizeof(error), "couldn't find library '%s'", library); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
101 } else { |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
102 snprintf(error, sizeof(error), "couldn't find library '%s' version %d. The latest version available is %d", library, version, (*iter).second->GetVersion()); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
103 } |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
104 sq_throwerror(vm, OTTD2SQ(error)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
105 return false; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
106 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
107 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
108 /* Get the current table/class we belong to */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
109 HSQOBJECT parent; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
110 sq_getstackobj(vm, 1, &parent); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
111 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
112 char fake_class[1024]; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
113 int next_number; |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
114 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
115 if (!controller->LoadedLibrary(library_name, &next_number, &fake_class[0], sizeof(fake_class))) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
116 /* Create a new fake internal name */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
117 snprintf(fake_class, sizeof(fake_class), "_internalNA%d", next_number); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
118 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
119 /* Load the library in a 'fake' namespace, so we can link it to the name the user requested */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
120 sq_pushroottable(vm); |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
121 sq_pushstring(vm, OTTD2SQ(fake_class), -1); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
122 sq_newclass(vm, SQFalse); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
123 /* Load the library */ |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
124 if (!Squirrel::LoadScript(vm, (*iter).second->GetMainScript(), false)) { |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
125 char error[1024]; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
126 snprintf(error, sizeof(error), "there was a compile error when importing '%s' version %d", library, version); |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
127 sq_throwerror(vm, OTTD2SQ(error)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
128 return false; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
129 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
130 /* Create the fake class */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
131 sq_newslot(vm, -3, SQFalse); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
132 sq_pop(vm, 1); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
133 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
134 controller->AddLoadedLibrary(library_name, fake_class); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
135 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
136 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
137 /* Find the real class inside the fake class (like 'sets.Vector') */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
138 sq_pushroottable(vm); |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
139 sq_pushstring(vm, OTTD2SQ(fake_class), -1); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
140 if (SQ_FAILED(sq_get(vm, -2))) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
141 sq_throwerror(vm, _SC("internal error assigning library class")); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
142 return false; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
143 } |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
144 sq_pushstring(vm, OTTD2SQ((*iter).second->GetInstanceName()), -1); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
145 if (SQ_FAILED(sq_get(vm, -2))) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
146 char error[1024]; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
147 snprintf(error, sizeof(error), "unable to find class '%s' in the library '%s' version %d", (*iter).second->GetInstanceName(), library, version); |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
148 sq_throwerror(vm, OTTD2SQ(error)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
149 return false; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
150 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
151 HSQOBJECT obj; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
152 sq_getstackobj(vm, -1, &obj); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
153 sq_pop(vm, 3); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
154 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
155 if (StrEmpty(class_name)) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
156 sq_pushobject(vm, obj); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
157 return true; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
158 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
159 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
160 /* Now link the name the user wanted to our 'fake' class */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
161 sq_pushobject(vm, parent); |
14310
84c12fbfc0f1
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
162 sq_pushstring(vm, OTTD2SQ(class_name), -1); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
163 sq_pushobject(vm, obj); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
164 sq_newclass(vm, SQTrue); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
165 sq_newslot(vm, -3, SQFalse); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
166 sq_pop(vm, 1); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
167 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
168 sq_pushobject(vm, obj); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
169 return true; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
170 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
171 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
172 void AIScanner::RegisterLibrary(AILibrary *library) |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
173 { |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
174 char library_name[1024]; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
175 snprintf(library_name, sizeof(library_name), "%s.%s.%d", library->GetCategory(), library->GetInstanceName(), library->GetVersion()); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
176 strtolower(library_name); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
177 |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
178 if (this->library_list.find(library_name) != this->library_list.end()) { |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
179 /* This AI was already registered */ |
10891
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
180 #ifdef WIN32 |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
181 /* Windows doesn't care about the case */ |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
182 if (strcasecmp(this->library_list[library_name]->GetMainScript(), library->GetMainScript()) == 0) { |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
183 #else |
10787
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
184 if (strcmp(this->library_list[library_name]->GetMainScript(), library->GetMainScript()) == 0) { |
10891
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
185 #endif |
10787
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
186 delete library; |
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
187 return; |
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
188 } |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
189 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
190 DEBUG(ai, 0, "Registering two libraries with the same name and version"); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
191 DEBUG(ai, 0, " 1: %s", this->library_list[library_name]->GetMainScript()); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
192 DEBUG(ai, 0, " 2: %s", library->GetMainScript()); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
193 DEBUG(ai, 0, "The first is taking precedence."); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
194 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
195 delete library; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
196 return; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
197 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
198 |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
199 this->library_list[strdup(library_name)] = library; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
200 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
201 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
202 void AIScanner::RegisterAI(AIInfo *info) |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
203 { |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
204 char ai_name[1024]; |
11209
5a38ee27e201
(svn r15562) -Change: Use GetName() to determine the unique AI name instead of GetInstanceName() to make branching of AIs easier.
yexo <yexo@openttd.org>
parents:
11121
diff
changeset
|
205 snprintf(ai_name, sizeof(ai_name), "%s.%d", info->GetName(), info->GetVersion()); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
206 strtolower(ai_name); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
207 |
10757
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
208 /* Check if GetShortName follows the rules */ |
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
209 if (strlen(info->GetShortName()) != 4) { |
11209
5a38ee27e201
(svn r15562) -Change: Use GetName() to determine the unique AI name instead of GetInstanceName() to make branching of AIs easier.
yexo <yexo@openttd.org>
parents:
11121
diff
changeset
|
210 DEBUG(ai, 0, "The AI '%s' returned a string from GetShortName() which is not four characaters. Unable to load the AI.", info->GetName()); |
10757
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
211 delete info; |
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
212 return; |
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
213 } |
dcc20859477f
(svn r15090) -Add [NoAI] [API CHANGE]: info.nut/library.nut now requires a function GetShortName(), which should return a 4 (four) character string, unique throughout the world. This id is simular to a GRFid.
truebrain <truebrain@openttd.org>
parents:
10749
diff
changeset
|
214 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
215 if (this->info_list.find(ai_name) != this->info_list.end()) { |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
216 /* This AI was already registered */ |
10891
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
217 #ifdef WIN32 |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
218 /* Windows doesn't care about the case */ |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
219 if (strcasecmp(this->info_list[ai_name]->GetMainScript(), info->GetMainScript()) == 0) { |
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
220 #else |
10787
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
221 if (strcmp(this->info_list[ai_name]->GetMainScript(), info->GetMainScript()) == 0) { |
10891
4c37fc0ec65c
(svn r15226) -Fix (r15214): broken AI content download
glx <glx@openttd.org>
parents:
10879
diff
changeset
|
222 #endif |
10787
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
223 delete info; |
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
224 return; |
95c485f0d1af
(svn r15120) -Fix: more mem-leak fixes
truebrain <truebrain@openttd.org>
parents:
10774
diff
changeset
|
225 } |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
226 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
227 DEBUG(ai, 0, "Registering two AIs with the same name and version"); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
228 DEBUG(ai, 0, " 1: %s", this->info_list[ai_name]->GetMainScript()); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
229 DEBUG(ai, 0, " 2: %s", info->GetMainScript()); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
230 DEBUG(ai, 0, "The first is taking precedence."); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
231 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
232 delete info; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
233 return; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
234 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
235 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
236 this->info_list[strdup(ai_name)] = info; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
237 |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
238 /* Add the AI to the 'unique' AI list, where only the highest version of the |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
239 * AI is registered. */ |
11209
5a38ee27e201
(svn r15562) -Change: Use GetName() to determine the unique AI name instead of GetInstanceName() to make branching of AIs easier.
yexo <yexo@openttd.org>
parents:
11121
diff
changeset
|
240 snprintf(ai_name, sizeof(ai_name), "%s", info->GetName()); |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
241 strtolower(ai_name); |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
242 if (this->info_single_list.find(ai_name) == this->info_single_list.end()) { |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
243 this->info_single_list[strdup(ai_name)] = info; |
10788
689e9e617727
(svn r15121) -Fix: more mem-leak fixes (this should make SmatZ so happy ;) :p)
truebrain <truebrain@openttd.org>
parents:
10787
diff
changeset
|
244 } else if (this->info_single_list[ai_name]->GetVersion() < info->GetVersion()) { |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
245 this->info_single_list[ai_name] = info; |
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
246 } |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
247 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
248 |
14197
06812674f0fc
(svn r18747) -Codechange: add some constness to the AI code
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
249 AIInfo *AIScanner::SelectRandomAI() const |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
250 { |
11725
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
251 uint num_random_ais = 0; |
14197
06812674f0fc
(svn r18747) -Codechange: add some constness to the AI code
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
252 for (AIInfoList::const_iterator it = this->info_single_list.begin(); it != this->info_single_list.end(); it++) { |
11725
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
253 if (it->second->UseAsRandomAI()) num_random_ais++; |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
254 } |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
255 |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
256 if (num_random_ais == 0) { |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
257 DEBUG(ai, 0, "No suitable AI found, loading 'dummy' AI."); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
258 return this->info_dummy; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
259 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
260 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
261 /* Find a random AI */ |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
262 uint pos; |
11725
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
263 if (_networking) { |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
264 pos = InteractiveRandomRange(num_random_ais); |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
265 } else { |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
266 pos = RandomRange(num_random_ais); |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
267 } |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
268 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
269 /* Find the Nth item from the array */ |
14197
06812674f0fc
(svn r18747) -Codechange: add some constness to the AI code
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
270 AIInfoList::const_iterator it = this->info_single_list.begin(); |
11725
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
271 while (!it->second->UseAsRandomAI()) it++; |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
272 for (; pos > 0; pos--) { |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
273 it++; |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
274 while (!it->second->UseAsRandomAI()) it++; |
acd8ca0836d4
(svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI.
yexo <yexo@openttd.org>
parents:
11644
diff
changeset
|
275 } |
10713
76a61ec44203
(svn r15045) -Add [NoAI API CHANGE]: in info.nut you can now have (optional) a CanLoadFromVersion(version), which should return true/false, to indicate if you can load a savegame made with your AI of version 'version'
truebrain <truebrain@openttd.org>
parents:
10696
diff
changeset
|
276 return (*it).second; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
277 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
278 |
14387
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
279 AIInfo *AIScanner::FindInfo(const char *nameParam, int versionParam, bool force_exact_match) |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
280 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
281 if (this->info_list.size() == 0) return NULL; |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
282 if (nameParam == NULL) return NULL; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
283 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
284 char ai_name[1024]; |
10774
b7eaf7ee6d39
(svn r15107) -Fix [NoAI]: don't use so much explicit string copies if it is not required
truebrain <truebrain@openttd.org>
parents:
10773
diff
changeset
|
285 ttd_strlcpy(ai_name, nameParam, sizeof(ai_name)); |
b7eaf7ee6d39
(svn r15107) -Fix [NoAI]: don't use so much explicit string copies if it is not required
truebrain <truebrain@openttd.org>
parents:
10773
diff
changeset
|
286 strtolower(ai_name); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
287 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
288 AIInfo *info = NULL; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
289 int version = -1; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
290 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
291 if (versionParam == -1) { |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
292 /* We want to load the latest version of this AI; so find it */ |
10763
50c7b054901b
(svn r15096) -Fix [NoAI]: free memory when no longer needed
truebrain <truebrain@openttd.org>
parents:
10762
diff
changeset
|
293 if (this->info_single_list.find(ai_name) != this->info_single_list.end()) return this->info_single_list[ai_name]; |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
294 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
295 /* If we didn't find a match AI, maybe the user included a version */ |
10774
b7eaf7ee6d39
(svn r15107) -Fix [NoAI]: don't use so much explicit string copies if it is not required
truebrain <truebrain@openttd.org>
parents:
10773
diff
changeset
|
296 char *e = strrchr(ai_name, '.'); |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
297 if (e == NULL) return NULL; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
298 *e = '\0'; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
299 e++; |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
300 versionParam = atoi(e); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
301 /* Fall-through, like we were calling this function with a version */ |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
302 } |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
303 |
14387
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
304 if (force_exact_match) { |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
305 /* Try to find a direct 'name.version' match */ |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
306 char ai_name_tmp[1024]; |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
307 snprintf(ai_name_tmp, sizeof(ai_name_tmp), "%s.%d", ai_name, versionParam); |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
308 strtolower(ai_name_tmp); |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
309 if (this->info_list.find(ai_name_tmp) != this->info_list.end()) return this->info_list[ai_name_tmp]; |
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
310 } |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
311 |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
312 /* See if there is a compatible AI which goes by that name, with the highest |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
313 * version which allows loading the requested version */ |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
314 AIInfoList::iterator it = this->info_list.begin(); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
315 for (; it != this->info_list.end(); it++) { |
14387
564d4bfbb911
(svn r18944) -Change [FS#3232]: use the highest version of an AI that can load the AI data from a savegame instead of the exact same version
yexo <yexo@openttd.org>
parents:
14310
diff
changeset
|
316 if (strcasecmp(ai_name, (*it).second->GetName()) == 0 && (*it).second->CanLoadFromVersion(versionParam) && (version == -1 || (*it).second->GetVersion() > version)) { |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
317 version = (*it).second->GetVersion(); |
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
318 info = (*it).second; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
319 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
320 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
321 |
10762
ef33f4596ff0
(svn r15095) -Add [NoAI]: allow AI Libraries to be in .tar files (subdir required, as with AIs
truebrain <truebrain@openttd.org>
parents:
10757
diff
changeset
|
322 return info; |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
323 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
324 |
14197
06812674f0fc
(svn r18747) -Codechange: add some constness to the AI code
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
325 char *AIScanner::GetAIConsoleList(char *p, const char *last) const |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
326 { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
327 p += seprintf(p, last, "List of AIs:\n"); |
14197
06812674f0fc
(svn r18747) -Codechange: add some constness to the AI code
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
328 AIInfoList::const_iterator it = this->info_list.begin(); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
329 for (; it != this->info_list.end(); it++) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
330 AIInfo *i = (*it).second; |
11209
5a38ee27e201
(svn r15562) -Change: Use GetName() to determine the unique AI name instead of GetInstanceName() to make branching of AIs easier.
yexo <yexo@openttd.org>
parents:
11121
diff
changeset
|
331 p += seprintf(p, last, "%10s (v%d): %s\n", i->GetName(), i->GetVersion(), i->GetDescription()); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
332 } |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
333 p += seprintf(p, last, "\n"); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
334 |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
335 return p; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
diff
changeset
|
336 } |
10793
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
337 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
338 #if defined(ENABLE_NETWORK) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
339 #include "../network/network_content.h" |
12777
5732e685a232
(svn r17247) -Change: move '3rd party' MD5 implementation also to the 3rdparty directory.
rubidium <rubidium@openttd.org>
parents:
12235
diff
changeset
|
340 #include "../3rdparty/md5/md5.h" |
10793
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
341 #include "../tar_type.h" |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
342 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
343 /** Helper for creating a MD5sum of all files within of an AI. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
344 struct AIFileChecksumCreator : FileScanner { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
345 byte md5sum[16]; ///< The final md5sum |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
346 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
347 /** |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
348 * Initialise the md5sum to be all zeroes, |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
349 * so we can easily xor the data. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
350 */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
351 AIFileChecksumCreator() |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
352 { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
353 memset(this->md5sum, 0, sizeof(this->md5sum)); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
354 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
355 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
356 /* Add the file and calculate the md5 sum. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
357 virtual bool AddFile(const char *filename, size_t basepath_length) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
358 { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
359 Md5 checksum; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
360 uint8 buffer[1024]; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
361 size_t len, size; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
362 byte tmp_md5sum[16]; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
363 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
364 /* Open the file ... */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
365 FILE *f = FioFOpenFile(filename, "rb", DATA_DIR, &size); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
366 if (f == NULL) return false; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
367 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
368 /* ... calculate md5sum... */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
369 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
370 size -= len; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
371 checksum.Append(buffer, len); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
372 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
373 checksum.Finish(tmp_md5sum); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
374 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
375 FioFCloseFile(f); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
376 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
377 /* ... and xor it to the overall md5sum. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
378 for (uint i = 0; i < sizeof(md5sum); i++) this->md5sum[i] ^= tmp_md5sum[i]; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
379 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
380 return true; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
381 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
382 }; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
383 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
384 /** |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
385 * Check whether the AI given in info is the same as in ci based |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
386 * on the shortname and md5 sum. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
387 * @param ci the information to compare to |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
388 * @param md5sum whether to check the MD5 checksum |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
389 * @param info the AI to get the shortname and md5 sum from |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
390 * @return true iff they're the same |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
391 */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
392 static bool IsSameAI(const ContentInfo *ci, bool md5sum, AIFileInfo *info) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
393 { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
394 uint32 id = 0; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
395 const char *str = info->GetShortName(); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
396 for (int j = 0; j < 4 && *str != '\0'; j++, str++) id |= *str << (8 * j); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
397 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
398 if (id != ci->unique_id) return false; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
399 if (!md5sum) return true; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
400 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
401 AIFileChecksumCreator checksum; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
402 char path[MAX_PATH]; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
403 strecpy(path, info->GetMainScript(), lastof(path)); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
404 /* There'll always be at least 2 path separator characters in an AI's |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
405 * main script name as the search algorithm requires the main script to |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
406 * be in a subdirectory of the AI directory; so ai/<path>/main.nut. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
407 *strrchr(path, PATHSEPCHAR) = '\0'; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
408 *strrchr(path, PATHSEPCHAR) = '\0'; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
409 TarList::iterator iter = _tar_list.find(path); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
410 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
411 if (iter != _tar_list.end()) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
412 /* The main script is in a tar file, so find all files that |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
413 * are in the same tar and add them to the MD5 checksumming. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
414 TarFileList::iterator tar; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
415 FOR_ALL_TARS(tar) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
416 /* Not in the same tar. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
417 if (tar->second.tar_filename != iter->first) continue; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
418 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
419 /* Check the extension. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
420 const char *ext = strrchr(tar->first.c_str(), '.'); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
421 if (ext == NULL || strcasecmp(ext, ".nut") != 0) continue; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
422 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
423 /* Create the full path name, */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
424 seprintf(path, lastof(path), "%s%c%s", tar->second.tar_filename, PATHSEPCHAR, tar->first.c_str()); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
425 checksum.AddFile(path, 0); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
426 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
427 } else { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
428 /* Add the path sep char back when searching a directory, so we are |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
429 * in the actual directory. */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
430 path[strlen(path)] = PATHSEPCHAR; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
431 checksum.Scan(".nut", path); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
432 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
433 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
434 return memcmp(ci->md5sum, checksum.md5sum, sizeof(ci->md5sum)) == 0; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
435 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
436 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
437 /** |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
438 * Check whether we have an AI (library) with the exact characteristics as ci. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
439 * @param ci the characteristics to search on (shortname and md5sum) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
440 * @param md5sum whether to check the MD5 checksum |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
441 * @return true iff we have an AI (library) matching. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
442 */ |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
443 bool AIScanner::HasAI(const ContentInfo *ci, bool md5sum) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
444 { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
445 switch (ci->type) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
446 case CONTENT_TYPE_AI: |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
447 for (AIInfoList::iterator it = this->info_list.begin(); it != this->info_list.end(); it++) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
448 if (IsSameAI(ci, md5sum, (*it).second)) return true; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
449 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
450 return false; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
451 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
452 case CONTENT_TYPE_AI_LIBRARY: |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
453 for (AILibraryList::iterator it = this->library_list.begin(); it != this->library_list.end(); it++) { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
454 if (IsSameAI(ci, md5sum, (*it).second)) return true; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
455 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
456 return false; |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
457 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
458 default: |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
459 NOT_REACHED(); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
460 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
461 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
462 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
463 /** |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
464 * Check whether we have an AI (library) with the exact characteristics as ci. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
465 * @param ci the characteristics to search on (shortname and md5sum) |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
466 * @param md5sum whether to check the MD5 checksum |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
467 * @return true iff we have an AI (library) matching. |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
468 */ |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11366
diff
changeset
|
469 /* static */ bool AI::HasAI(const ContentInfo *ci, bool md5sum) |
10793
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
470 { |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
471 return AI::ai_scanner->HasAI(ci, md5sum); |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
472 } |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
473 |
0744d383a56b
(svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents:
10788
diff
changeset
|
474 #endif /* ENABLE_NETWORK */ |