1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 
21 #include "script/cbottoken.h"
22 
23 #include "app/app.h"
24 
25 #include "object/object_type.h"
26 
27 #include <string.h>
28 
29 
30 // Seeking the name of an object.
31 
GetObjectName(ObjectType type)32 const char* GetObjectName(ObjectType type)
33 {
34     if ( type == OBJECT_PORTICO     )  return "Portico";
35     if ( type == OBJECT_BASE        )  return "SpaceShip";
36     if ( type == OBJECT_DERRICK     )  return "Derrick";
37     if ( type == OBJECT_FACTORY     )  return "BotFactory";
38     if ( type == OBJECT_STATION     )  return "PowerStation";
39     if ( type == OBJECT_CONVERT     )  return "Converter";
40     if ( type == OBJECT_REPAIR      )  return "RepairCenter";
41     if ( type == OBJECT_DESTROYER   )  return "Destroyer";
42     if ( type == OBJECT_TOWER       )  return "DefenseTower";
43     if ( type == OBJECT_NEST        )  return "AlienNest";
44     if ( type == OBJECT_RESEARCH    )  return "ResearchCenter";
45     if ( type == OBJECT_RADAR       )  return "RadarStation";
46     if ( type == OBJECT_INFO        )  return "ExchangePost";
47     if ( type == OBJECT_ENERGY      )  return "PowerPlant";
48     if ( type == OBJECT_LABO        )  return "AutoLab";
49     if ( type == OBJECT_NUCLEAR     )  return "NuclearPlant";
50     if ( type == OBJECT_PARA        )  return "PowerCaptor";
51     if ( type == OBJECT_SAFE        )  return "Vault";
52     if ( type == OBJECT_HUSTON      )  return "Houston";
53     if ( type == OBJECT_TARGET1     )  return "Target1";
54     if ( type == OBJECT_TARGET2     )  return "Target2";
55     if ( type == OBJECT_START       )  return "StartArea";
56     if ( type == OBJECT_END         )  return "GoalArea";
57     if ( type == OBJECT_TEEN34      )  return "Stone";
58     if ( type == OBJECT_STONE       )  return "TitaniumOre";
59     if ( type == OBJECT_URANIUM     )  return "UraniumOre";
60     if ( type == OBJECT_METAL       )  return "Titanium";
61     if ( type == OBJECT_POWER       )  return "PowerCell";
62     if ( type == OBJECT_ATOMIC      )  return "NuclearCell";
63     if ( type == OBJECT_BULLET      )  return "OrgaMatter";
64     if ( type == OBJECT_BBOX        )  return "BlackBox";
65     if ( type == OBJECT_KEYa        )  return "KeyA";
66     if ( type == OBJECT_KEYb        )  return "KeyB";
67     if ( type == OBJECT_KEYc        )  return "KeyC";
68     if ( type == OBJECT_KEYd        )  return "KeyD";
69     if ( type == OBJECT_TNT         )  return "TNT";
70     if ( type == OBJECT_BOMB        )  return "Mine";
71     if ( type == OBJECT_BARRIER1    )  return "Barrier";
72     if ( type == OBJECT_WAYPOINT    )  return "WayPoint";
73     if ( type == OBJECT_FLAGb       )  return "BlueFlag";
74     if ( type == OBJECT_FLAGr       )  return "RedFlag";
75     if ( type == OBJECT_FLAGg       )  return "GreenFlag";
76     if ( type == OBJECT_FLAGy       )  return "YellowFlag";
77     if ( type == OBJECT_FLAGv       )  return "VioletFlag";
78     if ( type == OBJECT_MARKPOWER   )  return "PowerSpot";
79     if ( type == OBJECT_MARKSTONE   )  return "TitaniumSpot";
80     if ( type == OBJECT_MARKURANIUM )  return "UraniumSpot";
81     if ( type == OBJECT_MARKKEYa    )  return "KeyASpot";
82     if ( type == OBJECT_MARKKEYb    )  return "KeyBSpot";
83     if ( type == OBJECT_MARKKEYc    )  return "KeyCSpot";
84     if ( type == OBJECT_MARKKEYd    )  return "KeyDSpot";
85     if ( type == OBJECT_MOBILEwt    )  return "WheeledTrainer";
86     if ( type == OBJECT_MOBILEtt    )  return "TrackedTrainer";
87     if ( type == OBJECT_MOBILEft    )  return "WingedTrainer";
88     if ( type == OBJECT_MOBILEit    )  return "LeggedTrainer";
89     if ( type == OBJECT_MOBILErp    )  return "HeavyTrainer";
90     if ( type == OBJECT_MOBILEst    )  return "AmphibiousTrainer";
91     if ( type == OBJECT_MOBILEwa    )  return "WheeledGrabber";
92     if ( type == OBJECT_MOBILEta    )  return "TrackedGrabber";
93     if ( type == OBJECT_MOBILEfa    )  return "WingedGrabber";
94     if ( type == OBJECT_MOBILEia    )  return "LeggedGrabber";
95     if ( type == OBJECT_MOBILEwc    )  return "WheeledShooter";
96     if ( type == OBJECT_MOBILEtc    )  return "TrackedShooter";
97     if ( type == OBJECT_MOBILEfc    )  return "WingedShooter";
98     if ( type == OBJECT_MOBILEic    )  return "LeggedShooter";
99     if ( type == OBJECT_MOBILEwi    )  return "WheeledOrgaShooter";
100     if ( type == OBJECT_MOBILEti    )  return "TrackedOrgaShooter";
101     if ( type == OBJECT_MOBILEfi    )  return "WingedOrgaShooter";
102     if ( type == OBJECT_MOBILEii    )  return "LeggedOrgaShooter";
103     if ( type == OBJECT_MOBILEws    )  return "WheeledSniffer";
104     if ( type == OBJECT_MOBILEts    )  return "TrackedSniffer";
105     if ( type == OBJECT_MOBILEfs    )  return "WingedSniffer";
106     if ( type == OBJECT_MOBILEis    )  return "LeggedSniffer";
107     if ( type == OBJECT_MOBILEwb    )  return "WheeledBuilder";
108     if ( type == OBJECT_MOBILEtb    )  return "TrackedBuilder";
109     if ( type == OBJECT_MOBILEfb    )  return "WingedBuilder";
110     if ( type == OBJECT_MOBILEib    )  return "LeggedBuilder";
111     if ( type == OBJECT_MOBILErt    )  return "Thumper";
112     if ( type == OBJECT_MOBILErc    )  return "PhazerShooter";
113     if ( type == OBJECT_MOBILErr    )  return "Recycler";
114     if ( type == OBJECT_MOBILErs    )  return "Shielder";
115     if ( type == OBJECT_MOBILEsa    )  return "Subber";
116     if ( type == OBJECT_MOBILEtg    )  return "TargetBot";
117     if ( type == OBJECT_MOBILEdr    )  return "Scribbler";
118     if ( type == OBJECT_MOBILEpr    )  return "PracticeBot";
119     if ( type == OBJECT_HUMAN       )  return "Me";
120     if ( type == OBJECT_TECH        )  return "Tech";
121     if ( type == OBJECT_MOTHER      )  return "AlienQueen";
122     if ( type == OBJECT_EGG         )  return "AlienEgg";
123     if ( type == OBJECT_ANT         )  return "AlienAnt";
124     if ( type == OBJECT_SPIDER      )  return "AlienSpider";
125     if ( type == OBJECT_BEE         )  return "AlienWasp";
126     if ( type == OBJECT_WORM        )  return "AlienWorm";
127     if ( type == OBJECT_RUINmobilew1)  return "Wreck";
128     if ( type == OBJECT_RUINfactory )  return "Ruin";
129     if ( type == OBJECT_PLANT0      )  return "Bush";
130     if ( type == OBJECT_ROOT5       )  return "GraviPlant";
131     if ( type == OBJECT_QUARTZ0     )  return "Crystal";
132     if ( type == OBJECT_MUSHROOM1   )  return "BrownMushroom";
133     if ( type == OBJECT_MUSHROOM2   )  return "GreenMushroom";
134     return "";
135 }
136 
137 // Seeking the name of a secondary object.
138 // (because Otto thinks that Germans do not like nuclear power)
139 
GetObjectAlias(ObjectType type)140 const char* GetObjectAlias(ObjectType type)
141 {
142     if ( type == OBJECT_NUCLEAR     )  return "FuelCellPlant";
143     if ( type == OBJECT_URANIUM     )  return "PlatinumOre";
144     if ( type == OBJECT_ATOMIC      )  return "FuelCell";
145     if ( type == OBJECT_MARKURANIUM )  return "PlatinumSpot";
146     return "";
147 }
148 
149 
150 // Returns the help file to use for the object.
151 
GetHelpFilename(ObjectType type)152 std::string GetHelpFilename(ObjectType type)
153 {
154     std::string helpfile = "";
155 
156     if ( type == OBJECT_BASE        )  helpfile = "object/base";
157     if ( type == OBJECT_DERRICK     )  helpfile = "object/derrick";
158     if ( type == OBJECT_FACTORY     )  helpfile = "object/factory";
159     if ( type == OBJECT_STATION     )  helpfile = "object/station";
160     if ( type == OBJECT_CONVERT     )  helpfile = "object/convert";
161     if ( type == OBJECT_REPAIR      )  helpfile = "object/repair";
162     if ( type == OBJECT_DESTROYER   )  helpfile = "object/destroy";
163     if ( type == OBJECT_TOWER       )  helpfile = "object/tower";
164     if ( type == OBJECT_NEST        )  helpfile = "object/nest";
165     if ( type == OBJECT_RESEARCH    )  helpfile = "object/research";
166     if ( type == OBJECT_RADAR       )  helpfile = "object/radar";
167     if ( type == OBJECT_INFO        )  helpfile = "object/exchange";
168     if ( type == OBJECT_ENERGY      )  helpfile = "object/energy";
169     if ( type == OBJECT_LABO        )  helpfile = "object/labo";
170     if ( type == OBJECT_NUCLEAR     )  helpfile = "object/nuclear";
171     if ( type == OBJECT_PARA        )  helpfile = "object/captor";
172     if ( type == OBJECT_SAFE        )  helpfile = "object/safe";
173     if ( type == OBJECT_HUSTON      )  helpfile = "object/huston";
174     if ( type == OBJECT_START       )  helpfile = "object/start";
175     if ( type == OBJECT_END         )  helpfile = "object/goal";
176     if ( type == OBJECT_STONE       )  helpfile = "object/titanore";
177     if ( type == OBJECT_URANIUM     )  helpfile = "object/uranore";
178     if ( type == OBJECT_METAL       )  helpfile = "object/titan";
179     if ( type == OBJECT_POWER       )  helpfile = "object/power";
180     if ( type == OBJECT_ATOMIC      )  helpfile = "object/atomic";
181     if ( type == OBJECT_BULLET      )  helpfile = "object/bullet";
182     if ( type == OBJECT_BBOX        )  helpfile = "object/bbox";
183     if ( type == OBJECT_KEYa        )  helpfile = "object/key";
184     if ( type == OBJECT_KEYb        )  helpfile = "object/key";
185     if ( type == OBJECT_KEYc        )  helpfile = "object/key";
186     if ( type == OBJECT_KEYd        )  helpfile = "object/key";
187     if ( type == OBJECT_TNT         )  helpfile = "object/tnt";
188     if ( type == OBJECT_BOMB        )  helpfile = "object/mine";
189     if ( type == OBJECT_BARRIER1    )  helpfile = "object/barrier";
190     if ( type == OBJECT_WAYPOINT    )  helpfile = "object/waypoint";
191     if ( type == OBJECT_FLAGb       )  helpfile = "object/flag";
192     if ( type == OBJECT_FLAGr       )  helpfile = "object/flag";
193     if ( type == OBJECT_FLAGg       )  helpfile = "object/flag";
194     if ( type == OBJECT_FLAGy       )  helpfile = "object/flag";
195     if ( type == OBJECT_FLAGv       )  helpfile = "object/flag";
196     if ( type == OBJECT_MARKPOWER   )  helpfile = "object/enerspot";
197     if ( type == OBJECT_MARKSTONE   )  helpfile = "object/stonspot";
198     if ( type == OBJECT_MARKURANIUM )  helpfile = "object/uranspot";
199     if ( type == OBJECT_MOBILEwa    )  helpfile = "object/botgr";
200     if ( type == OBJECT_MOBILEta    )  helpfile = "object/botgc";
201     if ( type == OBJECT_MOBILEfa    )  helpfile = "object/botgj";
202     if ( type == OBJECT_MOBILEia    )  helpfile = "object/botgs";
203     if ( type == OBJECT_MOBILEws    )  helpfile = "object/botsr";
204     if ( type == OBJECT_MOBILEts    )  helpfile = "object/botsc";
205     if ( type == OBJECT_MOBILEfs    )  helpfile = "object/botsj";
206     if ( type == OBJECT_MOBILEis    )  helpfile = "object/botss";
207     if ( type == OBJECT_MOBILEwi    )  helpfile = "object/botor";
208     if ( type == OBJECT_MOBILEti    )  helpfile = "object/botoc";
209     if ( type == OBJECT_MOBILEfi    )  helpfile = "object/botoj";
210     if ( type == OBJECT_MOBILEii    )  helpfile = "object/botos";
211     if ( type == OBJECT_MOBILEwc    )  helpfile = "object/botfr";
212     if ( type == OBJECT_MOBILEtc    )  helpfile = "object/botfc";
213     if ( type == OBJECT_MOBILEfc    )  helpfile = "object/botfj";
214     if ( type == OBJECT_MOBILEic    )  helpfile = "object/botfs";
215     if ( type == OBJECT_MOBILEwb    )  helpfile = "object/botbr";
216     if ( type == OBJECT_MOBILEtb    )  helpfile = "object/botbc";
217     if ( type == OBJECT_MOBILEfb    )  helpfile = "object/botbj";
218     if ( type == OBJECT_MOBILEib    )  helpfile = "object/botbs";
219     if ( type == OBJECT_MOBILErt    )  helpfile = "object/bottump";
220     if ( type == OBJECT_MOBILErc    )  helpfile = "object/botphaz";
221     if ( type == OBJECT_MOBILErr    )  helpfile = "object/botrecy";
222     if ( type == OBJECT_MOBILErs    )  helpfile = "object/botshld";
223     if ( type == OBJECT_MOBILEsa    )  helpfile = "object/botsub";
224     if ( type == OBJECT_MOBILEwt    )  helpfile = "object/bottr";
225     if ( type == OBJECT_MOBILEtt    )  helpfile = "object/bottr";
226     if ( type == OBJECT_MOBILEft    )  helpfile = "object/bottr";
227     if ( type == OBJECT_MOBILEit    )  helpfile = "object/bottr";
228     if ( type == OBJECT_MOBILErp    )  helpfile = "object/bottr";
229     if ( type == OBJECT_MOBILEst    )  helpfile = "object/bottr";
230     if ( type == OBJECT_MOBILEtg    )  helpfile = "object/bottarg";
231     if ( type == OBJECT_MOBILEdr    )  helpfile = "object/botdraw";
232     if ( type == OBJECT_MOBILEpr    )  helpfile = "object/bottr";
233     if ( type == OBJECT_APOLLO2     )  helpfile = "object/lrv";
234     if ( type == OBJECT_HUMAN       )  helpfile = "object/human";
235     if ( type == OBJECT_MOTHER      )  helpfile = "object/mother";
236     if ( type == OBJECT_EGG         )  helpfile = "object/egg";
237     if ( type == OBJECT_ANT         )  helpfile = "object/ant";
238     if ( type == OBJECT_SPIDER      )  helpfile = "object/spider";
239     if ( type == OBJECT_BEE         )  helpfile = "object/wasp";
240     if ( type == OBJECT_WORM        )  helpfile = "object/worm";
241     if ( type == OBJECT_RUINmobilew1)  helpfile = "object/wreck";
242     if ( type == OBJECT_RUINfactory )  helpfile = "object/ruin";
243     if ( type == OBJECT_PLANT0      )  helpfile = "object/bush";
244     if ( type == OBJECT_ROOT5       )  helpfile = "object/gravi";
245     if ( type == OBJECT_QUARTZ0     )  helpfile = "object/crystal";
246     if ( type == OBJECT_MUSHROOM1   )  helpfile = "object/bromush";
247     if ( type == OBJECT_MUSHROOM2   )  helpfile = "object/gremush";
248 
249     if (helpfile.empty())
250         return "";
251 
252     return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + helpfile + ".txt";
253 }
254 
255 
256 // Returns the help file to use for instruction.
257 
GetHelpFilename(const char * token)258 std::string GetHelpFilename(const char *token)
259 {
260     std::string helpfile = "";
261 
262     if ( strcmp(token, "if"            ) == 0 )  helpfile = "cbot/if";
263     if ( strcmp(token, "else"          ) == 0 )  helpfile = "cbot/if";
264     if ( strcmp(token, "repeat"        ) == 0 )  helpfile = "cbot/repeat";
265     if ( strcmp(token, "for"           ) == 0 )  helpfile = "cbot/for";
266     if ( strcmp(token, "while"         ) == 0 )  helpfile = "cbot/while";
267     if ( strcmp(token, "do"            ) == 0 )  helpfile = "cbot/do";
268     if ( strcmp(token, "break"         ) == 0 )  helpfile = "cbot/break";
269     if ( strcmp(token, "continue"      ) == 0 )  helpfile = "cbot/continue";
270     if ( strcmp(token, "return"        ) == 0 )  helpfile = "cbot/return";
271     if ( strcmp(token, "sizeof"        ) == 0 )  helpfile = "cbot/sizeof";
272     if ( strcmp(token, "byte"          ) == 0 )  helpfile = "cbot/byte";
273     if ( strcmp(token, "short"         ) == 0 )  helpfile = "cbot/short";
274     if ( strcmp(token, "char"          ) == 0 )  helpfile = "cbot/char";
275     if ( strcmp(token, "int"           ) == 0 )  helpfile = "cbot/int";
276     if ( strcmp(token, "long"          ) == 0 )  helpfile = "cbot/long";
277     if ( strcmp(token, "float"         ) == 0 )  helpfile = "cbot/float";
278     if ( strcmp(token, "double"        ) == 0 )  helpfile = "cbot/double";
279     if ( strcmp(token, "bool"          ) == 0 )  helpfile = "cbot/bool";
280     if ( strcmp(token, "string"        ) == 0 )  helpfile = "cbot/string";
281     if ( strcmp(token, "point"         ) == 0 )  helpfile = "cbot/point";
282     if ( strcmp(token, "object"        ) == 0 )  helpfile = "cbot/object";
283     if ( strcmp(token, "file"          ) == 0 )  helpfile = "cbot/file";
284     if ( strcmp(token, "void"          ) == 0 )  helpfile = "cbot/void";
285     if ( strcmp(token, "null"          ) == 0 )  helpfile = "cbot/null";
286     if ( strcmp(token, "nan"           ) == 0 )  helpfile = "cbot/nan";
287     if ( strcmp(token, "true"          ) == 0 )  helpfile = "cbot/true";
288     if ( strcmp(token, "false"         ) == 0 )  helpfile = "cbot/false";
289     if ( strcmp(token, "sin"           ) == 0 )  helpfile = "cbot/sin";
290     if ( strcmp(token, "cos"           ) == 0 )  helpfile = "cbot/cos";
291     if ( strcmp(token, "tan"           ) == 0 )  helpfile = "cbot/tan";
292     if ( strcmp(token, "asin"          ) == 0 )  helpfile = "cbot/asin";
293     if ( strcmp(token, "acos"          ) == 0 )  helpfile = "cbot/acos";
294     if ( strcmp(token, "atan"          ) == 0 )  helpfile = "cbot/atan";
295     if ( strcmp(token, "atan2"         ) == 0 )  helpfile = "cbot/atan2";
296     if ( strcmp(token, "sqrt"          ) == 0 )  helpfile = "cbot/sqrt";
297     if ( strcmp(token, "pow"           ) == 0 )  helpfile = "cbot/pow";
298     if ( strcmp(token, "rand"          ) == 0 )  helpfile = "cbot/rand";
299     if ( strcmp(token, "abs"           ) == 0 )  helpfile = "cbot/abs";
300     if ( strcmp(token, "floor"         ) == 0 )  helpfile = "cbot/floor";
301     if ( strcmp(token, "ceil"          ) == 0 )  helpfile = "cbot/ceil";
302     if ( strcmp(token, "round"         ) == 0 )  helpfile = "cbot/round";
303     if ( strcmp(token, "trunc"         ) == 0 )  helpfile = "cbot/trunc";
304     if ( strcmp(token, "retobject"     ) == 0 )  helpfile = "cbot/retobj";
305     if ( strcmp(token, "errmode"       ) == 0 )  helpfile = "cbot/errmode";
306     if ( strcmp(token, "isbusy"          ) == 0 )  helpfile = "cbot/isbusy";
307     if ( strcmp(token, "takeoff"       ) == 0 )  helpfile = "cbot/takeoff";
308     if ( strcmp(token, "research"      ) == 0 )  helpfile = "cbot/research";
309     if ( strcmp(token, "factory"       ) == 0 )  helpfile = "cbot/factory";
310     if ( strcmp(token, "destroy"       ) == 0 )  helpfile = "cbot/destroy";
311     if ( strcmp(token, "search"        ) == 0 )  helpfile = "cbot/search";
312     if ( strcmp(token, "searchall"     ) == 0 )  helpfile = "cbot/searchall";
313     if ( strcmp(token, "radar"         ) == 0 )  helpfile = "cbot/radar";
314     if ( strcmp(token, "radarall"      ) == 0 )  helpfile = "cbot/radarall";
315     if ( strcmp(token, "direction"     ) == 0 )  helpfile = "cbot/direct";
316     if ( strcmp(token, "distance"      ) == 0 )  helpfile = "cbot/dist";
317     if ( strcmp(token, "distance2d"    ) == 0 )  helpfile = "cbot/dist2d";
318     if ( strcmp(token, "space"         ) == 0 )  helpfile = "cbot/space";
319     if ( strcmp(token, "flatspace"     ) == 0 )  helpfile = "cbot/flatspace";
320     if ( strcmp(token, "flatground"    ) == 0 )  helpfile = "cbot/flatgrnd";
321     if ( strcmp(token, "canbuild"       ) == 0 )  helpfile = "cbot/canbuild";
322     if ( strcmp(token, "canresearch"    ) == 0 )  helpfile = "cbot/canresearch";
323     if ( strcmp(token, "researched"     ) == 0 )  helpfile = "cbot/researched";
324     if ( strcmp(token, "buildingenabled") == 0 )  helpfile = "cbot/buildingenabled";
325     if ( strcmp(token, "build"         ) == 0 )  helpfile = "cbot/build";
326     if ( strcmp(token, "flag"          ) == 0 )  helpfile = "cbot/flag";
327     if ( strcmp(token, "deflag"        ) == 0 )  helpfile = "cbot/deflag";
328     if ( strcmp(token, "wait"          ) == 0 )  helpfile = "cbot/wait";
329     if ( strcmp(token, "move"          ) == 0 )  helpfile = "cbot/move";
330     if ( strcmp(token, "turn"          ) == 0 )  helpfile = "cbot/turn";
331     if ( strcmp(token, "goto"          ) == 0 )  helpfile = "cbot/goto";
332     if ( strcmp(token, "grab"          ) == 0 )  helpfile = "cbot/grab";
333     if ( strcmp(token, "drop"          ) == 0 )  helpfile = "cbot/drop";
334     if ( strcmp(token, "sniff"         ) == 0 )  helpfile = "cbot/sniff";
335     if ( strcmp(token, "receive"       ) == 0 )  helpfile = "cbot/receive";
336     if ( strcmp(token, "send"          ) == 0 )  helpfile = "cbot/send";
337     if ( strcmp(token, "deleteinfo"    ) == 0 )  helpfile = "cbot/delinfo";
338     if ( strcmp(token, "testinfo"      ) == 0 )  helpfile = "cbot/testinfo";
339     if ( strcmp(token, "thump"         ) == 0 )  helpfile = "cbot/thump";
340     if ( strcmp(token, "recycle"       ) == 0 )  helpfile = "cbot/recycle";
341     if ( strcmp(token, "shield"        ) == 0 )  helpfile = "cbot/shield";
342     if ( strcmp(token, "fire"          ) == 0 )  helpfile = "cbot/fire";
343     if ( strcmp(token, "antfire"       ) == 0 )  helpfile = "cbot/antfire";
344     if ( strcmp(token, "aim"           ) == 0 )  helpfile = "cbot/aim";
345     if ( strcmp(token, "motor"         ) == 0 )  helpfile = "cbot/motor";
346     if ( strcmp(token, "jet"           ) == 0 )  helpfile = "cbot/jet";
347     if ( strcmp(token, "topo"          ) == 0 )  helpfile = "cbot/topo";
348     if ( strcmp(token, "message"       ) == 0 )  helpfile = "cbot/message";
349     if ( strcmp(token, "abstime"       ) == 0 )  helpfile = "cbot/abstime";
350     if ( strcmp(token, "Blue"          ) == 0 )  helpfile = "cbot/flag";
351     if ( strcmp(token, "Red"           ) == 0 )  helpfile = "cbot/flag";
352     if ( strcmp(token, "Green"         ) == 0 )  helpfile = "cbot/flag";
353     if ( strcmp(token, "Yellow"        ) == 0 )  helpfile = "cbot/flag";
354     if ( strcmp(token, "Violet"        ) == 0 )  helpfile = "cbot/flag";
355     if ( strcmp(token, "BlackArrow"    ) == 0 )  helpfile = "cbot/pendown";
356     if ( strcmp(token, "RedArrow"      ) == 0 )  helpfile = "cbot/pendown";
357     if ( strcmp(token, "White"         ) == 0 )  helpfile = "cbot/pendown";
358     if ( strcmp(token, "Black"         ) == 0 )  helpfile = "cbot/pendown";
359     if ( strcmp(token, "Gray"          ) == 0 )  helpfile = "cbot/pendown";
360     if ( strcmp(token, "LightGray"     ) == 0 )  helpfile = "cbot/pendown";
361     if ( strcmp(token, "Pink"          ) == 0 )  helpfile = "cbot/pendown";
362     if ( strcmp(token, "Purple"        ) == 0 )  helpfile = "cbot/pendown";
363     if ( strcmp(token, "Orange"        ) == 0 )  helpfile = "cbot/pendown";
364     if ( strcmp(token, "Beige"         ) == 0 )  helpfile = "cbot/pendown";
365     if ( strcmp(token, "Brown"         ) == 0 )  helpfile = "cbot/pendown";
366     if ( strcmp(token, "Skin"          ) == 0 )  helpfile = "cbot/pendown";
367     if ( strcmp(token, "LightGreen"    ) == 0 )  helpfile = "cbot/pendown";
368     if ( strcmp(token, "LightBlue"     ) == 0 )  helpfile = "cbot/pendown";
369     if ( strcmp(token, "InFront"       ) == 0 )  helpfile = "cbot/grab";
370     if ( strcmp(token, "Behind"        ) == 0 )  helpfile = "cbot/grab";
371     if ( strcmp(token, "EnergyCell"    ) == 0 )  helpfile = "cbot/grab";
372     if ( strcmp(token, "DisplayError"  ) == 0 )  helpfile = "cbot/message";
373     if ( strcmp(token, "DisplayWarning") == 0 )  helpfile = "cbot/message";
374     if ( strcmp(token, "DisplayInfo"   ) == 0 )  helpfile = "cbot/message";
375     if ( strcmp(token, "DisplayMessage") == 0 )  helpfile = "cbot/message";
376     if ( strcmp(token, "ResearchTracked"       ) == 0 )  helpfile = "cbot/researches";
377     if ( strcmp(token, "ResearchWinged"        ) == 0 )  helpfile = "cbot/researches";
378     if ( strcmp(token, "ResearchShooter"       ) == 0 )  helpfile = "cbot/researches";
379     if ( strcmp(token, "ResearchDefenseTower"  ) == 0 )  helpfile = "cbot/researches";
380     if ( strcmp(token, "ResearchNuclearPlant"  ) == 0 )  helpfile = "cbot/researches";
381     if ( strcmp(token, "ResearchThumper"       ) == 0 )  helpfile = "cbot/researches";
382     if ( strcmp(token, "ResearchShielder"      ) == 0 )  helpfile = "cbot/researches";
383     if ( strcmp(token, "ResearchPhazerShooter" ) == 0 )  helpfile = "cbot/researches";
384     if ( strcmp(token, "ResearchLegged"        ) == 0 )  helpfile = "cbot/researches";
385     if ( strcmp(token, "ResearchOrgaShooter"   ) == 0 )  helpfile = "cbot/researches";
386     if ( strcmp(token, "ResearchRecycler"      ) == 0 )  helpfile = "cbot/researches";
387     if ( strcmp(token, "ResearchSubber"        ) == 0 )  helpfile = "cbot/researches";
388     if ( strcmp(token, "ResearchSniffer"       ) == 0 )  helpfile = "cbot/researches";
389     if ( strcmp(token, "strlen"        ) == 0 )  helpfile = "cbot/string";
390     if ( strcmp(token, "strleft"       ) == 0 )  helpfile = "cbot/string";
391     if ( strcmp(token, "strright"      ) == 0 )  helpfile = "cbot/string";
392     if ( strcmp(token, "strmid"        ) == 0 )  helpfile = "cbot/string";
393     if ( strcmp(token, "strval"        ) == 0 )  helpfile = "cbot/string";
394     if ( strcmp(token, "strfind"       ) == 0 )  helpfile = "cbot/string";
395     if ( strcmp(token, "strlower"      ) == 0 )  helpfile = "cbot/string";
396     if ( strcmp(token, "strupper"      ) == 0 )  helpfile = "cbot/string";
397     if ( strcmp(token, "open"          ) == 0 )  helpfile = "cbot/open";
398     if ( strcmp(token, "close"         ) == 0 )  helpfile = "cbot/close";
399     if ( strcmp(token, "writeln"       ) == 0 )  helpfile = "cbot/writeln";
400     if ( strcmp(token, "readln"        ) == 0 )  helpfile = "cbot/readln";
401     if ( strcmp(token, "eof"           ) == 0 )  helpfile = "cbot/eof";
402     if ( strcmp(token, "deletefile"    ) == 0 )  helpfile = "cbot/deletef";
403     if ( strcmp(token, "openfile"      ) == 0 )  helpfile = "cbot/openfile";
404     if ( strcmp(token, "pendown"       ) == 0 )  helpfile = "cbot/pendown";
405     if ( strcmp(token, "penup"         ) == 0 )  helpfile = "cbot/penup";
406     if ( strcmp(token, "pencolor"      ) == 0 )  helpfile = "cbot/pencolor";
407     if ( strcmp(token, "penwidth"      ) == 0 )  helpfile = "cbot/penwidth";
408     if ( strcmp(token, "extern"        ) == 0 )  helpfile = "cbot/extern";
409     if ( strcmp(token, "class"         ) == 0 )  helpfile = "cbot/class";
410     if ( strcmp(token, "static"        ) == 0 )  helpfile = "cbot/static";
411     if ( strcmp(token, "public"        ) == 0 )  helpfile = "cbot/public";
412     if ( strcmp(token, "private"       ) == 0 )  helpfile = "cbot/private";
413     if ( strcmp(token, "synchronized"  ) == 0 )  helpfile = "cbot/synchro";
414     if ( strcmp(token, "new"           ) == 0 )  helpfile = "cbot/new";
415     if ( strcmp(token, "this"          ) == 0 )  helpfile = "cbot/this";
416     if ( strcmp(token, "switch"        ) == 0 ||
417          strcmp(token, "case"          ) == 0 ||
418          strcmp(token, "default"       ) == 0 )  helpfile = "cbot/switch";
419 
420     if (helpfile.empty())
421         return "";
422 
423     return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + helpfile + ".txt";
424 }
425 
426 
427 // Test if a keyword is a type of variable.
428 
IsType(const char * token)429 bool IsType(const char *token)
430 {
431     if ( strcmp(token, "void"   ) == 0 )  return true;
432     if ( strcmp(token, "byte"   ) == 0 )  return true;
433     if ( strcmp(token, "short"  ) == 0 )  return true;
434     if ( strcmp(token, "char"   ) == 0 )  return true;
435     if ( strcmp(token, "int"    ) == 0 )  return true;
436     if ( strcmp(token, "long"   ) == 0 )  return true;
437     if ( strcmp(token, "float"  ) == 0 )  return true;
438     if ( strcmp(token, "double" ) == 0 )  return true;
439     if ( strcmp(token, "bool"   ) == 0 )  return true;
440     if ( strcmp(token, "string" ) == 0 )  return true;
441     if ( strcmp(token, "point"  ) == 0 )  return true;
442     if ( strcmp(token, "object" ) == 0 )  return true;
443     if ( strcmp(token, "file"   ) == 0 )  return true;
444     return false;
445 }
446 
447 // Test if a keyword is a function.
448 
IsFunction(const char * token)449 bool IsFunction(const char *token)
450 {
451     if ( strcmp(token, "sin"          ) == 0 )  return true;
452     if ( strcmp(token, "cos"          ) == 0 )  return true;
453     if ( strcmp(token, "tan"          ) == 0 )  return true;
454     if ( strcmp(token, "asin"         ) == 0 )  return true;
455     if ( strcmp(token, "acos"         ) == 0 )  return true;
456     if ( strcmp(token, "atan"         ) == 0 )  return true;
457     if ( strcmp(token, "atan2"        ) == 0 )  return true;
458     if ( strcmp(token, "sqrt"         ) == 0 )  return true;
459     if ( strcmp(token, "pow"          ) == 0 )  return true;
460     if ( strcmp(token, "rand"         ) == 0 )  return true;
461     if ( strcmp(token, "abs"          ) == 0 )  return true;
462     if ( strcmp(token, "floor"        ) == 0 )  return true;
463     if ( strcmp(token, "ceil"         ) == 0 )  return true;
464     if ( strcmp(token, "round"        ) == 0 )  return true;
465     if ( strcmp(token, "trunc"        ) == 0 )  return true;
466     if ( strcmp(token, "retobjectbyid") == 0 )  return true;
467     if ( strcmp(token, "retobject"    ) == 0 )  return true;
468     if ( strcmp(token, "isbusy"         ) == 0 )  return true;
469     if ( strcmp(token, "factory"      ) == 0 )  return true;
470     if ( strcmp(token, "research"     ) == 0 )  return true;
471     if ( strcmp(token, "takeoff"      ) == 0 )  return true;
472     if ( strcmp(token, "destroy"      ) == 0 )  return true;
473     if ( strcmp(token, "search"       ) == 0 )  return true;
474     if ( strcmp(token, "searchall"    ) == 0 )  return true;
475     if ( strcmp(token, "radar"        ) == 0 )  return true;
476     if ( strcmp(token, "radarall"     ) == 0 )  return true;
477     if ( strcmp(token, "detect"       ) == 0 )  return true;
478     if ( strcmp(token, "direction"    ) == 0 )  return true;
479     if ( strcmp(token, "distance"     ) == 0 )  return true;
480     if ( strcmp(token, "distance2d"   ) == 0 )  return true;
481     if ( strcmp(token, "space"        ) == 0 )  return true;
482     if ( strcmp(token, "flatspace"    ) == 0 )  return true;
483     if ( strcmp(token, "flatground"   ) == 0 )  return true;
484     if ( strcmp(token, "canbuild"       ) == 0 )  return true;
485     if ( strcmp(token, "canresearch"    ) == 0 )  return true;
486     if ( strcmp(token, "researched"     ) == 0 )  return true;
487     if ( strcmp(token, "buildingenabled") == 0 )  return true;
488     if ( strcmp(token, "build"        ) == 0 )  return true;
489     if ( strcmp(token, "flag"         ) == 0 )  return true;
490     if ( strcmp(token, "deflag"       ) == 0 )  return true;
491     if ( strcmp(token, "wait"         ) == 0 )  return true;
492     if ( strcmp(token, "move"         ) == 0 )  return true;
493     if ( strcmp(token, "turn"         ) == 0 )  return true;
494     if ( strcmp(token, "goto"         ) == 0 )  return true;
495     if ( strcmp(token, "grab"         ) == 0 )  return true;
496     if ( strcmp(token, "drop"         ) == 0 )  return true;
497     if ( strcmp(token, "sniff"        ) == 0 )  return true;
498     if ( strcmp(token, "receive"      ) == 0 )  return true;
499     if ( strcmp(token, "send"         ) == 0 )  return true;
500     if ( strcmp(token, "deleteinfo"   ) == 0 )  return true;
501     if ( strcmp(token, "testinfo"     ) == 0 )  return true;
502     if ( strcmp(token, "thump"        ) == 0 )  return true;
503     if ( strcmp(token, "recycle"      ) == 0 )  return true;
504     if ( strcmp(token, "shield"       ) == 0 )  return true;
505     if ( strcmp(token, "fire"         ) == 0 )  return true;
506     if ( strcmp(token, "antfire"      ) == 0 )  return true;
507     if ( strcmp(token, "aim"          ) == 0 )  return true;
508     if ( strcmp(token, "motor"        ) == 0 )  return true;
509     if ( strcmp(token, "jet"          ) == 0 )  return true;
510     if ( strcmp(token, "topo"         ) == 0 )  return true;
511     if ( strcmp(token, "message"      ) == 0 )  return true;
512     if ( strcmp(token, "abstime"      ) == 0 )  return true;
513     if ( strcmp(token, "ismovie"      ) == 0 )  return true;
514     if ( strcmp(token, "errmode"      ) == 0 )  return true;
515     if ( strcmp(token, "ipf"          ) == 0 )  return true;
516     if ( strcmp(token, "strlen"       ) == 0 )  return true;
517     if ( strcmp(token, "strleft"      ) == 0 )  return true;
518     if ( strcmp(token, "strright"     ) == 0 )  return true;
519     if ( strcmp(token, "strmid"       ) == 0 )  return true;
520     if ( strcmp(token, "strval"       ) == 0 )  return true;
521     if ( strcmp(token, "strfind"      ) == 0 )  return true;
522     if ( strcmp(token, "strlower"     ) == 0 )  return true;
523     if ( strcmp(token, "strupper"     ) == 0 )  return true;
524     if ( strcmp(token, "open"         ) == 0 )  return true;
525     if ( strcmp(token, "close"        ) == 0 )  return true;
526     if ( strcmp(token, "writeln"      ) == 0 )  return true;
527     if ( strcmp(token, "readln"       ) == 0 )  return true;
528     if ( strcmp(token, "eof"          ) == 0 )  return true;
529     if ( strcmp(token, "deletefile"   ) == 0 )  return true;
530     if ( strcmp(token, "openfile"     ) == 0 )  return true;
531     if ( strcmp(token, "pendown"      ) == 0 )  return true;
532     if ( strcmp(token, "penup"        ) == 0 )  return true;
533     if ( strcmp(token, "pencolor"     ) == 0 )  return true;
534     if ( strcmp(token, "penwidth"     ) == 0 )  return true;
535     if ( strcmp(token, "camerafocus"  ) == 0 )  return true;
536     if ( strcmp(token, "sizeof"       ) == 0 )  return true;
537     return false;
538 }
539 
540 
541 // Returns using a compact instruction.
542 
GetHelpText(const char * token)543 const char* GetHelpText(const char *token)
544 {
545     if ( strcmp(token, "if"        ) == 0 )  return "if ( condition ) { code }";
546     if ( strcmp(token, "else"      ) == 0 )  return "else { code }";
547     if ( strcmp(token, "repeat"    ) == 0 )  return "repeat ( number )";
548     if ( strcmp(token, "for"       ) == 0 )  return "for ( before ; condition ; end )";
549     if ( strcmp(token, "while"     ) == 0 )  return "while ( condition ) { code }";
550     if ( strcmp(token, "do"        ) == 0 )  return "do { code } while ( condition );";
551     if ( strcmp(token, "switch"    ) == 0 )  return "switch ( value ) { code }";
552     if ( strcmp(token, "case"      ) == 0 )  return "case label: { code }";
553     if ( strcmp(token, "default"   ) == 0 )  return "default: { code } ";
554     if ( strcmp(token, "break"     ) == 0 )  return "break;";
555     if ( strcmp(token, "continue"  ) == 0 )  return "continue;";
556     if ( strcmp(token, "return"    ) == 0 )  return "return;";
557     if ( strcmp(token, "sizeof"    ) == 0 )  return "sizeof( array );";
558     if ( strcmp(token, "int"       ) == 0 )  return "int";
559     if ( strcmp(token, "sin"       ) == 0 )  return "sin ( angle );";
560     if ( strcmp(token, "cos"       ) == 0 )  return "cos ( angle );";
561     if ( strcmp(token, "tan"       ) == 0 )  return "tan ( angle );";
562     if ( strcmp(token, "asin"      ) == 0 )  return "asin ( value );";
563     if ( strcmp(token, "acos"      ) == 0 )  return "acos ( value );";
564     if ( strcmp(token, "atan"      ) == 0 )  return "atan ( value );";
565     if ( strcmp(token, "atan2"     ) == 0 )  return "atan2 ( y, x );";
566     if ( strcmp(token, "sqrt"      ) == 0 )  return "sqrt ( value );";
567     if ( strcmp(token, "pow"       ) == 0 )  return "pow ( x, y );";
568     if ( strcmp(token, "rand"      ) == 0 )  return "rand ( );";
569     if ( strcmp(token, "abs"       ) == 0 )  return "abs ( value );";
570     if ( strcmp(token, "floor"     ) == 0 )  return "floor ( value );";
571     if ( strcmp(token, "ceil"      ) == 0 )  return "ceil ( value );";
572     if ( strcmp(token, "round"     ) == 0 )  return "round ( value );";
573     if ( strcmp(token, "trunc"     ) == 0 )  return "trunc ( value );";
574     if ( strcmp(token, "retobject"    ) == 0 )  return "retobject ( rank );";
575     if ( strcmp(token, "retobjectbyid") == 0 )  return "retobjectbyid ( rank );";
576     if ( strcmp(token, "progfunc"  ) == 0 )  return "progfunc ( funcname );";
577     if ( strcmp(token, "isbusy"      ) == 0 )  return "isbusy ( object );";
578     if ( strcmp(token, "factory"   ) == 0 )  return "factory ( cat, program, object );";
579     if ( strcmp(token, "research"  ) == 0 )  return "research ( type, object );";
580     if ( strcmp(token, "takeoff"   ) == 0 )  return "takeoff ( object );";
581     if ( strcmp(token, "destroy"   ) == 0 )  return "destroy ( object );";
582     if ( strcmp(token, "search"    ) == 0 )  return "search ( cat, pos, min, max, sens, filter );";
583     if ( strcmp(token, "searchall" ) == 0 )  return "searchall ( cat, pos, min, max, sens, filter );";
584     if ( strcmp(token, "radar"     ) == 0 )  return "radar ( cat, angle, focus, min, max, sens, filter );";
585     if ( strcmp(token, "radarall"  ) == 0 )  return "radarall ( cat, angle, focus, min, max, sens, filter );";
586     if ( strcmp(token, "detect"    ) == 0 )  return "detect ( cat );";
587     if ( strcmp(token, "direction" ) == 0 )  return "direction ( position );";
588     if ( strcmp(token, "distance2d") == 0 )  return "distance2d ( p1, p2 );";
589     if ( strcmp(token, "distance"  ) == 0 )  return "distance ( p1, p2 );";
590     if ( strcmp(token, "flatspace" ) == 0 )  return "flatspace ( center, flatmin, rmin, rmax, dist );";
591     if ( strcmp(token, "space"     ) == 0 )  return "space ( center, rmin, rmax, dist );";
592     if ( strcmp(token, "flatground") == 0 )  return "flatground ( center, rmax );";
593     if ( strcmp(token, "canbuild"       ) == 0 )  return "canbuild ( category );";
594     if ( strcmp(token, "canresearch"    ) == 0 )  return "canresearch ( research );";
595     if ( strcmp(token, "researched"     ) == 0 )  return "researched ( research );";
596     if ( strcmp(token, "buildingenabled") == 0 )  return "buildingenabled ( category );";
597     if ( strcmp(token, "build"     ) == 0 )  return "build ( category );";
598     if ( strcmp(token, "flag"      ) == 0 )  return "flag ( color );";
599     if ( strcmp(token, "deflag"    ) == 0 )  return "deflag ( );";
600     if ( strcmp(token, "wait"      ) == 0 )  return "wait ( time );";
601     if ( strcmp(token, "move"      ) == 0 )  return "move ( distance );";
602     if ( strcmp(token, "turn"      ) == 0 )  return "turn ( angle );";
603     if ( strcmp(token, "goto"      ) == 0 )  return "goto ( position, altitude );";
604     if ( strcmp(token, "grab"      ) == 0 )  return "grab ( order );";
605     if ( strcmp(token, "drop"      ) == 0 )  return "drop ( order );";
606     if ( strcmp(token, "sniff"     ) == 0 )  return "sniff ( );";
607     if ( strcmp(token, "receive"   ) == 0 )  return "receive ( name, power );";
608     if ( strcmp(token, "send"      ) == 0 )  return "send ( name, value, power );";
609     if ( strcmp(token, "deleteinfo") == 0 )  return "deleteinfo ( name, power );";
610     if ( strcmp(token, "testinfo"  ) == 0 )  return "testinfo ( name, power );";
611     if ( strcmp(token, "thump"     ) == 0 )  return "thump ( );";
612     if ( strcmp(token, "recycle"   ) == 0 )  return "recycle ( );";
613     if ( strcmp(token, "shield"    ) == 0 )  return "shield ( oper, radius );";
614     if ( strcmp(token, "fire"      ) == 0 )  return "fire ( time );";
615     if ( strcmp(token, "aim"       ) == 0 )  return "aim ( y, x );";
616     if ( strcmp(token, "motor"     ) == 0 )  return "motor ( left, right );";
617     if ( strcmp(token, "jet"       ) == 0 )  return "jet ( power );";
618     if ( strcmp(token, "topo"      ) == 0 )  return "topo ( position );";
619     if ( strcmp(token, "message"   ) == 0 )  return "message ( string, type );";
620     if ( strcmp(token, "abstime"   ) == 0 )  return "abstime ( );";
621     if ( strcmp(token, "ismovie"   ) == 0 )  return "ismovie ( );";
622     if ( strcmp(token, "errmode"   ) == 0 )  return "errmode ( mode );";
623     if ( strcmp(token, "ipf"       ) == 0 )  return "ipf ( number );";
624     if ( strcmp(token, "strlen"    ) == 0 )  return "strlen ( string );";
625     if ( strcmp(token, "strleft"   ) == 0 )  return "strleft ( string, len );";
626     if ( strcmp(token, "strright"  ) == 0 )  return "strright ( string, len );";
627     if ( strcmp(token, "strmid"    ) == 0 )  return "strmid ( string, pos, len );";
628     if ( strcmp(token, "strval"    ) == 0 )  return "strval ( string );";
629     if ( strcmp(token, "strfind"   ) == 0 )  return "strfind ( string, substring );";
630     if ( strcmp(token, "strlower"  ) == 0 )  return "strlower ( string );";
631     if ( strcmp(token, "strupper"  ) == 0 )  return "strupper ( string );";
632     if ( strcmp(token, "open"      ) == 0 )  return "file.open ( filename, mode );";
633     if ( strcmp(token, "close"     ) == 0 )  return "file.close ( );";
634     if ( strcmp(token, "writeln"   ) == 0 )  return "file.writeln ( string );";
635     if ( strcmp(token, "readln"    ) == 0 )  return "file.readln ( );";
636     if ( strcmp(token, "eof"       ) == 0 )  return "eof ( );";
637     if ( strcmp(token, "deletefile") == 0 )  return "deletefile ( filename );";
638     if ( strcmp(token, "openfile"  ) == 0 )  return "openfile ( filename, mode );";
639     if ( strcmp(token, "pendown"   ) == 0 )  return "pendown ( color, width );";
640     if ( strcmp(token, "penup"     ) == 0 )  return "penup ( );";
641     if ( strcmp(token, "pencolor"  ) == 0 )  return "pencolor ( color );";
642     if ( strcmp(token, "penwidth"  ) == 0 )  return "penwidth ( width );";
643     if ( strcmp(token, "camerafocus") == 0 )  return "camerafocus ( object );";
644     return "";
645 }
646