Xorras

MapInitialization

Jul 23rd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. --*********************************************************************
  2. -- Anton Scriptsov/ Xbow Software - Copyright (C) 2003
  3. -- Author: AntiPoD
  4. -- Date: 28.11.2002
  5. -- Time: 11:25
  6. -- Abstract: Основные функции для обеспечения работы скриптовой системы
  7. --*********************************************************************/
  8.  
  9. -- Edited '24.07.2015::10:57' by Nocalora29: Added new root folder from where new Lua/script Files can be Executed.
  10. -- 30.09.2015: Optimized Logging Capabilities, by adding an Indexing Feature for the Addons.
  11. -- Reason: Mainly so it becomes easier to sort out Mod-Files from Game-Files
  12. -- 07.03.2017 - Nocalora: Updated the Addonloader to support an embedded Autorun
  13.  
  14. --REGISTER YOUR ADDONS HERE !!!
  15. --WARNING: This embedded Autorun has a Higher load Priority than SW3 Expansion's GetFollowers() Init Hook, so if -
  16. -- - you use this Autorun, make sure it doesn't rely on SW3EXP Functions
  17. -- "Addon Name", "Content-Type", {Table of Functions to be Executed}
  18. __AddonsList = {
  19. --Addons
  20. {"MGVE", "Inactive"},
  21. {"MQLE", "Addon"},
  22. {"PPHooks", "Addon"},
  23. {"StarRover", "Addon"},
  24. {"SW3_Expansion", "Addon"},
  25. {"Motherships_Mod_0.27", "Addon"},
  26. {"Fleet_Mod", "Addon"},
  27. {"Plugins", "Addon"},
  28.  
  29. --Core Scripts
  30. {"Data/Scripts/", "Core"}
  31. };
  32. -- Content Types:
  33. -- Inactive: Will not be Loaded
  34. -- Addon: Will be loaded as an Addon
  35. -- Core: Core game files/Scripts
  36. --REGISTER YOUR ADDONS HERE !!!
  37.  
  38. --//////////// DEFINES //////////////////
  39. TRUE = 1;
  40. FALSE = 0;
  41.  
  42. --//////////// DEFINES //////////////////
  43. -- Standart functions library
  44.  
  45. -- относительный путь к скиптам
  46. _script_path = "DATA/Scripts/";
  47.  
  48. -- имя файла скриптовых ошибок
  49. userfolder = GetUserFolder();
  50. userfolder = userfolder.."ScriptErrors.log";
  51. _script_error_filename = userfolder;
  52.  
  53. -- хэндлер файла скриптовых ошибок
  54. _script_error_output = openfile(_script_error_filename, "w");
  55.  
  56. --/////////// INDEXED ADDONS ///////////////
  57. ADDONS = 0;
  58. --/////////// INDEXED ADDONS ///////////////
  59.  
  60. --/////////// LOAD PRIORITY ///////////////
  61. -- 0 = Game Scripts have Priority
  62. -- 1 = Addon Scripts have Priority
  63. LOADPRIORITY = 1;
  64. --/////////// LOAD PRIORITY ///////////////
  65.  
  66. -- перехватчик для отображения в лог файле информации об ошибках произошедших в скрипте
  67. function _ALERT(error)
  68. write(_script_error_output, error);
  69. --flush(_script_error_output);
  70. --closefile(_script_error_output);
  71.  
  72. --SLOG(" Error: look at ".._script_error_filename.." file");
  73. --LOG(" Error: look at ".._script_error_filename.." file");
  74. SLOG(error);
  75. LOG(error);
  76.  
  77. end
  78.  
  79. -- функция для вывода ошибки в лог файл(по умолчанию) или в SLOG - ErrorLog("Trouble", "SLOG")
  80. function ErrorLog(message, to)
  81.  
  82. if (to == nil or to == 'LOG')
  83. then
  84. write(_script_error_output, message);
  85. write(_script_error_output,'\n');
  86. SLOG("Script error: "..message);
  87. LOG("Script error: "..message);
  88. return
  89. end
  90. SLOG(message);
  91. end;
  92.  
  93. -- ======= DIALOG SECTION =======
  94.  
  95. function ProcessDialog()
  96. if Dialog == nil
  97. then
  98. ErrorLog("Have not a Dialog file");
  99. return
  100. end
  101.  
  102. local dialog = CreateDlg(Dialog.name, Dialog.dialogID);--, Dialog.dialogInitializingScript
  103.  
  104. print(dialog.classname, dialog.id);
  105. for k, i in Dialog.DialogSheetEntres
  106. do
  107. --print("Dialog stuff:"..dialog.classname.." "..dialog.id);
  108. local sheet = CreateDlgSheet(dialog, i.sheetID, i.question);
  109. --print("sheet stuff:"..sheet.classname.." "..sheet.id);
  110. --print(Dialog.DialogSheetEntres[k].question);
  111.  
  112. for _,j in Dialog.DialogSheetEntres[k].answers
  113. do
  114. AddAnswerToDlgSheet(dialog, sheet, j.answer, j.to, j.script);
  115. end;
  116. end;
  117. end;
  118.  
  119. -- Обработчик данных содержащихся в файле
  120. function ProcessQuest()
  121. if Quest == nil
  122. then
  123. ErrorLog("Have not a Quest file");
  124. return
  125. end;
  126.  
  127. local quest = CreateQuest(Quest.id, Quest.name, Quest.desc);
  128.  
  129. for k, i in Quest.Objectives
  130. do
  131. quest:AddObjectiveToQuest(i.desc, OBJECTIVE_INPROCESS);
  132. end;
  133.  
  134. --sentinel
  135. -- для невозможности считывания повторных данных без считывания файла
  136. ret = {id = Quest.id};
  137. Quest = nil;
  138.  
  139. settag(ret, TAG_QUEST);
  140. SLOG("TAG_QUEST is "..TAG_QUEST);
  141. return ret;
  142. end;
  143.  
  144. function ParseQuestFilesList(file)
  145. if file == nil
  146. then
  147. file = _script_path.."questFiles.lst";
  148. end;
  149. ExecuteScriptFile(file);
  150. SLOG("DO FILE DONE.....");
  151. for _, val in sys_questFiles
  152. do
  153. ExecuteScriptFile(_script_path..val);
  154. ProcessQuest();
  155. end;
  156. end;
  157. -- подключение файлов необходимых для скриптового движка
  158. function LoadLevel(path)
  159. if (path == nil)
  160. then
  161. ErrorLog("Can't load level! Path is undefined!");
  162. return FALSE;
  163. else
  164. file = path.."level.lst";
  165. end;
  166.  
  167. ret = ExecuteScriptFile(file);
  168. if (ret == nil)
  169. then
  170. return FALSE;
  171. end;
  172.  
  173. if sys_IncludeFileList == nil
  174. then
  175. ErrorLog("Can't parse IncludeFiles List. File is invalid");
  176. return
  177. end;
  178.  
  179. for _, val in sys_IncludeFileList
  180. do
  181. --SLOG("1Open "..path..val);
  182. local ret = ExecuteScriptFile(path..val);
  183. if (ret == nil)
  184. then
  185. return FALSE;
  186. end;
  187. end;
  188.  
  189.  
  190. end;
  191.  
  192. function ParseSystemScripts(path)
  193. if (path == nil)
  194. then
  195. file = "DATA/Scripts/system.lst";
  196. else
  197. file = path.."system.lst";
  198. end;
  199.  
  200. --SLOG("Loading "..file);
  201. ret = ExecuteScriptFile(file);
  202. if (ret == nil)
  203. then
  204. return FALSE;
  205. end;
  206.  
  207. if sys_IncludeFileList == nil
  208. then
  209. ErrorLog("Can't parse IncludeFiles List. File is invalid");
  210. return
  211. end;
  212.  
  213. for _, val in sys_IncludeFileList
  214. do
  215. local ret = ExecuteScriptFile(path..val);
  216. if (ret == nil)
  217. then
  218. return FALSE;
  219. end;
  220. end;
  221. end;
  222.  
  223.  
  224. function ParseSystemScripts_Edited(path)
  225.  
  226. if (path == nil)
  227. then
  228. -- Execute Plugins
  229. file = "DATA/Addons/@Plugins/system.lst";
  230. else
  231. file = path.."system.lst";
  232. end;
  233.  
  234. --SLOG("Loading "..file);
  235. ret = ExecuteScriptFile(file);
  236. if (ret == nil)
  237. then
  238. return FALSE;
  239. end;
  240.  
  241. if sys_IncludeFileList == nil
  242. then
  243. ErrorLog("Can't parse IncludeFiles List. File is invalid");
  244. return
  245. end;
  246.  
  247. for _, val in sys_IncludeFileList
  248. do
  249. local ret = ExecuteScriptFile(path..val);
  250.  
  251. if (ret == nil)
  252. then
  253. return FALSE;
  254. end;
  255. end;
  256. end;
  257.  
  258. -- End of Standart functions library
  259.  
  260. -- ////////// REGISTERED EVENTS /////////
  261. EVENT_MAP_INITIALIZING = 1;
  262. EVENT_SELECTED = 2;
  263. EVENT_DESELECTED = 3;
  264. EVENT_DIALOG_ACTIVATED = 4;
  265. EVENT_DIALOG_ITEM_SELECTED = 5;
  266. -- ////////// REGISTERED EVENTS /////////
  267.  
  268. -- MAP INITIALIZING Script
  269. function MapInitializing()
  270. unit_0001 = 1;
  271. condition = TRUE;
  272. print("Map initializing.....completed");
  273.  
  274. end;
  275.  
  276. function MapInitializing_Condition()
  277. print("MapInitializing_Condition executed...");
  278. return TRUE;
  279. end;
  280. -- MAP INITIALIZING Script
  281.  
  282. --SW3EXP Addons folder Prefix Function
  283. function ExecuteModScripts(ModFName)
  284. ADDONS = ADDONS + 1;
  285. LOG("SW3EXP::Addon-System-> Adding Mod INDEX["..ADDONS.."]: '"..ModFName.."'");
  286.  
  287. ParseSystemScripts_Edited("DATA/Addons/"..ModFName.."/");
  288. LOG("SW3EXP::Addon-System-> Mod INDEX["..ADDONS.."]: '".. ModFName.."' Successfully Added.");
  289. end
  290.  
  291. --ParseQuestFilesList();
  292.  
  293. -- Include base library files
  294.  
  295. --New Plugin Loader
  296. --AddonLoader
  297. function AddonLoader()
  298. LOG("SW3EXP::ADDONLOADER: Beginning Operation...");
  299.  
  300. --Process all Objects inside Table.
  301. for Addon, CurAddon in __AddonsList do
  302.  
  303. --Check Property
  304. if CurAddon[2] == "Addon" then
  305. ExecuteModScripts("@"..CurAddon[1]);
  306.  
  307. --Auto Execute Functions
  308. if (CurAddon[3]) then
  309. LOG("SW3EXP::ADDONLOADER: Addon '"..CurAddon[1].."' Has an Active Autorun routine.");
  310. for AllFunctions, CurrentFunction in CurAddon[3] do
  311. LOG("SW3EXP::ADDONLOADER: Addon '"..CurAddon[1].."' AUTORUN-> Executes: "..tostring(CurrentFunction));
  312. getglobal(CurrentFunction)();
  313. end;
  314. end;
  315. end;
  316.  
  317. if CurAddon[2] == "Core" then
  318. ParseSystemScripts(CurAddon[1]);
  319. end;
  320.  
  321. if CurAddon[2] == "Inactive" then
  322. --Ignore
  323. LOG("SW3EXP::ADDONLOADER: Addon '"..CurAddon[1].."' is Inactive!");
  324. end;
  325.  
  326. end;--for Objects, CurObject in ObjectsTable do
  327.  
  328. LOG("SW3EXP::ADDONLOADER: Operation Complete.");
  329. end;
  330.  
  331. AddonLoader();
Advertisement
Add Comment
Please, Sign In to add comment