NPC_stats.cpp 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019
  1. //NPC_stats.cpp
  2. // leave this line at the top for all NPC_xxxx.cpp files...
  3. #include "g_headers.h"
  4. #include "b_local.h"
  5. #include "b_public.h"
  6. #include "anims.h"
  7. #include "wp_saber.h"
  8. #include "g_Vehicles.h"
  9. #if !defined(RUFL_HSTRING_INC)
  10. #include "..\Rufl\hstring.h"
  11. #endif
  12. #include "..\Ratl\string_vs.h"
  13. #include "..\Rufl\hstring.h"
  14. #include "..\Ratl\vector_vs.h"
  15. extern void WP_RemoveSaber( gentity_t *ent, int saberNum );
  16. extern qboolean NPCsPrecached;
  17. extern vec3_t playerMins;
  18. extern vec3_t playerMaxs;
  19. extern stringID_table_t WPTable[];
  20. #define MAX_MODELS_PER_LEVEL 40
  21. #ifdef _XBOX
  22. using dllNamespace::hstring;
  23. #endif
  24. hstring modelsAlreadyDone[MAX_MODELS_PER_LEVEL];
  25. stringID_table_t animEventTypeTable[] =
  26. {
  27. ENUM2STRING(AEV_SOUND), //# animID AEV_SOUND framenum soundpath randomlow randomhi chancetoplay
  28. ENUM2STRING(AEV_FOOTSTEP), //# animID AEV_FOOTSTEP framenum footstepType
  29. ENUM2STRING(AEV_EFFECT), //# animID AEV_EFFECT framenum effectpath boltName
  30. ENUM2STRING(AEV_FIRE), //# animID AEV_FIRE framenum altfire chancetofire
  31. ENUM2STRING(AEV_MOVE), //# animID AEV_MOVE framenum forwardpush rightpush uppush
  32. ENUM2STRING(AEV_SOUNDCHAN), //# animID AEV_SOUNDCHAN framenum CHANNEL soundpath randomlow randomhi chancetoplay
  33. //must be terminated
  34. NULL,-1
  35. };
  36. stringID_table_t footstepTypeTable[] =
  37. {
  38. ENUM2STRING(FOOTSTEP_R),
  39. ENUM2STRING(FOOTSTEP_L),
  40. ENUM2STRING(FOOTSTEP_HEAVY_R),
  41. ENUM2STRING(FOOTSTEP_HEAVY_L),
  42. //must be terminated
  43. NULL,-1
  44. };
  45. stringID_table_t FPTable[] =
  46. {
  47. ENUM2STRING(FP_HEAL),
  48. ENUM2STRING(FP_LEVITATION),
  49. ENUM2STRING(FP_SPEED),
  50. ENUM2STRING(FP_PUSH),
  51. ENUM2STRING(FP_PULL),
  52. ENUM2STRING(FP_TELEPATHY),
  53. ENUM2STRING(FP_GRIP),
  54. ENUM2STRING(FP_LIGHTNING),
  55. ENUM2STRING(FP_SABERTHROW),
  56. ENUM2STRING(FP_SABER_DEFENSE),
  57. ENUM2STRING(FP_SABER_OFFENSE),
  58. //new Jedi Academy powers
  59. ENUM2STRING(FP_RAGE),
  60. ENUM2STRING(FP_PROTECT),
  61. ENUM2STRING(FP_ABSORB),
  62. ENUM2STRING(FP_DRAIN),
  63. ENUM2STRING(FP_SEE),
  64. "", -1
  65. };
  66. stringID_table_t TeamTable[] =
  67. {
  68. "free", TEAM_FREE, // caution, some code checks a team_t via "if (!team_t_varname)" so I guess this should stay as entry 0, great or what? -slc
  69. ENUM2STRING(TEAM_FREE), // caution, some code checks a team_t via "if (!team_t_varname)" so I guess this should stay as entry 0, great or what? -slc
  70. "player", TEAM_PLAYER,
  71. ENUM2STRING(TEAM_PLAYER),
  72. "enemy", TEAM_ENEMY,
  73. ENUM2STRING(TEAM_ENEMY),
  74. "neutral", TEAM_NEUTRAL, // most droids are team_neutral, there are some exceptions like Probe,Seeker,Interrogator
  75. ENUM2STRING(TEAM_NEUTRAL), // most droids are team_neutral, there are some exceptions like Probe,Seeker,Interrogator
  76. "", -1
  77. };
  78. // this list was made using the model directories, this MUST be in the same order as the CLASS_ enum in teams.h
  79. stringID_table_t ClassTable[] =
  80. {
  81. ENUM2STRING(CLASS_NONE), // hopefully this will never be used by an npc), just covering all bases
  82. ENUM2STRING(CLASS_ATST), // technically droid...
  83. ENUM2STRING(CLASS_BARTENDER),
  84. ENUM2STRING(CLASS_BESPIN_COP),
  85. ENUM2STRING(CLASS_CLAW),
  86. ENUM2STRING(CLASS_COMMANDO),
  87. ENUM2STRING(CLASS_DESANN),
  88. ENUM2STRING(CLASS_FISH),
  89. ENUM2STRING(CLASS_FLIER2),
  90. ENUM2STRING(CLASS_GALAK),
  91. ENUM2STRING(CLASS_GLIDER),
  92. ENUM2STRING(CLASS_GONK), // droid
  93. ENUM2STRING(CLASS_GRAN),
  94. ENUM2STRING(CLASS_HOWLER),
  95. ENUM2STRING(CLASS_RANCOR),
  96. ENUM2STRING(CLASS_SAND_CREATURE),
  97. ENUM2STRING(CLASS_WAMPA),
  98. ENUM2STRING(CLASS_IMPERIAL),
  99. ENUM2STRING(CLASS_IMPWORKER),
  100. ENUM2STRING(CLASS_INTERROGATOR), // droid
  101. ENUM2STRING(CLASS_JAN),
  102. ENUM2STRING(CLASS_JEDI),
  103. ENUM2STRING(CLASS_KYLE),
  104. ENUM2STRING(CLASS_LANDO),
  105. ENUM2STRING(CLASS_LIZARD),
  106. ENUM2STRING(CLASS_LUKE),
  107. ENUM2STRING(CLASS_MARK1), // droid
  108. ENUM2STRING(CLASS_MARK2), // droid
  109. ENUM2STRING(CLASS_GALAKMECH), // droid
  110. ENUM2STRING(CLASS_MINEMONSTER),
  111. ENUM2STRING(CLASS_MONMOTHA),
  112. ENUM2STRING(CLASS_MORGANKATARN),
  113. ENUM2STRING(CLASS_MOUSE), // droid
  114. ENUM2STRING(CLASS_MURJJ),
  115. ENUM2STRING(CLASS_PRISONER),
  116. ENUM2STRING(CLASS_PROBE), // droid
  117. ENUM2STRING(CLASS_PROTOCOL), // droid
  118. ENUM2STRING(CLASS_R2D2), // droid
  119. ENUM2STRING(CLASS_R5D2), // droid
  120. ENUM2STRING(CLASS_REBEL),
  121. ENUM2STRING(CLASS_REBORN),
  122. ENUM2STRING(CLASS_REELO),
  123. ENUM2STRING(CLASS_REMOTE),
  124. ENUM2STRING(CLASS_RODIAN),
  125. ENUM2STRING(CLASS_SEEKER), // droid
  126. ENUM2STRING(CLASS_SENTRY),
  127. ENUM2STRING(CLASS_SHADOWTROOPER),
  128. ENUM2STRING(CLASS_SABOTEUR),
  129. ENUM2STRING(CLASS_STORMTROOPER),
  130. ENUM2STRING(CLASS_SWAMP),
  131. ENUM2STRING(CLASS_SWAMPTROOPER),
  132. ENUM2STRING(CLASS_NOGHRI),
  133. ENUM2STRING(CLASS_TAVION),
  134. ENUM2STRING(CLASS_ALORA),
  135. ENUM2STRING(CLASS_TRANDOSHAN),
  136. ENUM2STRING(CLASS_UGNAUGHT),
  137. ENUM2STRING(CLASS_JAWA),
  138. ENUM2STRING(CLASS_WEEQUAY),
  139. ENUM2STRING(CLASS_TUSKEN),
  140. ENUM2STRING(CLASS_BOBAFETT),
  141. ENUM2STRING(CLASS_ROCKETTROOPER),
  142. ENUM2STRING(CLASS_SABER_DROID),
  143. ENUM2STRING(CLASS_PLAYER),
  144. ENUM2STRING(CLASS_ASSASSIN_DROID),
  145. ENUM2STRING(CLASS_HAZARD_TROOPER),
  146. ENUM2STRING(CLASS_VEHICLE),
  147. "", -1
  148. };
  149. /*
  150. NPC_ReactionTime
  151. */
  152. //FIXME use grandom in here
  153. int NPC_ReactionTime ( void )
  154. {
  155. return 200 * ( 6 - NPCInfo->stats.reactions );
  156. }
  157. //
  158. // parse support routines
  159. //
  160. qboolean G_ParseLiteral( const char **data, const char *string )
  161. {
  162. const char *token;
  163. token = COM_ParseExt( data, qtrue );
  164. if ( token[0] == 0 )
  165. {
  166. gi.Printf( "unexpected EOF\n" );
  167. return qtrue;
  168. }
  169. if ( Q_stricmp( token, string ) )
  170. {
  171. gi.Printf( "required string '%s' missing\n", string );
  172. return qtrue;
  173. }
  174. return qfalse;
  175. }
  176. //
  177. // NPC parameters file : ext_data/NPCs/*.npc*
  178. //
  179. #define MAX_NPC_DATA_SIZE 0x20000
  180. char NPCParms[MAX_NPC_DATA_SIZE];
  181. /*
  182. static rank_t TranslateRankName( const char *name )
  183. Should be used to determine pip bolt-ons
  184. */
  185. static rank_t TranslateRankName( const char *name )
  186. {
  187. if ( !Q_stricmp( name, "civilian" ) )
  188. {
  189. return RANK_CIVILIAN;
  190. }
  191. if ( !Q_stricmp( name, "crewman" ) )
  192. {
  193. return RANK_CREWMAN;
  194. }
  195. if ( !Q_stricmp( name, "ensign" ) )
  196. {
  197. return RANK_ENSIGN;
  198. }
  199. if ( !Q_stricmp( name, "ltjg" ) )
  200. {
  201. return RANK_LT_JG;
  202. }
  203. if ( !Q_stricmp( name, "lt" ) )
  204. {
  205. return RANK_LT;
  206. }
  207. if ( !Q_stricmp( name, "ltcomm" ) )
  208. {
  209. return RANK_LT_COMM;
  210. }
  211. if ( !Q_stricmp( name, "commander" ) )
  212. {
  213. return RANK_COMMANDER;
  214. }
  215. if ( !Q_stricmp( name, "captain" ) )
  216. {
  217. return RANK_CAPTAIN;
  218. }
  219. return RANK_CIVILIAN;
  220. }
  221. #ifdef _XBOX
  222. extern saber_colors_t TranslateSaberColor( const char *name );
  223. #else
  224. saber_colors_t TranslateSaberColor( const char *name )
  225. {
  226. if ( !Q_stricmp( name, "red" ) )
  227. {
  228. return SABER_RED;
  229. }
  230. if ( !Q_stricmp( name, "orange" ) )
  231. {
  232. return SABER_ORANGE;
  233. }
  234. if ( !Q_stricmp( name, "yellow" ) )
  235. {
  236. return SABER_YELLOW;
  237. }
  238. if ( !Q_stricmp( name, "green" ) )
  239. {
  240. return SABER_GREEN;
  241. }
  242. if ( !Q_stricmp( name, "blue" ) )
  243. {
  244. return SABER_BLUE;
  245. }
  246. if ( !Q_stricmp( name, "purple" ) )
  247. {
  248. return SABER_PURPLE;
  249. }
  250. if ( !Q_stricmp( name, "random" ) )
  251. {
  252. return ((saber_colors_t)(Q_irand( SABER_ORANGE, SABER_PURPLE )));
  253. }
  254. return SABER_BLUE;
  255. }
  256. #endif
  257. /* static int MethodNameToNumber( const char *name ) {
  258. if ( !Q_stricmp( name, "EXPONENTIAL" ) ) {
  259. return METHOD_EXPONENTIAL;
  260. }
  261. if ( !Q_stricmp( name, "LINEAR" ) ) {
  262. return METHOD_LINEAR;
  263. }
  264. if ( !Q_stricmp( name, "LOGRITHMIC" ) ) {
  265. return METHOD_LOGRITHMIC;
  266. }
  267. if ( !Q_stricmp( name, "ALWAYS" ) ) {
  268. return METHOD_ALWAYS;
  269. }
  270. if ( !Q_stricmp( name, "NEVER" ) ) {
  271. return METHOD_NEVER;
  272. }
  273. return -1;
  274. }
  275. static int ItemNameToNumber( const char *name, int itemType ) {
  276. // int n;
  277. for ( n = 0; n < bg_numItems; n++ ) {
  278. if ( bg_itemlist[n].type != itemType ) {
  279. continue;
  280. }
  281. if ( Q_stricmp( bg_itemlist[n].classname, name ) == 0 ) {
  282. return bg_itemlist[n].tag;
  283. }
  284. }
  285. return -1;
  286. }
  287. */
  288. static int MoveTypeNameToEnum( const char *name )
  289. {
  290. if(!Q_stricmp("runjump", name))
  291. {
  292. return MT_RUNJUMP;
  293. }
  294. else if(!Q_stricmp("walk", name))
  295. {
  296. return MT_WALK;
  297. }
  298. else if(!Q_stricmp("flyswim", name))
  299. {
  300. return MT_FLYSWIM;
  301. }
  302. else if(!Q_stricmp("static", name))
  303. {
  304. return MT_STATIC;
  305. }
  306. return MT_STATIC;
  307. }
  308. extern void CG_RegisterClientRenderInfo(clientInfo_t *ci, renderInfo_t *ri);
  309. extern void CG_RegisterClientModels (int entityNum);
  310. extern void CG_RegisterNPCCustomSounds( clientInfo_t *ci );
  311. //extern void CG_RegisterNPCEffects( team_t team );
  312. //#define CONVENIENT_ANIMATION_FILE_DEBUG_THING
  313. #ifdef CONVENIENT_ANIMATION_FILE_DEBUG_THING
  314. void SpewDebugStuffToFile(animation_t *bgGlobalAnimations)
  315. {
  316. char BGPAFtext[40000];
  317. fileHandle_t f;
  318. int i = 0;
  319. gi.FS_FOpenFile("file_of_debug_stuff_SP.txt", &f, FS_WRITE);
  320. if (!f)
  321. {
  322. return;
  323. }
  324. BGPAFtext[0] = 0;
  325. while (i < MAX_ANIMATIONS)
  326. {
  327. strcat(BGPAFtext, va("%i %i\n", i, bgGlobalAnimations[i].frameLerp));
  328. i++;
  329. }
  330. gi.FS_Write(BGPAFtext, strlen(BGPAFtext), f);
  331. gi.FS_FCloseFile(f);
  332. }
  333. #endif
  334. int CG_CheckAnimFrameForEventType( animevent_t *animEvents, int keyFrame, animEventType_t eventType, unsigned short modelIndex )
  335. {
  336. for ( int i = 0; i < MAX_ANIM_EVENTS; i++ )
  337. {
  338. if ( animEvents[i].keyFrame == keyFrame )
  339. {//there is an animevent on this frame already
  340. if ( animEvents[i].eventType == eventType )
  341. {//and it is of the same type
  342. if ( animEvents[i].modelOnly == modelIndex )
  343. {//and it is for the same model
  344. return i;
  345. }
  346. }
  347. }
  348. }
  349. //nope
  350. return -1;
  351. }
  352. /*
  353. ======================
  354. ParseAnimationEvtBlock
  355. ======================
  356. */
  357. static void ParseAnimationEvtBlock(int glaIndex, unsigned short modelIndex, const char* aeb_filename, animevent_t *animEvents, animation_t *animations, unsigned char &lastAnimEvent, const char **text_p, bool bIsFrameSkipped)
  358. {
  359. const char *token;
  360. int num, n, animNum, keyFrame, lowestVal, highestVal, curAnimEvent = 0;
  361. animEventType_t eventType;
  362. char stringData[MAX_QPATH];
  363. // get past starting bracket
  364. while(1)
  365. {
  366. token = COM_Parse( text_p );
  367. if ( !Q_stricmp( token, "{" ) )
  368. {
  369. break;
  370. }
  371. }
  372. //NOTE: instead of a blind increment, increase the index
  373. // this way if we have an event on an anim that already
  374. // has an event of that type, it stomps it
  375. // read information for each frame
  376. while ( 1 )
  377. {
  378. if ( lastAnimEvent >= MAX_ANIM_EVENTS )
  379. {
  380. CG_Error( "ParseAnimationEvtBlock: number events in file %s > MAX_ANIM_EVENTS(%i)", aeb_filename, MAX_ANIM_EVENTS );
  381. }
  382. // Get base frame of sequence
  383. token = COM_Parse( text_p );
  384. if ( !token || !token[0])
  385. {
  386. break;
  387. }
  388. if ( !Q_stricmp( token, "}" ) ) // At end of block
  389. {
  390. break;
  391. }
  392. //Compare to same table as animations used
  393. // so we don't have to use actual numbers for animation first frames,
  394. // just need offsets.
  395. //This way when animation numbers change, this table won't have to be updated,
  396. // at least not much.
  397. animNum = GetIDForString(animTable, token);
  398. if(animNum == -1)
  399. {//Unrecognized ANIM ENUM name,
  400. Com_Printf(S_COLOR_YELLOW"WARNING: Unknown ANIM %s in file %s\n", token, aeb_filename );
  401. //skip this entry
  402. SkipRestOfLine( text_p );
  403. continue;
  404. }
  405. if ( animations[animNum].numFrames == 0 )
  406. {//we don't use this anim
  407. #ifndef FINAL_BUILD
  408. Com_Printf(S_COLOR_YELLOW"WARNING: %s: anim %s not used by this model\n", aeb_filename, token);
  409. #endif
  410. //skip this entry
  411. SkipRestOfLine( text_p );
  412. continue;
  413. }
  414. token = COM_Parse( text_p );
  415. eventType = (animEventType_t)GetIDForString(animEventTypeTable, token);
  416. if ( eventType == AEV_NONE || eventType == -1 )
  417. {//Unrecognized ANIM EVENT TYPE
  418. Com_Printf(S_COLOR_RED"ERROR: Unknown EVENT %s in animEvent file %s\n", token, aeb_filename );
  419. continue;
  420. }
  421. // Get offset to frame within sequence
  422. token = COM_Parse( text_p );
  423. if ( !token )
  424. {
  425. break;
  426. }
  427. keyFrame = atoi( token );
  428. if ( bIsFrameSkipped &&
  429. (animations[animNum].numFrames>1) // important, else frame 1 gets divided down and becomes frame 0. Carcass & Assimilate also work this way
  430. )
  431. {
  432. keyFrame /= 2; // if we ever use any other value in frame-skipping we'll have to figure out some way of reading it, since it's not stored anywhere
  433. }
  434. if(keyFrame >= animations[animNum].numFrames)
  435. {
  436. Com_Printf(S_COLOR_YELLOW"WARNING: Event out of range on %s in %s\n", GetStringForID(animTable,animNum), aeb_filename );
  437. assert(keyFrame < animations[animNum].numFrames);
  438. keyFrame = animations[animNum].numFrames-1; //clamp it
  439. }
  440. //set our start frame
  441. keyFrame += animations[animNum].firstFrame;
  442. //see if this frame already has an event of this type on it, if so, overwrite it
  443. curAnimEvent = CG_CheckAnimFrameForEventType( animEvents, keyFrame, eventType, modelIndex );
  444. if ( curAnimEvent == -1 )
  445. {//this anim frame doesn't already have an event of this type on it
  446. curAnimEvent = lastAnimEvent;
  447. }
  448. //now that we know which event index we're going to plug the data into, start doing it
  449. animEvents[curAnimEvent].eventType = eventType;
  450. assert(keyFrame >= 0 && keyFrame < 65535); //
  451. animEvents[curAnimEvent].keyFrame = keyFrame;
  452. animEvents[curAnimEvent].glaIndex = glaIndex;
  453. animEvents[curAnimEvent].modelOnly = modelIndex;
  454. int tempVal;
  455. //now read out the proper data based on the type
  456. switch ( animEvents[curAnimEvent].eventType )
  457. {
  458. case AEV_SOUNDCHAN: //# animID AEV_SOUNDCHAN framenum CHANNEL soundpath randomlow randomhi chancetoplay
  459. token = COM_Parse( text_p );
  460. if ( !token )
  461. {
  462. break;
  463. }
  464. if ( stricmp( token, "CHAN_VOICE_ATTEN" ) == 0 )
  465. {
  466. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_VOICE_ATTEN;
  467. }
  468. else if ( stricmp( token, "CHAN_VOICE_GLOBAL" ) == 0 )
  469. {
  470. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_VOICE_GLOBAL;
  471. }
  472. else if ( stricmp( token, "CHAN_ANNOUNCER" ) == 0 )
  473. {
  474. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_ANNOUNCER;
  475. }
  476. else if ( stricmp( token, "CHAN_BODY" ) == 0 )
  477. {
  478. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_BODY;
  479. }
  480. else if ( stricmp( token, "CHAN_WEAPON" ) == 0 )
  481. {
  482. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_WEAPON;
  483. }
  484. else if ( stricmp( token, "CHAN_VOICE" ) == 0 )
  485. {
  486. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_VOICE;
  487. }
  488. else
  489. {
  490. animEvents[curAnimEvent].eventData[AED_SOUNDCHANNEL] = CHAN_AUTO;
  491. }
  492. //fall through to normal sound
  493. case AEV_SOUND: //# animID AEV_SOUND framenum soundpath randomlow randomhi chancetoplay
  494. //get soundstring
  495. token = COM_Parse( text_p );
  496. if ( !token )
  497. {
  498. break;
  499. }
  500. strcpy(stringData, token);
  501. //get lowest value
  502. token = COM_Parse( text_p );
  503. if ( !token )
  504. {//WARNING! BAD TABLE!
  505. break;
  506. }
  507. lowestVal = atoi( token );
  508. //get highest value
  509. token = COM_Parse( text_p );
  510. if ( !token )
  511. {//WARNING! BAD TABLE!
  512. break;
  513. }
  514. highestVal = atoi( token );
  515. //Now precache all the sounds
  516. //NOTE: If we can be assured sequential handles, we can store the first sound index and count
  517. // unfortunately, if these sounds were previously registered, we cannot be guaranteed sequential indices. Thus an array
  518. if(lowestVal && highestVal)
  519. {
  520. assert(highestVal - lowestVal < MAX_RANDOM_ANIM_SOUNDS);
  521. for ( n = lowestVal, num = AED_SOUNDINDEX_START; n <= highestVal && num <= AED_SOUNDINDEX_END; n++, num++ )
  522. {
  523. animEvents[curAnimEvent].eventData[num] = G_SoundIndex( va( stringData, n ) );//cgi_S_RegisterSound
  524. }
  525. animEvents[curAnimEvent].eventData[AED_SOUND_NUMRANDOMSNDS] = num - 1;
  526. }
  527. else
  528. {
  529. animEvents[curAnimEvent].eventData[AED_SOUNDINDEX_START] = G_SoundIndex( stringData );//cgi_S_RegisterSound
  530. #if 0 //#ifndef FINAL_BUILD (only meaningfull if using S_RegisterSound
  531. if ( !animEvents[curAnimEvent].eventData[AED_SOUNDINDEX_START] )
  532. {//couldn't register it - file not found
  533. Com_Printf( S_COLOR_RED "ParseAnimationSndBlock: sound %s does not exist (%s)!\n", stringData, *aeb_filename );
  534. }
  535. #endif
  536. animEvents[curAnimEvent].eventData[AED_SOUND_NUMRANDOMSNDS] = 0;
  537. }
  538. //get probability
  539. token = COM_Parse( text_p );
  540. if ( !token )
  541. {//WARNING! BAD TABLE!
  542. break;
  543. }
  544. animEvents[curAnimEvent].eventData[AED_SOUND_PROBABILITY] = atoi( token );
  545. break;
  546. case AEV_FOOTSTEP: //# animID AEV_FOOTSTEP framenum footstepType
  547. //get footstep type
  548. token = COM_Parse( text_p );
  549. if ( !token )
  550. {
  551. break;
  552. }
  553. animEvents[curAnimEvent].eventData[AED_FOOTSTEP_TYPE] = GetIDForString(footstepTypeTable, token);
  554. //get probability
  555. token = COM_Parse( text_p );
  556. if ( !token )
  557. {//WARNING! BAD TABLE!
  558. break;
  559. }
  560. animEvents[curAnimEvent].eventData[AED_FOOTSTEP_PROBABILITY] = atoi( token );
  561. break;
  562. case AEV_EFFECT: //# animID AEV_EFFECT framenum effectpath boltName
  563. //get effect index
  564. token = COM_Parse( text_p );
  565. if ( !token )
  566. {
  567. break;
  568. }
  569. if ( token[0] && Q_stricmp( "special", token ) == 0 )
  570. {//special hard-coded effects
  571. //let cgame know it's not a real effect
  572. animEvents[curAnimEvent].eventData[AED_EFFECTINDEX] = -1;
  573. //get the name of it
  574. token = COM_Parse( text_p );
  575. animEvents[curAnimEvent].stringData = G_NewString( token );
  576. }
  577. else
  578. {//regular effect
  579. tempVal = G_EffectIndex(token);
  580. assert(tempVal > -32767 && tempVal < 32767);
  581. animEvents[curAnimEvent].eventData[AED_EFFECTINDEX] = tempVal;
  582. //get bolt index
  583. token = COM_Parse( text_p );
  584. if ( !token )
  585. {
  586. break;
  587. }
  588. if ( Q_stricmp( "none", token ) != 0 && Q_stricmp( "NULL", token ) != 0 )
  589. {//actually are specifying a bolt to use
  590. animEvents[curAnimEvent].stringData = G_NewString( token );
  591. }
  592. }
  593. //NOTE: this string will later be used to add a bolt and store the index, as below:
  594. //animEvent->eventData[AED_BOLTINDEX] = gi.G2API_AddBolt( &cent->gent->ghoul2[cent->gent->playerModel], animEvent->stringData );
  595. //get probability
  596. token = COM_Parse( text_p );
  597. if ( !token )
  598. {//WARNING! BAD TABLE!
  599. break;
  600. }
  601. animEvents[curAnimEvent].eventData[AED_EFFECT_PROBABILITY] = atoi( token );
  602. break;
  603. case AEV_FIRE: //# animID AEV_FIRE framenum altfire chancetofire
  604. //get altfire
  605. token = COM_Parse( text_p );
  606. if ( !token )
  607. {//WARNING! BAD TABLE!
  608. break;
  609. }
  610. animEvents[curAnimEvent].eventData[AED_FIRE_ALT] = atoi( token );
  611. //get probability
  612. token = COM_Parse( text_p );
  613. if ( !token )
  614. {//WARNING! BAD TABLE!
  615. break;
  616. }
  617. animEvents[curAnimEvent].eventData[AED_FIRE_PROBABILITY] = atoi( token );
  618. break;
  619. case AEV_MOVE: //# animID AEV_MOVE framenum forwardpush rightpush uppush
  620. //get forward push
  621. token = COM_Parse( text_p );
  622. if ( !token )
  623. {//WARNING! BAD TABLE!
  624. break;
  625. }
  626. tempVal = atoi(token);
  627. assert(tempVal > -32767 && tempVal < 32767);
  628. animEvents[curAnimEvent].eventData[AED_MOVE_FWD] = tempVal;
  629. //get right push
  630. token = COM_Parse( text_p );
  631. if ( !token )
  632. {//WARNING! BAD TABLE!
  633. break;
  634. }
  635. tempVal = atoi(token);
  636. assert(tempVal > -32767 && tempVal < 32767);
  637. animEvents[curAnimEvent].eventData[AED_MOVE_RT] = tempVal;
  638. //get upwards push
  639. token = COM_Parse( text_p );
  640. if ( !token )
  641. {//WARNING! BAD TABLE!
  642. break;
  643. }
  644. tempVal = atoi(token);
  645. assert(tempVal > -32767 && tempVal < 32767);
  646. animEvents[curAnimEvent].eventData[AED_MOVE_UP] = tempVal;
  647. break;
  648. default: //unknown?
  649. SkipRestOfLine( text_p );
  650. continue;
  651. break;
  652. }
  653. if ( curAnimEvent == lastAnimEvent )
  654. {
  655. lastAnimEvent++;
  656. }
  657. }
  658. }
  659. /*
  660. ======================
  661. G_ParseAnimationEvtFile
  662. Read a configuration file containing animation events
  663. models/players/kyle/animevents.cfg, etc
  664. This file's presence is not required
  665. ======================
  666. */
  667. static
  668. void G_ParseAnimationEvtFile(int glaIndex, const char* eventsDirectory, int fileIndex, int iRealGLAIndex = -1, bool modelSpecific = false)
  669. {
  670. int len;
  671. const char* token;
  672. char text[80000];
  673. const char* text_p = text;
  674. fileHandle_t f;
  675. char eventsPath[MAX_QPATH];
  676. int modelIndex = 0;
  677. assert(fileIndex>=0 && fileIndex<MAX_ANIM_FILES);
  678. const char *psAnimFileInternalName = (iRealGLAIndex == -1 ? NULL : gi.G2API_GetAnimFileInternalNameIndex( iRealGLAIndex ));
  679. // bool bIsFrameSkipped = (psAnimFileInternalName && strlen(psAnimFileInternalName)>5 && !stricmp(&psAnimFileInternalName[strlen(psAnimFileInternalName)-5],"_skip"));
  680. bool bIsFrameSkipped = false;
  681. if( (psAnimFileInternalName && strstr(psAnimFileInternalName, "_humanoid")) ||
  682. strstr(eventsDirectory, "rancor") )
  683. bIsFrameSkipped = true;
  684. // Open The File, Make Sure It Is Safe
  685. //-------------------------------------
  686. Com_sprintf(eventsPath, MAX_QPATH, "models/players/%s/animevents.cfg", eventsDirectory);
  687. len = cgi_FS_FOpenFile(eventsPath, &f, FS_READ);
  688. if ( len <= 0 )
  689. {//no file
  690. return;
  691. }
  692. if ( len >= sizeof( text ) - 1 )
  693. {
  694. CG_Printf( "File %s too long\n", eventsPath );
  695. return;
  696. }
  697. // Read It To The Buffer, Close The File
  698. //---------------------------------------
  699. cgi_FS_Read( text, len, f );
  700. text[len] = 0;
  701. cgi_FS_FCloseFile( f );
  702. // Get The Pointers To The Anim Event Arrays
  703. //-------------------------------------------
  704. animFileSet_t& afileset = level.knownAnimFileSets[fileIndex];
  705. animevent_t *legsAnimEvents = afileset.legsAnimEvents;
  706. animevent_t *torsoAnimEvents = afileset.torsoAnimEvents;
  707. animation_t *animations = afileset.animations;
  708. if (modelSpecific)
  709. {
  710. hstring modelName(eventsDirectory);
  711. modelIndex = modelName.handle();
  712. }
  713. // read information for batches of sounds (UPPER or LOWER)
  714. while ( 1 )
  715. {
  716. // Get base frame of sequence
  717. token = COM_Parse( &text_p );
  718. if ( !token || !token[0] )
  719. {
  720. break;
  721. }
  722. //these stomp anything set in the include file (if it's an event of the same type on the same frame)!
  723. if ( !Q_stricmp(token,"UPPEREVENTS") ) // A batch of upper events
  724. {
  725. ParseAnimationEvtBlock(glaIndex, modelIndex, eventsPath, torsoAnimEvents, animations, afileset.torsoAnimEventCount, &text_p, bIsFrameSkipped);
  726. }
  727. else if ( !Q_stricmp(token,"LOWEREVENTS") ) // A batch of lower events
  728. {
  729. ParseAnimationEvtBlock(glaIndex, modelIndex, eventsPath, legsAnimEvents, animations, afileset.legsAnimEventCount, &text_p, bIsFrameSkipped);
  730. }
  731. }
  732. }
  733. /*
  734. ======================
  735. G_ParseAnimationFile
  736. Read a configuration file containing animation coutns and rates
  737. models/players/visor/animation.cfg, etc
  738. ======================
  739. */
  740. qboolean G_ParseAnimationFile(int glaIndex, const char *skeletonName, int fileIndex)
  741. {
  742. char text[80000];
  743. int len = 0;
  744. const char *token = 0;
  745. float fps = 0;
  746. const char* text_p = text;
  747. int animNum = 0;
  748. animation_t* animations = level.knownAnimFileSets[fileIndex].animations;
  749. char skeletonPath[MAX_QPATH];
  750. // Read In The File To The Text Buffer, Make Sure Everything Is Safe To Continue
  751. //-------------------------------------------------------------------------------
  752. Com_sprintf(skeletonPath, MAX_QPATH, "models/players/%s/%s.cfg", skeletonName, skeletonName);
  753. len = gi.RE_GetAnimationCFG(skeletonPath, text, sizeof(text));
  754. if ( len <= 0 )
  755. {
  756. Com_sprintf(skeletonPath, MAX_QPATH, "models/players/%s/animation.cfg", skeletonName);
  757. len = gi.RE_GetAnimationCFG(skeletonPath, text, sizeof(text));
  758. if ( len <= 0 )
  759. {
  760. return qfalse;
  761. }
  762. }
  763. if ( len >= sizeof( text ) - 1 )
  764. {
  765. G_Error( "G_ParseAnimationFile: File %s too long\n (%d > %d)", skeletonName, len, sizeof( text ) - 1);
  766. return qfalse;
  767. }
  768. // Read In Each Token
  769. //--------------------
  770. while(1)
  771. {
  772. token = COM_Parse( &text_p );
  773. // If No Token, We've Reached The End Of The File
  774. //------------------------------------------------
  775. if ( !token || !token[0])
  776. {
  777. break;
  778. }
  779. // Get The Anim Number Converted From The First Token
  780. //----------------------------------------------------
  781. animNum = GetIDForString(animTable, token);
  782. if(animNum == -1)
  783. {
  784. #ifndef FINAL_BUILD
  785. if (strcmp(token,"ROOT"))
  786. {
  787. Com_Printf(S_COLOR_RED"WARNING: Unknown token %s in %s\n", token, skeletonPath);
  788. }
  789. #endif
  790. //unrecognized animation so skip to end of line,
  791. while (token[0])
  792. {
  793. token = COM_ParseExt( &text_p, qfalse ); //returns empty string when next token is EOL
  794. }
  795. continue;
  796. }
  797. // GLAIndex
  798. //----------
  799. animations[animNum].glaIndex = glaIndex; // Passed Into This Func
  800. // First Frame
  801. //-------------
  802. token = COM_Parse( &text_p );
  803. if ( !token )
  804. {
  805. break;
  806. }
  807. assert(atoi(token) >= 0 && atoi(token) < 65536);
  808. animations[animNum].firstFrame = atoi( token );
  809. // Num Frames
  810. //------------
  811. token = COM_Parse( &text_p );
  812. if ( !token )
  813. {
  814. break;
  815. }
  816. assert(atoi(token) >= 0 && atoi(token) < 65536);
  817. animations[animNum].numFrames = atoi( token );
  818. // Loop Frames
  819. //-------------
  820. token = COM_Parse( &text_p );
  821. if ( !token )
  822. {
  823. break;
  824. }
  825. assert(atoi(token) >= -1 && atoi(token) < 128);
  826. animations[animNum].loopFrames = atoi( token );
  827. // FPS
  828. //-----
  829. token = COM_Parse( &text_p );
  830. if ( !token )
  831. {
  832. break;
  833. }
  834. fps = atof( token );
  835. if ( fps == 0 )
  836. {
  837. fps = 1;//Don't allow divide by zero error
  838. }
  839. // Calculate Frame Lerp
  840. //----------------------
  841. int lerp;
  842. if ( fps < 0 )
  843. {//backwards
  844. lerp = floor(1000.0f / fps);
  845. assert(lerp > -32767 && lerp < 32767);
  846. animations[animNum].frameLerp = lerp;
  847. assert(animations[animNum].frameLerp <= 1);
  848. }
  849. else
  850. {
  851. lerp = ceil(1000.0f / fps);
  852. assert(lerp > -32767 && lerp < 32767);
  853. animations[animNum].frameLerp = lerp;
  854. assert(animations[animNum].frameLerp >= 1);
  855. }
  856. /* lerp = ceil(1000.0f / Q_fabs(fps));
  857. assert(lerp > -32767 && lerp < 32767);
  858. animations[animNum].initialLerp = lerp;
  859. */
  860. }
  861. #ifdef CONVENIENT_ANIMATION_FILE_DEBUG_THING
  862. if (strstr(af_filename, "humanoid"))
  863. {
  864. SpewDebugStuffToFile(animations);
  865. }
  866. #endif
  867. return qtrue;
  868. }
  869. ////////////////////////////////////////////////////////////////////////
  870. // G_ParseAnimFileSet
  871. //
  872. // This function is responsible for building the animation file and
  873. // the animation event file.
  874. //
  875. ////////////////////////////////////////////////////////////////////////
  876. int G_ParseAnimFileSet(const char *skeletonName, const char *modelName=0)
  877. {
  878. int fileIndex=0;
  879. // Try To Find An Existing Skeleton File For This Animation Set
  880. //--------------------------------------------------------------
  881. for (fileIndex=0; fileIndex<level.numKnownAnimFileSets; fileIndex++)
  882. {
  883. if (Q_stricmp(level.knownAnimFileSets[fileIndex].filename, skeletonName)==0)
  884. {
  885. break;
  886. }
  887. }
  888. // Ok, We Don't Already Have One, So Time To Create A New One And Initialize It
  889. //------------------------------------------------------------------------------
  890. if (fileIndex>=level.numKnownAnimFileSets)
  891. {
  892. if (level.numKnownAnimFileSets==MAX_ANIM_FILES)
  893. {
  894. G_Error( "G_ParseAnimFileSet: MAX_ANIM_FILES" );
  895. return -1;
  896. }
  897. // Allocate A new File Set, And Get Some Shortcut Pointers
  898. //---------------------------------------------------------
  899. fileIndex = level.numKnownAnimFileSets;
  900. level.numKnownAnimFileSets++;
  901. strcpy(level.knownAnimFileSets[fileIndex].filename, skeletonName);
  902. level.knownAnimFileSets[fileIndex].torsoAnimEventCount = 0;
  903. level.knownAnimFileSets[fileIndex].legsAnimEventCount = 0;
  904. animation_t* animations = level.knownAnimFileSets[fileIndex].animations;
  905. animevent_t* legsAnimEvents = level.knownAnimFileSets[fileIndex].legsAnimEvents;
  906. animevent_t* torsoAnimEvents = level.knownAnimFileSets[fileIndex].torsoAnimEvents;
  907. int i, j;
  908. // Initialize The Frames Information
  909. //-----------------------------------
  910. for(i=0; i<MAX_ANIMATIONS; i++)
  911. {
  912. animations[i].firstFrame = 0;
  913. animations[i].numFrames = 0;
  914. animations[i].loopFrames = -1;
  915. animations[i].frameLerp = 100;
  916. // animations[i].initialLerp = 100;
  917. animations[i].glaIndex = 0;
  918. }
  919. // Initialize Animation Event Array
  920. //----------------------------------
  921. for(i=0; i<MAX_ANIM_EVENTS; i++)
  922. {
  923. torsoAnimEvents[i].eventType = AEV_NONE; //Type of event
  924. legsAnimEvents[i].eventType = AEV_NONE;
  925. torsoAnimEvents[i].keyFrame = (unsigned short)-1; //65535 should never be a valid frame... :)
  926. legsAnimEvents[i].keyFrame = (unsigned short)-1; //Frame to play event on
  927. torsoAnimEvents[i].stringData = NULL; //we allow storage of one string, temporarily (in case we have to look up an index later,
  928. legsAnimEvents[i].stringData = NULL; //then make sure to set stringData to NULL so we only do the look-up once)
  929. torsoAnimEvents[i].modelOnly = 0;
  930. legsAnimEvents[i].modelOnly = 0;
  931. torsoAnimEvents[i].glaIndex = 0;
  932. legsAnimEvents[i].glaIndex = 0;
  933. for (j=0; j<AED_ARRAY_SIZE; j++) //Unique IDs, can be soundIndex of sound file to play OR effect index or footstep type, etc.
  934. {
  935. torsoAnimEvents[i].eventData[j] = -1;
  936. legsAnimEvents[i].eventData[j] = -1;
  937. }
  938. }
  939. // Get The Cinematic GLA Name
  940. //----------------------------
  941. if (stricmp(skeletonName, "_humanoid")==0)
  942. {
  943. const char* mapName = strrchr( level.mapname, '/' );
  944. if (mapName)
  945. {
  946. mapName++;
  947. }
  948. else
  949. {
  950. mapName = level.mapname;
  951. }
  952. char skeletonMapName[MAX_QPATH];
  953. Com_sprintf(skeletonMapName, MAX_QPATH, "_humanoid_%s", mapName);
  954. const int normalGLAIndex = gi.G2API_PrecacheGhoul2Model("models/players/_humanoid/_humanoid.gla");//double check this always comes first!
  955. // Make Sure To Precache The GLAs (both regular and cinematic), And Remember Their Indicies
  956. //------------------------------------------------------------------------------------------
  957. G_ParseAnimationFile(0, skeletonName, fileIndex);
  958. G_ParseAnimationEvtFile(0, skeletonName, fileIndex, normalGLAIndex, false/*flag for model specific*/);
  959. const int cineGLAIndex = gi.G2API_PrecacheGhoul2Model( va("models/players/%s/%s.gla", skeletonMapName, skeletonMapName));
  960. if (cineGLAIndex)
  961. {
  962. assert(cineGLAIndex == normalGLAIndex+1);
  963. if (cineGLAIndex != normalGLAIndex+1)
  964. {
  965. Com_Error(ERR_DROP,"Cinematic GLA was not loaded after the normal GLA. Cannot continue safely.");
  966. }
  967. G_ParseAnimationFile(1, skeletonMapName, fileIndex);
  968. G_ParseAnimationEvtFile(1, skeletonMapName, fileIndex, cineGLAIndex, false/*flag for model specific*/);
  969. }
  970. }
  971. else
  972. {
  973. // non-humanoid...
  974. //
  975. // Make Sure To Precache The GLAs (both regular and cinematic), And Remember Their Indicies
  976. //------------------------------------------------------------------------------------------
  977. G_ParseAnimationFile(0, skeletonName, fileIndex);
  978. G_ParseAnimationEvtFile(0, skeletonName, fileIndex);
  979. }
  980. }
  981. // Tack Any Additional Per Model Events
  982. //--------------------------------------
  983. if (modelName)
  984. {
  985. // Quick Search To See If We've Already Loaded This Model
  986. //--------------------------------------------------------
  987. int curModel=0;
  988. hstring curModelName(modelName);
  989. while (curModel<MAX_MODELS_PER_LEVEL && !modelsAlreadyDone[curModel].empty())
  990. {
  991. if (modelsAlreadyDone[curModel]==curModelName)
  992. {
  993. return fileIndex;
  994. }
  995. curModel++;
  996. }
  997. if (curModel == MAX_MODELS_PER_LEVEL)
  998. {
  999. Com_Error(ERR_DROP, "About to overflow modelsAlreadyDone, increase MAX_MODELS_PER_LEVEL\n");
  1000. }
  1001. // Nope, Ok, Record The Model As Found And Parse It's Event File
  1002. //---------------------------------------------------------------
  1003. modelsAlreadyDone[curModel]=curModelName;
  1004. // Only Do The Event File If The Model Is Not The Same As The Skeleton
  1005. //---------------------------------------------------------------------
  1006. if (stricmp(skeletonName, modelName)!=0)
  1007. {
  1008. const int iGLAIndexToCheckForSkip = (stricmp(skeletonName, "_humanoid")?-1:gi.G2API_PrecacheGhoul2Model("models/players/_humanoid/_humanoid.gla")); // ;-)
  1009. G_ParseAnimationEvtFile(0, modelName, fileIndex, iGLAIndexToCheckForSkip, true);
  1010. }
  1011. }
  1012. return fileIndex;
  1013. }
  1014. #ifdef _XBOX
  1015. // Utility to wipe the modelsAlreadyDone array, as it is never cleared
  1016. void ClearModelsAlreadyDone(void)
  1017. {
  1018. memset(modelsAlreadyDone, 0, sizeof(modelsAlreadyDone));
  1019. }
  1020. #endif
  1021. extern cvar_t *g_char_model;
  1022. void G_LoadAnimFileSet( gentity_t *ent, const char *pModelName )
  1023. {
  1024. //load its animation config
  1025. char animName[MAX_QPATH];
  1026. char *GLAName, *modelName;
  1027. char *slash = NULL;
  1028. char *strippedName;
  1029. if ( ent->playerModel == -1 )
  1030. {
  1031. return;
  1032. }
  1033. if ( Q_stricmp( "player", pModelName ) == 0 )
  1034. {//model is actually stored on console
  1035. modelName = g_char_model->string;
  1036. }
  1037. else
  1038. {
  1039. modelName = (char *)pModelName;
  1040. }
  1041. //get the location of the animation.cfg
  1042. GLAName = gi.G2API_GetGLAName( &ent->ghoul2[ent->playerModel] );
  1043. //now load and parse the animation.cfg, animevents.cfg and set the animFileIndex
  1044. if ( !GLAName)
  1045. {
  1046. Com_Printf( S_COLOR_RED"Failed find animation file name models/players/%s\n", modelName );
  1047. strippedName="_humanoid"; //take a guess, maybe it's right?
  1048. }
  1049. else
  1050. {
  1051. Q_strncpyz( animName, GLAName, sizeof( animName ), qtrue );
  1052. slash = strrchr( animName, '/' );
  1053. if ( slash )
  1054. {
  1055. *slash = 0;
  1056. }
  1057. strippedName = COM_SkipPath( animName );
  1058. }
  1059. //now load and parse the animation.cfg, animevents.cfg and set the animFileIndex
  1060. ent->client->clientInfo.animFileIndex = G_ParseAnimFileSet(strippedName, modelName);
  1061. if (ent->client->clientInfo.animFileIndex<0)
  1062. {
  1063. Com_Printf( S_COLOR_RED"Failed to load animation file set models/players/%s/animation.cfg\n", modelName );
  1064. #ifndef FINAL_BUILD
  1065. Com_Error(ERR_FATAL, "Failed to load animation file set models/players/%s/animation.cfg\n", modelName);
  1066. #endif
  1067. }
  1068. }
  1069. void NPC_PrecacheAnimationCFG( const char *NPC_type )
  1070. {
  1071. char filename[MAX_QPATH];
  1072. const char *token;
  1073. const char *value;
  1074. const char *p;
  1075. if ( !Q_stricmp( "random", NPC_type ) )
  1076. {//sorry, can't precache a random just yet
  1077. return;
  1078. }
  1079. p = NPCParms;
  1080. COM_BeginParseSession();
  1081. // look for the right NPC
  1082. while ( p )
  1083. {
  1084. token = COM_ParseExt( &p, qtrue );
  1085. if ( token[0] == 0 )
  1086. return;
  1087. if ( !Q_stricmp( token, NPC_type ) )
  1088. {
  1089. break;
  1090. }
  1091. SkipBracedSection( &p );
  1092. }
  1093. if ( !p )
  1094. {
  1095. return;
  1096. }
  1097. if ( G_ParseLiteral( &p, "{" ) )
  1098. {
  1099. return;
  1100. }
  1101. // parse the NPC info block
  1102. while ( 1 )
  1103. {
  1104. token = COM_ParseExt( &p, qtrue );
  1105. if ( !token[0] )
  1106. {
  1107. gi.Printf( S_COLOR_RED"ERROR: unexpected EOF while parsing '%s'\n", NPC_type );
  1108. return;
  1109. }
  1110. if ( !Q_stricmp( token, "}" ) )
  1111. {
  1112. break;
  1113. }
  1114. // legsmodel
  1115. if ( !Q_stricmp( token, "legsmodel" ) )
  1116. {
  1117. if ( COM_ParseString( &p, &value ) )
  1118. {
  1119. continue;
  1120. }
  1121. //must copy data out of this pointer into a different part of memory because the funcs we're about to call will call COM_ParseExt
  1122. Q_strncpyz( filename, value, sizeof( filename ), qtrue );
  1123. G_ParseAnimFileSet( filename );
  1124. return;
  1125. }
  1126. // playerModel
  1127. if ( !Q_stricmp( token, "playerModel" ) )
  1128. {
  1129. if ( COM_ParseString( &p, &value ) )
  1130. {
  1131. continue;
  1132. }
  1133. char animName[MAX_QPATH];
  1134. char *GLAName;
  1135. char *slash = NULL;
  1136. char *strippedName;
  1137. int handle = gi.G2API_PrecacheGhoul2Model( va( "models/players/%s/model.glm", value ) );
  1138. if ( handle > 0 )//FIXME: isn't 0 a valid handle?
  1139. {
  1140. GLAName = gi.G2API_GetAnimFileNameIndex( handle );
  1141. if ( GLAName )
  1142. {
  1143. Q_strncpyz( animName, GLAName, sizeof( animName ), qtrue );
  1144. slash = strrchr( animName, '/' );
  1145. if ( slash )
  1146. {
  1147. *slash = 0;
  1148. }
  1149. strippedName = COM_SkipPath( animName );
  1150. //must copy data out of this pointer into a different part of memory because the funcs we're about to call will call COM_ParseExt
  1151. Q_strncpyz( filename, value, sizeof( filename ), qtrue );
  1152. G_ParseAnimFileSet(strippedName, filename);
  1153. return;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. extern int NPC_WeaponsForTeam( team_t team, int spawnflags, const char *NPC_type );
  1160. void NPC_PrecacheWeapons( team_t playerTeam, int spawnflags, char *NPCtype )
  1161. {
  1162. int weapons = NPC_WeaponsForTeam( playerTeam, spawnflags, NPCtype );
  1163. gitem_t *item;
  1164. for ( int curWeap = WP_SABER; curWeap < WP_NUM_WEAPONS; curWeap++ )
  1165. {
  1166. if ( (weapons & ( 1 << curWeap )) )
  1167. {
  1168. item = FindItemForWeapon( ((weapon_t)(curWeap)) ); //precache the weapon
  1169. CG_RegisterItemSounds( (item-bg_itemlist) );
  1170. CG_RegisterItemVisuals( (item-bg_itemlist) );
  1171. //precache the in-hand/in-world ghoul2 weapon model
  1172. char weaponModel[64];
  1173. strcpy (weaponModel, weaponData[curWeap].weaponMdl);
  1174. if (char *spot = strstr(weaponModel, ".md3") ) {
  1175. *spot = 0;
  1176. spot = strstr(weaponModel, "_w");//i'm using the in view weapon array instead of scanning the item list, so put the _w back on
  1177. if (!spot) {
  1178. strcat (weaponModel, "_w");
  1179. }
  1180. strcat (weaponModel, ".glm"); //and change to ghoul2
  1181. }
  1182. gi.G2API_PrecacheGhoul2Model( weaponModel ); // correct way is item->world_model
  1183. }
  1184. }
  1185. }
  1186. /*
  1187. void NPC_PrecacheByClassName ( char *NPCName )
  1188. This runs all the class specific precache functions
  1189. */
  1190. extern void NPC_ShadowTrooper_Precache( void );
  1191. extern void NPC_Gonk_Precache( void );
  1192. extern void NPC_Mouse_Precache( void );
  1193. extern void NPC_Seeker_Precache( void );
  1194. extern void NPC_Remote_Precache( void );
  1195. extern void NPC_R2D2_Precache(void);
  1196. extern void NPC_R5D2_Precache(void);
  1197. extern void NPC_Probe_Precache(void);
  1198. extern void NPC_Interrogator_Precache(gentity_t *self);
  1199. extern void NPC_MineMonster_Precache( void );
  1200. extern void NPC_Howler_Precache( void );
  1201. extern void NPC_Rancor_Precache( void );
  1202. extern void NPC_MutantRancor_Precache( void );
  1203. extern void NPC_Wampa_Precache( void );
  1204. extern void NPC_ATST_Precache(void);
  1205. extern void NPC_Sentry_Precache(void);
  1206. extern void NPC_Mark1_Precache(void);
  1207. extern void NPC_Mark2_Precache(void);
  1208. extern void NPC_Protocol_Precache( void );
  1209. extern void Boba_Precache( void );
  1210. extern void RT_Precache( void );
  1211. extern void SandCreature_Precache( void );
  1212. extern void NPC_TavionScepter_Precache( void );
  1213. extern void NPC_TavionSithSword_Precache( void );
  1214. extern void NPC_Rosh_Dark_Precache( void );
  1215. extern void NPC_Tusken_Precache( void );
  1216. extern void NPC_Saboteur_Precache( void );
  1217. extern void NPC_CultistDestroyer_Precache( void );
  1218. void NPC_Jawa_Precache( void )
  1219. {
  1220. for ( int i = 1; i < 7; i++ )
  1221. {
  1222. G_SoundIndex( va( "sound/chars/jawa/misc/chatter%d.wav", i ) );
  1223. }
  1224. G_SoundIndex( "sound/chars/jawa/misc/ooh-tee-nee.wav" );
  1225. }
  1226. void NPC_PrecacheByClassName( const char* type )
  1227. {
  1228. if (!type || !type[0])
  1229. {
  1230. return;
  1231. }
  1232. if ( !Q_stricmp( "gonk", type))
  1233. {
  1234. NPC_Gonk_Precache();
  1235. }
  1236. else if ( !Q_stricmp( "mouse", type))
  1237. {
  1238. NPC_Mouse_Precache();
  1239. }
  1240. else if ( !Q_stricmpn( "r2d2", type, 4))
  1241. {
  1242. NPC_R2D2_Precache();
  1243. }
  1244. else if ( !Q_stricmp( "atst", type))
  1245. {
  1246. NPC_ATST_Precache();
  1247. }
  1248. else if ( !Q_stricmpn( "r5d2", type, 4))
  1249. {
  1250. NPC_R5D2_Precache();
  1251. }
  1252. else if ( !Q_stricmp( "mark1", type))
  1253. {
  1254. NPC_Mark1_Precache();
  1255. }
  1256. else if ( !Q_stricmp( "mark2", type))
  1257. {
  1258. NPC_Mark2_Precache();
  1259. }
  1260. else if ( !Q_stricmp( "interrogator", type))
  1261. {
  1262. NPC_Interrogator_Precache(NULL);
  1263. }
  1264. else if ( !Q_stricmp( "probe", type))
  1265. {
  1266. NPC_Probe_Precache();
  1267. }
  1268. else if ( !Q_stricmp( "seeker", type))
  1269. {
  1270. NPC_Seeker_Precache();
  1271. }
  1272. else if ( !Q_stricmpn( "remote", type, 6))
  1273. {
  1274. NPC_Remote_Precache();
  1275. }
  1276. else if ( !Q_stricmpn( "shadowtrooper", type, 13 ) )
  1277. {
  1278. NPC_ShadowTrooper_Precache();
  1279. }
  1280. else if ( !Q_stricmp( "minemonster", type ))
  1281. {
  1282. NPC_MineMonster_Precache();
  1283. }
  1284. else if ( !Q_stricmp( "howler", type ))
  1285. {
  1286. NPC_Howler_Precache();
  1287. }
  1288. else if ( !Q_stricmp( "rancor", type ))
  1289. {
  1290. NPC_Rancor_Precache();
  1291. }
  1292. else if ( !Q_stricmp( "mutant_rancor", type ))
  1293. {
  1294. NPC_Rancor_Precache();
  1295. NPC_MutantRancor_Precache();
  1296. }
  1297. else if ( !Q_stricmp( "wampa", type ))
  1298. {
  1299. NPC_Wampa_Precache();
  1300. }
  1301. else if ( !Q_stricmp( "sand_creature", type ))
  1302. {
  1303. SandCreature_Precache();
  1304. }
  1305. else if ( !Q_stricmp( "sentry", type ))
  1306. {
  1307. NPC_Sentry_Precache();
  1308. }
  1309. else if ( !Q_stricmp( "protocol", type ))
  1310. {
  1311. NPC_Protocol_Precache();
  1312. }
  1313. else if ( !Q_stricmp( "boba_fett", type ))
  1314. {
  1315. Boba_Precache();
  1316. }
  1317. else if ( !Q_stricmp( "rockettrooper2", type ))
  1318. {
  1319. RT_Precache();
  1320. }
  1321. else if ( !Q_stricmp( "rockettrooper2Officer", type ))
  1322. {
  1323. RT_Precache();
  1324. }
  1325. else if ( !Q_stricmp( "tavion_scepter", type ))
  1326. {
  1327. NPC_TavionScepter_Precache();
  1328. }
  1329. else if ( !Q_stricmp( "tavion_sith_sword", type ))
  1330. {
  1331. NPC_TavionSithSword_Precache();
  1332. }
  1333. else if ( !Q_stricmp( "rosh_dark", type ) )
  1334. {
  1335. NPC_Rosh_Dark_Precache();
  1336. }
  1337. else if ( !Q_stricmpn( "tusken", type, 6 ) )
  1338. {
  1339. NPC_Tusken_Precache();
  1340. }
  1341. else if ( !Q_stricmpn( "saboteur", type, 8 ) )
  1342. {
  1343. NPC_Saboteur_Precache();
  1344. }
  1345. else if ( !Q_stricmp( "cultist_destroyer", type ) )
  1346. {
  1347. NPC_CultistDestroyer_Precache();
  1348. }
  1349. else if ( !Q_stricmpn( "jawa", type, 4 ) )
  1350. {
  1351. NPC_Jawa_Precache();
  1352. }
  1353. }
  1354. /*
  1355. void NPC_Precache ( char *NPCName )
  1356. Precaches NPC skins, tgas and md3s.
  1357. */
  1358. void NPC_Precache ( gentity_t *spawner )
  1359. {
  1360. clientInfo_t ci={0};
  1361. renderInfo_t ri={0};
  1362. team_t playerTeam = TEAM_FREE;
  1363. const char *token;
  1364. const char *value;
  1365. const char *p;
  1366. char *patch;
  1367. char sound[MAX_QPATH];
  1368. qboolean md3Model = qfalse;
  1369. char playerModel[MAX_QPATH] = { 0 };
  1370. char customSkin[MAX_QPATH];
  1371. if ( !Q_stricmp( "random", spawner->NPC_type ) )
  1372. {//sorry, can't precache a random just yet
  1373. return;
  1374. }
  1375. strcpy(customSkin,"default");
  1376. p = NPCParms;
  1377. COM_BeginParseSession();
  1378. // look for the right NPC
  1379. while ( p )
  1380. {
  1381. token = COM_ParseExt( &p, qtrue );
  1382. if ( token[0] == 0 )
  1383. return;
  1384. if ( !Q_stricmp( token, spawner->NPC_type ) )
  1385. {
  1386. break;
  1387. }
  1388. SkipBracedSection( &p );
  1389. }
  1390. if ( !p )
  1391. {
  1392. return;
  1393. }
  1394. if ( G_ParseLiteral( &p, "{" ) )
  1395. {
  1396. return;
  1397. }
  1398. // parse the NPC info block
  1399. while ( 1 )
  1400. {
  1401. token = COM_ParseExt( &p, qtrue );
  1402. if ( !token[0] )
  1403. {
  1404. gi.Printf( S_COLOR_RED"ERROR: unexpected EOF while parsing '%s'\n", spawner->NPC_type );
  1405. return;
  1406. }
  1407. if ( !Q_stricmp( token, "}" ) )
  1408. {
  1409. break;
  1410. }
  1411. // headmodel
  1412. if ( !Q_stricmp( token, "headmodel" ) )
  1413. {
  1414. if ( COM_ParseString( &p, &value ) )
  1415. {
  1416. continue;
  1417. }
  1418. if(!Q_stricmp("none", value))
  1419. {
  1420. }
  1421. else
  1422. {
  1423. Q_strncpyz( ri.headModelName, value, sizeof(ri.headModelName), qtrue);
  1424. }
  1425. md3Model = qtrue;
  1426. continue;
  1427. }
  1428. // torsomodel
  1429. if ( !Q_stricmp( token, "torsomodel" ) )
  1430. {
  1431. if ( COM_ParseString( &p, &value ) )
  1432. {
  1433. continue;
  1434. }
  1435. if(!Q_stricmp("none", value))
  1436. {
  1437. }
  1438. else
  1439. {
  1440. Q_strncpyz( ri.torsoModelName, value, sizeof(ri.torsoModelName), qtrue);
  1441. }
  1442. md3Model = qtrue;
  1443. continue;
  1444. }
  1445. // legsmodel
  1446. if ( !Q_stricmp( token, "legsmodel" ) )
  1447. {
  1448. if ( COM_ParseString( &p, &value ) )
  1449. {
  1450. continue;
  1451. }
  1452. Q_strncpyz( ri.legsModelName, value, sizeof(ri.legsModelName), qtrue);
  1453. md3Model = qtrue;
  1454. continue;
  1455. }
  1456. // playerModel
  1457. if ( !Q_stricmp( token, "playerModel" ) )
  1458. {
  1459. if ( COM_ParseString( &p, &value ) )
  1460. {
  1461. continue;
  1462. }
  1463. Q_strncpyz( playerModel, value, sizeof(playerModel), qtrue);
  1464. md3Model = qfalse;
  1465. continue;
  1466. }
  1467. // customSkin
  1468. if ( !Q_stricmp( token, "customSkin" ) )
  1469. {
  1470. if ( COM_ParseString( &p, &value ) )
  1471. {
  1472. continue;
  1473. }
  1474. Q_strncpyz( customSkin, value, sizeof(customSkin), qtrue);
  1475. continue;
  1476. }
  1477. // playerTeam
  1478. if ( !Q_stricmp( token, "playerTeam" ) )
  1479. {
  1480. if ( COM_ParseString( &p, &value ) )
  1481. {
  1482. continue;
  1483. }
  1484. playerTeam = (team_t)GetIDForString( TeamTable, token );
  1485. continue;
  1486. }
  1487. // snd
  1488. if ( !Q_stricmp( token, "snd" ) ) {
  1489. if ( COM_ParseString( &p, &value ) ) {
  1490. continue;
  1491. }
  1492. if ( !(spawner->svFlags&SVF_NO_BASIC_SOUNDS) )
  1493. {
  1494. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  1495. Q_strncpyz( sound, value, sizeof( sound ) );
  1496. patch = strstr( sound, "/" );
  1497. if ( patch )
  1498. {
  1499. *patch = 0;
  1500. }
  1501. ci.customBasicSoundDir = G_NewString( sound );
  1502. }
  1503. continue;
  1504. }
  1505. // sndcombat
  1506. if ( !Q_stricmp( token, "sndcombat" ) ) {
  1507. if ( COM_ParseString( &p, &value ) ) {
  1508. continue;
  1509. }
  1510. if ( !(spawner->svFlags&SVF_NO_COMBAT_SOUNDS) )
  1511. {
  1512. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  1513. Q_strncpyz( sound, value, sizeof( sound ) );
  1514. patch = strstr( sound, "/" );
  1515. if ( patch )
  1516. {
  1517. *patch = 0;
  1518. }
  1519. ci.customCombatSoundDir = G_NewString( sound );
  1520. }
  1521. continue;
  1522. }
  1523. // sndextra
  1524. if ( !Q_stricmp( token, "sndextra" ) ) {
  1525. if ( COM_ParseString( &p, &value ) ) {
  1526. continue;
  1527. }
  1528. if ( !(spawner->svFlags&SVF_NO_EXTRA_SOUNDS) )
  1529. {
  1530. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  1531. Q_strncpyz( sound, value, sizeof( sound ) );
  1532. patch = strstr( sound, "/" );
  1533. if ( patch )
  1534. {
  1535. *patch = 0;
  1536. }
  1537. ci.customExtraSoundDir = G_NewString( sound );
  1538. }
  1539. continue;
  1540. }
  1541. // sndjedi
  1542. if ( !Q_stricmp( token, "sndjedi" ) ) {
  1543. if ( COM_ParseString( &p, &value ) ) {
  1544. continue;
  1545. }
  1546. if ( !(spawner->svFlags&SVF_NO_EXTRA_SOUNDS) )
  1547. {
  1548. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  1549. Q_strncpyz( sound, value, sizeof( sound ) );
  1550. patch = strstr( sound, "/" );
  1551. if ( patch )
  1552. {
  1553. *patch = 0;
  1554. }
  1555. ci.customJediSoundDir = G_NewString( sound );
  1556. }
  1557. continue;
  1558. }
  1559. //cache weapons
  1560. if ( !Q_stricmp( token, "weapon" ) )
  1561. {
  1562. if ( COM_ParseString( &p, &value ) )
  1563. {
  1564. continue;
  1565. }
  1566. int weap = GetIDForString( WPTable, value );
  1567. if ( weap >= WP_NONE && weap < WP_NUM_WEAPONS )
  1568. {
  1569. if ( weap > WP_NONE )
  1570. {
  1571. RegisterItem( FindItemForWeapon( (weapon_t)(weap) ) ); //precache the weapon
  1572. }
  1573. }
  1574. continue;
  1575. }
  1576. //cache sabers
  1577. //saber name
  1578. if ( !Q_stricmp( token, "saber" ) )
  1579. {
  1580. if ( COM_ParseString( &p, &value ) )
  1581. {
  1582. continue;
  1583. }
  1584. char *saberName = G_NewString( value );
  1585. saberInfo_t saber;
  1586. WP_SaberParseParms( saberName, &saber );
  1587. if ( saber.model && saber.model[0] )
  1588. {
  1589. G_ModelIndex( saber.model );
  1590. }
  1591. if ( saber.skin && saber.skin[0] )
  1592. {
  1593. gi.RE_RegisterSkin( saber.skin );
  1594. G_SkinIndex( saber.skin );
  1595. }
  1596. continue;
  1597. }
  1598. //second saber name
  1599. if ( !Q_stricmp( token, "saber2" ) )
  1600. {
  1601. if ( COM_ParseString( &p, &value ) )
  1602. {
  1603. continue;
  1604. }
  1605. char *saberName = G_NewString( value );
  1606. saberInfo_t saber;
  1607. WP_SaberParseParms( saberName, &saber );
  1608. if ( saber.model && saber.model[0] )
  1609. {
  1610. G_ModelIndex( saber.model );
  1611. }
  1612. if ( saber.skin && saber.skin[0] )
  1613. {
  1614. gi.RE_RegisterSkin( saber.skin );
  1615. G_SkinIndex( saber.skin );
  1616. }
  1617. continue;
  1618. }
  1619. }
  1620. if ( md3Model )
  1621. {
  1622. CG_RegisterClientRenderInfo( &ci, &ri );
  1623. }
  1624. else
  1625. {
  1626. char skinName[MAX_QPATH];
  1627. //precache ghoul2 model
  1628. gi.G2API_PrecacheGhoul2Model( va( "models/players/%s/model.glm", playerModel ) );
  1629. //precache skin
  1630. if (strchr(customSkin, '|'))
  1631. {//three part skin
  1632. Com_sprintf( skinName, sizeof( skinName ), "models/players/%s/|%s", playerModel, customSkin );
  1633. }
  1634. else
  1635. {//standard skin
  1636. Com_sprintf( skinName, sizeof( skinName ), "models/players/%s/model_%s.skin", playerModel, customSkin );
  1637. }
  1638. // lets see if it's out there
  1639. gi.RE_RegisterSkin( skinName );
  1640. }
  1641. //precache this NPC's possible weapons
  1642. NPC_PrecacheWeapons( playerTeam, spawner->spawnflags, spawner->NPC_type );
  1643. // Anything else special about them
  1644. NPC_PrecacheByClassName( spawner->NPC_type );
  1645. CG_RegisterNPCCustomSounds( &ci );
  1646. //CG_RegisterNPCEffects( playerTeam );
  1647. //FIXME: Look for a "sounds" directory and precache death, pain, alert sounds
  1648. }
  1649. void NPC_BuildRandom( gentity_t *NPC )
  1650. {
  1651. }
  1652. extern void G_MatchPlayerWeapon( gentity_t *ent );
  1653. extern void G_InitPlayerFromCvars( gentity_t *ent );
  1654. extern void G_SetG2PlayerModel( gentity_t * const ent, const char *modelName, const char *customSkin, const char *surfOff, const char *surfOn );
  1655. qboolean NPC_ParseParms( const char *NPCName, gentity_t *NPC )
  1656. {
  1657. const char *token;
  1658. const char *value;
  1659. const char *p;
  1660. int n;
  1661. float f;
  1662. char *patch;
  1663. char sound[MAX_QPATH];
  1664. char playerModel[MAX_QPATH];
  1665. char customSkin[MAX_QPATH];
  1666. clientInfo_t *ci = &NPC->client->clientInfo;
  1667. renderInfo_t *ri = &NPC->client->renderInfo;
  1668. gNPCstats_t *stats = NULL;
  1669. qboolean md3Model = qtrue;
  1670. char surfOff[1024]={0};
  1671. char surfOn[1024]={0};
  1672. qboolean parsingPlayer = qfalse;
  1673. strcpy(customSkin,"default");
  1674. if ( !NPCName || !NPCName[0])
  1675. {
  1676. NPCName = "Player";
  1677. }
  1678. if ( !NPC->s.number && NPC->client != NULL )
  1679. {//player, only want certain data
  1680. parsingPlayer = qtrue;
  1681. }
  1682. if ( NPC->NPC )
  1683. {
  1684. stats = &NPC->NPC->stats;
  1685. /*
  1686. NPC->NPC->allWeaponOrder[0] = WP_BRYAR_PISTOL;
  1687. NPC->NPC->allWeaponOrder[1] = WP_SABER;
  1688. NPC->NPC->allWeaponOrder[2] = WP_IMOD;
  1689. NPC->NPC->allWeaponOrder[3] = WP_SCAVENGER_RIFLE;
  1690. NPC->NPC->allWeaponOrder[4] = WP_TRICORDER;
  1691. NPC->NPC->allWeaponOrder[6] = WP_NONE;
  1692. NPC->NPC->allWeaponOrder[6] = WP_NONE;
  1693. NPC->NPC->allWeaponOrder[7] = WP_NONE;
  1694. */
  1695. // fill in defaults
  1696. stats->sex = SEX_MALE;
  1697. stats->aggression = 3;
  1698. stats->aim = 3;
  1699. stats->earshot = 1024;
  1700. stats->evasion = 3;
  1701. stats->hfov = 90;
  1702. stats->intelligence = 3;
  1703. stats->move = 3;
  1704. stats->reactions = 3;
  1705. stats->vfov = 60;
  1706. stats->vigilance = 0.1f;
  1707. stats->visrange = 1024;
  1708. if (g_entities[ENTITYNUM_WORLD].max_health && stats->visrange>g_entities[ENTITYNUM_WORLD].max_health)
  1709. {
  1710. stats->visrange = g_entities[ENTITYNUM_WORLD].max_health;
  1711. }
  1712. stats->health = 0;
  1713. stats->yawSpeed = 90;
  1714. stats->walkSpeed = 90;
  1715. stats->runSpeed = 300;
  1716. stats->acceleration = 15;//Increase/descrease speed this much per frame (20fps)
  1717. }
  1718. else
  1719. {
  1720. stats = NULL;
  1721. }
  1722. Q_strncpyz( ci->name, NPCName, sizeof( ci->name ) );
  1723. NPC->playerModel = -1;
  1724. //Set defaults
  1725. //FIXME: should probably put default torso and head models, but what about enemies
  1726. //that don't have any- like Stasis?
  1727. //Q_strncpyz( ri->headModelName, DEFAULT_HEADMODEL, sizeof(ri->headModelName), qtrue);
  1728. //Q_strncpyz( ri->torsoModelName, DEFAULT_TORSOMODEL, sizeof(ri->torsoModelName), qtrue);
  1729. //Q_strncpyz( ri->legsModelName, DEFAULT_LEGSMODEL, sizeof(ri->legsModelName), qtrue);
  1730. ri->headModelName[0] = 0;
  1731. ri->torsoModelName[0]= 0;
  1732. ri->legsModelName[0] =0;
  1733. ri->headYawRangeLeft = 80;
  1734. ri->headYawRangeRight = 80;
  1735. ri->headPitchRangeUp = 45;
  1736. ri->headPitchRangeDown = 45;
  1737. ri->torsoYawRangeLeft = 60;
  1738. ri->torsoYawRangeRight = 60;
  1739. ri->torsoPitchRangeUp = 30;
  1740. ri->torsoPitchRangeDown = 50;
  1741. VectorCopy(playerMins, NPC->mins);
  1742. VectorCopy(playerMaxs, NPC->maxs);
  1743. NPC->client->crouchheight = CROUCH_MAXS_2;
  1744. NPC->client->standheight = DEFAULT_MAXS_2;
  1745. NPC->client->moveType = MT_RUNJUMP;
  1746. NPC->client->dismemberProbHead = 100;
  1747. NPC->client->dismemberProbArms = 100;
  1748. NPC->client->dismemberProbHands = 100;
  1749. NPC->client->dismemberProbWaist = 100;
  1750. NPC->client->dismemberProbLegs = 100;
  1751. NPC->s.modelScale[0] = NPC->s.modelScale[1] = NPC->s.modelScale[2] = 1.0f;
  1752. *(int*)ri->customRGBA=-1;
  1753. if ( !Q_stricmp( "random", NPCName ) )
  1754. {//Randomly assemble an NPC
  1755. NPC_BuildRandom( NPC );
  1756. }
  1757. else
  1758. {
  1759. p = NPCParms;
  1760. COM_BeginParseSession();
  1761. // look for the right NPC
  1762. while ( p )
  1763. {
  1764. token = COM_ParseExt( &p, qtrue );
  1765. if ( token[0] == 0 )
  1766. {
  1767. return qfalse;
  1768. }
  1769. if ( !Q_stricmp( token, NPCName ) )
  1770. {
  1771. break;
  1772. }
  1773. SkipBracedSection( &p );
  1774. }
  1775. if ( !p )
  1776. {
  1777. return qfalse;
  1778. }
  1779. if ( G_ParseLiteral( &p, "{" ) )
  1780. {
  1781. return qfalse;
  1782. }
  1783. // parse the NPC info block
  1784. while ( 1 )
  1785. {
  1786. token = COM_ParseExt( &p, qtrue );
  1787. if ( !token[0] )
  1788. {
  1789. gi.Printf( S_COLOR_RED"ERROR: unexpected EOF while parsing '%s'\n", NPCName );
  1790. return qfalse;
  1791. }
  1792. if ( !Q_stricmp( token, "}" ) )
  1793. {
  1794. break;
  1795. }
  1796. //===MODEL PROPERTIES===========================================================
  1797. // custom color
  1798. if ( !Q_stricmp( token, "customRGBA" ) )
  1799. {
  1800. if ( COM_ParseString( &p, &value ) )
  1801. {
  1802. continue;
  1803. }
  1804. if ( !Q_stricmp( value, "random") )
  1805. {
  1806. ri->customRGBA[0]=Q_irand(0,255);
  1807. ri->customRGBA[1]=Q_irand(0,255);
  1808. ri->customRGBA[2]=Q_irand(0,255);
  1809. ri->customRGBA[3]=255;
  1810. }
  1811. else if ( !Q_stricmp( value, "random1") )
  1812. {
  1813. ri->customRGBA[3]=255;
  1814. switch (Q_irand(0,5))
  1815. {
  1816. default:
  1817. case 0:
  1818. ri->customRGBA[0]=127;
  1819. ri->customRGBA[1]=153;
  1820. ri->customRGBA[2]=255;
  1821. break;
  1822. case 1:
  1823. ri->customRGBA[0]=177;
  1824. ri->customRGBA[1]=29;
  1825. ri->customRGBA[2]=13;
  1826. break;
  1827. case 2:
  1828. ri->customRGBA[0]=47;
  1829. ri->customRGBA[1]=90;
  1830. ri->customRGBA[2]=40;
  1831. break;
  1832. case 3:
  1833. ri->customRGBA[0]=181;
  1834. ri->customRGBA[1]=207;
  1835. ri->customRGBA[2]=255;
  1836. break;
  1837. case 4:
  1838. ri->customRGBA[0]=138;
  1839. ri->customRGBA[1]=83;
  1840. ri->customRGBA[2]=0;
  1841. break;
  1842. case 5:
  1843. ri->customRGBA[0]=254;
  1844. ri->customRGBA[1]=199;
  1845. ri->customRGBA[2]=14;
  1846. break;
  1847. }
  1848. }
  1849. else if ( !Q_stricmp( value, "jedi_hf" ) )
  1850. {
  1851. ri->customRGBA[3]=255;
  1852. switch (Q_irand(0,7))
  1853. {
  1854. default:
  1855. case 0://red1
  1856. ri->customRGBA[0]=165;
  1857. ri->customRGBA[1]=48;
  1858. ri->customRGBA[2]=21;
  1859. break;
  1860. case 1://yellow1
  1861. ri->customRGBA[0]=254;
  1862. ri->customRGBA[1]=230;
  1863. ri->customRGBA[2]=132;
  1864. break;
  1865. case 2://bluegray
  1866. ri->customRGBA[0]=181;
  1867. ri->customRGBA[1]=207;
  1868. ri->customRGBA[2]=255;
  1869. break;
  1870. case 3://pink
  1871. ri->customRGBA[0]=233;
  1872. ri->customRGBA[1]=183;
  1873. ri->customRGBA[2]=208;
  1874. break;
  1875. case 4://lt blue
  1876. ri->customRGBA[0]=161;
  1877. ri->customRGBA[1]=226;
  1878. ri->customRGBA[2]=240;
  1879. break;
  1880. case 5://blue
  1881. ri->customRGBA[0]=101;
  1882. ri->customRGBA[1]=159;
  1883. ri->customRGBA[2]=255;
  1884. break;
  1885. case 6://orange
  1886. ri->customRGBA[0]=255;
  1887. ri->customRGBA[1]=157;
  1888. ri->customRGBA[2]=114;
  1889. break;
  1890. case 7://violet
  1891. ri->customRGBA[0]=216;
  1892. ri->customRGBA[1]=160;
  1893. ri->customRGBA[2]=255;
  1894. break;
  1895. }
  1896. }
  1897. else if ( !Q_stricmp( value, "jedi_hm" ) )
  1898. {
  1899. ri->customRGBA[3]=255;
  1900. switch (Q_irand(0,7))
  1901. {
  1902. default:
  1903. case 0://yellow
  1904. ri->customRGBA[0]=252;
  1905. ri->customRGBA[1]=243;
  1906. ri->customRGBA[2]=180;
  1907. break;
  1908. case 1://blue
  1909. ri->customRGBA[0]=69;
  1910. ri->customRGBA[1]=109;
  1911. ri->customRGBA[2]=255;
  1912. break;
  1913. case 2://gold
  1914. ri->customRGBA[0]=254;
  1915. ri->customRGBA[1]=197;
  1916. ri->customRGBA[2]=73;
  1917. break;
  1918. case 3://orange
  1919. ri->customRGBA[0]=178;
  1920. ri->customRGBA[1]=78;
  1921. ri->customRGBA[2]=18;
  1922. break;
  1923. case 4://bluegreen
  1924. ri->customRGBA[0]=112;
  1925. ri->customRGBA[1]=153;
  1926. ri->customRGBA[2]=161;
  1927. break;
  1928. case 5://blue2
  1929. ri->customRGBA[0]=123;
  1930. ri->customRGBA[1]=182;
  1931. ri->customRGBA[2]=255;
  1932. break;
  1933. case 6://green2
  1934. ri->customRGBA[0]=0;
  1935. ri->customRGBA[1]=88;
  1936. ri->customRGBA[2]=105;
  1937. break;
  1938. case 7://violet
  1939. ri->customRGBA[0]=138;
  1940. ri->customRGBA[1]=0;
  1941. ri->customRGBA[2]=0;
  1942. break;
  1943. }
  1944. }
  1945. else if ( !Q_stricmp( value, "jedi_kdm" ) )
  1946. {
  1947. ri->customRGBA[3]=255;
  1948. switch (Q_irand(0,8))
  1949. {
  1950. default:
  1951. case 0://blue
  1952. ri->customRGBA[0]=85;
  1953. ri->customRGBA[1]=120;
  1954. ri->customRGBA[2]=255;
  1955. break;
  1956. case 1://violet
  1957. ri->customRGBA[0]=173;
  1958. ri->customRGBA[1]=142;
  1959. ri->customRGBA[2]=219;
  1960. break;
  1961. case 2://brown1
  1962. ri->customRGBA[0]=254;
  1963. ri->customRGBA[1]=197;
  1964. ri->customRGBA[2]=73;
  1965. break;
  1966. case 3://orange
  1967. ri->customRGBA[0]=138;
  1968. ri->customRGBA[1]=83;
  1969. ri->customRGBA[2]=0;
  1970. break;
  1971. case 4://gold
  1972. ri->customRGBA[0]=254;
  1973. ri->customRGBA[1]=199;
  1974. ri->customRGBA[2]=14;
  1975. break;
  1976. case 5://blue2
  1977. ri->customRGBA[0]=68;
  1978. ri->customRGBA[1]=194;
  1979. ri->customRGBA[2]=217;
  1980. break;
  1981. case 6://red1
  1982. ri->customRGBA[0]=170;
  1983. ri->customRGBA[1]=3;
  1984. ri->customRGBA[2]=30;
  1985. break;
  1986. case 7://yellow1
  1987. ri->customRGBA[0]=225;
  1988. ri->customRGBA[1]=226;
  1989. ri->customRGBA[2]=144;
  1990. break;
  1991. case 8://violet2
  1992. ri->customRGBA[0]=167;
  1993. ri->customRGBA[1]=202;
  1994. ri->customRGBA[2]=255;
  1995. break;
  1996. }
  1997. }
  1998. else if ( !Q_stricmp( value, "jedi_rm" ) )
  1999. {
  2000. ri->customRGBA[3]=255;
  2001. switch (Q_irand(0,8))
  2002. {
  2003. default:
  2004. case 0://blue
  2005. ri->customRGBA[0]=127;
  2006. ri->customRGBA[1]=153;
  2007. ri->customRGBA[2]=255;
  2008. break;
  2009. case 1://green1
  2010. ri->customRGBA[0]=208;
  2011. ri->customRGBA[1]=249;
  2012. ri->customRGBA[2]=85;
  2013. break;
  2014. case 2://blue2
  2015. ri->customRGBA[0]=181;
  2016. ri->customRGBA[1]=207;
  2017. ri->customRGBA[2]=255;
  2018. break;
  2019. case 3://gold
  2020. ri->customRGBA[0]=138;
  2021. ri->customRGBA[1]=83;
  2022. ri->customRGBA[2]=0;
  2023. break;
  2024. case 4://gold
  2025. ri->customRGBA[0]=224;
  2026. ri->customRGBA[1]=171;
  2027. ri->customRGBA[2]=44;
  2028. break;
  2029. case 5://green2
  2030. ri->customRGBA[0]=49;
  2031. ri->customRGBA[1]=155;
  2032. ri->customRGBA[2]=131;
  2033. break;
  2034. case 6://red1
  2035. ri->customRGBA[0]=163;
  2036. ri->customRGBA[1]=79;
  2037. ri->customRGBA[2]=17;
  2038. break;
  2039. case 7://violet2
  2040. ri->customRGBA[0]=148;
  2041. ri->customRGBA[1]=104;
  2042. ri->customRGBA[2]=228;
  2043. break;
  2044. case 8://green3
  2045. ri->customRGBA[0]=138;
  2046. ri->customRGBA[1]=136;
  2047. ri->customRGBA[2]=0;
  2048. break;
  2049. }
  2050. }
  2051. else if ( !Q_stricmp( value, "jedi_tf" ) )
  2052. {
  2053. ri->customRGBA[3]=255;
  2054. switch (Q_irand(0,5))
  2055. {
  2056. default:
  2057. case 0://green1
  2058. ri->customRGBA[0]=255;
  2059. ri->customRGBA[1]=235;
  2060. ri->customRGBA[2]=100;
  2061. break;
  2062. case 1://blue1
  2063. ri->customRGBA[0]=62;
  2064. ri->customRGBA[1]=155;
  2065. ri->customRGBA[2]=255;
  2066. break;
  2067. case 2://red1
  2068. ri->customRGBA[0]=255;
  2069. ri->customRGBA[1]=110;
  2070. ri->customRGBA[2]=120;
  2071. break;
  2072. case 3://purple
  2073. ri->customRGBA[0]=180;
  2074. ri->customRGBA[1]=150;
  2075. ri->customRGBA[2]=255;
  2076. break;
  2077. case 4://flesh
  2078. ri->customRGBA[0]=255;
  2079. ri->customRGBA[1]=200;
  2080. ri->customRGBA[2]=212;
  2081. break;
  2082. case 5://base
  2083. ri->customRGBA[0]=255;
  2084. ri->customRGBA[1]=255;
  2085. ri->customRGBA[2]=255;
  2086. break;
  2087. }
  2088. }
  2089. else if ( !Q_stricmp( value, "jedi_zf" ) )
  2090. {
  2091. ri->customRGBA[3]=255;
  2092. switch (Q_irand(0,7))
  2093. {
  2094. default:
  2095. case 0://red1
  2096. ri->customRGBA[0]=204;
  2097. ri->customRGBA[1]=19;
  2098. ri->customRGBA[2]=21;
  2099. break;
  2100. case 1://orange1
  2101. ri->customRGBA[0]=255;
  2102. ri->customRGBA[1]=107;
  2103. ri->customRGBA[2]=40;
  2104. break;
  2105. case 2://pink1
  2106. ri->customRGBA[0]=255;
  2107. ri->customRGBA[1]=148;
  2108. ri->customRGBA[2]=155;
  2109. break;
  2110. case 3://gold
  2111. ri->customRGBA[0]=255;
  2112. ri->customRGBA[1]=164;
  2113. ri->customRGBA[2]=59;
  2114. break;
  2115. case 4://violet1
  2116. ri->customRGBA[0]=216;
  2117. ri->customRGBA[1]=160;
  2118. ri->customRGBA[2]=255;
  2119. break;
  2120. case 5://blue1
  2121. ri->customRGBA[0]=101;
  2122. ri->customRGBA[1]=159;
  2123. ri->customRGBA[2]=255;
  2124. break;
  2125. case 6://blue2
  2126. ri->customRGBA[0]=161;
  2127. ri->customRGBA[1]=226;
  2128. ri->customRGBA[2]=240;
  2129. break;
  2130. case 7://blue3
  2131. ri->customRGBA[0]=37;
  2132. ri->customRGBA[1]=155;
  2133. ri->customRGBA[2]=181;
  2134. break;
  2135. }
  2136. }
  2137. else
  2138. {
  2139. ri->customRGBA[0]=atoi(value);
  2140. if ( COM_ParseInt( &p, &n ) )
  2141. {
  2142. continue;
  2143. }
  2144. ri->customRGBA[1]=n;
  2145. if ( COM_ParseInt( &p, &n ) )
  2146. {
  2147. continue;
  2148. }
  2149. ri->customRGBA[2]=n;
  2150. if ( COM_ParseInt( &p, &n ) )
  2151. {
  2152. continue;
  2153. }
  2154. ri->customRGBA[3]=n;
  2155. }
  2156. continue;
  2157. }
  2158. // headmodel
  2159. if ( !Q_stricmp( token, "headmodel" ) )
  2160. {
  2161. if ( COM_ParseString( &p, &value ) )
  2162. {
  2163. continue;
  2164. }
  2165. if(!Q_stricmp("none", value))
  2166. {
  2167. ri->headModelName[0] = NULL;
  2168. //Zero the head clamp range so the torso & legs don't lag behind
  2169. ri->headYawRangeLeft =
  2170. ri->headYawRangeRight =
  2171. ri->headPitchRangeUp =
  2172. ri->headPitchRangeDown = 0;
  2173. }
  2174. else
  2175. {
  2176. Q_strncpyz( ri->headModelName, value, sizeof(ri->headModelName), qtrue);
  2177. }
  2178. continue;
  2179. }
  2180. // torsomodel
  2181. if ( !Q_stricmp( token, "torsomodel" ) )
  2182. {
  2183. if ( COM_ParseString( &p, &value ) )
  2184. {
  2185. continue;
  2186. }
  2187. if(!Q_stricmp("none", value))
  2188. {
  2189. ri->torsoModelName[0] = NULL;
  2190. //Zero the torso clamp range so the legs don't lag behind
  2191. ri->torsoYawRangeLeft =
  2192. ri->torsoYawRangeRight =
  2193. ri->torsoPitchRangeUp =
  2194. ri->torsoPitchRangeDown = 0;
  2195. }
  2196. else
  2197. {
  2198. Q_strncpyz( ri->torsoModelName, value, sizeof(ri->torsoModelName), qtrue);
  2199. }
  2200. continue;
  2201. }
  2202. // legsmodel
  2203. if ( !Q_stricmp( token, "legsmodel" ) )
  2204. {
  2205. if ( COM_ParseString( &p, &value ) )
  2206. {
  2207. continue;
  2208. }
  2209. Q_strncpyz( ri->legsModelName, value, sizeof(ri->legsModelName), qtrue);
  2210. //Need to do this here to get the right index
  2211. ci->animFileIndex = G_ParseAnimFileSet(ri->legsModelName);
  2212. continue;
  2213. }
  2214. // playerModel
  2215. if ( !Q_stricmp( token, "playerModel" ) )
  2216. {
  2217. if ( COM_ParseString( &p, &value ) )
  2218. {
  2219. continue;
  2220. }
  2221. Q_strncpyz( playerModel, value, sizeof(playerModel), qtrue);
  2222. md3Model = qfalse;
  2223. continue;
  2224. }
  2225. // customSkin
  2226. if ( !Q_stricmp( token, "customSkin" ) )
  2227. {
  2228. if ( COM_ParseString( &p, &value ) )
  2229. {
  2230. continue;
  2231. }
  2232. Q_strncpyz( customSkin, value, sizeof(customSkin), qtrue);
  2233. continue;
  2234. }
  2235. // surfOff
  2236. if ( !Q_stricmp( token, "surfOff" ) )
  2237. {
  2238. if ( COM_ParseString( &p, &value ) )
  2239. {
  2240. continue;
  2241. }
  2242. if ( surfOff[0] )
  2243. {
  2244. strncat( (char *)surfOff, ",", sizeof(surfOff) );
  2245. strncat( (char *)surfOff, value, sizeof(surfOff) );
  2246. }
  2247. else
  2248. {
  2249. Q_strncpyz( surfOff, value, sizeof(surfOff), qtrue);
  2250. }
  2251. continue;
  2252. }
  2253. // surfOn
  2254. if ( !Q_stricmp( token, "surfOn" ) )
  2255. {
  2256. if ( COM_ParseString( &p, &value ) )
  2257. {
  2258. continue;
  2259. }
  2260. if ( surfOn[0] )
  2261. {
  2262. strncat( (char *)surfOn, ",", sizeof(surfOn) );
  2263. strncat( (char *)surfOn, value, sizeof(surfOn) );
  2264. }
  2265. else
  2266. {
  2267. Q_strncpyz( surfOn, value, sizeof(surfOn), qtrue);
  2268. }
  2269. continue;
  2270. }
  2271. //headYawRangeLeft
  2272. if ( !Q_stricmp( token, "headYawRangeLeft" ) )
  2273. {
  2274. if ( COM_ParseInt( &p, &n ) )
  2275. {
  2276. SkipRestOfLine( &p );
  2277. continue;
  2278. }
  2279. if ( n < 0 )
  2280. {
  2281. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2282. continue;
  2283. }
  2284. ri->headYawRangeLeft = n;
  2285. continue;
  2286. }
  2287. //headYawRangeRight
  2288. if ( !Q_stricmp( token, "headYawRangeRight" ) )
  2289. {
  2290. if ( COM_ParseInt( &p, &n ) )
  2291. {
  2292. SkipRestOfLine( &p );
  2293. continue;
  2294. }
  2295. if ( n < 0 )
  2296. {
  2297. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2298. continue;
  2299. }
  2300. ri->headYawRangeRight = n;
  2301. continue;
  2302. }
  2303. //headPitchRangeUp
  2304. if ( !Q_stricmp( token, "headPitchRangeUp" ) )
  2305. {
  2306. if ( COM_ParseInt( &p, &n ) )
  2307. {
  2308. SkipRestOfLine( &p );
  2309. continue;
  2310. }
  2311. if ( n < 0 )
  2312. {
  2313. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2314. continue;
  2315. }
  2316. ri->headPitchRangeUp = n;
  2317. continue;
  2318. }
  2319. //headPitchRangeDown
  2320. if ( !Q_stricmp( token, "headPitchRangeDown" ) )
  2321. {
  2322. if ( COM_ParseInt( &p, &n ) )
  2323. {
  2324. SkipRestOfLine( &p );
  2325. continue;
  2326. }
  2327. if ( n < 0 )
  2328. {
  2329. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2330. continue;
  2331. }
  2332. ri->headPitchRangeDown = n;
  2333. continue;
  2334. }
  2335. //torsoYawRangeLeft
  2336. if ( !Q_stricmp( token, "torsoYawRangeLeft" ) )
  2337. {
  2338. if ( COM_ParseInt( &p, &n ) )
  2339. {
  2340. SkipRestOfLine( &p );
  2341. continue;
  2342. }
  2343. if ( n < 0 )
  2344. {
  2345. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2346. continue;
  2347. }
  2348. ri->torsoYawRangeLeft = n;
  2349. continue;
  2350. }
  2351. //torsoYawRangeRight
  2352. if ( !Q_stricmp( token, "torsoYawRangeRight" ) )
  2353. {
  2354. if ( COM_ParseInt( &p, &n ) )
  2355. {
  2356. SkipRestOfLine( &p );
  2357. continue;
  2358. }
  2359. if ( n < 0 )
  2360. {
  2361. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2362. continue;
  2363. }
  2364. ri->torsoYawRangeRight = n;
  2365. continue;
  2366. }
  2367. //torsoPitchRangeUp
  2368. if ( !Q_stricmp( token, "torsoPitchRangeUp" ) )
  2369. {
  2370. if ( COM_ParseInt( &p, &n ) )
  2371. {
  2372. SkipRestOfLine( &p );
  2373. continue;
  2374. }
  2375. if ( n < 0 )
  2376. {
  2377. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2378. continue;
  2379. }
  2380. ri->torsoPitchRangeUp = n;
  2381. continue;
  2382. }
  2383. //torsoPitchRangeDown
  2384. if ( !Q_stricmp( token, "torsoPitchRangeDown" ) )
  2385. {
  2386. if ( COM_ParseInt( &p, &n ) )
  2387. {
  2388. SkipRestOfLine( &p );
  2389. continue;
  2390. }
  2391. if ( n < 0 )
  2392. {
  2393. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2394. continue;
  2395. }
  2396. ri->torsoPitchRangeDown = n;
  2397. continue;
  2398. }
  2399. // Uniform XYZ scale
  2400. if ( !Q_stricmp( token, "scale" ) )
  2401. {
  2402. if ( COM_ParseInt( &p, &n ) )
  2403. {
  2404. SkipRestOfLine( &p );
  2405. continue;
  2406. }
  2407. if ( n < 0 )
  2408. {
  2409. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2410. continue;
  2411. }
  2412. if (n != 100)
  2413. {
  2414. NPC->s.modelScale[0] = NPC->s.modelScale[1] = NPC->s.modelScale[2] = n/100.0f;
  2415. }
  2416. continue;
  2417. }
  2418. //X scale
  2419. if ( !Q_stricmp( token, "scaleX" ) )
  2420. {
  2421. if ( COM_ParseInt( &p, &n ) )
  2422. {
  2423. SkipRestOfLine( &p );
  2424. continue;
  2425. }
  2426. if ( n < 0 )
  2427. {
  2428. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2429. continue;
  2430. }
  2431. if (n != 100)
  2432. {
  2433. NPC->s.modelScale[0] = n/100.0f;
  2434. }
  2435. continue;
  2436. }
  2437. //Y scale
  2438. if ( !Q_stricmp( token, "scaleY" ) )
  2439. {
  2440. if ( COM_ParseInt( &p, &n ) )
  2441. {
  2442. SkipRestOfLine( &p );
  2443. continue;
  2444. }
  2445. if ( n < 0 )
  2446. {
  2447. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2448. continue;
  2449. }
  2450. if (n != 100)
  2451. {
  2452. NPC->s.modelScale[1] = n/100.0f;
  2453. }
  2454. continue;
  2455. }
  2456. //Z scale
  2457. if ( !Q_stricmp( token, "scaleZ" ) )
  2458. {
  2459. if ( COM_ParseInt( &p, &n ) )
  2460. {
  2461. SkipRestOfLine( &p );
  2462. continue;
  2463. }
  2464. if ( n < 0 )
  2465. {
  2466. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2467. continue;
  2468. }
  2469. if (n != 100)
  2470. {
  2471. NPC->s.modelScale[2] = n/100.0f;
  2472. }
  2473. continue;
  2474. }
  2475. //===AI STATS=====================================================================
  2476. if ( !parsingPlayer )
  2477. {
  2478. // aggression
  2479. if ( !Q_stricmp( token, "aggression" ) ) {
  2480. if ( COM_ParseInt( &p, &n ) ) {
  2481. SkipRestOfLine( &p );
  2482. continue;
  2483. }
  2484. if ( n < 1 || n > 5 ) {
  2485. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2486. continue;
  2487. }
  2488. if ( NPC->NPC )
  2489. {
  2490. stats->aggression = n;
  2491. }
  2492. continue;
  2493. }
  2494. // aim
  2495. if ( !Q_stricmp( token, "aim" ) ) {
  2496. if ( COM_ParseInt( &p, &n ) ) {
  2497. SkipRestOfLine( &p );
  2498. continue;
  2499. }
  2500. if ( n < 1 || n > 5 ) {
  2501. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2502. continue;
  2503. }
  2504. if ( NPC->NPC )
  2505. {
  2506. stats->aim = n;
  2507. }
  2508. continue;
  2509. }
  2510. // earshot
  2511. if ( !Q_stricmp( token, "earshot" ) ) {
  2512. if ( COM_ParseFloat( &p, &f ) ) {
  2513. SkipRestOfLine( &p );
  2514. continue;
  2515. }
  2516. if ( f < 0.0f )
  2517. {
  2518. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2519. continue;
  2520. }
  2521. if ( NPC->NPC )
  2522. {
  2523. stats->earshot = f;
  2524. }
  2525. continue;
  2526. }
  2527. // evasion
  2528. if ( !Q_stricmp( token, "evasion" ) )
  2529. {
  2530. if ( COM_ParseInt( &p, &n ) )
  2531. {
  2532. SkipRestOfLine( &p );
  2533. continue;
  2534. }
  2535. if ( n < 1 || n > 5 )
  2536. {
  2537. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2538. continue;
  2539. }
  2540. if ( NPC->NPC )
  2541. {
  2542. stats->evasion = n;
  2543. }
  2544. continue;
  2545. }
  2546. // hfov
  2547. if ( !Q_stricmp( token, "hfov" ) ) {
  2548. if ( COM_ParseInt( &p, &n ) ) {
  2549. SkipRestOfLine( &p );
  2550. continue;
  2551. }
  2552. if ( n < 1 || n > 180 ) {
  2553. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2554. continue;
  2555. }
  2556. if ( NPC->NPC )
  2557. {
  2558. stats->hfov = n;// / 2; //FIXME: Why was this being done?!
  2559. }
  2560. continue;
  2561. }
  2562. // intelligence
  2563. if ( !Q_stricmp( token, "intelligence" ) ) {
  2564. if ( COM_ParseInt( &p, &n ) ) {
  2565. SkipRestOfLine( &p );
  2566. continue;
  2567. }
  2568. if ( n < 1 || n > 5 ) {
  2569. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2570. continue;
  2571. }
  2572. if ( NPC->NPC )
  2573. {
  2574. stats->intelligence = n;
  2575. }
  2576. continue;
  2577. }
  2578. // move
  2579. if ( !Q_stricmp( token, "move" ) ) {
  2580. if ( COM_ParseInt( &p, &n ) ) {
  2581. SkipRestOfLine( &p );
  2582. continue;
  2583. }
  2584. if ( n < 1 || n > 5 ) {
  2585. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2586. continue;
  2587. }
  2588. if ( NPC->NPC )
  2589. {
  2590. stats->move = n;
  2591. }
  2592. continue;
  2593. }
  2594. // reactions
  2595. if ( !Q_stricmp( token, "reactions" ) ) {
  2596. if ( COM_ParseInt( &p, &n ) ) {
  2597. SkipRestOfLine( &p );
  2598. continue;
  2599. }
  2600. if ( n < 1 || n > 5 ) {
  2601. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2602. continue;
  2603. }
  2604. if ( NPC->NPC )
  2605. {
  2606. stats->reactions = n;
  2607. }
  2608. continue;
  2609. }
  2610. // shootDistance
  2611. if ( !Q_stricmp( token, "shootDistance" ) ) {
  2612. if ( COM_ParseFloat( &p, &f ) ) {
  2613. SkipRestOfLine( &p );
  2614. continue;
  2615. }
  2616. if ( f < 0.0f )
  2617. {
  2618. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2619. continue;
  2620. }
  2621. if ( NPC->NPC )
  2622. {
  2623. stats->shootDistance = f;
  2624. }
  2625. continue;
  2626. }
  2627. // vfov
  2628. if ( !Q_stricmp( token, "vfov" ) ) {
  2629. if ( COM_ParseInt( &p, &n ) ) {
  2630. SkipRestOfLine( &p );
  2631. continue;
  2632. }
  2633. if ( n < 2 || n > 360 ) {
  2634. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2635. continue;
  2636. }
  2637. if ( NPC->NPC )
  2638. {
  2639. stats->vfov = n / 2;
  2640. }
  2641. continue;
  2642. }
  2643. // vigilance
  2644. if ( !Q_stricmp( token, "vigilance" ) ) {
  2645. if ( COM_ParseFloat( &p, &f ) ) {
  2646. SkipRestOfLine( &p );
  2647. continue;
  2648. }
  2649. if ( f < 0.0f )
  2650. {
  2651. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2652. continue;
  2653. }
  2654. if ( NPC->NPC )
  2655. {
  2656. stats->vigilance = f;
  2657. }
  2658. continue;
  2659. }
  2660. // visrange
  2661. if ( !Q_stricmp( token, "visrange" ) ) {
  2662. if ( COM_ParseFloat( &p, &f ) ) {
  2663. SkipRestOfLine( &p );
  2664. continue;
  2665. }
  2666. if ( f < 0.0f )
  2667. {
  2668. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2669. continue;
  2670. }
  2671. if ( NPC->NPC )
  2672. {
  2673. stats->visrange = f;
  2674. if (g_entities[ENTITYNUM_WORLD].max_health && stats->visrange>g_entities[ENTITYNUM_WORLD].max_health)
  2675. {
  2676. stats->visrange = g_entities[ENTITYNUM_WORLD].max_health;
  2677. }
  2678. }
  2679. continue;
  2680. }
  2681. // race
  2682. // if ( !Q_stricmp( token, "race" ) )
  2683. // {
  2684. // if ( COM_ParseString( &p, &value ) )
  2685. // {
  2686. // continue;
  2687. // }
  2688. // NPC->client->race = TranslateRaceName(value);
  2689. // continue;
  2690. // }
  2691. // rank
  2692. if ( !Q_stricmp( token, "rank" ) )
  2693. {
  2694. if ( COM_ParseString( &p, &value ) )
  2695. {
  2696. continue;
  2697. }
  2698. if ( NPC->NPC )
  2699. {
  2700. NPC->NPC->rank = TranslateRankName(value);
  2701. }
  2702. continue;
  2703. }
  2704. }
  2705. // health
  2706. if ( !Q_stricmp( token, "health" ) )
  2707. {
  2708. if ( COM_ParseInt( &p, &n ) )
  2709. {
  2710. SkipRestOfLine( &p );
  2711. continue;
  2712. }
  2713. if ( n < 0 )
  2714. {
  2715. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2716. continue;
  2717. }
  2718. if ( NPC->NPC )
  2719. {
  2720. stats->health = n;
  2721. }
  2722. else if ( parsingPlayer )
  2723. {
  2724. NPC->client->ps.stats[STAT_MAX_HEALTH] = NPC->client->pers.maxHealth = NPC->max_health = n;
  2725. }
  2726. continue;
  2727. }
  2728. // fullName
  2729. if ( !Q_stricmp( token, "fullName" ) )
  2730. {
  2731. #ifndef FINAL_BUILD
  2732. gi.Printf( S_COLOR_YELLOW"WARNING: fullname ignored in NPC '%s'\n", NPCName );
  2733. #endif
  2734. if ( COM_ParseString( &p, &value ) )
  2735. {
  2736. continue;
  2737. }
  2738. continue;
  2739. }
  2740. // playerTeam
  2741. if ( !Q_stricmp( token, "playerTeam" ) )
  2742. {
  2743. if ( COM_ParseString( &p, &value ) )
  2744. {
  2745. continue;
  2746. }
  2747. NPC->client->playerTeam = (team_t)GetIDForString( TeamTable, value );
  2748. continue;
  2749. }
  2750. // enemyTeam
  2751. if ( !Q_stricmp( token, "enemyTeam" ) )
  2752. {
  2753. if ( COM_ParseString( &p, &value ) )
  2754. {
  2755. continue;
  2756. }
  2757. NPC->client->enemyTeam = (team_t)GetIDForString( TeamTable, value );
  2758. continue;
  2759. }
  2760. // class
  2761. if ( !Q_stricmp( token, "class" ) )
  2762. {
  2763. if ( COM_ParseString( &p, &value ) )
  2764. {
  2765. continue;
  2766. }
  2767. NPC->client->NPC_class = (class_t)GetIDForString( ClassTable, value );
  2768. // No md3's for vehicles.
  2769. if ( NPC->client->NPC_class == CLASS_VEHICLE )
  2770. {
  2771. if ( !NPC->m_pVehicle )
  2772. {//you didn't spawn this guy right!
  2773. Com_Printf ( S_COLOR_RED "ERROR: Tried to spawn a vehicle NPC (%s) without using NPC_Vehicle or 'NPC spawn vehicle <vehiclename>'!!! Bad, bad, bad! Shame on you!\n", NPCName );
  2774. return qfalse;
  2775. }
  2776. md3Model = qfalse;
  2777. }
  2778. continue;
  2779. }
  2780. // dismemberment probability for head
  2781. if ( !Q_stricmp( token, "dismemberProbHead" ) ) {
  2782. if ( COM_ParseInt( &p, &n ) ) {
  2783. SkipRestOfLine( &p );
  2784. continue;
  2785. }
  2786. if ( n < 0 )
  2787. {
  2788. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2789. continue;
  2790. }
  2791. if ( NPC->NPC )
  2792. {
  2793. NPC->client->dismemberProbHead = n;
  2794. }
  2795. continue;
  2796. }
  2797. // dismemberment probability for arms
  2798. if ( !Q_stricmp( token, "dismemberProbArms" ) ) {
  2799. if ( COM_ParseInt( &p, &n ) ) {
  2800. SkipRestOfLine( &p );
  2801. continue;
  2802. }
  2803. if ( n < 0 )
  2804. {
  2805. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2806. continue;
  2807. }
  2808. if ( NPC->NPC )
  2809. {
  2810. NPC->client->dismemberProbArms = n;
  2811. }
  2812. continue;
  2813. }
  2814. // dismemberment probability for hands
  2815. if ( !Q_stricmp( token, "dismemberProbHands" ) ) {
  2816. if ( COM_ParseInt( &p, &n ) ) {
  2817. SkipRestOfLine( &p );
  2818. continue;
  2819. }
  2820. if ( n < 0 )
  2821. {
  2822. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2823. continue;
  2824. }
  2825. if ( NPC->NPC )
  2826. {
  2827. NPC->client->dismemberProbHands = n;
  2828. }
  2829. continue;
  2830. }
  2831. // dismemberment probability for waist
  2832. if ( !Q_stricmp( token, "dismemberProbWaist" ) ) {
  2833. if ( COM_ParseInt( &p, &n ) ) {
  2834. SkipRestOfLine( &p );
  2835. continue;
  2836. }
  2837. if ( n < 0 )
  2838. {
  2839. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2840. continue;
  2841. }
  2842. if ( NPC->NPC )
  2843. {
  2844. NPC->client->dismemberProbWaist = n;
  2845. }
  2846. continue;
  2847. }
  2848. // dismemberment probability for legs
  2849. if ( !Q_stricmp( token, "dismemberProbLegs" ) ) {
  2850. if ( COM_ParseInt( &p, &n ) ) {
  2851. SkipRestOfLine( &p );
  2852. continue;
  2853. }
  2854. if ( n < 0 )
  2855. {
  2856. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2857. continue;
  2858. }
  2859. if ( NPC->NPC )
  2860. {
  2861. NPC->client->dismemberProbLegs = n;
  2862. }
  2863. continue;
  2864. }
  2865. //===MOVEMENT STATS============================================================
  2866. if ( !Q_stricmp( token, "width" ) )
  2867. {
  2868. if ( COM_ParseInt( &p, &n ) )
  2869. {
  2870. continue;
  2871. }
  2872. NPC->mins[0] = NPC->mins[1] = -n;
  2873. NPC->maxs[0] = NPC->maxs[1] = n;
  2874. continue;
  2875. }
  2876. if ( !Q_stricmp( token, "height" ) )
  2877. {
  2878. if ( COM_ParseInt( &p, &n ) )
  2879. {
  2880. continue;
  2881. }
  2882. if ( NPC->client->NPC_class == CLASS_VEHICLE
  2883. && NPC->m_pVehicle
  2884. && NPC->m_pVehicle->m_pVehicleInfo
  2885. && NPC->m_pVehicle->m_pVehicleInfo->type == VH_FIGHTER )
  2886. {//a flying vehicle's origin must be centered in bbox
  2887. NPC->maxs[2] = NPC->client->standheight = (n/2.0f);
  2888. NPC->mins[2] = -NPC->maxs[2];
  2889. NPC->s.origin[2] += (DEFAULT_MINS_2-NPC->mins[2])+0.125f;
  2890. VectorCopy(NPC->s.origin, NPC->client->ps.origin);
  2891. VectorCopy(NPC->s.origin, NPC->currentOrigin);
  2892. G_SetOrigin( NPC, NPC->s.origin );
  2893. gi.linkentity(NPC);
  2894. }
  2895. else
  2896. {
  2897. NPC->mins[2] = DEFAULT_MINS_2;//Cannot change
  2898. NPC->maxs[2] = NPC->client->standheight = n + DEFAULT_MINS_2;
  2899. }
  2900. NPC->s.radius = n;
  2901. continue;
  2902. }
  2903. if ( !Q_stricmp( token, "crouchheight" ) )
  2904. {
  2905. if ( COM_ParseInt( &p, &n ) )
  2906. {
  2907. continue;
  2908. }
  2909. NPC->client->crouchheight = n + DEFAULT_MINS_2;
  2910. continue;
  2911. }
  2912. if ( !parsingPlayer )
  2913. {
  2914. if ( !Q_stricmp( token, "movetype" ) )
  2915. {
  2916. if ( COM_ParseString( &p, &value ) )
  2917. {
  2918. continue;
  2919. }
  2920. NPC->client->moveType = (movetype_t)MoveTypeNameToEnum(value);
  2921. continue;
  2922. }
  2923. // yawSpeed
  2924. if ( !Q_stricmp( token, "yawSpeed" ) ) {
  2925. if ( COM_ParseInt( &p, &n ) ) {
  2926. SkipRestOfLine( &p );
  2927. continue;
  2928. }
  2929. if ( n <= 0) {
  2930. gi.Printf( "bad %s in NPC '%s'\n", token, NPCName );
  2931. continue;
  2932. }
  2933. if ( NPC->NPC )
  2934. {
  2935. stats->yawSpeed = ((float)(n));
  2936. }
  2937. continue;
  2938. }
  2939. // walkSpeed
  2940. if ( !Q_stricmp( token, "walkSpeed" ) )
  2941. {
  2942. if ( COM_ParseInt( &p, &n ) )
  2943. {
  2944. SkipRestOfLine( &p );
  2945. continue;
  2946. }
  2947. if ( n < 0 )
  2948. {
  2949. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2950. continue;
  2951. }
  2952. if ( NPC->NPC )
  2953. {
  2954. stats->walkSpeed = n;
  2955. }
  2956. continue;
  2957. }
  2958. //runSpeed
  2959. if ( !Q_stricmp( token, "runSpeed" ) )
  2960. {
  2961. if ( COM_ParseInt( &p, &n ) )
  2962. {
  2963. SkipRestOfLine( &p );
  2964. continue;
  2965. }
  2966. if ( n < 0 )
  2967. {
  2968. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2969. continue;
  2970. }
  2971. if ( NPC->NPC )
  2972. {
  2973. stats->runSpeed = n;
  2974. }
  2975. continue;
  2976. }
  2977. //acceleration
  2978. if ( !Q_stricmp( token, "acceleration" ) )
  2979. {
  2980. if ( COM_ParseInt( &p, &n ) )
  2981. {
  2982. SkipRestOfLine( &p );
  2983. continue;
  2984. }
  2985. if ( n < 0 )
  2986. {
  2987. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  2988. continue;
  2989. }
  2990. if ( NPC->NPC )
  2991. {
  2992. stats->acceleration = n;
  2993. }
  2994. continue;
  2995. }
  2996. //sex
  2997. if ( !Q_stricmp( token, "sex" ) )
  2998. {
  2999. if ( COM_ParseString( &p, &value ) )
  3000. {
  3001. SkipRestOfLine( &p );
  3002. continue;
  3003. }
  3004. if ( value[0] == 'm' )
  3005. {//male
  3006. stats->sex = SEX_MALE;
  3007. }
  3008. else if ( value[0] == 'n' )
  3009. {//neutral
  3010. stats->sex = SEX_NEUTRAL;
  3011. }
  3012. else if ( value[0] == 'a' )
  3013. {//asexual?
  3014. stats->sex = SEX_NEUTRAL;
  3015. }
  3016. else if ( value[0] == 'f' )
  3017. {//female
  3018. stats->sex = SEX_FEMALE;
  3019. }
  3020. else if ( value[0] == 's' )
  3021. {//shemale?
  3022. stats->sex = SEX_SHEMALE;
  3023. }
  3024. else if ( value[0] == 'h' )
  3025. {//hermaphrodite?
  3026. stats->sex = SEX_SHEMALE;
  3027. }
  3028. else if ( value[0] == 't' )
  3029. {//transsexual/transvestite?
  3030. stats->sex = SEX_SHEMALE;
  3031. }
  3032. continue;
  3033. }
  3034. //===MISC===============================================================================
  3035. // default behavior
  3036. if ( !Q_stricmp( token, "behavior" ) )
  3037. {
  3038. if ( COM_ParseInt( &p, &n ) )
  3039. {
  3040. SkipRestOfLine( &p );
  3041. continue;
  3042. }
  3043. if ( n < BS_DEFAULT || n >= NUM_BSTATES )
  3044. {
  3045. gi.Printf( S_COLOR_YELLOW"WARNING: bad %s in NPC '%s'\n", token, NPCName );
  3046. continue;
  3047. }
  3048. if ( NPC->NPC )
  3049. {
  3050. NPC->NPC->defaultBehavior = (bState_t)(n);
  3051. }
  3052. continue;
  3053. }
  3054. }
  3055. // snd
  3056. if ( !Q_stricmp( token, "snd" ) )
  3057. {
  3058. if ( COM_ParseString( &p, &value ) )
  3059. {
  3060. continue;
  3061. }
  3062. if ( !(NPC->svFlags&SVF_NO_BASIC_SOUNDS) )
  3063. {
  3064. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  3065. Q_strncpyz( sound, value, sizeof( sound ) );
  3066. patch = strstr( sound, "/" );
  3067. if ( patch )
  3068. {
  3069. *patch = 0;
  3070. }
  3071. ci->customBasicSoundDir = G_NewString( sound );
  3072. }
  3073. continue;
  3074. }
  3075. // sndcombat
  3076. if ( !Q_stricmp( token, "sndcombat" ) )
  3077. {
  3078. if ( COM_ParseString( &p, &value ) )
  3079. {
  3080. continue;
  3081. }
  3082. if ( !(NPC->svFlags&SVF_NO_COMBAT_SOUNDS) )
  3083. {
  3084. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  3085. Q_strncpyz( sound, value, sizeof( sound ) );
  3086. patch = strstr( sound, "/" );
  3087. if ( patch )
  3088. {
  3089. *patch = 0;
  3090. }
  3091. ci->customCombatSoundDir = G_NewString( sound );
  3092. }
  3093. continue;
  3094. }
  3095. // sndextra
  3096. if ( !Q_stricmp( token, "sndextra" ) )
  3097. {
  3098. if ( COM_ParseString( &p, &value ) )
  3099. {
  3100. continue;
  3101. }
  3102. if ( !(NPC->svFlags&SVF_NO_EXTRA_SOUNDS) )
  3103. {
  3104. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  3105. Q_strncpyz( sound, value, sizeof( sound ) );
  3106. patch = strstr( sound, "/" );
  3107. if ( patch )
  3108. {
  3109. *patch = 0;
  3110. }
  3111. ci->customExtraSoundDir = G_NewString( sound );
  3112. }
  3113. continue;
  3114. }
  3115. // sndjedi
  3116. if ( !Q_stricmp( token, "sndjedi" ) )
  3117. {
  3118. if ( COM_ParseString( &p, &value ) )
  3119. {
  3120. continue;
  3121. }
  3122. if ( !(NPC->svFlags&SVF_NO_EXTRA_SOUNDS) )
  3123. {
  3124. //FIXME: store this in some sound field or parse in the soundTable like the animTable...
  3125. Q_strncpyz( sound, value, sizeof( sound ) );
  3126. patch = strstr( sound, "/" );
  3127. if ( patch )
  3128. {
  3129. *patch = 0;
  3130. }
  3131. ci->customJediSoundDir = G_NewString( sound );
  3132. }
  3133. continue;
  3134. }
  3135. //New NPC/jedi stats:
  3136. //starting weapon
  3137. if ( !Q_stricmp( token, "weapon" ) )
  3138. {
  3139. if ( COM_ParseString( &p, &value ) )
  3140. {
  3141. continue;
  3142. }
  3143. //FIXME: need to precache the weapon, too? (in above func)
  3144. int weap = GetIDForString( WPTable, value );
  3145. if ( weap >= WP_NONE && weap < WP_NUM_WEAPONS )
  3146. {
  3147. NPC->client->ps.weapon = weap;
  3148. NPC->client->ps.stats[STAT_WEAPONS] |= ( 1 << weap );
  3149. if ( weap > WP_NONE )
  3150. {
  3151. RegisterItem( FindItemForWeapon( (weapon_t)(weap) ) ); //precache the weapon
  3152. NPC->client->ps.ammo[weaponData[weap].ammoIndex] = ammoData[weaponData[weap].ammoIndex].max;
  3153. }
  3154. }
  3155. continue;
  3156. }
  3157. if ( !parsingPlayer )
  3158. {
  3159. //altFire
  3160. if ( !Q_stricmp( token, "altFire" ) )
  3161. {
  3162. if ( COM_ParseInt( &p, &n ) )
  3163. {
  3164. SkipRestOfLine( &p );
  3165. continue;
  3166. }
  3167. if ( NPC->NPC )
  3168. {
  3169. if ( n != 0 )
  3170. {
  3171. NPC->NPC->scriptFlags |= SCF_ALT_FIRE;
  3172. }
  3173. }
  3174. continue;
  3175. }
  3176. //Other unique behaviors/numbers that are currently hardcoded?
  3177. }
  3178. //force powers
  3179. int fp = GetIDForString( FPTable, token );
  3180. if ( fp >= FP_FIRST && fp < NUM_FORCE_POWERS )
  3181. {
  3182. if ( COM_ParseInt( &p, &n ) )
  3183. {
  3184. SkipRestOfLine( &p );
  3185. continue;
  3186. }
  3187. //FIXME: need to precache the fx, too? (in above func)
  3188. //cap
  3189. if ( n > 5 )
  3190. {
  3191. n = 5;
  3192. }
  3193. else if ( n < 0 )
  3194. {
  3195. n = 0;
  3196. }
  3197. if ( n )
  3198. {//set
  3199. NPC->client->ps.forcePowersKnown |= ( 1 << fp );
  3200. }
  3201. else
  3202. {//clear
  3203. NPC->client->ps.forcePowersKnown &= ~( 1 << fp );
  3204. }
  3205. NPC->client->ps.forcePowerLevel[fp] = n;
  3206. continue;
  3207. }
  3208. //max force power
  3209. if ( !Q_stricmp( token, "forcePowerMax" ) )
  3210. {
  3211. if ( COM_ParseInt( &p, &n ) )
  3212. {
  3213. SkipRestOfLine( &p );
  3214. continue;
  3215. }
  3216. NPC->client->ps.forcePowerMax = n;
  3217. continue;
  3218. }
  3219. //force regen rate - default is 100ms
  3220. if ( !Q_stricmp( token, "forceRegenRate" ) )
  3221. {
  3222. if ( COM_ParseInt( &p, &n ) )
  3223. {
  3224. SkipRestOfLine( &p );
  3225. continue;
  3226. }
  3227. NPC->client->ps.forcePowerRegenRate = n;
  3228. continue;
  3229. }
  3230. //force regen amount - default is 1 (points per second)
  3231. if ( !Q_stricmp( token, "forceRegenAmount" ) )
  3232. {
  3233. if ( COM_ParseInt( &p, &n ) )
  3234. {
  3235. SkipRestOfLine( &p );
  3236. continue;
  3237. }
  3238. NPC->client->ps.forcePowerRegenAmount = n;
  3239. continue;
  3240. }
  3241. //have a sabers.cfg and just name your saber in your NPCs.cfg/ICARUS script
  3242. //saber name
  3243. if ( !Q_stricmp( token, "saber" ) )
  3244. {
  3245. if ( COM_ParseString( &p, &value ) )
  3246. {
  3247. continue;
  3248. }
  3249. char *saberName = G_NewString( value );
  3250. WP_SaberParseParms( saberName, &NPC->client->ps.saber[0] );
  3251. //if it requires a specific style, make sure we know how to use it
  3252. if ( NPC->client->ps.saber[0].style )
  3253. {
  3254. NPC->client->ps.saberStylesKnown |= (1<<NPC->client->ps.saber[0].style);
  3255. }
  3256. continue;
  3257. }
  3258. //second saber name
  3259. if ( !Q_stricmp( token, "saber2" ) )
  3260. {
  3261. if ( COM_ParseString( &p, &value ) )
  3262. {
  3263. continue;
  3264. }
  3265. if ( !NPC->client->ps.saber[0].twoHanded )
  3266. {//can't use a second saber if first one is a two-handed saber...?
  3267. char *saberName = G_NewString( value );
  3268. WP_SaberParseParms( saberName, &NPC->client->ps.saber[1] );
  3269. if ( NPC->client->ps.saber[1].style )
  3270. {
  3271. NPC->client->ps.saberStylesKnown |= (1<<NPC->client->ps.saber[1].style);
  3272. }
  3273. if ( NPC->client->ps.saber[1].twoHanded )
  3274. {//tsk tsk, can't use a twoHanded saber as second saber
  3275. WP_RemoveSaber( NPC, 1 );
  3276. }
  3277. else
  3278. {
  3279. NPC->client->ps.dualSabers = qtrue;
  3280. }
  3281. }
  3282. continue;
  3283. }
  3284. // saberColor
  3285. if ( !Q_stricmpn( token, "saberColor", 10) )
  3286. {
  3287. if ( !NPC->client )
  3288. {
  3289. continue;
  3290. }
  3291. if (strlen(token)==10)
  3292. {
  3293. if ( COM_ParseString( &p, &value ) )
  3294. {
  3295. continue;
  3296. }
  3297. saber_colors_t color = TranslateSaberColor( value );
  3298. for ( n = 0; n < MAX_BLADES; n++ )
  3299. {
  3300. NPC->client->ps.saber[0].blade[n].color = color;
  3301. }
  3302. }
  3303. else if (strlen(token)==11)
  3304. {
  3305. int index = atoi(&token[10])-1;
  3306. if (index > 7 || index < 1 )
  3307. {
  3308. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberColor '%s' in %s\n", token, NPCName );
  3309. continue;
  3310. }
  3311. if ( COM_ParseString( &p, &value ) )
  3312. {
  3313. continue;
  3314. }
  3315. NPC->client->ps.saber[0].blade[index].color = TranslateSaberColor( value );
  3316. }
  3317. else
  3318. {
  3319. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberColor '%s' in %s\n", token, NPCName );
  3320. }
  3321. continue;
  3322. }
  3323. if ( !Q_stricmpn( token, "saber2Color", 11 ) )
  3324. {
  3325. if ( !NPC->client )
  3326. {
  3327. continue;
  3328. }
  3329. if (strlen(token)==11)
  3330. {
  3331. if ( COM_ParseString( &p, &value ) )
  3332. {
  3333. continue;
  3334. }
  3335. saber_colors_t color = TranslateSaberColor( value );
  3336. for ( n = 0; n < MAX_BLADES; n++ )
  3337. {
  3338. NPC->client->ps.saber[1].blade[n].color = color;
  3339. }
  3340. }
  3341. else if (strlen(token)==12)
  3342. {
  3343. n = atoi(&token[11])-1;
  3344. if (n > 7 || n < 1 )
  3345. {
  3346. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Color '%s' in %s\n", token, NPCName );
  3347. continue;
  3348. }
  3349. if ( COM_ParseString( &p, &value ) )
  3350. {
  3351. continue;
  3352. }
  3353. NPC->client->ps.saber[1].blade[n].color = TranslateSaberColor( value );
  3354. }
  3355. else
  3356. {
  3357. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Color '%s' in %s\n", token, NPCName );
  3358. }
  3359. continue;
  3360. }
  3361. //saber length
  3362. if ( !Q_stricmpn( token, "saberLength", 11) )
  3363. {
  3364. if (strlen(token)==11)
  3365. {
  3366. n = -1;
  3367. }
  3368. else if (strlen(token)==12)
  3369. {
  3370. n = atoi(&token[11])-1;
  3371. if (n > 7 || n < 1 )
  3372. {
  3373. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberLength '%s' in %s\n", token, NPCName );
  3374. continue;
  3375. }
  3376. }
  3377. else
  3378. {
  3379. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberLength '%s' in %s\n", token, NPCName );
  3380. continue;
  3381. }
  3382. if ( COM_ParseFloat( &p, &f ) )
  3383. {
  3384. SkipRestOfLine( &p );
  3385. continue;
  3386. }
  3387. //cap
  3388. if ( f < 4.0f )
  3389. {
  3390. f = 4.0f;
  3391. }
  3392. if (n == -1)//do them all
  3393. {
  3394. for ( n = 0; n < MAX_BLADES; n++ )
  3395. {
  3396. NPC->client->ps.saber[0].blade[n].lengthMax = f;
  3397. }
  3398. }
  3399. else //just one
  3400. {
  3401. NPC->client->ps.saber[0].blade[n].lengthMax = f;
  3402. }
  3403. continue;
  3404. }
  3405. if ( !Q_stricmpn( token, "saber2Length", 12) )
  3406. {
  3407. if (strlen(token)==12)
  3408. {
  3409. n = -1;
  3410. }
  3411. else if (strlen(token)==13)
  3412. {
  3413. n = atoi(&token[12])-1;
  3414. if (n > 7 || n < 1 )
  3415. {
  3416. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Length '%s' in %s\n", token, NPCName );
  3417. continue;
  3418. }
  3419. }
  3420. else
  3421. {
  3422. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Length '%s' in %s\n", token, NPCName );
  3423. continue;
  3424. }
  3425. if ( COM_ParseFloat( &p, &f ) )
  3426. {
  3427. SkipRestOfLine( &p );
  3428. continue;
  3429. }
  3430. //cap
  3431. if ( f < 4.0f )
  3432. {
  3433. f = 4.0f;
  3434. }
  3435. if (n == -1)//do them all
  3436. {
  3437. for ( n = 0; n < MAX_BLADES; n++ )
  3438. {
  3439. NPC->client->ps.saber[1].blade[n].lengthMax = f;
  3440. }
  3441. }
  3442. else //just one
  3443. {
  3444. NPC->client->ps.saber[1].blade[n].lengthMax = f;
  3445. }
  3446. continue;
  3447. }
  3448. //saber radius
  3449. if ( !Q_stricmpn( token, "saberRadius", 11 ) )
  3450. {
  3451. if (strlen(token)==11)
  3452. {
  3453. n = -1;
  3454. }
  3455. else if (strlen(token)==12)
  3456. {
  3457. n = atoi(&token[11])-1;
  3458. if (n > 7 || n < 1 )
  3459. {
  3460. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberRadius '%s' in %s\n", token, NPCName );
  3461. continue;
  3462. }
  3463. }
  3464. else
  3465. {
  3466. gi.Printf( S_COLOR_YELLOW"WARNING: bad saberRadius '%s' in %s\n", token, NPCName );
  3467. continue;
  3468. }
  3469. if ( COM_ParseFloat( &p, &f ) )
  3470. {
  3471. SkipRestOfLine( &p );
  3472. continue;
  3473. }
  3474. //cap
  3475. if ( f < 0.25f )
  3476. {
  3477. f = 0.25f;
  3478. }
  3479. if (n==-1)
  3480. {//NOTE: this fills in the rest of the blades with the same length by default
  3481. for ( n = 0; n < MAX_BLADES; n++ )
  3482. {
  3483. NPC->client->ps.saber[0].blade[n].radius = f;
  3484. }
  3485. }
  3486. else
  3487. {
  3488. NPC->client->ps.saber[0].blade[n].radius = f;
  3489. }
  3490. continue;
  3491. }
  3492. if ( !Q_stricmpn( token, "saber2Radius", 12 ) )
  3493. {
  3494. if (strlen(token)==12)
  3495. {
  3496. n = -1;
  3497. }
  3498. else if (strlen(token)==13)
  3499. {
  3500. n = atoi(&token[12])-1;
  3501. if (n > 7 || n < 1 )
  3502. {
  3503. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Radius '%s' in %s\n", token, NPCName );
  3504. continue;
  3505. }
  3506. }
  3507. else
  3508. {
  3509. gi.Printf( S_COLOR_YELLOW"WARNING: bad saber2Radius '%s' in %s\n", token, NPCName );
  3510. continue;
  3511. }
  3512. if ( COM_ParseFloat( &p, &f ) )
  3513. {
  3514. SkipRestOfLine( &p );
  3515. continue;
  3516. }
  3517. //cap
  3518. if ( f < 0.25f )
  3519. {
  3520. f = 0.25f;
  3521. }
  3522. if (n==-1)
  3523. {//NOTE: this fills in the rest of the blades with the same length by default
  3524. for ( n = 0; n < MAX_BLADES; n++ )
  3525. {
  3526. NPC->client->ps.saber[1].blade[n].radius = f;
  3527. }
  3528. }
  3529. else
  3530. {
  3531. NPC->client->ps.saber[1].blade[n].radius = f;
  3532. }
  3533. continue;
  3534. }
  3535. //ADD:
  3536. //saber sounds (on, off, loop)
  3537. //loop sound (like Vader's breathing or droid bleeps, etc.)
  3538. //starting saber style
  3539. if ( !Q_stricmp( token, "saberStyle" ) )
  3540. {
  3541. if ( COM_ParseInt( &p, &n ) )
  3542. {
  3543. SkipRestOfLine( &p );
  3544. continue;
  3545. }
  3546. //cap
  3547. if ( n > SS_STAFF )
  3548. {
  3549. n = SS_STAFF;
  3550. }
  3551. else if ( n < SS_FAST )
  3552. {
  3553. n = SS_FAST;
  3554. }
  3555. if ( n )
  3556. {//set
  3557. NPC->client->ps.saberStylesKnown |= ( 1 << n );
  3558. }
  3559. else
  3560. {//clear
  3561. NPC->client->ps.saberStylesKnown &= ~( 1 << n );
  3562. }
  3563. NPC->client->ps.saberAnimLevel = n;
  3564. if ( parsingPlayer )
  3565. {
  3566. cg.saberAnimLevelPending = n;
  3567. }
  3568. continue;
  3569. }
  3570. if ( !parsingPlayer )
  3571. {
  3572. gi.Printf( "WARNING: unknown keyword '%s' while parsing '%s'\n", token, NPCName );
  3573. }
  3574. SkipRestOfLine( &p );
  3575. }
  3576. }
  3577. ci->infoValid = qfalse;
  3578. /*
  3579. Ghoul2 Insert Start
  3580. */
  3581. if ( !md3Model )
  3582. {
  3583. NPC->weaponModel[0] = -1;
  3584. if ( Q_stricmp( "player", playerModel ) == 0 )
  3585. {//set the model from the console cvars
  3586. G_InitPlayerFromCvars( NPC );
  3587. //now set the weapon, etc.
  3588. G_MatchPlayerWeapon( NPC );
  3589. //NPC->NPC->aiFlags |= NPCAI_MATCHPLAYERWEAPON;//FIXME: may not always want this
  3590. }
  3591. else
  3592. {//do a normal model load
  3593. // If this is a vehicle, set the model name from the vehicle type array.
  3594. if ( NPC->client->NPC_class == CLASS_VEHICLE )
  3595. {
  3596. int iVehIndex = BG_VehicleGetIndex( NPC->NPC_type );
  3597. strcpy(customSkin, "default"); // Ignore any custom skin that may have come from the NPC File
  3598. Q_strncpyz( playerModel, g_vehicleInfo[iVehIndex].model, sizeof(playerModel), qtrue);
  3599. if ( g_vehicleInfo[iVehIndex].skin && g_vehicleInfo[iVehIndex].skin[0] )
  3600. {
  3601. bool forceSkin = false;
  3602. // Iterate Over All Possible Skins
  3603. //---------------------------------
  3604. ratl::vector_vs<hstring, 15> skinarray;
  3605. ratl::string_vs<256> skins(g_vehicleInfo[iVehIndex].skin);
  3606. for (ratl::string_vs<256>::tokenizer i = skins.begin("|"); i!=skins.end(); i++)
  3607. {
  3608. if (NPC->soundSet && NPC->soundSet[0] && Q_stricmp(*i, NPC->soundSet)==0)
  3609. {
  3610. forceSkin = true;
  3611. }
  3612. skinarray.push_back(*i);
  3613. }
  3614. // Soundset Is The Designer Set Way To Supply A Skin
  3615. //---------------------------------------------------
  3616. if (forceSkin)
  3617. {
  3618. Q_strncpyz( customSkin, NPC->soundSet, sizeof(customSkin), qtrue);
  3619. }
  3620. // Otherwise Choose A Random Skin
  3621. //--------------------------------
  3622. else
  3623. {
  3624. if (NPC->soundSet && NPC->soundSet[0])
  3625. {
  3626. gi.Printf(S_COLOR_RED"WARNING: Unable to use skin (%s)", NPC->soundSet);
  3627. }
  3628. Q_strncpyz( customSkin, *skinarray[Q_irand(0, skinarray.size()-1)], sizeof(customSkin), qtrue);
  3629. }
  3630. if (NPC->soundSet && gi.bIsFromZone(NPC->soundSet, TAG_G_ALLOC)) {
  3631. gi.Free(NPC->soundSet);
  3632. }
  3633. NPC->soundSet = 0; // clear the pointer
  3634. }
  3635. }
  3636. G_SetG2PlayerModel( NPC, playerModel, customSkin, surfOff, surfOn );
  3637. }
  3638. }
  3639. /*
  3640. Ghoul2 Insert End
  3641. */
  3642. if( NPCsPrecached )
  3643. {//Spawning in after initial precache, our models are precached, we just need to set our clientInfo
  3644. CG_RegisterClientModels( NPC->s.number );
  3645. CG_RegisterNPCCustomSounds( ci );
  3646. //CG_RegisterNPCEffects( NPC->client->playerTeam );
  3647. }
  3648. return qtrue;
  3649. }
  3650. void NPC_LoadParms( void )
  3651. {
  3652. int len, totallen, npcExtFNLen, fileCnt, i;
  3653. char *buffer, *holdChar, *marker;
  3654. char npcExtensionListBuf[2048]; // The list of file names read in
  3655. //gi.Printf( "Parsing ext_data/npcs/*.npc definitions\n" );
  3656. //set where to store the first one
  3657. totallen = 0;
  3658. marker = NPCParms;
  3659. marker[0] = '\0';
  3660. //now load in the .npc definitions
  3661. fileCnt = gi.FS_GetFileList("ext_data/npcs", ".npc", npcExtensionListBuf, sizeof(npcExtensionListBuf) );
  3662. holdChar = npcExtensionListBuf;
  3663. for ( i = 0; i < fileCnt; i++, holdChar += npcExtFNLen + 1 )
  3664. {
  3665. npcExtFNLen = strlen( holdChar );
  3666. //gi.Printf( "Parsing %s\n", holdChar );
  3667. len = gi.FS_ReadFile( va( "ext_data/npcs/%s", holdChar), (void **) &buffer );
  3668. if ( len == -1 )
  3669. {
  3670. gi.Printf( "NPC_LoadParms: error reading file %s\n", holdChar );
  3671. }
  3672. else
  3673. {
  3674. if ( totallen && *(marker-1) == '}' )
  3675. {//don't let previous file end on a } because that must be a stand-alone token
  3676. strcat( marker, " " );
  3677. totallen++;
  3678. marker++;
  3679. }
  3680. len = COM_Compress( buffer );
  3681. if ( totallen + len >= MAX_NPC_DATA_SIZE ) {
  3682. G_Error( "NPC_LoadParms: ran out of space before reading %s\n(you must make the .npc files smaller)", holdChar );
  3683. }
  3684. strcat( marker, buffer );
  3685. gi.FS_FreeFile( buffer );
  3686. totallen += len;
  3687. marker += len;
  3688. }
  3689. }
  3690. }