m_parasite.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. /*
  16. ==============================================================================
  17. parasite
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_parasite.h"
  22. static int sound_pain1;
  23. static int sound_pain2;
  24. static int sound_die;
  25. static int sound_launch;
  26. static int sound_impact;
  27. static int sound_suck;
  28. static int sound_reelin;
  29. static int sound_sight;
  30. static int sound_tap;
  31. static int sound_scratch;
  32. static int sound_search;
  33. void parasite_stand (edict_t *self);
  34. void parasite_start_run (edict_t *self);
  35. void parasite_run (edict_t *self);
  36. void parasite_walk (edict_t *self);
  37. void parasite_start_walk (edict_t *self);
  38. void parasite_end_fidget (edict_t *self);
  39. void parasite_do_fidget (edict_t *self);
  40. void parasite_refidget (edict_t *self);
  41. void parasite_launch (edict_t *self)
  42. {
  43. gi.sound (self, CHAN_WEAPON, sound_launch, 1, ATTN_NORM, 0);
  44. }
  45. void parasite_reel_in (edict_t *self)
  46. {
  47. gi.sound (self, CHAN_WEAPON, sound_reelin, 1, ATTN_NORM, 0);
  48. }
  49. void parasite_sight (edict_t *self, edict_t *other)
  50. {
  51. gi.sound (self, CHAN_WEAPON, sound_sight, 1, ATTN_NORM, 0);
  52. }
  53. void parasite_tap (edict_t *self)
  54. {
  55. gi.sound (self, CHAN_WEAPON, sound_tap, 1, ATTN_IDLE, 0);
  56. }
  57. void parasite_scratch (edict_t *self)
  58. {
  59. gi.sound (self, CHAN_WEAPON, sound_scratch, 1, ATTN_IDLE, 0);
  60. }
  61. void parasite_search (edict_t *self)
  62. {
  63. gi.sound (self, CHAN_WEAPON, sound_search, 1, ATTN_IDLE, 0);
  64. }
  65. mframe_t parasite_frames_start_fidget [] =
  66. {
  67. ai_stand, 0, NULL,
  68. ai_stand, 0, NULL,
  69. ai_stand, 0, NULL,
  70. ai_stand, 0, NULL
  71. };
  72. mmove_t parasite_move_start_fidget = {FRAME_stand18, FRAME_stand21, parasite_frames_start_fidget, parasite_do_fidget};
  73. mframe_t parasite_frames_fidget [] =
  74. {
  75. ai_stand, 0, parasite_scratch,
  76. ai_stand, 0, NULL,
  77. ai_stand, 0, NULL,
  78. ai_stand, 0, parasite_scratch,
  79. ai_stand, 0, NULL,
  80. ai_stand, 0, NULL
  81. };
  82. mmove_t parasite_move_fidget = {FRAME_stand22, FRAME_stand27, parasite_frames_fidget, parasite_refidget};
  83. mframe_t parasite_frames_end_fidget [] =
  84. {
  85. ai_stand, 0, parasite_scratch,
  86. ai_stand, 0, NULL,
  87. ai_stand, 0, NULL,
  88. ai_stand, 0, NULL,
  89. ai_stand, 0, NULL,
  90. ai_stand, 0, NULL,
  91. ai_stand, 0, NULL,
  92. ai_stand, 0, NULL
  93. };
  94. mmove_t parasite_move_end_fidget = {FRAME_stand28, FRAME_stand35, parasite_frames_end_fidget, parasite_stand};
  95. void parasite_end_fidget (edict_t *self)
  96. {
  97. self->monsterinfo.currentmove = &parasite_move_end_fidget;
  98. }
  99. void parasite_do_fidget (edict_t *self)
  100. {
  101. self->monsterinfo.currentmove = &parasite_move_fidget;
  102. }
  103. void parasite_refidget (edict_t *self)
  104. {
  105. if (random() <= 0.8)
  106. self->monsterinfo.currentmove = &parasite_move_fidget;
  107. else
  108. self->monsterinfo.currentmove = &parasite_move_end_fidget;
  109. }
  110. void parasite_idle (edict_t *self)
  111. {
  112. self->monsterinfo.currentmove = &parasite_move_start_fidget;
  113. }
  114. mframe_t parasite_frames_stand [] =
  115. {
  116. ai_stand, 0, NULL,
  117. ai_stand, 0, NULL,
  118. ai_stand, 0, parasite_tap,
  119. ai_stand, 0, NULL,
  120. ai_stand, 0, parasite_tap,
  121. ai_stand, 0, NULL,
  122. ai_stand, 0, NULL,
  123. ai_stand, 0, NULL,
  124. ai_stand, 0, parasite_tap,
  125. ai_stand, 0, NULL,
  126. ai_stand, 0, parasite_tap,
  127. ai_stand, 0, NULL,
  128. ai_stand, 0, NULL,
  129. ai_stand, 0, NULL,
  130. ai_stand, 0, parasite_tap,
  131. ai_stand, 0, NULL,
  132. ai_stand, 0, parasite_tap
  133. };
  134. mmove_t parasite_move_stand = {FRAME_stand01, FRAME_stand17, parasite_frames_stand, parasite_stand};
  135. void parasite_stand (edict_t *self)
  136. {
  137. self->monsterinfo.currentmove = &parasite_move_stand;
  138. }
  139. mframe_t parasite_frames_run [] =
  140. {
  141. ai_run, 30, NULL,
  142. ai_run, 30, NULL,
  143. ai_run, 22, NULL,
  144. ai_run, 19, NULL,
  145. ai_run, 24, NULL,
  146. ai_run, 28, NULL,
  147. ai_run, 25, NULL
  148. };
  149. mmove_t parasite_move_run = {FRAME_run03, FRAME_run09, parasite_frames_run, NULL};
  150. mframe_t parasite_frames_start_run [] =
  151. {
  152. ai_run, 0, NULL,
  153. ai_run, 30, NULL,
  154. };
  155. mmove_t parasite_move_start_run = {FRAME_run01, FRAME_run02, parasite_frames_start_run, parasite_run};
  156. mframe_t parasite_frames_stop_run [] =
  157. {
  158. ai_run, 20, NULL,
  159. ai_run, 20, NULL,
  160. ai_run, 12, NULL,
  161. ai_run, 10, NULL,
  162. ai_run, 0, NULL,
  163. ai_run, 0, NULL
  164. };
  165. mmove_t parasite_move_stop_run = {FRAME_run10, FRAME_run15, parasite_frames_stop_run, NULL};
  166. void parasite_start_run (edict_t *self)
  167. {
  168. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  169. self->monsterinfo.currentmove = &parasite_move_stand;
  170. else
  171. self->monsterinfo.currentmove = &parasite_move_start_run;
  172. }
  173. void parasite_run (edict_t *self)
  174. {
  175. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  176. self->monsterinfo.currentmove = &parasite_move_stand;
  177. else
  178. self->monsterinfo.currentmove = &parasite_move_run;
  179. }
  180. mframe_t parasite_frames_walk [] =
  181. {
  182. ai_walk, 30, NULL,
  183. ai_walk, 30, NULL,
  184. ai_walk, 22, NULL,
  185. ai_walk, 19, NULL,
  186. ai_walk, 24, NULL,
  187. ai_walk, 28, NULL,
  188. ai_walk, 25, NULL
  189. };
  190. mmove_t parasite_move_walk = {FRAME_run03, FRAME_run09, parasite_frames_walk, parasite_walk};
  191. mframe_t parasite_frames_start_walk [] =
  192. {
  193. ai_walk, 0, NULL,
  194. ai_walk, 30, parasite_walk
  195. };
  196. mmove_t parasite_move_start_walk = {FRAME_run01, FRAME_run02, parasite_frames_start_walk, NULL};
  197. mframe_t parasite_frames_stop_walk [] =
  198. {
  199. ai_walk, 20, NULL,
  200. ai_walk, 20, NULL,
  201. ai_walk, 12, NULL,
  202. ai_walk, 10, NULL,
  203. ai_walk, 0, NULL,
  204. ai_walk, 0, NULL
  205. };
  206. mmove_t parasite_move_stop_walk = {FRAME_run10, FRAME_run15, parasite_frames_stop_walk, NULL};
  207. void parasite_start_walk (edict_t *self)
  208. {
  209. self->monsterinfo.currentmove = &parasite_move_start_walk;
  210. }
  211. void parasite_walk (edict_t *self)
  212. {
  213. self->monsterinfo.currentmove = &parasite_move_walk;
  214. }
  215. mframe_t parasite_frames_pain1 [] =
  216. {
  217. ai_move, 0, NULL,
  218. ai_move, 0, NULL,
  219. ai_move, 0, NULL,
  220. ai_move, 0, NULL,
  221. ai_move, 0, NULL,
  222. ai_move, 0, NULL,
  223. ai_move, 6, NULL,
  224. ai_move, 16, NULL,
  225. ai_move, -6, NULL,
  226. ai_move, -7, NULL,
  227. ai_move, 0, NULL
  228. };
  229. mmove_t parasite_move_pain1 = {FRAME_pain101, FRAME_pain111, parasite_frames_pain1, parasite_start_run};
  230. void parasite_pain (edict_t *self, edict_t *other, float kick, int damage)
  231. {
  232. if (self->health < (self->max_health / 2))
  233. self->s.skinnum = 1;
  234. if (level.time < self->pain_debounce_time)
  235. return;
  236. self->pain_debounce_time = level.time + 3;
  237. if (skill->value == 3)
  238. return; // no pain anims in nightmare
  239. if (random() < 0.5)
  240. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  241. else
  242. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  243. self->monsterinfo.currentmove = &parasite_move_pain1;
  244. }
  245. static qboolean parasite_drain_attack_ok (vec3_t start, vec3_t end)
  246. {
  247. vec3_t dir, angles;
  248. // check for max distance
  249. VectorSubtract (start, end, dir);
  250. if (VectorLength(dir) > 256)
  251. return false;
  252. // check for min/max pitch
  253. vectoangles (dir, angles);
  254. if (angles[0] < -180)
  255. angles[0] += 360;
  256. if (fabs(angles[0]) > 30)
  257. return false;
  258. return true;
  259. }
  260. void parasite_drain_attack (edict_t *self)
  261. {
  262. vec3_t offset, start, f, r, end, dir;
  263. trace_t tr;
  264. int damage;
  265. AngleVectors (self->s.angles, f, r, NULL);
  266. VectorSet (offset, 24, 0, 6);
  267. G_ProjectSource (self->s.origin, offset, f, r, start);
  268. VectorCopy (self->enemy->s.origin, end);
  269. if (!parasite_drain_attack_ok(start, end))
  270. {
  271. end[2] = self->enemy->s.origin[2] + self->enemy->maxs[2] - 8;
  272. if (!parasite_drain_attack_ok(start, end))
  273. {
  274. end[2] = self->enemy->s.origin[2] + self->enemy->mins[2] + 8;
  275. if (!parasite_drain_attack_ok(start, end))
  276. return;
  277. }
  278. }
  279. VectorCopy (self->enemy->s.origin, end);
  280. tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
  281. if (tr.ent != self->enemy)
  282. return;
  283. if (self->s.frame == FRAME_drain03)
  284. {
  285. damage = 5;
  286. gi.sound (self->enemy, CHAN_AUTO, sound_impact, 1, ATTN_NORM, 0);
  287. }
  288. else
  289. {
  290. if (self->s.frame == FRAME_drain04)
  291. gi.sound (self, CHAN_WEAPON, sound_suck, 1, ATTN_NORM, 0);
  292. damage = 2;
  293. }
  294. gi.WriteByte (svc_temp_entity);
  295. gi.WriteByte (TE_PARASITE_ATTACK);
  296. gi.WriteShort (self - g_edicts);
  297. gi.WritePosition (start);
  298. gi.WritePosition (end);
  299. gi.multicast (self->s.origin, MULTICAST_PVS);
  300. VectorSubtract (start, end, dir);
  301. T_Damage (self->enemy, self, self, dir, self->enemy->s.origin, vec3_origin, damage, 0, DAMAGE_NO_KNOCKBACK, MOD_UNKNOWN);
  302. }
  303. mframe_t parasite_frames_drain [] =
  304. {
  305. ai_charge, 0, parasite_launch,
  306. ai_charge, 0, NULL,
  307. ai_charge, 15, parasite_drain_attack, // Target hits
  308. ai_charge, 0, parasite_drain_attack, // drain
  309. ai_charge, 0, parasite_drain_attack, // drain
  310. ai_charge, 0, parasite_drain_attack, // drain
  311. ai_charge, 0, parasite_drain_attack, // drain
  312. ai_charge, -2, parasite_drain_attack, // drain
  313. ai_charge, -2, parasite_drain_attack, // drain
  314. ai_charge, -3, parasite_drain_attack, // drain
  315. ai_charge, -2, parasite_drain_attack, // drain
  316. ai_charge, 0, parasite_drain_attack, // drain
  317. ai_charge, -1, parasite_drain_attack, // drain
  318. ai_charge, 0, parasite_reel_in, // let go
  319. ai_charge, -2, NULL,
  320. ai_charge, -2, NULL,
  321. ai_charge, -3, NULL,
  322. ai_charge, 0, NULL
  323. };
  324. mmove_t parasite_move_drain = {FRAME_drain01, FRAME_drain18, parasite_frames_drain, parasite_start_run};
  325. mframe_t parasite_frames_break [] =
  326. {
  327. ai_charge, 0, NULL,
  328. ai_charge, -3, NULL,
  329. ai_charge, 1, NULL,
  330. ai_charge, 2, NULL,
  331. ai_charge, -3, NULL,
  332. ai_charge, 1, NULL,
  333. ai_charge, 1, NULL,
  334. ai_charge, 3, NULL,
  335. ai_charge, 0, NULL,
  336. ai_charge, -18, NULL,
  337. ai_charge, 3, NULL,
  338. ai_charge, 9, NULL,
  339. ai_charge, 6, NULL,
  340. ai_charge, 0, NULL,
  341. ai_charge, -18, NULL,
  342. ai_charge, 0, NULL,
  343. ai_charge, 8, NULL,
  344. ai_charge, 9, NULL,
  345. ai_charge, 0, NULL,
  346. ai_charge, -18, NULL,
  347. ai_charge, 0, NULL,
  348. ai_charge, 0, NULL, // airborne
  349. ai_charge, 0, NULL, // airborne
  350. ai_charge, 0, NULL, // slides
  351. ai_charge, 0, NULL, // slides
  352. ai_charge, 0, NULL, // slides
  353. ai_charge, 0, NULL, // slides
  354. ai_charge, 4, NULL,
  355. ai_charge, 11, NULL,
  356. ai_charge, -2, NULL,
  357. ai_charge, -5, NULL,
  358. ai_charge, 1, NULL
  359. };
  360. mmove_t parasite_move_break = {FRAME_break01, FRAME_break32, parasite_frames_break, parasite_start_run};
  361. /*
  362. ===
  363. Break Stuff Ends
  364. ===
  365. */
  366. void parasite_attack (edict_t *self)
  367. {
  368. // if (random() <= 0.2)
  369. // self->monsterinfo.currentmove = &parasite_move_break;
  370. // else
  371. self->monsterinfo.currentmove = &parasite_move_drain;
  372. }
  373. /*
  374. ===
  375. Death Stuff Starts
  376. ===
  377. */
  378. void parasite_dead (edict_t *self)
  379. {
  380. VectorSet (self->mins, -16, -16, -24);
  381. VectorSet (self->maxs, 16, 16, -8);
  382. self->movetype = MOVETYPE_TOSS;
  383. self->svflags |= SVF_DEADMONSTER;
  384. self->nextthink = 0;
  385. gi.linkentity (self);
  386. }
  387. mframe_t parasite_frames_death [] =
  388. {
  389. ai_move, 0, NULL,
  390. ai_move, 0, NULL,
  391. ai_move, 0, NULL,
  392. ai_move, 0, NULL,
  393. ai_move, 0, NULL,
  394. ai_move, 0, NULL,
  395. ai_move, 0, NULL
  396. };
  397. mmove_t parasite_move_death = {FRAME_death101, FRAME_death107, parasite_frames_death, parasite_dead};
  398. void parasite_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  399. {
  400. int n;
  401. // check for gib
  402. if (self->health <= self->gib_health)
  403. {
  404. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  405. for (n= 0; n < 2; n++)
  406. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  407. for (n= 0; n < 4; n++)
  408. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  409. ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  410. self->deadflag = DEAD_DEAD;
  411. return;
  412. }
  413. if (self->deadflag == DEAD_DEAD)
  414. return;
  415. // regular death
  416. gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  417. self->deadflag = DEAD_DEAD;
  418. self->takedamage = DAMAGE_YES;
  419. self->monsterinfo.currentmove = &parasite_move_death;
  420. }
  421. /*
  422. ===
  423. End Death Stuff
  424. ===
  425. */
  426. /*QUAKED monster_parasite (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  427. */
  428. void SP_monster_parasite (edict_t *self)
  429. {
  430. if (deathmatch->value)
  431. {
  432. G_FreeEdict (self);
  433. return;
  434. }
  435. sound_pain1 = gi.soundindex ("parasite/parpain1.wav");
  436. sound_pain2 = gi.soundindex ("parasite/parpain2.wav");
  437. sound_die = gi.soundindex ("parasite/pardeth1.wav");
  438. sound_launch = gi.soundindex("parasite/paratck1.wav");
  439. sound_impact = gi.soundindex("parasite/paratck2.wav");
  440. sound_suck = gi.soundindex("parasite/paratck3.wav");
  441. sound_reelin = gi.soundindex("parasite/paratck4.wav");
  442. sound_sight = gi.soundindex("parasite/parsght1.wav");
  443. sound_tap = gi.soundindex("parasite/paridle1.wav");
  444. sound_scratch = gi.soundindex("parasite/paridle2.wav");
  445. sound_search = gi.soundindex("parasite/parsrch1.wav");
  446. self->s.modelindex = gi.modelindex ("models/monsters/parasite/tris.md2");
  447. VectorSet (self->mins, -16, -16, -24);
  448. VectorSet (self->maxs, 16, 16, 24);
  449. self->movetype = MOVETYPE_STEP;
  450. self->solid = SOLID_BBOX;
  451. self->health = 175;
  452. self->gib_health = -50;
  453. self->mass = 250;
  454. self->pain = parasite_pain;
  455. self->die = parasite_die;
  456. self->monsterinfo.stand = parasite_stand;
  457. self->monsterinfo.walk = parasite_start_walk;
  458. self->monsterinfo.run = parasite_start_run;
  459. self->monsterinfo.attack = parasite_attack;
  460. self->monsterinfo.sight = parasite_sight;
  461. self->monsterinfo.idle = parasite_idle;
  462. gi.linkentity (self);
  463. self->monsterinfo.currentmove = &parasite_move_stand;
  464. self->monsterinfo.scale = MODEL_SCALE;
  465. walkmonster_start (self);
  466. }