Test_Cinematic.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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. *
  22. * DESCRIPTION
  23. *
  24. * PROGRAMMER
  25. * Byon Garrabrant
  26. *
  27. * VERSION INFO
  28. * $Author: Greg_h $
  29. * $Revision: 51 $
  30. * $Modtime: 12/13/01 10:37a $
  31. * $Archive: /Commando/Code/Scripts/Test_Cinematic.cpp $
  32. *
  33. ******************************************************************************/
  34. #include "scripts.h"
  35. #include "toolkit.h"
  36. #include <stdio.h>
  37. #include <string.h>
  38. #define LAST_VALID_TIMESTAMP 999000.0f
  39. DECLARE_SCRIPT (M00_Cinematic_Attack_Command_DLS, "AttackDuration=1.0:float")
  40. {
  41. void Created( GameObject * obj )
  42. {
  43. float facing = Commands->Get_Facing(Owner());
  44. Vector3 target = Commands->Get_Position(Owner());
  45. target.X += cos(DEG_TO_RADF(facing)) * 10.0f;
  46. target.Y += sin(DEG_TO_RADF(facing)) * 10.0f;
  47. target.Z += 2.0f;
  48. ActionParamsStruct params;
  49. params.Set_Basic( this, 99, 1 );
  50. params.Set_Attack( target, 100.0f, 0.0f, true );
  51. params.AttackForceFire = true;
  52. Commands->Action_Attack( obj, params );
  53. Commands->Send_Custom_Event( obj, obj, 1, 1, Get_Float_Parameter("AttackDuration") );
  54. }
  55. void Custom( GameObject * obj, int type, int param, GameObject * sender )
  56. {
  57. Commands->Action_Reset( obj, 100 );
  58. }
  59. };
  60. DECLARE_SCRIPT(Test_Cinematic_Primary_Killed, "CallbackID=:int")
  61. {
  62. bool custom_sent;
  63. // Register variables to be Auto-Saved
  64. // All variables must have a unique ID, less than 256, that never changes
  65. REGISTER_VARIABLES()
  66. {
  67. SAVE_VARIABLE( custom_sent, 1 );
  68. }
  69. virtual void Created (GameObject *game_obj)
  70. {
  71. custom_sent = false;
  72. }
  73. virtual void Killed( GameObject * obj, GameObject * killer )
  74. {
  75. if (!custom_sent)
  76. {
  77. custom_sent = true;
  78. Commands->Debug_Message( "Cinematic Primary Killed\n" );
  79. int id = Get_Int_Parameter( "CallbackID" );
  80. GameObject * callback = Commands->Find_Object( id );
  81. if ( callback ) {
  82. Commands->Send_Custom_Event( obj, callback, M00_CUSTOM_CINEMATIC_PRIMARY_KILLED, 0 );
  83. }
  84. }
  85. }
  86. virtual void Destroyed( GameObject * obj )
  87. {
  88. if (!custom_sent)
  89. {
  90. custom_sent = true;
  91. Commands->Debug_Message( "Cinematic Primary Destroyed\n" );
  92. int id = Get_Int_Parameter( "CallbackID" );
  93. GameObject * callback = Commands->Find_Object( id );
  94. if ( callback ) {
  95. Commands->Send_Custom_Event( obj, callback, M00_CUSTOM_CINEMATIC_PRIMARY_KILLED, 0 );
  96. }
  97. }
  98. }
  99. };
  100. DECLARE_SCRIPT(Test_Cinematic, "ControlFilename=:string")
  101. {
  102. public:
  103. /*
  104. ** Object Slots
  105. */
  106. #define NUM_SLOTS 40
  107. int ObjectSlots[ NUM_SLOTS ];
  108. int MyID; // doesn't need to be saved
  109. /*
  110. ** Timing
  111. */
  112. unsigned int LastSyncTime;
  113. float Time;
  114. float FrameSync;
  115. bool PrimaryKilled;
  116. bool IsCameraCinematic;
  117. /*
  118. ** Parameters
  119. */
  120. char * NextParameter;
  121. /*
  122. ** Control Lines
  123. */
  124. struct ControlLine {
  125. float Time;
  126. char * Command;
  127. ControlLine * Next;
  128. };
  129. ControlLine * Controls;
  130. void Add_Control_Line( float time, const char * command )
  131. {
  132. ControlLine * control = new ControlLine;
  133. control->Time = time;
  134. control->Command = strdup( command );
  135. control->Next = NULL;
  136. if ( Controls == NULL || Controls->Time > time ) {
  137. control->Next = Controls;
  138. Controls = control;
  139. } else {
  140. ControlLine * node = Controls;
  141. while ( (node->Next != NULL) && (node->Next->Time <= time) ) {
  142. node = node->Next;
  143. }
  144. control->Next = node->Next;
  145. node->Next = control;
  146. }
  147. }
  148. void Remove_Head_Control_Line( void )
  149. {
  150. if ( Controls != NULL ) {
  151. ControlLine * control = Controls;
  152. Controls = Controls->Next;
  153. free( control->Command );
  154. delete control;
  155. }
  156. }
  157. void Display_Control_Lines( void )
  158. {
  159. for ( ControlLine * node = Controls; node != NULL; node = node->Next ) {
  160. // Commands->Debug_Message( "%3.2f \"%s\"\n", node->Time, node->Command );
  161. }
  162. }
  163. /*
  164. ** Loading the control file, line-by-line
  165. */
  166. void Load_Control_File( const char * filename )
  167. {
  168. Commands->Debug_Message( "Loading Control File %s\n", (int)filename );
  169. char full_filename[80];
  170. sprintf( full_filename, "DATA\\%s", filename );
  171. // FILE * in = fopen( full_filename, "rt" );
  172. int handle = Commands->Text_File_Open( filename );
  173. if ( handle == 0 ) {
  174. Commands->Debug_Message( "Failed to open %s\n", (int)full_filename );
  175. return;
  176. }
  177. char *line,line_data[200];
  178. while ( Commands->Text_File_Get_String( handle, line_data, sizeof( line_data )-1 ) != NULL ) {
  179. line = line_data;
  180. // Convert tabs to spaces
  181. for ( char * l = line; *l; l++ ) {
  182. if ( *l == 9 ) *l = ' ';
  183. }
  184. // Remove leading and trailing white space
  185. while ( *line && *line <= ' ' ) line++;
  186. int length = ::strlen( line );
  187. while ( (length != 0) && (line[length-1] <= ' ') ) {
  188. line[--length] = 0;
  189. }
  190. if ( *line && *line != ';' ) { // ignore comments
  191. float time;
  192. time = atof( line );
  193. if ( time < 0 ) { // handle frame numbers
  194. time = -time / 30.f;
  195. }
  196. while ( *line && *line > ' ' ) line++;
  197. while ( *line && *line <= ' ' ) line++;
  198. if ( *line ) {
  199. Add_Control_Line( time, line );
  200. }
  201. }
  202. }
  203. // fclose( in );
  204. Commands->Text_File_Close( handle );
  205. }
  206. /*
  207. **
  208. */
  209. char * Get_Command_Parameter( char * string = NULL )
  210. {
  211. if ( string != NULL ) {
  212. NextParameter = string;
  213. }
  214. if ( NextParameter == NULL || *NextParameter == 0 ) return "";
  215. // Start at this parameter;
  216. char * parameter = NextParameter;
  217. // Skip leading whitespace
  218. while ( *parameter != 0 && *parameter <= ' ' ) parameter++;
  219. // if starting with quote, find end quote
  220. if ( *parameter == '\"' ) {
  221. parameter++;
  222. NextParameter = parameter;
  223. while ( *NextParameter && *NextParameter != '\"' ) {
  224. NextParameter++;
  225. }
  226. }
  227. // Find next parameter end
  228. while ( *NextParameter && *NextParameter != ',' ) {
  229. NextParameter++;
  230. }
  231. // Terminate
  232. if ( *NextParameter ) {
  233. *NextParameter++ = 0;
  234. }
  235. // Remove trailing whitespace
  236. int length = ::strlen( parameter );
  237. while ( length && parameter[ length-1 ] <= ' ' ) {
  238. parameter[ --length ] = 0;
  239. }
  240. // Remove end quote
  241. if ( length && parameter[ length-1 ] == '\"' ) {
  242. parameter[ --length ] = 0;
  243. }
  244. return parameter;
  245. }
  246. #define CHUNKID_VARIABLES 1000
  247. #define CHUNKID_OBJECT_SLOTS 1001
  248. #define CHUNKID_CONTROL_LINES 1002
  249. #define CHUNKID_VARIABLE_SYNC_DIFF 1
  250. #define CHUNKID_VARIABLE_TIME 2
  251. #define CHUNKID_CONTROL_TIME 4
  252. #define CHUNKID_CONTROL_COMMAND_SIZE 5
  253. #define CHUNKID_CONTROL_COMMAND 6
  254. #define CHUNKID_PRIMARY_KILLED 7
  255. /*
  256. **
  257. */
  258. void Save(ScriptSaver& saver)
  259. {
  260. // Commands->Debug_Message( "Cinematic Saving\n" );
  261. // Commands->Debug_Message("Sync time is %d.\n", Commands->Get_Sync_Time());
  262. // Save the Variables
  263. Commands->Begin_Chunk(saver, CHUNKID_VARIABLES);
  264. int sync_diff = Commands->Get_Sync_Time() - LastSyncTime;
  265. Commands->Save_Data(saver, CHUNKID_VARIABLE_SYNC_DIFF, sizeof( sync_diff ), &sync_diff );
  266. //Commands->Debug_Message( "Saving sync_diff %d\n", sync_diff );
  267. Commands->Save_Data(saver, CHUNKID_VARIABLE_TIME, sizeof( Time ), &Time );
  268. //Commands->Debug_Message( "Saving Time %f\n", Time );
  269. Commands->Save_Data(saver, CHUNKID_PRIMARY_KILLED, sizeof( PrimaryKilled ), &PrimaryKilled );
  270. Commands->End_Chunk(saver);
  271. // Save the Object Slots
  272. Commands->Begin_Chunk(saver, CHUNKID_OBJECT_SLOTS);
  273. for ( int i = 0; i < NUM_SLOTS; i++ ) {
  274. if ( ObjectSlots[i] != 0 ) {
  275. Commands->Save_Data(saver, i, sizeof( ObjectSlots[i] ), &ObjectSlots[ i ] );
  276. //Commands->Debug_Message( "Saving Slot %d as %d\n", i, ObjectSlots[ i ] );
  277. }
  278. }
  279. Commands->End_Chunk(saver);
  280. // Save Control Lines
  281. Commands->Begin_Chunk(saver, CHUNKID_CONTROL_LINES);
  282. ControlLine * controls = Controls;
  283. while ( controls != NULL ) {
  284. Commands->Save_Data(saver, CHUNKID_CONTROL_TIME, sizeof( controls->Time ), &controls->Time );
  285. int len = strlen( controls->Command ) + 1;
  286. Commands->Save_Data(saver, CHUNKID_CONTROL_COMMAND_SIZE, sizeof( len ), &len );
  287. Commands->Save_Data(saver, CHUNKID_CONTROL_COMMAND, len, controls->Command );
  288. //Commands->Debug_Message( "Saving Command %f %s\n", controls->Time, controls->Command );
  289. controls = controls->Next;
  290. }
  291. Commands->End_Chunk(saver);
  292. }
  293. void Load(ScriptLoader& loader)
  294. {
  295. Controls = NULL;
  296. NextParameter = NULL;
  297. for ( int i = 0; i < NUM_SLOTS; i++ ) {
  298. ObjectSlots[i] =0;
  299. }
  300. // Commands->Debug_Message( "Cinematic Loading\n" );
  301. // Commands->Debug_Message("Sync time is %d.\n", Commands->Get_Sync_Time());
  302. unsigned int chunkID;
  303. while (Commands->Open_Chunk(loader, &chunkID)) {
  304. switch (chunkID) {
  305. case CHUNKID_VARIABLES:
  306. {
  307. int id;
  308. int sync_diff;
  309. while (Commands->Load_Begin(loader, &id)) {
  310. switch ( id ) {
  311. case CHUNKID_VARIABLE_SYNC_DIFF:
  312. Commands->Load_Data(loader, sizeof( sync_diff ), &sync_diff );
  313. //Commands->Debug_Message( "Loading sync_diff %d\n", sync_diff );
  314. LastSyncTime = Commands->Get_Sync_Time() - sync_diff;
  315. break;
  316. case CHUNKID_VARIABLE_TIME:
  317. Commands->Load_Data(loader, sizeof( Time ), &Time );
  318. //Commands->Debug_Message( "Loading Time %f\n", Time );
  319. break;
  320. case CHUNKID_PRIMARY_KILLED:
  321. Commands->Load_Data(loader, sizeof( PrimaryKilled ), &PrimaryKilled );
  322. //Commands->Debug_Message( "Loading Time %f\n", Time );
  323. break;
  324. }
  325. Commands->Load_End(loader);
  326. }
  327. }
  328. break;
  329. case CHUNKID_OBJECT_SLOTS:
  330. {
  331. int id;
  332. while (Commands->Load_Begin(loader, &id)) {
  333. if ( id >= 0 && id < NUM_SLOTS ) {
  334. Commands->Load_Data(loader, sizeof( ObjectSlots[id] ), &ObjectSlots[id] );
  335. //Commands->Debug_Message( "Loading Slot %d as %d\n", id, ObjectSlots[ id ] );
  336. }
  337. Commands->Load_End(loader);
  338. }
  339. }
  340. break;
  341. case CHUNKID_CONTROL_LINES:
  342. {
  343. int id;
  344. float time = 0;
  345. int len = 0;
  346. while (Commands->Load_Begin(loader, &id)) {
  347. if ( id == CHUNKID_CONTROL_TIME ) {
  348. Commands->Load_Data(loader, sizeof( time ), &time );
  349. }
  350. if ( id == CHUNKID_CONTROL_COMMAND_SIZE ) {
  351. Commands->Load_Data(loader, sizeof( len ), &len );
  352. }
  353. if ( id == CHUNKID_CONTROL_COMMAND ) {
  354. #define MAX_COMMAND_LOAD_SIZE 200
  355. char load_command[MAX_COMMAND_LOAD_SIZE+1];
  356. if ( len < MAX_COMMAND_LOAD_SIZE ) {
  357. Commands->Load_Data(loader, len, &load_command[0] );
  358. Add_Control_Line( time, load_command );
  359. //Commands->Debug_Message( "Loading Command %f %s\n", time, load_command );
  360. }
  361. }
  362. Commands->Load_End(loader);
  363. }
  364. }
  365. break;
  366. default:
  367. DebugPrint("***** Cinematic Script::Load() - Unrecognized chunk %0x!\n", chunkID);
  368. break;
  369. }
  370. Commands->Close_Chunk(loader);
  371. }
  372. }
  373. char * Get_First_Parameter( char * str ) { return Get_Command_Parameter( str ); }
  374. char * Get_Next_Parameter( void ) { return Get_Command_Parameter(); }
  375. /*
  376. **
  377. */
  378. void Command_Create_Object( char * params )
  379. {
  380. // Commands->Debug_Message_2( "Creating Object %s\n", (int)params );
  381. int slot = atoi( Get_First_Parameter( params ) );
  382. char * model_name = Get_Next_Parameter();
  383. if ( (slot < 0) || ( slot >= NUM_SLOTS ) ) {
  384. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  385. slot = -1;
  386. }
  387. if ( slot != -1 && ObjectSlots[ slot ] != 0 ) {
  388. // Commands->Debug_Message( "Used Slot number %d\n", slot );
  389. // Commands->Debug_Message( "Slot used by %d\n", ObjectSlots[ slot ] );
  390. }
  391. // Create a decoration cinematic object, then set it's model
  392. GameObject * obj = Commands->Create_Object( "Generic_Cinematic", Commands->Get_Position( Owner() ) );
  393. Commands->Enable_Hibernation( obj, false );
  394. if ( obj ) {
  395. Commands->Add_To_Dirty_Cull_List(obj);
  396. Commands->Set_Model( obj, model_name );
  397. Commands->Set_Facing( obj, Commands->Get_Facing( Owner() ) );
  398. if ( slot != -1 ) {
  399. ObjectSlots[ slot ] = Commands->Get_ID( obj );
  400. }
  401. if ( IsCameraCinematic ) {
  402. Commands->Enable_Cinematic_Freeze( obj, false );
  403. Commands->Enable_Hibernation(obj, false);
  404. }
  405. } else {
  406. // Commands->Debug_Message( "Failed to create %s\n", (int)model_name );
  407. }
  408. }
  409. /*
  410. **
  411. */
  412. void Command_Create_Real_Object( char * params )
  413. {
  414. // Commands->Debug_Message_2( "Creating Real Object %s\n", (int)params );
  415. int slot = atoi( Get_First_Parameter( params ) );
  416. char * preset_name = Get_Next_Parameter();
  417. char * host_slot_name = Get_Next_Parameter();
  418. char * host_bone_name = Get_Next_Parameter();
  419. if ( (slot < 0) || ( slot >= NUM_SLOTS ) ) {
  420. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  421. slot = -1;
  422. }
  423. if ( slot != -1 && ObjectSlots[ slot ] != 0 ) {
  424. // Commands->Debug_Message( "Used Slot number %d\n", slot );
  425. // Commands->Debug_Message( "Slot used by %d\n", ObjectSlots[ slot ] );
  426. }
  427. GameObject * obj = NULL;
  428. if (( host_slot_name != NULL ) && ( *host_slot_name != 0 ) ) {
  429. int host_slot = atoi( host_slot_name );
  430. GameObject * host_obj = Commands->Find_Object( ObjectSlots[ host_slot ] );
  431. obj = Commands->Create_Object_At_Bone( host_obj, preset_name, host_bone_name );
  432. } else {
  433. obj = Commands->Create_Object( preset_name, Commands->Get_Position( Owner() ) );
  434. Commands->Set_Facing( obj, Commands->Get_Facing( Owner() ) );
  435. }
  436. if ( obj ) {
  437. Commands->Enable_Engine( obj, true );
  438. Commands->Add_To_Dirty_Cull_List(obj);
  439. // Commands->Enable_Hibernation( obj, false );
  440. if ( slot != -1 ) {
  441. ObjectSlots[ slot ] = Commands->Get_ID( obj );
  442. }
  443. if ( IsCameraCinematic ) {
  444. Commands->Enable_Cinematic_Freeze( obj, false );
  445. Commands->Enable_Hibernation(obj, false);
  446. }
  447. } else {
  448. // Commands->Debug_Message( "Failed to create real %s\n", (int)preset_name );
  449. }
  450. }
  451. /*
  452. **
  453. */
  454. void Command_Create_Explosion( char * params )
  455. {
  456. // Commands->Debug_Message_2( "Creating Explosion %s\n", (int)params );
  457. char * preset_name = Get_First_Parameter( params );
  458. int host_slot = atoi( Get_Next_Parameter() );
  459. char * host_bone_name = Get_Next_Parameter();
  460. GameObject * host_obj = Commands->Find_Object( ObjectSlots[ host_slot ] );
  461. Commands->Create_Explosion_At_Bone( preset_name, host_obj, host_bone_name );
  462. }
  463. void Command_Destroy_Object( char * params )
  464. {
  465. // Commands->Debug_Message_2( "Destroying Object %s\n", (int)params );
  466. int slot = atoi( Get_First_Parameter( params ) );
  467. if ( (slot < 0) || ( slot >= NUM_SLOTS ) ) {
  468. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  469. slot = -1;
  470. }
  471. if ( slot != -1 ) {
  472. if ( ObjectSlots[ slot ] == 0 ) {
  473. // Commands->Debug_Message( "Empty Slot number %d\n", slot );
  474. } else {
  475. int id = ObjectSlots[ slot ];
  476. GameObject * obj = Commands->Find_Object( id );
  477. if ( obj ) {
  478. Commands->Destroy_Object( obj );
  479. }
  480. }
  481. }
  482. }
  483. void Command_Play_Animation( char * params )
  484. {
  485. // Commands->Debug_Message( "Playing Animation %s\n", (int)params );
  486. int slot = atoi( Get_First_Parameter( params ) );
  487. char * name = Get_Next_Parameter();
  488. bool looping = atoi( Get_Next_Parameter() ) != 0;
  489. char * sub_obj_name = Get_Next_Parameter();
  490. bool is_blended = atoi( Get_Next_Parameter() ) == 1;
  491. if ( (slot < 0) || ( slot >= NUM_SLOTS ) ) {
  492. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  493. slot = -1;
  494. }
  495. if ( slot != -1 ) {
  496. int id = ObjectSlots[ slot ];
  497. GameObject * obj = Commands->Find_Object( id );
  498. if ( obj ) {
  499. Commands->Set_Animation( obj, name, looping, sub_obj_name, FrameSync, -1.0F, is_blended );
  500. // Anyone that plays an animation in a camera cine, doesn't get innate
  501. if ( IsCameraCinematic ) {
  502. Commands->Innate_Disable( obj );
  503. }
  504. } else {
  505. // Commands->Debug_Message( "Slot Object not found %d\n", slot );
  506. }
  507. }
  508. }
  509. void Command_Play_Audio( char * params )
  510. {
  511. // Commands->Debug_Message( "Playing Audio %s\n", (int)params );
  512. char * preset_name = Get_First_Parameter( params );
  513. char * slot_name = Get_Next_Parameter();
  514. char * bone_name = Get_Next_Parameter();
  515. int slot = -1;
  516. if (( slot_name != NULL ) && ( *slot_name != 0 ) ) {
  517. slot = atoi( slot_name );
  518. }
  519. if ( (slot < 0) || ( slot >= NUM_SLOTS ) ) {
  520. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  521. slot = -1;
  522. }
  523. if ( slot != -1 ) {
  524. int id = ObjectSlots[ slot ];
  525. GameObject * obj = Commands->Find_Object( id );
  526. if ( obj ) {
  527. Commands->Create_3D_Sound_At_Bone( preset_name, obj, bone_name );
  528. } else {
  529. // Commands->Debug_Message( "Slot Object not found %d\n", slot );
  530. }
  531. } else {
  532. Commands->Create_2D_Sound( preset_name );
  533. }
  534. }
  535. void Command_Control_Camera( char * params )
  536. {
  537. // Commands->Debug_Message_2( "Controlling the camera %s\n", (int)params );
  538. int slot = atoi( Get_First_Parameter( params ) );
  539. if ( (slot < -1) || ( slot >= NUM_SLOTS ) ) {
  540. // Commands->Debug_Message( "Bad Slot Number %d\n", slot );
  541. slot = -1;
  542. }
  543. if ( slot != -1 ) {
  544. int id = ObjectSlots[ slot ];
  545. GameObject * obj = Commands->Find_Object( id );
  546. if ( obj ) {
  547. Commands->Set_Camera_Host( obj );
  548. Commands->Control_Enable( Commands->Get_The_Star(), false );
  549. Commands->Enable_HUD(0);
  550. IsCameraCinematic = true;
  551. Commands->Enable_Cinematic_Freeze( obj, false );
  552. Commands->Enable_Hibernation(obj, false);
  553. } else {
  554. // Commands->Debug_Message( "Slot Object not found %d\n", slot );
  555. }
  556. } else {
  557. Commands->Set_Camera_Host( NULL );
  558. Commands->Control_Enable( Commands->Get_The_Star(), true );
  559. Commands->Enable_HUD(1);
  560. }
  561. }
  562. void Command_Send_Custom( char * params )
  563. {
  564. // Commands->Debug_Message_2( "Send Custom %s\n", (int)params );
  565. char * to_id_name = Get_First_Parameter( params );
  566. int type = atoi( Get_Next_Parameter() );
  567. char * parameter_name = Get_Next_Parameter();
  568. int to_id = -1;
  569. if ( ::strchr( to_id_name, '#' ) != NULL ) {
  570. int to_slot = atoi( ::strchr( to_id_name, '#' ) + 1 );
  571. if ( (to_slot < 0) || ( to_slot >= NUM_SLOTS ) ) {
  572. // Commands->Debug_Message( "Bad Slot Number %d\n", to_slot );
  573. } else {
  574. to_id = ObjectSlots[ to_slot ];
  575. }
  576. } else {
  577. to_id = atoi( to_id_name );
  578. }
  579. int parameter = 0;
  580. if ( ::strchr( parameter_name, '#' ) != NULL ) {
  581. int parameter_slot = atoi( ::strchr( parameter_name, '#' ) + 1 );
  582. if ( (parameter_slot < 0) || ( parameter_slot >= NUM_SLOTS ) ) {
  583. // Commands->Debug_Message( "Bad Slot Number %d\n", parameter_slot );
  584. } else {
  585. parameter = ObjectSlots[ parameter_slot ];
  586. }
  587. } else {
  588. parameter = atoi( parameter_name );
  589. }
  590. GameObject * to = Commands->Find_Object( to_id );
  591. if ( to ) {
  592. Commands->Send_Custom_Event( Owner(), to, type, parameter );
  593. } else {
  594. // Commands->Debug_Message( "Send Custom Target not found %d\n", to_id );
  595. }
  596. }
  597. void Command_Attach_To_Bone( char * params )
  598. {
  599. // Commands->Debug_Message_2( "Attach_To_Bone %s\n", (int)params );
  600. int obj_slot = atoi( Get_First_Parameter( params ) );
  601. int host_slot = atoi( Get_Next_Parameter() );
  602. char * bone_name = Get_Next_Parameter();
  603. if ( (obj_slot < 0) || ( obj_slot >= NUM_SLOTS ) ) {
  604. // Commands->Debug_Message( "Bad Obj Slot Number %d\n", obj_slot );
  605. obj_slot = -1;
  606. }
  607. if ( (host_slot < 0) || ( host_slot >= NUM_SLOTS ) ) {
  608. // Commands->Debug_Message( "Bad Host Slot Number %d\n", host_slot );
  609. host_slot = -1;
  610. }
  611. if ( obj_slot != -1 ) {
  612. int id = ObjectSlots[ obj_slot ];
  613. GameObject * obj = Commands->Find_Object( id );
  614. if ( obj ) {
  615. if ( host_slot != -1 ) {
  616. int id = ObjectSlots[ host_slot ];
  617. GameObject * host = Commands->Find_Object( id );
  618. if ( host ) {
  619. Commands->Attach_To_Object_Bone( obj, host, bone_name );
  620. } else {
  621. // Commands->Debug_Message( "Host Object not found %d\n", host_slot );
  622. }
  623. } else {
  624. Commands->Attach_To_Object_Bone( obj, NULL, NULL );
  625. }
  626. } else {
  627. // Commands->Debug_Message( "Slot Object not found %d\n", obj_slot );
  628. }
  629. }
  630. }
  631. void Command_Attach_Script( char * params )
  632. {
  633. // Commands->Debug_Message_2( "Attach_Script %s\n", (int)params );
  634. int obj_slot = atoi( Get_First_Parameter( params ) );
  635. char * script_name = Get_Next_Parameter();
  636. char * script_parameters = Get_Next_Parameter();
  637. if ( (obj_slot < 0) || ( obj_slot >= NUM_SLOTS ) ) {
  638. // Commands->Debug_Message( "Bad Obj Slot Number %d\n", obj_slot );
  639. obj_slot = -1;
  640. }
  641. if ( obj_slot != -1 ) {
  642. int id = ObjectSlots[ obj_slot ];
  643. GameObject * obj = Commands->Find_Object( id );
  644. if ( obj ) {
  645. // Commands->Debug_Message( "Attaching Script %s \"%s\"\n", script_name, script_parameters );
  646. Commands->Attach_Script( obj, script_name, script_parameters );
  647. } else {
  648. // Commands->Debug_Message( "Slot Object not found %d\n", obj_slot );
  649. }
  650. }
  651. }
  652. void Command_Set_Primary( char * params )
  653. {
  654. // Commands->Debug_Message_2( "Set_Primary %s\n", (int)params );
  655. int obj_slot = atoi( Get_First_Parameter( params ) );
  656. if ( (obj_slot < 0) || ( obj_slot >= NUM_SLOTS ) ) {
  657. // Commands->Debug_Message( "Bad Obj Slot Number %d\n", obj_slot );
  658. obj_slot = -1;
  659. }
  660. if ( obj_slot != -1 ) {
  661. int id = ObjectSlots[ obj_slot ];
  662. GameObject * obj = Commands->Find_Object( id );
  663. if ( obj ) {
  664. Commands->Enable_Hibernation( obj, false );
  665. char id[10];
  666. sprintf( id, "%d", MyID );
  667. Commands->Attach_Script( obj, "Test_Cinematic_Primary_Killed", id );
  668. } else {
  669. // Commands->Debug_Message( "Slot Object not found %d\n", obj_slot );
  670. }
  671. }
  672. }
  673. void Command_Move_Slot( char * params )
  674. {
  675. int new_slot = atoi( Get_First_Parameter( params ) );
  676. int old_slot = atoi( Get_Next_Parameter() );
  677. if ( (new_slot < 0) || ( new_slot >= NUM_SLOTS ) ) {
  678. new_slot = -1;
  679. }
  680. if ( (old_slot < 0) || ( old_slot >= NUM_SLOTS ) ) {
  681. old_slot = -1;
  682. }
  683. if ( new_slot != -1 && old_slot != -1 && new_slot != old_slot ) {
  684. ObjectSlots[ new_slot ] = ObjectSlots[ old_slot ];
  685. ObjectSlots[ old_slot ] = 0;
  686. }
  687. }
  688. void Command_Sniper_Control( char * params )
  689. {
  690. int enabled = atoi( Get_First_Parameter( params ) );
  691. float zoom = atof( Get_Next_Parameter() );
  692. Commands->Cinematic_Sniper_Control( enabled != 0, zoom );
  693. }
  694. void Command_Shake_Camera( char * params )
  695. {
  696. int obj_slot = atoi( Get_First_Parameter( params ) );
  697. float intensity = atof( Get_Next_Parameter() );
  698. float duration = atof( Get_Next_Parameter() );
  699. if ( (obj_slot < 0) || ( obj_slot >= NUM_SLOTS ) ) {
  700. // Commands->Debug_Message( "Bad Obj Slot Number %d\n", obj_slot );
  701. obj_slot = -1;
  702. }
  703. if ( obj_slot != -1 ) {
  704. int id = ObjectSlots[ obj_slot ];
  705. GameObject * obj = Commands->Find_Object( id );
  706. if ( obj ) {
  707. Vector3 pos = Commands->Get_Bone_Position( obj, "Camera" );
  708. Commands->Shake_Camera( pos, 100, intensity, duration );
  709. } else {
  710. // Commands->Debug_Message( "Slot Object not found %d\n", obj_slot );
  711. }
  712. }
  713. }
  714. void Command_Enable_Shadow( char * params )
  715. {
  716. int obj_slot = atoi( Get_First_Parameter( params ) );
  717. int onoff = atoi( Get_Next_Parameter() );
  718. if ( (obj_slot < 0) || ( obj_slot >= NUM_SLOTS ) ) {
  719. // Commands->Debug_Message( "Bad Obj Slot Number %d\n", obj_slot );
  720. obj_slot = -1;
  721. }
  722. if ( obj_slot != -1 ) {
  723. int id = ObjectSlots[ obj_slot ];
  724. GameObject * obj = Commands->Find_Object( id );
  725. if ( obj ) {
  726. Commands->Enable_Shadow(obj,(onoff != 0));
  727. } else {
  728. // Commands->Debug_Message( "Slot Object not found %d\n", obj_slot );
  729. }
  730. }
  731. }
  732. void Command_Enable_Letterbox( char * params )
  733. {
  734. int onoff = atoi( Get_First_Parameter( params ) );
  735. float time = atof( Get_Next_Parameter() );
  736. Commands->Enable_Letterbox(!!onoff,time);
  737. }
  738. void Command_Set_Screen_Fade_Color( char * params )
  739. {
  740. float r = atof( Get_First_Parameter( params ) );
  741. float g = atof( Get_Next_Parameter() );
  742. float b = atof( Get_Next_Parameter() );
  743. float time = atof( Get_Next_Parameter() );
  744. Commands->Set_Screen_Fade_Color(r,g,b,time);
  745. }
  746. void Command_Set_Screen_Fade_Opacity( char * params )
  747. {
  748. float opacity = atof( Get_First_Parameter( params ) );
  749. float time = atof( Get_Next_Parameter() );
  750. Commands->Set_Screen_Fade_Opacity(opacity,time);
  751. }
  752. /*
  753. **
  754. */
  755. bool Title_Match( char * * command, char * title )
  756. {
  757. if ( ::strnicmp( *command, title, strlen( title ) ) == 0 ) {
  758. *command += strlen( title );
  759. while ( **command && **command != ',' ) {
  760. (*command)++;
  761. }
  762. if ( **command == ',' ) {
  763. (*command)++;
  764. }
  765. return true;
  766. }
  767. return false;
  768. }
  769. void Parse_Command( char *command )
  770. {
  771. // Commands->Debug_Message( "Parse %s\n", (int)command );
  772. if ( Title_Match( &command, "Create_Object" ) ) Command_Create_Object( command );
  773. else if ( Title_Match( &command, "Create_Real_Object" ) ) Command_Create_Real_Object( command );
  774. else if ( Title_Match( &command, "Create_Explosion" ) ) Command_Create_Explosion( command );
  775. else if ( Title_Match( &command, "Destroy_Object" ) ) Command_Destroy_Object( command );
  776. else if ( Title_Match( &command, "Play_Animation" ) ) Command_Play_Animation( command );
  777. else if ( Title_Match( &command, "Play_Audio" ) ) Command_Play_Audio( command );
  778. else if ( Title_Match( &command, "Control_Camera" ) ) Command_Control_Camera( command );
  779. else if ( Title_Match( &command, "Send_Custom" ) ) Command_Send_Custom( command );
  780. else if ( Title_Match( &command, "Attach_To_Bone" ) ) Command_Attach_To_Bone( command );
  781. else if ( Title_Match( &command, "Attach_Script" ) ) Command_Attach_Script( command );
  782. else if ( Title_Match( &command, "Set_Primary" ) ) Command_Set_Primary( command );
  783. else if ( Title_Match( &command, "Move_Slot" ) ) Command_Move_Slot( command );
  784. else if ( Title_Match( &command, "Sniper_Control" ) ) Command_Sniper_Control( command );
  785. else if ( Title_Match( &command, "Shake_Camera" ) ) Command_Shake_Camera( command );
  786. else if ( Title_Match( &command, "Enable_Shadow" ) ) Command_Enable_Shadow( command );
  787. else if ( Title_Match( &command, "Enable_Letterbox" ) ) Command_Enable_Letterbox( command );
  788. else if ( Title_Match( &command, "Set_Screen_Fade_Color" ) ) Command_Set_Screen_Fade_Color( command );
  789. else if ( Title_Match( &command, "Set_Screen_Fade_Opacity" ) ) Command_Set_Screen_Fade_Opacity( command );
  790. else {
  791. // Commands->Debug_Message( "Failed to parse %s\n", (int)command );
  792. }
  793. }
  794. void Parse_Commands( GameObject* obj ) {
  795. unsigned int sync_diff = Commands->Get_Sync_Time() - LastSyncTime;
  796. LastSyncTime += sync_diff;
  797. float bump_time = ((float)sync_diff) / 1000.0f;
  798. Time += bump_time;
  799. MyID = Commands->Get_ID( obj );
  800. // Commands->Debug_Message( "Cinematic Time %1.3f Frame %1.3f Bump Time %1.3f\n", Time, Time * 30.0f, bump_time );
  801. // If Primary Destroyed,
  802. if ( PrimaryKilled ) {
  803. // skip all timestamps < LAST_VALID_TIMESTAMP
  804. while ( Controls != NULL && Controls->Time <= LAST_VALID_TIMESTAMP ) {
  805. Remove_Head_Control_Line();
  806. }
  807. // Run all remaining commands
  808. while ( Controls != NULL ) {
  809. Parse_Command( Controls->Command );
  810. Remove_Head_Control_Line();
  811. }
  812. }
  813. while ( Controls != NULL && Controls->Time <= Time ) {
  814. FrameSync = (Time - Controls->Time) * 30.0f;
  815. Parse_Command( Controls->Command );
  816. Remove_Head_Control_Line();
  817. }
  818. if ( Controls != NULL ) {
  819. // if the next command is > than the LAST_VALID_TIMESTAMP, we are done
  820. if ( Controls->Time >= LAST_VALID_TIMESTAMP ) {
  821. Commands->Destroy_Object( obj );
  822. } else {
  823. float time_diff = Controls->Time - Time;
  824. Commands->Start_Timer( obj, this, time_diff, 0 );
  825. }
  826. } else {
  827. Commands->Destroy_Object( obj );
  828. }
  829. // Make sure we don't sleep
  830. if ( IsCameraCinematic ) {
  831. Commands->Enable_Cinematic_Freeze( obj, false );
  832. }
  833. }
  834. /*
  835. **
  836. */
  837. void Created(GameObject* obj)
  838. {
  839. Commands->Enable_Hibernation( obj, false );
  840. Controls = NULL;
  841. for ( int i = 0; i < NUM_SLOTS; i++ ) {
  842. ObjectSlots[ i ] = 0;
  843. }
  844. LastSyncTime = Commands->Get_Sync_Time();
  845. Time = 0;
  846. PrimaryKilled = false;
  847. IsCameraCinematic = false;
  848. Load_Control_File( Get_Parameter( "ControlFilename" ) );
  849. Parse_Commands( obj );
  850. }
  851. void Timer_Expired (GameObject* obj, int Timer_ID)
  852. {
  853. // Commands->Debug_Message("In Timer_Expired Get_Sync_Time is %d.\n", Commands->Get_Sync_Time());
  854. Parse_Commands(obj);
  855. }
  856. void Custom( GameObject * obj, int type, int param, GameObject * sender )
  857. {
  858. if ( type == M00_CUSTOM_CINEMATIC_PRIMARY_KILLED ) {
  859. if ( !PrimaryKilled ) { // Prevent loops
  860. Commands->Debug_Message("Cinematic:Primary Killed\n");
  861. PrimaryKilled = true;
  862. Parse_Commands( obj );
  863. }
  864. }
  865. if ( type >= M00_CUSTOM_CINEMATIC_SET_SLOT ) {
  866. int slot = type - M00_CUSTOM_CINEMATIC_SET_SLOT;
  867. if ( slot < NUM_SLOTS ) {
  868. if ( ObjectSlots[ slot ] != 0 ) {
  869. // Commands->Debug_Message( "Slot number %d used by %d\n", slot, ObjectSlots[ slot ] );
  870. } else {
  871. ObjectSlots[ slot ] = param;
  872. // Commands->Debug_Message( "Slot number %d set to %d\n", slot, ObjectSlots[ slot ] );
  873. }
  874. }
  875. }
  876. }
  877. };
  878. #if 0
  879. ;_________________________________________
  880. ;
  881. ; Available Cinematic Script Commands
  882. ;
  883. ; time/frame Create_Object, id (slot), preset_name, x, y, z, facing, animation
  884. ; id can be -1 to mean do not store this object, and do not destroy
  885. ; 0 Create_Object, 0, .44 Magnum, 0, 0, 0, 180, "Human.jump"
  886. ;
  887. ; time/frame Destroy_Object, id (slot)
  888. ; 0 Destroy_Object, 0
  889. ;
  890. ; time/frame Play_Animation, id (slot), animation_name, looping, sub_obj_name
  891. ; 0 Play_Animation, 0, "Human.Jump", false
  892. ;
  893. ; time/frame Control_Camera, id ( slot )
  894. ; use id -1 for disabling control;
  895. ; note this will also disable star control and disbale the hud
  896. ; 0 Control_Camera, 0
  897. ;
  898. TIME Create_Object SLOT MODEL_NAME
  899. TIME Create_Real_Object SLOT PRESET_NAME HOST_SLOT HOST_BONE_NAME
  900. TIME Destroy_Object SLOT
  901. TIME Play_Animation SLOT ANIMATION_NAME LOOPING SUB_OBJ_NAME IS_BLENDED
  902. TIME Play_Audio PRESET_NAME HOST_SLOT HOST_BONE_NAME
  903. TIME Control_Camera SLOT
  904. TIME Send_Custon [TO_ID/#TO_SLOT] TYPE [PARAM/#SLOT_PARAM]
  905. TIME Attach_To_Bone SLOT HOST_SLOT HOST_BONE_NAME
  906. TIME Attach_Script SLOT SCRIPT_NAME "SCRIPT_PARAMETERS"
  907. TIME Move_Slot New_Slot, Old_Slot
  908. TIME Sniper_Control ENABLED, ZOOM
  909. TIME Shake_Camera SLOT, INTENSITY, DURATION
  910. TIME Enable_Shadow SLOT, [1/0]
  911. TIME Enable_Letterbox [1/0], TIME_TO_ANIMATE_IN
  912. TIME Set_Screen_Fade_Color RED,GREEN,BLUE,TIME_TO_FADE (all colors floating point 0.0-1.0)
  913. TIME Set_Screen_Fade_Opacity OPACITY,TIME_TO_FADE
  914. To fill a slot, Send_Custom to the controller with
  915. type = M00_CUSTOM_CINEMATIC_SET_SLOT + SLOT_NUMBER
  916. parameter = OBJECT_ID
  917. ;_________________________________________
  918. #endif