Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.91 KB | None | 0 0
  1. scriptPrintln(channel, msg)
  2. {
  3. setprintchannel(channel);
  4. println(msg);
  5. setprintchannel ("script");
  6. }
  7.  
  8. debugPrintln(channel, msg)
  9. {
  10. setprintchannel("script_debug");
  11. println(msg);
  12. setprintchannel ("script");
  13. }
  14.  
  15. draw_debug_line(start, end, timer)
  16. {
  17. for (i=0;i<timer*20;i++)
  18. {
  19. line (start, end, (1,1,0.5));
  20. wait (0.05);
  21. }
  22. }
  23.  
  24. waittillend(msg)
  25. {
  26. self waittillmatch (msg, "end");
  27. }
  28.  
  29. randomvector(num)
  30. {
  31. return (randomfloat(num) - num*0.5, randomfloat(num) - num*0.5,randomfloat(num) - num*0.5);
  32. }
  33.  
  34. angle_dif(oldangle, newangle)
  35. {
  36. // returns the difference between two yaws
  37. if (oldangle == newangle)
  38. return 0;
  39.  
  40. while (newangle > 360)
  41. newangle -=360;
  42.  
  43. while (newangle < 0)
  44. newangle +=360;
  45.  
  46. while (oldangle > 360)
  47. oldangle -=360;
  48.  
  49. while (oldangle < 0)
  50. oldangle +=360;
  51.  
  52. olddif = undefined;
  53. newdif = undefined;
  54.  
  55. if (newangle > 180)
  56. newdif = 360 - newangle;
  57. else
  58. newdif = newangle;
  59.  
  60. if (oldangle > 180)
  61. olddif = 360 - oldangle;
  62. else
  63. olddif = oldangle;
  64.  
  65. outerdif = newdif + olddif;
  66. innerdif = 0;
  67.  
  68. if (newangle > oldangle)
  69. innerdif = newangle - oldangle;
  70. else
  71. innerdif = oldangle - newangle;
  72.  
  73. if (innerdif < outerdif)
  74. return innerdif;
  75. else
  76. return outerdif;
  77. }
  78.  
  79. vectorScale( vector, scale )
  80. {
  81. vector = (vector[0] * scale, vector[1] * scale, vector[2] * scale);
  82. return vector;
  83. }
  84.  
  85. sign( x )
  86. {
  87. if ( x >= 0 )
  88. return 1;
  89. return -1;
  90. }
  91.  
  92.  
  93. track(spot_to_track)
  94. {
  95. if(isdefined(self.current_target))
  96. {
  97. if(spot_to_track == self.current_target)
  98. return;
  99. }
  100. self.current_target = spot_to_track;
  101. }
  102.  
  103. get_enemy_team( team )
  104. {
  105. assertEx( team != "neutral", "Team must be allies or axis" );
  106.  
  107. teams = [];
  108. teams["axis"] = "allies";
  109. teams["allies"] = "axis";
  110.  
  111. return teams[team];
  112. }
  113.  
  114.  
  115. clear_exception( type )
  116. {
  117. assert( isdefined( self.exception[ type ] ) );
  118. self.exception[ type ] = anim.defaultException;
  119. }
  120.  
  121. set_exception( type, func )
  122. {
  123. assert( isdefined( self.exception[ type ] ) );
  124. self.exception[ type ] = func;
  125. }
  126.  
  127. set_all_exceptions( exceptionFunc )
  128. {
  129. keys = getArrayKeys( self.exception );
  130. for ( i=0; i < keys.size; i++ )
  131. {
  132. self.exception[ keys[ i ] ] = exceptionFunc;
  133. }
  134. }
  135.  
  136. set_flash_duration(time_in_seconds)
  137. {
  138. self.flashduration = time_in_seconds * 1000;
  139. }
  140.  
  141. cointoss()
  142. {
  143. return randomint( 100 ) >= 50 ;
  144. }
  145.  
  146.  
  147. waittill_string( msg, ent )
  148. {
  149. if ( msg != "death" )
  150. self endon ("death");
  151.  
  152. ent endon ( "die" );
  153. self waittill ( msg );
  154. ent notify ( "returned", msg );
  155. }
  156.  
  157. waittill_multiple( string1, string2, string3, string4, string5 )
  158. {
  159. self endon ("death");
  160. ent = spawnstruct();
  161. ent.threads = 0;
  162.  
  163. if (isdefined (string1))
  164. {
  165. self thread waittill_string (string1, ent);
  166. ent.threads++;
  167. }
  168. if (isdefined (string2))
  169. {
  170. self thread waittill_string (string2, ent);
  171. ent.threads++;
  172. }
  173. if (isdefined (string3))
  174. {
  175. self thread waittill_string (string3, ent);
  176. ent.threads++;
  177. }
  178. if (isdefined (string4))
  179. {
  180. self thread waittill_string (string4, ent);
  181. ent.threads++;
  182. }
  183. if (isdefined (string5))
  184. {
  185. self thread waittill_string (string5, ent);
  186. ent.threads++;
  187. }
  188.  
  189. while (ent.threads)
  190. {
  191. ent waittill ("returned");
  192. ent.threads--;
  193. }
  194.  
  195. ent notify ("die");
  196. }
  197.  
  198. waittill_multiple_ents( ent1, string1, ent2, string2, ent3, string3, ent4, string4 )
  199. {
  200. self endon ("death");
  201. ent = spawnstruct();
  202. ent.threads = 0;
  203.  
  204. if ( isdefined( ent1 ) )
  205. {
  206. assert( isdefined( string1 ) );
  207. ent1 thread waittill_string( string1, ent );
  208. ent.threads++;
  209. }
  210. if ( isdefined( ent2 ) )
  211. {
  212. assert( isdefined( string2 ) );
  213. ent2 thread waittill_string ( string2, ent );
  214. ent.threads++;
  215. }
  216. if ( isdefined( ent3 ) )
  217. {
  218. assert( isdefined( string3 ) );
  219. ent3 thread waittill_string ( string3, ent );
  220. ent.threads++;
  221. }
  222. if ( isdefined( ent4 ) )
  223. {
  224. assert( isdefined( string4 ) );
  225. ent4 thread waittill_string ( string4, ent );
  226. ent.threads++;
  227. }
  228.  
  229. while (ent.threads)
  230. {
  231. ent waittill ("returned");
  232. ent.threads--;
  233. }
  234.  
  235. ent notify ("die");
  236. }
  237.  
  238. waittill_any_return( string1, string2, string3, string4, string5 )
  239. {
  240. if ((!isdefined (string1) || string1 != "death") &&
  241. (!isdefined (string2) || string2 != "death") &&
  242. (!isdefined (string3) || string3 != "death") &&
  243. (!isdefined (string4) || string4 != "death") &&
  244. (!isdefined (string5) || string5 != "death"))
  245. self endon ("death");
  246.  
  247. ent = spawnstruct();
  248.  
  249. if (isdefined (string1))
  250. self thread waittill_string (string1, ent);
  251.  
  252. if (isdefined (string2))
  253. self thread waittill_string (string2, ent);
  254.  
  255. if (isdefined (string3))
  256. self thread waittill_string (string3, ent);
  257.  
  258. if (isdefined (string4))
  259. self thread waittill_string (string4, ent);
  260.  
  261. if (isdefined (string5))
  262. self thread waittill_string (string5, ent);
  263.  
  264. ent waittill ("returned", msg);
  265. ent notify ("die");
  266. return msg;
  267. }
  268.  
  269. waittill_any( string1, string2, string3, string4, string5 )
  270. {
  271. assert( isdefined( string1 ) );
  272.  
  273. if ( isdefined( string2 ) )
  274. self endon( string2 );
  275.  
  276. if ( isdefined( string3 ) )
  277. self endon( string3 );
  278.  
  279. if ( isdefined( string4 ) )
  280. self endon( string4 );
  281.  
  282. if ( isdefined( string5 ) )
  283. self endon( string5 );
  284.  
  285. self waittill( string1 );
  286. }
  287.  
  288. waittill_any_ents( ent1, string1, ent2, string2, ent3, string3, ent4, string4, ent5, string5, ent6, string6, ent7, string7 )
  289. {
  290. assert( isdefined( ent1 ) );
  291. assert( isdefined( string1 ) );
  292.  
  293. if ( ( isdefined( ent2 ) ) && ( isdefined( string2 ) ) )
  294. ent2 endon( string2 );
  295.  
  296. if ( ( isdefined( ent3 ) ) && ( isdefined( string3 ) ) )
  297. ent3 endon( string3 );
  298.  
  299. if ( ( isdefined( ent4 ) ) && ( isdefined( string4 ) ) )
  300. ent4 endon( string4 );
  301.  
  302. if ( ( isdefined( ent5 ) ) && ( isdefined( string5 ) ) )
  303. ent5 endon( string5 );
  304.  
  305. if ( ( isdefined( ent6 ) ) && ( isdefined( string6 ) ) )
  306. ent6 endon( string6 );
  307.  
  308. if ( ( isdefined( ent7 ) ) && ( isdefined( string7 ) ) )
  309. ent7 endon( string7 );
  310.  
  311. ent1 waittill( string1 );
  312. }
  313.  
  314. /*
  315. =============
  316. ///ScriptDocBegin
  317. "Name: isFlashed()"
  318. "Summary: Returns true if the player or an AI is flashed"
  319. "Module: Utility"
  320. "CallOn: An AI"
  321. "Example: flashed = level.price isflashed();"
  322. "SPMP: singleplayer"
  323. ///ScriptDocEnd
  324. =============
  325. */
  326. isFlashed()
  327. {
  328. if ( !isdefined( self.flashEndTime ) )
  329. return false;
  330.  
  331. return gettime() < self.flashEndTime;
  332. }
  333.  
  334.  
  335. /*
  336. =============
  337. ///ScriptDocBegin
  338. "Name: flag( <flagname> )"
  339. "Summary: Checks if the flag is set. Returns true or false."
  340. "Module: Flag"
  341. "CallOn: "
  342. "MandatoryArg: <flagname> : name of the flag to check"
  343. "Example: flag( "hq_cleared" );"
  344. "SPMP: both"
  345. ///ScriptDocEnd
  346. =============
  347. */
  348. flag( message )
  349. {
  350. assertEx( isdefined( message ), "Tried to check flag but the flag was not defined." );
  351. assertEx( isdefined( level.flag[ message ] ), "Tried to check flag " + message + " but the flag was not initialized." );
  352. if ( !level.flag[ message ] )
  353. return false;
  354.  
  355. return true;
  356. }
  357.  
  358.  
  359. /*
  360. =============
  361. ///ScriptDocBegin
  362. "Name: flag_init( <flagname> )"
  363. "Summary: Initialize a flag to be used. All flags must be initialized before using flag_set or flag_wait"
  364. "Module: Flag"
  365. "CallOn: "
  366. "MandatoryArg: <flagname> : name of the flag to create"
  367. "Example: flag_init( "hq_cleared" );"
  368. "SPMP: singleplayer"
  369. ///ScriptDocEnd
  370. =============
  371. */
  372. flag_init( message )
  373. {
  374. if ( !isDefined( level.flag ) )
  375. {
  376. level.flag = [];
  377. level.flags_lock = [];
  378. if ( !isdefined( level.sp_stat_tracking_func ) )
  379. level.sp_stat_tracking_func = ::empty_init_func;
  380. }
  381.  
  382. if ( !isdefined( level.first_frame ) )
  383. assertEx( !isDefined( level.flag[ message ] ), "Attempt to reinitialize existing message: " + message );
  384.  
  385. level.flag[ message ] = false;
  386. /#
  387. level.flags_lock[ message ] = false;
  388. #/
  389. if ( !isdefined( level.trigger_flags ) )
  390. {
  391. init_trigger_flags();
  392. level.trigger_flags[ message ] = [];
  393. }
  394. else
  395. if ( !isdefined( level.trigger_flags[ message ] ) )
  396. {
  397. level.trigger_flags[ message ] = [];
  398. }
  399.  
  400. if ( issuffix( message, "aa_" ) )
  401. {
  402. thread [[ level.sp_stat_tracking_func ]]( message );
  403. }
  404. }
  405.  
  406. empty_init_func( empty )
  407. {
  408. }
  409.  
  410. issuffix( msg, suffix )
  411. {
  412. if ( suffix.size > msg.size )
  413. return false;
  414.  
  415. for ( i = 0; i < suffix.size; i++ )
  416. {
  417. if ( msg[ i ] != suffix[ i ] )
  418. return false;
  419. }
  420. return true;
  421. }
  422. /*
  423. =============
  424. ///ScriptDocBegin
  425. "Name: flag_set( <flagname> )"
  426. "Summary: Sets the specified flag, all scripts using flag_wait will now continue."
  427. "Module: Flag"
  428. "CallOn: "
  429. "MandatoryArg: <flagname> : name of the flag to set"
  430. "Example: flag_set( "hq_cleared" );"
  431. "SPMP: both"
  432. ///ScriptDocEnd
  433. =============
  434. */
  435. flag_set( message )
  436. {
  437. /#
  438. assertEx( isDefined( level.flag[ message ] ), "Attempt to set a flag before calling flag_init: " + message );
  439. assert( level.flag[ message ] == level.flags_lock[ message ] );
  440. level.flags_lock[ message ] = true;
  441. #/
  442. level.flag[ message ] = true;
  443. level notify( message );
  444.  
  445. set_trigger_flag_permissions( message );
  446. }
  447.  
  448. /*
  449. =============
  450. ///ScriptDocBegin
  451. "Name: flag_wait( <flagname> )"
  452. "Summary: Waits until the specified flag is set."
  453. "Module: Flag"
  454. "CallOn: "
  455. "MandatoryArg: <flagname> : name of the flag to wait on"
  456. "Example: flag_wait( "hq_cleared" );"
  457. "SPMP: both"
  458. ///ScriptDocEnd
  459. =============
  460. */
  461. flag_wait( msg )
  462. {
  463. while( !level.flag[ msg ] )
  464. level waittill( msg );
  465. }
  466.  
  467. /*
  468. =============
  469. ///ScriptDocBegin
  470. "Name: flag_clear( <flagname> )"
  471. "Summary: Clears the specified flag."
  472. "Module: Flag"
  473. "CallOn: "
  474. "MandatoryArg: <flagname> : name of the flag to clear"
  475. "Example: flag_clear( "hq_cleared" );"
  476. "SPMP: both"
  477. ///ScriptDocEnd
  478. =============
  479. */
  480. flag_clear( message )
  481. {
  482. /#
  483. assertEx( isDefined( level.flag[ message ] ), "Attempt to set a flag before calling flag_init: " + message );
  484. assert( level.flag[ message ] == level.flags_lock[ message ] );
  485. level.flags_lock[ message ] = false;
  486. #/
  487. //do this check so we don't unneccessarily send a notify
  488. if ( level.flag[ message ] )
  489. {
  490. level.flag[ message ] = false;
  491. level notify( message );
  492. set_trigger_flag_permissions( message );
  493. }
  494. }
  495.  
  496. /*
  497. =============
  498. ///ScriptDocBegin
  499. "Name: flag_waitopen( <flagname> )"
  500. "Summary: Waits for the flag to open"
  501. "Module: Flag"
  502. "MandatoryArg: <flagname>: The flag"
  503. "Example: flag_waitopen( "get_me_bagels" );"
  504. "SPMP: singleplayer"
  505. ///ScriptDocEnd
  506. =============
  507. */
  508.  
  509. flag_waitopen( msg )
  510. {
  511. while( level.flag[ msg ] )
  512. level waittill( msg );
  513. }
  514.  
  515. script_gen_dump_addline( string, signature )
  516. {
  517.  
  518. if ( !isdefined( string ) )
  519. string = "nowrite";// some things like the standardized CSV sound entries don't really need anything in script. just the asset
  520.  
  521. if ( !isdefined( level._loadstarted ) )
  522. {
  523. // stashes commands away so they can be handled in the correct place within load
  524. if ( !isdefined( level.script_gen_dump_preload ) )
  525. level.script_gen_dump_preload = [];
  526. struct = spawnstruct();
  527. struct.string = string;
  528. struct.signature = signature;
  529. level.script_gen_dump_preload[ level.script_gen_dump_preload.size ] = struct;
  530. return;
  531. }
  532.  
  533.  
  534. if ( !isdefined( level.script_gen_dump[ signature ] ) )
  535. level.script_gen_dump_reasons[ level.script_gen_dump_reasons.size ] = "Added: " + string;// console print as well as triggering the dump
  536. level.script_gen_dump[ signature ] = string;
  537. level.script_gen_dump2[ signature ] = string;// second array gets compared later with saved array. When something is missing dump is generated
  538. }
  539.  
  540. /*
  541. =============
  542. ///ScriptDocBegin
  543. "Name: array_thread( <entities> , <process> , <var1> , <var2> , <var3> )"
  544. "Summary: Threads the < process > function on every entity in the < entities > array. The entity will become "self" in the specified function."
  545. "Module: Array"
  546. "CallOn: "
  547. "MandatoryArg: <entities> : array of entities to thread the process"
  548. "MandatoryArg: <process> : pointer to a script function"
  549. "OptionalArg: <var1> : parameter 1 to pass to the process"
  550. "OptionalArg: <var2> : parameter 2 to pass to the process"
  551. "OptionalArg: <var3> : parameter 3 to pass to the process"
  552. "Example: array_thread( getaiarray( "allies" ), ::set_ignoreme, false );"
  553. "SPMP: both"
  554. ///ScriptDocEnd
  555. =============
  556. */
  557. array_thread( entities, process, var1, var2, var3 )
  558. {
  559. keys = getArrayKeys( entities );
  560.  
  561. if ( isdefined( var3 ) )
  562. {
  563. for( i = 0 ; i < keys.size ; i ++ )
  564. entities[ keys[ i ] ] thread [[ process ]]( var1, var2, var3 );
  565.  
  566. return;
  567. }
  568.  
  569. if ( isdefined( var2 ) )
  570. {
  571. for( i = 0 ; i < keys.size ; i ++ )
  572. entities[ keys[ i ] ] thread [[ process ]]( var1, var2 );
  573.  
  574. return;
  575. }
  576.  
  577. if ( isdefined( var1 ) )
  578. {
  579. for( i = 0 ; i < keys.size ; i ++ )
  580. entities[ keys[ i ] ] thread [[ process ]]( var1 );
  581.  
  582. return;
  583. }
  584.  
  585. for( i = 0 ; i < keys.size ; i ++ )
  586. entities[ keys[ i ] ] thread [[ process ]]();
  587. }
  588.  
  589. array_thread4( entities, process, var1, var2, var3, var4 )
  590. {
  591. keys = getArrayKeys( entities );
  592. for( i = 0 ; i < keys.size ; i ++ )
  593. entities[ keys[ i ] ] thread [[ process ]]( var1, var2, var3, var4 );
  594. }
  595.  
  596. array_thread5( entities, process, var1, var2, var3, var4, var5 )
  597. {
  598. keys = getArrayKeys( entities );
  599. for( i = 0 ; i < keys.size ; i ++ )
  600. entities[ keys[ i ] ] thread [[ process ]]( var1, var2, var3, var4, var5 );
  601. }
  602.  
  603. remove_undefined_from_array( array )
  604. {
  605. newarray = [];
  606. for( i = 0; i < array.size; i ++ )
  607. {
  608. if ( !isdefined( array[ i ] ) )
  609. continue;
  610. newarray[ newarray.size ] = array[ i ];
  611. }
  612. return newarray;
  613. }
  614.  
  615. /*
  616. =============
  617. ///ScriptDocBegin
  618. "Name: trigger_on( <name>, <type> )"
  619. "Summary: Turns a trigger on. This only needs to be called if it was previously turned off"
  620. "Module: Trigger"
  621. "CallOn: A trigger"
  622. "OptionalArg: <name> : the name corrisponding to a targetname or script_noteworthy to grab the trigger internally"
  623. "OptionalArg: <type> : the type( targetname, or script_noteworthy ) corrisponding to a name to grab the trigger internally"
  624. "Example: trigger trigger_on(); -or- trigger_on( "base_trigger", "targetname" )"
  625. "SPMP: both"
  626. ///ScriptDocEnd
  627. =============
  628. */
  629. trigger_on( name, type )
  630. {
  631. if ( isdefined ( name ) && isdefined( type ) )
  632. {
  633. ents = getentarray( name, type );
  634. array_thread( ents, ::trigger_on_proc );
  635. }
  636. else
  637. self trigger_on_proc();
  638. }
  639.  
  640. trigger_on_proc()
  641. {
  642. if ( isDefined( self.realOrigin ) )
  643. self.origin = self.realOrigin;
  644. self.trigger_off = undefined;
  645. }
  646.  
  647.  
  648. /*
  649. =============
  650. ///ScriptDocBegin
  651. "Name: trigger_off( <name>, <type> )"
  652. "Summary: Turns a trigger off so it can no longer be triggered."
  653. "Module: Trigger"
  654. "CallOn: A trigger"
  655. "OptionalArg: <name> : the name corrisponding to a targetname or script_noteworthy to grab the trigger internally"
  656. "OptionalArg: <type> : the type( targetname, or script_noteworthy ) corrisponding to a name to grab the trigger internally"
  657. "Example: trigger trigger_off();"
  658. "SPMP: both"
  659. ///ScriptDocEnd
  660. =============
  661. */
  662. trigger_off( name, type )
  663. {
  664. if ( isdefined ( name ) && isdefined( type ) )
  665. {
  666. ents = getentarray( name, type );
  667. array_thread( ents, ::trigger_off_proc );
  668. }
  669. else
  670. self trigger_off_proc();
  671. }
  672.  
  673. trigger_off_proc()
  674. {
  675. if ( !isDefined( self.realOrigin ) )
  676. self.realOrigin = self.origin;
  677.  
  678. if ( self.origin == self.realorigin )
  679. self.origin += ( 0, 0, -10000 );
  680. self.trigger_off = true;
  681. }
  682.  
  683. set_trigger_flag_permissions( msg )
  684. {
  685. // turns triggers on or off depending on if they have the proper flags set, based on their shift-g menu settings
  686.  
  687. // this can be init before _load has run, thanks to AI.
  688. if ( !isdefined( level.trigger_flags ) )
  689. return;
  690.  
  691. // cheaper to do the upkeep at this time rather than with endons and waittills on the individual triggers
  692. level.trigger_flags[ msg ] = remove_undefined_from_array( level.trigger_flags[ msg ] );
  693. array_thread( level.trigger_flags[ msg ], ::update_trigger_based_on_flags );
  694. }
  695.  
  696. update_trigger_based_on_flags()
  697. {
  698. true_on = true;
  699. if ( isdefined( self.script_flag_true ) )
  700. {
  701. true_on = false;
  702. tokens = create_flags_and_return_tokens( self.script_flag_true );
  703.  
  704. // stay off unless all the flags are false
  705. for( i=0; i < tokens.size; i++ )
  706. {
  707. if ( flag( tokens[ i ] ) )
  708. {
  709. true_on = true;
  710. break;
  711. }
  712. }
  713. }
  714.  
  715. false_on = true;
  716. if ( isdefined( self.script_flag_false ) )
  717. {
  718. tokens = create_flags_and_return_tokens( self.script_flag_false );
  719.  
  720. // stay on unless any flag is true
  721. for( i=0; i < tokens.size; i++ )
  722. {
  723. if ( flag( tokens[ i ] ) )
  724. {
  725. false_on = false;
  726. break;
  727. }
  728. }
  729. }
  730.  
  731. [ [ level.trigger_func[ true_on && false_on ] ] ]();
  732. }
  733.  
  734. create_flags_and_return_tokens( flags )
  735. {
  736. tokens = strtok( flags, " " );
  737.  
  738. // create the flag if level script does not
  739. for( i=0; i < tokens.size; i++ )
  740. {
  741. if ( !isdefined( level.flag[ tokens[ i ] ] ) )
  742. {
  743. flag_init( tokens[ i ] );
  744. }
  745. }
  746.  
  747. return tokens;
  748. }
  749.  
  750. init_trigger_flags()
  751. {
  752. level.trigger_flags = [];
  753. level.trigger_func[ true ] = ::trigger_on;
  754. level.trigger_func[ false ] = ::trigger_off;
  755. }
  756.  
  757. /*
  758. =============
  759. ///ScriptDocBegin
  760. "Name: getstructarray( <name> , <type )"
  761. "Summary: gets an array of script_structs"
  762. "Module: Array"
  763. "CallOn: An entity"
  764. "MandatoryArg: <name> : "
  765. "MandatoryArg: <type> : "
  766. "Example: fxemitters = getstructarray( "streetlights", "targetname" )"
  767. "SPMP: both"
  768. ///ScriptDocEnd
  769. =============
  770. */
  771.  
  772. getstructarray( name, type )
  773. {
  774. assertEx( isdefined( level.struct_class_names ), "Tried to getstruct before the structs were init" );
  775.  
  776. array = level.struct_class_names[ type ][ name ];
  777. if ( !isdefined( array ) )
  778. return [];
  779. return array;
  780. }
  781.  
  782. struct_class_init()
  783. {
  784. assertEx( !isdefined( level.struct_class_names ), "level.struct_class_names is being initialized in the wrong place! It shouldn't be initialized yet." );
  785.  
  786. level.struct_class_names = [];
  787. level.struct_class_names[ "target" ] = [];
  788. level.struct_class_names[ "targetname" ] = [];
  789. level.struct_class_names[ "script_noteworthy" ] = [];
  790. level.struct_class_names[ "script_linkname" ] = [];
  791.  
  792. for ( i=0; i < level.struct.size; i++ )
  793. {
  794. if ( isdefined( level.struct[ i ].targetname ) )
  795. {
  796. if ( !isdefined( level.struct_class_names[ "targetname" ][ level.struct[ i ].targetname ] ) )
  797. level.struct_class_names[ "targetname" ][ level.struct[ i ].targetname ] = [];
  798.  
  799. size = level.struct_class_names[ "targetname" ][ level.struct[ i ].targetname ].size;
  800. level.struct_class_names[ "targetname" ][ level.struct[ i ].targetname ][ size ] = level.struct[ i ];
  801. }
  802. if ( isdefined( level.struct[ i ].target ) )
  803. {
  804. if ( !isdefined( level.struct_class_names[ "target" ][ level.struct[ i ].target ] ) )
  805. level.struct_class_names[ "target" ][ level.struct[ i ].target ] = [];
  806.  
  807. size = level.struct_class_names[ "target" ][ level.struct[ i ].target ].size;
  808. level.struct_class_names[ "target" ][ level.struct[ i ].target ][ size ] = level.struct[ i ];
  809. }
  810. if ( isdefined( level.struct[ i ].script_noteworthy ) )
  811. {
  812. if ( !isdefined( level.struct_class_names[ "script_noteworthy" ][ level.struct[ i ].script_noteworthy ] ) )
  813. level.struct_class_names[ "script_noteworthy" ][ level.struct[ i ].script_noteworthy ] = [];
  814.  
  815. size = level.struct_class_names[ "script_noteworthy" ][ level.struct[ i ].script_noteworthy ].size;
  816. level.struct_class_names[ "script_noteworthy" ][ level.struct[ i ].script_noteworthy ][ size ] = level.struct[ i ];
  817. }
  818. if ( isdefined( level.struct[ i ].script_linkname ) )
  819. {
  820. assertex( !isdefined( level.struct_class_names[ "script_linkname" ][ level.struct[ i ].script_linkname ] ), "Two structs have the same linkname" );
  821. level.struct_class_names[ "script_linkname" ][ level.struct[ i ].script_linkname ][ 0 ] = level.struct[ i ];
  822. }
  823. }
  824. }
  825.  
  826. fileprint_start( file )
  827. {
  828. /#
  829. filename = file;
  830.  
  831. //hackery here, sometimes the file just doesn't open so keep trying
  832. // file = -1;
  833. // while( file == -1 )
  834. // {
  835. file = openfile( filename, "write" );
  836. // if (file == -1)
  837. // wait .05; // try every frame untill the file becomes writeable
  838. // }
  839. level.fileprint = file;
  840. level.fileprintlinecount = 0;
  841. level.fileprint_filename = filename;
  842. #/
  843. }
  844.  
  845. /*
  846. =============
  847. ///ScriptDocBegin
  848. "Name: fileprint_map_start( <filename> )"
  849. "Summary: starts map export with the file trees\cod3\cod3\map_source\xenon_export\ < filename > .map adds header / worldspawn entity to the map. Use this if you want to start a .map export."
  850. "Module: Fileprint"
  851. "CallOn: Level"
  852. "MandatoryArg: <param1> : "
  853. "OptionalArg: <param2> : "
  854. "Example: fileprint_map_start( filename );"
  855. "SPMP: singleplayer"
  856. ///ScriptDocEnd
  857. =============
  858. */
  859.  
  860. fileprint_map_start( file )
  861. {
  862. /#
  863. file = "map_source/" + file + ".map";
  864. fileprint_start( file );
  865.  
  866. // for the entity count
  867. level.fileprint_mapentcount = 0;
  868.  
  869. fileprint_map_header( true );
  870. #/
  871.  
  872. }
  873.  
  874. fileprint_chk( file , str )
  875. {
  876. /#
  877. //dodging infinite loops for file dumping. kind of dangerous
  878. level.fileprintlinecount++;
  879. if (level.fileprintlinecount>400)
  880. {
  881. wait .05;
  882. level.fileprintlinecount++;
  883. level.fileprintlinecount = 0;
  884. }
  885. fprintln( file, str );
  886. #/
  887. }
  888.  
  889. fileprint_map_header( bInclude_blank_worldspawn )
  890. {
  891. if ( !isdefined( bInclude_blank_worldspawn ) )
  892. bInclude_blank_worldspawn = false;
  893.  
  894. // this may need to be updated if map format changes
  895. assert( isdefined( level.fileprint ) );
  896. /#
  897. fileprint_chk( level.fileprint, "iwmap 4" );
  898. fileprint_chk( level.fileprint, "\"000_Global\" flags active" );
  899. fileprint_chk( level.fileprint, "\"The Map\" flags" );
  900.  
  901. if ( !bInclude_blank_worldspawn )
  902. return;
  903. fileprint_map_entity_start();
  904. fileprint_map_keypairprint( "classname", "worldspawn" );
  905. fileprint_map_entity_end();
  906.  
  907. #/
  908. }
  909.  
  910. /*
  911. =============
  912. ///ScriptDocBegin
  913. "Name: fileprint_map_keypairprint( <key1> , <key2> )"
  914. "Summary: prints a pair of keys to the current open map( by fileprint_map_start() )"
  915. "Module: Fileprint"
  916. "CallOn: Level"
  917. "MandatoryArg: <key1> : "
  918. "MandatoryArg: <key2> : "
  919. "Example: fileprint_map_keypairprint( "classname", "script_model" );"
  920. "SPMP: singleplayer"
  921. ///ScriptDocEnd
  922. =============
  923. */
  924.  
  925. fileprint_map_keypairprint( key1, key2 )
  926. {
  927. /#
  928. assert( isdefined( level.fileprint ) );
  929. fileprint_chk( level.fileprint, "\"" + key1 + "\" \"" + key2 + "\"" );
  930. #/
  931. }
  932.  
  933. /*
  934. =============
  935. ///ScriptDocBegin
  936. "Name: fileprint_map_entity_start()"
  937. "Summary: prints entity number and opening bracket to currently opened file"
  938. "Module: Fileprint"
  939. "CallOn: Level"
  940. "Example: fileprint_map_entity_start();"
  941. "SPMP: singleplayer"
  942. ///ScriptDocEnd
  943. =============
  944. */
  945.  
  946. fileprint_map_entity_start()
  947. {
  948. /#
  949. assert( !isdefined( level.fileprint_entitystart ) );
  950. level.fileprint_entitystart = true;
  951. assert( isdefined( level.fileprint ) );
  952. fileprint_chk( level.fileprint, "// entity " + level.fileprint_mapentcount );
  953. fileprint_chk( level.fileprint, "{" );
  954. level.fileprint_mapentcount ++ ;
  955. #/
  956. }
  957.  
  958. /*
  959. =============
  960. ///ScriptDocBegin
  961. "Name: fileprint_map_entity_end()"
  962. "Summary: close brackets an entity, required for the next entity to begin"
  963. "Module: Fileprint"
  964. "CallOn: Level"
  965. "Example: fileprint_map_entity_end();"
  966. "SPMP: singleplayer"
  967. ///ScriptDocEnd
  968. =============
  969. */
  970.  
  971. fileprint_map_entity_end()
  972. {
  973. /#
  974. assert( isdefined( level.fileprint_entitystart ) );
  975. assert( isdefined( level.fileprint ) );
  976. level.fileprint_entitystart = undefined;
  977. fileprint_chk( level.fileprint, "}" );
  978. #/
  979. }
  980.  
  981. /*
  982. =============
  983. ///ScriptDocBegin
  984. "Name: fileprint_end()"
  985. "Summary: saves the currently opened file"
  986. "Module: Fileprint"
  987. "CallOn: Level"
  988. "Example: fileprint_end();"
  989. "SPMP: singleplayer"
  990. ///ScriptDocEnd
  991. =============
  992. */
  993.  
  994. fileprint_end()
  995. {
  996. /#
  997. assert( !isdefined( level.fileprint_entitystart ) );
  998. saved = closefile( level.fileprint );
  999. if (saved != 1)
  1000. {
  1001. println("-----------------------------------");
  1002. println(" ");
  1003. println("file write failure");
  1004. println("file with name: "+level.fileprint_filename);
  1005. println("make sure you checkout the file you are trying to save");
  1006. println("note: USE P4 Search to find the file and check that one out");
  1007. println(" Do not checkin files in from the xenonoutput folder, ");
  1008. println(" this is junctioned to the proper directory where you need to go");
  1009. println("junctions looks like this");
  1010. println(" ");
  1011. println("..\\xenonOutput\\scriptdata\\createfx ..\\share\\raw\\maps\\createfx");
  1012. println("..\\xenonOutput\\scriptdata\\createart ..\\share\\raw\\maps\\createart");
  1013. println("..\\xenonOutput\\scriptdata\\vision ..\\share\\raw\\vision");
  1014. println("..\\xenonOutput\\scriptdata\\scriptgen ..\\share\\raw\\maps\\scriptgen");
  1015. println("..\\xenonOutput\\scriptdata\\zone_source ..\\xenon\\zone_source");
  1016. println("..\\xenonOutput\\accuracy ..\\share\\raw\\accuracy");
  1017. println("..\\xenonOutput\\scriptdata\\map_source ..\\map_source\\xenon_export");
  1018. println(" ");
  1019. println("-----------------------------------");
  1020.  
  1021. println( "File not saved( see console.log for info ) " );
  1022. }
  1023. level.fileprint = undefined;
  1024. level.fileprint_filename = undefined;
  1025. #/
  1026. }
  1027.  
  1028. /*
  1029. =============
  1030. ///ScriptDocBegin
  1031. "Name: fileprint_radiant_vec( <vector> )"
  1032. "Summary: this converts a vector to a .map file readable format"
  1033. "Module: Fileprint"
  1034. "CallOn: An entity"
  1035. "MandatoryArg: <vector> : "
  1036. "Example: origin_string = fileprint_radiant_vec( vehicle.angles )"
  1037. "SPMP: singleplayer"
  1038. ///ScriptDocEnd
  1039. =============
  1040. */
  1041.  
  1042. fileprint_radiant_vec( vector )
  1043. {
  1044. /#
  1045. string = "" + vector[ 0 ] + " " + vector[ 1 ] + " " + vector[ 2 ] + "";
  1046. return string;
  1047. #/
  1048. }
  1049.  
  1050.  
  1051. // MikeD (4/28/2008): Check to see if "mature" is enabled.
  1052. is_mature()
  1053. {
  1054. // CODER_MOD: Austin (8/21/08): always mature if playing online
  1055. if ( level.onlineGame )
  1056. return true;
  1057.  
  1058. // CODER_MOD: Austin (6/22/08): Change from cg_blood to cg_mature
  1059. return GetDvarInt( "cg_mature" );
  1060. }
  1061.  
  1062. is_german_build()
  1063. {
  1064. if( GetDvar( "language" ) == "german" )
  1065. {
  1066. return true;
  1067. }
  1068. return false;
  1069. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement