Toolkit_Sounds.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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_Sounds.cpp
  22. *
  23. * DESCRIPTION
  24. * Designer Toolkit for Mission Construction - Sounds Subset
  25. *
  26. * PROGRAMMER
  27. * Design Team
  28. *
  29. * VERSION INFO
  30. * $Author: David_y $
  31. * $Revision: 13 $
  32. * $Modtime: 12/05/01 6:04p $
  33. * $Archive: /Commando/Code/Scripts/Toolkit_Sounds.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "toolkit.h"
  37. /*
  38. Function - M00_Controller_Sound_RAD
  39. This script plays a 2D or 3D sound once, then returns.
  40. Parameters:
  41. GameObject* obj = The object that is creating the sound.
  42. Vector3 sound_loc = Where the sound is to be played.
  43. char sound_effect[] = The string name of the sound effect to play.
  44. bool two_dimensional = 1 if 2D, 0 if 3D.
  45. */
  46. void M00_Controller_Sound_RAD (GameObject* obj, const Vector3& sound_loc, const char* sound_effect, bool two_dimensional)
  47. {
  48. if (two_dimensional)
  49. {
  50. Commands->Create_2D_WAV_Sound (sound_effect);
  51. }
  52. else
  53. {
  54. Commands->Create_Sound (sound_effect, sound_loc, obj);
  55. }
  56. };
  57. /*
  58. Editor Script - M00_Sound_Play_2D_RAD
  59. Play a 2D sound one or more times, with a delay factor in between.
  60. Parameters:
  61. Sound_Effect = The 2D sound effect to play.
  62. Play_Count = How many times the sound should play.
  63. Sound_Delay_Min = The minimum wait before playing the sound.
  64. Sound_Delay_Max = The maximum wait before playing the sound.
  65. */
  66. DECLARE_SCRIPT(M00_Sound_Play_2D_RAD, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Sound_Effect:string, Play_Count=1:int, Sound_Delay_Min=0.1:float, Sound_Delay_Max=0.1:float, Debug_Mode=0:int")
  67. {
  68. int play_count;
  69. int current_count;
  70. float delay_time_min;
  71. float delay_time_max;
  72. float delay_time;
  73. bool debug_mode;
  74. void Created(GameObject* obj)
  75. {
  76. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  77. play_count = Get_Int_Parameter("Play_Count");
  78. delay_time_min = Get_Float_Parameter("Sound_Delay_Min");
  79. delay_time_max = Get_Float_Parameter("Sound_Delay_Max");
  80. current_count = 0;
  81. if (delay_time_max < delay_time_min)
  82. {
  83. delay_time_max = delay_time_min;
  84. }
  85. if (Get_Int_Parameter("Start_Now"))
  86. {
  87. delay_time = 0.1f;
  88. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_2D_RAD);
  89. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD ACTIVATED.\n"));
  90. }
  91. }
  92. void Custom(GameObject* obj, int type, int param, GameObject* sender)
  93. {
  94. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD received custom type %d, param %d.\n", type, param));
  95. if (type == Get_Int_Parameter("Receive_Type"))
  96. {
  97. if (param == Get_Int_Parameter("Receive_Param_On"))
  98. {
  99. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD ACTIVATED.\n"));
  100. if (play_count > 1)
  101. {
  102. delay_time = 0.1f;
  103. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_2D_RAD);
  104. }
  105. else
  106. {
  107. const char *sound_effect;
  108. sound_effect = Get_Parameter("Sound_Effect");
  109. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD Playing sound.\n"));
  110. M00_Controller_Sound_RAD (obj, Vector3(0.0f, 0.0f, 0.0f), sound_effect, 1);
  111. }
  112. }
  113. if (param == Get_Int_Parameter("Receive_Param_Off"))
  114. {
  115. play_count = 0;
  116. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD DEACTIVATED.\n"));
  117. }
  118. }
  119. }
  120. void Timer_Expired(GameObject* obj, int timer_id)
  121. {
  122. if (timer_id == M00_TIMER_SOUND_PLAY_2D_RAD)
  123. {
  124. current_count++;
  125. if (current_count <= play_count)
  126. {
  127. if (delay_time_min == delay_time_max)
  128. {
  129. delay_time = delay_time_min;
  130. }
  131. else
  132. {
  133. delay_time = Commands->Get_Random(delay_time_min, delay_time_max);
  134. }
  135. const char *sound_effect;
  136. sound_effect = Get_Parameter("Sound_Effect");
  137. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_2D_RAD playing sound.\n"));
  138. M00_Controller_Sound_RAD (obj, Vector3(0.0f, 0.0f, 0.0f), sound_effect, 1);
  139. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_2D_RAD);
  140. }
  141. else
  142. {
  143. current_count = 0;
  144. }
  145. }
  146. }
  147. };
  148. /*
  149. Editor Script - M00_Sound_Play_3D_On_Object_RAD
  150. Play a 3D sound one or more times, with a delay factor in between, on an object.
  151. Parameters:
  152. Object_ID = The ID of the object to play the sound on.
  153. Sound_Effect = The sound effect to play.
  154. Play_Count = The number of times to play this effect.
  155. Sound_Delay_Min = The minimum delay until the sound is played.
  156. Sound_Delay_Max = The maximum delay until the sound is played.
  157. Special Information:
  158. Object_ID of 0 = Play on self.
  159. Play_Count of 0 = Play an endless loop.
  160. */
  161. DECLARE_SCRIPT (M00_Sound_Play_3D_On_Object_RAD, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Object_ID:int, Sound_Effect:string, Play_Count=1:int, Sound_Delay_Min=0.1:float, Sound_Delay_Max=0.1:float, Debug_Mode=0:int")
  162. {
  163. int play_count;
  164. int current_count;
  165. float delay_time_min;
  166. float delay_time_max;
  167. float delay_time;
  168. Vector3 my_position;
  169. bool debug_mode;
  170. void Created (GameObject* obj)
  171. {
  172. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  173. play_count = Get_Int_Parameter("Play_Count");
  174. delay_time_min = Get_Float_Parameter("Sound_Delay_Min");
  175. delay_time_max = Get_Float_Parameter("Sound_Delay_Max");
  176. current_count = 0;
  177. if (delay_time_max < delay_time_min)
  178. {
  179. delay_time_max = delay_time_min;
  180. }
  181. if (Get_Int_Parameter("Start_Now"))
  182. {
  183. delay_time = 0.1f;
  184. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  185. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD ACTIVATED.\n"));
  186. }
  187. }
  188. void Custom (GameObject* obj, int type, int param, GameObject* sender)
  189. {
  190. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD received custom type %d, param %d.\n", type, param));
  191. if (type == Get_Int_Parameter("Receive_Type"))
  192. {
  193. if (param == Get_Int_Parameter("Receive_Param_On"))
  194. {
  195. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD ACTIVATED.\n"));
  196. if ((play_count > 1) || (!play_count))
  197. {
  198. delay_time = 0.1f;
  199. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  200. }
  201. else
  202. {
  203. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD playing sound.\n"));
  204. if (Get_Int_Parameter("Object_ID"))
  205. {
  206. GameObject* target_object;
  207. target_object = Commands->Find_Object(Get_Int_Parameter("Object_ID"));
  208. if (target_object)
  209. {
  210. const char* sound_effect;
  211. sound_effect = Get_Parameter("Sound_Effect");
  212. my_position = Commands->Get_Position(target_object);
  213. M00_Controller_Sound_RAD (target_object, my_position, sound_effect, 0);
  214. }
  215. }
  216. else
  217. {
  218. const char* sound_effect;
  219. sound_effect = Get_Parameter("Sound_Effect");
  220. my_position = Commands->Get_Position(obj);
  221. M00_Controller_Sound_RAD (obj, my_position, sound_effect, 0);
  222. }
  223. }
  224. }
  225. if (param == Get_Int_Parameter("Receive_Param_Off"))
  226. {
  227. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD DEACTIVATED.\n"));
  228. play_count = 0;
  229. }
  230. }
  231. }
  232. void Timer_Expired (GameObject* obj, int timer_id)
  233. {
  234. if (timer_id == M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD)
  235. {
  236. current_count++;
  237. if (play_count)
  238. {
  239. if (current_count <= play_count)
  240. {
  241. Play_The_Sound (obj);
  242. }
  243. else
  244. {
  245. current_count = 0;
  246. }
  247. }
  248. else
  249. {
  250. Play_The_Sound (obj);
  251. }
  252. }
  253. }
  254. void Play_The_Sound (GameObject* obj)
  255. {
  256. if (delay_time_min == delay_time_max)
  257. {
  258. delay_time = delay_time_min;
  259. }
  260. else
  261. {
  262. delay_time = Commands->Get_Random(delay_time_min, delay_time_max);
  263. }
  264. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_On_Object_RAD playing sound.\n"));
  265. if (!Get_Int_Parameter("Object_ID"))
  266. {
  267. const char *sound_effect;
  268. sound_effect = Get_Parameter("Sound_Effect");
  269. my_position = Commands->Get_Position(obj);
  270. M00_Controller_Sound_RAD (obj, my_position, sound_effect, 0);
  271. }
  272. else
  273. {
  274. GameObject *target_obj;
  275. target_obj = Commands->Find_Object(Get_Int_Parameter("Object_ID"));
  276. if (target_obj)
  277. {
  278. const char *sound_effect;
  279. sound_effect = Get_Parameter("Sound_Effect");
  280. my_position = Commands->Get_Position(target_obj);
  281. M00_Controller_Sound_RAD (target_obj, my_position, sound_effect, 0);
  282. }
  283. }
  284. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  285. }
  286. };
  287. /*
  288. Editor Script - M00_Sound_Play_3D_At_Location_RMV
  289. Play a 3D sound one or more times, with a delay factor in between, at this location.
  290. Parameters:
  291. Sound_Effect = The sound effect to be played.
  292. Play_Count = The number of times to play the sound.
  293. Sound_Delay_Min = The minimum delay before playing the sound.
  294. Sound_Delay_Max = The maximum delay before playing the sound.
  295. Origin = The Vector3 coordinate to play the sound at.
  296. */
  297. DECLARE_SCRIPT(M00_Sound_Play_3D_At_Location_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Sound_Effect:string, Play_Count=1:int, Sound_Delay_Min=0.1:float, Sound_Delay_Max=0.1:float, Origin:vector3, Debug_Mode=0:int")
  298. {
  299. int play_count;
  300. int current_count;
  301. float delay_time_min;
  302. float delay_time_max;
  303. float delay_time;
  304. Vector3 my_position;
  305. bool debug_mode;
  306. void Created(GameObject* obj)
  307. {
  308. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  309. play_count = Get_Int_Parameter("Play_Count");
  310. delay_time_min = Get_Float_Parameter("Sound_Delay_Min");
  311. delay_time_max = Get_Float_Parameter("Sound_Delay_Max");
  312. my_position = Get_Vector3_Parameter("Origin");
  313. current_count = 0;
  314. if (delay_time_max < delay_time_min)
  315. {
  316. delay_time_max = delay_time_min;
  317. }
  318. if (Get_Int_Parameter("Start_Now"))
  319. {
  320. delay_time = 0.1f;
  321. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_RAD);
  322. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Location_RMV ACTIVATED.\n"));
  323. }
  324. }
  325. void Custom(GameObject* obj, int type, int param, GameObject* sender)
  326. {
  327. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Location_RMV received custom type %d, param %d.\n", type, param));
  328. if (type == Get_Int_Parameter("Receive_Type"))
  329. {
  330. if (param == Get_Int_Parameter("Receive_Param_On"))
  331. {
  332. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Location_RMV ACTIVATED.\n"));
  333. if (play_count > 1)
  334. {
  335. delay_time = 0.1f;
  336. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_RAD);
  337. }
  338. else
  339. {
  340. const char* sound_effect;
  341. sound_effect = Get_Parameter("Sound_Effect");
  342. M00_Controller_Sound_RAD (obj, my_position, sound_effect, 0);
  343. }
  344. }
  345. if (param == Get_Int_Parameter("Receive_Param_Off"))
  346. {
  347. play_count = 0;
  348. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Location_RMV DEACTIVATED.\n"));
  349. }
  350. }
  351. }
  352. void Timer_Expired(GameObject* obj, int timer_id)
  353. {
  354. if (timer_id == M00_TIMER_SOUND_PLAY_3D_RAD)
  355. {
  356. current_count++;
  357. if (current_count <= play_count)
  358. {
  359. if (delay_time_min == delay_time_max)
  360. {
  361. delay_time = delay_time_min;
  362. }
  363. else
  364. {
  365. delay_time = Commands->Get_Random(delay_time_min, delay_time_max);
  366. }
  367. const char* sound_effect;
  368. sound_effect = Get_Parameter("Sound_Effect");
  369. M00_Controller_Sound_RAD (obj, my_position, sound_effect, 0);
  370. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_RAD);
  371. }
  372. else
  373. {
  374. current_count = 0;
  375. }
  376. }
  377. }
  378. };
  379. /*
  380. Editor Script - M00_Sound_Play_3D_At_Bone_RMV
  381. Play a 3D sound one or more times, with a delay factor in between, on an object.
  382. Parameters:
  383. Object_ID = The ID of the object to play the sound on.
  384. Bone_Name = The bone at which to play the sound.
  385. Sound_Effect = The sound effect to play.
  386. Play_Count = The number of times to play the sound.
  387. Sound_Delay_Min = The minimum delay before playing the sound.
  388. Sound_Delay_Max = The maximum delay before playing the sound.
  389. */
  390. DECLARE_SCRIPT(M00_Sound_Play_3D_At_Bone_RMV, "Start_Now=0:int, Receive_Type:int, Receive_Param_On=1:int, Receive_Param_Off=0:int, Object_ID:int, Bone_Name:string, Sound_Effect:string, Play_Count=1:int, Sound_Delay_Min=0.1:float, Sound_Delay_Max=0.1:float, Debug_Mode=0:int")
  391. {
  392. int play_count;
  393. int current_count;
  394. float delay_time_min;
  395. float delay_time_max;
  396. float delay_time;
  397. Vector3 my_position;
  398. bool debug_mode;
  399. void Created(GameObject* obj)
  400. {
  401. debug_mode = (Get_Int_Parameter("Debug_Mode") == 1) ? true : false;
  402. play_count = Get_Int_Parameter("Play_Count");
  403. delay_time_min = Get_Float_Parameter("Sound_Delay_Min");
  404. delay_time_max = Get_Float_Parameter("Sound_Delay_Max");
  405. current_count = 0;
  406. if (delay_time_max < delay_time_min)
  407. {
  408. delay_time_max = delay_time_min;
  409. }
  410. if (Get_Int_Parameter("Start_Now"))
  411. {
  412. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Bone_RMV ACTIVATED.\n"));
  413. delay_time = 0.1f;
  414. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  415. }
  416. }
  417. void Custom(GameObject* obj, int type, int param, GameObject* sender)
  418. {
  419. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Bone_RMV received custom type %d, param %d.\n", type, param));
  420. if (type == Get_Int_Parameter("Receive_Type"))
  421. {
  422. if (param == Get_Int_Parameter("Receive_Param_On"))
  423. {
  424. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Bone_RMV ACTIVATED.\n"));
  425. if (play_count > 1)
  426. {
  427. delay_time = 0.1f;
  428. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  429. }
  430. else
  431. {
  432. GameObject *target_object;
  433. target_object = Commands->Find_Object(Get_Int_Parameter("Object_ID"));
  434. if (target_object)
  435. {
  436. const char* sound_effect;
  437. sound_effect = Get_Parameter("Sound_Effect");
  438. my_position = Commands->Get_Bone_Position(target_object, Get_Parameter("Bone_Name"));
  439. M00_Controller_Sound_RAD (target_object, my_position, sound_effect, 0);
  440. }
  441. }
  442. }
  443. if (param == Get_Int_Parameter("Receive_Param_Off"))
  444. {
  445. play_count = 0;
  446. SCRIPT_DEBUG_MESSAGE(("M00_Sound_Play_3D_At_Bone_RMV DEACTIVATED.\n"));
  447. }
  448. }
  449. }
  450. void Timer_Expired(GameObject* obj, int timer_id)
  451. {
  452. if (timer_id == M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD)
  453. {
  454. current_count++;
  455. if (current_count <= play_count)
  456. {
  457. if (delay_time_min == delay_time_max)
  458. {
  459. delay_time = delay_time_min;
  460. }
  461. else
  462. {
  463. delay_time = Commands->Get_Random(delay_time_min, delay_time_max);
  464. }
  465. GameObject *target_object;
  466. target_object = Commands->Find_Object(Get_Int_Parameter("Object_ID"));
  467. if (target_object)
  468. {
  469. const char *sound_effect;
  470. sound_effect = Get_Parameter("Sound_Effect");
  471. my_position = Commands->Get_Bone_Position(target_object, Get_Parameter("Bone_Name"));
  472. M00_Controller_Sound_RAD (target_object, my_position, sound_effect, 0);
  473. }
  474. Commands->Start_Timer (obj, this, delay_time, M00_TIMER_SOUND_PLAY_3D_ON_OBJECT_RAD);
  475. }
  476. else
  477. {
  478. current_count = 0;
  479. }
  480. }
  481. }
  482. };
  483. /*
  484. Editor Script - M00_Sound_Building_Ambient_RAD
  485. This script handles all ambient sound effects for standard buildings. It is placed on an
  486. object that is located where the Master Control Terminal for the building is. For those
  487. buildings with no MCT, the object is located at the approximate center of the building
  488. (this mainly applies to the Guard Tower and Tiberium Silo).
  489. When the script is created, the building is assumed to start at full power. We can adjust
  490. this later through other means - this script is only reactive, meaning its output only
  491. plays sound effects and does not control other objects.
  492. When a building is active, all sound effects for the building are played normally at
  493. appropriate positions. Some may be on a timer basis, which is also handled here.
  494. When a building is destroyed, the main ambient sounds are deactivated, and the power-down
  495. sound sequence is played. This is another set of sounds played at preset locations.
  496. When the power-down sequence completes, the power-down sound effects are deactivated and
  497. the destroyed building sound effects commence, if the building is destroyed and has not
  498. merely lost power.
  499. When the building is repaired, the destroyed building sound effects cease, and a power-up
  500. sequence is played.
  501. When the power-up sequence completes, the power-up sound effects are stopped, and the
  502. standard ambient sounds are reinstated.
  503. When the building loses power, the power-down sound effects are played, and all power-loss
  504. sounds are started.
  505. In essence, there are several points throughout each building where standard sounds will
  506. be played. Each location plays one sound at a time, and may or may not loop.
  507. Parameters:
  508. Building_ID = Which building this script is associated with.
  509. Building_Type = A number indicating which type of building this is.
  510. Building_Facing = Which cardinal direction the building is facing.
  511. Building Type Numbers:
  512. 01 = NOD Tiberium Refinery
  513. 02 = NOD Communications Center
  514. 03 = NOD Power Plant
  515. 04 = NOD Airfield
  516. 05 = NOD Construction Yard
  517. 06 = NOD Guard Tower
  518. 07 = NOD Hand of Nod
  519. 08 = NOD Landing Pad
  520. 09 = NOD Obelisk of Light
  521. 10 = NOD Repair Facility
  522. 11 = NOD Tiberium Silo
  523. 21 = GDI Tiberium Refinery
  524. 22 = GDI Communications Center
  525. 23 = GDI Power Plant
  526. 24 = GDI Weapons Factory
  527. 25 = GDI Construction Yard
  528. 26 = GDI Guard Tower
  529. 27 = GDI Infantry Barracks
  530. 28 = GDI Landing Pad
  531. 29 = GDI Advanced Guard Tower
  532. 30 = GDI Repair Facility
  533. 31 = GDI Tiberium Silo
  534. Cardinal Direction Numbers:
  535. 0 = North
  536. 1 = East
  537. 2 = South
  538. 3 = West
  539. */
  540. DECLARE_SCRIPT (M00_Sound_Building_Ambient_RAD, "Building_ID=0:int, Building_Type=0:int, Building Facing=0:int")
  541. {
  542. };
  543. DECLARE_SCRIPT(RMV_Audio_Timer_Delay, "Target_ID:int, Custom_Type=0:int, Custom_Param=0:int, Delay_Min=0.0:float, Delay_Max=0.0:float, Timer_ID=0:int, Repeat=1:int, Randomize_Each_Time=1:int")
  544. {
  545. int type, param, id;
  546. float min, max, delay;
  547. bool repeat, random;
  548. void Created(GameObject * obj)
  549. {
  550. type = Get_Int_Parameter("Custom_Type");
  551. param = Get_Int_Parameter("Custom_Param");
  552. id = Get_Int_Parameter("Timer_ID");
  553. min = Get_Float_Parameter("Delay_Min");
  554. max = Get_Float_Parameter("Delay_Max");
  555. repeat = (Get_Int_Parameter("Repeat") == 1) ? true : false;
  556. random = (Get_Int_Parameter("Randomize_Each_Time") == 1) ? true : false;
  557. if ((min == 0) && (max == 0))
  558. {
  559. GameObject *target;
  560. target = Commands->Find_Object(Get_Int_Parameter("Target_ID"));
  561. Commands->Send_Custom_Event(obj, target, type, param);
  562. }
  563. else
  564. if ((min != 0) && (max == 0))
  565. {
  566. delay = min;
  567. Commands->Start_Timer(obj, this, delay, id);
  568. }
  569. else if (max != 0)
  570. {
  571. delay = Commands->Get_Random(min, max);
  572. Commands->Start_Timer(obj, this, delay, id);
  573. }
  574. }
  575. void Timer_Expired(GameObject * obj, int timer_id)
  576. {
  577. if ((timer_id == id) && (repeat))
  578. {
  579. if (max !=0)
  580. if (random)
  581. delay = Commands->Get_Random(min, max);
  582. Commands->Start_Timer(obj, this, delay, id);
  583. }
  584. }
  585. };
  586. DECLARE_SCRIPT(RMV_Audio_Sound_Player_WAV, "WAV_File:string, Is_3D=1:int, Custom_Type=0:int, Custom_Param=0:int")
  587. {
  588. bool is3d;
  589. int c_type, c_param;
  590. void Created(GameObject * obj)
  591. {
  592. is3d = (Get_Int_Parameter("Is_3D") == 1) ? true : false;
  593. c_type = Get_Int_Parameter("Custom_Type");
  594. c_param = Get_Int_Parameter("Custom_Param");
  595. }
  596. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  597. {
  598. if ((c_type == type) && (c_param == param))
  599. {
  600. const char *sound;
  601. sound = Get_Parameter("WAV_File");
  602. if (is3d)
  603. {
  604. Commands->Create_3D_WAV_Sound_At_Bone(sound, obj, "ROOTTRANSFORM");
  605. }
  606. else
  607. {
  608. Commands->Create_2D_WAV_Sound(sound);
  609. }
  610. }
  611. }
  612. };
  613. DECLARE_SCRIPT(RMV_Audio_Sound_Player_Preset, "Preset_Name:string, Custom_Type=0:int, Custom_Param=0:int, Sound_Origin:vector3")
  614. {
  615. Vector3 origin;
  616. int c_type, c_param;
  617. void Created(GameObject * obj)
  618. {
  619. origin = Get_Vector3_Parameter("Sound_Origin");
  620. c_type = Get_Int_Parameter("Custom_Type");
  621. c_param = Get_Int_Parameter("Custom_Param");
  622. }
  623. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  624. {
  625. if ((c_type == type) && (c_param == param))
  626. {
  627. const char *sound;
  628. sound = Get_Parameter("Preset_Name");
  629. Commands->Create_Sound(sound, origin, obj);
  630. }
  631. }
  632. };
  633. DECLARE_SCRIPT(RMV_Sound_Play_Near_Player, "Receive_Type:int, Receive_Param:int, Max_Offset:vector3, Sound_Preset:string, Frequency_Min:float, Frequency_Max=0.0:float")
  634. {
  635. Vector3 offset, current;
  636. bool enabled;
  637. float freq_min, freq_max, freq;
  638. enum {SOUND_PLAYER_TIMER};
  639. void Created(GameObject * obj)
  640. {
  641. enabled = false;
  642. offset = Get_Vector3_Parameter("Max_Offset");
  643. freq_min = Get_Float_Parameter("Frequency_Min");
  644. freq_max = Get_Float_Parameter("Frequency_Max");
  645. }
  646. void Custom(GameObject * obj, int type, int param, GameObject * sender)
  647. {
  648. if ((type == Get_Int_Parameter("Receive_Type")) && (param == Get_Int_Parameter("Receive_Param")))
  649. enabled = !enabled;
  650. Timer_Expired(obj, SOUND_PLAYER_TIMER);
  651. }
  652. void Timer_Expired(GameObject * obj, int timer_id)
  653. {
  654. if ((enabled) && (timer_id == SOUND_PLAYER_TIMER))
  655. {
  656. const char *preset;
  657. preset = Get_Parameter("Sound_Preset");
  658. GameObject *player;
  659. player = Commands->Get_A_Star(Vector3(0,0,0));
  660. Vector3 player_pos = Commands->Get_Position(player);
  661. current.X = (int)Commands->Get_Random(-offset.X, offset.X);
  662. current.Y = (int)Commands->Get_Random(-offset.Y, offset.Y);
  663. current.Z = (int)Commands->Get_Random(0.0, offset.Z);
  664. Vector3 sound_pos = player_pos + current;
  665. if (freq_max == 0.0)
  666. freq = freq_min;
  667. else freq = Commands->Get_Random(freq_min, freq_max);
  668. Commands->Create_Sound(preset, sound_pos, obj);
  669. Commands->Start_Timer(obj, this, freq, SOUND_PLAYER_TIMER);
  670. }
  671. }
  672. };
  673. /***********************************************************************************************
  674. **
  675. ** Building State Sound System - Plays sounds at a simple object location. Requires Building
  676. ** controller ID to switch sound from normal to destroyed state.
  677. **
  678. ** Requires one script attached to the speaker object and the ID of the building controller.
  679. ** On Created, the speaker finds the building controller and attaches a script with the speaker's
  680. ** ID as a param. The script attached to the building sends a custom back to each individual
  681. ** speaker on events.
  682. **
  683. ** There is a one-to-one ratio of scripts attached to the building controller and speakers
  684. ** placed for the building.
  685. **
  686. ************************************************************************************************/
  687. DECLARE_SCRIPT (M00_BuildingStateSoundSpeaker, "Sound_Normal:string,Sound_Destroyed:string,BuildingController_ID:int,Is_3D=1:int,Offset:vector3,Offset_Randomness:vector3,Frequency_Min=-1:float,Frequency_Max:float,Is_3D_Destroyed=1:int,Offset_Destroyed:vector3,Offset_Randomness_Destroyed:vector3,Frequency_Min_Destroyed=-1:float,Frequency_Max_Destroyed:float, Explosion_Name:string")
  688. {
  689. int sound_int;
  690. bool building_destroyed;
  691. bool building_explode;
  692. REGISTER_VARIABLES()
  693. {
  694. SAVE_VARIABLE( sound_int, 1 );
  695. SAVE_VARIABLE( building_destroyed, 3);
  696. }
  697. void Created( GameObject * obj )
  698. {
  699. building_destroyed = false;
  700. building_explode = true; // set play building explosions to true for when building is destroyed.
  701. GameObject *building = Commands->Find_Object( Get_Int_Parameter("BuildingController_ID") );
  702. if (building)
  703. {
  704. int speaker_id = Commands->Get_ID ( obj );
  705. char speaker[16];
  706. sprintf (speaker, "%d", speaker_id);
  707. Commands->Attach_Script( building, "M00_BuildingStateSoundController", speaker);
  708. }
  709. if (Get_Int_Parameter("Frequency_Min") == -1)
  710. {
  711. Timer_Expired(obj, 0);
  712. }
  713. else
  714. {
  715. float time = Commands->Get_Random(Get_Float_Parameter("Frequency_Min"), Get_Float_Parameter("Frequency_Max"));
  716. Commands->Start_Timer(obj, this, time, 0);
  717. }
  718. }
  719. void Timer_Expired(GameObject * obj, int timer_id)
  720. {
  721. if ( building_destroyed == false )
  722. {
  723. bool is_3d = (Get_Int_Parameter("Is_3D") == 1) ? true : false;
  724. Vector3 pos = Commands->Get_Position(obj);
  725. pos += Get_Vector3_Parameter("Offset");
  726. Vector3 offset_random = Get_Vector3_Parameter("Offset_Randomness");
  727. pos.X += Commands->Get_Random(-offset_random.X, offset_random.X);
  728. pos.Y += Commands->Get_Random(-offset_random.Y, offset_random.Y);
  729. pos.Z += Commands->Get_Random(-offset_random.Z, offset_random.Z);
  730. if (is_3d)
  731. {
  732. Commands->Debug_Message("Playing 3D Sound\n");
  733. sound_int = Commands->Create_Sound(Get_Parameter("Sound_Normal"), pos, obj);
  734. }
  735. else
  736. {
  737. Commands->Debug_Message("Playing 2D Sound\n");
  738. sound_int = Commands->Create_2D_Sound(Get_Parameter("Sound_Normal"));
  739. }
  740. }
  741. else
  742. {
  743. bool is_3d_destroyed = (Get_Int_Parameter("Is_3D_Destroyed") == 1) ? true : false;
  744. Vector3 pos = Commands->Get_Position(obj);
  745. pos += Get_Vector3_Parameter("Offset_Destroyed");
  746. Vector3 offset_random = Get_Vector3_Parameter("Offset_Randomness_Destroyed");
  747. pos.X += Commands->Get_Random(-offset_random.X, offset_random.X);
  748. pos.Y += Commands->Get_Random(-offset_random.Y, offset_random.Y);
  749. pos.Z += Commands->Get_Random(-offset_random.Z, offset_random.Z);
  750. if (is_3d_destroyed)
  751. {
  752. Commands->Debug_Message("Playing 3D Sound\n");
  753. sound_int = Commands->Create_Sound(Get_Parameter("Sound_Destroyed"), pos, obj);
  754. }
  755. else
  756. {
  757. Commands->Debug_Message("Playing 2D Sound\n");
  758. sound_int = Commands->Create_2D_Sound(Get_Parameter("Sound_Destroyed"));
  759. }
  760. }
  761. Commands->Monitor_Sound(obj, sound_int);
  762. }
  763. void Custom( GameObject * obj, int type, int param, GameObject * sender )
  764. {
  765. if (type == CUSTOM_EVENT_SOUND_ENDED)
  766. {
  767. if ( building_destroyed == false )
  768. {
  769. if (Get_Int_Parameter("Frequency_Min") != -1)
  770. {
  771. float time = Commands->Get_Random(Get_Float_Parameter("Frequency_Min"), Get_Float_Parameter("Frequency_Max"));
  772. Commands->Start_Timer(obj, this, time, 0);
  773. }
  774. }
  775. else
  776. {
  777. if (Get_Int_Parameter("Frequency_Min_Destroyed") != -1)
  778. {
  779. float time = Commands->Get_Random(Get_Float_Parameter("Frequency_Min_Destroyed"), Get_Float_Parameter("Frequency_Max_Destroyed"));
  780. Commands->Start_Timer(obj, this, time, 0);
  781. }
  782. }
  783. }
  784. if ( type == M00_CUSTOM_SOUND_BUILDING )
  785. {
  786. if ( param == 1 )
  787. {
  788. Commands->Stop_Sound( sound_int, true );
  789. Timer_Expired(obj, 0);
  790. }
  791. }
  792. if ( type == M00_CUSTOM_BUILDING_EXPLODE )
  793. {
  794. if ( building_explode )
  795. {
  796. const char *explosion_def_name;
  797. // insert EXPLODE sound code here...
  798. Vector3 pos = Commands->Get_Position(obj);
  799. pos.X += Commands->Get_Random(2, 5);
  800. pos.Y += Commands->Get_Random(2, 5);
  801. pos.Z += Commands->Get_Random(2, 5);
  802. explosion_def_name = Get_Parameter("Explosion_Name");
  803. Commands->Create_Explosion( explosion_def_name, pos, NULL );
  804. float time = Commands->Get_Random( 3, 6 );
  805. Commands->Send_Custom_Event( obj, obj, M00_CUSTOM_BUILDING_EXPLODE, 1, time );
  806. }
  807. }
  808. if ( type == M00_CUSTOM_BUILDING_EXPLODE_NO )
  809. {
  810. building_explode = false;
  811. }
  812. if ( type == M00_CUSTOM_BUILDING_EXPLODE_YES )
  813. {
  814. building_explode = true;
  815. }
  816. }
  817. };
  818. DECLARE_SCRIPT (M00_BuildingStateSoundController, "BuildingSpeaker_ID:int")
  819. {
  820. int object_from;
  821. REGISTER_VARIABLES()
  822. {
  823. SAVE_VARIABLE( object_from, 1 );
  824. }
  825. void Created( GameObject *obj)
  826. {
  827. object_from = Get_Int_Parameter("BuildingSpeaker_ID");
  828. }
  829. void Killed( GameObject * obj, GameObject *killer )
  830. {
  831. GameObject *target = Commands->Find_Object(object_from);
  832. if (target)
  833. {
  834. Commands->Send_Custom_Event( obj, target, M00_CUSTOM_SOUND_BUILDING, 1, 0.0f); // Play Destroyed Sounds
  835. Commands->Send_Custom_Event( obj, target, M00_CUSTOM_BUILDING_EXPLODE, 1, 0.0f); // Play Explosion Sounds
  836. }
  837. }
  838. void Custom (GameObject* obj, int type, int param, GameObject* sender)
  839. {
  840. if ( type == M00_CUSTOM_BUILDING_EXPLODE_NO ) // flip play building explosions to false.
  841. {
  842. GameObject *target = Commands->Find_Object(object_from);
  843. if (target)
  844. Commands->Send_Custom_Event( obj, target, M00_CUSTOM_BUILDING_EXPLODE_NO, 1, 0.0f);
  845. }
  846. if ( type == M00_CUSTOM_BUILDING_EXPLODE_YES ) // flip play building explosions to true.
  847. {
  848. GameObject *target = Commands->Find_Object(object_from);
  849. if (target)
  850. Commands->Send_Custom_Event( obj, target, M00_CUSTOM_BUILDING_EXPLODE_YES, 1, 0.0f);
  851. }
  852. }
  853. };