p_weapon.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. 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. static void Weapon_Generic2 (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 || instantweap->value)
  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. if (instantweap->value) {
  359. ChangeWeapon(ent);
  360. return;
  361. } else
  362. ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
  363. if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
  364. {
  365. ent->client->anim_priority = ANIM_REVERSE;
  366. if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  367. {
  368. ent->s.frame = FRAME_crpain4+1;
  369. ent->client->anim_end = FRAME_crpain1;
  370. }
  371. else
  372. {
  373. ent->s.frame = FRAME_pain304+1;
  374. ent->client->anim_end = FRAME_pain301;
  375. }
  376. }
  377. return;
  378. }
  379. if (ent->client->weaponstate == WEAPON_READY)
  380. {
  381. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  382. {
  383. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  384. if ((!ent->client->ammo_index) ||
  385. ( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
  386. {
  387. ent->client->ps.gunframe = FRAME_FIRE_FIRST;
  388. ent->client->weaponstate = WEAPON_FIRING;
  389. // start the animation
  390. ent->client->anim_priority = ANIM_ATTACK;
  391. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  392. {
  393. ent->s.frame = FRAME_crattak1-1;
  394. ent->client->anim_end = FRAME_crattak9;
  395. }
  396. else
  397. {
  398. ent->s.frame = FRAME_attack1-1;
  399. ent->client->anim_end = FRAME_attack8;
  400. }
  401. }
  402. else
  403. {
  404. if (level.time >= ent->pain_debounce_time)
  405. {
  406. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  407. ent->pain_debounce_time = level.time + 1;
  408. }
  409. NoAmmoWeaponChange (ent);
  410. }
  411. }
  412. else
  413. {
  414. if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
  415. {
  416. ent->client->ps.gunframe = FRAME_IDLE_FIRST;
  417. return;
  418. }
  419. if (pause_frames)
  420. {
  421. for (n = 0; pause_frames[n]; n++)
  422. {
  423. if (ent->client->ps.gunframe == pause_frames[n])
  424. {
  425. if (rand()&15)
  426. return;
  427. }
  428. }
  429. }
  430. ent->client->ps.gunframe++;
  431. return;
  432. }
  433. }
  434. if (ent->client->weaponstate == WEAPON_FIRING)
  435. {
  436. for (n = 0; fire_frames[n]; n++)
  437. {
  438. if (ent->client->ps.gunframe == fire_frames[n])
  439. {
  440. //ZOID
  441. if (!CTFApplyStrengthSound(ent))
  442. //ZOID
  443. if (ent->client->quad_framenum > level.framenum)
  444. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);
  445. //ZOID
  446. CTFApplyHasteSound(ent);
  447. //ZOID
  448. fire (ent);
  449. break;
  450. }
  451. }
  452. if (!fire_frames[n])
  453. ent->client->ps.gunframe++;
  454. if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
  455. ent->client->weaponstate = WEAPON_READY;
  456. }
  457. }
  458. //ZOID
  459. 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))
  460. {
  461. int oldstate = ent->client->weaponstate;
  462. Weapon_Generic2 (ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST,
  463. FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames,
  464. fire_frames, fire);
  465. // run the weapon frame again if hasted
  466. if (stricmp(ent->client->pers.weapon->pickup_name, "Grapple") == 0 &&
  467. ent->client->weaponstate == WEAPON_FIRING)
  468. return;
  469. if ((CTFApplyHaste(ent) ||
  470. (Q_stricmp(ent->client->pers.weapon->pickup_name, "Grapple") == 0 &&
  471. ent->client->weaponstate != WEAPON_FIRING))
  472. && oldstate == ent->client->weaponstate) {
  473. Weapon_Generic2 (ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST,
  474. FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames,
  475. fire_frames, fire);
  476. }
  477. }
  478. //ZOID
  479. /*
  480. ======================================================================
  481. GRENADE
  482. ======================================================================
  483. */
  484. #define GRENADE_TIMER 3.0
  485. #define GRENADE_MINSPEED 400
  486. #define GRENADE_MAXSPEED 800
  487. void weapon_grenade_fire (edict_t *ent, qboolean held)
  488. {
  489. vec3_t offset;
  490. vec3_t forward, right;
  491. vec3_t start;
  492. int damage = 125;
  493. float timer;
  494. int speed;
  495. float radius;
  496. radius = damage+40;
  497. if (is_quad)
  498. damage *= 4;
  499. VectorSet(offset, 8, 8, ent->viewheight-8);
  500. AngleVectors (ent->client->v_angle, forward, right, NULL);
  501. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  502. timer = ent->client->grenade_time - level.time;
  503. speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER);
  504. fire_grenade2 (ent, start, forward, damage, speed, timer, radius, held);
  505. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  506. ent->client->pers.inventory[ent->client->ammo_index]--;
  507. ent->client->grenade_time = level.time + 1.0;
  508. if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
  509. {
  510. return;
  511. }
  512. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  513. {
  514. ent->client->anim_priority = ANIM_ATTACK;
  515. ent->s.frame = FRAME_crattak1-1;
  516. ent->client->anim_end = FRAME_crattak3;
  517. }
  518. else
  519. {
  520. ent->client->anim_priority = ANIM_REVERSE;
  521. ent->s.frame = FRAME_wave08;
  522. ent->client->anim_end = FRAME_wave01;
  523. }
  524. }
  525. void Weapon_Grenade (edict_t *ent)
  526. {
  527. if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
  528. {
  529. ChangeWeapon (ent);
  530. return;
  531. }
  532. if (ent->client->weaponstate == WEAPON_ACTIVATING)
  533. {
  534. ent->client->weaponstate = WEAPON_READY;
  535. ent->client->ps.gunframe = 16;
  536. return;
  537. }
  538. if (ent->client->weaponstate == WEAPON_READY)
  539. {
  540. if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
  541. {
  542. ent->client->latched_buttons &= ~BUTTON_ATTACK;
  543. if (ent->client->pers.inventory[ent->client->ammo_index])
  544. {
  545. ent->client->ps.gunframe = 1;
  546. ent->client->weaponstate = WEAPON_FIRING;
  547. ent->client->grenade_time = 0;
  548. }
  549. else
  550. {
  551. if (level.time >= ent->pain_debounce_time)
  552. {
  553. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  554. ent->pain_debounce_time = level.time + 1;
  555. }
  556. NoAmmoWeaponChange (ent);
  557. }
  558. return;
  559. }
  560. if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48))
  561. {
  562. if (rand()&15)
  563. return;
  564. }
  565. if (++ent->client->ps.gunframe > 48)
  566. ent->client->ps.gunframe = 16;
  567. return;
  568. }
  569. if (ent->client->weaponstate == WEAPON_FIRING)
  570. {
  571. if (ent->client->ps.gunframe == 5)
  572. gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);
  573. if (ent->client->ps.gunframe == 11)
  574. {
  575. if (!ent->client->grenade_time)
  576. {
  577. ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
  578. ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
  579. }
  580. // they waited too long, detonate it in their hand
  581. if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
  582. {
  583. ent->client->weapon_sound = 0;
  584. weapon_grenade_fire (ent, true);
  585. ent->client->grenade_blew_up = true;
  586. }
  587. if (ent->client->buttons & BUTTON_ATTACK)
  588. return;
  589. if (ent->client->grenade_blew_up)
  590. {
  591. if (level.time >= ent->client->grenade_time)
  592. {
  593. ent->client->ps.gunframe = 15;
  594. ent->client->grenade_blew_up = false;
  595. }
  596. else
  597. {
  598. return;
  599. }
  600. }
  601. }
  602. if (ent->client->ps.gunframe == 12)
  603. {
  604. ent->client->weapon_sound = 0;
  605. weapon_grenade_fire (ent, false);
  606. }
  607. if ((ent->client->ps.gunframe == 15) && (level.time < ent->client->grenade_time))
  608. return;
  609. ent->client->ps.gunframe++;
  610. if (ent->client->ps.gunframe == 16)
  611. {
  612. ent->client->grenade_time = 0;
  613. ent->client->weaponstate = WEAPON_READY;
  614. }
  615. }
  616. }
  617. /*
  618. ======================================================================
  619. GRENADE LAUNCHER
  620. ======================================================================
  621. */
  622. void weapon_grenadelauncher_fire (edict_t *ent)
  623. {
  624. vec3_t offset;
  625. vec3_t forward, right;
  626. vec3_t start;
  627. int damage = 120;
  628. float radius;
  629. radius = damage+40;
  630. if (is_quad)
  631. damage *= 4;
  632. VectorSet(offset, 8, 8, ent->viewheight-8);
  633. AngleVectors (ent->client->v_angle, forward, right, NULL);
  634. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  635. VectorScale (forward, -2, ent->client->kick_origin);
  636. ent->client->kick_angles[0] = -1;
  637. fire_grenade (ent, start, forward, damage, 600, 2.5, radius);
  638. gi.WriteByte (svc_muzzleflash);
  639. gi.WriteShort (ent-g_edicts);
  640. gi.WriteByte (MZ_GRENADE | is_silenced);
  641. gi.multicast (ent->s.origin, MULTICAST_PVS);
  642. ent->client->ps.gunframe++;
  643. PlayerNoise(ent, start, PNOISE_WEAPON);
  644. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  645. ent->client->pers.inventory[ent->client->ammo_index]--;
  646. }
  647. void Weapon_GrenadeLauncher (edict_t *ent)
  648. {
  649. static int pause_frames[] = {34, 51, 59, 0};
  650. static int fire_frames[] = {6, 0};
  651. Weapon_Generic (ent, 5, 16, 59, 64, pause_frames, fire_frames, weapon_grenadelauncher_fire);
  652. }
  653. /*
  654. ======================================================================
  655. ROCKET
  656. ======================================================================
  657. */
  658. void Weapon_RocketLauncher_Fire (edict_t *ent)
  659. {
  660. vec3_t offset, start;
  661. vec3_t forward, right;
  662. int damage;
  663. float damage_radius;
  664. int radius_damage;
  665. damage = 100 + (int)(random() * 20.0);
  666. radius_damage = 120;
  667. damage_radius = 120;
  668. if (is_quad)
  669. {
  670. damage *= 4;
  671. radius_damage *= 4;
  672. }
  673. AngleVectors (ent->client->v_angle, forward, right, NULL);
  674. VectorScale (forward, -2, ent->client->kick_origin);
  675. ent->client->kick_angles[0] = -1;
  676. VectorSet(offset, 8, 8, ent->viewheight-8);
  677. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  678. fire_rocket (ent, start, forward, damage, 650, damage_radius, radius_damage);
  679. // send muzzle flash
  680. gi.WriteByte (svc_muzzleflash);
  681. gi.WriteShort (ent-g_edicts);
  682. gi.WriteByte (MZ_ROCKET | is_silenced);
  683. gi.multicast (ent->s.origin, MULTICAST_PVS);
  684. ent->client->ps.gunframe++;
  685. PlayerNoise(ent, start, PNOISE_WEAPON);
  686. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  687. ent->client->pers.inventory[ent->client->ammo_index]--;
  688. }
  689. void Weapon_RocketLauncher (edict_t *ent)
  690. {
  691. static int pause_frames[] = {25, 33, 42, 50, 0};
  692. static int fire_frames[] = {5, 0};
  693. Weapon_Generic (ent, 4, 12, 50, 54, pause_frames, fire_frames, Weapon_RocketLauncher_Fire);
  694. }
  695. /*
  696. ======================================================================
  697. BLASTER / HYPERBLASTER
  698. ======================================================================
  699. */
  700. void Blaster_Fire (edict_t *ent, vec3_t g_offset, int damage, qboolean hyper, int effect)
  701. {
  702. vec3_t forward, right;
  703. vec3_t start;
  704. vec3_t offset;
  705. if (is_quad)
  706. damage *= 4;
  707. AngleVectors (ent->client->v_angle, forward, right, NULL);
  708. VectorSet(offset, 24, 8, ent->viewheight-8);
  709. VectorAdd (offset, g_offset, offset);
  710. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  711. VectorScale (forward, -2, ent->client->kick_origin);
  712. ent->client->kick_angles[0] = -1;
  713. fire_blaster (ent, start, forward, damage, 1000, effect, hyper);
  714. // send muzzle flash
  715. gi.WriteByte (svc_muzzleflash);
  716. gi.WriteShort (ent-g_edicts);
  717. if (hyper)
  718. gi.WriteByte (MZ_HYPERBLASTER | is_silenced);
  719. else
  720. gi.WriteByte (MZ_BLASTER | is_silenced);
  721. gi.multicast (ent->s.origin, MULTICAST_PVS);
  722. PlayerNoise(ent, start, PNOISE_WEAPON);
  723. }
  724. void Weapon_Blaster_Fire (edict_t *ent)
  725. {
  726. int damage;
  727. if (deathmatch->value)
  728. damage = 15;
  729. else
  730. damage = 10;
  731. Blaster_Fire (ent, vec3_origin, damage, false, EF_BLASTER);
  732. ent->client->ps.gunframe++;
  733. }
  734. void Weapon_Blaster (edict_t *ent)
  735. {
  736. static int pause_frames[] = {19, 32, 0};
  737. static int fire_frames[] = {5, 0};
  738. Weapon_Generic (ent, 4, 8, 52, 55, pause_frames, fire_frames, Weapon_Blaster_Fire);
  739. }
  740. void Weapon_HyperBlaster_Fire (edict_t *ent)
  741. {
  742. float rotation;
  743. vec3_t offset;
  744. int effect;
  745. int damage;
  746. ent->client->weapon_sound = gi.soundindex("weapons/hyprbl1a.wav");
  747. if (!(ent->client->buttons & BUTTON_ATTACK))
  748. {
  749. ent->client->ps.gunframe++;
  750. }
  751. else
  752. {
  753. if (! ent->client->pers.inventory[ent->client->ammo_index] )
  754. {
  755. if (level.time >= ent->pain_debounce_time)
  756. {
  757. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  758. ent->pain_debounce_time = level.time + 1;
  759. }
  760. NoAmmoWeaponChange (ent);
  761. }
  762. else
  763. {
  764. rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
  765. offset[0] = -4 * sin(rotation);
  766. offset[1] = 0;
  767. offset[2] = 4 * cos(rotation);
  768. if ((ent->client->ps.gunframe == 6) || (ent->client->ps.gunframe == 9))
  769. effect = EF_HYPERBLASTER;
  770. else
  771. effect = 0;
  772. if (deathmatch->value)
  773. damage = 15;
  774. else
  775. damage = 20;
  776. Blaster_Fire (ent, offset, damage, true, effect);
  777. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  778. ent->client->pers.inventory[ent->client->ammo_index]--;
  779. ent->client->anim_priority = ANIM_ATTACK;
  780. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  781. {
  782. ent->s.frame = FRAME_crattak1 - 1;
  783. ent->client->anim_end = FRAME_crattak9;
  784. }
  785. else
  786. {
  787. ent->s.frame = FRAME_attack1 - 1;
  788. ent->client->anim_end = FRAME_attack8;
  789. }
  790. }
  791. ent->client->ps.gunframe++;
  792. if (ent->client->ps.gunframe == 12 && ent->client->pers.inventory[ent->client->ammo_index])
  793. ent->client->ps.gunframe = 6;
  794. }
  795. if (ent->client->ps.gunframe == 12)
  796. {
  797. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/hyprbd1a.wav"), 1, ATTN_NORM, 0);
  798. ent->client->weapon_sound = 0;
  799. }
  800. }
  801. void Weapon_HyperBlaster (edict_t *ent)
  802. {
  803. static int pause_frames[] = {0};
  804. static int fire_frames[] = {6, 7, 8, 9, 10, 11, 0};
  805. Weapon_Generic (ent, 5, 20, 49, 53, pause_frames, fire_frames, Weapon_HyperBlaster_Fire);
  806. }
  807. /*
  808. ======================================================================
  809. MACHINEGUN / CHAINGUN
  810. ======================================================================
  811. */
  812. void Machinegun_Fire (edict_t *ent)
  813. {
  814. int i;
  815. vec3_t start;
  816. vec3_t forward, right;
  817. vec3_t angles;
  818. int damage = 8;
  819. int kick = 2;
  820. vec3_t offset;
  821. if (!(ent->client->buttons & BUTTON_ATTACK))
  822. {
  823. ent->client->machinegun_shots = 0;
  824. ent->client->ps.gunframe++;
  825. return;
  826. }
  827. if (ent->client->ps.gunframe == 5)
  828. ent->client->ps.gunframe = 4;
  829. else
  830. ent->client->ps.gunframe = 5;
  831. if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
  832. {
  833. ent->client->ps.gunframe = 6;
  834. if (level.time >= ent->pain_debounce_time)
  835. {
  836. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  837. ent->pain_debounce_time = level.time + 1;
  838. }
  839. NoAmmoWeaponChange (ent);
  840. return;
  841. }
  842. if (is_quad)
  843. {
  844. damage *= 4;
  845. kick *= 4;
  846. }
  847. for (i=1 ; i<3 ; i++)
  848. {
  849. ent->client->kick_origin[i] = crandom() * 0.35;
  850. ent->client->kick_angles[i] = crandom() * 0.7;
  851. }
  852. ent->client->kick_origin[0] = crandom() * 0.35;
  853. ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;
  854. // raise the gun as it is firing
  855. if (!deathmatch->value)
  856. {
  857. ent->client->machinegun_shots++;
  858. if (ent->client->machinegun_shots > 9)
  859. ent->client->machinegun_shots = 9;
  860. }
  861. // get start / end positions
  862. VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
  863. AngleVectors (angles, forward, right, NULL);
  864. VectorSet(offset, 0, 8, ent->viewheight-8);
  865. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  866. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
  867. gi.WriteByte (svc_muzzleflash);
  868. gi.WriteShort (ent-g_edicts);
  869. gi.WriteByte (MZ_MACHINEGUN | is_silenced);
  870. gi.multicast (ent->s.origin, MULTICAST_PVS);
  871. PlayerNoise(ent, start, PNOISE_WEAPON);
  872. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  873. ent->client->pers.inventory[ent->client->ammo_index]--;
  874. ent->client->anim_priority = ANIM_ATTACK;
  875. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  876. {
  877. ent->s.frame = FRAME_crattak1 - (int) (random()+0.25);
  878. ent->client->anim_end = FRAME_crattak9;
  879. }
  880. else
  881. {
  882. ent->s.frame = FRAME_attack1 - (int) (random()+0.25);
  883. ent->client->anim_end = FRAME_attack8;
  884. }
  885. }
  886. void Weapon_Machinegun (edict_t *ent)
  887. {
  888. static int pause_frames[] = {23, 45, 0};
  889. static int fire_frames[] = {4, 5, 0};
  890. Weapon_Generic (ent, 3, 5, 45, 49, pause_frames, fire_frames, Machinegun_Fire);
  891. }
  892. void Chaingun_Fire (edict_t *ent)
  893. {
  894. int i;
  895. int shots;
  896. vec3_t start;
  897. vec3_t forward, right, up;
  898. float r, u;
  899. vec3_t offset;
  900. int damage;
  901. int kick = 2;
  902. if (deathmatch->value)
  903. damage = 6;
  904. else
  905. damage = 8;
  906. if (ent->client->ps.gunframe == 5)
  907. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);
  908. if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
  909. {
  910. ent->client->ps.gunframe = 32;
  911. ent->client->weapon_sound = 0;
  912. return;
  913. }
  914. else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
  915. && ent->client->pers.inventory[ent->client->ammo_index])
  916. {
  917. ent->client->ps.gunframe = 15;
  918. }
  919. else
  920. {
  921. ent->client->ps.gunframe++;
  922. }
  923. if (ent->client->ps.gunframe == 22)
  924. {
  925. ent->client->weapon_sound = 0;
  926. gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
  927. }
  928. else
  929. {
  930. ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
  931. }
  932. ent->client->anim_priority = ANIM_ATTACK;
  933. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  934. {
  935. ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
  936. ent->client->anim_end = FRAME_crattak9;
  937. }
  938. else
  939. {
  940. ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
  941. ent->client->anim_end = FRAME_attack8;
  942. }
  943. if (ent->client->ps.gunframe <= 9)
  944. shots = 1;
  945. else if (ent->client->ps.gunframe <= 14)
  946. {
  947. if (ent->client->buttons & BUTTON_ATTACK)
  948. shots = 2;
  949. else
  950. shots = 1;
  951. }
  952. else
  953. shots = 3;
  954. if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
  955. shots = ent->client->pers.inventory[ent->client->ammo_index];
  956. if (!shots)
  957. {
  958. if (level.time >= ent->pain_debounce_time)
  959. {
  960. gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
  961. ent->pain_debounce_time = level.time + 1;
  962. }
  963. NoAmmoWeaponChange (ent);
  964. return;
  965. }
  966. if (is_quad)
  967. {
  968. damage *= 4;
  969. kick *= 4;
  970. }
  971. for (i=0 ; i<3 ; i++)
  972. {
  973. ent->client->kick_origin[i] = crandom() * 0.35;
  974. ent->client->kick_angles[i] = crandom() * 0.7;
  975. }
  976. for (i=0 ; i<shots ; i++)
  977. {
  978. // get start / end positions
  979. AngleVectors (ent->client->v_angle, forward, right, up);
  980. r = 7 + crandom()*4;
  981. u = crandom()*4;
  982. VectorSet(offset, 0, r, u + ent->viewheight-8);
  983. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  984. fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
  985. }
  986. // send muzzle flash
  987. gi.WriteByte (svc_muzzleflash);
  988. gi.WriteShort (ent-g_edicts);
  989. gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
  990. gi.multicast (ent->s.origin, MULTICAST_PVS);
  991. PlayerNoise(ent, start, PNOISE_WEAPON);
  992. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  993. ent->client->pers.inventory[ent->client->ammo_index] -= shots;
  994. }
  995. void Weapon_Chaingun (edict_t *ent)
  996. {
  997. static int pause_frames[] = {38, 43, 51, 61, 0};
  998. static int fire_frames[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0};
  999. Weapon_Generic (ent, 4, 31, 61, 64, pause_frames, fire_frames, Chaingun_Fire);
  1000. }
  1001. /*
  1002. ======================================================================
  1003. SHOTGUN / SUPERSHOTGUN
  1004. ======================================================================
  1005. */
  1006. void weapon_shotgun_fire (edict_t *ent)
  1007. {
  1008. vec3_t start;
  1009. vec3_t forward, right;
  1010. vec3_t offset;
  1011. int damage = 4;
  1012. int kick = 8;
  1013. if (ent->client->ps.gunframe == 9)
  1014. {
  1015. ent->client->ps.gunframe++;
  1016. return;
  1017. }
  1018. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1019. VectorScale (forward, -2, ent->client->kick_origin);
  1020. ent->client->kick_angles[0] = -2;
  1021. VectorSet(offset, 0, 8, ent->viewheight-8);
  1022. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1023. if (is_quad)
  1024. {
  1025. damage *= 4;
  1026. kick *= 4;
  1027. }
  1028. if (deathmatch->value)
  1029. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN);
  1030. else
  1031. fire_shotgun (ent, start, forward, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);
  1032. // send muzzle flash
  1033. gi.WriteByte (svc_muzzleflash);
  1034. gi.WriteShort (ent-g_edicts);
  1035. gi.WriteByte (MZ_SHOTGUN | is_silenced);
  1036. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1037. ent->client->ps.gunframe++;
  1038. PlayerNoise(ent, start, PNOISE_WEAPON);
  1039. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1040. ent->client->pers.inventory[ent->client->ammo_index]--;
  1041. }
  1042. void Weapon_Shotgun (edict_t *ent)
  1043. {
  1044. static int pause_frames[] = {22, 28, 34, 0};
  1045. static int fire_frames[] = {8, 9, 0};
  1046. Weapon_Generic (ent, 7, 18, 36, 39, pause_frames, fire_frames, weapon_shotgun_fire);
  1047. }
  1048. void weapon_supershotgun_fire (edict_t *ent)
  1049. {
  1050. vec3_t start;
  1051. vec3_t forward, right;
  1052. vec3_t offset;
  1053. vec3_t v;
  1054. int damage = 6;
  1055. int kick = 12;
  1056. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1057. VectorScale (forward, -2, ent->client->kick_origin);
  1058. ent->client->kick_angles[0] = -2;
  1059. VectorSet(offset, 0, 8, ent->viewheight-8);
  1060. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1061. if (is_quad)
  1062. {
  1063. damage *= 4;
  1064. kick *= 4;
  1065. }
  1066. v[PITCH] = ent->client->v_angle[PITCH];
  1067. v[YAW] = ent->client->v_angle[YAW] - 5;
  1068. v[ROLL] = ent->client->v_angle[ROLL];
  1069. AngleVectors (v, forward, NULL, NULL);
  1070. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1071. v[YAW] = ent->client->v_angle[YAW] + 5;
  1072. AngleVectors (v, forward, NULL, NULL);
  1073. fire_shotgun (ent, start, forward, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT/2, MOD_SSHOTGUN);
  1074. // send muzzle flash
  1075. gi.WriteByte (svc_muzzleflash);
  1076. gi.WriteShort (ent-g_edicts);
  1077. gi.WriteByte (MZ_SSHOTGUN | is_silenced);
  1078. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1079. ent->client->ps.gunframe++;
  1080. PlayerNoise(ent, start, PNOISE_WEAPON);
  1081. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1082. ent->client->pers.inventory[ent->client->ammo_index] -= 2;
  1083. }
  1084. void Weapon_SuperShotgun (edict_t *ent)
  1085. {
  1086. static int pause_frames[] = {29, 42, 57, 0};
  1087. static int fire_frames[] = {7, 0};
  1088. Weapon_Generic (ent, 6, 17, 57, 61, pause_frames, fire_frames, weapon_supershotgun_fire);
  1089. }
  1090. /*
  1091. ======================================================================
  1092. RAILGUN
  1093. ======================================================================
  1094. */
  1095. void weapon_railgun_fire (edict_t *ent)
  1096. {
  1097. vec3_t start;
  1098. vec3_t forward, right;
  1099. vec3_t offset;
  1100. int damage;
  1101. int kick;
  1102. if (deathmatch->value)
  1103. { // normal damage is too extreme in dm
  1104. damage = 100;
  1105. kick = 200;
  1106. }
  1107. else
  1108. {
  1109. damage = 150;
  1110. kick = 250;
  1111. }
  1112. if (is_quad)
  1113. {
  1114. damage *= 4;
  1115. kick *= 4;
  1116. }
  1117. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1118. VectorScale (forward, -3, ent->client->kick_origin);
  1119. ent->client->kick_angles[0] = -3;
  1120. VectorSet(offset, 0, 7, ent->viewheight-8);
  1121. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1122. fire_rail (ent, start, forward, damage, kick);
  1123. // send muzzle flash
  1124. gi.WriteByte (svc_muzzleflash);
  1125. gi.WriteShort (ent-g_edicts);
  1126. gi.WriteByte (MZ_RAILGUN | is_silenced);
  1127. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1128. ent->client->ps.gunframe++;
  1129. PlayerNoise(ent, start, PNOISE_WEAPON);
  1130. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1131. ent->client->pers.inventory[ent->client->ammo_index]--;
  1132. }
  1133. void Weapon_Railgun (edict_t *ent)
  1134. {
  1135. static int pause_frames[] = {56, 0};
  1136. static int fire_frames[] = {4, 0};
  1137. Weapon_Generic (ent, 3, 18, 56, 61, pause_frames, fire_frames, weapon_railgun_fire);
  1138. }
  1139. /*
  1140. ======================================================================
  1141. BFG10K
  1142. ======================================================================
  1143. */
  1144. void weapon_bfg_fire (edict_t *ent)
  1145. {
  1146. vec3_t offset, start;
  1147. vec3_t forward, right;
  1148. int damage;
  1149. float damage_radius = 1000;
  1150. if (deathmatch->value)
  1151. damage = 200;
  1152. else
  1153. damage = 500;
  1154. if (ent->client->ps.gunframe == 9)
  1155. {
  1156. // send muzzle flash
  1157. gi.WriteByte (svc_muzzleflash);
  1158. gi.WriteShort (ent-g_edicts);
  1159. gi.WriteByte (MZ_BFG | is_silenced);
  1160. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1161. ent->client->ps.gunframe++;
  1162. PlayerNoise(ent, start, PNOISE_WEAPON);
  1163. return;
  1164. }
  1165. // cells can go down during windup (from power armor hits), so
  1166. // check again and abort firing if we don't have enough now
  1167. if (ent->client->pers.inventory[ent->client->ammo_index] < 50)
  1168. {
  1169. ent->client->ps.gunframe++;
  1170. return;
  1171. }
  1172. if (is_quad)
  1173. damage *= 4;
  1174. AngleVectors (ent->client->v_angle, forward, right, NULL);
  1175. VectorScale (forward, -2, ent->client->kick_origin);
  1176. // make a big pitch kick with an inverse fall
  1177. ent->client->v_dmg_pitch = -40;
  1178. ent->client->v_dmg_roll = crandom()*8;
  1179. ent->client->v_dmg_time = level.time + DAMAGE_TIME;
  1180. VectorSet(offset, 8, 8, ent->viewheight-8);
  1181. P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
  1182. fire_bfg (ent, start, forward, damage, 400, damage_radius);
  1183. ent->client->ps.gunframe++;
  1184. PlayerNoise(ent, start, PNOISE_WEAPON);
  1185. if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
  1186. ent->client->pers.inventory[ent->client->ammo_index] -= 50;
  1187. }
  1188. void Weapon_BFG (edict_t *ent)
  1189. {
  1190. static int pause_frames[] = {39, 45, 50, 55, 0};
  1191. static int fire_frames[] = {9, 17, 0};
  1192. Weapon_Generic (ent, 8, 32, 55, 58, pause_frames, fire_frames, weapon_bfg_fire);
  1193. }
  1194. //======================================================================