m_parasite.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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. constexpr float g_athena_parasite_miss_chance = 0.1f;
  11. constexpr float g_athena_parasite_proboscis_speed = 1250;
  12. constexpr float g_athena_parasite_proboscis_retract_modifier = 2.0f;
  13. static cached_soundindex sound_pain1;
  14. static cached_soundindex sound_pain2;
  15. static cached_soundindex sound_die;
  16. static cached_soundindex sound_launch;
  17. static cached_soundindex sound_impact;
  18. static cached_soundindex sound_suck;
  19. static cached_soundindex sound_reelin;
  20. static cached_soundindex sound_sight;
  21. static cached_soundindex sound_tap;
  22. static cached_soundindex sound_scratch;
  23. static cached_soundindex sound_search;
  24. void parasite_stand(edict_t *self);
  25. void parasite_start_run(edict_t *self);
  26. void parasite_run(edict_t *self);
  27. void parasite_walk(edict_t *self);
  28. void parasite_end_fidget(edict_t *self);
  29. void parasite_do_fidget(edict_t *self);
  30. void parasite_refidget(edict_t *self);
  31. void parasite_launch(edict_t *self)
  32. {
  33. gi.sound(self, CHAN_WEAPON, sound_launch, 1, ATTN_NORM, 0);
  34. }
  35. void parasite_reel_in(edict_t *self)
  36. {
  37. gi.sound(self, CHAN_WEAPON, sound_reelin, 1, ATTN_NORM, 0);
  38. }
  39. MONSTERINFO_SIGHT(parasite_sight) (edict_t *self, edict_t *other) -> void
  40. {
  41. gi.sound(self, CHAN_WEAPON, sound_sight, 1, ATTN_NORM, 0);
  42. }
  43. void parasite_tap(edict_t *self)
  44. {
  45. gi.sound(self, CHAN_WEAPON, sound_tap, 0.75f, 2.75f, 0);
  46. }
  47. void parasite_scratch(edict_t *self)
  48. {
  49. gi.sound(self, CHAN_WEAPON, sound_scratch, 0.75f, 2.75f, 0);
  50. }
  51. #if 0
  52. void parasite_search(edict_t *self)
  53. {
  54. gi.sound(self, CHAN_WEAPON, sound_search, 1, ATTN_IDLE, 0);
  55. }
  56. #endif
  57. mframe_t parasite_frames_start_fidget[] = {
  58. { ai_stand },
  59. { ai_stand },
  60. { ai_stand },
  61. { ai_stand }
  62. };
  63. MMOVE_T(parasite_move_start_fidget) = { FRAME_stand18, FRAME_stand21, parasite_frames_start_fidget, parasite_do_fidget };
  64. mframe_t parasite_frames_fidget[] = {
  65. { ai_stand, 0, parasite_scratch },
  66. { ai_stand },
  67. { ai_stand },
  68. { ai_stand, 0, parasite_scratch },
  69. { ai_stand },
  70. { ai_stand }
  71. };
  72. MMOVE_T(parasite_move_fidget) = { FRAME_stand22, FRAME_stand27, parasite_frames_fidget, parasite_refidget };
  73. mframe_t parasite_frames_end_fidget[] = {
  74. { ai_stand, 0, parasite_scratch },
  75. { ai_stand },
  76. { ai_stand },
  77. { ai_stand },
  78. { ai_stand },
  79. { ai_stand },
  80. { ai_stand },
  81. { ai_stand }
  82. };
  83. MMOVE_T(parasite_move_end_fidget) = { FRAME_stand28, FRAME_stand35, parasite_frames_end_fidget, parasite_stand };
  84. void parasite_end_fidget(edict_t *self)
  85. {
  86. M_SetAnimation(self, &parasite_move_end_fidget);
  87. }
  88. void parasite_do_fidget(edict_t *self)
  89. {
  90. M_SetAnimation(self, &parasite_move_fidget);
  91. }
  92. void parasite_refidget(edict_t *self)
  93. {
  94. if (frandom() <= 0.8f)
  95. M_SetAnimation(self, &parasite_move_fidget);
  96. else
  97. M_SetAnimation(self, &parasite_move_end_fidget);
  98. }
  99. MONSTERINFO_IDLE(parasite_idle) (edict_t *self) -> void
  100. {
  101. if (self->enemy)
  102. return;
  103. M_SetAnimation(self, &parasite_move_start_fidget);
  104. }
  105. mframe_t parasite_frames_stand[] = {
  106. { ai_stand },
  107. { ai_stand },
  108. { ai_stand, 0, parasite_tap },
  109. { ai_stand },
  110. { ai_stand, 0, parasite_tap },
  111. { ai_stand },
  112. { ai_stand },
  113. { ai_stand },
  114. { ai_stand, 0, parasite_tap },
  115. { ai_stand },
  116. { ai_stand, 0, parasite_tap },
  117. { ai_stand },
  118. { ai_stand },
  119. { ai_stand },
  120. { ai_stand, 0, parasite_tap },
  121. { ai_stand },
  122. { ai_stand, 0, parasite_tap }
  123. };
  124. MMOVE_T(parasite_move_stand) = { FRAME_stand01, FRAME_stand17, parasite_frames_stand, parasite_stand };
  125. MONSTERINFO_STAND(parasite_stand) (edict_t *self) -> void
  126. {
  127. M_SetAnimation(self, &parasite_move_stand);
  128. }
  129. mframe_t parasite_frames_run[] = {
  130. { ai_run, 30 },
  131. { ai_run, 30 },
  132. { ai_run, 22, monster_footstep },
  133. { ai_run, 19, monster_footstep },
  134. { ai_run, 24 },
  135. { ai_run, 28, monster_footstep },
  136. { ai_run, 25, monster_footstep }
  137. };
  138. MMOVE_T(parasite_move_run) = { FRAME_run03, FRAME_run09, parasite_frames_run, nullptr };
  139. mframe_t parasite_frames_start_run[] = {
  140. { ai_run },
  141. { ai_run, 30 },
  142. };
  143. MMOVE_T(parasite_move_start_run) = { FRAME_run01, FRAME_run02, parasite_frames_start_run, parasite_run };
  144. #if 0
  145. mframe_t parasite_frames_stop_run[] = {
  146. { ai_run, 20 },
  147. { ai_run, 20 },
  148. { ai_run, 12 },
  149. { ai_run, 10 },
  150. { ai_run },
  151. { ai_run }
  152. };
  153. MMOVE_T(parasite_move_stop_run) = { FRAME_run10, FRAME_run15, parasite_frames_stop_run, nullptr };
  154. #endif
  155. MONSTERINFO_RUN(parasite_start_run) (edict_t *self) -> void
  156. {
  157. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  158. M_SetAnimation(self, &parasite_move_stand);
  159. else
  160. M_SetAnimation(self, &parasite_move_start_run);
  161. }
  162. static void proboscis_retract(edict_t *self);
  163. void parasite_run(edict_t *self)
  164. {
  165. if (self->proboscus && self->proboscus->style != 2)
  166. proboscis_retract(self->proboscus);
  167. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  168. M_SetAnimation(self, &parasite_move_stand);
  169. else
  170. M_SetAnimation(self, &parasite_move_run);
  171. }
  172. mframe_t parasite_frames_walk[] = {
  173. { ai_walk, 30 },
  174. { ai_walk, 30 },
  175. { ai_walk, 22, monster_footstep },
  176. { ai_walk, 19, monster_footstep },
  177. { ai_walk, 24 },
  178. { ai_walk, 28, monster_footstep },
  179. { ai_walk, 25, monster_footstep }
  180. };
  181. MMOVE_T(parasite_move_walk) = { FRAME_run03, FRAME_run09, parasite_frames_walk, parasite_walk };
  182. mframe_t parasite_frames_start_walk[] = {
  183. { ai_walk, 0 },
  184. { ai_walk, 30, parasite_walk }
  185. };
  186. MMOVE_T(parasite_move_start_walk) = { FRAME_run01, FRAME_run02, parasite_frames_start_walk, nullptr };
  187. #if 0
  188. mframe_t parasite_frames_stop_walk[] = {
  189. { ai_walk, 20 },
  190. { ai_walk, 20 },
  191. { ai_walk, 12 },
  192. { ai_walk, 10 },
  193. { ai_walk },
  194. { ai_walk }
  195. };
  196. MMOVE_T(parasite_move_stop_walk) = { FRAME_run10, FRAME_run15, parasite_frames_stop_walk, nullptr };
  197. #endif
  198. MONSTERINFO_WALK(parasite_start_walk) (edict_t *self) -> void
  199. {
  200. M_SetAnimation(self, &parasite_move_start_walk);
  201. }
  202. void parasite_walk(edict_t *self)
  203. {
  204. M_SetAnimation(self, &parasite_move_walk);
  205. }
  206. // hard reset on proboscis; like we never existed
  207. THINK(proboscis_reset) (edict_t *self) -> void
  208. {
  209. self->owner->proboscus = nullptr;
  210. G_FreeEdict(self->proboscus);
  211. G_FreeEdict(self);
  212. }
  213. DIE(proboscis_die) (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void
  214. {
  215. if (mod.id == MOD_CRUSH)
  216. proboscis_reset(self);
  217. }
  218. extern const mmove_t parasite_move_fire_proboscis;
  219. static void parasite_break_wait(edict_t *self)
  220. {
  221. // prob exploded?
  222. if (self->proboscus && self->proboscus->style != 3)
  223. self->monsterinfo.nextframe = FRAME_break19;
  224. else if (brandom())
  225. {
  226. // don't get hurt
  227. parasite_reel_in(self);
  228. self->monsterinfo.nextframe = FRAME_break31;
  229. }
  230. }
  231. static void proboscis_retract(edict_t *self)
  232. {
  233. // start retract animation
  234. if (self->owner->monsterinfo.active_move == &parasite_move_fire_proboscis)
  235. self->owner->monsterinfo.nextframe = FRAME_drain12;
  236. // mark as retracting
  237. self->movetype = MOVETYPE_NONE;
  238. self->solid = SOLID_NOT;
  239. // come back real hard
  240. if (self->style != 2)
  241. self->speed *= g_athena_parasite_proboscis_retract_modifier;
  242. self->style = 2;
  243. gi.linkentity(self);
  244. }
  245. static void parasite_break_retract(edict_t *self)
  246. {
  247. if (self->proboscus)
  248. proboscis_retract(self->proboscus);
  249. }
  250. static void parasite_break_sound(edict_t *self)
  251. {
  252. if (frandom() < 0.5f)
  253. gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  254. else
  255. gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  256. self->pain_debounce_time = level.time + 3_sec;
  257. }
  258. void proboscis_segment_draw(edict_t *self);
  259. static void parasite_charge_proboscis(edict_t *self, float dist)
  260. {
  261. if (self->s.frame >= FRAME_break01 && self->s.frame <= FRAME_break32)
  262. ai_move(self, dist);
  263. else
  264. ai_charge(self, dist);
  265. if (self->proboscus)
  266. proboscis_segment_draw(self->proboscus->proboscus);
  267. }
  268. static void parasite_break_noise(edict_t *self)
  269. {
  270. gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  271. }
  272. constexpr mframe_t parasite_frames_break[] = {
  273. { parasite_charge_proboscis },
  274. { parasite_charge_proboscis, -3, parasite_break_noise },
  275. { parasite_charge_proboscis, 1 },
  276. { parasite_charge_proboscis, 2 },
  277. { parasite_charge_proboscis, -3 },
  278. { parasite_charge_proboscis, 1 },
  279. { parasite_charge_proboscis, 1 },
  280. { parasite_charge_proboscis, 3 },
  281. { parasite_charge_proboscis, 0, parasite_break_noise },
  282. { parasite_charge_proboscis, -18 },
  283. { parasite_charge_proboscis, 3 },
  284. { parasite_charge_proboscis, 9 },
  285. { parasite_charge_proboscis, 6 },
  286. { parasite_charge_proboscis },
  287. { parasite_charge_proboscis, -18 },
  288. { parasite_charge_proboscis },
  289. { parasite_charge_proboscis, 8, parasite_break_retract },
  290. { parasite_charge_proboscis, 9 },
  291. { parasite_charge_proboscis, 0, parasite_break_wait },
  292. { parasite_charge_proboscis, -18, parasite_break_sound },
  293. { parasite_charge_proboscis },
  294. { parasite_charge_proboscis }, // airborne
  295. { parasite_charge_proboscis }, // airborne
  296. { parasite_charge_proboscis }, // slides
  297. { parasite_charge_proboscis }, // slides
  298. { parasite_charge_proboscis }, // slides
  299. { parasite_charge_proboscis }, // slides
  300. { parasite_charge_proboscis, 4 },
  301. { parasite_charge_proboscis, 11 },
  302. { parasite_charge_proboscis, -2 },
  303. { parasite_charge_proboscis, -5 },
  304. { parasite_charge_proboscis, 1 }
  305. };
  306. MMOVE_T(parasite_move_break) = { FRAME_break01, FRAME_break32, parasite_frames_break, parasite_start_run };
  307. TOUCH(proboscis_touch) (edict_t *self, edict_t *other, const trace_t &tr, bool other_touching_self) -> void
  308. {
  309. // owner isn't trying to probe any more, don't touch anything
  310. if (self->owner->monsterinfo.active_move != &parasite_move_fire_proboscis)
  311. return;
  312. vec3_t p;
  313. // hit what we want to succ
  314. if ((other->svflags & SVF_PLAYER) || other == self->owner->enemy)
  315. {
  316. if (tr.startsolid)
  317. p = tr.endpos;
  318. else
  319. p = tr.endpos - ((self->s.origin - tr.endpos).normalized() * 12);
  320. self->owner->monsterinfo.nextframe = FRAME_drain06;
  321. self->movetype = MOVETYPE_NONE;
  322. self->solid = SOLID_NOT;
  323. self->style = 1;
  324. // stick to this guy
  325. self->move_origin = p - other->s.origin;
  326. self->enemy = other;
  327. self->s.alpha = 0.35f;
  328. gi.sound(self, CHAN_WEAPON, sound_suck, 1, ATTN_NORM, 0);
  329. }
  330. else
  331. {
  332. p = tr.endpos + tr.plane.normal;
  333. // hit monster, don't suck but do small damage
  334. // and retract immediately
  335. if (other->svflags & (SVF_MONSTER | SVF_DEADMONSTER))
  336. proboscis_retract(self);
  337. else
  338. {
  339. // hit wall; stick to it and do break animation
  340. self->owner->monsterinfo.active_move = &parasite_move_break;
  341. self->movetype = MOVETYPE_NONE;
  342. self->solid = SOLID_NOT;
  343. self->style = 1;
  344. self->owner->s.angles[YAW] = self->s.angles[YAW];
  345. }
  346. }
  347. if (other->takedamage)
  348. T_Damage(other, self, self->owner, tr.plane.normal, tr.endpos, tr.plane.normal, 5, 0, DAMAGE_NONE, MOD_UNKNOWN);
  349. gi.positioned_sound(tr.endpos, self->owner, CHAN_AUTO, sound_impact, 1, ATTN_NORM, 0);
  350. self->s.origin = p;
  351. self->nextthink = level.time + FRAME_TIME_S; // start doing stuff on next frame
  352. gi.linkentity(self);
  353. }
  354. // from break01
  355. constexpr vec3_t parasite_break_offsets[] = {
  356. { 7.0f, 0, 7.0f },
  357. { 6.3f, 14.5f, 4.0f },
  358. { 8.5f, 0, 5.6f },
  359. { 5.0f, -15.25f, 4.0f, },
  360. { 9.5f, -1.8f, 5.9f },
  361. { 6.2f, 14.f, 4.0f },
  362. { 12.25f, 7.5f, 1.4f },
  363. { 13.8f, 0, -2.4f },
  364. { 13.8f, 0, -4.0f },
  365. { 0.1f, 0, -0.7f },
  366. { 5.0f, 0, 3.7f },
  367. { 11.f, 0, 4.f },
  368. { 13.5f, 0, -4.0f },
  369. { 13.5f, 0, -4.0f },
  370. { 0.2f, 0, -0.7f },
  371. { 3.9f, 0, 3.6f },
  372. { 8.5f, 0, 5.0f },
  373. { 14.0f, 0, -4.f },
  374. { 14.0f, 0, -4.f },
  375. { 0.1f, 0, -0.5f }
  376. };
  377. // from drain01
  378. constexpr vec3_t parasite_drain_offsets[] = {
  379. { -1.7f, 0, 1.2f },
  380. { -2.2f, 0, -0.6f },
  381. { 7.7f, 0, 7.2f },
  382. { 7.2f, 0, 5.7f },
  383. { 6.2f, 0, 7.8f },
  384. { 4.7f, 0, 6.7f },
  385. { 5.0f, 0, 9.0f },
  386. { 5.0f, 0, 7.0f },
  387. { 5.0f, 0, 10.5f },
  388. { 4.5f, 0, 9.7f },
  389. { 1.5f, 0, 12.0f },
  390. { 2.9f, 0, 11.0f },
  391. { 2.1f, 0, 7.6f },
  392. };
  393. vec3_t parasite_get_proboscis_start(edict_t *self)
  394. {
  395. vec3_t f, r, start;
  396. AngleVectors(self->s.angles, f, r, nullptr);
  397. vec3_t offset;
  398. if (self->s.frame >= FRAME_break01 && self->s.frame < FRAME_break01 + q_countof(parasite_break_offsets))
  399. offset = parasite_break_offsets[self->s.frame - FRAME_break01];
  400. else if (self->s.frame >= FRAME_drain01 && self->s.frame < FRAME_drain01 + q_countof(parasite_drain_offsets))
  401. offset = parasite_drain_offsets[self->s.frame - FRAME_drain01];
  402. else
  403. offset = { 8, 0, 6 };
  404. start = M_ProjectFlashSource(self, offset, f, r);
  405. return start;
  406. }
  407. THINK(proboscis_think) (edict_t *self) -> void
  408. {
  409. self->nextthink = level.time + FRAME_TIME_S; // start doing stuff on next frame
  410. // retracting; keep pulling until we hit the parasite
  411. if (self->style == 2)
  412. {
  413. vec3_t start = parasite_get_proboscis_start(self->owner);
  414. vec3_t dir = (self->s.origin - start);
  415. float dist = dir.normalize();
  416. if (dist <= (self->speed * 2) * gi.frame_time_s)
  417. {
  418. // reached target; free self on next frame, let parasite know
  419. self->style = 3;
  420. self->think = proboscis_reset;
  421. self->s.origin = start;
  422. gi.linkentity(self);
  423. return;
  424. }
  425. // pull us in
  426. self->s.origin -= dir * (self->speed * gi.frame_time_s);
  427. gi.linkentity(self);
  428. }
  429. // stuck on target; do damage, suck health
  430. // and check if target goes away
  431. else if (self->style == 1)
  432. {
  433. if (!self->enemy)
  434. {
  435. // stuck in wall
  436. }
  437. else if (!self->enemy->inuse || self->enemy->health <= 0 || !self->enemy->takedamage)
  438. {
  439. // target gone, retract early
  440. proboscis_retract(self);
  441. }
  442. else
  443. {
  444. // update our position
  445. self->s.origin = self->enemy->s.origin + self->move_origin;
  446. vec3_t start = parasite_get_proboscis_start(self->owner);
  447. self->s.angles = vectoangles((self->s.origin - start).normalized());
  448. // see if we got cut by the world
  449. trace_t tr = gi.traceline(start, self->s.origin, nullptr, MASK_SOLID);
  450. if (tr.fraction != 1.0f)
  451. {
  452. // blocked, so retract
  453. proboscis_retract(self);
  454. self->s.origin = self->s.old_origin;
  455. }
  456. else
  457. {
  458. // succ & drain
  459. if (self->timestamp <= level.time)
  460. {
  461. T_Damage(self->enemy, self, self->owner, tr.plane.normal, tr.endpos, tr.plane.normal, 2, 0, DAMAGE_NONE, MOD_UNKNOWN);
  462. self->owner->health = min(self->owner->max_health, self->owner->health + 2);
  463. self->owner->monsterinfo.setskin(self->owner);
  464. self->timestamp = level.time + 10_hz;
  465. }
  466. }
  467. gi.linkentity(self);
  468. }
  469. }
  470. // flying
  471. else if (self->style == 0)
  472. {
  473. // owner gone away?
  474. if (!self->owner->enemy || !self->owner->enemy->inuse || self->owner->enemy->health <= 0)
  475. {
  476. proboscis_retract(self);
  477. return;
  478. }
  479. // if we're well behind our target and missed by 2x velocity,
  480. // be smart enough to pull in automatically
  481. vec3_t to_target = (self->s.origin - self->owner->enemy->s.origin);
  482. float dist_to_target = to_target.normalize();
  483. if (dist_to_target > (self->speed * 2) / 15.f)
  484. {
  485. vec3_t from_owner = (self->s.origin - self->owner->s.origin).normalized();
  486. float dot = to_target.dot(from_owner);
  487. if (dot > 0.f)
  488. {
  489. proboscis_retract(self);
  490. return;
  491. }
  492. }
  493. }
  494. }
  495. PRETHINK(proboscis_segment_draw) (edict_t *self) -> void
  496. {
  497. vec3_t start = parasite_get_proboscis_start(self->owner->owner);
  498. self->s.origin = start;
  499. self->s.old_origin = self->owner->s.origin - ((self->owner->s.origin - start).normalized() * 8.f);
  500. gi.linkentity(self);
  501. }
  502. static void fire_proboscis(edict_t *self, vec3_t start, vec3_t dir, float speed)
  503. {
  504. edict_t *tip = G_Spawn();
  505. tip->s.angles = vectoangles(dir);
  506. tip->s.modelindex = gi.modelindex("models/monsters/parasite/tip/tris.md2");
  507. tip->movetype = MOVETYPE_FLYMISSILE;
  508. tip->owner = self;
  509. self->proboscus = tip;
  510. tip->clipmask = MASK_PROJECTILE & ~CONTENTS_DEADMONSTER;
  511. tip->s.origin = tip->s.old_origin = start;
  512. tip->speed = speed;
  513. tip->velocity = dir * speed;
  514. tip->solid = SOLID_BBOX;
  515. tip->takedamage = true;
  516. tip->flags |= FL_NO_DAMAGE_EFFECTS | FL_NO_KNOCKBACK;
  517. tip->die = proboscis_die;
  518. tip->touch = proboscis_touch;
  519. tip->think = proboscis_think;
  520. tip->nextthink = level.time + FRAME_TIME_S; // start doing stuff on next frame
  521. tip->svflags |= SVF_PROJECTILE;
  522. edict_t *segment = G_Spawn();
  523. segment->s.modelindex = gi.modelindex("models/monsters/parasite/segment/tris.md2");
  524. segment->s.renderfx = RF_BEAM;
  525. segment->postthink = proboscis_segment_draw;
  526. tip->proboscus = segment;
  527. segment->owner = tip;
  528. trace_t tr = gi.traceline(tip->s.origin, tip->s.origin + (tip->velocity * gi.frame_time_s), self, tip->clipmask);
  529. if (tr.startsolid)
  530. {
  531. tr.plane.normal = -dir;
  532. tr.endpos = start;
  533. tip->touch(tip, tr.ent, tr, false);
  534. }
  535. else if (tr.fraction < 1.0f)
  536. tip->touch(tip, tr.ent, tr, false);
  537. segment->s.origin = start;
  538. segment->s.old_origin = tip->s.origin + ((tip->s.origin - start).normalized() * 8.f);
  539. gi.linkentity(tip);
  540. gi.linkentity(segment);
  541. }
  542. static void parasite_fire_proboscis(edict_t *self)
  543. {
  544. if (self->proboscus && self->proboscus->style != 2)
  545. proboscis_reset(self->proboscus);
  546. vec3_t start = parasite_get_proboscis_start(self);
  547. vec3_t dir;
  548. PredictAim(self, self->enemy, start, g_athena_parasite_proboscis_speed, false, crandom_open() * g_athena_parasite_miss_chance, &dir, nullptr);
  549. fire_proboscis(self, start, dir, g_athena_parasite_proboscis_speed);
  550. }
  551. static void parasite_proboscis_wait(edict_t *self)
  552. {
  553. // loop frames while we wait
  554. if (self->s.frame == FRAME_drain04)
  555. self->monsterinfo.nextframe = FRAME_drain05;
  556. else
  557. self->monsterinfo.nextframe = FRAME_drain04;
  558. }
  559. static void parasite_proboscis_pull_wait(edict_t *self)
  560. {
  561. // prob exploded?
  562. if (!self->proboscus || self->proboscus->style == 3)
  563. {
  564. self->monsterinfo.nextframe = FRAME_drain14;
  565. return;
  566. }
  567. // being pulled in, so wait until we get destroyed
  568. if (self->s.frame == FRAME_drain12)
  569. self->monsterinfo.nextframe = FRAME_drain13;
  570. else
  571. self->monsterinfo.nextframe = FRAME_drain12;
  572. if (self->proboscus->style != 2)
  573. proboscis_retract(self->proboscus);
  574. }
  575. mframe_t parasite_frames_fire_proboscis[] = {
  576. { parasite_charge_proboscis, 0, parasite_launch },
  577. { parasite_charge_proboscis },
  578. { parasite_charge_proboscis, 15, parasite_fire_proboscis }, // Target hits
  579. { parasite_charge_proboscis, 0, parasite_proboscis_wait }, // drain
  580. { parasite_charge_proboscis, 0, parasite_proboscis_wait }, // drain
  581. { parasite_charge_proboscis, 0 }, // drain
  582. { parasite_charge_proboscis, 0 }, // drain
  583. { parasite_charge_proboscis, -2 }, // drain
  584. { parasite_charge_proboscis, -2 }, // drain
  585. { parasite_charge_proboscis, -3 }, // drain
  586. { parasite_charge_proboscis, -2 }, // drain
  587. { parasite_charge_proboscis, 0, parasite_proboscis_pull_wait }, // drain
  588. { parasite_charge_proboscis, -1, parasite_proboscis_pull_wait }, // drain
  589. { parasite_charge_proboscis, 0, parasite_reel_in }, // let go
  590. { parasite_charge_proboscis, -2 },
  591. { parasite_charge_proboscis, -2 },
  592. { parasite_charge_proboscis, -3 },
  593. { parasite_charge_proboscis }
  594. };
  595. MMOVE_T(parasite_move_fire_proboscis) = { FRAME_drain01, FRAME_drain18, parasite_frames_fire_proboscis, parasite_start_run };
  596. MONSTERINFO_ATTACK(parasite_attack) (edict_t *self) -> void
  597. {
  598. if (!M_CheckClearShot(self, parasite_drain_offsets[0]))
  599. return;
  600. if (self->proboscus && self->proboscus->style != 2)
  601. proboscis_retract(self->proboscus);
  602. M_SetAnimation(self, &parasite_move_fire_proboscis);
  603. }
  604. //================
  605. // ROGUE
  606. void parasite_jump_down(edict_t *self)
  607. {
  608. vec3_t forward, up;
  609. AngleVectors(self->s.angles, forward, nullptr, up);
  610. self->velocity += (forward * 100);
  611. self->velocity += (up * 300);
  612. }
  613. void parasite_jump_up(edict_t *self)
  614. {
  615. vec3_t forward, up;
  616. AngleVectors(self->s.angles, forward, nullptr, up);
  617. self->velocity += (forward * 200);
  618. self->velocity += (up * 450);
  619. }
  620. void parasite_jump_wait_land(edict_t *self)
  621. {
  622. if (self->groundentity == nullptr)
  623. {
  624. self->monsterinfo.nextframe = self->s.frame;
  625. if (monster_jump_finished(self))
  626. self->monsterinfo.nextframe = self->s.frame + 1;
  627. }
  628. else
  629. self->monsterinfo.nextframe = self->s.frame + 1;
  630. }
  631. mframe_t parasite_frames_jump_up[] = {
  632. { ai_move, -8 },
  633. { ai_move, -8 },
  634. { ai_move, -8 },
  635. { ai_move, -8, parasite_jump_up },
  636. { ai_move },
  637. { ai_move },
  638. { ai_move, 0, parasite_jump_wait_land },
  639. { ai_move }
  640. };
  641. MMOVE_T(parasite_move_jump_up) = { FRAME_jump01, FRAME_jump08, parasite_frames_jump_up, parasite_run };
  642. mframe_t parasite_frames_jump_down[] = {
  643. { ai_move },
  644. { ai_move },
  645. { ai_move },
  646. { ai_move, 0, parasite_jump_down },
  647. { ai_move },
  648. { ai_move },
  649. { ai_move, 0, parasite_jump_wait_land },
  650. { ai_move }
  651. };
  652. MMOVE_T(parasite_move_jump_down) = { FRAME_jump01, FRAME_jump08, parasite_frames_jump_down, parasite_run };
  653. void parasite_jump(edict_t *self, blocked_jump_result_t result)
  654. {
  655. if (!self->enemy)
  656. return;
  657. if (result == blocked_jump_result_t::JUMP_JUMP_UP)
  658. M_SetAnimation(self, &parasite_move_jump_up);
  659. else
  660. M_SetAnimation(self, &parasite_move_jump_down);
  661. }
  662. /*
  663. ===
  664. Blocked
  665. ===
  666. */
  667. MONSTERINFO_BLOCKED(parasite_blocked) (edict_t *self, float dist) -> bool
  668. {
  669. if (auto result = blocked_checkjump(self, dist); result != blocked_jump_result_t::NO_JUMP)
  670. {
  671. if (result != blocked_jump_result_t::JUMP_TURN)
  672. parasite_jump(self, result);
  673. return true;
  674. }
  675. if (blocked_checkplat(self, dist))
  676. return true;
  677. return false;
  678. }
  679. // ROGUE
  680. //================
  681. /*
  682. ===
  683. Death Stuff Starts
  684. ===
  685. */
  686. void parasite_dead(edict_t *self)
  687. {
  688. self->mins = { -16, -16, -24 };
  689. self->maxs = { 16, 16, -8 };
  690. monster_dead(self);
  691. }
  692. static void parasite_shrink(edict_t *self)
  693. {
  694. self->maxs[2] = 0;
  695. self->svflags |= SVF_DEADMONSTER;
  696. gi.linkentity(self);
  697. }
  698. mframe_t parasite_frames_death[] = {
  699. { ai_move, 0, nullptr, FRAME_stand01 },
  700. { ai_move },
  701. { ai_move },
  702. { ai_move, 0, parasite_shrink },
  703. { ai_move, 0, monster_footstep },
  704. { ai_move },
  705. { ai_move }
  706. };
  707. MMOVE_T(parasite_move_death) = { FRAME_death101, FRAME_death107, parasite_frames_death, parasite_dead };
  708. DIE(parasite_die) (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void
  709. {
  710. if (self->proboscus && self->proboscus->style != 2)
  711. proboscis_reset(self->proboscus);
  712. // check for gib
  713. if (M_CheckGib(self, mod))
  714. {
  715. gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
  716. self->s.skinnum /= 2;
  717. ThrowGibs(self, damage, {
  718. { 1, "models/objects/gibs/bone/tris.md2" },
  719. { 3, "models/objects/gibs/sm_meat/tris.md2" },
  720. { "models/monsters/parasite/gibs/chest.md2", GIB_SKINNED },
  721. { 2, "models/monsters/parasite/gibs/bleg.md2", GIB_SKINNED | GIB_UPRIGHT },
  722. { 2, "models/monsters/parasite/gibs/fleg.md2", GIB_SKINNED | GIB_UPRIGHT },
  723. { "models/monsters/parasite/gibs/head.md2", GIB_SKINNED | GIB_HEAD }
  724. });
  725. self->deadflag = true;
  726. return;
  727. }
  728. if (self->deadflag)
  729. return;
  730. // regular death
  731. gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  732. self->deadflag = true;
  733. self->takedamage = true;
  734. M_SetAnimation(self, &parasite_move_death);
  735. }
  736. /*
  737. ===
  738. End Death Stuff
  739. ===
  740. */
  741. mframe_t parasite_frames_pain1[] = {
  742. { ai_move, 0, nullptr, FRAME_stand01 },
  743. { ai_move },
  744. { ai_move, 0, [](edict_t *self) { self->monsterinfo.nextframe = FRAME_pain105; } },
  745. { ai_move, 0, monster_footstep },
  746. { ai_move },
  747. { ai_move },
  748. { ai_move, 6, monster_footstep },
  749. { ai_move, 16 },
  750. { ai_move, -6, monster_footstep },
  751. { ai_move, -7 },
  752. { ai_move }
  753. };
  754. MMOVE_T(parasite_move_pain1) = { FRAME_pain101, FRAME_pain111, parasite_frames_pain1, parasite_start_run };
  755. PAIN(parasite_pain) (edict_t *self, edict_t *other, float kick, int damage, const mod_t &mod) -> void
  756. {
  757. if (level.time < self->pain_debounce_time)
  758. return;
  759. if (self->proboscus && self->proboscus->style != 2)
  760. proboscis_retract(self->proboscus);
  761. self->pain_debounce_time = level.time + 3_sec;
  762. if (frandom() < 0.5f)
  763. gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  764. else
  765. gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  766. if (!M_ShouldReactToPain(self, mod))
  767. return; // no pain anims in nightmare
  768. M_SetAnimation(self, &parasite_move_pain1);
  769. }
  770. MONSTERINFO_SETSKIN(parasite_setskin) (edict_t *self) -> void
  771. {
  772. if (self->health < (self->max_health / 2))
  773. self->s.skinnum = 1;
  774. else
  775. self->s.skinnum = 0;
  776. }
  777. constexpr spawnflags_t SPAWNFLAG_PARASITE_NOJUMPING = 8_spawnflag;
  778. /*QUAKED monster_parasite (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight NoJumping
  779. */
  780. void SP_monster_parasite(edict_t *self)
  781. {
  782. if ( !M_AllowSpawn( self ) ) {
  783. G_FreeEdict( self );
  784. return;
  785. }
  786. sound_pain1.assign("parasite/parpain1.wav");
  787. sound_pain2.assign("parasite/parpain2.wav");
  788. sound_die.assign("parasite/pardeth1.wav");
  789. sound_launch.assign("parasite/paratck1.wav");
  790. sound_impact.assign("parasite/paratck2.wav");
  791. sound_suck.assign("parasite/paratck3.wav");
  792. sound_reelin.assign("parasite/paratck4.wav");
  793. sound_sight.assign("parasite/parsght1.wav");
  794. sound_tap.assign("parasite/paridle1.wav");
  795. sound_scratch.assign("parasite/paridle2.wav");
  796. sound_search.assign("parasite/parsrch1.wav");
  797. gi.modelindex("models/monsters/parasite/tip/tris.md2");
  798. gi.modelindex("models/monsters/parasite/segment/tris.md2");
  799. self->s.modelindex = gi.modelindex("models/monsters/parasite/tris.md2");
  800. gi.modelindex("models/monsters/parasite/gibs/head.md2");
  801. gi.modelindex("models/monsters/parasite/gibs/chest.md2");
  802. gi.modelindex("models/monsters/parasite/gibs/bleg.md2");
  803. gi.modelindex("models/monsters/parasite/gibs/fleg.md2");
  804. self->mins = { -16, -16, -24 };
  805. self->maxs = { 16, 16, 24 };
  806. self->movetype = MOVETYPE_STEP;
  807. self->solid = SOLID_BBOX;
  808. self->health = 175 * st.health_multiplier;
  809. self->gib_health = -50;
  810. self->mass = 250;
  811. self->pain = parasite_pain;
  812. self->die = parasite_die;
  813. self->monsterinfo.stand = parasite_stand;
  814. self->monsterinfo.walk = parasite_start_walk;
  815. self->monsterinfo.run = parasite_start_run;
  816. self->monsterinfo.attack = parasite_attack;
  817. self->monsterinfo.sight = parasite_sight;
  818. self->monsterinfo.idle = parasite_idle;
  819. self->monsterinfo.blocked = parasite_blocked; // PGM
  820. self->monsterinfo.setskin = parasite_setskin;
  821. gi.linkentity(self);
  822. M_SetAnimation(self, &parasite_move_stand);
  823. self->monsterinfo.scale = MODEL_SCALE;
  824. self->yaw_speed = 30;
  825. self->monsterinfo.can_jump = !self->spawnflags.has(SPAWNFLAG_PARASITE_NOJUMPING);
  826. self->monsterinfo.drop_height = 256;
  827. self->monsterinfo.jump_height = 68;
  828. walkmonster_start(self);
  829. }