g_weapon.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. #include "g_local.h"
  16. /*
  17. =================
  18. check_dodge
  19. This is a support routine used when a client is firing
  20. a non-instant attack weapon. It checks to see if a
  21. monster's dodge function should be called.
  22. =================
  23. */
  24. static void check_dodge (edict_t *self, vec3_t start, vec3_t dir, int speed)
  25. {
  26. vec3_t end;
  27. vec3_t v;
  28. trace_t tr;
  29. float eta;
  30. // easy mode only ducks one quarter the time
  31. if (skill->value == 0)
  32. {
  33. if (random() > 0.25)
  34. return;
  35. }
  36. VectorMA (start, 8192, dir, end);
  37. tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
  38. if ((tr.ent) && (tr.ent->svflags & SVF_MONSTER) && (tr.ent->health > 0) && (tr.ent->monsterinfo.dodge) && infront(tr.ent, self))
  39. {
  40. VectorSubtract (tr.endpos, start, v);
  41. eta = (VectorLength(v) - tr.ent->maxs[0]) / speed;
  42. tr.ent->monsterinfo.dodge (tr.ent, self, eta);
  43. }
  44. }
  45. /*
  46. =================
  47. fire_hit
  48. Used for all impact (hit/punch/slash) attacks
  49. =================
  50. */
  51. qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick)
  52. {
  53. trace_t tr;
  54. vec3_t forward, right, up;
  55. vec3_t v;
  56. vec3_t point;
  57. float range;
  58. vec3_t dir;
  59. //see if enemy is in range
  60. VectorSubtract (self->enemy->s.origin, self->s.origin, dir);
  61. range = VectorLength(dir);
  62. if (range > aim[0])
  63. return false;
  64. if (aim[1] > self->mins[0] && aim[1] < self->maxs[0])
  65. {
  66. // the hit is straight on so back the range up to the edge of their bbox
  67. range -= self->enemy->maxs[0];
  68. }
  69. else
  70. {
  71. // this is a side hit so adjust the "right" value out to the edge of their bbox
  72. if (aim[1] < 0)
  73. aim[1] = self->enemy->mins[0];
  74. else
  75. aim[1] = self->enemy->maxs[0];
  76. }
  77. VectorMA (self->s.origin, range, dir, point);
  78. tr = gi.trace (self->s.origin, NULL, NULL, point, self, MASK_SHOT);
  79. if (tr.fraction < 1)
  80. {
  81. if (!tr.ent->takedamage)
  82. return false;
  83. // if it will hit any client/monster then hit the one we wanted to hit
  84. if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
  85. tr.ent = self->enemy;
  86. }
  87. AngleVectors(self->s.angles, forward, right, up);
  88. VectorMA (self->s.origin, range, forward, point);
  89. VectorMA (point, aim[1], right, point);
  90. VectorMA (point, aim[2], up, point);
  91. VectorSubtract (point, self->enemy->s.origin, dir);
  92. // do the damage
  93. T_Damage (tr.ent, self, self, dir, point, vec3_origin, damage, kick/2, DAMAGE_NO_KNOCKBACK, MOD_HIT);
  94. if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
  95. return false;
  96. // do our special form of knockback here
  97. VectorMA (self->enemy->absmin, 0.5, self->enemy->size, v);
  98. VectorSubtract (v, point, v);
  99. VectorNormalize (v);
  100. VectorMA (self->enemy->velocity, kick, v, self->enemy->velocity);
  101. if (self->enemy->velocity[2] > 0)
  102. self->enemy->groundentity = NULL;
  103. return true;
  104. }
  105. /*
  106. =================
  107. fire_lead
  108. This is an internal support routine used for bullet/pellet based weapons.
  109. =================
  110. */
  111. static void fire_lead (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int te_impact, int hspread, int vspread, int mod)
  112. {
  113. trace_t tr;
  114. vec3_t dir;
  115. vec3_t forward, right, up;
  116. vec3_t end;
  117. float r;
  118. float u;
  119. vec3_t water_start;
  120. qboolean water = false;
  121. int content_mask = MASK_SHOT | MASK_WATER;
  122. tr = gi.trace (self->s.origin, NULL, NULL, start, self, MASK_SHOT);
  123. if (!(tr.fraction < 1.0))
  124. {
  125. vectoangles (aimdir, dir);
  126. AngleVectors (dir, forward, right, up);
  127. r = crandom()*hspread;
  128. u = crandom()*vspread;
  129. VectorMA (start, 8192, forward, end);
  130. VectorMA (end, r, right, end);
  131. VectorMA (end, u, up, end);
  132. if (gi.pointcontents (start) & MASK_WATER)
  133. {
  134. water = true;
  135. VectorCopy (start, water_start);
  136. content_mask &= ~MASK_WATER;
  137. }
  138. tr = gi.trace (start, NULL, NULL, end, self, content_mask);
  139. // see if we hit water
  140. if (tr.contents & MASK_WATER)
  141. {
  142. int color;
  143. water = true;
  144. VectorCopy (tr.endpos, water_start);
  145. if (!VectorCompare (start, tr.endpos))
  146. {
  147. if (tr.contents & CONTENTS_WATER)
  148. {
  149. if (strcmp(tr.surface->name, "*brwater") == 0)
  150. color = SPLASH_BROWN_WATER;
  151. else
  152. color = SPLASH_BLUE_WATER;
  153. }
  154. else if (tr.contents & CONTENTS_SLIME)
  155. color = SPLASH_SLIME;
  156. else if (tr.contents & CONTENTS_LAVA)
  157. color = SPLASH_LAVA;
  158. else
  159. color = SPLASH_UNKNOWN;
  160. if (color != SPLASH_UNKNOWN)
  161. {
  162. gi.WriteByte (svc_temp_entity);
  163. gi.WriteByte (TE_SPLASH);
  164. gi.WriteByte (8);
  165. gi.WritePosition (tr.endpos);
  166. gi.WriteDir (tr.plane.normal);
  167. gi.WriteByte (color);
  168. gi.multicast (tr.endpos, MULTICAST_PVS);
  169. }
  170. // change bullet's course when it enters water
  171. VectorSubtract (end, start, dir);
  172. vectoangles (dir, dir);
  173. AngleVectors (dir, forward, right, up);
  174. r = crandom()*hspread*2;
  175. u = crandom()*vspread*2;
  176. VectorMA (water_start, 8192, forward, end);
  177. VectorMA (end, r, right, end);
  178. VectorMA (end, u, up, end);
  179. }
  180. // re-trace ignoring water this time
  181. tr = gi.trace (water_start, NULL, NULL, end, self, MASK_SHOT);
  182. }
  183. }
  184. // send gun puff / flash
  185. if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
  186. {
  187. if (tr.fraction < 1.0)
  188. {
  189. if (tr.ent->takedamage)
  190. {
  191. T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
  192. }
  193. else
  194. {
  195. if (strncmp (tr.surface->name, "sky", 3) != 0)
  196. {
  197. gi.WriteByte (svc_temp_entity);
  198. gi.WriteByte (te_impact);
  199. gi.WritePosition (tr.endpos);
  200. gi.WriteDir (tr.plane.normal);
  201. gi.multicast (tr.endpos, MULTICAST_PVS);
  202. if (self->client)
  203. PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
  204. }
  205. }
  206. }
  207. }
  208. // if went through water, determine where the end and make a bubble trail
  209. if (water)
  210. {
  211. vec3_t pos;
  212. VectorSubtract (tr.endpos, water_start, dir);
  213. VectorNormalize (dir);
  214. VectorMA (tr.endpos, -2, dir, pos);
  215. if (gi.pointcontents (pos) & MASK_WATER)
  216. VectorCopy (pos, tr.endpos);
  217. else
  218. tr = gi.trace (pos, NULL, NULL, water_start, tr.ent, MASK_WATER);
  219. VectorAdd (water_start, tr.endpos, pos);
  220. VectorScale (pos, 0.5, pos);
  221. gi.WriteByte (svc_temp_entity);
  222. gi.WriteByte (TE_BUBBLETRAIL);
  223. gi.WritePosition (water_start);
  224. gi.WritePosition (tr.endpos);
  225. gi.multicast (pos, MULTICAST_PVS);
  226. }
  227. }
  228. /*
  229. =================
  230. fire_bullet
  231. Fires a single round. Used for machinegun and chaingun. Would be fine for
  232. pistols, rifles, etc....
  233. =================
  234. */
  235. void fire_bullet (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod)
  236. {
  237. fire_lead (self, start, aimdir, damage, kick, TE_GUNSHOT, hspread, vspread, mod);
  238. }
  239. /*
  240. =================
  241. fire_shotgun
  242. Shoots shotgun pellets. Used by shotgun and super shotgun.
  243. =================
  244. */
  245. void fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod)
  246. {
  247. int i;
  248. for (i = 0; i < count; i++)
  249. fire_lead (self, start, aimdir, damage, kick, TE_SHOTGUN, hspread, vspread, mod);
  250. }
  251. /*
  252. =================
  253. fire_blaster
  254. Fires a single blaster bolt. Used by the blaster and hyper blaster.
  255. =================
  256. */
  257. void blaster_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  258. {
  259. int mod;
  260. if (other == self->owner)
  261. return;
  262. if (surf && (surf->flags & SURF_SKY))
  263. {
  264. G_FreeEdict (self);
  265. return;
  266. }
  267. if (self->owner->client)
  268. PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
  269. if (other->takedamage)
  270. {
  271. if (self->spawnflags & 1)
  272. mod = MOD_HYPERBLASTER;
  273. else
  274. mod = MOD_BLASTER;
  275. T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, self->dmg, 1, DAMAGE_ENERGY, mod);
  276. }
  277. else
  278. {
  279. gi.WriteByte (svc_temp_entity);
  280. gi.WriteByte (TE_BLASTER);
  281. gi.WritePosition (self->s.origin);
  282. if (!plane)
  283. gi.WriteDir (vec3_origin);
  284. else
  285. gi.WriteDir (plane->normal);
  286. gi.multicast (self->s.origin, MULTICAST_PVS);
  287. }
  288. G_FreeEdict (self);
  289. }
  290. void fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int effect, qboolean hyper)
  291. {
  292. edict_t *bolt;
  293. trace_t tr;
  294. VectorNormalize (dir);
  295. bolt = G_Spawn();
  296. bolt->svflags = SVF_PROJECTILE; // special net code is used for projectiles
  297. VectorCopy (start, bolt->s.origin);
  298. VectorCopy (start, bolt->s.old_origin);
  299. vectoangles (dir, bolt->s.angles);
  300. VectorScale (dir, speed, bolt->velocity);
  301. bolt->movetype = MOVETYPE_FLYMISSILE;
  302. bolt->clipmask = MASK_SHOT;
  303. bolt->solid = SOLID_BBOX;
  304. bolt->s.effects |= effect;
  305. VectorClear (bolt->mins);
  306. VectorClear (bolt->maxs);
  307. bolt->s.modelindex = gi.modelindex ("models/objects/laser/tris.md2");
  308. bolt->s.sound = gi.soundindex ("misc/lasfly.wav");
  309. bolt->owner = self;
  310. bolt->touch = blaster_touch;
  311. bolt->nextthink = level.time + 2;
  312. bolt->think = G_FreeEdict;
  313. bolt->dmg = damage;
  314. bolt->classname = "bolt";
  315. if (hyper)
  316. bolt->spawnflags = 1;
  317. gi.linkentity (bolt);
  318. if (self->client)
  319. check_dodge (self, bolt->s.origin, dir, speed);
  320. tr = gi.trace (self->s.origin, NULL, NULL, bolt->s.origin, bolt, MASK_SHOT);
  321. if (tr.fraction < 1.0)
  322. {
  323. VectorMA (bolt->s.origin, -10, dir, bolt->s.origin);
  324. bolt->touch (bolt, tr.ent, NULL, NULL);
  325. }
  326. }
  327. /*
  328. =================
  329. fire_grenade
  330. =================
  331. */
  332. static void Grenade_Explode (edict_t *ent)
  333. {
  334. vec3_t origin;
  335. int mod;
  336. if (ent->owner->client)
  337. PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
  338. //FIXME: if we are onground then raise our Z just a bit since we are a point?
  339. if (ent->enemy)
  340. {
  341. float points;
  342. vec3_t v;
  343. vec3_t dir;
  344. VectorAdd (ent->enemy->mins, ent->enemy->maxs, v);
  345. VectorMA (ent->enemy->s.origin, 0.5, v, v);
  346. VectorSubtract (ent->s.origin, v, v);
  347. points = ent->dmg - 0.5 * VectorLength (v);
  348. VectorSubtract (ent->enemy->s.origin, ent->s.origin, dir);
  349. if (ent->spawnflags & 1)
  350. mod = MOD_HANDGRENADE;
  351. else
  352. mod = MOD_GRENADE;
  353. T_Damage (ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
  354. }
  355. if (ent->spawnflags & 2)
  356. mod = MOD_HELD_GRENADE;
  357. else if (ent->spawnflags & 1)
  358. mod = MOD_HG_SPLASH;
  359. else
  360. mod = MOD_G_SPLASH;
  361. T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy, ent->dmg_radius, mod);
  362. VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
  363. gi.WriteByte (svc_temp_entity);
  364. if (ent->waterlevel)
  365. {
  366. if (ent->groundentity)
  367. gi.WriteByte (TE_GRENADE_EXPLOSION_WATER);
  368. else
  369. gi.WriteByte (TE_ROCKET_EXPLOSION_WATER);
  370. }
  371. else
  372. {
  373. if (ent->groundentity)
  374. gi.WriteByte (TE_GRENADE_EXPLOSION);
  375. else
  376. gi.WriteByte (TE_ROCKET_EXPLOSION);
  377. }
  378. gi.WritePosition (origin);
  379. gi.multicast (ent->s.origin, MULTICAST_PHS);
  380. G_FreeEdict (ent);
  381. }
  382. static void Grenade_Touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
  383. {
  384. if (other == ent->owner)
  385. return;
  386. if (surf && (surf->flags & SURF_SKY))
  387. {
  388. G_FreeEdict (ent);
  389. return;
  390. }
  391. if (!other->takedamage)
  392. {
  393. if (ent->spawnflags & 1)
  394. {
  395. if (random() > 0.5)
  396. gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb1a.wav"), 1, ATTN_NORM, 0);
  397. else
  398. gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/hgrenb2a.wav"), 1, ATTN_NORM, 0);
  399. }
  400. else
  401. {
  402. gi.sound (ent, CHAN_VOICE, gi.soundindex ("weapons/grenlb1b.wav"), 1, ATTN_NORM, 0);
  403. }
  404. return;
  405. }
  406. ent->enemy = other;
  407. Grenade_Explode (ent);
  408. }
  409. void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius)
  410. {
  411. edict_t *grenade;
  412. vec3_t dir;
  413. vec3_t forward, right, up;
  414. vectoangles (aimdir, dir);
  415. AngleVectors (dir, forward, right, up);
  416. grenade = G_Spawn();
  417. VectorCopy (start, grenade->s.origin);
  418. VectorScale (aimdir, speed, grenade->velocity);
  419. VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
  420. VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
  421. VectorSet (grenade->avelocity, 300, 300, 300);
  422. grenade->movetype = MOVETYPE_BOUNCE;
  423. grenade->clipmask = MASK_SHOT;
  424. grenade->solid = SOLID_BBOX;
  425. grenade->s.effects |= EF_GRENADE;
  426. VectorClear (grenade->mins);
  427. VectorClear (grenade->maxs);
  428. grenade->s.modelindex = gi.modelindex ("models/objects/grenade/tris.md2");
  429. grenade->owner = self;
  430. grenade->touch = Grenade_Touch;
  431. grenade->nextthink = level.time + timer;
  432. grenade->think = Grenade_Explode;
  433. grenade->dmg = damage;
  434. grenade->dmg_radius = damage_radius;
  435. grenade->classname = "grenade";
  436. gi.linkentity (grenade);
  437. }
  438. void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held)
  439. {
  440. edict_t *grenade;
  441. vec3_t dir;
  442. vec3_t forward, right, up;
  443. vectoangles (aimdir, dir);
  444. AngleVectors (dir, forward, right, up);
  445. grenade = G_Spawn();
  446. VectorCopy (start, grenade->s.origin);
  447. VectorScale (aimdir, speed, grenade->velocity);
  448. VectorMA (grenade->velocity, 200 + crandom() * 10.0, up, grenade->velocity);
  449. VectorMA (grenade->velocity, crandom() * 10.0, right, grenade->velocity);
  450. VectorSet (grenade->avelocity, 300, 300, 300);
  451. grenade->movetype = MOVETYPE_BOUNCE;
  452. grenade->clipmask = MASK_SHOT;
  453. grenade->solid = SOLID_BBOX;
  454. grenade->s.effects |= EF_GRENADE;
  455. VectorClear (grenade->mins);
  456. VectorClear (grenade->maxs);
  457. grenade->s.modelindex = gi.modelindex ("models/objects/grenade2/tris.md2");
  458. grenade->owner = self;
  459. grenade->touch = Grenade_Touch;
  460. grenade->nextthink = level.time + timer;
  461. grenade->think = Grenade_Explode;
  462. grenade->dmg = damage;
  463. grenade->dmg_radius = damage_radius;
  464. grenade->classname = "hgrenade";
  465. if (held)
  466. grenade->spawnflags = 3;
  467. else
  468. grenade->spawnflags = 1;
  469. grenade->s.sound = gi.soundindex("weapons/hgrenc1b.wav");
  470. if (timer <= 0.0)
  471. Grenade_Explode (grenade);
  472. else
  473. {
  474. gi.sound (self, CHAN_WEAPON, gi.soundindex ("weapons/hgrent1a.wav"), 1, ATTN_NORM, 0);
  475. gi.linkentity (grenade);
  476. }
  477. }
  478. /*
  479. =================
  480. fire_rocket
  481. =================
  482. */
  483. void rocket_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
  484. {
  485. vec3_t origin;
  486. int n;
  487. if (other == ent->owner)
  488. return;
  489. if (surf && (surf->flags & SURF_SKY))
  490. {
  491. G_FreeEdict (ent);
  492. return;
  493. }
  494. if (ent->owner->client)
  495. PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
  496. // calculate position for the explosion entity
  497. VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
  498. if (other->takedamage)
  499. {
  500. T_Damage (other, ent, ent->owner, ent->velocity, ent->s.origin, plane->normal, ent->dmg, 0, 0, MOD_ROCKET);
  501. }
  502. else
  503. {
  504. // don't throw any debris in net games
  505. if (!deathmatch->value && !coop->value)
  506. {
  507. if ((surf) && !(surf->flags & (SURF_WARP|SURF_TRANS33|SURF_TRANS66|SURF_FLOWING)))
  508. {
  509. n = rand() % 5;
  510. while(n--)
  511. ThrowDebris (ent, "models/objects/debris2/tris.md2", 2, ent->s.origin);
  512. }
  513. }
  514. }
  515. T_RadiusDamage(ent, ent->owner, ent->radius_dmg, other, ent->dmg_radius, MOD_R_SPLASH);
  516. gi.WriteByte (svc_temp_entity);
  517. if (ent->waterlevel)
  518. gi.WriteByte (TE_ROCKET_EXPLOSION_WATER);
  519. else
  520. gi.WriteByte (TE_ROCKET_EXPLOSION);
  521. gi.WritePosition (origin);
  522. gi.multicast (ent->s.origin, MULTICAST_PHS);
  523. G_FreeEdict (ent);
  524. }
  525. void fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage)
  526. {
  527. edict_t *rocket;
  528. rocket = G_Spawn();
  529. VectorCopy (start, rocket->s.origin);
  530. VectorCopy (dir, rocket->movedir);
  531. vectoangles (dir, rocket->s.angles);
  532. VectorScale (dir, speed, rocket->velocity);
  533. rocket->movetype = MOVETYPE_FLYMISSILE;
  534. rocket->clipmask = MASK_SHOT;
  535. rocket->solid = SOLID_BBOX;
  536. rocket->s.effects |= EF_ROCKET;
  537. VectorClear (rocket->mins);
  538. VectorClear (rocket->maxs);
  539. rocket->s.modelindex = gi.modelindex ("models/objects/rocket/tris.md2");
  540. rocket->owner = self;
  541. rocket->touch = rocket_touch;
  542. rocket->nextthink = level.time + 8000/speed;
  543. rocket->think = G_FreeEdict;
  544. rocket->dmg = damage;
  545. rocket->radius_dmg = radius_damage;
  546. rocket->dmg_radius = damage_radius;
  547. rocket->s.sound = gi.soundindex ("weapons/rockfly.wav");
  548. rocket->classname = "rocket";
  549. if (self->client)
  550. check_dodge (self, rocket->s.origin, dir, speed);
  551. gi.linkentity (rocket);
  552. }
  553. /*
  554. =================
  555. fire_rail
  556. =================
  557. */
  558. void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick)
  559. {
  560. vec3_t from;
  561. vec3_t end;
  562. trace_t tr;
  563. edict_t *ignore;
  564. int mask;
  565. qboolean water;
  566. VectorMA (start, 8192, aimdir, end);
  567. VectorCopy (start, from);
  568. ignore = self;
  569. water = false;
  570. mask = MASK_SHOT|CONTENTS_SLIME|CONTENTS_LAVA;
  571. while (ignore)
  572. {
  573. tr = gi.trace (from, NULL, NULL, end, ignore, mask);
  574. if (tr.contents & (CONTENTS_SLIME|CONTENTS_LAVA))
  575. {
  576. mask &= ~(CONTENTS_SLIME|CONTENTS_LAVA);
  577. water = true;
  578. }
  579. else
  580. {
  581. if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
  582. ignore = tr.ent;
  583. else
  584. ignore = NULL;
  585. if ((tr.ent != self) && (tr.ent->takedamage))
  586. T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);
  587. }
  588. VectorCopy (tr.endpos, from);
  589. }
  590. // send gun puff / flash
  591. gi.WriteByte (svc_temp_entity);
  592. gi.WriteByte (TE_RAILTRAIL);
  593. gi.WritePosition (start);
  594. gi.WritePosition (tr.endpos);
  595. gi.multicast (self->s.origin, MULTICAST_PHS);
  596. // gi.multicast (start, MULTICAST_PHS);
  597. if (water)
  598. {
  599. gi.WriteByte (svc_temp_entity);
  600. gi.WriteByte (TE_RAILTRAIL);
  601. gi.WritePosition (start);
  602. gi.WritePosition (tr.endpos);
  603. gi.multicast (tr.endpos, MULTICAST_PHS);
  604. }
  605. if (self->client)
  606. PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
  607. }
  608. /*
  609. =================
  610. fire_bfg
  611. =================
  612. */
  613. void bfg_explode (edict_t *self)
  614. {
  615. edict_t *ent;
  616. float points;
  617. vec3_t v;
  618. float dist;
  619. if (self->s.frame == 0)
  620. {
  621. // the BFG effect
  622. ent = NULL;
  623. while ((ent = findradius(ent, self->s.origin, self->dmg_radius)) != NULL)
  624. {
  625. if (!ent->takedamage)
  626. continue;
  627. if (ent == self->owner)
  628. continue;
  629. if (!CanDamage (ent, self))
  630. continue;
  631. if (!CanDamage (ent, self->owner))
  632. continue;
  633. VectorAdd (ent->mins, ent->maxs, v);
  634. VectorMA (ent->s.origin, 0.5, v, v);
  635. VectorSubtract (self->s.origin, v, v);
  636. dist = VectorLength(v);
  637. points = self->radius_dmg * (1.0 - sqrt(dist/self->dmg_radius));
  638. if (ent == self->owner)
  639. points = points * 0.5;
  640. gi.WriteByte (svc_temp_entity);
  641. gi.WriteByte (TE_BFG_EXPLOSION);
  642. gi.WritePosition (ent->s.origin);
  643. gi.multicast (ent->s.origin, MULTICAST_PHS);
  644. T_Damage (ent, self, self->owner, self->velocity, ent->s.origin, vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
  645. }
  646. }
  647. self->nextthink = level.time + FRAMETIME;
  648. self->s.frame++;
  649. if (self->s.frame == 5)
  650. self->think = G_FreeEdict;
  651. }
  652. void bfg_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  653. {
  654. if (other == self->owner)
  655. return;
  656. if (surf && (surf->flags & SURF_SKY))
  657. {
  658. G_FreeEdict (self);
  659. return;
  660. }
  661. if (self->owner->client)
  662. PlayerNoise(self->owner, self->s.origin, PNOISE_IMPACT);
  663. // core explosion - prevents firing it into the wall/floor
  664. if (other->takedamage)
  665. T_Damage (other, self, self->owner, self->velocity, self->s.origin, plane->normal, 200, 0, 0, MOD_BFG_BLAST);
  666. T_RadiusDamage(self, self->owner, 200, other, 100, MOD_BFG_BLAST);
  667. gi.sound (self, CHAN_VOICE, gi.soundindex ("weapons/bfg__x1b.wav"), 1, ATTN_NORM, 0);
  668. self->solid = SOLID_NOT;
  669. self->touch = NULL;
  670. VectorMA (self->s.origin, -1 * FRAMETIME, self->velocity, self->s.origin);
  671. VectorClear (self->velocity);
  672. self->s.modelindex = gi.modelindex ("sprites/s_bfg3.sp2");
  673. self->s.frame = 0;
  674. self->s.sound = 0;
  675. self->s.effects &= ~EF_ANIM_ALLFAST;
  676. self->think = bfg_explode;
  677. self->nextthink = level.time + FRAMETIME;
  678. self->enemy = other;
  679. gi.WriteByte (svc_temp_entity);
  680. gi.WriteByte (TE_BFG_BIGEXPLOSION);
  681. gi.WritePosition (self->s.origin);
  682. gi.multicast (self->s.origin, MULTICAST_PVS);
  683. }
  684. void bfg_think (edict_t *self)
  685. {
  686. edict_t *ent;
  687. edict_t *ignore;
  688. vec3_t point;
  689. vec3_t dir;
  690. vec3_t start;
  691. vec3_t end;
  692. int dmg;
  693. trace_t tr;
  694. if (deathmatch->value)
  695. dmg = 5;
  696. else
  697. dmg = 10;
  698. ent = NULL;
  699. while ((ent = findradius(ent, self->s.origin, 256)) != NULL)
  700. {
  701. if (ent == self)
  702. continue;
  703. if (ent == self->owner)
  704. continue;
  705. if (!ent->takedamage)
  706. continue;
  707. if (!(ent->svflags & SVF_MONSTER) && (!ent->client) && (strcmp(ent->classname, "misc_explobox") != 0))
  708. continue;
  709. //ZOID
  710. //don't target players in CTF
  711. if (ctf->value && ent->client &&
  712. self->owner->client &&
  713. ent->client->resp.ctf_team == self->owner->client->resp.ctf_team)
  714. continue;
  715. //ZOID
  716. VectorMA (ent->absmin, 0.5, ent->size, point);
  717. VectorSubtract (point, self->s.origin, dir);
  718. VectorNormalize (dir);
  719. ignore = self;
  720. VectorCopy (self->s.origin, start);
  721. VectorMA (start, 2048, dir, end);
  722. while(1)
  723. {
  724. tr = gi.trace (start, NULL, NULL, end, ignore, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
  725. if (!tr.ent)
  726. break;
  727. // hurt it if we can
  728. if ((tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER) && (tr.ent != self->owner))
  729. T_Damage (tr.ent, self, self->owner, dir, tr.endpos, vec3_origin, dmg, 1, DAMAGE_ENERGY, MOD_BFG_LASER);
  730. // if we hit something that's not a monster or player we're done
  731. if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client))
  732. {
  733. gi.WriteByte (svc_temp_entity);
  734. gi.WriteByte (TE_LASER_SPARKS);
  735. gi.WriteByte (4);
  736. gi.WritePosition (tr.endpos);
  737. gi.WriteDir (tr.plane.normal);
  738. gi.WriteByte (self->s.skinnum);
  739. gi.multicast (tr.endpos, MULTICAST_PVS);
  740. break;
  741. }
  742. ignore = tr.ent;
  743. VectorCopy (tr.endpos, start);
  744. }
  745. gi.WriteByte (svc_temp_entity);
  746. gi.WriteByte (TE_BFG_LASER);
  747. gi.WritePosition (self->s.origin);
  748. gi.WritePosition (tr.endpos);
  749. gi.multicast (self->s.origin, MULTICAST_PHS);
  750. }
  751. self->nextthink = level.time + FRAMETIME;
  752. }
  753. void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius)
  754. {
  755. edict_t *bfg;
  756. bfg = G_Spawn();
  757. VectorCopy (start, bfg->s.origin);
  758. VectorCopy (dir, bfg->movedir);
  759. vectoangles (dir, bfg->s.angles);
  760. VectorScale (dir, speed, bfg->velocity);
  761. bfg->movetype = MOVETYPE_FLYMISSILE;
  762. bfg->clipmask = MASK_SHOT;
  763. bfg->solid = SOLID_BBOX;
  764. bfg->s.effects |= EF_BFG | EF_ANIM_ALLFAST;
  765. VectorClear (bfg->mins);
  766. VectorClear (bfg->maxs);
  767. bfg->s.modelindex = gi.modelindex ("sprites/s_bfg1.sp2");
  768. bfg->owner = self;
  769. bfg->touch = bfg_touch;
  770. bfg->nextthink = level.time + 8000/speed;
  771. bfg->think = G_FreeEdict;
  772. bfg->radius_dmg = damage;
  773. bfg->dmg_radius = damage_radius;
  774. bfg->classname = "bfg blast";
  775. bfg->s.sound = gi.soundindex ("weapons/bfg__l1a.wav");
  776. bfg->think = bfg_think;
  777. bfg->nextthink = level.time + FRAMETIME;
  778. bfg->teammaster = bfg;
  779. bfg->teamchain = NULL;
  780. if (self->client)
  781. check_dodge (self, bfg->s.origin, dir, speed);
  782. gi.linkentity (bfg);
  783. }