p_weapon.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // g_weapon.c
  16. #include "g_local.h"
  17. #include "m_player.h"
  18. static qboolean is_quad;
  19. static byte is_silenced;
  20. void weapon_grenade_fire (edict_t *ent, qboolean held);
  21. static void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
  22. {
  23. vec3_t _distance;
  24. VectorCopy (distance, _distance);
  25. if (client->pers.hand == LEFT_HANDED)
  26. _distance[1] *= -1;
  27. else if (client->pers.hand == CENTER_HANDED)
  28. _distance[1] = 0;
  29. G_ProjectSource (point, _distance, forward, right, result);
  30. }
  31. /*
  32. ===============
  33. PlayerNoise
  34. Each player can have two noise objects associated with it:
  35. a personal noise (jumping, pain, weapon firing), and a weapon
  36. target noise (bullet wall impacts)
  37. Monsters that don't directly see the player can move
  38. to a noise in hopes of seeing the player from there.
  39. ===============
  40. */
  41. void PlayerNoise(edict_t *who, vec3_t where, int type)
  42. {
  43. edict_t *noise;
  44. if (type == PNOISE_WEAPON)
  45. {
  46. if (who->client->silencer_shots)
  47. {
  48. who->client->silencer_shots--;
  49. return;
  50. }
  51. }
  52. if (deathmatch->value)
  53. return;
  54. if (who->flags & FL_NOTARGET)
  55. return;
  56. if (!who->mynoise)
  57. {
  58. noise = G_Spawn();
  59. noise->classname = "player_noise";
  60. VectorSet (noise->mins, -8, -8, -8);
  61. VectorSet (noise->maxs, 8, 8, 8);
  62. noise->owner = who;
  63. noise->svflags = SVF_NOCLIENT;
  64. who->mynoise = noise;
  65. noise = G_Spawn();
  66. noise->classname = "player_noise";
  67. VectorSet (noise->mins, -8, -8, -8);
  68. VectorSet (noise->maxs, 8, 8, 8);
  69. noise->owner = who;
  70. noise->svflags = SVF_NOCLIENT;
  71. who->mynoise2 = noise;
  72. }
  73. if (type == PNOISE_SELF || type == PNOISE_WEAPON)
  74. {
  75. noise = who->mynoise;
  76. level.sound_entity = noise;
  77. level.sound_entity_framenum = level.framenum;
  78. }
  79. else // type == PNOISE_IMPACT
  80. {
  81. noise = who->mynoise2;
  82. level.sound2_entity = noise;
  83. level.sound2_entity_framenum = level.framenum;
  84. }
  85. VectorCopy (where, noise->s.origin);
  86. VectorSubtract (where, noise->maxs, noise->absmin);
  87. VectorAdd (where, noise->maxs, noise->absmax);
  88. noise->teleport_time = level.time;
  89. gi.linkentity (noise);
  90. }
  91. qboolean Pickup_Weapon (edict_t *ent, edict_t *other)
  92. {
  93. int index;
  94. gitem_t *ammo;
  95. index = ITEM_INDEX(ent->item);
  96. if ( ( ((int)(dmflags->value) & DF_WEAPONS_STAY) || coop->value)
  97. && other->client->pers.inventory[index])
  98. {
  99. if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM) ) )
  100. return false; // leave the weapon for others to pickup
  101. }
  102. other->client->pers.inventory[index]++;
  103. if (!(ent->spawnflags & DROPPED_ITEM) )
  104. {
  105. // give them some ammo with it
  106. ammo = FindItem (ent->item->ammo);
  107. if ( (int)dmflags->value & DF_INFINITE_AMMO )
  108. Add_Ammo (other, ammo, 1000);
  109. else
  110. Add_Ammo (other, ammo, ammo->quantity);
  111. if (! (ent->spawnflags & DROPPED_PLAYER_ITEM) )
  112. {
  113. if (deathmatch->value)
  114. {
  115. if ((int)(dmflags->value) & DF_WEAPONS_STAY)
  116. ent->flags |= FL_RESPAWN;
  117. else
  118. SetRespawn (ent, 30);
  119. }
  120. if (coop->value)
  121. ent->flags |= FL_RESPAWN;
  122. }
  123. }
  124. if (other->client->pers.weapon != ent->item &&
  125. (other->client->pers.inventory[index] == 1) &&
  126. ( !deathmatch->value || other->client->pers.weapon == FindItem("blaster") ) )
  127. other->client->newweapon = ent->item;
  128. return true;
  129. }
  130. /*
  131. ===============
  132. ChangeWeapon
  133. The old weapon has been dropped all the way, so make the new one
  134. current
  135. ===============
  136. */
  137. void ChangeWeapon (edict_t *ent)
  138. {
  139. int i;
  140. if (ent->client->grenade_time)
  141. {
  142. ent->client->grenade_time = level.time;
  143. ent->client->weapon_sound = 0;
  144. weapon_grenade_fire (ent, false);
  145. ent->client->grenade_time = 0;
  146. }
  147. ent->client->pers.lastweapon = ent->client->pers.weapon;
  148. ent->client->pers.weapon = ent->client->newweapon;
  149. ent->client->newweapon = NULL;
  150. ent->client->machinegun_shots = 0;
  151. // set visible model
  152. if (ent->s.modelindex == 255) {
  153. if (ent->client->pers.weapon)
  154. i = ((ent->client->pers.weapon->weapmodel & 0xff) << 8);
  155. else
  156. i = 0;
  157. ent->s.skinnum = (ent - g_edicts - 1) | i;
  158. }
  159. if (ent->client->pers.weapon && ent->client->pers.weapon->ammo)
  160. ent->client->ammo_index = ITEM_INDEX(FindItem(ent->client->pers.weapon->ammo));
  161. else
  162. ent->client->ammo_index = 0;
  163. if (!ent->client->pers.weapon)
  164. { // dead
  165. ent->client->ps.gunindex = 0;
  166. return;
  167. }
  168. ent->client->weaponstate = WEAPON_ACTIVATING;
  169. ent->client->ps.gunframe = 0;
  170. ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);
  171. ent->client->anim_priority = ANIM_PAIN;
  172. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  173. {
  174. ent->s.frame = FRAME_crpain1;
  175. ent->client->anim_end = FRAME_crpain4;
  176. }
  177. else
  178. {
  179. ent->s.frame = FRAME_pain301;
  180. ent->client->anim_end = FRAME_pain304;
  181. }
  182. }
  183. /*
  184. =================
  185. NoAmmoWeaponChange
  186. =================
  187. */
  188. void NoAmmoWeaponChange (edict_t *ent)
  189. {
  190. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("slugs"))]
  191. && ent->client->pers.inventory[ITEM_INDEX(FindItem("railgun"))] )
  192. {
  193. ent->client->newweapon = FindItem ("railgun");
  194. return;
  195. }
  196. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("cells"))]
  197. && ent->client->pers.inventory[ITEM_INDEX(FindItem("hyperblaster"))] )
  198. {
  199. ent->client->newweapon = FindItem ("hyperblaster");
  200. return;
  201. }
  202. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
  203. && ent->client->pers.inventory[ITEM_INDEX(FindItem("chaingun"))] )
  204. {
  205. ent->client->newweapon = FindItem ("chaingun");
  206. return;
  207. }
  208. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("bullets"))]
  209. && ent->client->pers.inventory[ITEM_INDEX(FindItem("machinegun"))] )
  210. {
  211. ent->client->newweapon = FindItem ("machinegun");
  212. return;
  213. }
  214. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))] > 1
  215. && ent->client->pers.inventory[ITEM_INDEX(FindItem("super shotgun"))] )
  216. {
  217. ent->client->newweapon = FindItem ("super shotgun");
  218. return;
  219. }
  220. if ( ent->client->pers.inventory[ITEM_INDEX(FindItem("shells"))]
  221. && ent->client->pers.inventory[ITEM_INDEX(FindItem("shotgun"))] )
  222. {
  223. ent->client->newweapon = FindItem ("shotgun");
  224. return;
  225. }
  226. ent->client->newweapon = FindItem ("blaster");
  227. }
  228. /*
  229. =================
  230. Think_Weapon
  231. Called by ClientBeginServerFrame and ClientThink
  232. =================
  233. */
  234. void Think_Weapon (edict_t *ent)
  235. {
  236. // if just died, put the weapon away
  237. if (ent->health < 1)
  238. {
  239. ent->client->newweapon = NULL;
  240. ChangeWeapon (ent);
  241. }
  242. // call active weapon think routine
  243. if (ent->client->pers.weapon && ent->client->pers.weapon->weaponthink)
  244. {
  245. is_quad = (ent->client->quad_framenum > level.framenum);
  246. if (ent->client->silencer_shots)
  247. is_silenced = MZ_SILENCED;
  248. else
  249. is_silenced = 0;
  250. ent->client->pers.weapon->weaponthink (ent);
  251. }
  252. }
  253. /*
  254. ================
  255. Use_Weapon
  256. Make the weapon ready if there is ammo
  257. ================
  258. */
  259. void Use_Weapon (edict_t *ent, gitem_t *item)
  260. {
  261. int ammo_index;
  262. gitem_t *ammo_item;
  263. // see if we're already using it
  264. if (item == ent->client->pers.weapon)
  265. return;
  266. if (item->ammo && !g_select_empty->value && !(item->flags & IT_AMMO))
  267. {
  268. ammo_item = FindItem(item->ammo);
  269. ammo_index = ITEM_INDEX(ammo_item);
  270. if (!ent->client->pers.inventory[ammo_index])
  271. {
  272. gi.cprintf (ent, PRINT_HIGH, "No %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
  273. return;
  274. }
  275. if (ent->client->pers.inventory[ammo_index] < item->quantity)
  276. {
  277. gi.cprintf (ent, PRINT_HIGH, "Not enough %s for %s.\n", ammo_item->pickup_name, item->pickup_name);
  278. return;
  279. }
  280. }
  281. // change to this weapon when down
  282. ent->client->newweapon = item;
  283. }
  284. /*
  285. ================
  286. Drop_Weapon
  287. ================
  288. */
  289. void Drop_Weapon (edict_t *ent, gitem_t *item)
  290. {
  291. int index;
  292. if ((int)(dmflags->value) & DF_WEAPONS_STAY)
  293. return;
  294. index = ITEM_INDEX(item);
  295. // see if we're already using it
  296. if ( ((item == ent->client->pers.weapon) || (item == ent->client->newweapon))&& (ent->client->pers.inventory[index] == 1) )
  297. {
  298. gi.cprintf (ent, PRINT_HIGH, "Can't drop current weapon\n");
  299. return;
  300. }
  301. Drop_Item (ent, item);
  302. ent->client->pers.inventory[index]--;
  303. }
  304. /*
  305. ================
  306. Weapon_Generic
  307. A generic function to handle the basics of weapon thinking
  308. ================
  309. */
  310. #define FRAME_FIRE_FIRST (FRAME_ACTIVATE_LAST + 1)
  311. #define FRAME_IDLE_FIRST (FRAME_FIRE_LAST + 1)
  312. #define FRAME_DEACTIVATE_FIRST (FRAME_IDLE_LAST + 1)
  313. 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))
  314. {
  315. int n;
  316. if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
  317. {
  318. return;
  319. }
  320. if (ent->client->weaponstate == WEAPON_DROPPING)
  321. {
  322. if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST)
  323. {
  324. ChangeWeapon (ent);
  325. return;
  326. }
  327. else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4)
  328. {
  329. ent->client->anim_priority = ANIM_REVERSE;
  330. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  331. {
  332. ent->s.frame = FRAME_crpain4+1;
  333. ent->client->anim_end = FRAME_crpain1;
  334. }
  335. else
  336. {
  337. ent->s.frame = FRAME_pain304+1;
  338. ent->client->anim_end = FRAME_pain301;
  339. }
  340. }
  341. ent->client->ps.gunframe++;
  342. return;
  343. }
  344. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  345. {
  346. if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST)
  347. {
  348. ent->client->weaponstate = WEAPON_READY;
  349. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  350. return;
  351. }
  352. ent->client->ps.gunframe++;
  353. return;
  354. }
  355. if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
  356. {
  357. ent->client->weaponstate = WEAPON_DROPPING;
  358. ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
  359. if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
  360. {
  361. ent->client->anim_priority = ANIM_REVERSE;
  362. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  363. {
  364. ent->s.frame = FRAME_crpain4+1;
  365. ent->client->anim_end = FRAME_crpain1;
  366. }
  367. else
  368. {
  369. ent->s.frame = FRAME_pain304+1;
  370. ent->client->anim_end = FRAME_pain301;
  371. }
  372. }
  373. return;
  374. }
  375. if (ent->client->weaponstate == WEAPON_READY)
  376. {
  377. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  378. {
  379. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  380. if ((!ent->client->ammo_index) ||
  381. ( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
  382. {
  383. ent->client->ps.gunframe = FRAME_FIRE_FIRST;
  384. ent->client->weaponstate = WEAPON_FIRING;
  385. // start the animation
  386. ent->client->anim_priority = ANIM_ATTACK;
  387. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  388. {
  389. ent->s.frame = FRAME_crattak1-1;
  390. ent->client->anim_end = FRAME_crattak9;
  391. }
  392. else
  393. {
  394. ent->s.frame = FRAME_attack1-1;
  395. ent->client->anim_end = FRAME_attack8;
  396. }
  397. }
  398. else
  399. {
  400. if (level.time >= ent->pain_debounce_time)
  401. {
  402. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  403. ent->pain_debounce_time = level.time + 1;
  404. }
  405. NoAmmoWeaponChange (ent);
  406. }
  407. }
  408. else
  409. {
  410. if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
  411. {
  412. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  413. return;
  414. }
  415. if (pause_frames)
  416. {
  417. for (n = 0; pause_frames[n]; n++)
  418. {
  419. if (ent->client->ps.gunframe == pause_frames[n])
  420. {
  421. if (rand()&15)
  422. return;
  423. }
  424. }
  425. }
  426. ent->client->ps.gunframe++;
  427. return;
  428. }
  429. }
  430. if (ent->client->weaponstate == WEAPON_FIRING)
  431. {
  432. for (n = 0; fire_frames[n]; n++)
  433. {
  434. if (ent->client->ps.gunframe == fire_frames[n])
  435. {
  436. if (ent->client->quad_framenum > level.framenum)
  437. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);
  438. fire (ent);
  439. break;
  440. }
  441. }
  442. if (!fire_frames[n])
  443. ent->client->ps.gunframe++;
  444. if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
  445. ent->client->weaponstate = WEAPON_READY;
  446. }
  447. }
  448. /*
  449. ======================================================================
  450. GRENADE
  451. ======================================================================
  452. */
  453. #define GRENADE_TIMER 3.0
  454. #define GRENADE_MINSPEED 400
  455. #define GRENADE_MAXSPEED 800
  456. void weapon_grenade_fire (edict_t *ent, qboolean held)
  457. {
  458. vec3_t offset;
  459. vec3_t forward, right;
  460. vec3_t start;
  461. int damage = 125;
  462. float timer;
  463. int speed;
  464. float radius;
  465. radius = damage+40;
  466. if (is_quad)
  467. damage *= 4;
  468. VectorSet(offset, 8, 8, ent->viewheight-8);
  469. AngleVectors (ent->client->v_angle, forward, right, NULL);
  470. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  471. timer = ent->client->grenade_time - level.time;
  472. speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER);
  473. fire_grenade2 (ent, start, forward, damage, speed, timer, radius, held);
  474. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  475. ent->client->pers.inventory[ent->client->ammo_index]--;
  476. ent->client->grenade_time = level.time + 1.0;
  477. if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
  478. {
  479. return;
  480. }
  481. if (ent->health <= 0)
  482. return;
  483. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  484. {
  485. ent->client->anim_priority = ANIM_ATTACK;
  486. ent->s.frame = FRAME_crattak1-1;
  487. ent->client->anim_end = FRAME_crattak3;
  488. }
  489. else
  490. {
  491. ent->client->anim_priority = ANIM_REVERSE;
  492. ent->s.frame = FRAME_wave08;
  493. ent->client->anim_end = FRAME_wave01;
  494. }
  495. }
  496. void Weapon_Grenade (edict_t *ent)
  497. {
  498. if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
  499. {
  500. ChangeWeapon (ent);
  501. return;
  502. }
  503. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  504. {
  505. ent->client->weaponstate = WEAPON_READY;
  506. ent->client->ps.gunframe = 16;
  507. return;
  508. }
  509. if (ent->client->weaponstate == WEAPON_READY)
  510. {
  511. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  512. {
  513. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  514. if (ent->client->pers.inventory[ent->client->ammo_index])
  515. {
  516. ent->client->ps.gunframe = 1;
  517. ent->client->weaponstate = WEAPON_FIRING;
  518. ent->client->grenade_time = 0;
  519. }
  520. else
  521. {
  522. if (level.time >= ent->pain_debounce_time)
  523. {
  524. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  525. ent->pain_debounce_time = level.time + 1;
  526. }
  527. NoAmmoWeaponChange (ent);
  528. }
  529. return;
  530. }
  531. if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48))
  532. {
  533. if (rand()&15)
  534. return;
  535. }
  536. if (++ent->client->ps.gunframe > 48)
  537. ent->client->ps.gunframe = 16;
  538. return;
  539. }
  540. if (ent->client->weaponstate == WEAPON_FIRING)
  541. {
  542. if (ent->client->ps.gunframe == 5)
  543. gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);
  544. if (ent->client->ps.gunframe == 11)
  545. {
  546. if (!ent->client->grenade_time)
  547. {
  548. ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
  549. ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
  550. }
  551. // they waited too long, detonate it in their hand
  552. if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
  553. {
  554. ent->client->weapon_sound = 0;
  555. weapon_grenade_fire (ent, true);
  556. ent->client->grenade_blew_up = true;
  557. }
  558. if (ent->client->buttons & BUTTON_ATTACK)
  559. return;
  560. if (ent->client->grenade_blew_up)
  561. {
  562. if (level.time >= ent->client->grenade_time)
  563. {
  564. ent->client->ps.gunframe = 15;
  565. ent->client->grenade_blew_up = false;
  566. }
  567. else
  568. {
  569. return;
  570. }
  571. }
  572. }
  573. if (ent->client->ps.gunframe == 12)
  574. {
  575. ent->client->weapon_sound = 0;
  576. weapon_grenade_fire (ent, false);
  577. }
  578. if ((ent->client->ps.gunframe == 15) && (level.time < ent->client->grenade_time))
  579. return;
  580. ent->client->ps.gunframe++;
  581. if (ent->client->ps.gunframe == 16)
  582. {
  583. ent->client->grenade_time = 0;
  584. ent->client->weaponstate = WEAPON_READY;
  585. }
  586. }
  587. }
  588. /*
  589. ======================================================================
  590. GRENADE LAUNCHER
  591. ======================================================================
  592. */
  593. void weapon_grenadelauncher_fire (edict_t *ent)
  594. {
  595. vec3_t offset;
  596. vec3_t forward, right;
  597. vec3_t start;
  598. int damage = 120;
  599. float radius;
  600. radius = damage+40;
  601. if (is_quad)
  602. damage *= 4;
  603. VectorSet(offset, 8, 8, ent->viewheight-8);
  604. AngleVectors (ent->client->v_angle, forward, right, NULL);
  605. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  606. VectorScale (forward, -2, ent->client->kick_origin);
  607. ent->client->kick_angles[0] = -1;
  608. fire_grenade (ent, start, forward, damage, 600, 2.5, radius);
  609. gi.WriteByte (svc_muzzleflash);
  610. gi.WriteShort (ent-g_edicts);
  611. gi.WriteByte (MZ_GRENADE | is_silenced);
  612. gi.multicast (ent->s.origin, MULTICAST_PVS);
  613. ent->client->ps.gunframe++;
  614. PlayerNoise(ent, start, PNOISE_WEAPON);
  615. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  616. ent->client->pers.inventory[ent->client->ammo_index]--;
  617. }
  618. void Weapon_GrenadeLauncher (edict_t *ent)
  619. {
  620. static int pause_frames[] = {34, 51, 59, 0};
  621. static int fire_frames[] = {6, 0};
  622. Weapon_Generic (ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
  623. }
  624. /*
  625. ======================================================================
  626. ROCKET
  627. ======================================================================
  628. */
  629. void Weapon_RocketLauncher_Fire (edict_t *ent)
  630. {
  631. vec3_t offset, start;
  632. vec3_t forward, right;
  633. int damage;
  634. float damage_radius;
  635. int radius_damage;
  636. damage = 100 + (int)(random() * 20.0);
  637. radius_damage = 120;
  638. damage_radius = 120;
  639. if (is_quad)
  640. {
  641. damage *= 4;
  642. radius_damage *= 4;
  643. }
  644. AngleVectors (ent->client->v_angle, forward, right, NULL);
  645. VectorScale (forward, -2, ent->client->kick_origin);
  646. ent->client->kick_angles[0] = -1;
  647. VectorSet(offset, 8, 8, ent->viewheight-8);
  648. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  649. fire_rocket (ent, start, forward, damage, 650, damage_radius, radius_damage);
  650. // send muzzle flash
  651. gi.WriteByte (svc_muzzleflash);
  652. gi.WriteShort (ent-g_edicts);
  653. gi.WriteByte (MZ_ROCKET | is_silenced);
  654. gi.multicast (ent->s.origin, MULTICAST_PVS);
  655. ent->client->ps.gunframe++;
  656. PlayerNoise(ent, start, PNOISE_WEAPON);
  657. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  658. ent->client->pers.inventory[ent->client->ammo_index]--;
  659. }
  660. void Weapon_RocketLauncher (edict_t *ent)
  661. {
  662. static int pause_frames[] = {25, 33, 42, 50, 0};
  663. static int fire_frames[] = {5, 0};
  664. Weapon_Generic (ent, 4, 12, 50, 54, pause_frames, fire_frames, Weapon_RocketLauncher_Fire);
  665. }
  666. /*
  667. ======================================================================
  668. BLASTER / HYPERBLASTER
  669. ======================================================================
  670. */
  671. void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, int effect)
  672. {
  673. vec3_t forward, right;
  674. vec3_t start;
  675. vec3_t offset;
  676. if (is_quad)
  677. damage *= 4;
  678. AngleVectors (ent->client->v_angle, forward, right, NULL);
  679. VectorSet(offset, 24, 8, ent->viewheight-8);
  680. VectorAdd (offset, g_offset, offset);
  681. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  682. VectorScale (forward, -2, ent->client->kick_origin);
  683. ent->client->kick_angles[0] = -1;
  684. fire_blaster (ent, start, forward, damage, 1000, effect, hyper);
  685. // send muzzle flash
  686. gi.WriteByte (svc_muzzleflash);
  687. gi.WriteShort (ent-g_edicts);
  688. if (hyper)
  689. gi.WriteByte (MZ_HYPERBLASTER | is_silenced);
  690. else
  691. gi.WriteByte (MZ_BLASTER | is_silenced);
  692. gi.multicast (ent->s.origin, MULTICAST_PVS);
  693. PlayerNoise(ent, start, PNOISE_WEAPON);
  694. }
  695. void Weapon_Blaster_Fire (edict_t *ent)
  696. {
  697. int damage;
  698. if (deathmatch->value)
  699. damage = 15;
  700. else
  701. damage = 10;
  702. Blaster_Fire (ent, vec3_origin, damage, false, EF_BLASTER);
  703. ent->client->ps.gunframe++;
  704. }
  705. void Weapon_Blaster (edict_t *ent)
  706. {
  707. static int pause_frames[] = {19, 32, 0};
  708. static int fire_frames[] = {5, 0};
  709. Weapon_Generic (ent, 4, 8, 52, 55, pause_frames, fire_frames, Weapon_Blaster_Fire);
  710. }
  711. void Weapon_HyperBlaster_Fire (edict_t *ent)
  712. {
  713. float rotation;
  714. vec3_t offset;
  715. int effect;
  716. int damage;
  717. ent->client->weapon_sound = gi.soundindex("weapons/hyprbl1a.wav");
  718. if (!(ent->client->buttons & BUTTON_ATTACK))
  719. {
  720. ent->client->ps.gunframe++;
  721. }
  722. else
  723. {
  724. if (! ent->client->pers.inventory[ent->client->ammo_index] )
  725. {
  726. if (level.time >= ent->pain_debounce_time)
  727. {
  728. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  729. ent->pain_debounce_time = level.time + 1;
  730. }
  731. NoAmmoWeaponChange (ent);
  732. }
  733. else
  734. {
  735. rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
  736. offset[0] = -4 * sin(rotation);
  737. offset[1] = 0;
  738. offset[2] = 4 * cos(rotation);
  739. if ((ent->client->ps.gunframe == 6) || (ent->client->ps.gunframe == 9))
  740. effect = EF_HYPERBLASTER;
  741. else
  742. effect = 0;
  743. if (deathmatch->value)
  744. damage = 15;
  745. else
  746. damage = 20;
  747. Blaster_Fire (ent, offset, damage, true, effect);
  748. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  749. ent->client->pers.inventory[ent->client->ammo_index]--;
  750. ent->client->anim_priority = ANIM_ATTACK;
  751. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  752. {
  753. ent->s.frame = FRAME_crattak1 - 1;
  754. ent->client->anim_end = FRAME_crattak9;
  755. }
  756. else
  757. {
  758. ent->s.frame = FRAME_attack1 - 1;
  759. ent->client->anim_end = FRAME_attack8;
  760. }
  761. }
  762. ent->client->ps.gunframe++;
  763. if (ent->client->ps.gunframe == 12 && ent->client->pers.inventory[ent->client->ammo_index])
  764. ent->client->ps.gunframe = 6;
  765. }
  766. if (ent->client->ps.gunframe == 12)
  767. {
  768. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/hyprbd1a.wav"), 1, ATTN_NORM, 0);
  769. ent->client->weapon_sound = 0;
  770. }
  771. }
  772. void Weapon_HyperBlaster (edict_t *ent)
  773. {
  774. static int pause_frames[] = {0};
  775. static int fire_frames[] = {6, 7, 8, 9, 10, 11, 0};
  776. Weapon_Generic (ent, 5, 20, 49, 53, pause_frames, fire_frames, Weapon_HyperBlaster_Fire);
  777. }
  778. /*
  779. ======================================================================
  780. MACHINEGUN / CHAINGUN
  781. ======================================================================
  782. */
  783. void Machinegun_Fire (edict_t *ent)
  784. {
  785. int i;
  786. vec3_t start;
  787. vec3_t forward, right;
  788. vec3_t angles;
  789. int damage = 8;
  790. int kick = 2;
  791. vec3_t offset;
  792. if (!(ent->client->buttons & BUTTON_ATTACK))
  793. {
  794. ent->client->machinegun_shots = 0;
  795. ent->client->ps.gunframe++;
  796. return;
  797. }
  798. if (ent->client->ps.gunframe == 5)
  799. ent->client->ps.gunframe = 4;
  800. else
  801. ent->client->ps.gunframe = 5;
  802. if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
  803. {
  804. ent->client->ps.gunframe = 6;
  805. if (level.time >= ent->pain_debounce_time)
  806. {
  807. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  808. ent->pain_debounce_time = level.time + 1;
  809. }
  810. NoAmmoWeaponChange (ent);
  811. return;
  812. }
  813. if (is_quad)
  814. {
  815. damage *= 4;
  816. kick *= 4;
  817. }
  818. for (i=1 ; i<3 ; i++)
  819. {
  820. ent->client->kick_origin[i] = crandom() * 0.35;
  821. ent->client->kick_angles[i] = crandom() * 0.7;
  822. }
  823. ent->client->kick_origin[0] = crandom() * 0.35;
  824. ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;
  825. // raise the gun as it is firing
  826. if (!deathmatch->value)
  827. {
  828. ent->client->machinegun_shots++;
  829. if (ent->client->machinegun_shots > 9)
  830. ent->client->machinegun_shots = 9;
  831. }
  832. // get start / end positions
  833. VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
  834. AngleVectors (angles, forward, right, NULL);
  835. VectorSet(offset, 0, 8, ent->viewheight-8);
  836. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  837. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
  838. gi.WriteByte (svc_muzzleflash);
  839. gi.WriteShort (ent-g_edicts);
  840. gi.WriteByte (MZ_MACHINEGUN | is_silenced);
  841. gi.multicast (ent->s.origin, MULTICAST_PVS);
  842. PlayerNoise(ent, start, PNOISE_WEAPON);
  843. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  844. ent->client->pers.inventory[ent->client->ammo_index]--;
  845. ent->client->anim_priority = ANIM_ATTACK;
  846. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  847. {
  848. ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
  849. ent->client->anim_end = FRAME_crattak9;
  850. }
  851. else
  852. {
  853. ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
  854. ent->client->anim_end = FRAME_attack8;
  855. }
  856. }
  857. void Weapon_Machinegun (edict_t *ent)
  858. {
  859. static int pause_frames[] = {23, 45, 0};
  860. static int fire_frames[] = {4, 5, 0};
  861. Weapon_Generic (ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
  862. }
  863. void Chaingun_Fire (edict_t *ent)
  864. {
  865. int i;
  866. int shots;
  867. vec3_t start;
  868. vec3_t forward, right, up;
  869. float r, u;
  870. vec3_t offset;
  871. int damage;
  872. int kick = 2;
  873. if (deathmatch->value)
  874. damage = 6;
  875. else
  876. damage = 8;
  877. if (ent->client->ps.gunframe == 5)
  878. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);
  879. if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
  880. {
  881. ent->client->ps.gunframe = 32;
  882. ent->client->weapon_sound = 0;
  883. return;
  884. }
  885. else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
  886. && ent->client->pers.inventory[ent->client->ammo_index])
  887. {
  888. ent->client->ps.gunframe = 15;
  889. }
  890. else
  891. {
  892. ent->client->ps.gunframe++;
  893. }
  894. if (ent->client->ps.gunframe == 22)
  895. {
  896. ent->client->weapon_sound = 0;
  897. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
  898. }
  899. else
  900. {
  901. ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
  902. }
  903. ent->client->anim_priority = ANIM_ATTACK;
  904. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  905. {
  906. ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
  907. ent->client->anim_end = FRAME_crattak9;
  908. }
  909. else
  910. {
  911. ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
  912. ent->client->anim_end = FRAME_attack8;
  913. }
  914. if (ent->client->ps.gunframe <= 9)
  915. shots = 1;
  916. else if (ent->client->ps.gunframe <= 14)
  917. {
  918. if (ent->client->buttons & BUTTON_ATTACK)
  919. shots = 2;
  920. else
  921. shots = 1;
  922. }
  923. else
  924. shots = 3;
  925. if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
  926. shots = ent->client->pers.inventory[ent->client->ammo_index];
  927. if (!shots)
  928. {
  929. if (level.time >= ent->pain_debounce_time)
  930. {
  931. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  932. ent->pain_debounce_time = level.time + 1;
  933. }
  934. NoAmmoWeaponChange (ent);
  935. return;
  936. }
  937. if (is_quad)
  938. {
  939. damage *= 4;
  940. kick *= 4;
  941. }
  942. for (i=0 ; i<3 ; i++)
  943. {
  944. ent->client->kick_origin[i] = crandom() * 0.35;
  945. ent->client->kick_angles[i] = crandom() * 0.7;
  946. }
  947. for (i=0 ; i<shots ; i++)
  948. {
  949. // get start / end positions
  950. AngleVectors (ent->client->v_angle, forward, right, up);
  951. r = 7 + crandom()*4;
  952. u = crandom()*4;
  953. VectorSet(offset, 0, r, u + ent->viewheight-8);
  954. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  955. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
  956. }
  957. // send muzzle flash
  958. gi.WriteByte (svc_muzzleflash);
  959. gi.WriteShort (ent-g_edicts);
  960. gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
  961. gi.multicast (ent->s.origin, MULTICAST_PVS);
  962. PlayerNoise(ent, start, PNOISE_WEAPON);
  963. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  964. ent->client->pers.inventory[ent->client->ammo_index] -= shots;
  965. }
  966. void Weapon_Chaingun (edict_t *ent)
  967. {
  968. static int pause_frames[] = {38, 43, 51, 61, 0};
  969. static int fire_frames[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
  970. Weapon_Generic (ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
  971. }
  972. /*
  973. ======================================================================
  974. SHOTGUN / SUPERSHOTGUN
  975. ======================================================================
  976. */
  977. void weapon_shotgun_fire (edict_t *ent)
  978. {
  979. vec3_t start;
  980. vec3_t forward, right;
  981. vec3_t offset;
  982. int damage = 4;
  983. int kick = 8;
  984. if (ent->client->ps.gunframe == 9)
  985. {
  986. ent->client->ps.gunframe++;
  987. return;
  988. }
  989. AngleVectors (ent->client->v_angle, forward, right, NULL);
  990. VectorScale (forward, -2, ent->client->kick_origin);
  991. ent->client->kick_angles[0] = -2;
  992. VectorSet(offset, 0, 8, ent->viewheight-8);
  993. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  994. if (is_quad)
  995. {
  996. damage *= 4;
  997. kick *= 4;
  998. }
  999. if (deathmatch->value)
  1000. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN);
  1001. else
  1002. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);
  1003. // send muzzle flash
  1004. gi.WriteByte (svc_muzzleflash);
  1005. gi.WriteShort (ent-g_edicts);
  1006. gi.WriteByte (MZ_SHOTGUN | is_silenced);
  1007. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1008. ent->client->ps.gunframe++;
  1009. PlayerNoise(ent, start, PNOISE_WEAPON);
  1010. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1011. ent->client->pers.inventory[ent->client->ammo_index]--;
  1012. }
  1013. void Weapon_Shotgun (edict_t *ent)
  1014. {
  1015. static int pause_frames[] = {22, 28, 34, 0};
  1016. static int fire_frames[] = {8, 9, 0};
  1017. Weapon_Generic (ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
  1018. }
  1019. void weapon_supershotgun_fire (edict_t *ent)
  1020. {
  1021. vec3_t start;
  1022. vec3_t forward, right;
  1023. vec3_t offset;
  1024. vec3_t v;
  1025. int damage = 6;
  1026. int kick = 12;
  1027. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1028. VectorScale (forward, -2, ent->client->kick_origin);
  1029. ent->client->kick_angles[0] = -2;
  1030. VectorSet(offset, 0, 8, ent->viewheight-8);
  1031. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1032. if (is_quad)
  1033. {
  1034. damage *= 4;
  1035. kick *= 4;
  1036. }
  1037. v[PITCH] = ent->client->v_angle[PITCH];
  1038. v[YAW] = ent->client->v_angle[YAW] - 5;
  1039. v[ROLL] = ent->client->v_angle[ROLL];
  1040. AngleVectors (v, forward, NULL, NULL);
  1041. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1042. v[YAW] = ent->client->v_angle[YAW] + 5;
  1043. AngleVectors (v, forward, NULL, NULL);
  1044. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1045. // send muzzle flash
  1046. gi.WriteByte (svc_muzzleflash);
  1047. gi.WriteShort (ent-g_edicts);
  1048. gi.WriteByte (MZ_SSHOTGUN | is_silenced);
  1049. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1050. ent->client->ps.gunframe++;
  1051. PlayerNoise(ent, start, PNOISE_WEAPON);
  1052. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1053. ent->client->pers.inventory[ent->client->ammo_index] -= 2;
  1054. }
  1055. void Weapon_SuperShotgun (edict_t *ent)
  1056. {
  1057. static int pause_frames[] = {29, 42, 57, 0};
  1058. static int fire_frames[] = {7, 0};
  1059. Weapon_Generic (ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
  1060. }
  1061. /*
  1062. ======================================================================
  1063. RAILGUN
  1064. ======================================================================
  1065. */
  1066. void weapon_railgun_fire (edict_t *ent)
  1067. {
  1068. vec3_t start;
  1069. vec3_t forward, right;
  1070. vec3_t offset;
  1071. int damage;
  1072. int kick;
  1073. if (deathmatch->value)
  1074. { // normal damage is too extreme in dm
  1075. damage = 100;
  1076. kick = 200;
  1077. }
  1078. else
  1079. {
  1080. damage = 150;
  1081. kick = 250;
  1082. }
  1083. if (is_quad)
  1084. {
  1085. damage *= 4;
  1086. kick *= 4;
  1087. }
  1088. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1089. VectorScale (forward, -3, ent->client->kick_origin);
  1090. ent->client->kick_angles[0] = -3;
  1091. VectorSet(offset, 0, 7, ent->viewheight-8);
  1092. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1093. fire_rail (ent, start, forward, damage, kick);
  1094. // send muzzle flash
  1095. gi.WriteByte (svc_muzzleflash);
  1096. gi.WriteShort (ent-g_edicts);
  1097. gi.WriteByte (MZ_RAILGUN | is_silenced);
  1098. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1099. ent->client->ps.gunframe++;
  1100. PlayerNoise(ent, start, PNOISE_WEAPON);
  1101. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1102. ent->client->pers.inventory[ent->client->ammo_index]--;
  1103. }
  1104. void Weapon_Railgun (edict_t *ent)
  1105. {
  1106. static int pause_frames[] = {56, 0};
  1107. static int fire_frames[] = {4, 0};
  1108. Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
  1109. }
  1110. /*
  1111. ======================================================================
  1112. BFG10K
  1113. ======================================================================
  1114. */
  1115. void weapon_bfg_fire (edict_t *ent)
  1116. {
  1117. vec3_t offset, start;
  1118. vec3_t forward, right;
  1119. int damage;
  1120. float damage_radius = 1000;
  1121. if (deathmatch->value)
  1122. damage = 200;
  1123. else
  1124. damage = 500;
  1125. if (ent->client->ps.gunframe == 9)
  1126. {
  1127. // send muzzle flash
  1128. gi.WriteByte (svc_muzzleflash);
  1129. gi.WriteShort (ent-g_edicts);
  1130. gi.WriteByte (MZ_BFG | is_silenced);
  1131. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1132. ent->client->ps.gunframe++;
  1133. PlayerNoise(ent, ent->s.origin, PNOISE_WEAPON);
  1134. return;
  1135. }
  1136. // cells can go down during windup (from power armor hits), so
  1137. // check again and abort firing if we don't have enough now
  1138. if (ent->client->pers.inventory[ent->client->ammo_index] < 50)
  1139. {
  1140. ent->client->ps.gunframe++;
  1141. return;
  1142. }
  1143. if (is_quad)
  1144. damage *= 4;
  1145. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1146. VectorScale (forward, -2, ent->client->kick_origin);
  1147. // make a big pitch kick with an inverse fall
  1148. ent->client->v_dmg_pitch = -40;
  1149. ent->client->v_dmg_roll = crandom()*8;
  1150. ent->client->v_dmg_time = level.time + DAMAGE_TIME;
  1151. VectorSet(offset, 8, 8, ent->viewheight-8);
  1152. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1153. fire_bfg (ent, start, forward, damage, 400, damage_radius);
  1154. ent->client->ps.gunframe++;
  1155. PlayerNoise(ent, start, PNOISE_WEAPON);
  1156. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1157. ent->client->pers.inventory[ent->client->ammo_index] -= 50;
  1158. }
  1159. void Weapon_BFG (edict_t *ent)
  1160. {
  1161. static int pause_frames[] = {39, 45, 50, 55, 0};
  1162. static int fire_frames[] = {9, 17, 0};
  1163. Weapon_Generic (ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
  1164. }
  1165. //======================================================================