m_guncmdr.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. /*
  4. ==============================================================================
  5. GUNNER
  6. ==============================================================================
  7. */
  8. #include "g_local.h"
  9. #include "m_gunner.h"
  10. #include "m_flash.h"
  11. constexpr spawnflags_t SPAWNFLAG_GUNCMDR_NOJUMPING = 8_spawnflag;
  12. static cached_soundindex sound_pain;
  13. static cached_soundindex sound_pain2;
  14. static cached_soundindex sound_death;
  15. static cached_soundindex sound_idle;
  16. static cached_soundindex sound_open;
  17. static cached_soundindex sound_search;
  18. static cached_soundindex sound_sight;
  19. void guncmdr_idlesound(edict_t *self)
  20. {
  21. gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  22. }
  23. MONSTERINFO_SIGHT(guncmdr_sight) (edict_t *self, edict_t *other) -> void
  24. {
  25. gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  26. }
  27. MONSTERINFO_SEARCH(guncmdr_search) (edict_t *self) -> void
  28. {
  29. gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  30. }
  31. void GunnerGrenade(edict_t *self);
  32. void GunnerFire(edict_t *self);
  33. void guncmdr_fire_chain(edict_t *self);
  34. void guncmdr_refire_chain(edict_t *self);
  35. void guncmdr_stand(edict_t *self);
  36. mframe_t guncmdr_frames_fidget[] = {
  37. { ai_stand },
  38. { ai_stand },
  39. { ai_stand },
  40. { ai_stand },
  41. { ai_stand },
  42. { ai_stand },
  43. { ai_stand, 0, guncmdr_idlesound },
  44. { ai_stand },
  45. { ai_stand },
  46. { ai_stand },
  47. { ai_stand, 0, guncmdr_idlesound },
  48. { ai_stand },
  49. { ai_stand },
  50. { ai_stand },
  51. { ai_stand },
  52. { ai_stand },
  53. { ai_stand },
  54. { ai_stand },
  55. { ai_stand },
  56. { ai_stand },
  57. { ai_stand },
  58. { ai_stand },
  59. { ai_stand },
  60. { ai_stand },
  61. { ai_stand },
  62. { ai_stand },
  63. { ai_stand },
  64. { ai_stand },
  65. { ai_stand },
  66. { ai_stand },
  67. { ai_stand },
  68. { ai_stand },
  69. { ai_stand },
  70. { ai_stand },
  71. { ai_stand },
  72. { ai_stand },
  73. { ai_stand },
  74. { ai_stand },
  75. { ai_stand },
  76. { ai_stand },
  77. { ai_stand },
  78. { ai_stand },
  79. { ai_stand },
  80. { ai_stand },
  81. { ai_stand },
  82. { ai_stand },
  83. { ai_stand },
  84. { ai_stand },
  85. { ai_stand },
  86. { ai_stand },
  87. { ai_stand },
  88. { ai_stand },
  89. { ai_stand },
  90. { ai_stand }
  91. };
  92. MMOVE_T(guncmdr_move_fidget) = { FRAME_c_stand201, FRAME_c_stand254, guncmdr_frames_fidget, guncmdr_stand };
  93. void guncmdr_fidget(edict_t *self)
  94. {
  95. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  96. return;
  97. else if (self->enemy)
  98. return;
  99. if (frandom() <= 0.05f)
  100. M_SetAnimation(self, &guncmdr_move_fidget);
  101. }
  102. mframe_t guncmdr_frames_stand[] = {
  103. { ai_stand },
  104. { ai_stand },
  105. { ai_stand },
  106. { ai_stand },
  107. { ai_stand },
  108. { ai_stand },
  109. { ai_stand },
  110. { ai_stand },
  111. { ai_stand },
  112. { ai_stand, 0, guncmdr_fidget },
  113. { ai_stand },
  114. { ai_stand },
  115. { ai_stand },
  116. { ai_stand },
  117. { ai_stand },
  118. { ai_stand },
  119. { ai_stand },
  120. { ai_stand },
  121. { ai_stand },
  122. { ai_stand, 0, guncmdr_fidget },
  123. { ai_stand },
  124. { ai_stand },
  125. { ai_stand },
  126. { ai_stand },
  127. { ai_stand },
  128. { ai_stand },
  129. { ai_stand },
  130. { ai_stand },
  131. { ai_stand },
  132. { ai_stand, 0, guncmdr_fidget },
  133. { ai_stand },
  134. { ai_stand },
  135. { ai_stand },
  136. { ai_stand },
  137. { ai_stand },
  138. { ai_stand },
  139. { ai_stand },
  140. { ai_stand },
  141. { ai_stand },
  142. { ai_stand, 0, guncmdr_fidget }
  143. };
  144. MMOVE_T(guncmdr_move_stand) = { FRAME_c_stand101, FRAME_c_stand140, guncmdr_frames_stand, nullptr };
  145. MONSTERINFO_STAND(guncmdr_stand) (edict_t *self) -> void
  146. {
  147. M_SetAnimation(self, &guncmdr_move_stand);
  148. }
  149. mframe_t guncmdr_frames_walk[] = {
  150. { ai_walk, 1.5f, monster_footstep },
  151. { ai_walk, 2.5f },
  152. { ai_walk, 3.0f },
  153. { ai_walk, 2.5f },
  154. { ai_walk, 2.3f },
  155. { ai_walk, 3.0f },
  156. { ai_walk, 2.8f, monster_footstep },
  157. { ai_walk, 3.6f },
  158. { ai_walk, 2.8f },
  159. { ai_walk, 2.5f },
  160. { ai_walk, 2.3f },
  161. { ai_walk, 4.3f },
  162. { ai_walk, 3.0f, monster_footstep },
  163. { ai_walk, 1.5f },
  164. { ai_walk, 2.5f },
  165. { ai_walk, 3.3f },
  166. { ai_walk, 2.8f },
  167. { ai_walk, 3.0f },
  168. { ai_walk, 2.0f, monster_footstep },
  169. { ai_walk, 2.0f },
  170. { ai_walk, 3.3f },
  171. { ai_walk, 3.6f },
  172. { ai_walk, 3.4f },
  173. { ai_walk, 2.8f },
  174. };
  175. MMOVE_T(guncmdr_move_walk) = { FRAME_c_walk101, FRAME_c_walk124, guncmdr_frames_walk, nullptr };
  176. MONSTERINFO_WALK(guncmdr_walk) (edict_t *self) -> void
  177. {
  178. M_SetAnimation(self, &guncmdr_move_walk);
  179. }
  180. mframe_t guncmdr_frames_run[] = {
  181. { ai_run, 15.f, monster_done_dodge },
  182. { ai_run, 16.f, monster_footstep },
  183. { ai_run, 20.f },
  184. { ai_run, 18.f },
  185. { ai_run, 24.f, monster_footstep },
  186. { ai_run, 13.5f }
  187. };
  188. MMOVE_T(guncmdr_move_run) = { FRAME_c_run101, FRAME_c_run106, guncmdr_frames_run, nullptr };
  189. MONSTERINFO_RUN(guncmdr_run) (edict_t *self) -> void
  190. {
  191. monster_done_dodge(self);
  192. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  193. M_SetAnimation(self, &guncmdr_move_stand);
  194. else
  195. M_SetAnimation(self, &guncmdr_move_run);
  196. }
  197. // standing pains
  198. mframe_t guncmdr_frames_pain1[] = {
  199. { ai_move },
  200. { ai_move },
  201. { ai_move },
  202. { ai_move },
  203. };
  204. MMOVE_T(guncmdr_move_pain1) = { FRAME_c_pain101, FRAME_c_pain104, guncmdr_frames_pain1, guncmdr_run };
  205. mframe_t guncmdr_frames_pain2[] = {
  206. { ai_move },
  207. { ai_move },
  208. { ai_move },
  209. { ai_move }
  210. };
  211. MMOVE_T(guncmdr_move_pain2) = { FRAME_c_pain201, FRAME_c_pain204, guncmdr_frames_pain2, guncmdr_run };
  212. mframe_t guncmdr_frames_pain3[] = {
  213. { ai_move, -3.0f },
  214. { ai_move },
  215. { ai_move },
  216. { ai_move },
  217. };
  218. MMOVE_T(guncmdr_move_pain3) = { FRAME_c_pain301, FRAME_c_pain304, guncmdr_frames_pain3, guncmdr_run };
  219. mframe_t guncmdr_frames_pain4[] = {
  220. { ai_move, -17.1f },
  221. { ai_move, -3.2f },
  222. { ai_move, 0.9f },
  223. { ai_move, 3.6f },
  224. { ai_move, -2.6f },
  225. { ai_move, 1.0f },
  226. { ai_move, -5.1f },
  227. { ai_move, -6.7f },
  228. { ai_move, -8.8f },
  229. { ai_move },
  230. { ai_move },
  231. { ai_move, -2.1f },
  232. { ai_move, -2.3f },
  233. { ai_move, -2.5f },
  234. { ai_move }
  235. };
  236. MMOVE_T(guncmdr_move_pain4) = { FRAME_c_pain401, FRAME_c_pain415, guncmdr_frames_pain4, guncmdr_run };
  237. void guncmdr_dead(edict_t *);
  238. mframe_t guncmdr_frames_death1[] = {
  239. { ai_move },
  240. { ai_move },
  241. { ai_move, 4.0f }, // scoot
  242. { ai_move },
  243. { ai_move },
  244. { ai_move },
  245. { ai_move },
  246. { ai_move },
  247. { ai_move },
  248. { ai_move },
  249. { ai_move },
  250. { ai_move },
  251. { ai_move },
  252. { ai_move },
  253. { ai_move },
  254. { ai_move },
  255. { ai_move },
  256. { ai_move }
  257. };
  258. MMOVE_T(guncmdr_move_death1) = { FRAME_c_death101, FRAME_c_death118, guncmdr_frames_death1, guncmdr_dead };
  259. void guncmdr_pain5_to_death1(edict_t *self)
  260. {
  261. if (self->health < 0)
  262. M_SetAnimation(self, &guncmdr_move_death1, false);
  263. }
  264. mframe_t guncmdr_frames_death2[] = {
  265. { ai_move },
  266. { ai_move },
  267. { ai_move },
  268. { ai_move }
  269. };
  270. MMOVE_T(guncmdr_move_death2) = { FRAME_c_death201, FRAME_c_death204, guncmdr_frames_death2, guncmdr_dead };
  271. void guncmdr_pain5_to_death2(edict_t *self)
  272. {
  273. if (self->health < 0 && brandom())
  274. M_SetAnimation(self, &guncmdr_move_death2, false);
  275. }
  276. mframe_t guncmdr_frames_pain5[] = {
  277. { ai_move, -29.f },
  278. { ai_move, -5.f },
  279. { ai_move, -5.f },
  280. { ai_move, -3.f },
  281. { ai_move },
  282. { ai_move, 0, guncmdr_pain5_to_death2 },
  283. { ai_move, 9.f },
  284. { ai_move, 3.f },
  285. { ai_move, 0, guncmdr_pain5_to_death1 },
  286. { ai_move },
  287. { ai_move },
  288. { ai_move, -4.6f },
  289. { ai_move, -4.8f },
  290. { ai_move },
  291. { ai_move },
  292. { ai_move },
  293. { ai_move, 9.5f },
  294. { ai_move, 3.4f },
  295. { ai_move },
  296. { ai_move },
  297. { ai_move, -2.4f },
  298. { ai_move, -9.0f },
  299. { ai_move, -5.0f },
  300. { ai_move, -3.6f },
  301. };
  302. MMOVE_T(guncmdr_move_pain5) = { FRAME_c_pain501, FRAME_c_pain524, guncmdr_frames_pain5, guncmdr_run };
  303. void guncmdr_dead(edict_t *self)
  304. {
  305. self->mins = vec3_t { -16, -16, -24 } * self->s.scale;
  306. self->maxs = vec3_t { 16, 16, -8 } * self->s.scale;
  307. monster_dead(self);
  308. }
  309. static void guncmdr_shrink(edict_t *self)
  310. {
  311. self->maxs[2] = -4 * self->s.scale;
  312. self->svflags |= SVF_DEADMONSTER;
  313. gi.linkentity(self);
  314. }
  315. mframe_t guncmdr_frames_death6[] = {
  316. { ai_move, 0, guncmdr_shrink },
  317. { ai_move },
  318. { ai_move },
  319. { ai_move },
  320. { ai_move },
  321. { ai_move },
  322. { ai_move },
  323. { ai_move },
  324. { ai_move },
  325. { ai_move },
  326. { ai_move },
  327. { ai_move },
  328. { ai_move },
  329. { ai_move }
  330. };
  331. MMOVE_T(guncmdr_move_death6) = { FRAME_c_death601, FRAME_c_death614, guncmdr_frames_death6, guncmdr_dead };
  332. static void guncmdr_pain6_to_death6(edict_t *self)
  333. {
  334. if (self->health < 0)
  335. M_SetAnimation(self, &guncmdr_move_death6, false);
  336. }
  337. mframe_t guncmdr_frames_pain6[] = {
  338. { ai_move, 16.f },
  339. { ai_move, 16.f },
  340. { ai_move, 12.f },
  341. { ai_move, 5.5f, monster_duck_down },
  342. { ai_move, 3.0f },
  343. { ai_move, -4.7f },
  344. { ai_move, -6.0f, guncmdr_pain6_to_death6 },
  345. { ai_move },
  346. { ai_move, 1.8f },
  347. { ai_move, 0.7f },
  348. { ai_move },
  349. { ai_move, -2.1f },
  350. { ai_move },
  351. { ai_move },
  352. { ai_move },
  353. { ai_move },
  354. { ai_move },
  355. { ai_move },
  356. { ai_move },
  357. { ai_move },
  358. { ai_move },
  359. { ai_move, -6.1f },
  360. { ai_move, 10.5f },
  361. { ai_move, 4.3f },
  362. { ai_move, 4.7f, monster_duck_up },
  363. { ai_move, 1.4f },
  364. { ai_move },
  365. { ai_move, -3.2f },
  366. { ai_move, 2.3f },
  367. { ai_move, -4.4f },
  368. { ai_move, -4.4f },
  369. { ai_move, -2.4f }
  370. };
  371. MMOVE_T(guncmdr_move_pain6) = { FRAME_c_pain601, FRAME_c_pain632, guncmdr_frames_pain6, guncmdr_run };
  372. mframe_t guncmdr_frames_pain7[] = {
  373. { ai_move },
  374. { ai_move },
  375. { ai_move },
  376. { ai_move },
  377. { ai_move },
  378. { ai_move },
  379. { ai_move },
  380. { ai_move },
  381. { ai_move },
  382. { ai_move },
  383. { ai_move },
  384. { ai_move },
  385. { ai_move },
  386. { ai_move }
  387. };
  388. MMOVE_T(guncmdr_move_pain7) = { FRAME_c_pain701, FRAME_c_pain714, guncmdr_frames_pain7, guncmdr_run };
  389. extern const mmove_t guncmdr_move_jump;
  390. extern const mmove_t guncmdr_move_jump2;
  391. extern const mmove_t guncmdr_move_duck_attack;
  392. bool guncmdr_sidestep(edict_t *self);
  393. PAIN(guncmdr_pain) (edict_t *self, edict_t *other, float kick, int damage, const mod_t &mod) -> void
  394. {
  395. monster_done_dodge(self);
  396. if (self->monsterinfo.active_move == &guncmdr_move_jump ||
  397. self->monsterinfo.active_move == &guncmdr_move_jump2 ||
  398. self->monsterinfo.active_move == &guncmdr_move_duck_attack)
  399. return;
  400. if (level.time < self->pain_debounce_time)
  401. {
  402. if (frandom() < 0.3)
  403. self->monsterinfo.dodge(self, other, FRAME_TIME_S, nullptr, false);
  404. return;
  405. }
  406. self->pain_debounce_time = level.time + 3_sec;
  407. if (brandom())
  408. gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  409. else
  410. gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  411. if (!M_ShouldReactToPain(self, mod))
  412. {
  413. if (frandom() < 0.3)
  414. self->monsterinfo.dodge(self, other, FRAME_TIME_S, nullptr, false);
  415. return; // no pain anims in nightmare
  416. }
  417. vec3_t forward;
  418. AngleVectors(self->s.angles, forward, nullptr, nullptr);
  419. vec3_t dif = (other->s.origin - self->s.origin);
  420. dif.z = 0;
  421. dif.normalize();
  422. // small pain
  423. if (damage < 35)
  424. {
  425. int r = irandom(0, 4);
  426. if (r == 0)
  427. M_SetAnimation(self, &guncmdr_move_pain3);
  428. else if (r == 1)
  429. M_SetAnimation(self, &guncmdr_move_pain2);
  430. else if (r == 2)
  431. M_SetAnimation(self, &guncmdr_move_pain1);
  432. else
  433. M_SetAnimation(self, &guncmdr_move_pain7);
  434. }
  435. // large pain from behind (aka Paril)
  436. else if (dif.dot(forward) < -0.40f)
  437. {
  438. M_SetAnimation(self, &guncmdr_move_pain6);
  439. self->pain_debounce_time += 1.5_sec;
  440. }
  441. else
  442. {
  443. if (brandom())
  444. M_SetAnimation(self, &guncmdr_move_pain4);
  445. else
  446. M_SetAnimation(self, &guncmdr_move_pain5);
  447. self->pain_debounce_time += 1.5_sec;
  448. }
  449. self->monsterinfo.aiflags &= ~AI_MANUAL_STEERING;
  450. // PMM - clear duck flag
  451. if (self->monsterinfo.aiflags & AI_DUCKED)
  452. monster_duck_up(self);
  453. }
  454. MONSTERINFO_SETSKIN(guncmdr_setskin) (edict_t *self) -> void
  455. {
  456. if (self->health < (self->max_health / 2))
  457. self->s.skinnum |= 1;
  458. else
  459. self->s.skinnum &= ~1;
  460. }
  461. mframe_t guncmdr_frames_death3[] = {
  462. { ai_move, 20.f },
  463. { ai_move, 10.f },
  464. { ai_move, 10.f, [](edict_t *self) { monster_footstep(self); guncmdr_shrink(self); } },
  465. { ai_move, 0.f, monster_footstep },
  466. { ai_move },
  467. { ai_move },
  468. { ai_move },
  469. { ai_move },
  470. { ai_move },
  471. { ai_move },
  472. { ai_move },
  473. { ai_move },
  474. { ai_move },
  475. { ai_move },
  476. { ai_move },
  477. { ai_move },
  478. { ai_move },
  479. { ai_move },
  480. { ai_move },
  481. { ai_move },
  482. { ai_move }
  483. };
  484. MMOVE_T(guncmdr_move_death3) = { FRAME_c_death301, FRAME_c_death321, guncmdr_frames_death3, guncmdr_dead };
  485. mframe_t guncmdr_frames_death7[] = {
  486. { ai_move, 30.f },
  487. { ai_move, 20.f },
  488. { ai_move, 16.f, [](edict_t *self) { monster_footstep(self); guncmdr_shrink(self); } },
  489. { ai_move, 5.f, monster_footstep },
  490. { ai_move, -6.f },
  491. { ai_move, -7.f, monster_footstep },
  492. { ai_move },
  493. { ai_move },
  494. { ai_move },
  495. { ai_move },
  496. { ai_move },
  497. { ai_move },
  498. { ai_move },
  499. { ai_move },
  500. { ai_move },
  501. { ai_move },
  502. { ai_move },
  503. { ai_move },
  504. { ai_move },
  505. { ai_move },
  506. { ai_move },
  507. { ai_move },
  508. { ai_move },
  509. { ai_move },
  510. { ai_move, 0.f, monster_footstep },
  511. { ai_move },
  512. { ai_move },
  513. { ai_move, 0.f, monster_footstep },
  514. { ai_move },
  515. { ai_move },
  516. };
  517. MMOVE_T(guncmdr_move_death7) = { FRAME_c_death701, FRAME_c_death730, guncmdr_frames_death7, guncmdr_dead };
  518. mframe_t guncmdr_frames_death4[] = {
  519. { ai_move, -20.f },
  520. { ai_move, -16.f },
  521. { ai_move, -26.f, [](edict_t *self) { monster_footstep(self); guncmdr_shrink(self); } },
  522. { ai_move, 0.f, monster_footstep },
  523. { ai_move, -12.f },
  524. { ai_move, 16.f },
  525. { ai_move, 9.2f },
  526. { ai_move },
  527. { ai_move },
  528. { ai_move },
  529. { ai_move },
  530. { ai_move },
  531. { ai_move },
  532. { ai_move },
  533. { ai_move },
  534. { ai_move },
  535. { ai_move },
  536. { ai_move },
  537. { ai_move },
  538. { ai_move },
  539. { ai_move },
  540. { ai_move },
  541. { ai_move },
  542. { ai_move },
  543. { ai_move },
  544. { ai_move },
  545. { ai_move },
  546. { ai_move },
  547. { ai_move },
  548. { ai_move },
  549. { ai_move },
  550. { ai_move },
  551. { ai_move },
  552. { ai_move },
  553. { ai_move },
  554. { ai_move }
  555. };
  556. MMOVE_T(guncmdr_move_death4) = { FRAME_c_death401, FRAME_c_death436, guncmdr_frames_death4, guncmdr_dead };
  557. mframe_t guncmdr_frames_death5[] = {
  558. { ai_move, -14.f },
  559. { ai_move, -2.7f },
  560. { ai_move, -2.5f },
  561. { ai_move, -4.6f, monster_footstep },
  562. { ai_move, -4.0f, monster_footstep },
  563. { ai_move, -1.5f },
  564. { ai_move, 2.3f },
  565. { ai_move, 2.5f },
  566. { ai_move },
  567. { ai_move },
  568. { ai_move },
  569. { ai_move },
  570. { ai_move },
  571. { ai_move },
  572. { ai_move, 3.5f },
  573. { ai_move, 12.9f, monster_footstep },
  574. { ai_move, 3.8f },
  575. { ai_move },
  576. { ai_move },
  577. { ai_move },
  578. { ai_move, -2.1f },
  579. { ai_move, -1.3f },
  580. { ai_move },
  581. { ai_move },
  582. { ai_move, 3.4f },
  583. { ai_move, 5.7f },
  584. { ai_move, 11.2f },
  585. { ai_move, 0, monster_footstep }
  586. };
  587. MMOVE_T(guncmdr_move_death5) = { FRAME_c_death501, FRAME_c_death528, guncmdr_frames_death5, guncmdr_dead };
  588. DIE(guncmdr_die) (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void
  589. {
  590. // check for gib
  591. if (M_CheckGib(self, mod))
  592. {
  593. gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
  594. const char *head_gib = (self->monsterinfo.active_move != &guncmdr_move_death5) ? "models/objects/gibs/sm_meat/tris.md2" : "models/monsters/gunner/gibs/head.md2";
  595. self->s.skinnum /= 2;
  596. ThrowGibs(self, damage, {
  597. { 2, "models/objects/gibs/bone/tris.md2" },
  598. { 2, "models/objects/gibs/sm_meat/tris.md2" },
  599. { 1, "models/objects/gibs/gear/tris.md2" },
  600. { "models/monsters/gunner/gibs/chest.md2", GIB_SKINNED },
  601. { "models/monsters/gunner/gibs/garm.md2", GIB_SKINNED | GIB_UPRIGHT },
  602. { "models/monsters/gunner/gibs/gun.md2", GIB_SKINNED | GIB_UPRIGHT },
  603. { "models/monsters/gunner/gibs/foot.md2", GIB_SKINNED },
  604. { head_gib, GIB_SKINNED | GIB_HEAD }
  605. });
  606. self->deadflag = true;
  607. return;
  608. }
  609. if (self->deadflag)
  610. return;
  611. // regular death
  612. gi.sound(self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
  613. self->deadflag = true;
  614. self->takedamage = true;
  615. // these animations cleanly transitions to death, so just keep going
  616. if (self->monsterinfo.active_move == &guncmdr_move_pain5 &&
  617. self->s.frame < FRAME_c_pain508)
  618. return;
  619. else if (self->monsterinfo.active_move == &guncmdr_move_pain6 &&
  620. self->s.frame < FRAME_c_pain607)
  621. return;
  622. vec3_t forward;
  623. AngleVectors(self->s.angles, forward, nullptr, nullptr);
  624. vec3_t dif = (inflictor->s.origin - self->s.origin);
  625. dif.z = 0;
  626. dif.normalize();
  627. // off with da head
  628. if (fabsf((self->s.origin[2] + self->viewheight) - point[2]) <= 4 &&
  629. self->velocity.z < 65.f)
  630. {
  631. M_SetAnimation(self, &guncmdr_move_death5);
  632. edict_t *head = ThrowGib(self, "models/monsters/gunner/gibs/head.md2", damage, GIB_NONE, self->s.scale);
  633. if (head)
  634. {
  635. head->s.angles = self->s.angles;
  636. head->s.origin = self->s.origin + vec3_t{0, 0, 24.f};
  637. vec3_t headDir = (self->s.origin - inflictor->s.origin);
  638. head->velocity = headDir / headDir.length() * 100.0f;
  639. head->velocity[2] = 200.0f;
  640. head->avelocity *= 0.15f;
  641. gi.linkentity(head);
  642. }
  643. }
  644. // damage came from behind; use backwards death
  645. else if (dif.dot(forward) < -0.40f)
  646. {
  647. int r = irandom(0, self->monsterinfo.active_move == &guncmdr_move_pain6 ? 2 : 3);
  648. if (r == 0)
  649. M_SetAnimation(self, &guncmdr_move_death3);
  650. else if (r == 1)
  651. M_SetAnimation(self, &guncmdr_move_death7);
  652. else if (r == 2)
  653. M_SetAnimation(self, &guncmdr_move_pain6);
  654. }
  655. else
  656. {
  657. int r = irandom(0, self->monsterinfo.active_move == &guncmdr_move_pain5 ? 1 : 2);
  658. if (r == 0)
  659. M_SetAnimation(self, &guncmdr_move_death4);
  660. else
  661. M_SetAnimation(self, &guncmdr_move_pain5);
  662. }
  663. }
  664. void guncmdr_opengun(edict_t *self)
  665. {
  666. gi.sound(self, CHAN_VOICE, sound_open, 1, ATTN_IDLE, 0);
  667. }
  668. void GunnerCmdrFire(edict_t *self)
  669. {
  670. vec3_t start;
  671. vec3_t forward, right;
  672. vec3_t aim;
  673. monster_muzzleflash_id_t flash_number;
  674. if (!self->enemy || !self->enemy->inuse) // PGM
  675. return; // PGM
  676. if (self->s.frame >= FRAME_c_attack401 && self->s.frame <= FRAME_c_attack505)
  677. flash_number = MZ2_GUNCMDR_CHAINGUN_2;
  678. else
  679. flash_number = MZ2_GUNCMDR_CHAINGUN_1;
  680. AngleVectors(self->s.angles, forward, right, nullptr);
  681. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  682. PredictAim(self, self->enemy, start, 800, false, frandom() * 0.3f, &aim, nullptr);
  683. for (int i = 0; i < 3; i++)
  684. aim[i] += crandom_open() * 0.025f;
  685. monster_fire_flechette(self, start, aim, 4, 800, flash_number);
  686. }
  687. mframe_t guncmdr_frames_attack_chain[] = {
  688. { ai_charge },
  689. { ai_charge },
  690. { ai_charge },
  691. { ai_charge },
  692. { ai_charge, 0, guncmdr_opengun },
  693. { ai_charge }
  694. };
  695. MMOVE_T(guncmdr_move_attack_chain) = { FRAME_c_attack101, FRAME_c_attack106, guncmdr_frames_attack_chain, guncmdr_fire_chain };
  696. mframe_t guncmdr_frames_fire_chain[] = {
  697. { ai_charge, 0, GunnerCmdrFire },
  698. { ai_charge, 0, GunnerCmdrFire },
  699. { ai_charge, 0, GunnerCmdrFire },
  700. { ai_charge, 0, GunnerCmdrFire },
  701. { ai_charge, 0, GunnerCmdrFire },
  702. { ai_charge, 0, GunnerCmdrFire }
  703. };
  704. MMOVE_T(guncmdr_move_fire_chain) = { FRAME_c_attack107, FRAME_c_attack112, guncmdr_frames_fire_chain, guncmdr_refire_chain };
  705. mframe_t guncmdr_frames_fire_chain_run[] = {
  706. { ai_charge, 15.f, GunnerCmdrFire },
  707. { ai_charge, 16.f, GunnerCmdrFire },
  708. { ai_charge, 20.f, GunnerCmdrFire },
  709. { ai_charge, 18.f, GunnerCmdrFire },
  710. { ai_charge, 24.f, GunnerCmdrFire },
  711. { ai_charge, 13.5f, GunnerCmdrFire }
  712. };
  713. MMOVE_T(guncmdr_move_fire_chain_run) = { FRAME_c_run201, FRAME_c_run206, guncmdr_frames_fire_chain_run, guncmdr_refire_chain };
  714. mframe_t guncmdr_frames_fire_chain_dodge_right[] = {
  715. { ai_charge, 5.1f * 2.0f, GunnerCmdrFire },
  716. { ai_charge, 9.0f * 2.0f, GunnerCmdrFire },
  717. { ai_charge, 3.5f * 2.0f, GunnerCmdrFire },
  718. { ai_charge, 3.6f * 2.0f, GunnerCmdrFire },
  719. { ai_charge, -1.0f * 2.0f, GunnerCmdrFire }
  720. };
  721. MMOVE_T(guncmdr_move_fire_chain_dodge_right) = { FRAME_c_attack401, FRAME_c_attack405, guncmdr_frames_fire_chain_dodge_right, guncmdr_refire_chain };
  722. mframe_t guncmdr_frames_fire_chain_dodge_left[] = {
  723. { ai_charge, 5.1f * 2.0f, GunnerCmdrFire },
  724. { ai_charge, 9.0f * 2.0f, GunnerCmdrFire },
  725. { ai_charge, 3.5f * 2.0f, GunnerCmdrFire },
  726. { ai_charge, 3.6f * 2.0f, GunnerCmdrFire },
  727. { ai_charge, -1.0f * 2.0f, GunnerCmdrFire }
  728. };
  729. MMOVE_T(guncmdr_move_fire_chain_dodge_left) = { FRAME_c_attack501, FRAME_c_attack505, guncmdr_frames_fire_chain_dodge_left, guncmdr_refire_chain };
  730. mframe_t guncmdr_frames_endfire_chain[] = {
  731. { ai_charge },
  732. { ai_charge },
  733. { ai_charge, 0, guncmdr_opengun },
  734. { ai_charge },
  735. { ai_charge },
  736. { ai_charge },
  737. { ai_charge }
  738. };
  739. MMOVE_T(guncmdr_move_endfire_chain) = { FRAME_c_attack118, FRAME_c_attack124, guncmdr_frames_endfire_chain, guncmdr_run };
  740. constexpr float MORTAR_SPEED = 850.f;
  741. constexpr float GRENADE_SPEED = 600.f;
  742. void GunnerCmdrGrenade(edict_t *self)
  743. {
  744. vec3_t start;
  745. vec3_t forward, right, up;
  746. vec3_t aim;
  747. monster_muzzleflash_id_t flash_number;
  748. float spread;
  749. float pitch = 0;
  750. // PMM
  751. vec3_t target;
  752. bool blindfire = false;
  753. if (!self->enemy || !self->enemy->inuse) // PGM
  754. return; // PGM
  755. // pmm
  756. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  757. blindfire = true;
  758. if (self->s.frame == FRAME_c_attack205)
  759. {
  760. spread = -0.1f;
  761. flash_number = MZ2_GUNCMDR_GRENADE_MORTAR_1;
  762. }
  763. else if (self->s.frame == FRAME_c_attack208)
  764. {
  765. spread = 0.f;
  766. flash_number = MZ2_GUNCMDR_GRENADE_MORTAR_2;
  767. }
  768. else if (self->s.frame == FRAME_c_attack211)
  769. {
  770. spread = 0.1f;
  771. flash_number = MZ2_GUNCMDR_GRENADE_MORTAR_3;
  772. }
  773. else if (self->s.frame == FRAME_c_attack304)
  774. {
  775. spread = -0.1f;
  776. flash_number = MZ2_GUNCMDR_GRENADE_FRONT_1;
  777. }
  778. else if (self->s.frame == FRAME_c_attack307)
  779. {
  780. spread = 0.f;
  781. flash_number = MZ2_GUNCMDR_GRENADE_FRONT_2;
  782. }
  783. else if (self->s.frame == FRAME_c_attack310)
  784. {
  785. spread = 0.1f;
  786. flash_number = MZ2_GUNCMDR_GRENADE_FRONT_3;
  787. }
  788. else if (self->s.frame == FRAME_c_attack911)
  789. {
  790. spread = 0.25f;
  791. flash_number = MZ2_GUNCMDR_GRENADE_CROUCH_1;
  792. }
  793. else if (self->s.frame == FRAME_c_attack912)
  794. {
  795. spread = 0.f;
  796. flash_number = MZ2_GUNCMDR_GRENADE_CROUCH_2;
  797. }
  798. else if (self->s.frame == FRAME_c_attack913)
  799. {
  800. spread = -0.25f;
  801. flash_number = MZ2_GUNCMDR_GRENADE_CROUCH_3;
  802. }
  803. // pmm
  804. // if we're shooting blind and we still can't see our enemy
  805. if ((blindfire) && (!visible(self, self->enemy)))
  806. {
  807. // and we have a valid blind_fire_target
  808. if (!self->monsterinfo.blind_fire_target)
  809. return;
  810. target = self->monsterinfo.blind_fire_target;
  811. }
  812. else
  813. target = self->enemy->s.origin;
  814. // pmm
  815. AngleVectors(self->s.angles, forward, right, up); // PGM
  816. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  817. // PGM
  818. if (self->enemy && !(flash_number >= MZ2_GUNCMDR_GRENADE_CROUCH_1 && flash_number <= MZ2_GUNCMDR_GRENADE_CROUCH_3))
  819. {
  820. float dist;
  821. aim = target - self->s.origin;
  822. dist = aim.length();
  823. // aim up if they're on the same level as me and far away.
  824. if ((dist > 512) && (aim[2] < 64) && (aim[2] > -64))
  825. {
  826. aim[2] += (dist - 512);
  827. }
  828. aim.normalize();
  829. pitch = aim[2];
  830. if (pitch > 0.4f)
  831. pitch = 0.4f;
  832. else if (pitch < -0.5f)
  833. pitch = -0.5f;
  834. if ((self->enemy->absmin.z - self->absmax.z) > 16.f && flash_number >= MZ2_GUNCMDR_GRENADE_MORTAR_1 && flash_number <= MZ2_GUNCMDR_GRENADE_MORTAR_3)
  835. pitch += 0.5f;
  836. }
  837. // PGM
  838. if (flash_number >= MZ2_GUNCMDR_GRENADE_FRONT_1 && flash_number <= MZ2_GUNCMDR_GRENADE_FRONT_3)
  839. pitch -= 0.05f;
  840. if (!(flash_number >= MZ2_GUNCMDR_GRENADE_CROUCH_1 && flash_number <= MZ2_GUNCMDR_GRENADE_CROUCH_3))
  841. {
  842. aim = forward + (right * spread);
  843. aim += (up * pitch);
  844. aim.normalize();
  845. }
  846. else
  847. {
  848. PredictAim(self, self->enemy, start, 800, false, 0.f, &aim, nullptr);
  849. aim += right * spread;
  850. aim.normalize();
  851. }
  852. if (flash_number >= MZ2_GUNCMDR_GRENADE_CROUCH_1 && flash_number <= MZ2_GUNCMDR_GRENADE_CROUCH_3)
  853. {
  854. constexpr float inner_spread = 0.125f;
  855. for (int32_t i = 0; i < 3; i++)
  856. fire_ionripper(self, start, aim + (right * (-(inner_spread * 2) + (inner_spread * (i + 1)))), 15, 800, EF_IONRIPPER);
  857. monster_muzzleflash(self, start, flash_number);
  858. }
  859. else
  860. {
  861. // mortar fires farther
  862. float speed;
  863. if (flash_number >= MZ2_GUNCMDR_GRENADE_MORTAR_1 && flash_number <= MZ2_GUNCMDR_GRENADE_MORTAR_3)
  864. speed = MORTAR_SPEED;
  865. else
  866. speed = GRENADE_SPEED;
  867. // try search for best pitch
  868. if (M_CalculatePitchToFire(self, target, start, aim, speed, 2.5f, (flash_number >= MZ2_GUNCMDR_GRENADE_MORTAR_1 && flash_number <= MZ2_GUNCMDR_GRENADE_MORTAR_3)))
  869. monster_fire_grenade(self, start, aim, 50, speed, flash_number, (crandom_open() * 10.0f), frandom() * 10.f);
  870. else
  871. // normal shot
  872. monster_fire_grenade(self, start, aim, 50, speed, flash_number, (crandom_open() * 10.0f), 200.f + (crandom_open() * 10.0f));
  873. }
  874. }
  875. mframe_t guncmdr_frames_attack_mortar[] = {
  876. { ai_charge },
  877. { ai_charge },
  878. { ai_charge },
  879. { ai_charge },
  880. { ai_charge, 0, GunnerCmdrGrenade },
  881. { ai_charge },
  882. { ai_charge },
  883. { ai_charge, 0, GunnerCmdrGrenade },
  884. { ai_charge },
  885. { ai_charge },
  886. { ai_charge, 0, GunnerCmdrGrenade },
  887. { ai_charge },
  888. { ai_charge },
  889. { ai_charge, 0, monster_duck_up },
  890. { ai_charge },
  891. { ai_charge },
  892. { ai_charge },
  893. { ai_charge },
  894. { ai_charge },
  895. { ai_charge },
  896. { ai_charge }
  897. };
  898. MMOVE_T(guncmdr_move_attack_mortar) = { FRAME_c_attack201, FRAME_c_attack221, guncmdr_frames_attack_mortar, guncmdr_run };
  899. void guncmdr_grenade_mortar_resume(edict_t *self)
  900. {
  901. M_SetAnimation(self, &guncmdr_move_attack_mortar);
  902. self->monsterinfo.attack_state = AS_STRAIGHT;
  903. self->s.frame = self->count;
  904. }
  905. mframe_t guncmdr_frames_attack_mortar_dodge[] = {
  906. { ai_charge, 11.f },
  907. { ai_charge, 12.f },
  908. { ai_charge, 16.f },
  909. { ai_charge, 16.f },
  910. { ai_charge, 12.f },
  911. { ai_charge, 11.f }
  912. };
  913. MMOVE_T(guncmdr_move_attack_mortar_dodge) = { FRAME_c_duckstep01, FRAME_c_duckstep06, guncmdr_frames_attack_mortar_dodge, guncmdr_grenade_mortar_resume };
  914. mframe_t guncmdr_frames_attack_back[] = {
  915. //{ ai_charge },
  916. { ai_charge, -2.f },
  917. { ai_charge, -1.5f },
  918. { ai_charge, -0.5f, GunnerCmdrGrenade },
  919. { ai_charge, -6.0f },
  920. { ai_charge, -4.f },
  921. { ai_charge, -2.5f, GunnerCmdrGrenade },
  922. { ai_charge, -7.0f },
  923. { ai_charge, -3.5f },
  924. { ai_charge, -1.1f, GunnerCmdrGrenade },
  925. { ai_charge, -4.6f },
  926. { ai_charge, 1.9f },
  927. { ai_charge, 1.0f },
  928. { ai_charge, -4.5f },
  929. { ai_charge, 3.2f },
  930. { ai_charge, 4.4f },
  931. { ai_charge, -6.5f },
  932. { ai_charge, -6.1f },
  933. { ai_charge, 3.0f },
  934. { ai_charge, -0.7f },
  935. { ai_charge, -1.0f }
  936. };
  937. MMOVE_T(guncmdr_move_attack_grenade_back) = { FRAME_c_attack302, FRAME_c_attack321, guncmdr_frames_attack_back, guncmdr_run };
  938. void guncmdr_grenade_back_dodge_resume(edict_t *self)
  939. {
  940. M_SetAnimation(self, &guncmdr_move_attack_grenade_back);
  941. self->monsterinfo.attack_state = AS_STRAIGHT;
  942. self->s.frame = self->count;
  943. }
  944. mframe_t guncmdr_frames_attack_grenade_back_dodge_right[] = {
  945. { ai_charge, 5.1f * 2.0f },
  946. { ai_charge, 9.0f * 2.0f },
  947. { ai_charge, 3.5f * 2.0f },
  948. { ai_charge, 3.6f * 2.0f },
  949. { ai_charge, -1.0f * 2.0f }
  950. };
  951. MMOVE_T(guncmdr_move_attack_grenade_back_dodge_right) = { FRAME_c_attack601, FRAME_c_attack605, guncmdr_frames_attack_grenade_back_dodge_right, guncmdr_grenade_back_dodge_resume };
  952. mframe_t guncmdr_frames_attack_grenade_back_dodge_left[] = {
  953. { ai_charge, 5.1f * 2.0f },
  954. { ai_charge, 9.0f * 2.0f },
  955. { ai_charge, 3.5f * 2.0f },
  956. { ai_charge, 3.6f * 2.0f },
  957. { ai_charge, -1.0f * 2.0f }
  958. };
  959. MMOVE_T(guncmdr_move_attack_grenade_back_dodge_left) = { FRAME_c_attack701, FRAME_c_attack705, guncmdr_frames_attack_grenade_back_dodge_left, guncmdr_grenade_back_dodge_resume };
  960. static void guncmdr_kick_finished(edict_t *self)
  961. {
  962. self->monsterinfo.melee_debounce_time = level.time + 3_sec;
  963. self->monsterinfo.attack(self);
  964. }
  965. static void guncmdr_kick(edict_t *self)
  966. {
  967. if (fire_hit(self, vec3_t { MELEE_DISTANCE, 0.f, -32.f }, 15.f, 400.f))
  968. {
  969. if (self->enemy && self->enemy->client && self->enemy->velocity.z < 270.f)
  970. self->enemy->velocity.z = 270.f;
  971. }
  972. }
  973. mframe_t guncmdr_frames_attack_kick[] = {
  974. { ai_charge, -7.7f },
  975. { ai_charge, -4.9f },
  976. { ai_charge, 12.6f, guncmdr_kick },
  977. { ai_charge },
  978. { ai_charge, -3.0f },
  979. { ai_charge },
  980. { ai_charge, -4.1f },
  981. { ai_charge, 8.6f },
  982. //{ ai_charge, -3.5f }
  983. };
  984. MMOVE_T(guncmdr_move_attack_kick) = { FRAME_c_attack801, FRAME_c_attack808, guncmdr_frames_attack_kick, guncmdr_kick_finished };
  985. // don't ever try grenades if we get this close
  986. constexpr float RANGE_GRENADE = 100.f;
  987. // always use mortar at this range
  988. constexpr float RANGE_GRENADE_MORTAR = 525.f;
  989. // at this range, run towards the enemy
  990. constexpr float RANGE_CHAINGUN_RUN = 400.f;
  991. MONSTERINFO_ATTACK(guncmdr_attack) (edict_t *self) -> void
  992. {
  993. monster_done_dodge(self);
  994. float d = range_to(self, self->enemy);
  995. vec3_t forward, right, aim;
  996. AngleVectors(self->s.angles, forward, right, nullptr); // PGM
  997. // always use chaingun on tesla
  998. // kick close enemies
  999. if (!self->bad_area && d < RANGE_MELEE && self->monsterinfo.melee_debounce_time < level.time)
  1000. M_SetAnimation(self, &guncmdr_move_attack_kick);
  1001. else if (self->bad_area || ((d <= RANGE_GRENADE || brandom()) && M_CheckClearShot(self, monster_flash_offset[MZ2_GUNCMDR_CHAINGUN_1])))
  1002. M_SetAnimation(self, &guncmdr_move_attack_chain);
  1003. else if ((d >= RANGE_GRENADE_MORTAR ||
  1004. fabs(self->absmin.z - self->enemy->absmax.z) > 64.f // enemy is far below or above us, always try mortar
  1005. ) && M_CheckClearShot(self, monster_flash_offset[MZ2_GUNCMDR_GRENADE_MORTAR_1]) &&
  1006. M_CalculatePitchToFire(self, self->enemy->s.origin, M_ProjectFlashSource(self, monster_flash_offset[MZ2_GUNCMDR_GRENADE_MORTAR_1], forward, right),
  1007. aim = (self->enemy->s.origin - self->s.origin).normalized(), MORTAR_SPEED, 2.5f, true)
  1008. )
  1009. {
  1010. M_SetAnimation(self, &guncmdr_move_attack_mortar);
  1011. monster_duck_down(self);
  1012. }
  1013. else if (M_CheckClearShot(self, monster_flash_offset[MZ2_GUNCMDR_GRENADE_FRONT_1]) && !(self->monsterinfo.aiflags & AI_STAND_GROUND) &&
  1014. M_CalculatePitchToFire(self, self->enemy->s.origin, M_ProjectFlashSource(self, monster_flash_offset[MZ2_GUNCMDR_GRENADE_FRONT_1], forward, right),
  1015. aim = (self->enemy->s.origin - self->s.origin).normalized(), GRENADE_SPEED, 2.5f, false))
  1016. M_SetAnimation(self, &guncmdr_move_attack_grenade_back);
  1017. else if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  1018. M_SetAnimation(self, &guncmdr_move_attack_chain);
  1019. }
  1020. void guncmdr_fire_chain(edict_t *self)
  1021. {
  1022. if (!(self->monsterinfo.aiflags & AI_STAND_GROUND) && self->enemy && range_to(self, self->enemy) > RANGE_CHAINGUN_RUN && ai_check_move(self, 8.0f))
  1023. M_SetAnimation(self, &guncmdr_move_fire_chain_run);
  1024. else
  1025. M_SetAnimation(self, &guncmdr_move_fire_chain);
  1026. }
  1027. void guncmdr_refire_chain(edict_t *self)
  1028. {
  1029. monster_done_dodge(self);
  1030. self->monsterinfo.attack_state = AS_STRAIGHT;
  1031. if (self->enemy->health > 0)
  1032. if (visible(self, self->enemy))
  1033. if (frandom() <= 0.5f)
  1034. {
  1035. if (!(self->monsterinfo.aiflags & AI_STAND_GROUND) && self->enemy && range_to(self, self->enemy) > RANGE_CHAINGUN_RUN && ai_check_move(self, 8.0f))
  1036. M_SetAnimation(self, &guncmdr_move_fire_chain_run, false);
  1037. else
  1038. M_SetAnimation(self, &guncmdr_move_fire_chain, false);
  1039. return;
  1040. }
  1041. M_SetAnimation(self, &guncmdr_move_endfire_chain, false);
  1042. }
  1043. //===========
  1044. // PGM
  1045. void guncmdr_jump_now(edict_t *self)
  1046. {
  1047. vec3_t forward, up;
  1048. AngleVectors(self->s.angles, forward, nullptr, up);
  1049. self->velocity += (forward * 100);
  1050. self->velocity += (up * 300);
  1051. }
  1052. void guncmdr_jump2_now(edict_t *self)
  1053. {
  1054. vec3_t forward, up;
  1055. AngleVectors(self->s.angles, forward, nullptr, up);
  1056. self->velocity += (forward * 150);
  1057. self->velocity += (up * 400);
  1058. }
  1059. void guncmdr_jump_wait_land(edict_t *self)
  1060. {
  1061. if (self->groundentity == nullptr)
  1062. {
  1063. self->monsterinfo.nextframe = self->s.frame;
  1064. if (monster_jump_finished(self))
  1065. self->monsterinfo.nextframe = self->s.frame + 1;
  1066. }
  1067. else
  1068. self->monsterinfo.nextframe = self->s.frame + 1;
  1069. }
  1070. mframe_t guncmdr_frames_jump[] = {
  1071. { ai_move },
  1072. { ai_move },
  1073. { ai_move },
  1074. { ai_move, 0, guncmdr_jump_now },
  1075. { ai_move },
  1076. { ai_move },
  1077. { ai_move, 0, guncmdr_jump_wait_land },
  1078. { ai_move },
  1079. { ai_move },
  1080. { ai_move }
  1081. };
  1082. MMOVE_T(guncmdr_move_jump) = { FRAME_c_jump01, FRAME_c_jump10, guncmdr_frames_jump, guncmdr_run };
  1083. mframe_t guncmdr_frames_jump2[] = {
  1084. { ai_move, -8 },
  1085. { ai_move, -4 },
  1086. { ai_move, -4 },
  1087. { ai_move, 0, guncmdr_jump2_now },
  1088. { ai_move },
  1089. { ai_move },
  1090. { ai_move, 0, guncmdr_jump_wait_land },
  1091. { ai_move },
  1092. { ai_move },
  1093. { ai_move }
  1094. };
  1095. MMOVE_T(guncmdr_move_jump2) = { FRAME_c_jump01, FRAME_c_jump10, guncmdr_frames_jump2, guncmdr_run };
  1096. void guncmdr_jump(edict_t *self, blocked_jump_result_t result)
  1097. {
  1098. if (!self->enemy)
  1099. return;
  1100. monster_done_dodge(self);
  1101. if (result == blocked_jump_result_t::JUMP_JUMP_UP)
  1102. M_SetAnimation(self, &guncmdr_move_jump2);
  1103. else
  1104. M_SetAnimation(self, &guncmdr_move_jump);
  1105. }
  1106. void T_SlamRadiusDamage(vec3_t point, edict_t *inflictor, edict_t *attacker, float damage, float kick, edict_t *ignore, float radius, mod_t mod);
  1107. static void GunnerCmdrCounter(edict_t *self)
  1108. {
  1109. gi.WriteByte(svc_temp_entity);
  1110. gi.WriteByte(TE_BERSERK_SLAM);
  1111. vec3_t f, r, start;
  1112. AngleVectors(self->s.angles, f, r, nullptr);
  1113. start = M_ProjectFlashSource(self, { 20.f, 0.f, 14.f }, f, r);
  1114. trace_t tr = gi.traceline(self->s.origin, start, self, MASK_SOLID);
  1115. gi.WritePosition(tr.endpos);
  1116. gi.WriteDir(f);
  1117. gi.multicast(tr.endpos, MULTICAST_PHS, false);
  1118. T_SlamRadiusDamage(tr.endpos, self, self, 15, 250.f, self, 200.f, MOD_UNKNOWN);
  1119. }
  1120. //===========
  1121. // PGM
  1122. mframe_t guncmdr_frames_duck_attack[] = {
  1123. { ai_move, 3.6f },
  1124. { ai_move, 5.6f, monster_duck_down },
  1125. { ai_move, 8.4f },
  1126. { ai_move, 2.0f, monster_duck_hold },
  1127. { ai_charge },
  1128. { ai_charge },
  1129. { ai_charge },
  1130. { ai_charge },
  1131. { ai_charge },
  1132. { ai_charge },
  1133. //{ ai_charge, 0, GunnerCmdrGrenade },
  1134. //{ ai_charge, 9.5f, GunnerCmdrGrenade },
  1135. //{ ai_charge, -1.5f, GunnerCmdrGrenade },
  1136. { ai_charge, 0 },
  1137. { ai_charge, 9.5f, GunnerCmdrCounter },
  1138. { ai_charge, -1.5f },
  1139. { ai_charge },
  1140. { ai_charge, 0, monster_duck_up },
  1141. { ai_charge },
  1142. { ai_charge, 11.f },
  1143. { ai_charge, 2.0f },
  1144. { ai_charge, 5.6f }
  1145. };
  1146. MMOVE_T(guncmdr_move_duck_attack) = { FRAME_c_attack901, FRAME_c_attack919, guncmdr_frames_duck_attack, guncmdr_run };
  1147. MONSTERINFO_DUCK(guncmdr_duck) (edict_t *self, gtime_t eta) -> bool
  1148. {
  1149. if ((self->monsterinfo.active_move == &guncmdr_move_jump2) ||
  1150. (self->monsterinfo.active_move == &guncmdr_move_jump))
  1151. {
  1152. return false;
  1153. }
  1154. if ((self->monsterinfo.active_move == &guncmdr_move_fire_chain_dodge_left) ||
  1155. (self->monsterinfo.active_move == &guncmdr_move_fire_chain_dodge_right) ||
  1156. (self->monsterinfo.active_move == &guncmdr_move_attack_grenade_back_dodge_left) ||
  1157. (self->monsterinfo.active_move == &guncmdr_move_attack_grenade_back_dodge_right) ||
  1158. (self->monsterinfo.active_move == &guncmdr_move_attack_mortar_dodge))
  1159. {
  1160. // if we're dodging, don't duck
  1161. self->monsterinfo.unduck(self);
  1162. return false;
  1163. }
  1164. M_SetAnimation(self, &guncmdr_move_duck_attack);
  1165. return true;
  1166. }
  1167. MONSTERINFO_SIDESTEP(guncmdr_sidestep) (edict_t *self) -> bool
  1168. {
  1169. // use special dodge during the main firing anim
  1170. if (self->monsterinfo.active_move == &guncmdr_move_fire_chain ||
  1171. self->monsterinfo.active_move == &guncmdr_move_fire_chain_run)
  1172. {
  1173. M_SetAnimation(self, !self->monsterinfo.lefty ? &guncmdr_move_fire_chain_dodge_right : &guncmdr_move_fire_chain_dodge_left, false);
  1174. return true;
  1175. }
  1176. // for backwards mortar, back up where we are in the animation and do a quick dodge
  1177. if (self->monsterinfo.active_move == &guncmdr_move_attack_grenade_back)
  1178. {
  1179. self->count = self->s.frame;
  1180. M_SetAnimation(self, !self->monsterinfo.lefty ? &guncmdr_move_attack_grenade_back_dodge_right : &guncmdr_move_attack_grenade_back_dodge_left, false);
  1181. return true;
  1182. }
  1183. // use crouch-move for mortar dodge
  1184. if (self->monsterinfo.active_move == &guncmdr_move_attack_mortar)
  1185. {
  1186. self->count = self->s.frame;
  1187. M_SetAnimation(self, &guncmdr_move_attack_mortar_dodge, false);
  1188. return true;
  1189. }
  1190. // regular sidestep during run
  1191. if (self->monsterinfo.active_move == &guncmdr_move_run)
  1192. {
  1193. M_SetAnimation(self, &guncmdr_move_run, true);
  1194. return true;
  1195. }
  1196. return false;
  1197. }
  1198. MONSTERINFO_BLOCKED(guncmdr_blocked) (edict_t *self, float dist) -> bool
  1199. {
  1200. if (blocked_checkplat(self, dist))
  1201. return true;
  1202. if (auto result = blocked_checkjump(self, dist); result != blocked_jump_result_t::NO_JUMP)
  1203. {
  1204. if (result != blocked_jump_result_t::JUMP_TURN)
  1205. guncmdr_jump(self, result);
  1206. return true;
  1207. }
  1208. return false;
  1209. }
  1210. // PGM
  1211. //===========
  1212. /*QUAKED monster_guncmdr (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight NoJumping
  1213. model="models/monsters/guncmdr/tris.md2"
  1214. */
  1215. void SP_monster_guncmdr(edict_t *self)
  1216. {
  1217. if ( !M_AllowSpawn( self ) ) {
  1218. G_FreeEdict( self );
  1219. return;
  1220. }
  1221. sound_death.assign("guncmdr/gcdrdeath1.wav");
  1222. sound_pain.assign("guncmdr/gcdrpain2.wav");
  1223. sound_pain2.assign("guncmdr/gcdrpain1.wav");
  1224. sound_idle.assign("guncmdr/gcdridle1.wav");
  1225. sound_open.assign("guncmdr/gcdratck1.wav");
  1226. sound_search.assign("guncmdr/gcdrsrch1.wav");
  1227. sound_sight.assign("guncmdr/sight1.wav");
  1228. gi.soundindex("guncmdr/gcdratck2.wav");
  1229. gi.soundindex("guncmdr/gcdratck3.wav");
  1230. self->movetype = MOVETYPE_STEP;
  1231. self->solid = SOLID_BBOX;
  1232. self->s.modelindex = gi.modelindex("models/monsters/gunner/tris.md2");
  1233. gi.modelindex("models/monsters/gunner/gibs/chest.md2");
  1234. gi.modelindex("models/monsters/gunner/gibs/foot.md2");
  1235. gi.modelindex("models/monsters/gunner/gibs/garm.md2");
  1236. gi.modelindex("models/monsters/gunner/gibs/gun.md2");
  1237. gi.modelindex("models/monsters/gunner/gibs/head.md2");
  1238. self->s.scale = 1.25f;
  1239. self->mins = vec3_t { -16, -16, -24 };
  1240. self->maxs = vec3_t { 16, 16, 36 };
  1241. self->s.skinnum = 2;
  1242. self->health = 325 * st.health_multiplier;
  1243. self->gib_health = -175;
  1244. self->mass = 255;
  1245. self->pain = guncmdr_pain;
  1246. self->die = guncmdr_die;
  1247. self->monsterinfo.stand = guncmdr_stand;
  1248. self->monsterinfo.walk = guncmdr_walk;
  1249. self->monsterinfo.run = guncmdr_run;
  1250. // pmm
  1251. self->monsterinfo.dodge = M_MonsterDodge;
  1252. self->monsterinfo.duck = guncmdr_duck;
  1253. self->monsterinfo.unduck = monster_duck_up;
  1254. self->monsterinfo.sidestep = guncmdr_sidestep;
  1255. self->monsterinfo.blocked = guncmdr_blocked; // PGM
  1256. // pmm
  1257. self->monsterinfo.attack = guncmdr_attack;
  1258. self->monsterinfo.melee = nullptr;
  1259. self->monsterinfo.sight = guncmdr_sight;
  1260. self->monsterinfo.search = guncmdr_search;
  1261. self->monsterinfo.setskin = guncmdr_setskin;
  1262. gi.linkentity(self);
  1263. M_SetAnimation(self, &guncmdr_move_stand);
  1264. self->monsterinfo.scale = MODEL_SCALE;
  1265. if (!st.was_key_specified("power_armor_power"))
  1266. self->monsterinfo.power_armor_power = 200;
  1267. if (!st.was_key_specified("power_armor_type"))
  1268. self->monsterinfo.power_armor_type = IT_ITEM_POWER_SHIELD;
  1269. // PMM
  1270. //self->monsterinfo.blindfire = true;
  1271. self->monsterinfo.can_jump = !self->spawnflags.has(SPAWNFLAG_GUNCMDR_NOJUMPING);
  1272. self->monsterinfo.drop_height = 192;
  1273. self->monsterinfo.jump_height = 40;
  1274. walkmonster_start(self);
  1275. }