m_parasite.c 13 KB

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