Test_RMV_Toolkit.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  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. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * Test_RMV_Toolkit.cpp
  22. *
  23. * DESCRIPTION
  24. * Additional Toolkit Scripts
  25. *
  26. * PROGRAMMER
  27. * Ryan Vervack
  28. *
  29. * VERSION INFO
  30. * $Author: Dan_e $
  31. * $Revision: 154 $
  32. * $Modtime: 11/03/01 11:18a $
  33. * $Archive: /Commando/Code/Scripts/Test_RMV_Toolkit.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "scripts.h"
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include "toolkit.h"
  40. enum {
  41. TECHNICIAN_MOVEMENT,
  42. TECHNICIAN_ANIMATION
  43. };
  44. DECLARE_SCRIPT(RMV_Trigger_Zone, "TargetID:int, Type:int, Param:int")
  45. {
  46. void Entered(GameObject * obj, GameObject * enterer)
  47. {
  48. if (Commands->Is_A_Star(enterer))
  49. {
  50. int type = Get_Int_Parameter("Type");
  51. int param = Get_Int_Parameter("Param");
  52. GameObject *target = Commands->Find_Object(Get_Int_Parameter("TargetID"));
  53. if (target)
  54. Commands->Send_Custom_Event(obj, target, type, param);
  55. if (obj)
  56. Commands->Destroy_Object(obj);
  57. }
  58. }
  59. };
  60. DECLARE_SCRIPT(RMV_Trigger_Zone_2, "TargetID:int, Type:int, Param:int")
  61. {
  62. void Entered(GameObject * obj, GameObject * enterer)
  63. {
  64. if (Commands->Is_A_Star(enterer))
  65. {
  66. int type = Get_Int_Parameter("Type");
  67. int param = Get_Int_Parameter("Param");
  68. GameObject *target = Commands->Find_Object(Get_Int_Parameter("TargetID"));
  69. if (target)
  70. Commands->Send_Custom_Event(obj, target, type, param);
  71. }
  72. }
  73. };
  74. DECLARE_SCRIPT(RMV_Trigger_Poked, "Target_ID:int, Type:int, Param:int")
  75. {
  76. void Poked(GameObject * obj, GameObject * poker)
  77. {
  78. int type = Get_Int_Parameter("Type");
  79. int param = Get_Int_Parameter("Param");
  80. GameObject * target;
  81. if (Get_Int_Parameter("Target_ID") == 0)
  82. {
  83. target = poker;
  84. }
  85. else
  86. {
  87. target = Commands->Find_Object(Get_Int_Parameter("Target_ID"));
  88. }
  89. if (target)
  90. {
  91. Commands->Send_Custom_Event(obj, target, type, param);
  92. }
  93. }
  94. };
  95. DECLARE_SCRIPT(RMV_Engineer_Wander, "Custom_Type:int, Custom_Param_1:int, Custom_Param_2:int, Building_Number:int, Evac_Object=None:string")
  96. {
  97. int c_type, c_param_1, c_param_2;
  98. int terminal_id, int_anim;
  99. bool busy, emergency, always_run, evacuating;
  100. REGISTER_VARIABLES()
  101. {
  102. SAVE_VARIABLE(c_type, 1);
  103. SAVE_VARIABLE(c_param_1, 2);
  104. SAVE_VARIABLE(c_param_2, 3);
  105. SAVE_VARIABLE(terminal_id, 4);
  106. SAVE_VARIABLE(int_anim, 5);
  107. SAVE_VARIABLE(busy, 6);
  108. SAVE_VARIABLE(emergency, 7);
  109. SAVE_VARIABLE(always_run, 8);
  110. SAVE_VARIABLE(evacuating, 9);
  111. }
  112. void Created(GameObject * obj)
  113. {
  114. busy = emergency = always_run = evacuating = false;
  115. c_type = Get_Int_Parameter("Custom_Type");
  116. c_param_1 = Get_Int_Parameter("Custom_Param_1");
  117. c_param_2 = Get_Int_Parameter("Custom_Param_2");
  118. }
  119. void Sound_Heard(GameObject * obj, const CombatSound & sound)
  120. {
  121. if (evacuating)
  122. {
  123. return;
  124. }
  125. if ((sound.Type == M00_SOUND_ENGINEER_WANDER) && (!busy))
  126. {
  127. emergency = false;
  128. if (always_run)
  129. {
  130. emergency = true;
  131. }
  132. Commands->Send_Custom_Event(obj, sound.Creator, c_type, c_param_1);
  133. }
  134. else if (sound.Type == M00_SOUND_ENGINEER_WANDER_EMERGENCY && !busy)
  135. {
  136. emergency = true;
  137. Commands->Send_Custom_Event(obj, sound.Creator, c_type, c_param_1);
  138. }
  139. else if (sound.Type == M00_SOUND_BUILDING_DESTROYED + Get_Int_Parameter("Building_Number"))
  140. {
  141. Evacuate();
  142. }
  143. else if (sound.Type == M00_SOUND_ALWAYS_RUN)
  144. {
  145. always_run = true;
  146. }
  147. else if (sound.Type == M00_SOUND_ALWAYS_RUN_OFF)
  148. {
  149. always_run = false;
  150. }
  151. }
  152. void Evacuate(void)
  153. {
  154. const char* evac = Get_Parameter("Evac_Object");
  155. Commands->Action_Reset(Owner(), 99);
  156. evacuating = true;
  157. if (stricmp(evac, "None") == 0)
  158. {
  159. return;
  160. }
  161. else
  162. {
  163. GameObject * my_evac_point = Commands->Find_Random_Simple_Object(evac);
  164. if (my_evac_point)
  165. {
  166. ActionParamsStruct params;
  167. params.Set_Basic(this, 99, 0);
  168. params.Set_Movement(my_evac_point, RUN, 2.0f);
  169. Commands->Action_Goto(Owner(), params);
  170. }
  171. }
  172. }
  173. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  174. {
  175. if (type == c_type)
  176. {
  177. busy = true;
  178. terminal_id = Commands->Get_ID(sender);
  179. char *anim;
  180. anim = (char *)param;
  181. int_anim = (int)anim;
  182. ActionParamsStruct params;
  183. params.Set_Basic(this, 70, TECHNICIAN_MOVEMENT);
  184. params.Set_Movement(sender, emergency ? RUN : WALK, 0.75f);
  185. Commands->Action_Goto(obj, params);
  186. }
  187. }
  188. void Action_Complete(GameObject * obj, int action_id, ActionCompleteReason reason)
  189. {
  190. if (action_id == TECHNICIAN_MOVEMENT)
  191. {
  192. if (reason != ACTION_COMPLETE_NORMAL)
  193. return;
  194. GameObject *terminal;
  195. terminal = Commands->Find_Object(terminal_id);
  196. if (terminal)
  197. {
  198. float facing = Commands->Get_Facing(terminal);
  199. Commands->Set_Facing(obj, facing + 180);
  200. }
  201. char *anim;
  202. anim = (char *)int_anim;
  203. anim = "s_a_human.h_a_con2";
  204. ActionParamsStruct params;
  205. params.Set_Basic(this, 70, TECHNICIAN_ANIMATION);
  206. params.Set_Animation(anim, false);
  207. Commands->Action_Play_Animation(obj, params);
  208. }
  209. if (action_id == TECHNICIAN_ANIMATION || reason == ACTION_COMPLETE_MOVE_NO_PROGRESS_MADE)
  210. {
  211. GameObject *terminal;
  212. terminal = Commands->Find_Object(terminal_id);
  213. Commands->Send_Custom_Event(obj, terminal, c_type, c_param_2);
  214. busy = emergency = false;
  215. if (always_run)
  216. {
  217. emergency = true;
  218. }
  219. }
  220. }
  221. };
  222. /*DECLARE_SCRIPT(RMV_Engineer_Wander_Terminal, "Animation_Name:string, Custom_Type:int, Custom_Param_1:int, Custom_Param_2:int")
  223. {
  224. enum {ENGINEER_WANDER_TIMER};
  225. bool i_am_occupied;
  226. Vector3 mypos;
  227. int c_type, c_param_1, c_param_2;
  228. REGISTER_VARIABLES()
  229. {
  230. SAVE_VARIABLE(i_am_occupied, 1);
  231. SAVE_VARIABLE(mypos, 2);
  232. SAVE_VARIABLE(c_type, 3);
  233. SAVE_VARIABLE(c_param_1, 4);
  234. SAVE_VARIABLE(c_param_2, 5);
  235. }
  236. void Created(GameObject * obj)
  237. {
  238. // Commands->Enable_Hibernation(obj, false);
  239. i_am_occupied = false;
  240. mypos = Commands->Get_Position(obj);
  241. c_type = Get_Int_Parameter("Custom_Type");
  242. c_param_1 = Get_Int_Parameter("Custom_Param_1");
  243. c_param_2 = Get_Int_Parameter("Custom_Param_2");
  244. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  245. }
  246. void Timer_Expired(GameObject * obj, int timer_id)
  247. {
  248. if ((timer_id == ENGINEER_WANDER_TIMER) && (!i_am_occupied))
  249. {
  250. Commands->Create_Logical_Sound(obj, M00_SOUND_ENGINEER_WANDER, mypos, 60.0f);
  251. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  252. }
  253. }
  254. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  255. {
  256. if ((type == c_type) && (param == c_param_1) && (!i_am_occupied))
  257. {
  258. i_am_occupied = true;
  259. const char *anim;
  260. anim = Get_Parameter("Animation_Name");
  261. Commands->Send_Custom_Event(obj, sender, c_type, (int)anim);
  262. }
  263. if ((type == c_type) && (param == c_param_2) && (i_am_occupied))
  264. {
  265. i_am_occupied = false;
  266. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  267. }
  268. }
  269. };*/
  270. DECLARE_SCRIPT(RMV_Building_Engineer_Controller, "Killed_Broadcast_Radius:float, 25_Start_ID:int, 25_Number:int, 50_Start_ID:int, 50_Number:int, 75_Start_ID:int, 75_Number:int, Building_Number:int")
  271. {
  272. bool sent_25, sent_50, sent_75;
  273. REGISTER_VARIABLES()
  274. {
  275. SAVE_VARIABLE(sent_25, 1);
  276. SAVE_VARIABLE(sent_50, 2);
  277. SAVE_VARIABLE(sent_75, 3);
  278. }
  279. void Created(GameObject * obj)
  280. {
  281. sent_25 = sent_50 = sent_75 = false;
  282. }
  283. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  284. {
  285. if (type == CUSTOM_EVENT_BUILDING_DAMAGED)
  286. {
  287. float percentage = 1 - ((float)param/100.0f);
  288. if (!sent_25 && percentage >= 0.25)
  289. {
  290. Commands->Debug_Message("Building took 25 percent or more damage, notifying engineers.\n");
  291. sent_25 = true;
  292. for (int x = 0; x < Get_Int_Parameter("25_Number"); x++)
  293. {
  294. GameObject * target = Commands->Find_Object(Get_Int_Parameter("25_Start_ID") + x);
  295. if (target)
  296. {
  297. Commands->Send_Custom_Event(obj, target, 1000, 1000);
  298. }
  299. }
  300. }
  301. if (!sent_50 && percentage >= 0.50)
  302. {
  303. Commands->Debug_Message("Building took 50 percent or more damage, notifying engineers.\n");
  304. Vector3 mypos = Commands->Get_Position(obj);
  305. Commands->Create_Logical_Sound(obj, M00_SOUND_ALWAYS_RUN, mypos, Get_Float_Parameter("Killed_Broadcast_Radius"));
  306. sent_50 = true;
  307. for (int x = 0; x < Get_Int_Parameter("50_Number"); x++)
  308. {
  309. GameObject * target = Commands->Find_Object(Get_Int_Parameter("50_Start_ID") + x);
  310. if (target)
  311. {
  312. Commands->Send_Custom_Event(obj, target, 1000, 1000);
  313. }
  314. }
  315. }
  316. if (!sent_75 && percentage >= 0.75)
  317. {
  318. Commands->Debug_Message("Building took 75 percent or more damages, notifying engineers.\n");
  319. sent_75 = true;
  320. for (int x = 0; x < Get_Int_Parameter("75_Number"); x++)
  321. {
  322. GameObject * target = Commands->Find_Object(Get_Int_Parameter("75_Start_ID") + x);
  323. if (target)
  324. {
  325. Commands->Send_Custom_Event(obj, target, 1000, 1000);
  326. }
  327. }
  328. }
  329. }
  330. if (type == CUSTOM_EVENT_BUILDING_REPAIRED)
  331. {
  332. float percentage = 1 - ((float)param/100.0f);
  333. if (percentage <= 0.25)
  334. {
  335. Commands->Debug_Message("Building repaired to 75 percent or more health, notifying engineers.\n");
  336. sent_25 = false;
  337. for (int x = 0; x < Get_Int_Parameter("25_Number"); x++)
  338. {
  339. GameObject * target = Commands->Find_Object(Get_Int_Parameter("25_Start_ID") + x);
  340. if (target)
  341. {
  342. Commands->Send_Custom_Event(obj, target, 2000, 2000);
  343. }
  344. }
  345. }
  346. if (percentage <= 0.50)
  347. {
  348. Commands->Debug_Message("Building repaired to 50 percent or more health, notifying engineers.\n");
  349. Vector3 mypos = Commands->Get_Position(obj);
  350. Commands->Create_Logical_Sound(obj, M00_SOUND_ALWAYS_RUN_OFF, mypos, Get_Float_Parameter("Killed_Broadcast_Radius"));
  351. sent_50 = false;
  352. for (int x = 0; x < Get_Int_Parameter("50_Number"); x++)
  353. {
  354. GameObject * target = Commands->Find_Object(Get_Int_Parameter("50_Start_ID") + x);
  355. if (target)
  356. {
  357. Commands->Send_Custom_Event(obj, target, 2000, 2000);
  358. }
  359. }
  360. }
  361. if (percentage <= 0.75)
  362. {
  363. Commands->Debug_Message("Building repaired to 25 percent or more health, notifying engineers.\n");
  364. sent_75 = false;
  365. for (int x = 0; x < Get_Int_Parameter("75_Number"); x++)
  366. {
  367. GameObject * target = Commands->Find_Object(Get_Int_Parameter("75_Start_ID") + x);
  368. if (target)
  369. {
  370. Commands->Send_Custom_Event(obj, target, 2000, 2000);
  371. }
  372. }
  373. }
  374. }
  375. }
  376. void Killed(GameObject * obj, GameObject * killer)
  377. {
  378. Vector3 mypos = Commands->Get_Position(obj);
  379. Commands->Create_Logical_Sound(obj, M00_SOUND_BUILDING_DESTROYED + Get_Int_Parameter("Building_Number"), mypos, Get_Float_Parameter("Killed_Broadcast_Radius"));
  380. }
  381. };
  382. DECLARE_SCRIPT(RMV_Toggled_Engineer_Target, "Emergency=1:int, Animation_Name:string, Custom_Type:int, Custom_Param_1:int, Custom_Param_2:int")
  383. {
  384. enum {ENGINEER_WANDER_TIMER};
  385. bool i_am_occupied;
  386. Vector3 mypos;
  387. int c_type, c_param_1, c_param_2;
  388. bool active;
  389. REGISTER_VARIABLES()
  390. {
  391. SAVE_VARIABLE(i_am_occupied, 1);
  392. SAVE_VARIABLE(mypos, 2);
  393. SAVE_VARIABLE(c_type, 3);
  394. SAVE_VARIABLE(c_param_1, 4);
  395. SAVE_VARIABLE(c_param_2, 5);
  396. SAVE_VARIABLE(active, 6);
  397. }
  398. void Created(GameObject * obj)
  399. {
  400. active = false;
  401. // Commands->Enable_Hibernation(obj, false);
  402. i_am_occupied = false;
  403. mypos = Commands->Get_Position(obj);
  404. c_type = Get_Int_Parameter("Custom_Type");
  405. c_param_1 = Get_Int_Parameter("Custom_Param_1");
  406. c_param_2 = Get_Int_Parameter("Custom_Param_2");
  407. }
  408. void Timer_Expired(GameObject * obj, int timer_id)
  409. {
  410. if ((timer_id == ENGINEER_WANDER_TIMER) && (!i_am_occupied) && active)
  411. {
  412. Commands->Create_Logical_Sound(obj, (Get_Int_Parameter("Emergency") == 0) ? M00_SOUND_ENGINEER_WANDER : M00_SOUND_ENGINEER_WANDER_EMERGENCY, mypos, 60.0f);
  413. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  414. }
  415. }
  416. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  417. {
  418. if (type == 1000 && param == 1000)
  419. {
  420. active = true;
  421. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  422. }
  423. if (type == 2000 && param == 2000)
  424. {
  425. active = false;
  426. }
  427. if ((type == c_type) && (param == c_param_1) && (!i_am_occupied))
  428. {
  429. i_am_occupied = true;
  430. const char *anim;
  431. anim = Get_Parameter("Animation_Name");
  432. Commands->Send_Custom_Event(obj, sender, c_type, (int)anim);
  433. }
  434. if ((type == c_type) && (param == c_param_2) && (i_am_occupied))
  435. {
  436. i_am_occupied = false;
  437. Commands->Start_Timer(obj, this, 2.0f, ENGINEER_WANDER_TIMER);
  438. }
  439. }
  440. };
  441. DECLARE_SCRIPT(RMV_MCT_Switcher, "")
  442. {
  443. void Killed(GameObject * obj, GameObject * killer)
  444. {
  445. GameObject *temp;
  446. temp = Commands->Create_Object("NOD MCT Off", Commands->Get_Position(obj));
  447. if (obj)
  448. {
  449. Commands->Set_Facing(temp, Commands->Get_Facing(obj));
  450. }
  451. }
  452. };
  453. DECLARE_SCRIPT(M00_Play_Sound, "Sound_Preset:string, Is_3D=1:int, Offset:vector3, Offset_Randomness:vector3, Frequency_Min=-1:float, Frequency_Max:float")
  454. {
  455. void Created(GameObject * obj)
  456. {
  457. if (Get_Int_Parameter("Frequency_Min") == -1)
  458. {
  459. Timer_Expired(obj, 0);
  460. }
  461. else
  462. {
  463. float time = Commands->Get_Random(Get_Float_Parameter("Frequency_Min"), Get_Float_Parameter("Frequency_Max"));
  464. Commands->Start_Timer(obj, this, time, 0);
  465. }
  466. }
  467. void Timer_Expired(GameObject * obj, int timer_id)
  468. {
  469. const char * sound = Get_Parameter("Sound_Preset");
  470. bool is_3d = (Get_Int_Parameter("Is_3D") == 1) ? true : false;
  471. Vector3 pos = Commands->Get_Position(obj);
  472. pos += Get_Vector3_Parameter("Offset");
  473. Vector3 offset_random = Get_Vector3_Parameter("Offset_Randomness");
  474. pos.X += Commands->Get_Random(-offset_random.X, offset_random.X);
  475. pos.Y += Commands->Get_Random(-offset_random.Y, offset_random.Y);
  476. pos.Z += Commands->Get_Random(-offset_random.Z, offset_random.Z);
  477. int id;
  478. if (is_3d)
  479. {
  480. Commands->Debug_Message("Playing 3D Sound\n");
  481. id = Commands->Create_Sound(sound, pos, obj);
  482. }
  483. else
  484. {
  485. Commands->Debug_Message("Playing 2D Sound\n");
  486. id = Commands->Create_2D_Sound(sound);
  487. }
  488. Commands->Monitor_Sound(obj, id);
  489. }
  490. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  491. {
  492. if (type == CUSTOM_EVENT_SOUND_ENDED)
  493. {
  494. if (Get_Int_Parameter("Frequency_Min") != -1)
  495. {
  496. float time = Commands->Get_Random(Get_Float_Parameter("Frequency_Min"), Get_Float_Parameter("Frequency_Max"));
  497. Commands->Start_Timer(obj, this, time, 0);
  498. }
  499. }
  500. }
  501. };