UserScriptsDlg.cpp 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // UserScriptsDlg.cpp: Implementierungsdatei
  17. //
  18. #include "stdafx.h"
  19. #include "finalsun.h"
  20. #include "UserScriptsDlg.h"
  21. #include <io.h>
  22. #include <fcntl.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include "variables.h"
  26. #include "functions.h"
  27. #include "inlines.h"
  28. #include "combouinputdlg.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. using namespace std;
  35. struct FunctionData
  36. {
  37. CString* name;
  38. CString* param;
  39. public:
  40. void Init();
  41. FunctionData();
  42. int paramcount;
  43. void AddParam();
  44. ~FunctionData();
  45. };
  46. struct JumpLineData
  47. {
  48. CString name;
  49. int line;
  50. };
  51. class CUserScript
  52. {
  53. public:
  54. void RaiseErr(int n, const char* str);
  55. char errortext[250];
  56. int error;
  57. int functioncount;
  58. int GetFunction(int index, CString* name, CString *params[], int* paramcount);
  59. int FindJumpLine(CString name);
  60. int LoadFile(const char* filename);
  61. CUserScript();
  62. virtual ~CUserScript();
  63. private:
  64. int AllocateFunction();
  65. FunctionData* functiondata;
  66. map<CString, int> jumplinedata;
  67. CString filename;
  68. };
  69. CUserScript::CUserScript()
  70. {
  71. functioncount=0;
  72. functiondata=NULL;
  73. }
  74. CUserScript::~CUserScript()
  75. {
  76. if(functiondata!=NULL) free( functiondata);
  77. }
  78. int CUserScript::FindJumpLine(CString name)
  79. {
  80. if(jumplinedata.find(name)==jumplinedata.end()) return -1;
  81. return jumplinedata[name];
  82. }
  83. int CUserScript::LoadFile(const char *setupfile)
  84. {
  85. filename=setupfile;
  86. int file=_open(setupfile, _O_RDONLY);
  87. if(file==-1)
  88. {
  89. MessageBox(0, "Error opening script file", "Error", MB_ICONERROR);
  90. return -1;
  91. }
  92. int parsepos=0, filesize=0;
  93. BOOL inFunction=FALSE;
  94. BOOL inParam=FALSE;
  95. BOOL inComment=FALSE;
  96. BOOL inFunctionHead=FALSE;
  97. BOOL inNewOrder=TRUE;
  98. BOOL inJumpLine=FALSE;
  99. while(!(_eof(file)))
  100. {
  101. unsigned char c;
  102. int res=_read(file,(void*) &c, 1);
  103. if(res>0) filesize++;
  104. }
  105. _lseek(file, 0, SEEK_SET);
  106. unsigned char *data=new(unsigned char[filesize+5]);
  107. data[filesize]=0;
  108. for (parsepos=0;parsepos<filesize;parsepos++)
  109. {
  110. _read(file, data+parsepos, 1);
  111. }
  112. _close(file);
  113. //MessageBox(0,(char*)data,"DEBUG: SETUPSCRIPT:/",0);
  114. BYTE jumplinename[512];
  115. memset(jumplinename, 512, 0);
  116. //// MAIN STUFF HERE ////
  117. for(parsepos=0;parsepos<filesize;parsepos++)
  118. {
  119. if(inComment==TRUE || inNewOrder==FALSE)
  120. {
  121. if(data[parsepos]=='\n')
  122. {
  123. //MessageBox(0, "NEWLINE", (char*)&data[parsepos+1], 0);
  124. inNewOrder=TRUE;
  125. inComment=FALSE;
  126. inJumpLine=FALSE;
  127. memset(jumplinename, 0, 512);
  128. }
  129. }
  130. else if(inFunction==FALSE && inComment==FALSE && inFunctionHead==FALSE && inJumpLine==FALSE)
  131. {
  132. // easy here, just seek for new position
  133. if(data[parsepos]=='/' && data[parsepos+1]=='/')
  134. {
  135. inComment=TRUE;
  136. }
  137. else if(data[parsepos]==';')
  138. {
  139. inNewOrder=TRUE;
  140. }
  141. else if(data[parsepos]==':')
  142. {
  143. inJumpLine=TRUE;
  144. }
  145. else if(IsCharAlphaNumeric(data[parsepos])!=0 && inNewOrder==TRUE && inJumpLine==FALSE)
  146. {
  147. inFunction=TRUE;
  148. int pos=AllocateFunction();
  149. //*functiondata[pos-1].name.append(data[parsepos]);
  150. *functiondata[pos-1].name = (char)data[parsepos];
  151. }
  152. }
  153. else if(data[parsepos]=='(' && inComment==FALSE && inParam==FALSE)
  154. {
  155. //MessageBox(0, "InHead","",0);
  156. inFunctionHead=TRUE;
  157. }
  158. else if(inFunctionHead==TRUE && inParam==TRUE)
  159. {
  160. if(data[parsepos]=='\\')
  161. {
  162. if(data[parsepos+1]=='n' || data[parsepos+1]=='N')
  163. {
  164. data[parsepos]='\n';
  165. functiondata[functioncount-1].param[functiondata[functioncount-1].paramcount-1]+=data[parsepos];
  166. parsepos++;
  167. }
  168. if(data[parsepos+1]=='r' || data[parsepos+1]=='R')
  169. {
  170. data[parsepos]='\r';
  171. functiondata[functioncount-1].param[functiondata[functioncount-1].paramcount-1]+=data[parsepos];
  172. parsepos++;
  173. }
  174. }
  175. else if(data[parsepos]=='"' && data[parsepos+1]!='"')
  176. {
  177. inParam=FALSE;
  178. //MessageBox(0, functiondata[functioncount-1].param[functiondata[functioncount-1].paramcount-1].data(), functiondata[functioncount-1].name->data(), 0);
  179. }
  180. else
  181. {
  182. // add character to param
  183. functiondata[functioncount-1].param[functiondata[functioncount-1].paramcount-1]+=data[parsepos];
  184. if(data[parsepos]=='"' && data[parsepos+1]=='"') parsepos++; // ignore the next "
  185. }
  186. }
  187. else if(inFunction==TRUE && inParam==FALSE && inFunctionHead==FALSE)
  188. {
  189. if(IsCharAlphaNumeric(data[parsepos])!=0)
  190. {
  191. *functiondata[functioncount-1].name+=data[parsepos];
  192. }
  193. else
  194. {
  195. inFunction=FALSE;
  196. //MessageBox(0, functiondata[functioncount-1].name->data(), "FUNCTIONAME", 0);
  197. }
  198. }
  199. else if(inFunctionHead==TRUE && inParam==FALSE)
  200. {
  201. if(data[parsepos]=='"')
  202. {
  203. // add a param!
  204. inParam=TRUE;
  205. functiondata[functioncount-1].AddParam();
  206. functiondata[functioncount-1].param[functiondata[functioncount-1].paramcount-1]="";
  207. }
  208. if(data[parsepos]==')')
  209. {
  210. inFunctionHead=FALSE;
  211. //MessageBox(0, (char*)&data[parsepos], "", 0);
  212. }
  213. }
  214. else if(inJumpLine==TRUE)
  215. {
  216. if(data[parsepos]!=':')
  217. {
  218. char d[2];
  219. d[0]=data[parsepos];
  220. d[1]=0;
  221. strcat((char*)jumplinename, d);
  222. }
  223. else
  224. {
  225. jumplinedata[jumplinename]=functioncount;
  226. //MessageBox(0,(char*)jumplinename,"",0);
  227. memset(jumplinename, 0, 512);
  228. inJumpLine=FALSE;
  229. inNewOrder=TRUE;
  230. }
  231. }
  232. }
  233. /////////////////////////
  234. delete[] (data);
  235. return 0;
  236. }
  237. int CUserScript::GetFunction(int index, CString *name, CString * params[], int* paramcount)
  238. {
  239. if(index<0 || index>=functioncount) return -1;
  240. *name=*functiondata[index].name;
  241. *paramcount=functiondata[index].paramcount;
  242. //if(params==NULL) return 0;
  243. if (*paramcount>0)
  244. {
  245. *params=new(CString[*paramcount]);
  246. }
  247. else *params=0;
  248. int i;
  249. for(i=0;i<*paramcount;i++)
  250. {
  251. //params[i]=new(CString);
  252. CString* str=*params;
  253. str[i]=functiondata[index].param[i];
  254. //memcpy((void*)params[i], (void*) &functiondata[index].param[i], &function
  255. //MessageBox(0,functiondata[index].param[i].data(),"",0);
  256. }
  257. return 0;
  258. }
  259. void FunctionData::AddParam()
  260. {
  261. //CString* tmp=NULL;
  262. //if(paramcount>0)
  263. //{
  264. //tmp=new(CString[paramcount]);
  265. //memcpy((void*)tmp, param, sizeof(CString)*paramcount);
  266. //delete[] (functiondata); //delete is bad-> CStrings would be deallocated!
  267. //delete[](param);
  268. //param=NULL;
  269. //}
  270. //param=(CString*)realloc(param, (paramcount+1)*sizeof(CString));
  271. //param[paramcount]=CString();
  272. //CString hack;
  273. //memset(&param[paramcount], 0, sizeof(CString));
  274. //memcpy(&param[paramcount], &hack, sizeof(CString));
  275. //param[paramcount]="";
  276. //param=new(CString[paramcount+1]);
  277. //
  278. //memcpy((void*) param, (void*) tmp, sizeof(CString)*paramcount);
  279. //name="";
  280. CString* newparam=new(CString[paramcount+1]);
  281. int i;
  282. for(i=0;i<paramcount;i++)
  283. {
  284. newparam[i]=param[i];
  285. }
  286. newparam[paramcount]="";
  287. delete[] param;
  288. param=newparam;
  289. paramcount++;
  290. //delete[](tmp);
  291. }
  292. FunctionData::FunctionData()
  293. {
  294. paramcount=0;
  295. param=NULL;
  296. name=new(CString);
  297. }
  298. FunctionData::~FunctionData()
  299. {
  300. if (param!=NULL) delete[] param;
  301. paramcount=0;
  302. delete (name);
  303. }
  304. int CUserScript::AllocateFunction()
  305. {
  306. /*FunctionData* tmp=NULL;
  307. if(functioncount>0)
  308. {
  309. tmp=new(FunctionData[functioncount]);
  310. memcpy((void*)tmp, functiondata, sizeof(FunctionData)*functioncount);
  311. delete[] functiondata;
  312. functiondata=NULL;
  313. }
  314. functiondata=new(FunctionData[functioncount+1]);
  315. memcpy((void*) functiondata, (void*) tmp, sizeof(FunctionData)*functioncount);
  316. functiondata[functioncount].name="";*/
  317. functiondata=(FunctionData*)realloc(functiondata, sizeof(FunctionData)*(functioncount+1));
  318. functiondata[functioncount].Init();
  319. *functiondata[functioncount].name="HUHU";
  320. functioncount++;
  321. //delete[] (tmp);
  322. return functioncount;
  323. }
  324. void CUserScript::RaiseErr(int n, const char *str)
  325. {
  326. }
  327. void FunctionData::Init()
  328. {
  329. paramcount=0;
  330. param=NULL;
  331. name=new(CString);
  332. }
  333. /////////////////////////////////////////////////////////////////////////////
  334. // Dialogfeld CUserScriptsDlg
  335. CUserScriptsDlg::CUserScriptsDlg(CWnd* pParent /*=NULL*/)
  336. : CDialog(CUserScriptsDlg::IDD, pParent)
  337. {
  338. //{{AFX_DATA_INIT(CUserScriptsDlg)
  339. m_Script = _T("");
  340. m_Report = _T("");
  341. //}}AFX_DATA_INIT
  342. }
  343. void CUserScriptsDlg::DoDataExchange(CDataExchange* pDX)
  344. {
  345. CDialog::DoDataExchange(pDX);
  346. //{{AFX_DATA_MAP(CUserScriptsDlg)
  347. DDX_LBString(pDX, IDC_SCRIPTS, m_Script);
  348. DDX_Text(pDX, IDC_REPORT, m_Report);
  349. //}}AFX_DATA_MAP
  350. }
  351. BEGIN_MESSAGE_MAP(CUserScriptsDlg, CDialog)
  352. //{{AFX_MSG_MAP(CUserScriptsDlg)
  353. //}}AFX_MSG_MAP
  354. END_MESSAGE_MAP()
  355. /////////////////////////////////////////////////////////////////////////////
  356. // Behandlungsroutinen für Nachrichten CUserScriptsDlg
  357. #define ASK_CONTINUE "AskContinue"
  358. #define ADD_TRIGGER "AddTrigger"
  359. #define MESSAGE "Message"
  360. #define SET_INI_KEY "SetIniKey"
  361. #define SET_SAFE_MODE "SetSafeMode"
  362. #define SET_VARIABLE "SetVariable"
  363. #define SET_VARIABLE_IF "SetVariableIf"
  364. #define ADD "Add"
  365. #define MULTI "Multi"
  366. #define SUBSTRACT "Substract"
  367. #define DIVIDE "Divide"
  368. #define SET_WAYPOINT "SetWaypoint"
  369. #define REQUIRES_MP "RequiresMP"
  370. #define REQUIRES_SP "RequiresSP"
  371. #define ADD_AI_TRIGGER "AddAITrigger"
  372. #define ADD_TAG "AddTag"
  373. #define RESIZE "Resize"
  374. #define IS "Is"
  375. #define CANCEL "Cancel"
  376. #define PRINT "Print"
  377. #define TOLOWER "LowerCase"
  378. #define TOUPPER "UpperCase"
  379. #define GET_FREE_WAYPOINT "GetFreeWaypoint"
  380. #define UINPUT_GET_INTEGER "UInputGetInteger"
  381. #define UINPUT_GET_STRING "UInputGetString"
  382. #define JUMP_TO_LINE "JumpTo"
  383. #define SET_AUTO_UPDATE "SetAutoUpdate"
  384. #define GET_RANDOM "GetRandom"
  385. #define ADD_TERRAIN "AddTerrain"
  386. #define GET_INI_KEY "GetIniKey"
  387. #define MODULO "Mod"
  388. #ifdef SMUDGE_SUPP
  389. #define ADD_SMUDGE "AddSmudge"
  390. #endif
  391. #define INSERT "Insert"
  392. #define LENGTH "Length"
  393. #define TRIM "Trim"
  394. #define GETCHAR "GetChar"
  395. #define REPLACE "Replace"
  396. #define REMOVE "Remove"
  397. #define GET_WAYPOINT_POS "GetWaypointPos"
  398. #define GET_PARAM "GetParam"
  399. #define SET_PARAM "SetParam"
  400. #define GET_PARAM_COUNT "GetParamCount"
  401. #define ALLOW_DELETE "AllowDelete"
  402. #define DELETE_TERRAIN "DeleteTerrain"
  403. #define DELETE_INFANTRY "DeleteInfantry"
  404. #define DELETE_AIRCRAFT "DeleteAircraft"
  405. #define DELETE_STRUCTURE "DeleteStructure"
  406. #define DELETE_VEHICLE "DeleteVehicle"
  407. #define IS_INFANTRY_DELETED "IsInfantryDeleted"
  408. #define IS_TERRAIN_DELETED "IsTerrainDeleted"
  409. #define ADD_INFANTRY "AddInfantry"
  410. #define ALLOW_ADD "AllowAdd"
  411. #define ADD_VEHICLE "AddVehicle"
  412. #define ADD_AIRCRAFT "AddAircraft"
  413. #define ADD_STRUCTURE "AddStructure"
  414. #define GET_INFANTRY "GetInfantry"
  415. #define GET_AIRCRAFT "GetAircraft"
  416. #define GET_STRUCTURE "GetStructure"
  417. #define GET_VEHICLE "GetVehicle"
  418. #define UINPUT_GET_HOUSE "UInputGetHouse"
  419. #define UINPUT_GET_COUNTRY "UInputGetCountry"
  420. #define UINPUT_GET_TRIGGER "UInputGetTrigger"
  421. #define UINPUT_GET_TAG "UInputGetTag"
  422. #define MESSAGE_YES_NO "Ask"
  423. #define GET_HOUSE "GetHouse"
  424. #define GET_COUNTRY "GetCountry"
  425. #define GET_HOUSE_INDEX "GetHouseIndex"
  426. #define OR "Or"
  427. #define AND "And"
  428. #define NOT "Not"
  429. #define UINPUT_GET_MANUAL "UInputSelect"
  430. #define ID_ASK_CONTINUE 0
  431. #define ID_ADD_TRIGGER 1
  432. #define ID_MESSAGE 2
  433. #define ID_SET_INI_KEY 3
  434. #define ID_SET_SAFE_MODE 4
  435. #define ID_SET_VARIABLE 5
  436. #define ID_SET_VARIABLE_IF 6
  437. #define ID_ADD 7
  438. #define ID_MULTI 8
  439. #define ID_SUBSTRACT 9
  440. #define ID_DIVIDE 10
  441. #define ID_SET_WAYPOINT 11
  442. #define ID_REQUIRES_MP 12
  443. #define ID_REQUIRES_SP 13
  444. #define ID_ADD_AI_TRIGGER 14
  445. #define ID_ADD_TAG 15
  446. #define ID_RESIZE 16
  447. #define ID_IS 17
  448. #define ID_CANCEL 18
  449. #define ID_PRINT 19
  450. #define ID_TOLOWER 20
  451. #define ID_TOUPPER 21
  452. #define ID_GET_FREE_WAYPOINT 22
  453. #define ID_UINPUT_GET_INTEGER 23
  454. #define ID_UINPUT_GET_STRING 24
  455. #define ID_JUMP_TO_LINE 25
  456. #define ID_SET_AUTO_UPDATE 26
  457. #define ID_GET_RANDOM 27
  458. #define ID_ADD_TERRAIN 28
  459. #define ID_GET_INI_KEY 29
  460. #define ID_MODULO 30
  461. #ifdef SMUDGE_SUPP
  462. #define ID_ADD_SMUDGE 31
  463. #endif
  464. #define ID_INSERT 32
  465. #define ID_LENGTH 33
  466. #define ID_TRIM 34
  467. #define ID_GETCHAR 35
  468. #define ID_REPLACE 36
  469. #define ID_REMOVE 37
  470. #define ID_GET_WAYPOINT_POS 38
  471. #define ID_GET_PARAM 39
  472. #define ID_SET_PARAM 40
  473. #define ID_GET_PARAM_COUNT 41
  474. #define ID_ALLOW_DELETE 42
  475. #define ID_DELETE_TERRAIN 43
  476. #define ID_DELETE_INFANTRY 44
  477. #define ID_DELETE_STRUCTURE 45
  478. #define ID_DELETE_AIRCRAFT 46
  479. #define ID_DELETE_VEHICLE 47
  480. #define ID_IS_INFANTRY_DELETED 48
  481. #define ID_IS_TERRAIN_DELETED 49
  482. #define ID_ADD_INFANTRY 50
  483. #define ID_ALLOW_ADD 51
  484. #define ID_ADD_VEHICLE 52
  485. #define ID_ADD_AIRCRAFT 53
  486. #define ID_ADD_STRUCTURE 54
  487. #define ID_GET_INFANTRY 55
  488. #define ID_GET_AIRCRAFT 56
  489. #define ID_GET_STRUCTURE 57
  490. #define ID_GET_VEHICLE 58
  491. #define ID_UINPUT_GET_HOUSE 59
  492. #define ID_UINPUT_GET_COUNTRY 60
  493. #define ID_UINPUT_GET_TRIGGER 61
  494. #define ID_UINPUT_GET_TAG 62
  495. #define ID_MESSAGE_YES_NO 63
  496. #define ID_GET_HOUSE 64
  497. #define ID_GET_COUNTRY 65
  498. #define ID_GET_HOUSE_INDEX 66
  499. #define ID_OR 67
  500. #define ID_AND 68
  501. #define ID_NOT 69
  502. #define ID_UINPUT_GET_MANUAL 70
  503. extern CString GetFree(const char* section);
  504. BOOL IsValSet(CString val)
  505. {
  506. val.MakeLower();
  507. if(val=="false" || val=="no") return FALSE; // val is not set
  508. if(val=="true" || val=="yes") return TRUE;
  509. if(atoi(val)) return TRUE;
  510. return FALSE;
  511. }
  512. int get_player_count()
  513. {
  514. if(Map->IsMultiplayer()==FALSE) return 1;
  515. int i;
  516. int wp_count=0;
  517. for(i=0;i<Map->GetWaypointCount();i++)
  518. {
  519. CString id;
  520. DWORD pos;
  521. Map->GetWaypointData(i, &id, &pos);
  522. int idi;
  523. idi=atoi(id);
  524. if(idi!=i) break;
  525. if(idi>=0 && idi<8)
  526. {
  527. wp_count++;
  528. }
  529. }
  530. return wp_count;
  531. }
  532. struct FUNC_INFO
  533. {
  534. int type;
  535. CString name;
  536. CString* params;
  537. int paramcount;
  538. };
  539. void CUserScriptsDlg::OnOK()
  540. {
  541. UpdateData(TRUE);
  542. //srand((unsigned)time(NULL));
  543. if(m_Script.GetLength()==0) return;
  544. CUserScript s;
  545. s.LoadFile((CString)AppPath+(CString)"\\Scripts\\"+m_Script);
  546. CIniFile& ini=Map->GetIniFile();
  547. BOOL bUpdate=FALSE;
  548. BOOL bUpdateOnlyMission=TRUE;
  549. BOOL bNoRepos=TRUE;
  550. BOOL bSafeMode=TRUE;
  551. map<CString, CString> variables;
  552. char c[50];
  553. CString report=m_Script+" Report:\r\n\r\n";
  554. BOOL bAutoUpdate=TRUE;
  555. BOOL bAllowLoop=TRUE; // for now we enable this, as we´ve introduced a loop counter
  556. // stuff for faster CMapData processing:
  557. BOOL bUpdateWaypoints=FALSE;
  558. BOOL bOldUpdate=Map->m_noAutoObjectUpdate;
  559. BOOL bDeleteAllowed=FALSE; // shall the script be able to delete stuff?
  560. BOOL bAddAllowed=FALSE; // " delete stuff
  561. // for delete/add stuff:
  562. int lastInfantryDeleted=-1;
  563. CString lastStructureDeleted="";
  564. int lastTerrainDeleted=-1;
  565. CString lastUnitDeleted="";
  566. CString lastAircraftDeleted="";
  567. BOOL bIgnoreLoopCounts=FALSE;
  568. int loop_count=0;
  569. map<int, FUNC_INFO> functions;
  570. // get function ids
  571. int i;
  572. for(i=0;i<s.functioncount;i++)
  573. {
  574. FUNC_INFO info;
  575. CString& name=info.name;
  576. s.GetFunction(i, &info.name, &info.params, &info.paramcount);
  577. if(name==ASK_CONTINUE)
  578. {
  579. info.type=ID_ASK_CONTINUE;
  580. }
  581. else if(name==MESSAGE)
  582. {
  583. info.type=ID_MESSAGE;
  584. }
  585. else if(name==ADD_TRIGGER)
  586. {
  587. info.type=ID_ADD_TRIGGER;
  588. }
  589. else if(name==SET_INI_KEY)
  590. {
  591. info.type=ID_SET_INI_KEY;
  592. }
  593. else if(name==SET_SAFE_MODE)
  594. {
  595. info.type=ID_SET_SAFE_MODE;
  596. }
  597. else if(name==SET_VARIABLE)
  598. {
  599. info.type=ID_SET_VARIABLE;
  600. }
  601. else if(name==ADD)
  602. {
  603. info.type=ID_ADD;
  604. }
  605. else if(name==SUBSTRACT)
  606. {
  607. info.type=ID_SUBSTRACT;
  608. }
  609. else if(name==MULTI)
  610. {
  611. info.type=ID_MULTI;
  612. }
  613. else if(name==DIVIDE)
  614. {
  615. info.type=ID_DIVIDE;
  616. }
  617. else if(name==SET_WAYPOINT)
  618. {
  619. info.type=ID_SET_WAYPOINT;
  620. }
  621. else if(name==REQUIRES_MP)
  622. {
  623. info.type=ID_REQUIRES_MP;
  624. }
  625. else if(name==REQUIRES_SP)
  626. {
  627. info.type=ID_REQUIRES_SP;
  628. }
  629. else if(name==ADD_AI_TRIGGER)
  630. {
  631. info.type=ID_ADD_AI_TRIGGER;
  632. }
  633. else if(name==ADD_TAG)
  634. {
  635. info.type=ID_ADD_TAG;
  636. }
  637. else if(name==RESIZE)
  638. {
  639. info.type=ID_RESIZE;
  640. }
  641. else if(name==IS)
  642. {
  643. info.type=ID_IS;
  644. }
  645. else if(name==CANCEL)
  646. {
  647. info.type=ID_CANCEL;
  648. }
  649. else if(name==PRINT)
  650. {
  651. info.type=ID_PRINT;
  652. }
  653. else if(name==TOLOWER)
  654. {
  655. info.type=ID_TOLOWER;
  656. }
  657. else if(name==TOUPPER)
  658. {
  659. info.type=ID_TOUPPER;
  660. }
  661. else if(name==GET_FREE_WAYPOINT)
  662. {
  663. info.type=ID_GET_FREE_WAYPOINT;
  664. }
  665. else if(name==UINPUT_GET_INTEGER)
  666. {
  667. info.type=ID_UINPUT_GET_INTEGER;
  668. }
  669. else if(name== UINPUT_GET_STRING )
  670. {
  671. info.type=ID_UINPUT_GET_STRING;
  672. }
  673. else if(name==JUMP_TO_LINE)
  674. {
  675. info.type=ID_JUMP_TO_LINE;
  676. }
  677. else if(name==SET_AUTO_UPDATE)
  678. {
  679. info.type=ID_SET_AUTO_UPDATE;
  680. }
  681. else if(name==GET_RANDOM)
  682. {
  683. info.type=ID_GET_RANDOM;
  684. }
  685. else if(name==ADD_TERRAIN)
  686. {
  687. info.type=ID_ADD_TERRAIN;
  688. }
  689. else if(name==GET_INI_KEY)
  690. {
  691. info.type=ID_GET_INI_KEY;
  692. }
  693. else if(name==MODULO)
  694. {
  695. info.type=ID_MODULO;
  696. }
  697. #ifdef SMUDGE_SUPP
  698. else if(name==ADD_SMUDGE)
  699. {
  700. info.type=ID_ADD_SMUDGE;
  701. }
  702. #endif
  703. else if(name==INSERT)
  704. {
  705. info.type=ID_INSERT;
  706. }
  707. else if(name==LENGTH)
  708. {
  709. info.type=ID_LENGTH;
  710. }
  711. else if(name==TRIM)
  712. {
  713. info.type=ID_TRIM;
  714. }
  715. else if(name==GETCHAR)
  716. {
  717. info.type=ID_GETCHAR;
  718. }
  719. else if(name==REPLACE)
  720. {
  721. info.type=ID_REPLACE;
  722. }
  723. else if(name==REMOVE)
  724. {
  725. info.type=ID_REMOVE;
  726. }
  727. else if(name==GET_WAYPOINT_POS)
  728. {
  729. info.type=ID_GET_WAYPOINT_POS;
  730. }
  731. else if(name==GET_PARAM)
  732. {
  733. info.type=ID_GET_PARAM;
  734. }
  735. else if(name==SET_PARAM)
  736. {
  737. info.type=ID_SET_PARAM;
  738. }
  739. else if(name==GET_PARAM_COUNT)
  740. {
  741. info.type=ID_GET_PARAM_COUNT;
  742. }
  743. else if(name==ALLOW_DELETE)
  744. {
  745. info.type=ID_ALLOW_DELETE;
  746. }
  747. else if(name==DELETE_TERRAIN)
  748. {
  749. info.type=ID_DELETE_TERRAIN;
  750. }
  751. else if(name==DELETE_INFANTRY)
  752. {
  753. info.type=ID_DELETE_INFANTRY;
  754. }
  755. else if(name==DELETE_STRUCTURE)
  756. {
  757. info.type=ID_DELETE_STRUCTURE;
  758. }
  759. else if(name==DELETE_AIRCRAFT)
  760. {
  761. info.type=ID_DELETE_AIRCRAFT;
  762. }
  763. else if(name==DELETE_VEHICLE)
  764. {
  765. info.type=ID_DELETE_VEHICLE;
  766. }
  767. else if(name==IS_INFANTRY_DELETED)
  768. {
  769. info.type=ID_IS_INFANTRY_DELETED;
  770. }
  771. else if(name==IS_TERRAIN_DELETED)
  772. {
  773. info.type=ID_IS_TERRAIN_DELETED;
  774. }
  775. else if(name==ADD_INFANTRY)
  776. {
  777. info.type=ID_ADD_INFANTRY;
  778. }
  779. else if(name==ALLOW_ADD)
  780. {
  781. info.type=ID_ALLOW_ADD;
  782. }
  783. else if(name==ADD_VEHICLE) info.type=ID_ADD_VEHICLE;
  784. else if(name==ADD_AIRCRAFT) info.type=ID_ADD_AIRCRAFT;
  785. else if(name==ADD_STRUCTURE) info.type=ID_ADD_STRUCTURE;
  786. else if(name==GET_INFANTRY) info.type=ID_GET_INFANTRY;
  787. else if(name==GET_AIRCRAFT) info.type=ID_GET_AIRCRAFT;
  788. else if(name==GET_STRUCTURE) info.type=ID_GET_STRUCTURE;
  789. else if(name==GET_VEHICLE) info.type=ID_GET_VEHICLE;
  790. else if(name==UINPUT_GET_HOUSE) info.type=ID_UINPUT_GET_HOUSE;
  791. else if(name==UINPUT_GET_COUNTRY) info.type=ID_UINPUT_GET_COUNTRY;
  792. else if(name==UINPUT_GET_TRIGGER) info.type=ID_UINPUT_GET_TRIGGER;
  793. else if(name==UINPUT_GET_TAG) info.type=ID_UINPUT_GET_TAG;
  794. else if(name==MESSAGE_YES_NO) info.type=ID_MESSAGE_YES_NO;
  795. else if(name==GET_HOUSE) info.type=ID_GET_HOUSE;
  796. else if(name==GET_COUNTRY) info.type=ID_GET_COUNTRY;
  797. else if(name==GET_HOUSE_INDEX) info.type=ID_GET_HOUSE_INDEX;
  798. else if(name==OR) info.type=ID_OR;
  799. else if(name==AND) info.type=ID_AND;
  800. else if(name==NOT) info.type=ID_NOT;
  801. else if(name==UINPUT_GET_MANUAL) info.type=ID_UINPUT_GET_MANUAL;
  802. else info.type=-1;
  803. functions[i]=info;
  804. }
  805. for(i=0;i<s.functioncount;i++)
  806. {
  807. // initialize global variables here so they can´t be overwritten!
  808. itoa(Map->GetWidth(), c, 10);
  809. variables["%Width%"]=c;
  810. itoa(Map->GetHeight(), c, 10);
  811. variables["%Height%"]=c;
  812. itoa(Map->GetIsoSize(), c, 10);
  813. variables["%IsoSize%"]=c;
  814. itoa(Map->GetWaypointCount(), c, 10);
  815. variables["%WaypointCount%"]=c;
  816. itoa(Map->GetUnitCount(), c, 10);
  817. variables["%UnitCount%"]=c;
  818. itoa(Map->GetInfantryCount(), c, 10);
  819. variables["%InfantryCount%"]=c;
  820. itoa(Map->GetStructureCount(), c, 10);
  821. variables["%StructureCount%"]=c;
  822. itoa(Map->GetAircraftCount(), c, 10);
  823. variables["%AircraftCount%"]=c;
  824. itoa(Map->GetTerrainCount(), c, 10);
  825. variables["%TerrainCount%"]=c;
  826. variables["%Theater%"]=Map->GetTheater();
  827. itoa(get_player_count(), c, 10);
  828. variables["%PlayerCount%"]=c;
  829. itoa(Map->GetHousesCount(FALSE), c, 10);
  830. variables["%HousesCount%"]=c;
  831. itoa(Map->GetHousesCount(TRUE), c, 10);
  832. variables["%CountriesCount%"]=c;
  833. if(bDeleteAllowed)
  834. {
  835. variables["%DeleteAllowed%"]="1";
  836. }
  837. else
  838. variables["%DeleteAllowed%"]="0";
  839. if(bAddAllowed)
  840. {
  841. variables["%AddAllowed%"]="1";
  842. }
  843. else
  844. variables["%AddAllowed%"]="0";
  845. if(bSafeMode)
  846. variables["%SafeMode%"]="1";
  847. else
  848. variables["%SafeMode%"]="0";
  849. //CString name;
  850. int name=functions[i].type;
  851. int paramcount=functions[i].paramcount;
  852. CString* params=NULL;
  853. if(paramcount)
  854. {
  855. params=new(CString[paramcount]);
  856. int e;
  857. for(e=0;e<paramcount;e++)
  858. params[e]=functions[i].params[e];
  859. }
  860. //s.GetFunction(i, &name, &params, &paramcount);
  861. BOOL * replaceVariables=new(BOOL[paramcount+4]); // make sure at least room for 4 variables
  862. int h;
  863. for(h=0;h<paramcount;h++) replaceVariables[h]=TRUE;
  864. if(name==ID_SET_VARIABLE || name==ID_ADD || name==ID_SUBSTRACT || name==ID_MULTI || name==ID_DIVIDE
  865. || name==ID_TOLOWER || name==ID_TOUPPER || name==ID_GET_FREE_WAYPOINT || name==ID_JUMP_TO_LINE
  866. || name==ID_UINPUT_GET_INTEGER || name==ID_UINPUT_GET_STRING || name==ID_GET_RANDOM || name==ID_ADD_TRIGGER
  867. || name==ID_ADD_AI_TRIGGER || name==ID_GET_INI_KEY || name==ID_MODULO || name==ID_INSERT
  868. || name==ID_LENGTH || name==ID_TRIM || name==ID_GETCHAR || name==ID_REPLACE || name==ID_REMOVE
  869. || name==ID_GET_PARAM || name==ID_SET_PARAM || name==ID_GET_PARAM_COUNT || name==ID_IS_INFANTRY_DELETED
  870. || name==ID_IS_TERRAIN_DELETED || name==ID_GET_INFANTRY || name==ID_GET_AIRCRAFT || name==ID_GET_STRUCTURE
  871. || name==ID_GET_VEHICLE || name==ID_UINPUT_GET_TRIGGER || name==ID_UINPUT_GET_TAG
  872. || name==ID_UINPUT_GET_HOUSE || name==ID_UINPUT_GET_COUNTRY || name==ID_MESSAGE_YES_NO
  873. || name==ID_OR || name==ID_AND || name==ID_NOT || name==ID_UINPUT_GET_MANUAL)
  874. {
  875. replaceVariables[0]=FALSE;
  876. }
  877. if(name==ID_GET_WAYPOINT_POS )
  878. {
  879. replaceVariables[1]=FALSE;
  880. replaceVariables[2]=FALSE;
  881. }
  882. if(name==ID_IS)
  883. {
  884. replaceVariables[3]=FALSE;
  885. }
  886. map<CString, CString>::iterator e;
  887. for(e=variables.begin();e!=variables.end();e++)
  888. {
  889. for(h=0;h<paramcount;h++)
  890. {
  891. if(replaceVariables[h])
  892. {
  893. params[h].Replace(e->first, e->second);
  894. }
  895. }
  896. }
  897. delete[] replaceVariables;
  898. if(name==ID_ASK_CONTINUE)
  899. {
  900. if(paramcount<1)
  901. {
  902. ReportScriptError(i);
  903. delete[] params;
  904. break;
  905. }
  906. // check bool
  907. if(paramcount>1)
  908. {
  909. if(params[1].GetLength()>0)
  910. {
  911. if(!IsValSet(params[1])) goto nextline;
  912. }
  913. }
  914. int res=MessageBox(params[0], "Continue?", MB_YESNO);
  915. if(res==IDNO) break;
  916. }
  917. else if(name==ID_MESSAGE)
  918. {
  919. if(paramcount<2)
  920. {
  921. ReportScriptError(i);
  922. delete[] params;
  923. break;
  924. }
  925. // check bool
  926. if(paramcount>2)
  927. {
  928. if(params[2].GetLength()>0)
  929. {
  930. if(!IsValSet(params[2])) goto nextline;
  931. }
  932. }
  933. MessageBox(params[0], params[1]);
  934. }
  935. else if(name==ID_MESSAGE_YES_NO)
  936. {
  937. if(paramcount<3)
  938. {
  939. ReportScriptError(i);
  940. delete[] params;
  941. break;
  942. }
  943. // check bool
  944. if(paramcount>3)
  945. {
  946. if(params[3].GetLength()>0)
  947. {
  948. if(!IsValSet(params[3])) goto nextline;
  949. }
  950. }
  951. int res=MessageBox(params[1], params[2], MB_YESNO);
  952. if(res==IDYES)
  953. {
  954. variables[params[0]]="1";
  955. }
  956. else
  957. variables[params[0]]="0";
  958. }
  959. else if(name==ID_ADD_TRIGGER)
  960. {
  961. if(paramcount<5)
  962. {
  963. ReportScriptError(i);
  964. delete[] params;
  965. break;
  966. }
  967. // check bool
  968. if(paramcount>5)
  969. {
  970. if(params[5].GetLength()>0)
  971. {
  972. if(!IsValSet(params[5])) goto nextline;
  973. }
  974. }
  975. if(!bAddAllowed) goto nextline;
  976. CString ID_T=GetFreeID();
  977. if(params[0].GetLength()>0)
  978. {
  979. variables[params[0]]=ID_T;
  980. }
  981. ini.sections["Triggers"].values[ID_T]=params[1];
  982. ini.sections["Events"].values[ID_T]=params[2];
  983. ini.sections["Actions"].values[ID_T]=params[3];
  984. BOOL tag=TRUE;
  985. params[4].MakeLower();
  986. if(params[4]=="false" || params[4]=="no") tag=FALSE;
  987. if(tag)
  988. {
  989. CString ID_TAG=GetFreeID();
  990. ini.sections["Tags"].values[ID_TAG]="0,";
  991. ini.sections["Tags"].values[ID_TAG]+=GetParam(params[1],2);
  992. ini.sections["Tags"].values[ID_TAG]+=",";
  993. ini.sections["Tags"].values[ID_TAG]+=ID_T;
  994. }
  995. report+="Trigger " + GetParam(params[1],2) + " added\r\n";
  996. bUpdate=TRUE;
  997. }
  998. else if(name==ID_SET_INI_KEY)
  999. {
  1000. if(paramcount<3)
  1001. {
  1002. ReportScriptError(i);
  1003. delete[] params;
  1004. break;
  1005. }
  1006. // check bool
  1007. if(paramcount>3)
  1008. {
  1009. if(params[3].GetLength()>0)
  1010. {
  1011. if(!IsValSet(params[3])) goto nextline;
  1012. }
  1013. }
  1014. //if(ini.sections[params[0]].FindName(params[1])>=0)
  1015. {
  1016. if(bSafeMode) goto nextline;
  1017. }
  1018. ini.sections[params[0]].values[params[1]]=params[2];
  1019. report +=params[0]+(CString)"->"+params[1]+(CString) " set to \"" + params[2] + "\"\r\n";
  1020. bUpdate=TRUE;
  1021. bUpdateOnlyMission=FALSE;
  1022. }
  1023. else if(name==ID_GET_INI_KEY)
  1024. {
  1025. if(paramcount<3)
  1026. {
  1027. ReportScriptError(i);
  1028. delete[] params;
  1029. break;
  1030. }
  1031. // check bool
  1032. if(paramcount>3)
  1033. {
  1034. if(params[3].GetLength()>0)
  1035. {
  1036. if(!IsValSet(params[3])) goto nextline;
  1037. }
  1038. }
  1039. if(ini.sections.find(params[1])==ini.sections.end() || ini.sections[params[1]].FindName(params[2])<0)
  1040. {
  1041. variables[params[0]]="";
  1042. }
  1043. else
  1044. variables[params[0]]=ini.sections[params[1]].values[params[2]];
  1045. }
  1046. else if(name==ID_SET_SAFE_MODE)
  1047. {
  1048. if(paramcount<2)
  1049. {
  1050. ReportScriptError(i);
  1051. delete[] params;
  1052. break;
  1053. }
  1054. // check bool
  1055. if(paramcount>2)
  1056. {
  1057. if(params[2].GetLength()>0)
  1058. {
  1059. if(!IsValSet(params[2])) goto nextline;
  1060. }
  1061. }
  1062. BOOL enabled=TRUE;
  1063. params[0].MakeLower();
  1064. if(params[0]=="false" || params[0]=="no") enabled=FALSE;
  1065. if(!enabled)
  1066. {
  1067. CString s;
  1068. s="This script wants to disable INI protection. For some scripts this may be necessary, but it can seriously damage your Map-> Reason why script wants to disable INI protection:\n";
  1069. s+=params[1];
  1070. s+="\n\nDisable INI protection?";
  1071. int res=MessageBox(s, "Disable INI protection?", MB_YESNO | MB_DEFBUTTON2);
  1072. if(res==IDNO) goto nextline;
  1073. }
  1074. if(!enabled) report+="INI Protection disabled\r\n";
  1075. if(enabled) report+="INI Protection enabled\r\n";
  1076. bSafeMode=enabled;
  1077. }
  1078. else if(name==ID_SET_VARIABLE)
  1079. {
  1080. if(paramcount<2)
  1081. {
  1082. ReportScriptError(i);
  1083. delete[] params;
  1084. break;
  1085. }
  1086. // check bool
  1087. if(paramcount>2)
  1088. {
  1089. if(params[2].GetLength()>0)
  1090. {
  1091. if(!IsValSet(params[2])) goto nextline;
  1092. }
  1093. }
  1094. variables[params[0]]=params[1];
  1095. }
  1096. else if(name==ID_ADD)
  1097. {
  1098. if(paramcount<2)
  1099. {
  1100. ReportScriptError(i);
  1101. delete[] params;
  1102. break;
  1103. }
  1104. // check bool
  1105. if(paramcount>2)
  1106. {
  1107. if(params[2].GetLength()>0)
  1108. {
  1109. if(!IsValSet(params[2])) goto nextline;
  1110. }
  1111. }
  1112. int n;
  1113. n=atoi(variables[params[0]]);
  1114. int n2=atoi(params[1]);
  1115. n+=n2;
  1116. char c[50];
  1117. itoa(n, c, 10);
  1118. variables[params[0]]=c;
  1119. }
  1120. else if(name==ID_INSERT)
  1121. {
  1122. if(paramcount<3)
  1123. {
  1124. ReportScriptError(i);
  1125. delete[] params;
  1126. break;
  1127. }
  1128. // check bool
  1129. if(paramcount>3)
  1130. {
  1131. if(params[3].GetLength()>0)
  1132. {
  1133. if(!IsValSet(params[3])) goto nextline;
  1134. }
  1135. }
  1136. int pos=atoi(params[2]);
  1137. if(pos<0)
  1138. {
  1139. pos=variables[params[0]].GetLength();
  1140. }
  1141. variables[params[0]].Insert(pos, params[1]);
  1142. }
  1143. else if(name==ID_REPLACE)
  1144. {
  1145. if(paramcount<3)
  1146. {
  1147. ReportScriptError(i);
  1148. delete[] params;
  1149. break;
  1150. }
  1151. // check bool
  1152. if(paramcount>3)
  1153. {
  1154. if(params[3].GetLength()>0)
  1155. {
  1156. if(!IsValSet(params[3])) goto nextline;
  1157. }
  1158. }
  1159. variables[params[0]].Replace(params[1], params[2]);
  1160. }
  1161. else if(name==ID_TRIM)
  1162. {
  1163. if(paramcount<1)
  1164. {
  1165. ReportScriptError(i);
  1166. delete[] params;
  1167. break;
  1168. }
  1169. // check bool
  1170. if(paramcount>1)
  1171. {
  1172. if(params[1].GetLength()>0)
  1173. {
  1174. if(!IsValSet(params[1])) goto nextline;
  1175. }
  1176. }
  1177. variables[params[0]].TrimLeft();
  1178. variables[params[0]].TrimRight();
  1179. }
  1180. else if(name==ID_NOT)
  1181. {
  1182. if(paramcount<1)
  1183. {
  1184. ReportScriptError(i);
  1185. delete[] params;
  1186. break;
  1187. }
  1188. // check bool
  1189. if(paramcount>1)
  1190. {
  1191. if(params[1].GetLength()>0)
  1192. {
  1193. if(!IsValSet(params[1])) goto nextline;
  1194. }
  1195. }
  1196. if(IsValSet(variables[params[0]]))
  1197. variables[params[0]]="0";
  1198. else
  1199. variables[params[0]]="1";
  1200. }
  1201. else if(name==ID_AND)
  1202. {
  1203. if(paramcount<2)
  1204. {
  1205. ReportScriptError(i);
  1206. delete[] params;
  1207. break;
  1208. }
  1209. BOOL bSet=TRUE;
  1210. int k;
  1211. for(k=1;k<paramcount;k++)
  1212. {
  1213. if(!IsValSet(params[k])) { bSet=FALSE; break; }
  1214. }
  1215. CString s="0";
  1216. if(bSet) s="1";
  1217. variables[params[0]]=s;
  1218. }
  1219. else if(name==ID_OR)
  1220. {
  1221. if(paramcount<2)
  1222. {
  1223. ReportScriptError(i);
  1224. delete[] params;
  1225. break;
  1226. }
  1227. BOOL bSet=FALSE;
  1228. int k;
  1229. for(k=1;k<paramcount;k++)
  1230. {
  1231. if(IsValSet(params[k])) { bSet=TRUE; break; }
  1232. }
  1233. CString s="0";
  1234. if(bSet) s="1";
  1235. variables[params[0]]=s;
  1236. }
  1237. else if(name==ID_LENGTH)
  1238. {
  1239. if(paramcount<2)
  1240. {
  1241. ReportScriptError(i);
  1242. delete[] params;
  1243. break;
  1244. }
  1245. // check bool
  1246. if(paramcount>2)
  1247. {
  1248. if(params[2].GetLength()>0)
  1249. {
  1250. if(!IsValSet(params[2])) goto nextline;
  1251. }
  1252. }
  1253. int len=params[1].GetLength();
  1254. char c[50];
  1255. itoa(len, c, 10);
  1256. variables[params[0]]=c;
  1257. }
  1258. else if(name==ID_REMOVE)
  1259. {
  1260. if(paramcount<2)
  1261. {
  1262. ReportScriptError(i);
  1263. delete[] params;
  1264. break;
  1265. }
  1266. // check bool
  1267. if(paramcount>2)
  1268. {
  1269. if(params[2].GetLength()>0)
  1270. {
  1271. if(!IsValSet(params[2])) goto nextline;
  1272. }
  1273. }
  1274. if(atoi(params[1])>=variables[params[0]].GetLength() || atoi(params[1])<0 || atoi(params[2])<0)
  1275. {
  1276. MessageBox("Invalid index or length for remove command, script cancelled.","Error");
  1277. delete[] params;
  1278. break;
  1279. }
  1280. variables[params[0]].Delete(atoi(params[1]),atoi(params[2]));
  1281. }
  1282. else if(name==ID_GETCHAR)
  1283. {
  1284. if(paramcount<3)
  1285. {
  1286. ReportScriptError(i);
  1287. delete[] params;
  1288. break;
  1289. }
  1290. // check bool
  1291. if(paramcount>3)
  1292. {
  1293. if(params[3].GetLength()>0)
  1294. {
  1295. if(!IsValSet(params[3])) goto nextline;
  1296. }
  1297. }
  1298. if(atoi(params[2])>=params[1].GetLength() || atoi(params[2])<0)
  1299. {
  1300. MessageBox("Invalid index for GetChar command, script cancelled.","Error");
  1301. delete[] params;
  1302. break;
  1303. }
  1304. variables[params[0]]=params[1].GetAt(atoi(params[2]));
  1305. }
  1306. else if(name==ID_SUBSTRACT)
  1307. {
  1308. if(paramcount<2)
  1309. {
  1310. ReportScriptError(i);
  1311. delete[] params;
  1312. break;
  1313. }
  1314. // check bool
  1315. if(paramcount>2)
  1316. {
  1317. if(params[2].GetLength()>0)
  1318. {
  1319. if(!IsValSet(params[2])) goto nextline;
  1320. }
  1321. }
  1322. int n;
  1323. n=atoi(variables[params[0]]);
  1324. int n2=atoi(params[1]);
  1325. n-=n2;
  1326. char c[50];
  1327. itoa(n, c, 10);
  1328. variables[params[0]]=c;
  1329. }
  1330. else if(name==ID_MULTI)
  1331. {
  1332. if(paramcount<2)
  1333. {
  1334. ReportScriptError(i);
  1335. delete[] params;
  1336. break;
  1337. }
  1338. // check bool
  1339. if(paramcount>2)
  1340. {
  1341. if(params[2].GetLength()>0)
  1342. {
  1343. if(!IsValSet(params[2])) goto nextline;
  1344. }
  1345. }
  1346. int n;
  1347. n=atoi(variables[params[0]]);
  1348. int n2=atoi(params[1]);
  1349. n=n*n2;
  1350. char c[50];
  1351. itoa(n, c, 10);
  1352. variables[params[0]]=c;
  1353. }
  1354. else if(name==ID_DIVIDE)
  1355. {
  1356. if(paramcount<2)
  1357. {
  1358. ReportScriptError(i);
  1359. delete[] params;
  1360. break;
  1361. }
  1362. // check bool
  1363. if(paramcount>2)
  1364. {
  1365. if(params[2].GetLength()>0)
  1366. {
  1367. if(!IsValSet(params[2])) goto nextline;
  1368. }
  1369. }
  1370. int n;
  1371. n=atoi(variables[params[0]]);
  1372. int n2=atoi(params[1]);
  1373. if(n2==0)
  1374. {
  1375. MessageBox("Division through 0, script cancelled", "Division through 0");
  1376. delete[] params;
  1377. break;
  1378. }
  1379. n=n/n2;
  1380. char c[50];
  1381. itoa(n, c, 10);
  1382. variables[params[0]]=c;
  1383. }
  1384. else if(name==ID_MODULO)
  1385. {
  1386. if(paramcount<2)
  1387. {
  1388. ReportScriptError(i);
  1389. delete[] params;
  1390. break;
  1391. }
  1392. // check bool
  1393. if(paramcount>2)
  1394. {
  1395. if(params[2].GetLength()>0)
  1396. {
  1397. if(!IsValSet(params[2])) goto nextline;
  1398. }
  1399. }
  1400. int n;
  1401. n=atoi(variables[params[0]]);
  1402. int n2=atoi(params[1]);
  1403. if(n2==0)
  1404. {
  1405. MessageBox("Division through 0, script cancelled", "Division through 0");
  1406. delete[] params;
  1407. break;
  1408. }
  1409. n=n%n2;
  1410. char c[50];
  1411. itoa(n, c, 10);
  1412. variables[params[0]]=c;
  1413. }
  1414. else if(name==ID_SET_WAYPOINT)
  1415. {
  1416. if(paramcount<3)
  1417. {
  1418. ReportScriptError(i);
  1419. delete[] params;
  1420. break;
  1421. }
  1422. // check bool
  1423. if(paramcount>3)
  1424. {
  1425. if(params[3].GetLength()>0)
  1426. {
  1427. if(!IsValSet(params[3])) goto nextline;
  1428. }
  1429. }
  1430. int n=atoi(params[0]);
  1431. CString id=params[0];
  1432. if(n<0)
  1433. {
  1434. id="";
  1435. }
  1436. if(bSafeMode && n>=0)
  1437. {
  1438. if(ini.sections["Waypoints"].FindName(id)>=0)
  1439. {
  1440. goto nextline;
  1441. }
  1442. }
  1443. DWORD pos=atoi(params[1])+atoi(params[2])*Map->GetIsoSize();
  1444. if(pos<Map->GetIsoSize()*Map->GetIsoSize())
  1445. {
  1446. //Map->m_noAutoObjectUpdate=TRUE;
  1447. Map->AddWaypoint(id, pos);
  1448. bUpdateWaypoints=TRUE;
  1449. //Map->m_noAutoObjectUpdate=bOldUpdate;
  1450. report+="Waypoint " + id + " set.\r\n";
  1451. }
  1452. else
  1453. {
  1454. report+="Waypoint " + id + " moving failed!\r\n";
  1455. }
  1456. bUpdate=TRUE;
  1457. bUpdateOnlyMission=FALSE;
  1458. }
  1459. else if(name==ID_REQUIRES_MP)
  1460. {
  1461. // check bool
  1462. if(paramcount>0)
  1463. {
  1464. if(params[0].GetLength()>0)
  1465. {
  1466. if(!IsValSet(params[0])) goto nextline;
  1467. }
  1468. }
  1469. if(Map->IsMultiplayer()==FALSE)
  1470. {
  1471. MessageBox("This script requires a multiplayer map and cannot be used with singleplayer maps", "Error");
  1472. break;
  1473. }
  1474. }
  1475. else if(name==ID_REQUIRES_SP)
  1476. {
  1477. // check bool
  1478. if(paramcount>0)
  1479. {
  1480. if(params[0].GetLength()>0)
  1481. {
  1482. if(!IsValSet(params[0])) goto nextline;
  1483. }
  1484. }
  1485. if(Map->IsMultiplayer()==TRUE)
  1486. {
  1487. MessageBox("This script requires a singleplayer map and cannot be used with multiplayer maps", "Error");
  1488. break;
  1489. }
  1490. }
  1491. else if(name==ID_ADD_AI_TRIGGER)
  1492. {
  1493. if(paramcount<2)
  1494. {
  1495. ReportScriptError(i);
  1496. delete[] params;
  1497. break;
  1498. }
  1499. // check bool
  1500. if(paramcount>2)
  1501. {
  1502. if(params[2].GetLength()>0)
  1503. {
  1504. if(!IsValSet(params[2])) goto nextline;
  1505. }
  1506. }
  1507. if(!bAddAllowed) goto nextline;
  1508. CString ID_T=GetFreeID();
  1509. if(params[0].GetLength()>0)
  1510. {
  1511. variables[params[0]]=ID_T;
  1512. }
  1513. ini.sections["AITriggerTypes"].values[ID_T]=params[1];
  1514. report+="AI Trigger " + GetParam(params[1],0) + " added\r\n";
  1515. bUpdate=TRUE;
  1516. }
  1517. else if(name==ID_ADD_TAG)
  1518. {
  1519. if(paramcount<2)
  1520. {
  1521. ReportScriptError(i);
  1522. delete[] params;
  1523. break;
  1524. }
  1525. // check bool
  1526. if(paramcount>2)
  1527. {
  1528. if(params[2].GetLength()>0)
  1529. {
  1530. if(!IsValSet(params[2])) goto nextline;
  1531. }
  1532. }
  1533. if(!bAddAllowed) goto nextline;
  1534. CString ID_T=GetFreeID();
  1535. if(params[0].GetLength()>0)
  1536. {
  1537. variables[params[0]]=ID_T;
  1538. }
  1539. CString ID_TAG=ID_T; //GetFreeID();
  1540. ini.sections["Tags"].values[ID_TAG]=params[1];
  1541. report+="Tag " + GetParam(params[1],1) + " added\r\n";
  1542. bUpdate=TRUE;
  1543. }
  1544. else if(name==ID_RESIZE)
  1545. {
  1546. if(paramcount<4)
  1547. {
  1548. ReportScriptError(i);
  1549. delete[] params;
  1550. break;
  1551. }
  1552. // check bool
  1553. if(paramcount>4)
  1554. {
  1555. if(params[4].GetLength()>0)
  1556. {
  1557. if(!IsValSet(params[4])) goto nextline;
  1558. }
  1559. }
  1560. int res=MessageBox("This script wants to resize the map. Resize map?", "Resize map?", MB_YESNO);
  1561. if(res==IDNO) goto nextline;
  1562. if(atoi(params[2])>200 || atoi(params[3])>200)
  1563. {
  1564. MessageBox("Resizing map failed. Script cancelled.", "Error");
  1565. break;
  1566. }
  1567. Map->ResizeMap(atoi(params[0]), atoi(params[1]), atoi(params[2]), atoi(params[3]));
  1568. bUpdate=TRUE;
  1569. bUpdateOnlyMission=FALSE;
  1570. bNoRepos=FALSE;
  1571. }
  1572. else if(name==ID_IS)
  1573. {
  1574. if(paramcount<4)
  1575. {
  1576. ReportScriptError(i);
  1577. delete[] params;
  1578. break;
  1579. }
  1580. // check bool
  1581. if(paramcount>4)
  1582. {
  1583. if(params[4].GetLength()>0)
  1584. {
  1585. if(!IsValSet(params[4])) goto nextline;
  1586. }
  1587. }
  1588. BOOL bIs=FALSE;
  1589. if(params[1]=="<")
  1590. {
  1591. if(atoi(params[0])<atoi(params[2])) bIs=TRUE;
  1592. }
  1593. if(params[1]=="<=")
  1594. {
  1595. if(atoi(params[0])<=atoi(params[2])) bIs=TRUE;
  1596. }
  1597. if(params[1]=="=")
  1598. {
  1599. if(atoi(params[0])==atoi(params[2]))
  1600. {
  1601. bIs=TRUE;
  1602. }
  1603. if(params[0]==params[2]) {bIs=TRUE;}
  1604. }
  1605. if(params[1]==">=")
  1606. {
  1607. if(atoi(params[0])>=atoi(params[2])) bIs=TRUE;
  1608. }
  1609. if(params[1]==">")
  1610. {
  1611. if(atoi(params[0])>atoi(params[2])) bIs=TRUE;
  1612. }
  1613. if(params[1]=="!=")
  1614. {
  1615. if(atoi(params[0])!=atoi(params[2])) bIs=TRUE;
  1616. if(params[0]!=params[2]) bIs=TRUE;
  1617. }
  1618. CString s="0";
  1619. if(bIs) s="1";
  1620. variables[params[3]]=s;
  1621. }
  1622. else if(name==ID_CANCEL)
  1623. {
  1624. // check bool
  1625. if(paramcount>0)
  1626. {
  1627. if(params[0].GetLength()>0)
  1628. {
  1629. if(!IsValSet(params[0])) goto nextline;
  1630. }
  1631. }
  1632. break;
  1633. }
  1634. else if(name==ID_PRINT)
  1635. {
  1636. if(paramcount<1)
  1637. {
  1638. ReportScriptError(i);
  1639. delete[] params;
  1640. break;
  1641. }
  1642. // check bool
  1643. if(paramcount>1)
  1644. {
  1645. if(params[1].GetLength()>0)
  1646. {
  1647. if(!IsValSet(params[1])) goto nextline;
  1648. }
  1649. }
  1650. report+=params[0];
  1651. report+="\r\n";
  1652. }
  1653. else if(name==ID_TOLOWER)
  1654. {
  1655. if(paramcount<1)
  1656. {
  1657. ReportScriptError(i);
  1658. delete[] params;
  1659. break;
  1660. }
  1661. // check bool
  1662. if(paramcount>1)
  1663. {
  1664. if(params[1].GetLength()>0)
  1665. {
  1666. if(!IsValSet(params[1])) goto nextline;
  1667. }
  1668. }
  1669. variables[params[0]].MakeLower();
  1670. }
  1671. else if(name==ID_TOUPPER)
  1672. {
  1673. if(paramcount<1)
  1674. {
  1675. ReportScriptError(i);
  1676. delete[] params;
  1677. break;
  1678. }
  1679. // check bool
  1680. if(paramcount>1)
  1681. {
  1682. if(params[1].GetLength()>0)
  1683. {
  1684. if(!IsValSet(params[1])) goto nextline;
  1685. }
  1686. }
  1687. variables[params[0]].MakeUpper();
  1688. }
  1689. else if(name==ID_GET_FREE_WAYPOINT)
  1690. {
  1691. if(paramcount<1)
  1692. {
  1693. ReportScriptError(i);
  1694. delete[] params;
  1695. break;
  1696. }
  1697. // check bool
  1698. if(paramcount>1)
  1699. {
  1700. if(params[1].GetLength()>0)
  1701. {
  1702. if(!IsValSet(params[1])) goto nextline;
  1703. }
  1704. }
  1705. variables[params[0]]=GetFree("Waypoints");
  1706. }
  1707. else if(name==ID_UINPUT_GET_INTEGER)
  1708. {
  1709. if(paramcount<4)
  1710. {
  1711. ReportScriptError(i);
  1712. delete[] params;
  1713. break;
  1714. }
  1715. // check bool
  1716. if(paramcount>4)
  1717. {
  1718. if(params[4].GetLength()>0)
  1719. {
  1720. if(!IsValSet(params[4])) goto nextline;
  1721. }
  1722. }
  1723. BOOL ok=FALSE;
  1724. int n=0;
  1725. while(!ok)
  1726. {
  1727. CString s=InputBox(params[1], "Enter Integer");
  1728. ok=TRUE;
  1729. if(s.GetLength()==0) ok=FALSE;
  1730. n=atoi(s);
  1731. if(params[2].GetLength()>0)
  1732. {
  1733. if(n<atoi(params[2])) ok=FALSE;
  1734. }
  1735. if(params[3].GetLength()>0)
  1736. {
  1737. if(n>atoi(params[3])) ok=FALSE;
  1738. }
  1739. }
  1740. char c[50];
  1741. itoa(n, c, 10);
  1742. variables[params[0]]=c;
  1743. }
  1744. else if(name==ID_UINPUT_GET_STRING)
  1745. {
  1746. if(paramcount<2)
  1747. {
  1748. ReportScriptError(i);
  1749. delete[] params;
  1750. break;
  1751. }
  1752. // check bool
  1753. if(paramcount>2)
  1754. {
  1755. if(params[2].GetLength()>0)
  1756. {
  1757. if(!IsValSet(params[2])) goto nextline;
  1758. }
  1759. }
  1760. BOOL ok=FALSE;
  1761. CString s;
  1762. while(!ok)
  1763. {
  1764. s=InputBox(params[1], "Enter String");
  1765. ok=TRUE;
  1766. if (s.GetLength()==0) ok=FALSE;
  1767. }
  1768. variables[params[0]]=s;
  1769. }
  1770. else if(name==ID_UINPUT_GET_HOUSE)
  1771. {
  1772. if(paramcount<2)
  1773. {
  1774. ReportScriptError(i);
  1775. delete[] params;
  1776. break;
  1777. }
  1778. // check bool
  1779. if(paramcount>2)
  1780. {
  1781. if(params[2].GetLength()>0)
  1782. {
  1783. if(!IsValSet(params[2])) goto nextline;
  1784. }
  1785. }
  1786. CComboUInputDlg dlg;
  1787. dlg.m_type=COMBOUINPUT_HOUSES;
  1788. dlg.m_Caption=params[1];
  1789. dlg.DoModal();
  1790. variables[params[0]]=dlg.m_Combo;
  1791. }
  1792. else if(name==ID_UINPUT_GET_COUNTRY)
  1793. {
  1794. if(paramcount<2)
  1795. {
  1796. ReportScriptError(i);
  1797. delete[] params;
  1798. break;
  1799. }
  1800. // check bool
  1801. if(paramcount>2)
  1802. {
  1803. if(params[2].GetLength()>0)
  1804. {
  1805. if(!IsValSet(params[2])) goto nextline;
  1806. }
  1807. }
  1808. CComboUInputDlg dlg;
  1809. dlg.m_type=COMBOUINPUT_COUNTRIES;
  1810. dlg.m_Caption=params[1];
  1811. dlg.DoModal();
  1812. variables[params[0]]=dlg.m_Combo;
  1813. }
  1814. else if(name==ID_UINPUT_GET_TRIGGER)
  1815. {
  1816. if(paramcount<2)
  1817. {
  1818. ReportScriptError(i);
  1819. delete[] params;
  1820. break;
  1821. }
  1822. // check bool
  1823. if(paramcount>2)
  1824. {
  1825. if(params[2].GetLength()>0)
  1826. {
  1827. if(!IsValSet(params[2])) goto nextline;
  1828. }
  1829. }
  1830. CComboUInputDlg dlg;
  1831. dlg.m_type=COMBOUINPUT_TRIGGERS;
  1832. dlg.m_Caption=params[1];
  1833. dlg.DoModal();
  1834. variables[params[0]]=dlg.m_Combo;
  1835. }
  1836. else if(name==ID_UINPUT_GET_TAG)
  1837. {
  1838. if(paramcount<2)
  1839. {
  1840. ReportScriptError(i);
  1841. delete[] params;
  1842. break;
  1843. }
  1844. // check bool
  1845. if(paramcount>2)
  1846. {
  1847. if(params[2].GetLength()>0)
  1848. {
  1849. if(!IsValSet(params[2])) goto nextline;
  1850. }
  1851. }
  1852. CComboUInputDlg dlg;
  1853. dlg.m_type=COMBOUINPUT_TAGS;
  1854. dlg.m_Caption=params[1];
  1855. dlg.DoModal();
  1856. variables[params[0]]=dlg.m_Combo;
  1857. }
  1858. /*else if(name==ID_UINPUT_GET_MANUAL)
  1859. {
  1860. if(paramcount<4)
  1861. {
  1862. ReportScriptError(i);
  1863. delete[] params;
  1864. break;
  1865. }
  1866. // check bool
  1867. if(paramcount>4)
  1868. {
  1869. if(params[4].GetLength()>0)
  1870. {
  1871. if(!IsValSet(params[4])) goto nextline;
  1872. }
  1873. }
  1874. CComboUInputDlg dlg;
  1875. dlg.m_type=COMBOUINPUT_MANUAL;
  1876. dlg.m_Caption=params[1];
  1877. dlg.bTruncateStrings=IsValSet(params[2]);
  1878. dlg.DoModal();
  1879. variables[params[0]]=dlg.m_Combo;
  1880. }*/
  1881. else if(name==ID_JUMP_TO_LINE)
  1882. {
  1883. if(paramcount<1)
  1884. {
  1885. ReportScriptError(i);
  1886. delete[] params;
  1887. break;
  1888. }
  1889. // check bool
  1890. if(paramcount>1)
  1891. {
  1892. if(params[1].GetLength()>0)
  1893. {
  1894. if(!IsValSet(params[1])) goto nextline;
  1895. }
  1896. }
  1897. if(!bAllowLoop)
  1898. {
  1899. int res=MessageBox("This script tries to use loops. Some scripts may require this. However, this holds the risk of infinite loops, which may cause the FinalSun/FinalAlert2 to crash. Do you want to allow looping for this script?", "Allow looping?", MB_YESNO);
  1900. if(res==IDYES)
  1901. {
  1902. bAllowLoop=TRUE;
  1903. }else
  1904. goto nextline; // not allowed in safe mode because of possible infinte loops#
  1905. }
  1906. if(!bIgnoreLoopCounts)
  1907. {
  1908. loop_count++;
  1909. if(loop_count>300)
  1910. {
  1911. int res=MessageBox("This script has exceeded the 300 loops limit. Do you want to remove the loop limit (not recommended, inherits risk of infinite loops if script has bugs)? If you press no, the script will stop after another 300 loops to ask you again. If you press cancel, the script will be cancelled.", "Loop Limit exceeded", MB_YESNOCANCEL | MB_DEFBUTTON2);
  1912. if(res==IDYES) bIgnoreLoopCounts=TRUE;
  1913. if(res==IDNO) loop_count=0;
  1914. if(res==IDCANCEL)
  1915. {
  1916. delete[] params;
  1917. break;
  1918. }
  1919. }
  1920. }
  1921. int n=s.FindJumpLine(params[0]);
  1922. if(n<0 || n>s.functioncount)
  1923. {
  1924. ReportScriptError(i);
  1925. delete[] params;
  1926. break;
  1927. }
  1928. i=n-1; // not n, as the for loop adds 1 again!
  1929. goto nextline_no_update;
  1930. }
  1931. else if(name==ID_SET_AUTO_UPDATE)
  1932. {
  1933. if(paramcount<1)
  1934. {
  1935. ReportScriptError(i);
  1936. delete[] params;
  1937. break;
  1938. }
  1939. // check bool
  1940. if(paramcount>1)
  1941. {
  1942. if(params[1].GetLength()>0)
  1943. {
  1944. if(!IsValSet(params[1])) goto nextline;
  1945. }
  1946. }
  1947. bAutoUpdate=IsValSet(params[0]);
  1948. goto nextline;
  1949. }
  1950. else if(name==ID_GET_RANDOM)
  1951. {
  1952. if(paramcount<1)
  1953. {
  1954. ReportScriptError(i);
  1955. delete[] params;
  1956. break;
  1957. }
  1958. // check bool
  1959. if(paramcount>1)
  1960. {
  1961. if(params[1].GetLength()>0)
  1962. {
  1963. if(!IsValSet(params[1])) goto nextline;
  1964. }
  1965. }
  1966. int n=rand(); // 0 and 32767
  1967. char c[50];
  1968. itoa(n, c, 10);
  1969. variables[params[0]]=c;
  1970. }
  1971. else if(name==ID_ADD_TERRAIN)
  1972. {
  1973. if(paramcount<3)
  1974. {
  1975. ReportScriptError(i);
  1976. delete[] params;
  1977. break;
  1978. }
  1979. // check bool
  1980. if(paramcount>3)
  1981. {
  1982. if(params[3].GetLength()>0)
  1983. {
  1984. if(!IsValSet(params[3])) goto nextline;
  1985. }
  1986. }
  1987. if(!bAddAllowed) goto nextline;
  1988. DWORD pos;
  1989. pos=atoi(params[1])+atoi(params[2])*Map->GetIsoSize();
  1990. if(Map->GetTerrainAt(pos)<0)
  1991. {
  1992. Map->AddTerrain(params[0], pos);
  1993. report+="Terrain added: " + params[0] + (CString)" at " + params[1] + (CString)"/" + params[2] + "\r\n";
  1994. bUpdate=TRUE;
  1995. bUpdateOnlyMission=FALSE;
  1996. }
  1997. }
  1998. #ifdef SMUDGE_SUPP
  1999. else if(name==ID_ADD_SMUDGE)
  2000. {
  2001. if(paramcount<3)
  2002. {
  2003. ReportScriptError(i);
  2004. delete[] params;
  2005. break;
  2006. }
  2007. // check bool
  2008. if(paramcount>3)
  2009. {
  2010. if(params[3].GetLength()>0)
  2011. {
  2012. if(!IsValSet(params[3])) goto nextline;
  2013. }
  2014. }
  2015. DWORD pos;
  2016. pos=atoi(params[1])+atoi(params[2])*Map->GetIsoSize();
  2017. FIELDDATA* fd=Map->GetFielddataAt(pos);
  2018. if(fd->smudge<0)
  2019. {
  2020. SMUDGE s;
  2021. s.deleted=0;
  2022. s.type=params[0];
  2023. s.x=atoi(params[1]);
  2024. s.y=atoi(params[2]);
  2025. Map->AddSmudge(&s);
  2026. report+="Smudge added: " + params[0] + (CString) " at " + params[1] + (CString)"/" + params[2] + "\r\n";
  2027. bUpdate=TRUE;
  2028. bUpdateOnlyMission=FALSE;
  2029. }
  2030. }
  2031. #endif
  2032. else if(name==ID_GET_WAYPOINT_POS)
  2033. {
  2034. if(paramcount<3)
  2035. {
  2036. ReportScriptError(i);
  2037. delete[] params;
  2038. break;
  2039. }
  2040. // check bool
  2041. if(paramcount>3)
  2042. {
  2043. if(params[3].GetLength()>0)
  2044. {
  2045. if(!IsValSet(params[3])) goto nextline;
  2046. }
  2047. }
  2048. BOOL bFound=FALSE;
  2049. DWORD pos;
  2050. int k;
  2051. for(k=0;k<Map->GetWaypointCount();k++)
  2052. {
  2053. CString id;
  2054. Map->GetWaypointData(k, &id, &pos);
  2055. if(id==params[0])
  2056. {
  2057. bFound=TRUE;
  2058. break;
  2059. }
  2060. }
  2061. if(!bFound) pos=0;
  2062. int x=pos%Map->GetIsoSize();
  2063. int y=pos/Map->GetIsoSize();
  2064. char c[50];
  2065. itoa(x, c, 10);
  2066. variables[params[1]]=c;
  2067. itoa(y, c, 10);
  2068. variables[params[2]]=c;
  2069. }
  2070. else if(name==ID_GET_PARAM)
  2071. {
  2072. if(paramcount<3)
  2073. {
  2074. ReportScriptError(i);
  2075. delete[] params;
  2076. break;
  2077. }
  2078. // check bool
  2079. if(paramcount>3)
  2080. {
  2081. if(params[3].GetLength()>0)
  2082. {
  2083. if(!IsValSet(params[3])) goto nextline;
  2084. }
  2085. }
  2086. variables[params[0]]=GetParam(params[1], atoi(params[2]));
  2087. }
  2088. else if(name==ID_SET_PARAM)
  2089. {
  2090. if(paramcount<3)
  2091. {
  2092. ReportScriptError(i);
  2093. delete[] params;
  2094. break;
  2095. }
  2096. // check bool
  2097. if(paramcount>3)
  2098. {
  2099. if(params[3].GetLength()>0)
  2100. {
  2101. if(!IsValSet(params[3])) goto nextline;
  2102. }
  2103. }
  2104. variables[params[0]]=SetParam(variables[params[0]], atoi(params[1]), params[2]);
  2105. }
  2106. else if(name==ID_GET_PARAM_COUNT)
  2107. {
  2108. if(paramcount<2)
  2109. {
  2110. ReportScriptError(i);
  2111. delete[] params;
  2112. break;
  2113. }
  2114. // check bool
  2115. if(paramcount>2)
  2116. {
  2117. if(params[2].GetLength()>0)
  2118. {
  2119. if(!IsValSet(params[2])) goto nextline;
  2120. }
  2121. }
  2122. int k;
  2123. int count=1; // we start at 1 param even if no , exists!
  2124. for(k=0;k<params[1].GetLength();k++)
  2125. {
  2126. if(params[1].GetAt(k)==',') count++;
  2127. }
  2128. char c[50];
  2129. itoa(count, c, 10);
  2130. variables[params[0]]=c;
  2131. }
  2132. else if(name==ID_ALLOW_DELETE)
  2133. {
  2134. if(paramcount<1)
  2135. {
  2136. ReportScriptError(i);
  2137. delete[] params;
  2138. break;
  2139. }
  2140. // check bool
  2141. if(paramcount>1)
  2142. {
  2143. if(params[1].GetLength()>0)
  2144. {
  2145. if(!IsValSet(params[1])) goto nextline;
  2146. }
  2147. }
  2148. {
  2149. CString s;
  2150. s="This script wants to delete objects or triggers from your map. For some scripts this may be necessary, but it can seriously damage your map. Reason why script wants to delete objects:\n";
  2151. s+=params[0];
  2152. s+="\n\nDo you want to allow the script to do this?";
  2153. int res=MessageBox(s, "Allow deletion of objects?", MB_YESNO | MB_DEFBUTTON2);
  2154. if(res==IDNO) goto nextline;
  2155. }
  2156. bDeleteAllowed=TRUE;
  2157. }
  2158. else if(name==ID_ALLOW_ADD)
  2159. {
  2160. if(paramcount<1)
  2161. {
  2162. ReportScriptError(i);
  2163. delete[] params;
  2164. break;
  2165. }
  2166. // check bool
  2167. if(paramcount>1)
  2168. {
  2169. if(params[1].GetLength()>0)
  2170. {
  2171. if(!IsValSet(params[1])) goto nextline;
  2172. }
  2173. }
  2174. {
  2175. CString s;
  2176. s="This script wants to add objects or triggers to your map. For some scripts this may be necessary, but it can seriously damage your map. Reason why script wants to add objects:\n";
  2177. s+=params[0];
  2178. s+="\n\nDo you want to allow the script to do this?";
  2179. int res=MessageBox(s, "Allow adding of objects?", MB_YESNO | MB_DEFBUTTON2);
  2180. if(res==IDNO) goto nextline;
  2181. }
  2182. bAddAllowed=TRUE;
  2183. }
  2184. else if(name==ID_DELETE_TERRAIN)
  2185. {
  2186. if(paramcount<1)
  2187. {
  2188. ReportScriptError(i);
  2189. delete[] params;
  2190. break;
  2191. }
  2192. // check bool
  2193. if(paramcount>1)
  2194. {
  2195. if(params[1].GetLength()>0)
  2196. {
  2197. if(!IsValSet(params[1])) goto nextline;
  2198. }
  2199. }
  2200. if(!bDeleteAllowed ) goto nextline;
  2201. int index=atoi(params[0]);
  2202. if(index<0 || index>=Map->GetTerrainCount())
  2203. {
  2204. report+="Terrain deletion failed, invalid index\r\n";
  2205. goto nextline;
  2206. }
  2207. lastTerrainDeleted=index;
  2208. Map->DeleteTerrain(index);
  2209. report+="Terrain deleted\r\n";
  2210. bUpdate=TRUE;
  2211. bUpdateOnlyMission=FALSE;
  2212. }
  2213. else if(name==ID_DELETE_INFANTRY)
  2214. {
  2215. if(paramcount<1)
  2216. {
  2217. ReportScriptError(i);
  2218. delete[] params;
  2219. break;
  2220. }
  2221. // check bool
  2222. if(paramcount>1)
  2223. {
  2224. if(params[1].GetLength()>0)
  2225. {
  2226. if(!IsValSet(params[1])) goto nextline;
  2227. }
  2228. }
  2229. if(!bDeleteAllowed ) goto nextline;
  2230. int index=atoi(params[0]);
  2231. if(index<0 || index>=Map->GetInfantryCount())
  2232. {
  2233. report+="Infantry deletion failed, invalid index\r\n";
  2234. goto nextline;
  2235. }
  2236. lastInfantryDeleted=index;
  2237. Map->DeleteInfantry(index);
  2238. report+="Infantry deleted\r\n";
  2239. bUpdate=TRUE;
  2240. bUpdateOnlyMission=FALSE;
  2241. }
  2242. else if(name==ID_DELETE_STRUCTURE)
  2243. {
  2244. if(paramcount<1)
  2245. {
  2246. ReportScriptError(i);
  2247. delete[] params;
  2248. break;
  2249. }
  2250. // check bool
  2251. if(paramcount>1)
  2252. {
  2253. if(params[1].GetLength()>0)
  2254. {
  2255. if(!IsValSet(params[1])) goto nextline;
  2256. }
  2257. }
  2258. if(!bDeleteAllowed ) goto nextline;
  2259. int index=atoi(params[0]);
  2260. if(index<0 || index>=Map->GetStructureCount())
  2261. {
  2262. report+="Structure deletion failed, invalid index\r\n";
  2263. goto nextline;
  2264. }
  2265. lastStructureDeleted=*ini.sections["Structures"].GetValueName(index);
  2266. Map->DeleteStructure(index);
  2267. report+="Structure deleted\r\n";
  2268. bUpdate=TRUE;
  2269. bUpdateOnlyMission=FALSE;
  2270. }
  2271. else if(name==ID_DELETE_VEHICLE)
  2272. {
  2273. if(paramcount<1)
  2274. {
  2275. ReportScriptError(i);
  2276. delete[] params;
  2277. break;
  2278. }
  2279. // check bool
  2280. if(paramcount>1)
  2281. {
  2282. if(params[1].GetLength()>0)
  2283. {
  2284. if(!IsValSet(params[1])) goto nextline;
  2285. }
  2286. }
  2287. if(!bDeleteAllowed ) goto nextline;
  2288. int index=atoi(params[0]);
  2289. if(index<0 || index>=Map->GetUnitCount())
  2290. {
  2291. report+="Vehicle deletion failed, invalid index\r\n";
  2292. goto nextline;
  2293. }
  2294. lastUnitDeleted=*ini.sections["Units"].GetValueName(index);
  2295. Map->DeleteUnit(index);
  2296. report+="Vehicle deleted\r\n";
  2297. bUpdate=TRUE;
  2298. bUpdateOnlyMission=FALSE;
  2299. }
  2300. else if(name==ID_DELETE_AIRCRAFT)
  2301. {
  2302. if(paramcount<1)
  2303. {
  2304. ReportScriptError(i);
  2305. delete[] params;
  2306. break;
  2307. }
  2308. // check bool
  2309. if(paramcount>1)
  2310. {
  2311. if(params[1].GetLength()>0)
  2312. {
  2313. if(!IsValSet(params[1])) goto nextline;
  2314. }
  2315. }
  2316. if(!bDeleteAllowed ) goto nextline;
  2317. int index=atoi(params[0]);
  2318. if(index<0 || index>=Map->GetAircraftCount())
  2319. {
  2320. report+="Aircraft deletion failed, invalid index\r\n";
  2321. goto nextline;
  2322. }
  2323. lastAircraftDeleted=*ini.sections["Aircraft"].GetValueName(index);
  2324. Map->DeleteAircraft(index);
  2325. report+="Aircraft deleted\r\n";
  2326. bUpdate=TRUE;
  2327. bUpdateOnlyMission=FALSE;
  2328. }
  2329. else if(name==ID_IS_INFANTRY_DELETED)
  2330. {
  2331. if(paramcount<2)
  2332. {
  2333. ReportScriptError(i);
  2334. delete[] params;
  2335. break;
  2336. }
  2337. // check bool
  2338. if(paramcount>2)
  2339. {
  2340. if(params[2].GetLength()>0)
  2341. {
  2342. if(!IsValSet(params[2])) goto nextline;
  2343. }
  2344. }
  2345. CString deleted="1";
  2346. int index=atoi(params[1]);
  2347. if(index>=0 && index<Map->GetInfantryCount())
  2348. {
  2349. INFANTRY id;
  2350. Map->GetInfantryData(index, &id);
  2351. if(id.deleted==0) deleted="0";
  2352. }
  2353. variables[params[0]]=deleted;
  2354. }
  2355. else if(name==ID_IS_TERRAIN_DELETED)
  2356. {
  2357. if(paramcount<2)
  2358. {
  2359. ReportScriptError(i);
  2360. delete[] params;
  2361. break;
  2362. }
  2363. // check bool
  2364. if(paramcount>2)
  2365. {
  2366. if(params[2].GetLength()>0)
  2367. {
  2368. if(!IsValSet(params[2])) goto nextline;
  2369. }
  2370. }
  2371. CString deleted="1";
  2372. int index=atoi(params[1]);
  2373. if(index>=0 && index<Map->GetTerrainCount())
  2374. {
  2375. TERRAIN id;
  2376. Map->GetTerrainData(index, &id);
  2377. if(id.deleted==0) deleted="0";
  2378. }
  2379. variables[params[0]]=deleted;
  2380. }
  2381. else if(name==ID_ADD_INFANTRY)
  2382. {
  2383. if(paramcount<1)
  2384. {
  2385. ReportScriptError(i);
  2386. delete[] params;
  2387. break;
  2388. }
  2389. // check bool
  2390. if(paramcount>1)
  2391. {
  2392. if(params[1].GetLength()>0)
  2393. {
  2394. if(!IsValSet(params[1])) goto nextline;
  2395. }
  2396. }
  2397. // check param count
  2398. int count=1; // we start at 1 param even if no , exists!
  2399. int k;
  2400. for(k=0;k<params[0].GetLength();k++)
  2401. {
  2402. if(params[0].GetAt(k)==',') count++;
  2403. }
  2404. if(count!=14)
  2405. {
  2406. report+="AddInfantry failed\r\n";
  2407. goto nextline;
  2408. }
  2409. CString data=params[0];
  2410. INFANTRY id;
  2411. id.deleted=0;
  2412. id.house=GetParam(data, 0);
  2413. id.type=GetParam(data, 1);
  2414. id.strength=GetParam(data, 2);
  2415. id.y=GetParam(data, 3);
  2416. id.x=GetParam(data, 4);
  2417. //id.pos=GetParam(data, 5);
  2418. id.pos="-1"; // ignore pos values!
  2419. id.action=GetParam(data, 6);
  2420. id.direction=GetParam(data, 7);
  2421. id.tag=GetParam(data, 8);
  2422. id.flag1=GetParam(data, 9);
  2423. id.flag2=GetParam(data, 10);
  2424. id.flag3=GetParam(data, 11);
  2425. id.flag4=GetParam(data, 12);
  2426. id.flag5=GetParam(data, 13);
  2427. if(Map->AddInfantry(&id, NULL, NULL, NULL, lastInfantryDeleted)==FALSE)
  2428. {
  2429. report+="AddInfantry failed\r\n";
  2430. }
  2431. else
  2432. {
  2433. report+="Infantry added\r\n";
  2434. bUpdate=TRUE;
  2435. bUpdateOnlyMission=FALSE;
  2436. }
  2437. }
  2438. else if(name==ID_ADD_VEHICLE)
  2439. {
  2440. if(paramcount<1)
  2441. {
  2442. ReportScriptError(i);
  2443. delete[] params;
  2444. break;
  2445. }
  2446. // check bool
  2447. if(paramcount>1)
  2448. {
  2449. if(params[1].GetLength()>0)
  2450. {
  2451. if(!IsValSet(params[1])) goto nextline;
  2452. }
  2453. }
  2454. // check param count
  2455. int count=1; // we start at 1 param even if no , exists!
  2456. int k;
  2457. for(k=0;k<params[0].GetLength();k++)
  2458. {
  2459. if(params[0].GetAt(k)==',') count++;
  2460. }
  2461. if(count!=14)
  2462. {
  2463. report+="AddVehicle failed\r\n";
  2464. goto nextline;
  2465. }
  2466. CString data=params[0];
  2467. UNIT unit;
  2468. unit.house=GetParam(data, 0);
  2469. unit.type=GetParam(data, 1);
  2470. unit.strength=GetParam(data, 2);
  2471. unit.y=GetParam(data, 3);
  2472. unit.x=GetParam(data, 4);
  2473. unit.direction=GetParam(data, 5);
  2474. unit.action=GetParam(data, 6);
  2475. unit.tag=GetParam(data, 7);
  2476. unit.flag1=GetParam(data, 8);
  2477. unit.flag2=GetParam(data, 9);
  2478. unit.flag3=GetParam(data, 10);
  2479. unit.flag4=GetParam(data, 11);
  2480. unit.flag5=GetParam(data, 12);
  2481. unit.flag6=GetParam(data, 13);
  2482. if(Map->GetUnitAt(atoi(unit.x)+atoi(unit.y)*Map->GetIsoSize())>=0)
  2483. {
  2484. report+="AddVehicle failed\r\n";
  2485. goto nextline;
  2486. }
  2487. if(Map->AddUnit(&unit, NULL, NULL, NULL, lastUnitDeleted)==FALSE)
  2488. {
  2489. report+="AddVehicle failed\r\n";
  2490. }
  2491. else
  2492. {
  2493. report+="Vehicle added\r\n";
  2494. bUpdate=TRUE;
  2495. bUpdateOnlyMission=FALSE;
  2496. }
  2497. }
  2498. else if(name==ID_ADD_AIRCRAFT)
  2499. {
  2500. if(paramcount<1)
  2501. {
  2502. ReportScriptError(i);
  2503. delete[] params;
  2504. break;
  2505. }
  2506. // check bool
  2507. if(paramcount>1)
  2508. {
  2509. if(params[1].GetLength()>0)
  2510. {
  2511. if(!IsValSet(params[1])) goto nextline;
  2512. }
  2513. }
  2514. // check param count
  2515. int count=1; // we start at 1 param even if no , exists!
  2516. int k;
  2517. for(k=0;k<params[0].GetLength();k++)
  2518. {
  2519. if(params[0].GetAt(k)==',') count++;
  2520. }
  2521. if(count!=12)
  2522. {
  2523. report+="AddAircraft failed\r\n";
  2524. goto nextline;
  2525. }
  2526. CString data=params[0];
  2527. AIRCRAFT air;
  2528. air.house=GetParam(data, 0);
  2529. air.type=GetParam(data, 1);
  2530. air.strength=GetParam(data, 2);
  2531. air.y=GetParam(data, 3);
  2532. air.x=GetParam(data, 4);
  2533. air.direction=GetParam(data, 5);
  2534. air.action=GetParam(data, 6);
  2535. air.tag=GetParam(data, 7);
  2536. air.flag1=GetParam(data, 8);
  2537. air.flag2=GetParam(data, 9);
  2538. air.flag3=GetParam(data, 10);
  2539. air.flag4=GetParam(data, 11);
  2540. if(Map->GetAirAt(atoi(air.x)+atoi(air.y)*Map->GetIsoSize())>=0)
  2541. {
  2542. report+="AddAircraft failed\r\n";
  2543. goto nextline;
  2544. }
  2545. if(Map->AddAircraft(&air, NULL, NULL, NULL, lastAircraftDeleted)==FALSE)
  2546. {
  2547. report+="AddAircraft failed\r\n";
  2548. }
  2549. else
  2550. {
  2551. report+="Aircraft added\r\n";
  2552. bUpdate=TRUE;
  2553. bUpdateOnlyMission=FALSE;
  2554. }
  2555. }
  2556. else if(name==ID_ADD_STRUCTURE)
  2557. {
  2558. if(paramcount<1)
  2559. {
  2560. ReportScriptError(i);
  2561. delete[] params;
  2562. break;
  2563. }
  2564. // check bool
  2565. if(paramcount>1)
  2566. {
  2567. if(params[1].GetLength()>0)
  2568. {
  2569. if(!IsValSet(params[1])) goto nextline;
  2570. }
  2571. }
  2572. // check param count
  2573. int count=1; // we start at 1 param even if no , exists!
  2574. int k;
  2575. for(k=0;k<params[0].GetLength();k++)
  2576. {
  2577. if(params[0].GetAt(k)==',') count++;
  2578. }
  2579. if(count!=17)
  2580. {
  2581. report+="AddStructure failed\r\n";
  2582. goto nextline;
  2583. }
  2584. CString data=params[0];
  2585. STRUCTURE structure;
  2586. structure.house=GetParam(data, 0);
  2587. structure.type=GetParam(data, 1);
  2588. structure.strength=GetParam(data, 2);
  2589. structure.y=GetParam(data, 3);
  2590. structure.x=GetParam(data, 4);
  2591. structure.direction=GetParam(data, 5);
  2592. structure.tag=GetParam(data, 6);
  2593. structure.flag1=GetParam(data, 7);
  2594. structure.flag2=GetParam(data, 8);
  2595. structure.energy=GetParam(data, 9);
  2596. structure.upgradecount=GetParam(data, 10);
  2597. structure.spotlight=GetParam(data, 11);
  2598. structure.upgrade1=GetParam(data, 12);
  2599. structure.upgrade2=GetParam(data, 13);
  2600. structure.upgrade3=GetParam(data, 14);
  2601. structure.flag3=GetParam(data, 15);
  2602. structure.flag4=GetParam(data, 16);
  2603. if(Map->GetStructureAt(atoi(structure.x)+atoi(structure.y)*Map->GetIsoSize())>=0)
  2604. {
  2605. report+="AddStructure failed\r\n";
  2606. goto nextline;
  2607. }
  2608. if(Map->AddStructure(&structure, NULL, NULL, NULL, lastStructureDeleted)==FALSE)
  2609. {
  2610. report+="AddStructure failed\r\n";
  2611. }
  2612. else
  2613. {
  2614. report+="Structure added\r\n";
  2615. bUpdate=TRUE;
  2616. bUpdateOnlyMission=FALSE;
  2617. }
  2618. }
  2619. else if(name==ID_GET_INFANTRY)
  2620. {
  2621. if(paramcount<2)
  2622. {
  2623. ReportScriptError(i);
  2624. delete[] params;
  2625. break;
  2626. }
  2627. // check bool
  2628. if(paramcount>2)
  2629. {
  2630. if(params[2].GetLength()>0)
  2631. {
  2632. if(!IsValSet(params[2])) goto nextline;
  2633. }
  2634. }
  2635. int index=atoi(params[1]);
  2636. CString s;
  2637. if(index>=0 && index<Map->GetInfantryCount())
  2638. {
  2639. INFANTRY id;
  2640. Map->GetInfantryINIData(index, &s);
  2641. }
  2642. variables[params[0]]=s;
  2643. }
  2644. else if(name==ID_GET_AIRCRAFT)
  2645. {
  2646. if(paramcount<2)
  2647. {
  2648. ReportScriptError(i);
  2649. delete[] params;
  2650. break;
  2651. }
  2652. // check bool
  2653. if(paramcount>2)
  2654. {
  2655. if(params[2].GetLength()>0)
  2656. {
  2657. if(!IsValSet(params[2])) goto nextline;
  2658. }
  2659. }
  2660. int index=atoi(params[1]);
  2661. CString s;
  2662. if(index>=0 && index<Map->GetAircraftCount())
  2663. {
  2664. s=*ini.sections["Aircraft"].GetValue(index);
  2665. }
  2666. variables[params[0]]=s;
  2667. }
  2668. else if(name==ID_GET_STRUCTURE)
  2669. {
  2670. if(paramcount<2)
  2671. {
  2672. ReportScriptError(i);
  2673. delete[] params;
  2674. break;
  2675. }
  2676. // check bool
  2677. if(paramcount>2)
  2678. {
  2679. if(params[2].GetLength()>0)
  2680. {
  2681. if(!IsValSet(params[2])) goto nextline;
  2682. }
  2683. }
  2684. int index=atoi(params[1]);
  2685. CString s;
  2686. if(index>=0 && index<Map->GetStructureCount())
  2687. {
  2688. s=*ini.sections["Structures"].GetValue(index);
  2689. }
  2690. variables[params[0]]=s;
  2691. }
  2692. else if(name==ID_GET_VEHICLE)
  2693. {
  2694. if(paramcount<2)
  2695. {
  2696. ReportScriptError(i);
  2697. delete[] params;
  2698. break;
  2699. }
  2700. // check bool
  2701. if(paramcount>2)
  2702. {
  2703. if(params[2].GetLength()>0)
  2704. {
  2705. if(!IsValSet(params[2])) goto nextline;
  2706. }
  2707. }
  2708. int index=atoi(params[1]);
  2709. CString s;
  2710. if(index>=0 && index<Map->GetUnitCount())
  2711. {
  2712. s=*ini.sections["Units"].GetValue(index);
  2713. }
  2714. variables[params[0]]=s;
  2715. }
  2716. else if(name==ID_GET_HOUSE)
  2717. {
  2718. if(paramcount<2)
  2719. {
  2720. ReportScriptError(i);
  2721. delete[] params;
  2722. break;
  2723. }
  2724. // check bool
  2725. if(paramcount>2)
  2726. {
  2727. if(params[2].GetLength()>0)
  2728. {
  2729. if(!IsValSet(params[2])) goto nextline;
  2730. }
  2731. }
  2732. int index=atoi(params[1]);
  2733. CString s;
  2734. if(index>=0 && index<Map->GetHousesCount(FALSE))
  2735. {
  2736. s=Map->GetHouseID(index, FALSE);
  2737. }
  2738. variables[params[0]]=s;
  2739. }
  2740. else if(name==ID_GET_COUNTRY)
  2741. {
  2742. if(paramcount<2)
  2743. {
  2744. ReportScriptError(i);
  2745. delete[] params;
  2746. break;
  2747. }
  2748. // check bool
  2749. if(paramcount>2)
  2750. {
  2751. if(params[2].GetLength()>0)
  2752. {
  2753. if(!IsValSet(params[2])) goto nextline;
  2754. }
  2755. }
  2756. int index=atoi(params[1]);
  2757. CString s;
  2758. if(index>=0 && index<Map->GetHousesCount(TRUE))
  2759. {
  2760. s=Map->GetHouseID(index, TRUE);
  2761. }
  2762. variables[params[0]]=s;
  2763. }
  2764. else
  2765. {
  2766. ReportScriptError(i);
  2767. delete[] params;
  2768. break;
  2769. }
  2770. nextline:
  2771. if(bAutoUpdate)
  2772. {
  2773. m_Report=report;
  2774. UpdateData(FALSE);
  2775. }
  2776. nextline_no_update:
  2777. delete[] params;
  2778. }
  2779. for(i=0;i<functions.size();i++)
  2780. {
  2781. delete[] functions[i].params;
  2782. functions[i].params=NULL;
  2783. }
  2784. m_Report=report;
  2785. UpdateData(FALSE);
  2786. //if(bUpdateWaypoints) Map->UpdateIniFile(MAPDATA_UPDATE_FROM_INI);
  2787. if(bUpdate) ((CFinalSunDlg*)theApp.GetMainWnd())->UpdateDialogs(bUpdateOnlyMission, bNoRepos);
  2788. // CDialog::OnOK();
  2789. }
  2790. BOOL CUserScriptsDlg::OnInitDialog()
  2791. {
  2792. CDialog::OnInitDialog();
  2793. int k;
  2794. CFileFind ff;
  2795. CString scripts=(CString)AppPath+"\\Scripts\\*.fscript";
  2796. {
  2797. CFileFind ff;
  2798. if(ff.FindFile(scripts))
  2799. {
  2800. CListBox* lb=(CListBox*)GetDlgItem(IDC_SCRIPTS);
  2801. BOOL bWorking=TRUE;
  2802. while(bWorking)
  2803. {
  2804. bWorking=ff.FindNextFile();
  2805. lb->AddString(ff.GetFileName());
  2806. }
  2807. }
  2808. }
  2809. return TRUE; // return TRUE unless you set the focus to a control
  2810. // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
  2811. }
  2812. void CUserScriptsDlg::ReportScriptError(int line)
  2813. {
  2814. char c[50];
  2815. itoa(line, c, 10);
  2816. MessageBox("Script error in line " + (CString)c + ". Probably wrong parameter count or unknown function call.","Error");
  2817. }