wp_saberLoad.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. //wp_saberLoad.cpp
  2. // leave this line at the top for all NPC_xxxx.cpp files...
  3. #include "g_headers.h"
  4. #include "q_shared.h"
  5. #include "wp_saber.h"
  6. extern qboolean G_ParseLiteral( const char **data, const char *string );
  7. extern saber_colors_t TranslateSaberColor( const char *name );
  8. extern qboolean PM_SaberInStart( int move );
  9. extern qboolean PM_SaberInTransition( int move );
  10. extern qboolean PM_SaberInAttack( int move );
  11. extern stringID_table_t FPTable[];
  12. #define MAX_SABER_DATA_SIZE 0x8000
  13. char SaberParms[MAX_SABER_DATA_SIZE];
  14. void Saber_SithSwordPrecache( void )
  15. {//*SIGH* special sounds used by the sith sword
  16. for ( int i = 1; i < 5; i++ )
  17. {
  18. G_SoundIndex( va( "sound/weapons/sword/stab%d.wav", i ) );
  19. }
  20. for ( i = 1; i < 5; i++ )
  21. {
  22. G_SoundIndex( va( "sound/weapons/sword/swing%d.wav", i ) );
  23. }
  24. for ( i = 1; i < 7; i++ )
  25. {
  26. G_SoundIndex( va( "sound/weapons/sword/fall%d.wav", i ) );
  27. }
  28. /*
  29. for ( i = 1; i < 4; i++ )
  30. {
  31. G_SoundIndex( va( "sound/weapons/sword/spin%d.wav", i ) );
  32. }
  33. */
  34. }
  35. stringID_table_t SaberTable[] =
  36. {
  37. ENUM2STRING(SABER_NONE),
  38. ENUM2STRING(SABER_SINGLE),
  39. ENUM2STRING(SABER_STAFF),
  40. ENUM2STRING(SABER_BROAD),
  41. ENUM2STRING(SABER_PRONG),
  42. ENUM2STRING(SABER_DAGGER),
  43. ENUM2STRING(SABER_ARC),
  44. ENUM2STRING(SABER_SAI),
  45. ENUM2STRING(SABER_CLAW),
  46. ENUM2STRING(SABER_LANCE),
  47. ENUM2STRING(SABER_STAR),
  48. ENUM2STRING(SABER_TRIDENT),
  49. ENUM2STRING(SABER_SITH_SWORD),
  50. "", -1
  51. };
  52. saber_styles_t TranslateSaberStyle( const char *name )
  53. {
  54. if ( !Q_stricmp( name, "fast" ) )
  55. {
  56. return SS_FAST;
  57. }
  58. if ( !Q_stricmp( name, "medium" ) )
  59. {
  60. return SS_MEDIUM;
  61. }
  62. if ( !Q_stricmp( name, "strong" ) )
  63. {
  64. return SS_STRONG;
  65. }
  66. if ( !Q_stricmp( name, "desann" ) )
  67. {
  68. return SS_DESANN;
  69. }
  70. if ( !Q_stricmp( name, "tavion" ) )
  71. {
  72. return SS_TAVION;
  73. }
  74. if ( !Q_stricmp( name, "dual" ) )
  75. {
  76. return SS_DUAL;
  77. }
  78. if ( !Q_stricmp( name, "staff" ) )
  79. {
  80. return SS_STAFF;
  81. }
  82. return SS_NONE;
  83. }
  84. void WP_SaberFreeStrings( saberInfo_t &saber )
  85. {
  86. if (saber.name && gi.bIsFromZone(saber.name , TAG_G_ALLOC)) {
  87. gi.Free (saber.name);
  88. saber.name=0;
  89. }
  90. if (saber.fullName && gi.bIsFromZone(saber.fullName , TAG_G_ALLOC)) {
  91. gi.Free (saber.fullName);
  92. saber.fullName=0;
  93. }
  94. if (saber.model && gi.bIsFromZone(saber.model , TAG_G_ALLOC)) {
  95. gi.Free (saber.model);
  96. saber.model=0;
  97. }
  98. if (saber.skin && gi.bIsFromZone(saber.skin , TAG_G_ALLOC)) {
  99. gi.Free (saber.skin);
  100. saber.skin=0;
  101. }
  102. if (saber.brokenSaber1 && gi.bIsFromZone(saber.brokenSaber1 , TAG_G_ALLOC)) {
  103. gi.Free (saber.brokenSaber1);
  104. saber.brokenSaber1=0;
  105. }
  106. if (saber.brokenSaber2 && gi.bIsFromZone(saber.brokenSaber2 , TAG_G_ALLOC)) {
  107. gi.Free (saber.brokenSaber2);
  108. saber.brokenSaber2=0;
  109. }
  110. }
  111. void WP_SaberSetDefaults( saberInfo_t *saber, qboolean setColors = qtrue )
  112. {
  113. //Set defaults so that, if it fails, there's at least something there
  114. saber->name = NULL;
  115. saber->fullName = NULL;
  116. for ( int i = 0; i < MAX_BLADES; i++ )
  117. {
  118. if ( setColors )
  119. {
  120. saber->blade[i].color = SABER_RED;
  121. }
  122. saber->blade[i].radius = SABER_RADIUS_STANDARD;
  123. saber->blade[i].lengthMax = 32;
  124. }
  125. saber->model = "models/weapons2/saber_reborn/saber_w.glm";
  126. saber->skin = NULL;
  127. saber->soundOn = G_SoundIndex( "sound/weapons/saber/enemy_saber_on.wav" );
  128. saber->soundLoop = G_SoundIndex( "sound/weapons/saber/saberhum3.wav" );
  129. saber->soundOff = G_SoundIndex( "sound/weapons/saber/enemy_saber_off.wav" );
  130. saber->numBlades = 1;
  131. saber->type = SABER_SINGLE;
  132. saber->style = SS_NONE;
  133. saber->maxChain = 0;//0 = use default behavior
  134. saber->lockable = qtrue;
  135. saber->throwable = qtrue;
  136. saber->disarmable = qtrue;
  137. saber->activeBlocking = qtrue;
  138. saber->twoHanded = qfalse;
  139. saber->forceRestrictions = 0;
  140. saber->lockBonus = 0;
  141. saber->parryBonus = 0;
  142. saber->breakParryBonus = 0;
  143. saber->disarmBonus = 0;
  144. saber->singleBladeStyle = SS_NONE;//makes it so that you use a different style if you only have the first blade active
  145. saber->singleBladeThrowable = qfalse;//makes it so that you can throw this saber if only the first blade is on
  146. saber->brokenSaber1 = NULL;//if saber is actually hit by another saber, it can be cut in half/broken and will be replaced with this saber in your right hand
  147. saber->brokenSaber2 = NULL;//if saber is actually hit by another saber, it can be cut in half/broken and will be replaced with this saber in your left hand
  148. saber->returnDamage = qfalse;//when returning from a saber throw, it keeps spinning and doing damage
  149. }
  150. qboolean WP_SaberParseParms( const char *SaberName, saberInfo_t *saber, qboolean setColors )
  151. {
  152. const char *token;
  153. const char *value;
  154. const char *p;
  155. float f;
  156. int n;
  157. if ( !saber )
  158. {
  159. return qfalse;
  160. }
  161. //Set defaults so that, if it fails, there's at least something there
  162. WP_SaberSetDefaults( saber, setColors );
  163. if ( !SaberName || !SaberName[0] )
  164. {
  165. return qfalse;
  166. }
  167. saber->name = G_NewString( SaberName );
  168. //try to parse it out
  169. p = SaberParms;
  170. COM_BeginParseSession();
  171. // look for the right saber
  172. while ( p )
  173. {
  174. token = COM_ParseExt( &p, qtrue );
  175. if ( token[0] == 0 )
  176. {
  177. return qfalse;
  178. }
  179. if ( !Q_stricmp( token, SaberName ) )
  180. {
  181. break;
  182. }
  183. SkipBracedSection( &p );
  184. }
  185. if ( !p )
  186. {
  187. return qfalse;
  188. }
  189. if ( G_ParseLiteral( &p, "{" ) )
  190. {
  191. return qfalse;
  192. }
  193. // parse the saber info block
  194. while ( 1 )
  195. {
  196. token = COM_ParseExt( &p, qtrue );
  197. if ( !token[0] )
  198. {
  199. gi.Printf( S_COLOR_RED"ERROR: unexpected EOF while parsing '%s'\n", SaberName );
  200. return qfalse;
  201. }
  202. if ( !Q_stricmp( token, "}" ) )
  203. {
  204. break;
  205. }
  206. //saber fullName
  207. if ( !Q_stricmp( token, "name" ) )
  208. {
  209. if ( COM_ParseString( &p, &value ) )
  210. {
  211. continue;
  212. }
  213. saber->fullName = G_NewString( value );
  214. continue;
  215. }
  216. //saber type
  217. if ( !Q_stricmp( token, "saberType" ) )
  218. {
  219. if ( COM_ParseString( &p, &value ) )
  220. {
  221. continue;
  222. }
  223. int saberType = GetIDForString( SaberTable, value );
  224. if ( saberType >= SABER_SINGLE && saberType <= NUM_SABERS )
  225. {
  226. saber->type = (saberType_t)saberType;
  227. }
  228. continue;
  229. }
  230. //saber hilt
  231. if ( !Q_stricmp( token, "saberModel" ) )
  232. {
  233. if ( COM_ParseString( &p, &value ) )
  234. {
  235. continue;
  236. }
  237. saber->model = G_NewString( value );
  238. continue;
  239. }
  240. if ( !Q_stricmp( token, "customSkin" ) )
  241. {
  242. if ( COM_ParseString( &p, &value ) )
  243. {
  244. continue;
  245. }
  246. saber->skin = G_NewString( value );
  247. continue;
  248. }
  249. //on sound
  250. if ( !Q_stricmp( token, "soundOn" ) )
  251. {
  252. if ( COM_ParseString( &p, &value ) )
  253. {
  254. continue;
  255. }
  256. saber->soundOn = G_SoundIndex( G_NewString( value ) );
  257. continue;
  258. }
  259. //loop sound
  260. if ( !Q_stricmp( token, "soundLoop" ) )
  261. {
  262. if ( COM_ParseString( &p, &value ) )
  263. {
  264. continue;
  265. }
  266. saber->soundLoop = G_SoundIndex( G_NewString( value ) );
  267. continue;
  268. }
  269. //off sound
  270. if ( !Q_stricmp( token, "soundOff" ) )
  271. {
  272. if ( COM_ParseString( &p, &value ) )
  273. {
  274. continue;
  275. }
  276. saber->soundOff = G_SoundIndex( G_NewString( value ) );
  277. continue;
  278. }
  279. if ( !Q_stricmp( token, "numBlades" ) )
  280. {
  281. if ( COM_ParseInt( &p, &n ) )
  282. {
  283. SkipRestOfLine( &p );
  284. continue;
  285. }
  286. if ( n < 1 || n >= MAX_BLADES )
  287. {
  288. G_Error( "WP_SaberParseParms: saber %s has illegal number of blades (%d) max: %d", SaberName, n, MAX_BLADES );
  289. continue;
  290. }
  291. saber->numBlades = n;
  292. continue;
  293. }
  294. // saberColor
  295. if ( !Q_stricmpn( token, "saberColor", 10 ) )
  296. {
  297. if ( !setColors )
  298. {//don't actually want to set the colors
  299. //read the color out anyway just to advance the *p pointer
  300. COM_ParseString( &p, &value );
  301. continue;
  302. }
  303. else
  304. {
  305. if (strlen(token)==10)
  306. {
  307. n = -1;
  308. }
  309. else if (strlen(token)==11)
  310. {
  311. n = atoi(&token[10])-1;
  312. if (n > 7 || n < 1 )
  313. {
  314. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberColor '%s' in %s\n", token, SaberName );
  315. //read the color out anyway just to advance the *p pointer
  316. COM_ParseString( &p, &value );
  317. continue;
  318. }
  319. }
  320. else
  321. {
  322. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberColor '%s' in %s\n", token, SaberName );
  323. //read the color out anyway just to advance the *p pointer
  324. COM_ParseString( &p, &value );
  325. continue;
  326. }
  327. if ( COM_ParseString( &p, &value ) ) //read the color
  328. {
  329. continue;
  330. }
  331. if (n==-1)
  332. {//NOTE: this fills in the rest of the blades with the same color by default
  333. saber_colors_t color = TranslateSaberColor( value );
  334. for ( n = 0; n < MAX_BLADES; n++ )
  335. {
  336. saber->blade[n].color = color;
  337. }
  338. } else
  339. {
  340. saber->blade[n].color = TranslateSaberColor( value );
  341. }
  342. continue;
  343. }
  344. }
  345. //saber length
  346. if ( !Q_stricmpn( token, "saberLength", 11 ) )
  347. {
  348. if (strlen(token)==11)
  349. {
  350. n = -1;
  351. }
  352. else if (strlen(token)==12)
  353. {
  354. n = atoi(&token[11])-1;
  355. if (n > 7 || n < 1 )
  356. {
  357. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberLength '%s' in %s\n", token, SaberName );
  358. continue;
  359. }
  360. }
  361. else
  362. {
  363. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberLength '%s' in %s\n", token, SaberName );
  364. continue;
  365. }
  366. if ( COM_ParseFloat( &p, &f ) )
  367. {
  368. SkipRestOfLine( &p );
  369. continue;
  370. }
  371. //cap
  372. if ( f < 4.0f )
  373. {
  374. f = 4.0f;
  375. }
  376. if (n==-1)
  377. {//NOTE: this fills in the rest of the blades with the same length by default
  378. for ( n = 0; n < MAX_BLADES; n++ )
  379. {
  380. saber->blade[n].lengthMax = f;
  381. }
  382. }
  383. else
  384. {
  385. saber->blade[n].lengthMax = f;
  386. }
  387. continue;
  388. }
  389. //blade radius
  390. if ( !Q_stricmpn( token, "saberRadius", 11 ) )
  391. {
  392. if (strlen(token)==11)
  393. {
  394. n = -1;
  395. }
  396. else if (strlen(token)==12)
  397. {
  398. n = atoi(&token[11])-1;
  399. if (n > 7 || n < 1 )
  400. {
  401. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberRadius '%s' in %s\n", token, SaberName );
  402. continue;
  403. }
  404. }
  405. else
  406. {
  407. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberRadius '%s' in %s\n", token, SaberName );
  408. continue;
  409. }
  410. if ( COM_ParseFloat( &p, &f ) )
  411. {
  412. SkipRestOfLine( &p );
  413. continue;
  414. }
  415. //cap
  416. if ( f < 0.25f )
  417. {
  418. f = 0.25f;
  419. }
  420. if (n==-1)
  421. {//NOTE: this fills in the rest of the blades with the same length by default
  422. for ( n = 0; n < MAX_BLADES; n++ )
  423. {
  424. saber->blade[n].radius = f;
  425. }
  426. }
  427. else
  428. {
  429. saber->blade[n].radius = f;
  430. }
  431. continue;
  432. }
  433. //locked saber style
  434. if ( !Q_stricmp( token, "saberStyle" ) )
  435. {
  436. if ( COM_ParseString( &p, &value ) )
  437. {
  438. continue;
  439. }
  440. saber->style = TranslateSaberStyle( value );
  441. continue;
  442. }
  443. //maxChain
  444. if ( !Q_stricmp( token, "maxChain" ) )
  445. {
  446. if ( COM_ParseInt( &p, &n ) )
  447. {
  448. SkipRestOfLine( &p );
  449. continue;
  450. }
  451. saber->maxChain = n;
  452. continue;
  453. }
  454. //lockable
  455. if ( !Q_stricmp( token, "lockable" ) )
  456. {
  457. if ( COM_ParseInt( &p, &n ) )
  458. {
  459. SkipRestOfLine( &p );
  460. continue;
  461. }
  462. saber->lockable = ((qboolean)(n!=0));
  463. continue;
  464. }
  465. //throwable
  466. if ( !Q_stricmp( token, "throwable" ) )
  467. {
  468. if ( COM_ParseInt( &p, &n ) )
  469. {
  470. SkipRestOfLine( &p );
  471. continue;
  472. }
  473. saber->throwable = ((qboolean)(n!=0));
  474. continue;
  475. }
  476. //disarmable
  477. if ( !Q_stricmp( token, "disarmable" ) )
  478. {
  479. if ( COM_ParseInt( &p, &n ) )
  480. {
  481. SkipRestOfLine( &p );
  482. continue;
  483. }
  484. saber->disarmable = ((qboolean)(n!=0));
  485. continue;
  486. }
  487. //active blocking
  488. if ( !Q_stricmp( token, "blocking" ) )
  489. {
  490. if ( COM_ParseInt( &p, &n ) )
  491. {
  492. SkipRestOfLine( &p );
  493. continue;
  494. }
  495. saber->activeBlocking = ((qboolean)(n!=0));
  496. continue;
  497. }
  498. //twoHanded
  499. if ( !Q_stricmp( token, "twoHanded" ) )
  500. {
  501. if ( COM_ParseInt( &p, &n ) )
  502. {
  503. SkipRestOfLine( &p );
  504. continue;
  505. }
  506. saber->twoHanded = ((qboolean)(n!=0));
  507. continue;
  508. }
  509. //force power restrictions
  510. if ( !Q_stricmp( token, "forceRestrict" ) )
  511. {
  512. if ( COM_ParseString( &p, &value ) )
  513. {
  514. continue;
  515. }
  516. int fp = GetIDForString( FPTable, value );
  517. if ( fp >= FP_FIRST && fp < NUM_FORCE_POWERS )
  518. {
  519. saber->forceRestrictions |= (1<<fp);
  520. }
  521. continue;
  522. }
  523. //lockBonus
  524. if ( !Q_stricmp( token, "lockBonus" ) )
  525. {
  526. if ( COM_ParseInt( &p, &n ) )
  527. {
  528. SkipRestOfLine( &p );
  529. continue;
  530. }
  531. saber->lockBonus = n;
  532. continue;
  533. }
  534. //parryBonus
  535. if ( !Q_stricmp( token, "parryBonus" ) )
  536. {
  537. if ( COM_ParseInt( &p, &n ) )
  538. {
  539. SkipRestOfLine( &p );
  540. continue;
  541. }
  542. saber->parryBonus = n;
  543. continue;
  544. }
  545. //breakParryBonus
  546. if ( !Q_stricmp( token, "breakParryBonus" ) )
  547. {
  548. if ( COM_ParseInt( &p, &n ) )
  549. {
  550. SkipRestOfLine( &p );
  551. continue;
  552. }
  553. saber->breakParryBonus = n;
  554. continue;
  555. }
  556. //disarmBonus
  557. if ( !Q_stricmp( token, "disarmBonus" ) )
  558. {
  559. if ( COM_ParseInt( &p, &n ) )
  560. {
  561. SkipRestOfLine( &p );
  562. continue;
  563. }
  564. saber->disarmBonus = n;
  565. continue;
  566. }
  567. //single blade saber style
  568. if ( !Q_stricmp( token, "singleBladeStyle" ) )
  569. {
  570. if ( COM_ParseString( &p, &value ) )
  571. {
  572. continue;
  573. }
  574. saber->singleBladeStyle = TranslateSaberStyle( value );
  575. continue;
  576. }
  577. //single blade throwable
  578. if ( !Q_stricmp( token, "singleBladeThrowable" ) )
  579. {
  580. if ( COM_ParseInt( &p, &n ) )
  581. {
  582. SkipRestOfLine( &p );
  583. continue;
  584. }
  585. saber->singleBladeThrowable = ((qboolean)(n!=0));
  586. continue;
  587. }
  588. //broken replacement saber1 (right hand)
  589. if ( !Q_stricmp( token, "brokenSaber1" ) )
  590. {
  591. if ( COM_ParseString( &p, &value ) )
  592. {
  593. continue;
  594. }
  595. saber->brokenSaber1 = G_NewString( value );
  596. continue;
  597. }
  598. //broken replacement saber2 (left hand)
  599. if ( !Q_stricmp( token, "brokenSaber2" ) )
  600. {
  601. if ( COM_ParseString( &p, &value ) )
  602. {
  603. continue;
  604. }
  605. saber->brokenSaber2 = G_NewString( value );
  606. continue;
  607. }
  608. //spins and does damage on return from saberthrow
  609. if ( !Q_stricmp( token, "returnDamage" ) )
  610. {
  611. if ( COM_ParseInt( &p, &n ) )
  612. {
  613. SkipRestOfLine( &p );
  614. continue;
  615. }
  616. saber->returnDamage = ((qboolean)(n!=0));
  617. continue;
  618. }
  619. if ( !Q_stricmp( token, "notInMP" ) )
  620. {//ignore this
  621. SkipRestOfLine( &p );
  622. continue;
  623. }
  624. gi.Printf( "WARNING: unknown keyword '%s' while parsing '%s'\n", token, SaberName );
  625. SkipRestOfLine( &p );
  626. }
  627. //FIXME: precache the saberModel(s)?
  628. if ( saber->type == SABER_SITH_SWORD )
  629. {//precache all the sith sword sounds
  630. Saber_SithSwordPrecache();
  631. }
  632. return qtrue;
  633. }
  634. void WP_RemoveSaber( gentity_t *ent, int saberNum )
  635. {
  636. if ( !ent || !ent->client )
  637. {
  638. return;
  639. }
  640. //reset everything for this saber just in case
  641. WP_SaberSetDefaults( &ent->client->ps.saber[saberNum] );
  642. ent->client->ps.dualSabers = qfalse;
  643. ent->client->ps.saber[saberNum].Deactivate();
  644. ent->client->ps.saber[saberNum].SetLength( 0.0f );
  645. if ( ent->weaponModel[saberNum] > 0 )
  646. {
  647. gi.G2API_SetSkin( &ent->ghoul2[ent->weaponModel[saberNum]], -1, 0 );
  648. gi.G2API_RemoveGhoul2Model( ent->ghoul2, ent->weaponModel[saberNum] );
  649. ent->weaponModel[saberNum] = -1;
  650. }
  651. if ( ent->client->ps.saberAnimLevel == SS_DUAL
  652. || ent->client->ps.saberAnimLevel == SS_STAFF )
  653. {//change to the style to the default
  654. for ( int i = SS_FAST; i < SS_NUM_SABER_STYLES; i++ )
  655. {
  656. if ( (ent->client->ps.saberStylesKnown&(1<<i)) )
  657. {
  658. ent->client->ps.saberAnimLevel = i;
  659. if ( ent->s.number < MAX_CLIENTS )
  660. {
  661. cg.saberAnimLevelPending = ent->client->ps.saberAnimLevel;
  662. }
  663. break;
  664. }
  665. }
  666. }
  667. }
  668. void WP_SetSaber( gentity_t *ent, int saberNum, char *saberName )
  669. {
  670. if ( !ent || !ent->client )
  671. {
  672. return;
  673. }
  674. if ( Q_stricmp( "none", saberName ) == 0 || Q_stricmp( "remove", saberName ) == 0 )
  675. {
  676. WP_RemoveSaber( ent, saberNum );
  677. return;
  678. }
  679. if ( ent->weaponModel[saberNum] > 0 )
  680. {
  681. gi.G2API_RemoveGhoul2Model(ent->ghoul2, ent->weaponModel[saberNum]);
  682. ent->weaponModel[saberNum] = -1;
  683. }
  684. WP_SaberParseParms( saberName, &ent->client->ps.saber[saberNum] );//get saber info
  685. if ( ent->client->ps.saber[saberNum].style )
  686. {
  687. ent->client->ps.saberStylesKnown |= (1<<ent->client->ps.saber[saberNum].style);
  688. }
  689. if ( saberNum == 1 && ent->client->ps.saber[1].twoHanded )
  690. {//not allowed to use a 2-handed saber as second saber
  691. WP_RemoveSaber( ent, saberNum );
  692. return;
  693. }
  694. G_ModelIndex( ent->client->ps.saber[saberNum].model );
  695. WP_SaberInitBladeData( ent );
  696. //int boltNum = ent->handRBolt;
  697. if ( saberNum == 1 )
  698. {
  699. ent->client->ps.dualSabers = qtrue;
  700. //boltNum = ent->handLBolt;
  701. }
  702. WP_SaberAddG2SaberModels( ent, saberNum );
  703. ent->client->ps.saber[saberNum].SetLength( 0.0f );
  704. ent->client->ps.saber[saberNum].Activate();
  705. if ( ent->client->ps.saber[saberNum].style != SS_NONE )
  706. {//change to the style we're supposed to be using
  707. ent->client->ps.saberAnimLevel = ent->client->ps.saber[saberNum].style;
  708. ent->client->ps.saberStylesKnown |= (1<<ent->client->ps.saberAnimLevel);
  709. if ( ent->s.number < MAX_CLIENTS )
  710. {
  711. cg.saberAnimLevelPending = ent->client->ps.saberAnimLevel;
  712. }
  713. }
  714. }
  715. void WP_SaberSetColor( gentity_t *ent, int saberNum, int bladeNum, char *colorName )
  716. {
  717. if ( !ent || !ent->client )
  718. {
  719. return;
  720. }
  721. ent->client->ps.saber[saberNum].blade[bladeNum].color = TranslateSaberColor( colorName );
  722. }
  723. extern void WP_SetSaberEntModelSkin( gentity_t *ent, gentity_t *saberent );
  724. qboolean WP_BreakSaber( gentity_t *ent, const char *surfName, saberType_t saberType )
  725. {//Make sure there *is* one specified and not using dualSabers
  726. if ( ent == NULL || ent->client == NULL )
  727. {//invalid ent or client
  728. return qfalse;
  729. }
  730. if ( ent->s.number < MAX_CLIENTS )
  731. {//player
  732. //if ( g_spskill->integer < 3 )
  733. {//only on the hardest level?
  734. //FIXME: add a cvar?
  735. return qfalse;
  736. }
  737. }
  738. if ( ent->health <= 0 )
  739. {//not if they're dead
  740. return qfalse;
  741. }
  742. if ( ent->client->ps.weapon != WP_SABER )
  743. {//not holding saber
  744. return qfalse;
  745. }
  746. if ( ent->client->ps.dualSabers )
  747. {//FIXME: handle this?
  748. return qfalse;
  749. }
  750. if ( !ent->client->ps.saber[0].brokenSaber1 )
  751. {//not breakable into another type of saber
  752. return qfalse;
  753. }
  754. if ( PM_SaberInStart( ent->client->ps.saberMove ) //in a start
  755. || PM_SaberInTransition( ent->client->ps.saberMove ) //in a transition
  756. || PM_SaberInAttack( ent->client->ps.saberMove ) )//in an attack
  757. {//don't break when in the middle of an attack
  758. return qfalse;
  759. }
  760. if ( Q_stricmpn( "w_", surfName, 2 )
  761. && Q_stricmpn( "saber_", surfName, 6 ) //hack because using mod-community made saber
  762. && Q_stricmp( "cylinder01", surfName ) )//hack because using mod-community made saber
  763. {//didn't hit my weapon
  764. return qfalse;
  765. }
  766. //Sith Sword should ALWAYS do this
  767. if ( saberType != SABER_SITH_SWORD && Q_irand( 0, 50 ) )//&& Q_irand( 0, 10 ) )
  768. {//10% chance - FIXME: extern this, too?
  769. return qfalse;
  770. }
  771. //break it
  772. char *replacementSaber1 = G_NewString( ent->client->ps.saber[0].brokenSaber1 );
  773. char *replacementSaber2 = G_NewString( ent->client->ps.saber[0].brokenSaber2 );
  774. int i, originalNumBlades = ent->client->ps.saber[0].numBlades;
  775. qboolean broken = qfalse;
  776. saber_colors_t colors[MAX_BLADES];
  777. //store the colors
  778. for ( i = 0; i < MAX_BLADES; i++ )
  779. {
  780. colors[i] = ent->client->ps.saber[0].blade[i].color;
  781. }
  782. //FIXME: chance of dropping the right-hand one? Based on damage, or...?
  783. //FIXME: sound & effect when this happens, and send them into a broken parry?
  784. //remove saber[0], replace with replacementSaber1
  785. if ( replacementSaber1 )
  786. {
  787. WP_RemoveSaber( ent, 0 );
  788. WP_SetSaber( ent, 0, replacementSaber1 );
  789. for ( i = 0; i < ent->client->ps.saber[0].numBlades; i++ )
  790. {
  791. ent->client->ps.saber[0].blade[i].color = colors[i];
  792. }
  793. broken = qtrue;
  794. //change my saberent's model and skin to match my new right-hand saber
  795. WP_SetSaberEntModelSkin( ent, &g_entities[ent->client->ps.saberEntityNum] );
  796. }
  797. if ( originalNumBlades <= 1 )
  798. {//nothing to split off
  799. //FIXME: handle this?
  800. }
  801. else
  802. {
  803. //remove saber[1], replace with replacementSaber2
  804. if ( replacementSaber2 )
  805. {//FIXME: 25% chance that it just breaks - just spawn the second saber piece and toss it away immediately, can't be picked up.
  806. //shouldn't be one in this hand, but just in case, remove it
  807. WP_RemoveSaber( ent, 1 );
  808. WP_SetSaber( ent, 1, replacementSaber2 );
  809. //put the remainder of the original saber's blade colors onto this saber's blade(s)
  810. for ( i = ent->client->ps.saber[0].numBlades; i < MAX_BLADES; i++ )
  811. {
  812. ent->client->ps.saber[1].blade[i-ent->client->ps.saber[0].numBlades].color = colors[i];
  813. }
  814. broken = qtrue;
  815. }
  816. }
  817. return broken;
  818. }
  819. void WP_SaberLoadParms( void )
  820. {
  821. int len, totallen, saberExtFNLen, fileCnt, i;
  822. char *buffer, *holdChar, *marker;
  823. char saberExtensionListBuf[2048]; // The list of file names read in
  824. //gi.Printf( "Parsing *.sab saber definitions\n" );
  825. //set where to store the first one
  826. totallen = 0;
  827. marker = SaberParms;
  828. marker[0] = '\0';
  829. //now load in the .sab definitions
  830. fileCnt = gi.FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) );
  831. holdChar = saberExtensionListBuf;
  832. for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 )
  833. {
  834. saberExtFNLen = strlen( holdChar );
  835. len = gi.FS_ReadFile( va( "ext_data/sabers/%s", holdChar), (void **) &buffer );
  836. if ( len == -1 )
  837. {
  838. gi.Printf( "WP_SaberLoadParms: error reading %s\n", holdChar );
  839. }
  840. else
  841. {
  842. if ( totallen && *(marker-1) == '}' )
  843. {//don't let it end on a } because that should be a stand-alone token
  844. strcat( marker, " " );
  845. totallen++;
  846. marker++;
  847. }
  848. len = COM_Compress( buffer );
  849. if ( totallen + len >= MAX_SABER_DATA_SIZE ) {
  850. G_Error( "WP_SaberLoadParms: ran out of space before reading %s\n(you must make the .npc files smaller)", holdChar );
  851. }
  852. strcat( marker, buffer );
  853. gi.FS_FreeFile( buffer );
  854. totallen += len;
  855. marker += len;
  856. }
  857. }
  858. }