p_weapon.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. // g_weapon.c
  4. #include "g_local.h"
  5. #include "m_player.h"
  6. static qboolean is_quad;
  7. static byte is_silenced;
  8. //PGM
  9. static byte damage_multiplier;
  10. //PGM
  11. void weapon_grenade_fire (edict_t *ent, qboolean held);
  12. //========
  13. //ROGUE
  14. byte P_DamageModifier(edict_t *ent)
  15. {
  16. is_quad = 0;
  17. damage_multiplier = 1;
  18. if(ent->client->quad_framenum > level.framenum)
  19. {
  20. damage_multiplier *= 4;
  21. is_quad = 1;
  22. // if we're quad and DF_NO_STACK_DOUBLE is on, return now.
  23. if(((int)(dmflags->value) & DF_NO_STACK_DOUBLE))
  24. return damage_multiplier;
  25. }
  26. if(ent->client->double_framenum > level.framenum)
  27. {
  28. if ((deathmatch->value) || (damage_multiplier == 1))
  29. {
  30. damage_multiplier *= 2;
  31. is_quad = 1;
  32. }
  33. }
  34. return damage_multiplier;
  35. }
  36. //ROGUE
  37. //========
  38. static void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
  39. {
  40. vec3_t _distance;
  41. VectorCopy (distance, _distance);
  42. if (client->pers.hand == LEFT_HANDED)
  43. _distance[1] *= -1;
  44. else if (client->pers.hand == CENTER_HANDED)
  45. _distance[1] = 0;
  46. G_ProjectSource (point, _distance, forward, right, result);
  47. }
  48. static void P_ProjectSource2 (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward,
  49. vec3_t right, vec3_t up, vec3_t result)
  50. {
  51. vec3_t _distance;
  52. VectorCopy (distance, _distance);
  53. if (client->pers.hand == LEFT_HANDED)
  54. _distance[1] *= -1;
  55. else if (client->pers.hand == CENTER_HANDED)
  56. _distance[1] = 0;
  57. G_ProjectSource2 (point, _distance, forward, right, up, result);
  58. }
  59. /*
  60. ===============
  61. PlayerNoise
  62. Each player can have two noise objects associated with it:
  63. a personal noise (jumping, pain, weapon firing), and a weapon
  64. target noise (bullet wall impacts)
  65. Monsters that don't directly see the player can move
  66. to a noise in hopes of seeing the player from there.
  67. ===============
  68. */
  69. void PlayerNoise(edict_t *who, vec3_t where, int type)
  70. {
  71. edict_t *noise;
  72. if (type == PNOISE_WEAPON)
  73. {
  74. if (who->client->silencer_shots)
  75. {
  76. who->client->silencer_shots--;
  77. return;
  78. }
  79. }
  80. if (deathmatch->value)
  81. return;
  82. if (who->flags & FL_NOTARGET)
  83. return;
  84. if (who->flags & FL_DISGUISED)
  85. {
  86. if (type == PNOISE_WEAPON)
  87. {
  88. level.disguise_violator = who;
  89. level.disguise_violation_framenum = level.framenum + 5;
  90. }
  91. else
  92. return;
  93. }
  94. if (!who->mynoise)
  95. {
  96. noise = G_Spawn();
  97. noise->classname = "player_noise";
  98. VectorSet (noise->mins, -8, -8, -8);
  99. VectorSet (noise->maxs, 8, 8, 8);
  100. noise->owner = who;
  101. noise->svflags = SVF_NOCLIENT;
  102. who->mynoise = noise;
  103. noise = G_Spawn();
  104. noise->classname = "player_noise";
  105. VectorSet (noise->mins, -8, -8, -8);
  106. VectorSet (noise->maxs, 8, 8, 8);
  107. noise->owner = who;
  108. noise->svflags = SVF_NOCLIENT;
  109. who->mynoise2 = noise;
  110. }
  111. if (type == PNOISE_SELF || type == PNOISE_WEAPON)
  112. {
  113. noise = who->mynoise;
  114. level.sound_entity = noise;
  115. level.sound_entity_framenum = level.framenum;
  116. }
  117. else // type == PNOISE_IMPACT
  118. {
  119. noise = who->mynoise2;
  120. level.sound2_entity = noise;
  121. level.sound2_entity_framenum = level.framenum;
  122. }
  123. VectorCopy (where, noise->s.origin);
  124. VectorSubtract (where, noise->maxs, noise->absmin);
  125. VectorAdd (where, noise->maxs, noise->absmax);
  126. noise->teleport_time = level.time;
  127. gi.linkentity (noise);
  128. }
  129. qboolean Pickup_Weapon (edict_t *ent, edict_t *other)
  130. {
  131. int index;
  132. gitem_t *ammo;
  133. index = ITEM_INDEX(ent->item);
  134. if ( ( ((int)(dmflags->value) & DF_WEAPONS_STAY) || coop->value)
  135. && other->client->pers.inventory[index])
  136. {
  137. if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM) ) )
  138. return false; // leave the weapon for others to pickup
  139. }
  140. other->client->pers.inventory[index]++;
  141. if (!(ent->spawnflags & DROPPED_ITEM) )
  142. {
  143. // give them some ammo with it
  144. // PGM -- IF APPROPRIATE!
  145. if(ent->item->ammo) //PGM
  146. {
  147. ammo = FindItem (ent->item->ammo);
  148. if ( (int)dmflags->value & DF_INFINITE_AMMO )
  149. Add_Ammo (other, ammo, 1000);
  150. else
  151. Add_Ammo (other, ammo, ammo->quantity);
  152. }
  153. if (! (ent->spawnflags & DROPPED_PLAYER_ITEM) )
  154. {
  155. if (deathmatch->value)
  156. {
  157. if ((int)(dmflags->value) & DF_WEAPONS_STAY)
  158. ent->flags |= FL_RESPAWN;
  159. else
  160. SetRespawn (ent, 30);
  161. }
  162. if (coop->value)
  163. ent->flags |= FL_RESPAWN;
  164. }
  165. }
  166. if (other->client->pers.weapon != ent->item &&
  167. (other->client->pers.inventory[index] == 1) &&
  168. ( !deathmatch->value || other->client->pers.weapon == FindItem("blaster") ) )
  169. other->client->newweapon = ent->item;
  170. return true;
  171. }
  172. /*
  173. ===============
  174. ChangeWeapon
  175. The old weapon has been dropped all the way, so make the new one
  176. current
  177. ===============
  178. */
  179. void ChangeWeapon (edict_t *ent)
  180. {
  181. int i;
  182. if (ent->client->grenade_time)
  183. {
  184. ent->client->grenade_time = level.time;
  185. ent->client->weapon_sound = 0;
  186. weapon_grenade_fire (ent, false);
  187. ent->client->grenade_time = 0;
  188. }
  189. ent->client->pers.lastweapon = ent->client->pers.weapon;
  190. ent->client->pers.weapon = ent->client->newweapon;
  191. ent->client->newweapon = NULL;
  192. ent->client->machinegun_shots = 0;
  193. // set visible model
  194. if (ent->s.modelindex == 255)
  195. {
  196. if (ent->client->pers.weapon)
  197. i = ((ent->client->pers.weapon->weapmodel & 0xff) << 8);
  198. else
  199. i = 0;
  200. ent->s.skinnum = (ent - g_edicts - 1) | i;
  201. }
  202. if (ent->client->pers.weapon && ent->client->pers.weapon->ammo)
  203. ent->client->ammo_index = ITEM_INDEX(FindItem(ent->client->pers.weapon->ammo));
  204. else
  205. ent->client->ammo_index = 0;
  206. if (!ent->client->pers.weapon)
  207. { // dead
  208. ent->client->ps.gunindex = 0;
  209. return;
  210. }
  211. ent->client->weaponstate = WEAPON_ACTIVATING;
  212. ent->client->ps.gunframe = 0;
  213. ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);
  214. ent->client->anim_priority = ANIM_PAIN;
  215. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  216. {
  217. ent->s.frame = FRAME_crpain1;
  218. ent->client->anim_end = FRAME_crpain4;
  219. }
  220. else
  221. {
  222. ent->s.frame = FRAME_pain301;
  223. ent->client->anim_end = FRAME_pain304;
  224. }
  225. }
  226. /*
  227. =================
  228. NoAmmoWeaponChange
  229. =================
  230. */
  231. // PMM - added rogue weapons to the list
  232. void NoAmmoWeaponChange (edict_t *ent)
  233. {
  234. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("slugs"))]
  235. && ent->client->pers.inventory[ITEM_INDEX(FindItem("railgun"))] )
  236. {
  237. ent->client->newweapon = FindItem ("railgun");
  238. return;
  239. }
  240. // ROGUE
  241. if ( (ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))] >= 2)
  242. && ent->client->pers.inventory[ITEM_INDEX(FindItem("Plasma Beam"))] )
  243. {
  244. ent->client->newweapon = FindItem ("Plasma Beam");
  245. return;
  246. }
  247. // -ROGUE
  248. /*
  249. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))]
  250. && ent->client->pers.inventory[ITEM_INDEX(FindItem("hyperblaster"))] )
  251. {
  252. ent->client->newweapon = FindItem ("hyperblaster");
  253. return;
  254. }
  255. */
  256. // ROGUE
  257. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("flechettes"))]
  258. && ent->client->pers.inventory[ITEM_INDEX(FindItem("etf rifle"))] )
  259. {
  260. ent->client->newweapon = FindItem ("etf rifle");
  261. return;
  262. }
  263. // -ROGUE
  264. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
  265. && ent->client->pers.inventory[ITEM_INDEX(FindItem("chaingun"))] )
  266. {
  267. ent->client->newweapon = FindItem ("chaingun");
  268. return;
  269. }
  270. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
  271. && ent->client->pers.inventory[ITEM_INDEX(FindItem("machinegun"))] )
  272. {
  273. ent->client->newweapon = FindItem ("machinegun");
  274. return;
  275. }
  276. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))] > 1
  277. && ent->client->pers.inventory[ITEM_INDEX(FindItem("super shotgun"))] )
  278. {
  279. ent->client->newweapon = FindItem ("super shotgun");
  280. return;
  281. }
  282. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))]
  283. && ent->client->pers.inventory[ITEM_INDEX(FindItem("shotgun"))] )
  284. {
  285. ent->client->newweapon = FindItem ("shotgun");
  286. return;
  287. }
  288. ent->client->newweapon = FindItem ("blaster");
  289. }
  290. /*
  291. =================
  292. Think_Weapon
  293. Called by ClientBeginServerFrame and ClientThink
  294. =================
  295. */
  296. void Think_Weapon (edict_t *ent)
  297. {
  298. // if just died, put the weapon away
  299. if (ent->health < 1)
  300. {
  301. ent->client->newweapon = NULL;
  302. ChangeWeapon (ent);
  303. }
  304. // call active weapon think routine
  305. if (ent->client->pers.weapon && ent->client->pers.weapon->weaponthink)
  306. {
  307. //PGM
  308. P_DamageModifier(ent);
  309. // is_quad = (ent->client->quad_framenum > level.framenum);
  310. //PGM
  311. if (ent->client->silencer_shots)
  312. is_silenced = MZ_SILENCED;
  313. else
  314. is_silenced = 0;
  315. ent->client->pers.weapon->weaponthink (ent);
  316. }
  317. }
  318. /*
  319. ================
  320. Use_Weapon
  321. Make the weapon ready if there is ammo
  322. ================
  323. */
  324. void Use_Weapon (edict_t *ent, gitem_t *item)
  325. {
  326. int ammo_index;
  327. gitem_t *ammo_item;
  328. // see if we're already using it
  329. if (item == ent->client->pers.weapon)
  330. return;
  331. if (item->ammo && !g_select_empty->value && !(item->flags & IT_AMMO))
  332. {
  333. ammo_item = FindItem(item->ammo);
  334. ammo_index = ITEM_INDEX(ammo_item);
  335. if (!ent->client->pers.inventory[ammo_index])
  336. {
  337. gi.cprintf (ent, PRINT_HIGH, "No %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
  338. return;
  339. }
  340. if (ent->client->pers.inventory[ammo_index] < item->quantity)
  341. {
  342. gi.cprintf (ent, PRINT_HIGH, "Not enough %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
  343. return;
  344. }
  345. }
  346. // change to this weapon when down
  347. ent->client->newweapon = item;
  348. }
  349. /*
  350. ================
  351. Drop_Weapon
  352. ================
  353. */
  354. void Drop_Weapon (edict_t *ent, gitem_t *item)
  355. {
  356. int index;
  357. if ((int)(dmflags->value) & DF_WEAPONS_STAY)
  358. return;
  359. index = ITEM_INDEX(item);
  360. // see if we're already using it
  361. if ( ((item == ent->client->pers.weapon) || (item == ent->client->newweapon))&& (ent->client->pers.inventory[index] == 1) )
  362. {
  363. gi.cprintf (ent, PRINT_HIGH, "Can't drop current weapon\n");
  364. return;
  365. }
  366. Drop_Item (ent, item);
  367. ent->client->pers.inventory[index]--;
  368. }
  369. /*
  370. ================
  371. Weapon_Generic
  372. A generic function to handle the basics of weapon thinking
  373. ================
  374. */
  375. #define FRAME_FIRE_FIRST (FRAME_ACTIVATE_LAST + 1)
  376. #define FRAME_IDLE_FIRST (FRAME_FIRE_LAST + 1)
  377. #define FRAME_DEACTIVATE_FIRST (FRAME_IDLE_LAST + 1)
  378. void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
  379. {
  380. int n;
  381. if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
  382. {
  383. return;
  384. }
  385. if (ent->client->weaponstate == WEAPON_DROPPING)
  386. {
  387. if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST)
  388. {
  389. ChangeWeapon (ent);
  390. return;
  391. }
  392. else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4)
  393. {
  394. ent->client->anim_priority = ANIM_REVERSE;
  395. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  396. {
  397. ent->s.frame = FRAME_crpain4+1;
  398. ent->client->anim_end = FRAME_crpain1;
  399. }
  400. else
  401. {
  402. ent->s.frame = FRAME_pain304+1;
  403. ent->client->anim_end = FRAME_pain301;
  404. }
  405. }
  406. ent->client->ps.gunframe++;
  407. return;
  408. }
  409. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  410. {
  411. if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST)
  412. {
  413. ent->client->weaponstate = WEAPON_READY;
  414. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  415. return;
  416. }
  417. ent->client->ps.gunframe++;
  418. return;
  419. }
  420. if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
  421. {
  422. ent->client->weaponstate = WEAPON_DROPPING;
  423. ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
  424. if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
  425. {
  426. ent->client->anim_priority = ANIM_REVERSE;
  427. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  428. {
  429. ent->s.frame = FRAME_crpain4+1;
  430. ent->client->anim_end = FRAME_crpain1;
  431. }
  432. else
  433. {
  434. ent->s.frame = FRAME_pain304+1;
  435. ent->client->anim_end = FRAME_pain301;
  436. }
  437. }
  438. return;
  439. }
  440. if (ent->client->weaponstate == WEAPON_READY)
  441. {
  442. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  443. {
  444. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  445. if ((!ent->client->ammo_index) ||
  446. ( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
  447. {
  448. ent->client->ps.gunframe = FRAME_FIRE_FIRST;
  449. ent->client->weaponstate = WEAPON_FIRING;
  450. // start the animation
  451. ent->client->anim_priority = ANIM_ATTACK;
  452. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  453. {
  454. ent->s.frame = FRAME_crattak1-1;
  455. ent->client->anim_end = FRAME_crattak9;
  456. }
  457. else
  458. {
  459. ent->s.frame = FRAME_attack1-1;
  460. ent->client->anim_end = FRAME_attack8;
  461. }
  462. }
  463. else
  464. {
  465. if (level.time >= ent->pain_debounce_time)
  466. {
  467. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  468. ent->pain_debounce_time = level.time + 1;
  469. }
  470. NoAmmoWeaponChange (ent);
  471. }
  472. }
  473. else
  474. {
  475. if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
  476. {
  477. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  478. return;
  479. }
  480. if (pause_frames)
  481. {
  482. for (n = 0; pause_frames[n]; n++)
  483. {
  484. if (ent->client->ps.gunframe == pause_frames[n])
  485. {
  486. if (rand()&15)
  487. return;
  488. }
  489. }
  490. }
  491. ent->client->ps.gunframe++;
  492. return;
  493. }
  494. }
  495. if (ent->client->weaponstate == WEAPON_FIRING)
  496. {
  497. for (n = 0; fire_frames[n]; n++)
  498. {
  499. if (ent->client->ps.gunframe == fire_frames[n])
  500. {
  501. // FIXME - double should use different sound
  502. if (ent->client->quad_framenum > level.framenum)
  503. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);
  504. else if (ent->client->double_framenum > level.framenum)
  505. gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/ddamage3.wav"), 1, ATTN_NORM, 0);
  506. fire (ent);
  507. break;
  508. }
  509. }
  510. if (!fire_frames[n])
  511. ent->client->ps.gunframe++;
  512. if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
  513. ent->client->weaponstate = WEAPON_READY;
  514. }
  515. }
  516. /*
  517. ======================================================================
  518. GRENADE
  519. ======================================================================
  520. */
  521. #define GRENADE_TIMER 3.0
  522. #define GRENADE_MINSPEED 400
  523. #define GRENADE_MAXSPEED 800
  524. void weapon_grenade_fire (edict_t *ent, qboolean held)
  525. {
  526. vec3_t offset;
  527. vec3_t forward, right, up;
  528. vec3_t start;
  529. int damage = 125;
  530. float timer;
  531. int speed;
  532. float radius;
  533. radius = damage+40;
  534. if (is_quad)
  535. // damage *= 4;
  536. damage *= damage_multiplier; // PGM
  537. AngleVectors (ent->client->v_angle, forward, right, up);
  538. if (ent->client->pers.weapon->tag == AMMO_TESLA)
  539. {
  540. // VectorSet(offset, 0, -12, ent->viewheight-26);
  541. VectorSet(offset, 0, -4, ent->viewheight-22);
  542. }
  543. else
  544. {
  545. // VectorSet(offset, 8, 8, ent->viewheight-8);
  546. VectorSet(offset, 2, 6, ent->viewheight-14);
  547. }
  548. P_ProjectSource2 (ent->client, ent->s.origin, offset, forward, right, up, start);
  549. timer = ent->client->grenade_time - level.time;
  550. speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER);
  551. if (speed > GRENADE_MAXSPEED)
  552. speed = GRENADE_MAXSPEED;
  553. // fire_grenade2 (ent, start, forward, damage, speed, timer, radius, held);
  554. // ============
  555. // PGM
  556. switch(ent->client->pers.weapon->tag)
  557. {
  558. case AMMO_GRENADES:
  559. fire_grenade2 (ent, start, forward, damage, speed, timer, radius, held);
  560. break;
  561. case AMMO_TESLA:
  562. fire_tesla (ent, start, forward, damage_multiplier, speed);
  563. break;
  564. default:
  565. fire_prox (ent, start, forward, damage_multiplier, speed);
  566. break;
  567. }
  568. // PGM
  569. // ============
  570. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  571. ent->client->pers.inventory[ent->client->ammo_index]--;
  572. ent->client->grenade_time = level.time + 1.0;
  573. if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
  574. {
  575. return;
  576. }
  577. if (ent->health <= 0)
  578. return;
  579. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  580. {
  581. ent->client->anim_priority = ANIM_ATTACK;
  582. ent->s.frame = FRAME_crattak1-1;
  583. ent->client->anim_end = FRAME_crattak3;
  584. }
  585. else
  586. {
  587. ent->client->anim_priority = ANIM_REVERSE;
  588. ent->s.frame = FRAME_wave08;
  589. ent->client->anim_end = FRAME_wave01;
  590. }
  591. }
  592. /*
  593. void Weapon_Grenade (edict_t *ent)
  594. {
  595. if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
  596. {
  597. ChangeWeapon (ent);
  598. return;
  599. }
  600. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  601. {
  602. ent->client->weaponstate = WEAPON_READY;
  603. ent->client->ps.gunframe = 16;
  604. return;
  605. }
  606. if (ent->client->weaponstate == WEAPON_READY)
  607. {
  608. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  609. {
  610. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  611. if (ent->client->pers.inventory[ent->client->ammo_index])
  612. {
  613. ent->client->ps.gunframe = 1;
  614. ent->client->weaponstate = WEAPON_FIRING;
  615. ent->client->grenade_time = 0;
  616. }
  617. else
  618. {
  619. if (level.time >= ent->pain_debounce_time)
  620. {
  621. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  622. ent->pain_debounce_time = level.time + 1;
  623. }
  624. NoAmmoWeaponChange (ent);
  625. }
  626. return;
  627. }
  628. if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48))
  629. {
  630. if (rand()&15)
  631. return;
  632. }
  633. if (++ent->client->ps.gunframe > 48)
  634. ent->client->ps.gunframe = 16;
  635. return;
  636. }
  637. if (ent->client->weaponstate == WEAPON_FIRING)
  638. {
  639. if (ent->client->ps.gunframe == 5)
  640. gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);
  641. if (ent->client->ps.gunframe == 11)
  642. {
  643. if (!ent->client->grenade_time)
  644. {
  645. ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
  646. ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
  647. }
  648. // they waited too long, detonate it in their hand
  649. if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
  650. {
  651. ent->client->weapon_sound = 0;
  652. weapon_grenade_fire (ent, true);
  653. ent->client->grenade_blew_up = true;
  654. }
  655. if (ent->client->buttons & BUTTON_ATTACK)
  656. return;
  657. if (ent->client->grenade_blew_up)
  658. {
  659. if (level.time >= ent->client->grenade_time)
  660. {
  661. ent->client->ps.gunframe = 15;
  662. ent->client->grenade_blew_up = false;
  663. }
  664. else
  665. {
  666. return;
  667. }
  668. }
  669. }
  670. if (ent->client->ps.gunframe == 12)
  671. {
  672. ent->client->weapon_sound = 0;
  673. weapon_grenade_fire (ent, false);
  674. }
  675. if ((ent->client->ps.gunframe == 15) && (level.time < ent->client->grenade_time))
  676. return;
  677. ent->client->ps.gunframe++;
  678. if (ent->client->ps.gunframe == 16)
  679. {
  680. ent->client->grenade_time = 0;
  681. ent->client->weaponstate = WEAPON_READY;
  682. }
  683. }
  684. }
  685. */
  686. #define FRAME_IDLE_FIRST (FRAME_FIRE_LAST + 1)
  687. //void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
  688. // 15 48 5 11 12 29,34,39,48
  689. void Throw_Generic (edict_t *ent, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_THROW_SOUND,
  690. int FRAME_THROW_HOLD, int FRAME_THROW_FIRE, int *pause_frames, int EXPLODE,
  691. void (*fire)(edict_t *ent, qboolean held))
  692. {
  693. int n;
  694. if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
  695. {
  696. ChangeWeapon (ent);
  697. return;
  698. }
  699. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  700. {
  701. ent->client->weaponstate = WEAPON_READY;
  702. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  703. return;
  704. }
  705. if (ent->client->weaponstate == WEAPON_READY)
  706. {
  707. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  708. {
  709. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  710. if (ent->client->pers.inventory[ent->client->ammo_index])
  711. {
  712. ent->client->ps.gunframe = 1;
  713. ent->client->weaponstate = WEAPON_FIRING;
  714. ent->client->grenade_time = 0;
  715. }
  716. else
  717. {
  718. if (level.time >= ent->pain_debounce_time)
  719. {
  720. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  721. ent->pain_debounce_time = level.time + 1;
  722. }
  723. NoAmmoWeaponChange (ent);
  724. }
  725. return;
  726. }
  727. if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
  728. {
  729. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  730. return;
  731. }
  732. if (pause_frames)
  733. {
  734. for (n = 0; pause_frames[n]; n++)
  735. {
  736. if (ent->client->ps.gunframe == pause_frames[n])
  737. {
  738. if (rand()&15)
  739. return;
  740. }
  741. }
  742. }
  743. ent->client->ps.gunframe++;
  744. return;
  745. }
  746. if (ent->client->weaponstate == WEAPON_FIRING)
  747. {
  748. if (ent->client->ps.gunframe == FRAME_THROW_SOUND)
  749. gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);
  750. if (ent->client->ps.gunframe == FRAME_THROW_HOLD)
  751. {
  752. if (!ent->client->grenade_time)
  753. {
  754. ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
  755. switch(ent->client->pers.weapon->tag)
  756. {
  757. case AMMO_GRENADES:
  758. ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
  759. break;
  760. }
  761. }
  762. // they waited too long, detonate it in their hand
  763. if (EXPLODE && !ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
  764. {
  765. ent->client->weapon_sound = 0;
  766. fire (ent, true);
  767. ent->client->grenade_blew_up = true;
  768. }
  769. if (ent->client->buttons & BUTTON_ATTACK)
  770. return;
  771. if (ent->client->grenade_blew_up)
  772. {
  773. if (level.time >= ent->client->grenade_time)
  774. {
  775. ent->client->ps.gunframe = FRAME_FIRE_LAST;
  776. ent->client->grenade_blew_up = false;
  777. }
  778. else
  779. {
  780. return;
  781. }
  782. }
  783. }
  784. if (ent->client->ps.gunframe == FRAME_THROW_FIRE)
  785. {
  786. ent->client->weapon_sound = 0;
  787. fire (ent, true);
  788. }
  789. if ((ent->client->ps.gunframe == FRAME_FIRE_LAST) && (level.time < ent->client->grenade_time))
  790. return;
  791. ent->client->ps.gunframe++;
  792. if (ent->client->ps.gunframe == FRAME_IDLE_FIRST)
  793. {
  794. ent->client->grenade_time = 0;
  795. ent->client->weaponstate = WEAPON_READY;
  796. }
  797. }
  798. }
  799. //void Throw_Generic (edict_t *ent, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_THROW_SOUND,
  800. // int FRAME_THROW_HOLD, int FRAME_THROW_FIRE, int *pause_frames,
  801. // int EXPLOSION_TIME, void (*fire)(edict_t *ent))
  802. void Weapon_Grenade (edict_t *ent)
  803. {
  804. static int pause_frames[] = {29,34,39,48,0};
  805. Throw_Generic (ent, 15, 48, 5, 11, 12, pause_frames, GRENADE_TIMER, weapon_grenade_fire);
  806. }
  807. void Weapon_Prox (edict_t *ent)
  808. {
  809. static int pause_frames[] = {22, 29, 0};
  810. Throw_Generic (ent, 7, 27, 99, 2, 4, pause_frames, 0, weapon_grenade_fire);
  811. }
  812. void Weapon_Tesla (edict_t *ent)
  813. {
  814. static int pause_frames[] = {21, 0};
  815. if ((ent->client->ps.gunframe > 1) && (ent->client->ps.gunframe < 9))
  816. {
  817. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_tesla2/tris.md2");
  818. }
  819. else
  820. {
  821. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_tesla/tris.md2");
  822. }
  823. Throw_Generic (ent, 8, 32, 99, 1, 2, pause_frames, 0, weapon_grenade_fire);
  824. }
  825. /*
  826. ======================================================================
  827. GRENADE LAUNCHER
  828. ======================================================================
  829. */
  830. void weapon_grenadelauncher_fire (edict_t *ent)
  831. {
  832. vec3_t offset;
  833. vec3_t forward, right;
  834. vec3_t start;
  835. // int damage = 120;
  836. int damage; // PGM
  837. float radius;
  838. // =====
  839. // PGM
  840. switch(ent->client->pers.weapon->tag)
  841. {
  842. case AMMO_PROX:
  843. damage = 90;
  844. break;
  845. default:
  846. damage = 120;
  847. break;
  848. }
  849. // PGM
  850. // =====
  851. radius = damage+40;
  852. if (is_quad)
  853. // damage *= 4;
  854. damage *= damage_multiplier; //pgm
  855. VectorSet(offset, 8, 8, ent->viewheight-8);
  856. AngleVectors (ent->client->v_angle, forward, right, NULL);
  857. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  858. VectorScale (forward, -2, ent->client->kick_origin);
  859. ent->client->kick_angles[0] = -1;
  860. // fire_grenade (ent, start, forward, damage, 600, 2.5, radius);
  861. // =====
  862. // PGM
  863. switch(ent->client->pers.weapon->tag)
  864. {
  865. case AMMO_PROX:
  866. fire_prox (ent, start, forward, damage_multiplier, 600);
  867. break;
  868. default:
  869. fire_grenade (ent, start, forward, damage, 600, 2.5, radius);
  870. break;
  871. }
  872. // PGM
  873. // =====
  874. gi.WriteByte (svc_muzzleflash);
  875. gi.WriteShort (ent-g_edicts);
  876. gi.WriteByte (MZ_GRENADE | is_silenced);
  877. gi.multicast (ent->s.origin, MULTICAST_PVS);
  878. ent->client->ps.gunframe++;
  879. PlayerNoise(ent, start, PNOISE_WEAPON);
  880. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  881. ent->client->pers.inventory[ent->client->ammo_index]--;
  882. }
  883. void Weapon_GrenadeLauncher (edict_t *ent)
  884. {
  885. static int pause_frames[] = {34, 51, 59, 0};
  886. static int fire_frames[] = {6, 0};
  887. Weapon_Generic (ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
  888. }
  889. //==========
  890. //PGM
  891. void Weapon_ProxLauncher (edict_t *ent)
  892. {
  893. static int pause_frames[] = {34, 51, 59, 0};
  894. static int fire_frames[] = {6, 0};
  895. Weapon_Generic (ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
  896. }
  897. //PGM
  898. //==========
  899. /*
  900. ======================================================================
  901. ROCKET
  902. ======================================================================
  903. */
  904. void Weapon_RocketLauncher_Fire (edict_t *ent)
  905. {
  906. vec3_t offset, start;
  907. vec3_t forward, right;
  908. int damage;
  909. float damage_radius;
  910. int radius_damage;
  911. damage = 100 + (int)(random() * 20.0);
  912. radius_damage = 120;
  913. damage_radius = 120;
  914. if (is_quad)
  915. {
  916. //PGM
  917. // damage *= 4;
  918. damage *= damage_multiplier;
  919. // radius_damage *= 4;
  920. radius_damage *= damage_multiplier;
  921. //PGM
  922. }
  923. AngleVectors (ent->client->v_angle, forward, right, NULL);
  924. VectorScale (forward, -2, ent->client->kick_origin);
  925. ent->client->kick_angles[0] = -1;
  926. VectorSet(offset, 8, 8, ent->viewheight-8);
  927. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  928. fire_rocket (ent, start, forward, damage, 650, damage_radius, radius_damage);
  929. // send muzzle flash
  930. gi.WriteByte (svc_muzzleflash);
  931. gi.WriteShort (ent-g_edicts);
  932. gi.WriteByte (MZ_ROCKET | is_silenced);
  933. gi.multicast (ent->s.origin, MULTICAST_PVS);
  934. ent->client->ps.gunframe++;
  935. PlayerNoise(ent, start, PNOISE_WEAPON);
  936. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  937. ent->client->pers.inventory[ent->client->ammo_index]--;
  938. }
  939. void Weapon_RocketLauncher (edict_t *ent)
  940. {
  941. static int pause_frames[] = {25, 33, 42, 50, 0};
  942. static int fire_frames[] = {5, 0};
  943. Weapon_Generic (ent, 4, 12, 50, 54, pause_frames, fire_frames, Weapon_RocketLauncher_Fire);
  944. }
  945. /*
  946. ======================================================================
  947. BLASTER / HYPERBLASTER
  948. ======================================================================
  949. */
  950. void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, int effect)
  951. {
  952. vec3_t forward, right;
  953. vec3_t start;
  954. vec3_t offset;
  955. if (is_quad)
  956. // damage *= 4;
  957. damage *= damage_multiplier; //pgm
  958. AngleVectors (ent->client->v_angle, forward, right, NULL);
  959. VectorSet(offset, 24, 8, ent->viewheight-8);
  960. VectorAdd (offset, g_offset, offset);
  961. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  962. VectorScale (forward, -2, ent->client->kick_origin);
  963. ent->client->kick_angles[0] = -1;
  964. fire_blaster (ent, start, forward, damage, 1000, effect, hyper);
  965. // send muzzle flash
  966. gi.WriteByte (svc_muzzleflash);
  967. gi.WriteShort (ent-g_edicts);
  968. if (hyper)
  969. gi.WriteByte (MZ_HYPERBLASTER | is_silenced);
  970. else
  971. gi.WriteByte (MZ_BLASTER | is_silenced);
  972. gi.multicast (ent->s.origin, MULTICAST_PVS);
  973. PlayerNoise(ent, start, PNOISE_WEAPON);
  974. }
  975. void Weapon_Blaster_Fire (edict_t *ent)
  976. {
  977. int damage;
  978. if (deathmatch->value)
  979. damage = 15;
  980. else
  981. damage = 10;
  982. Blaster_Fire (ent, vec3_origin, damage, false, EF_BLASTER);
  983. ent->client->ps.gunframe++;
  984. }
  985. void Weapon_Blaster (edict_t *ent)
  986. {
  987. static int pause_frames[] = {19, 32, 0};
  988. static int fire_frames[] = {5, 0};
  989. Weapon_Generic (ent, 4, 8, 52, 55, pause_frames, fire_frames, Weapon_Blaster_Fire);
  990. }
  991. void Weapon_HyperBlaster_Fire (edict_t *ent)
  992. {
  993. float rotation;
  994. vec3_t offset;
  995. int effect;
  996. int damage;
  997. ent->client->weapon_sound = gi.soundindex("weapons/hyprbl1a.wav");
  998. if (!(ent->client->buttons & BUTTON_ATTACK))
  999. {
  1000. ent->client->ps.gunframe++;
  1001. }
  1002. else
  1003. {
  1004. if (! ent->client->pers.inventory[ent->client->ammo_index] )
  1005. {
  1006. if (level.time >= ent->pain_debounce_time)
  1007. {
  1008. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  1009. ent->pain_debounce_time = level.time + 1;
  1010. }
  1011. NoAmmoWeaponChange (ent);
  1012. }
  1013. else
  1014. {
  1015. rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
  1016. offset[0] = -4 * sin(rotation);
  1017. offset[1] = 0;
  1018. offset[2] = 4 * cos(rotation);
  1019. if ((ent->client->ps.gunframe == 6) || (ent->client->ps.gunframe == 9))
  1020. effect = EF_HYPERBLASTER;
  1021. else
  1022. effect = 0;
  1023. if (deathmatch->value)
  1024. damage = 15;
  1025. else
  1026. damage = 20;
  1027. Blaster_Fire (ent, offset, damage, true, effect);
  1028. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1029. ent->client->pers.inventory[ent->client->ammo_index]--;
  1030. ent->client->anim_priority = ANIM_ATTACK;
  1031. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  1032. {
  1033. ent->s.frame = FRAME_crattak1 - 1;
  1034. ent->client->anim_end = FRAME_crattak9;
  1035. }
  1036. else
  1037. {
  1038. ent->s.frame = FRAME_attack1 - 1;
  1039. ent->client->anim_end = FRAME_attack8;
  1040. }
  1041. }
  1042. ent->client->ps.gunframe++;
  1043. if (ent->client->ps.gunframe == 12 && ent->client->pers.inventory[ent->client->ammo_index])
  1044. ent->client->ps.gunframe = 6;
  1045. }
  1046. if (ent->client->ps.gunframe == 12)
  1047. {
  1048. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/hyprbd1a.wav"), 1, ATTN_NORM, 0);
  1049. ent->client->weapon_sound = 0;
  1050. }
  1051. }
  1052. void Weapon_HyperBlaster (edict_t *ent)
  1053. {
  1054. static int pause_frames[] = {0};
  1055. static int fire_frames[] = {6, 7, 8, 9, 10, 11, 0};
  1056. Weapon_Generic (ent, 5, 20, 49, 53, pause_frames, fire_frames, Weapon_HyperBlaster_Fire);
  1057. }
  1058. /*
  1059. ======================================================================
  1060. MACHINEGUN / CHAINGUN
  1061. ======================================================================
  1062. */
  1063. void Machinegun_Fire (edict_t *ent)
  1064. {
  1065. int i;
  1066. vec3_t start;
  1067. vec3_t forward, right;
  1068. vec3_t angles;
  1069. int damage = 8;
  1070. int kick = 2;
  1071. vec3_t offset;
  1072. if (!(ent->client->buttons & BUTTON_ATTACK))
  1073. {
  1074. ent->client->machinegun_shots = 0;
  1075. ent->client->ps.gunframe++;
  1076. return;
  1077. }
  1078. if (ent->client->ps.gunframe == 5)
  1079. ent->client->ps.gunframe = 4;
  1080. else
  1081. ent->client->ps.gunframe = 5;
  1082. if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
  1083. {
  1084. ent->client->ps.gunframe = 6;
  1085. if (level.time >= ent->pain_debounce_time)
  1086. {
  1087. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  1088. ent->pain_debounce_time = level.time + 1;
  1089. }
  1090. NoAmmoWeaponChange (ent);
  1091. return;
  1092. }
  1093. if (is_quad)
  1094. {
  1095. //PGM
  1096. // damage *= 4;
  1097. damage *= damage_multiplier;
  1098. // kick *= 4;
  1099. kick *= damage_multiplier;
  1100. //PGM
  1101. }
  1102. for (i=1 ; i<3 ; i++)
  1103. {
  1104. ent->client->kick_origin[i] = crandom() * 0.35;
  1105. ent->client->kick_angles[i] = crandom() * 0.7;
  1106. }
  1107. ent->client->kick_origin[0] = crandom() * 0.35;
  1108. ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;
  1109. // raise the gun as it is firing
  1110. if (!deathmatch->value)
  1111. {
  1112. ent->client->machinegun_shots++;
  1113. if (ent->client->machinegun_shots > 9)
  1114. ent->client->machinegun_shots = 9;
  1115. }
  1116. // get start / end positions
  1117. VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
  1118. AngleVectors (angles, forward, right, NULL);
  1119. VectorSet(offset, 0, 8, ent->viewheight-8);
  1120. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1121. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
  1122. gi.WriteByte (svc_muzzleflash);
  1123. gi.WriteShort (ent-g_edicts);
  1124. gi.WriteByte (MZ_MACHINEGUN | is_silenced);
  1125. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1126. PlayerNoise(ent, start, PNOISE_WEAPON);
  1127. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1128. ent->client->pers.inventory[ent->client->ammo_index]--;
  1129. ent->client->anim_priority = ANIM_ATTACK;
  1130. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  1131. {
  1132. ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
  1133. ent->client->anim_end = FRAME_crattak9;
  1134. }
  1135. else
  1136. {
  1137. ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
  1138. ent->client->anim_end = FRAME_attack8;
  1139. }
  1140. }
  1141. void Weapon_Machinegun (edict_t *ent)
  1142. {
  1143. static int pause_frames[] = {23, 45, 0};
  1144. static int fire_frames[] = {4, 5, 0};
  1145. Weapon_Generic (ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
  1146. }
  1147. void Chaingun_Fire (edict_t *ent)
  1148. {
  1149. int i;
  1150. int shots;
  1151. vec3_t start;
  1152. vec3_t forward, right, up;
  1153. float r, u;
  1154. vec3_t offset;
  1155. int damage;
  1156. int kick = 2;
  1157. if (deathmatch->value)
  1158. damage = 6;
  1159. else
  1160. damage = 8;
  1161. if (ent->client->ps.gunframe == 5)
  1162. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);
  1163. if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
  1164. {
  1165. ent->client->ps.gunframe = 32;
  1166. ent->client->weapon_sound = 0;
  1167. return;
  1168. }
  1169. else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
  1170. && ent->client->pers.inventory[ent->client->ammo_index])
  1171. {
  1172. ent->client->ps.gunframe = 15;
  1173. }
  1174. else
  1175. {
  1176. ent->client->ps.gunframe++;
  1177. }
  1178. if (ent->client->ps.gunframe == 22)
  1179. {
  1180. ent->client->weapon_sound = 0;
  1181. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
  1182. }
  1183. else
  1184. {
  1185. ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
  1186. }
  1187. ent->client->anim_priority = ANIM_ATTACK;
  1188. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  1189. {
  1190. ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
  1191. ent->client->anim_end = FRAME_crattak9;
  1192. }
  1193. else
  1194. {
  1195. ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
  1196. ent->client->anim_end = FRAME_attack8;
  1197. }
  1198. if (ent->client->ps.gunframe <= 9)
  1199. shots = 1;
  1200. else if (ent->client->ps.gunframe <= 14)
  1201. {
  1202. if (ent->client->buttons & BUTTON_ATTACK)
  1203. shots = 2;
  1204. else
  1205. shots = 1;
  1206. }
  1207. else
  1208. shots = 3;
  1209. if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
  1210. shots = ent->client->pers.inventory[ent->client->ammo_index];
  1211. if (!shots)
  1212. {
  1213. if (level.time >= ent->pain_debounce_time)
  1214. {
  1215. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  1216. ent->pain_debounce_time = level.time + 1;
  1217. }
  1218. NoAmmoWeaponChange (ent);
  1219. return;
  1220. }
  1221. if (is_quad)
  1222. {
  1223. //PGM
  1224. // damage *= 4;
  1225. damage *= damage_multiplier;
  1226. // kick *= 4;
  1227. kick *= damage_multiplier;
  1228. //PGM
  1229. }
  1230. for (i=0 ; i<3 ; i++)
  1231. {
  1232. ent->client->kick_origin[i] = crandom() * 0.35;
  1233. ent->client->kick_angles[i] = crandom() * 0.7;
  1234. }
  1235. for (i=0 ; i<shots ; i++)
  1236. {
  1237. // get start / end positions
  1238. AngleVectors (ent->client->v_angle, forward, right, up);
  1239. r = 7 + crandom()*4;
  1240. u = crandom()*4;
  1241. VectorSet(offset, 0, r, u + ent->viewheight-8);
  1242. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1243. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
  1244. }
  1245. // send muzzle flash
  1246. gi.WriteByte (svc_muzzleflash);
  1247. gi.WriteShort (ent-g_edicts);
  1248. gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
  1249. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1250. PlayerNoise(ent, start, PNOISE_WEAPON);
  1251. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1252. ent->client->pers.inventory[ent->client->ammo_index] -= shots;
  1253. }
  1254. void Weapon_Chaingun (edict_t *ent)
  1255. {
  1256. static int pause_frames[] = {38, 43, 51, 61, 0};
  1257. static int fire_frames[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
  1258. Weapon_Generic (ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
  1259. }
  1260. /*
  1261. ======================================================================
  1262. SHOTGUN / SUPERSHOTGUN
  1263. ======================================================================
  1264. */
  1265. void weapon_shotgun_fire (edict_t *ent)
  1266. {
  1267. vec3_t start;
  1268. vec3_t forward, right;
  1269. vec3_t offset;
  1270. int damage = 4;
  1271. int kick = 8;
  1272. if (ent->client->ps.gunframe == 9)
  1273. {
  1274. ent->client->ps.gunframe++;
  1275. return;
  1276. }
  1277. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1278. VectorScale (forward, -2, ent->client->kick_origin);
  1279. ent->client->kick_angles[0] = -2;
  1280. VectorSet(offset, 0, 8, ent->viewheight-8);
  1281. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1282. if (is_quad)
  1283. {
  1284. //PGM
  1285. // damage *= 4;
  1286. damage *= damage_multiplier;
  1287. // kick *= 4;
  1288. kick *= damage_multiplier;
  1289. //PGM
  1290. }
  1291. if (deathmatch->value)
  1292. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN);
  1293. else
  1294. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);
  1295. // send muzzle flash
  1296. gi.WriteByte (svc_muzzleflash);
  1297. gi.WriteShort (ent-g_edicts);
  1298. gi.WriteByte (MZ_SHOTGUN | is_silenced);
  1299. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1300. ent->client->ps.gunframe++;
  1301. PlayerNoise(ent, start, PNOISE_WEAPON);
  1302. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1303. ent->client->pers.inventory[ent->client->ammo_index]--;
  1304. }
  1305. void Weapon_Shotgun (edict_t *ent)
  1306. {
  1307. static int pause_frames[] = {22, 28, 34, 0};
  1308. static int fire_frames[] = {8, 9, 0};
  1309. Weapon_Generic (ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
  1310. }
  1311. void weapon_supershotgun_fire (edict_t *ent)
  1312. {
  1313. vec3_t start;
  1314. vec3_t forward, right;
  1315. vec3_t offset;
  1316. vec3_t v;
  1317. int damage = 6;
  1318. int kick = 12;
  1319. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1320. VectorScale (forward, -2, ent->client->kick_origin);
  1321. ent->client->kick_angles[0] = -2;
  1322. VectorSet(offset, 0, 8, ent->viewheight-8);
  1323. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1324. if (is_quad)
  1325. {
  1326. //PGM
  1327. // damage *= 4;
  1328. damage *= damage_multiplier;
  1329. // kick *= 4;
  1330. kick *= damage_multiplier;
  1331. //PGM
  1332. }
  1333. v[PITCH] = ent->client->v_angle[PITCH];
  1334. v[YAW] = ent->client->v_angle[YAW] - 5;
  1335. v[ROLL] = ent->client->v_angle[ROLL];
  1336. AngleVectors (v, forward, NULL, NULL);
  1337. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1338. v[YAW] = ent->client->v_angle[YAW] + 5;
  1339. AngleVectors (v, forward, NULL, NULL);
  1340. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1341. // send muzzle flash
  1342. gi.WriteByte (svc_muzzleflash);
  1343. gi.WriteShort (ent-g_edicts);
  1344. gi.WriteByte (MZ_SSHOTGUN | is_silenced);
  1345. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1346. ent->client->ps.gunframe++;
  1347. PlayerNoise(ent, start, PNOISE_WEAPON);
  1348. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1349. ent->client->pers.inventory[ent->client->ammo_index] -= 2;
  1350. }
  1351. void Weapon_SuperShotgun (edict_t *ent)
  1352. {
  1353. static int pause_frames[] = {29, 42, 57, 0};
  1354. static int fire_frames[] = {7, 0};
  1355. Weapon_Generic (ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
  1356. }
  1357. /*
  1358. ======================================================================
  1359. RAILGUN
  1360. ======================================================================
  1361. */
  1362. void weapon_railgun_fire (edict_t *ent)
  1363. {
  1364. vec3_t start;
  1365. vec3_t forward, right;
  1366. vec3_t offset;
  1367. int damage;
  1368. int kick;
  1369. if (deathmatch->value)
  1370. { // normal damage is too extreme in dm
  1371. damage = 100;
  1372. kick = 200;
  1373. }
  1374. else
  1375. {
  1376. damage = 150;
  1377. kick = 250;
  1378. }
  1379. if (is_quad)
  1380. {
  1381. //PGM
  1382. // damage *= 4;
  1383. damage *= damage_multiplier;
  1384. // kick *= 4;
  1385. kick *= damage_multiplier;
  1386. //PGM
  1387. }
  1388. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1389. VectorScale (forward, -3, ent->client->kick_origin);
  1390. ent->client->kick_angles[0] = -3;
  1391. VectorSet(offset, 0, 7, ent->viewheight-8);
  1392. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1393. fire_rail (ent, start, forward, damage, kick);
  1394. // send muzzle flash
  1395. gi.WriteByte (svc_muzzleflash);
  1396. gi.WriteShort (ent-g_edicts);
  1397. gi.WriteByte (MZ_RAILGUN | is_silenced);
  1398. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1399. ent->client->ps.gunframe++;
  1400. PlayerNoise(ent, start, PNOISE_WEAPON);
  1401. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1402. ent->client->pers.inventory[ent->client->ammo_index]--;
  1403. }
  1404. void Weapon_Railgun (edict_t *ent)
  1405. {
  1406. static int pause_frames[] = {56, 0};
  1407. static int fire_frames[] = {4, 0};
  1408. Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
  1409. }
  1410. /*
  1411. ======================================================================
  1412. BFG10K
  1413. ======================================================================
  1414. */
  1415. void weapon_bfg_fire (edict_t *ent)
  1416. {
  1417. vec3_t offset, start;
  1418. vec3_t forward, right;
  1419. int damage;
  1420. float damage_radius = 1000;
  1421. if (deathmatch->value)
  1422. damage = 200;
  1423. else
  1424. damage = 500;
  1425. if (ent->client->ps.gunframe == 9)
  1426. {
  1427. // send muzzle flash
  1428. gi.WriteByte (svc_muzzleflash);
  1429. gi.WriteShort (ent-g_edicts);
  1430. gi.WriteByte (MZ_BFG | is_silenced);
  1431. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1432. ent->client->ps.gunframe++;
  1433. PlayerNoise(ent, start, PNOISE_WEAPON);
  1434. return;
  1435. }
  1436. // cells can go down during windup (from power armor hits), so
  1437. // check again and abort firing if we don't have enough now
  1438. if (ent->client->pers.inventory[ent->client->ammo_index] < 50)
  1439. {
  1440. ent->client->ps.gunframe++;
  1441. return;
  1442. }
  1443. if (is_quad)
  1444. //PGM
  1445. // damage *= 4;
  1446. damage *= damage_multiplier;
  1447. //PGM
  1448. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1449. VectorScale (forward, -2, ent->client->kick_origin);
  1450. // make a big pitch kick with an inverse fall
  1451. ent->client->v_dmg_pitch = -40;
  1452. ent->client->v_dmg_roll = crandom()*8;
  1453. ent->client->v_dmg_time = level.time + DAMAGE_TIME;
  1454. VectorSet(offset, 8, 8, ent->viewheight-8);
  1455. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1456. fire_bfg (ent, start, forward, damage, 400, damage_radius);
  1457. ent->client->ps.gunframe++;
  1458. PlayerNoise(ent, start, PNOISE_WEAPON);
  1459. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1460. ent->client->pers.inventory[ent->client->ammo_index] -= 50;
  1461. }
  1462. void Weapon_BFG (edict_t *ent)
  1463. {
  1464. static int pause_frames[] = {39, 45, 50, 55, 0};
  1465. static int fire_frames[] = {9, 17, 0};
  1466. Weapon_Generic (ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
  1467. }
  1468. //======================================================================
  1469. // ROGUE MODS BELOW
  1470. //======================================================================
  1471. //
  1472. // CHAINFIST
  1473. //
  1474. #define CHAINFIST_REACH 64
  1475. void weapon_chainfist_fire (edict_t *ent)
  1476. {
  1477. vec3_t offset;
  1478. vec3_t forward, right, up;
  1479. vec3_t start;
  1480. int damage;
  1481. damage = 15;
  1482. if(deathmatch->value)
  1483. damage = 30;
  1484. if (is_quad)
  1485. damage *= damage_multiplier;
  1486. AngleVectors (ent->client->v_angle, forward, right, up);
  1487. // kick back
  1488. VectorScale (forward, -2, ent->client->kick_origin);
  1489. ent->client->kick_angles[0] = -1;
  1490. // set start point
  1491. VectorSet(offset, 0, 8, ent->viewheight-4);
  1492. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1493. fire_player_melee (ent, start, forward, CHAINFIST_REACH, damage, 100, 1, MOD_CHAINFIST);
  1494. PlayerNoise(ent, start, PNOISE_WEAPON);
  1495. ent->client->ps.gunframe++;
  1496. ent->client->pers.inventory[ent->client->ammo_index] -= ent->client->pers.weapon->quantity;
  1497. }
  1498. // this spits out some smoke from the motor. it's a two-stroke, you know.
  1499. void chainfist_smoke (edict_t *ent)
  1500. {
  1501. vec3_t tempVec, forward, right, up;
  1502. vec3_t offset;
  1503. AngleVectors(ent->client->v_angle, forward, right, up);
  1504. VectorSet(offset, 8, 8, ent->viewheight -4);
  1505. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, tempVec);
  1506. gi.WriteByte (svc_temp_entity);
  1507. gi.WriteByte (TE_CHAINFIST_SMOKE);
  1508. gi.WritePosition (tempVec);
  1509. gi.unicast (ent, 0);
  1510. // gi.multicast (tempVec, MULTICAST_PVS);
  1511. }
  1512. #define HOLD_FRAMES 0
  1513. void Weapon_ChainFist (edict_t *ent)
  1514. {
  1515. static int pause_frames[] = {0};
  1516. static int fire_frames[] = {8, 9, 16, 17, 18, 30, 31, 0};
  1517. // these are caches for the sound index. there's probably a better way to do this.
  1518. // static int idle_index;
  1519. // static int attack_index;
  1520. float chance;
  1521. int last_sequence;
  1522. last_sequence = 0;
  1523. // load chainsaw sounds and store the indexes for later use.
  1524. // if(!idle_index && !attack_index)
  1525. // {
  1526. // idle_index = gi.soundindex("weapons/sawidle.wav");
  1527. // attack_index = gi.soundindex("weapons/sawhit.wav");
  1528. // }
  1529. if(ent->client->ps.gunframe == 13 ||
  1530. ent->client->ps.gunframe == 23) // end of attack, go idle
  1531. ent->client->ps.gunframe = 32;
  1532. #if HOLD_FRAMES
  1533. else if(ent->client->ps.gunframe == 9 && ((ent->client->buttons) & BUTTON_ATTACK))
  1534. ent->client->ps.gunframe = 7;
  1535. else if(ent->client->ps.gunframe == 18 && ((ent->client->buttons) & BUTTON_ATTACK))
  1536. ent->client->ps.gunframe = 16;
  1537. #endif
  1538. // holds for idle sequence
  1539. else if(ent->client->ps.gunframe == 42 && (rand()&7))
  1540. {
  1541. if((ent->client->pers.hand != CENTER_HANDED) && random() < 0.4)
  1542. chainfist_smoke(ent);
  1543. // ent->client->ps.gunframe = 40;
  1544. }
  1545. else if(ent->client->ps.gunframe == 51 && (rand()&7))
  1546. {
  1547. if((ent->client->pers.hand != CENTER_HANDED) && random() < 0.4)
  1548. chainfist_smoke(ent);
  1549. // ent->client->ps.gunframe = 49;
  1550. }
  1551. // set the appropriate weapon sound.
  1552. if(ent->client->weaponstate == WEAPON_FIRING)
  1553. // ent->client->weapon_sound = attack_index;
  1554. ent->client->weapon_sound = gi.soundindex("weapons/sawhit.wav");
  1555. else if(ent->client->weaponstate == WEAPON_DROPPING)
  1556. ent->client->weapon_sound = 0;
  1557. else
  1558. // ent->client->weapon_sound = idle_index;
  1559. ent->client->weapon_sound = gi.soundindex("weapons/sawidle.wav");
  1560. Weapon_Generic (ent, 4, 32, 57, 60, pause_frames, fire_frames, weapon_chainfist_fire);
  1561. // gi.dprintf("chainfist %d\n", ent->client->ps.gunframe);
  1562. if((ent->client->buttons) & BUTTON_ATTACK)
  1563. {
  1564. if(ent->client->ps.gunframe == 13 ||
  1565. ent->client->ps.gunframe == 23 ||
  1566. ent->client->ps.gunframe == 32)
  1567. {
  1568. last_sequence = ent->client->ps.gunframe;
  1569. ent->client->ps.gunframe = 6;
  1570. }
  1571. }
  1572. if (ent->client->ps.gunframe == 6)
  1573. {
  1574. chance = random();
  1575. if(last_sequence == 13) // if we just did sequence 1, do 2 or 3.
  1576. chance -= 0.34;
  1577. else if(last_sequence == 23) // if we just did sequence 2, do 1 or 3
  1578. chance += 0.33;
  1579. else if(last_sequence == 32) // if we just did sequence 3, do 1 or 2
  1580. {
  1581. if(chance >= 0.33)
  1582. chance += 0.34;
  1583. }
  1584. if(chance < 0.33)
  1585. ent->client->ps.gunframe = 14;
  1586. else if(chance < 0.66)
  1587. ent->client->ps.gunframe = 24;
  1588. }
  1589. }
  1590. //
  1591. // Disintegrator
  1592. //
  1593. void weapon_tracker_fire (edict_t *self)
  1594. {
  1595. vec3_t forward, right;
  1596. vec3_t start;
  1597. vec3_t end;
  1598. vec3_t offset;
  1599. edict_t *enemy;
  1600. trace_t tr;
  1601. int damage;
  1602. vec3_t mins, maxs;
  1603. // PMM - felt a little high at 25
  1604. if(deathmatch->value)
  1605. damage = 30;
  1606. else
  1607. damage = 45;
  1608. if (is_quad)
  1609. damage *= damage_multiplier; //pgm
  1610. VectorSet(mins, -16, -16, -16);
  1611. VectorSet(maxs, 16, 16, 16);
  1612. AngleVectors (self->client->v_angle, forward, right, NULL);
  1613. VectorSet(offset, 24, 8, self->viewheight-8);
  1614. P_ProjectSource (self->client, self->s.origin, offset, forward, right, start);
  1615. // FIXME - can we shorten this? do we need to?
  1616. VectorMA (start, 8192, forward, end);
  1617. enemy = NULL;
  1618. //PMM - doing two traces .. one point and one box.
  1619. tr = gi.trace (start, vec3_origin, vec3_origin, end, self, MASK_SHOT);
  1620. if(tr.ent != world)
  1621. {
  1622. if(tr.ent->svflags & SVF_MONSTER || tr.ent->client || tr.ent->svflags & SVF_DAMAGEABLE)
  1623. {
  1624. if(tr.ent->health > 0)
  1625. enemy = tr.ent;
  1626. }
  1627. }
  1628. else
  1629. {
  1630. tr = gi.trace (start, mins, maxs, end, self, MASK_SHOT);
  1631. if(tr.ent != world)
  1632. {
  1633. if(tr.ent->svflags & SVF_MONSTER || tr.ent->client || tr.ent->svflags & SVF_DAMAGEABLE)
  1634. {
  1635. if(tr.ent->health > 0)
  1636. enemy = tr.ent;
  1637. }
  1638. }
  1639. }
  1640. VectorScale (forward, -2, self->client->kick_origin);
  1641. self->client->kick_angles[0] = -1;
  1642. fire_tracker (self, start, forward, damage, 1000, enemy);
  1643. // send muzzle flash
  1644. gi.WriteByte (svc_muzzleflash);
  1645. gi.WriteShort (self-g_edicts);
  1646. gi.WriteByte (MZ_TRACKER);
  1647. gi.multicast (self->s.origin, MULTICAST_PVS);
  1648. PlayerNoise(self, start, PNOISE_WEAPON);
  1649. self->client->ps.gunframe++;
  1650. self->client->pers.inventory[self->client->ammo_index] -= self->client->pers.weapon->quantity;
  1651. }
  1652. void Weapon_Disintegrator (edict_t *ent)
  1653. {
  1654. static int pause_frames[] = {14, 19, 23, 0};
  1655. // static int fire_frames[] = {7, 0};
  1656. static int fire_frames[] = {5, 0};
  1657. Weapon_Generic (ent, 4, 9, 29, 34, pause_frames, fire_frames, weapon_tracker_fire);
  1658. }
  1659. /*
  1660. ======================================================================
  1661. ETF RIFLE
  1662. ======================================================================
  1663. */
  1664. void weapon_etf_rifle_fire (edict_t *ent)
  1665. {
  1666. vec3_t forward, right, up;
  1667. vec3_t start, tempPt;
  1668. int damage;
  1669. int kick = 3;
  1670. int i;
  1671. vec3_t angles;
  1672. vec3_t offset;
  1673. if(deathmatch->value)
  1674. damage = 10;
  1675. else
  1676. damage = 10;
  1677. // PGM - adjusted to use the quantity entry in the weapon structure.
  1678. if(ent->client->pers.inventory[ent->client->ammo_index] < ent->client->pers.weapon->quantity)
  1679. {
  1680. VectorClear (ent->client->kick_origin);
  1681. VectorClear (ent->client->kick_angles);
  1682. ent->client->ps.gunframe = 8;
  1683. if (level.time >= ent->pain_debounce_time)
  1684. {
  1685. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  1686. ent->pain_debounce_time = level.time + 1;
  1687. }
  1688. NoAmmoWeaponChange (ent);
  1689. return;
  1690. }
  1691. if (is_quad)
  1692. {
  1693. damage *= damage_multiplier;
  1694. kick *= damage_multiplier;
  1695. }
  1696. for(i=0;i<3;i++)
  1697. {
  1698. ent->client->kick_origin[i] = crandom() * 0.85;
  1699. ent->client->kick_angles[i] = crandom() * 0.85;
  1700. }
  1701. // get start / end positions
  1702. VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
  1703. // AngleVectors (angles, forward, right, NULL);
  1704. // gi.dprintf("v_angle: %s\n", vtos(ent->client->v_angle));
  1705. AngleVectors (ent->client->v_angle, forward, right, up);
  1706. // FIXME - set correct frames for different offsets.
  1707. if(ent->client->ps.gunframe == 6) // right barrel
  1708. {
  1709. // gi.dprintf("right\n");
  1710. VectorSet(offset, 15, 8, -8);
  1711. }
  1712. else // left barrel
  1713. {
  1714. // gi.dprintf("left\n");
  1715. VectorSet(offset, 15, 6, -8);
  1716. }
  1717. VectorCopy (ent->s.origin, tempPt);
  1718. tempPt[2] += ent->viewheight;
  1719. P_ProjectSource2 (ent->client, tempPt, offset, forward, right, up, start);
  1720. // gi.dprintf("start: %s\n", vtos(start));
  1721. fire_flechette (ent, start, forward, damage, 750, kick);
  1722. // send muzzle flash
  1723. gi.WriteByte (svc_muzzleflash);
  1724. gi.WriteShort (ent-g_edicts);
  1725. gi.WriteByte (MZ_ETF_RIFLE);
  1726. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1727. PlayerNoise(ent, start, PNOISE_WEAPON);
  1728. ent->client->ps.gunframe++;
  1729. ent->client->pers.inventory[ent->client->ammo_index] -= ent->client->pers.weapon->quantity;
  1730. ent->client->anim_priority = ANIM_ATTACK;
  1731. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  1732. {
  1733. ent->s.frame = FRAME_crattak1 - 1;
  1734. ent->client->anim_end = FRAME_crattak9;
  1735. }
  1736. else
  1737. {
  1738. ent->s.frame = FRAME_attack1 - 1;
  1739. ent->client->anim_end = FRAME_attack8;
  1740. }
  1741. }
  1742. void Weapon_ETF_Rifle (edict_t *ent)
  1743. {
  1744. static int pause_frames[] = {18, 28, 0};
  1745. static int fire_frames[] = {6, 7, 0};
  1746. // static int idle_seq;
  1747. // note - if you change the fire frame number, fix the offset in weapon_etf_rifle_fire.
  1748. // if (!(ent->client->buttons & BUTTON_ATTACK))
  1749. // ent->client->machinegun_shots = 0;
  1750. if (ent->client->weaponstate == WEAPON_FIRING)
  1751. {
  1752. if (ent->client->pers.inventory[ent->client->ammo_index] <= 0)
  1753. ent->client->ps.gunframe = 8;
  1754. }
  1755. Weapon_Generic (ent, 4, 7, 37, 41, pause_frames, fire_frames, weapon_etf_rifle_fire);
  1756. if(ent->client->ps.gunframe == 8 && (ent->client->buttons & BUTTON_ATTACK))
  1757. ent->client->ps.gunframe = 6;
  1758. // gi.dprintf("etf rifle %d\n", ent->client->ps.gunframe);
  1759. }
  1760. // pgm - this now uses ent->client->pers.weapon->quantity like all the other weapons
  1761. //#define HEATBEAM_AMMO_USE 2
  1762. #define HEATBEAM_DM_DMG 15
  1763. #define HEATBEAM_SP_DMG 15
  1764. void Heatbeam_Fire (edict_t *ent)
  1765. {
  1766. vec3_t start;
  1767. vec3_t forward, right, up;
  1768. vec3_t offset;
  1769. int damage;
  1770. int kick;
  1771. // for comparison, the hyperblaster is 15/20
  1772. // jim requested more damage, so try 15/15 --- PGM 07/23/98
  1773. if (deathmatch->value)
  1774. damage = HEATBEAM_DM_DMG;
  1775. else
  1776. damage = HEATBEAM_SP_DMG;
  1777. if (deathmatch->value) // really knock 'em around in deathmatch
  1778. kick = 75;
  1779. else
  1780. kick = 30;
  1781. // if(ent->client->pers.inventory[ent->client->ammo_index] < HEATBEAM_AMMO_USE)
  1782. // {
  1783. // NoAmmoWeaponChange (ent);
  1784. // return;
  1785. // }
  1786. ent->client->ps.gunframe++;
  1787. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_beamer2/tris.md2");
  1788. if (is_quad)
  1789. {
  1790. damage *= damage_multiplier;
  1791. kick *= damage_multiplier;
  1792. }
  1793. VectorClear (ent->client->kick_origin);
  1794. VectorClear (ent->client->kick_angles);
  1795. // get start / end positions
  1796. AngleVectors (ent->client->v_angle, forward, right, up);
  1797. // This offset is the "view" offset for the beam start (used by trace)
  1798. VectorSet(offset, 7, 2, ent->viewheight-3);
  1799. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1800. // This offset is the entity offset
  1801. VectorSet(offset, 2, 7, -3);
  1802. fire_heat (ent, start, forward, offset, damage, kick, false);
  1803. // send muzzle flash
  1804. gi.WriteByte (svc_muzzleflash);
  1805. gi.WriteShort (ent-g_edicts);
  1806. gi.WriteByte (MZ_HEATBEAM | is_silenced);
  1807. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1808. PlayerNoise(ent, start, PNOISE_WEAPON);
  1809. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1810. ent->client->pers.inventory[ent->client->ammo_index] -= ent->client->pers.weapon->quantity;
  1811. ent->client->anim_priority = ANIM_ATTACK;
  1812. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  1813. {
  1814. ent->s.frame = FRAME_crattak1 - 1;
  1815. ent->client->anim_end = FRAME_crattak9;
  1816. }
  1817. else
  1818. {
  1819. ent->s.frame = FRAME_attack1 - 1;
  1820. ent->client->anim_end = FRAME_attack8;
  1821. }
  1822. }
  1823. void Weapon_Heatbeam (edict_t *ent)
  1824. {
  1825. // static int pause_frames[] = {38, 43, 51, 61, 0};
  1826. // static int fire_frames[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
  1827. static int pause_frames[] = {35, 0};
  1828. // static int fire_frames[] = {9, 0};
  1829. static int fire_frames[] = {9, 10, 11, 12, 0};
  1830. // static int attack_index;
  1831. // static int off_model, on_model;
  1832. // if ((g_showlogic) && (g_showlogic->value)) {
  1833. // gi.dprintf ("Frame %d, skin %d\n", ent->client->ps.gunframe, ent->client->ps.gunskin);
  1834. // }
  1835. // if (!attack_index)
  1836. // {
  1837. // attack_index = gi.soundindex ("weapons/bfg__l1a.wav");
  1838. // off_model = gi.modelindex ("models/weapons/v_beamer/tris.md2");
  1839. // on_model = gi.modelindex ("models/weapons/v_beamer2/tris.md2");
  1840. //ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);
  1841. // }
  1842. if (ent->client->weaponstate == WEAPON_FIRING)
  1843. {
  1844. // ent->client->weapon_sound = attack_index;
  1845. ent->client->weapon_sound = gi.soundindex ("weapons/bfg__l1a.wav");
  1846. if ((ent->client->pers.inventory[ent->client->ammo_index] >= 2) && ((ent->client->buttons) & BUTTON_ATTACK))
  1847. {
  1848. // if(ent->client->ps.gunframe >= 9 && ((ent->client->buttons) & BUTTON_ATTACK))
  1849. // if(ent->client->ps.gunframe >= 12 && ((ent->client->buttons) & BUTTON_ATTACK))
  1850. if(ent->client->ps.gunframe >= 13)
  1851. {
  1852. ent->client->ps.gunframe = 9;
  1853. // ent->client->ps.gunframe = 8;
  1854. // ent->client->ps.gunskin = 0;
  1855. // ent->client->ps.gunindex = on_model;
  1856. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_beamer2/tris.md2");
  1857. }
  1858. else
  1859. {
  1860. // ent->client->ps.gunskin = 1;
  1861. // ent->client->ps.gunindex = on_model;
  1862. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_beamer2/tris.md2");
  1863. }
  1864. }
  1865. else
  1866. {
  1867. // ent->client->ps.gunframe = 10;
  1868. ent->client->ps.gunframe = 13;
  1869. // ent->client->ps.gunskin = 1;
  1870. // ent->client->ps.gunindex = off_model;
  1871. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_beamer/tris.md2");
  1872. }
  1873. }
  1874. else
  1875. {
  1876. // ent->client->ps.gunskin = 1;
  1877. // ent->client->ps.gunindex = off_model;
  1878. ent->client->ps.gunindex = gi.modelindex ("models/weapons/v_beamer/tris.md2");
  1879. ent->client->weapon_sound = 0;
  1880. }
  1881. // Weapon_Generic (ent, 8, 9, 39, 44, pause_frames, fire_frames, Heatbeam_Fire);
  1882. Weapon_Generic (ent, 8, 12, 39, 44, pause_frames, fire_frames, Heatbeam_Fire);
  1883. }