Toolkit_Objects.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. * Toolkit_Objects.cpp
  22. *
  23. * DESCRIPTION
  24. * Designer Toolkit for Mission Construction - Object Subset
  25. *
  26. * PROGRAMMER
  27. * Design Team
  28. *
  29. * VERSION INFO
  30. * $Author: Dave_s $
  31. * $Revision: 27 $
  32. * $Modtime: 12/11/01 11:13a $
  33. * $Archive: /Commando/Code/Scripts/Toolkit_Objects.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "toolkit.h"
  37. /*M00_Object_Create_RMV
  38. This script creates an object upon activation.
  39. Parameters:
  40. Object_To_Create = The object to create.
  41. Location = Where to create the object.
  42. Facing = What facing to place the object at.
  43. */
  44. DECLARE_SCRIPT(M00_Object_Create_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Object_To_Create:string, Location:vector3, Facing=0.00:float, Debug_Mode=0:int")
  45. {
  46. bool debug_mode;
  47. REGISTER_VARIABLES()
  48. {
  49. SAVE_VARIABLE(debug_mode, 1);
  50. }
  51. void Created(GameObject* obj)
  52. {
  53. /* debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  54. if (Get_Int_Parameter("Start_Now"))
  55. {
  56. SCRIPT_DEBUG_MESSAGE(("M00_Object_Create_RMV ACTIVATED.\n"));
  57. Create_Object();
  58. } */
  59. }
  60. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  61. {
  62. if (type == Get_Int_Parameter("Receive_Type"))
  63. {
  64. if (param == Get_Int_Parameter("Receive_Param_On"))
  65. {
  66. SCRIPT_DEBUG_MESSAGE(("M00_Object_Create_RMV ACTIVATED.\n"));
  67. Create_Object();
  68. }
  69. }
  70. }
  71. void Create_Object (void)
  72. {
  73. Vector3 position = Get_Vector3_Parameter("Location");
  74. GameObject *new_object;
  75. new_object = Commands->Create_Object(Get_Parameter("Object_To_Create"), position);
  76. if (new_object)
  77. {
  78. Commands->Set_Facing(new_object, Get_Float_Parameter("Facing"));
  79. }
  80. else
  81. {
  82. SCRIPT_DEBUG_MESSAGE(("ERROR - M00_Object_Create_RMV failed to create a new object!\n"));
  83. }
  84. }
  85. };
  86. DECLARE_SCRIPT(M00_Object_Destroy_RMV, "Receive_Type_Activate:int, Debug_Mode=0:int")
  87. {
  88. int r_type;
  89. bool debug_mode;
  90. REGISTER_VARIABLES()
  91. {
  92. SAVE_VARIABLE(r_type, 1);
  93. SAVE_VARIABLE(debug_mode, 2);
  94. }
  95. void Created(GameObject * obj)
  96. {
  97. r_type = Get_Int_Parameter("Receive_Type_Activate");
  98. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  99. }
  100. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  101. {
  102. if (debug_mode)
  103. Commands->Debug_Message("M00_Destroy_Object_RMV received custom of type %d and param %d.\n", type, param);
  104. if (type == r_type)
  105. {
  106. if (Commands->Find_Object(param) != NULL)
  107. {
  108. Commands->Destroy_Object(Commands->Find_Object(param));
  109. if (debug_mode)
  110. Commands->Debug_Message("M00_Destroy_Object_RMV - Object %d destroyed.\n", param);
  111. } else
  112. {
  113. if (debug_mode)
  114. Commands->Debug_Message("M00_Destroy_Object_RMV - Object %d not found!\n", param);
  115. }
  116. }
  117. }
  118. };
  119. DECLARE_SCRIPT(M00_Object_Create_Attach_Script_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Object_To_Create:string, Location:vector3, Facing=0.00:float, Debug_Mode=0:int, Script_To_Attach:string, Script_Params:string")
  120. {
  121. bool debug_mode;
  122. void Created(GameObject* obj)
  123. {
  124. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  125. if (Get_Int_Parameter("Start_Now"))
  126. {
  127. if (debug_mode)
  128. {
  129. Commands->Debug_Message("M00_Object_Create_Attach_Script_RMV ACTIVATED.\n");
  130. }
  131. Create_Object();
  132. }
  133. }
  134. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  135. {
  136. if (type == Get_Int_Parameter("Receive_Type"))
  137. {
  138. if (param == Get_Int_Parameter("Receive_Param_On"))
  139. {
  140. if (debug_mode)
  141. {
  142. Commands->Debug_Message("M00_Object_Create_Attach_Script_RMV ACTIVATED.\n");
  143. }
  144. Create_Object();
  145. }
  146. }
  147. }
  148. void Create_Object (void)
  149. {
  150. Vector3 position = Get_Vector3_Parameter("Location");
  151. GameObject *new_object;
  152. char *params, fixed_params[255];
  153. params = (char *)Get_Parameter("Script_Params");
  154. Fix_Params(params, fixed_params);
  155. new_object = Commands->Create_Object(Get_Parameter("Object_To_Create"), position);
  156. if (new_object)
  157. {
  158. Commands->Set_Facing(new_object, Get_Float_Parameter("Facing"));
  159. Commands->Attach_Script(new_object, Get_Parameter("Script_To_Attach"), fixed_params);
  160. }
  161. else
  162. {
  163. if (debug_mode)
  164. {
  165. Commands->Debug_Message("ERROR - M00_Object_Create_Attach_Script_RMV failed to create a new object!\n");
  166. }
  167. }
  168. }
  169. void Fix_Params(const char *input, char * output)
  170. {
  171. // copy string, converting | to ,
  172. while ( *input != 0 ) {
  173. if ( *input == '|' ) {
  174. *output++ = ',';
  175. input++;
  176. } else {
  177. *output++ = *input++;
  178. }
  179. }
  180. *output = 0; // null terminate
  181. }
  182. };
  183. DECLARE_SCRIPT(M00_Object_Destroy_Self_RMV, "Start_Now=1:int, Receive_Type=3:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Receive_Param_Activate:int, Debug_Mode=0:int")
  184. {
  185. bool active, debug_mode;
  186. int receive_type, receive_param_on, receive_param_off, receive_param_activate;
  187. REGISTER_VARIABLES()
  188. {
  189. SAVE_VARIABLE(active, 1);
  190. SAVE_VARIABLE(debug_mode, 2);
  191. SAVE_VARIABLE(receive_type, 3);
  192. SAVE_VARIABLE(receive_param_on, 4);
  193. SAVE_VARIABLE(receive_param_off, 5);
  194. SAVE_VARIABLE(receive_param_activate, 6);
  195. }
  196. void Created(GameObject * obj)
  197. {
  198. active = (Get_Int_Parameter("Start_Now") == 1) ? true : false;
  199. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  200. receive_type = Get_Int_Parameter("Receive_Type");
  201. receive_param_on = Get_Int_Parameter("Receive_Param_On");
  202. receive_param_off = Get_Int_Parameter("Receive_Param_Off");
  203. receive_param_activate = Get_Int_Parameter("Receive_Param_Activate");
  204. }
  205. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  206. {
  207. if (debug_mode)
  208. Commands->Debug_Message("M00_Trigger_Destroy_Self_RMV received custom, type %d and param %d.\n", type, param);
  209. if (type == receive_type)
  210. {
  211. if (param == receive_param_on)
  212. {
  213. active = true;
  214. if (debug_mode)
  215. Commands->Debug_Message("M00_Trigger_Destroy_Self_RMV on object %d made ACTIVE.\n", Commands->Get_ID(obj));
  216. }
  217. if (param == receive_param_off)
  218. {
  219. active = false;
  220. if (debug_mode)
  221. Commands->Debug_Message("M00_Trigger_Destroy_Self_RMV on object %d made INACTIVE.\n", Commands->Get_ID(obj));
  222. }
  223. if ((param == receive_param_activate) && (active))
  224. {
  225. if (debug_mode)
  226. Commands->Debug_Message("M00_Trigger_Destroy_Self_RMV activated on object %d, destroying.\n", Commands->Get_ID(obj));
  227. Commands->Destroy_Object(obj);
  228. }
  229. }
  230. }
  231. };
  232. /***********************************************************************************************************
  233. *
  234. * PowerUp Creation
  235. *
  236. * - Includes ability to create any preset in the asset database by preset name
  237. * - Includes ability to check a random to drop item (Drop_Percentage)
  238. * - Arbitrary Create Position (Create_At_Death_Pos) & (Position)
  239. * - Provision to Play a "Spawning" Special Effect with Create_Anim_Effect_DAY Script
  240. *
  241. ***********************************************************************************************************/
  242. DECLARE_SCRIPT(M00_PowerUp_Create_When_Killed_JDG, "Preset_Name:string,Drop_Percentage=100:float,Create_At_Death_Pos=1:int,Position:vector3,Z_Offset=0.75:float,Spawn_Effect=0:int")
  243. {
  244. void Killed( GameObject * obj, GameObject * killer )
  245. {
  246. const char *preset_name;
  247. bool create_death_pos_flag;
  248. float random;
  249. Vector3 create_position;
  250. float z_offset;
  251. float drop_percentage;
  252. bool spawn_effect;
  253. preset_name = Get_Parameter( "Preset_Name" );
  254. create_death_pos_flag = (Get_Int_Parameter( "Create_At_Death_Pos" ) == 1 ) ? true : false;
  255. z_offset = Get_Float_Parameter( "Z_Offset" );
  256. drop_percentage = Get_Float_Parameter( "Drop_Percentage" );
  257. random = Commands->Get_Random( 0, 1 );
  258. spawn_effect = (Get_Int_Parameter( "Spawn_Effect" ) == 1 ) ? true : false;
  259. if ( drop_percentage > random )
  260. {
  261. if ( create_death_pos_flag == true )
  262. {
  263. create_position = Commands->Get_Position( obj );
  264. }
  265. else
  266. {
  267. create_position = Get_Vector3_Parameter( "Position" );
  268. }
  269. if ( z_offset != 0 )
  270. {
  271. create_position.Z = create_position.Z + z_offset;
  272. }
  273. if (spawn_effect == true )
  274. {
  275. GameObject *spawn_object;
  276. spawn_object = Commands->Create_Object( "Spawner Created Special Effect", create_position );
  277. if ( spawn_object )
  278. {
  279. Commands->Attach_Script( spawn_object, "M00_Create_Anim_Effect_DAY", "C4_EX1A.C4_EX1A");
  280. }
  281. }
  282. Commands->Create_Object( preset_name, create_position );
  283. }
  284. }
  285. };
  286. /***********************************************************************************************************
  287. *
  288. * One Time Special Effect Player
  289. * Used with M00_PowerUp_Create_When_Killed_JDG
  290. *
  291. * - Attach this script to an object that is created through script to play a W3d animation
  292. * - (Effect_Model:string) is the name of the animation of the object.
  293. *
  294. ***********************************************************************************************************/
  295. DECLARE_SCRIPT(M00_Create_Anim_Effect_DAY, "Effect_Model:string")
  296. {
  297. void Created( GameObject * obj )
  298. {
  299. ActionParamsStruct params;
  300. params.Set_Basic(this, 99, 1 );
  301. params.Set_Animation( Get_Parameter("Effect_Model"), false );
  302. Commands->Action_Play_Animation( obj, params );
  303. }
  304. void Action_Complete(GameObject * obj, int action_id, ActionCompleteReason reason)
  305. {
  306. if ( obj )
  307. {
  308. Commands->Destroy_Object( obj );
  309. }
  310. }
  311. };
  312. /***********************************************************************************************************
  313. *
  314. * One Time Damage Modifier
  315. *
  316. * - Attach this script to an object that you do not want to recieve falling damage.
  317. * Such as from a paradrop.
  318. *
  319. ***********************************************************************************************************/
  320. DECLARE_SCRIPT(M00_No_Falling_Damage_DME, "")
  321. {
  322. bool ignore_next_dmg;
  323. float initial_health;
  324. // Register variables to be Auto-Saved
  325. // All variables must have a unique ID, less than 256, that never changes
  326. REGISTER_VARIABLES()
  327. {
  328. SAVE_VARIABLE( ignore_next_dmg, 1 );
  329. SAVE_VARIABLE( initial_health, 2 );
  330. }
  331. void Created( GameObject * obj )
  332. {
  333. ignore_next_dmg = false;
  334. }
  335. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  336. {
  337. if (type == CUSTOM_EVENT_FALLING_DAMAGE)
  338. {
  339. ignore_next_dmg = true;
  340. initial_health = Commands->Get_Health(obj);
  341. }
  342. }
  343. void Damaged( GameObject * obj, GameObject *damager, float amount)
  344. {
  345. if (ignore_next_dmg && damager == NULL)
  346. {
  347. Commands->Set_Health(obj, initial_health);
  348. }
  349. ignore_next_dmg = false;
  350. }
  351. };
  352. /***********************************************************************************************************
  353. *
  354. * Permanent Damage Modifier
  355. *
  356. * - Attach this script to an object that you do not want to recieve falling damage.
  357. *
  358. ***********************************************************************************************************/
  359. DECLARE_SCRIPT(M00_Permanent_No_Falling_Damage_IML, "")
  360. {
  361. float initial_health;
  362. // Register variables to be Auto-Saved
  363. // All variables must have a unique ID, less than 256, that never changes
  364. REGISTER_VARIABLES()
  365. {
  366. SAVE_VARIABLE( initial_health, 1 );
  367. }
  368. void Created( GameObject * obj )
  369. {
  370. initial_health = Commands->Get_Health(obj);
  371. }
  372. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  373. {
  374. if (type == CUSTOM_EVENT_FALLING_DAMAGE)
  375. {
  376. initial_health = Commands->Get_Health(obj);
  377. }
  378. }
  379. void Damaged( GameObject * obj, GameObject *damager, float amount)
  380. {
  381. if (damager == NULL)
  382. {
  383. Commands->Set_Health(obj, initial_health);
  384. }
  385. }
  386. };
  387. DECLARE_SCRIPT (M00_Disable_Transition, "")
  388. {
  389. void Created (GameObject * obj)
  390. {
  391. Commands->Enable_Vehicle_Transitions (obj, false);
  392. }
  393. };
  394. /***********************************************************************************************************
  395. *
  396. * Death Script for Fire, Gas and Electric troops.
  397. *
  398. * - new script for default Fire, Gas and Electric troop deaths.
  399. * - Takes preset DeathType:string ("Fire", "Gas", "Electric") and plays appropriate animation
  400. * and weapon FX. (1 = flailing and smoke. 2 = Elec Twiching and smoke? 3 = choking and green smoke. )
  401. *
  402. ***********************************************************************************************************/
  403. DECLARE_SCRIPT ( M00_Fire_Gas_Elec_Death_DAK, "DeathType=1:int,HealthThreshhold=0.25:float" )
  404. {
  405. bool firsttime; // prevents an infinante loop each time obj is damaged by DeathType.
  406. void Damaged ( GameObject *obj, GameObject *damager, float amount )
  407. {
  408. float bleah = Get_Float_Parameter( "HealthThreshhold" );
  409. // check to see if obj is at 25% or less of its health.
  410. if ( Commands->Get_Health ( obj ) <= bleah * Commands->Get_Max_Health ( obj ) )
  411. {
  412. // plays animation once.
  413. if ( firsttime == true )
  414. {
  415. firsttime = false;
  416. ActionParamsStruct params;
  417. params.Set_Basic( this, 99, 1 );
  418. // set animation based upon DeathType (Gas, Electric or Default to Fire)
  419. if ( Get_Int_Parameter( "DeathType" ) == 1 )
  420. {
  421. params.Set_Animation( "S_A_HUMAN.H_A_FLMA",0 ); // fire death
  422. }
  423. else
  424. if ( Get_Int_Parameter( "DeathType" ) == 2 )
  425. {
  426. params.Set_Animation( "S_A_HUMAN.H_A_6X05",0 ); // electric death
  427. }
  428. else params.Set_Animation( "S_A_HUMAN.H_A_6X01",0 ); // gas death
  429. Commands->Action_Play_Animation( obj, params );
  430. // begin DeathType damage
  431. Commands->Apply_Damage( obj, 1.0f, Get_Parameter( "DeathType" ) );
  432. }
  433. }
  434. }
  435. void Killed ( GameObject * obj, GameObject * killer )
  436. {
  437. ActionParamsStruct params;
  438. params.Set_Basic( this, 99, 1 );
  439. // set animation based upon DeathType (Gas, Electric or Default to Fire)
  440. if ( strcmp( Get_Parameter( "DeathType" ), "Fire" ) )
  441. {
  442. params.Set_Animation( "S_A_HUMAN.H_A_FLMA",0 ); // Fire Death
  443. }
  444. else
  445. if ( strcmp( Get_Parameter( "DeathType" ), "Gas" ) )
  446. {
  447. params.Set_Animation( "S_A_HUMAN.H_A_6X01",0 ); // Gas Death
  448. }
  449. else params.Set_Animation( "S_A_HUMAN.H_A_6X05",0 ); // Electrocution
  450. Commands->Action_Play_Animation( obj, params );
  451. }
  452. void Created ( GameObject *obj )
  453. {
  454. firsttime = true;
  455. }
  456. void Action_Complete(GameObject * obj, int action_id, ActionCompleteReason reason)
  457. {
  458. if((action_id == 1) && (reason == ACTION_COMPLETE_NORMAL))
  459. {
  460. // animation is complete. kill obj.
  461. Commands->Apply_Damage (obj, 10000.0f, "Blamokiller");
  462. }
  463. }
  464. };
  465. /***********************************************************************************************************
  466. *
  467. * Vehicle Health Regeneration Script for GDI Mammoth Tanks and Tiberium Harvesters.
  468. *
  469. * - continually checks vehicle's health to see if it needs to be regenerated.
  470. * - regenerates vehicle to 50% max health
  471. *
  472. ***********************************************************************************************************/
  473. DECLARE_SCRIPT(M00_Vehicle_Regen_DAK, "" )
  474. {
  475. void Created ( GameObject *obj )
  476. {
  477. Commands->Send_Custom_Event ( obj, obj, 0, 0, 0 );
  478. }
  479. void Custom (GameObject* obj, int type, int param, GameObject* sender)
  480. {
  481. if ( type == 0 ) // regenerate health.
  482. {
  483. // check to see if health needs to be regenerated.
  484. if ( Commands->Get_Health ( obj ) < ( Commands->Get_Max_Health ( obj ) ) )
  485. {
  486. Commands->Apply_Damage (obj, -2, "RegenHealth", NULL);
  487. }
  488. // restart the timer
  489. Commands->Send_Custom_Event ( obj, obj, 0, 0, 1 );
  490. }
  491. }
  492. };
  493. DECLARE_SCRIPT(M00_PCT_Pokable_DAK, "" )
  494. {
  495. void Created ( GameObject *obj )
  496. {
  497. Commands->Enable_HUD_Pokable_Indicator( obj, true );
  498. Commands->Display_Health_Bar( obj, false );
  499. }
  500. };
  501. DECLARE_SCRIPT(M00_Send_Object_ID, "Receiver_ID:int, Param=0:int, Delay=1.0f:int")
  502. {
  503. int r_type;
  504. bool debug_mode;
  505. REGISTER_VARIABLES()
  506. {
  507. SAVE_VARIABLE(r_type, 1);
  508. SAVE_VARIABLE(debug_mode, 2);
  509. }
  510. void Created(GameObject * obj)
  511. {
  512. // Send Custom and Parameter to Receiver object
  513. int receiver_id = Get_Int_Parameter("Receiver_ID");
  514. int parameter = Get_Int_Parameter("Param");
  515. float delay = Get_Float_Parameter("Delay");
  516. GameObject * receiver = Commands->Find_Object(receiver_id);
  517. if(receiver)
  518. {
  519. Commands->Send_Custom_Event ( obj, Commands->Find_Object(receiver_id), M00_SEND_OBJECT_ID, parameter, delay );
  520. }
  521. else
  522. {
  523. Commands->Debug_Message("M00_Send_Object_ID on object_id %d Warning! Receiver_ID %d does not exist! /n", Commands->Get_ID(obj), receiver_id);
  524. }
  525. }
  526. };