m_infantry.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. /*
  4. ==============================================================================
  5. INFANTRY
  6. ==============================================================================
  7. */
  8. #include "g_local.h"
  9. #include "m_infantry.h"
  10. #include "m_flash.h"
  11. void InfantryMachineGun(edict_t *self);
  12. static cached_soundindex sound_pain1;
  13. static cached_soundindex sound_pain2;
  14. static cached_soundindex sound_die1;
  15. static cached_soundindex sound_die2;
  16. static cached_soundindex sound_gunshot;
  17. static cached_soundindex sound_weapon_cock;
  18. static cached_soundindex sound_punch_swing;
  19. static cached_soundindex sound_punch_hit;
  20. static cached_soundindex sound_sight;
  21. static cached_soundindex sound_search;
  22. static cached_soundindex sound_idle;
  23. // range at which we'll try to initiate a run-attack to close distance
  24. constexpr float RANGE_RUN_ATTACK = RANGE_NEAR * 0.75f;
  25. mframe_t infantry_frames_stand[] = {
  26. { ai_stand },
  27. { ai_stand },
  28. { ai_stand },
  29. { ai_stand },
  30. { ai_stand },
  31. { ai_stand },
  32. { ai_stand },
  33. { ai_stand },
  34. { ai_stand },
  35. { ai_stand },
  36. { ai_stand },
  37. { ai_stand },
  38. { ai_stand },
  39. { ai_stand },
  40. { ai_stand },
  41. { ai_stand },
  42. { ai_stand },
  43. { ai_stand },
  44. { ai_stand },
  45. { ai_stand },
  46. { ai_stand },
  47. { ai_stand }
  48. };
  49. MMOVE_T(infantry_move_stand) = { FRAME_stand50, FRAME_stand71, infantry_frames_stand, nullptr };
  50. MONSTERINFO_STAND(infantry_stand) (edict_t *self) -> void
  51. {
  52. M_SetAnimation(self, &infantry_move_stand);
  53. }
  54. mframe_t infantry_frames_fidget[] = {
  55. { ai_stand, 1 },
  56. { ai_stand },
  57. { ai_stand, 1 },
  58. { ai_stand, 3 },
  59. { ai_stand, 6 },
  60. { ai_stand, 3, monster_footstep },
  61. { ai_stand },
  62. { ai_stand },
  63. { ai_stand },
  64. { ai_stand },
  65. { ai_stand, 1 },
  66. { ai_stand },
  67. { ai_stand },
  68. { ai_stand },
  69. { ai_stand },
  70. { ai_stand, 1 },
  71. { ai_stand },
  72. { ai_stand, -1 },
  73. { ai_stand },
  74. { ai_stand },
  75. { ai_stand, 1 },
  76. { ai_stand },
  77. { ai_stand, -2 },
  78. { ai_stand, 1 },
  79. { ai_stand, 1 },
  80. { ai_stand, 1 },
  81. { ai_stand, -1 },
  82. { ai_stand },
  83. { ai_stand },
  84. { ai_stand, -1 },
  85. { ai_stand },
  86. { ai_stand },
  87. { ai_stand },
  88. { ai_stand },
  89. { ai_stand },
  90. { ai_stand, -1 },
  91. { ai_stand },
  92. { ai_stand },
  93. { ai_stand, 1 },
  94. { ai_stand },
  95. { ai_stand },
  96. { ai_stand, -1 },
  97. { ai_stand, -1 },
  98. { ai_stand },
  99. { ai_stand, -3 },
  100. { ai_stand, -2 },
  101. { ai_stand, -3 },
  102. { ai_stand, -3, monster_footstep },
  103. { ai_stand, -2 }
  104. };
  105. MMOVE_T(infantry_move_fidget) = { FRAME_stand01, FRAME_stand49, infantry_frames_fidget, infantry_stand };
  106. MONSTERINFO_IDLE(infantry_fidget) (edict_t *self) -> void
  107. {
  108. if (self->enemy)
  109. return;
  110. M_SetAnimation(self, &infantry_move_fidget);
  111. gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  112. }
  113. mframe_t infantry_frames_walk[] = {
  114. { ai_walk, 5, monster_footstep },
  115. { ai_walk, 4 },
  116. { ai_walk, 4 },
  117. { ai_walk, 5 },
  118. { ai_walk, 4 },
  119. { ai_walk, 5 },
  120. { ai_walk, 6, monster_footstep },
  121. { ai_walk, 4 },
  122. { ai_walk, 4 },
  123. { ai_walk, 4 },
  124. { ai_walk, 4 },
  125. { ai_walk, 5 }
  126. };
  127. MMOVE_T(infantry_move_walk) = { FRAME_walk03, FRAME_walk14, infantry_frames_walk, nullptr };
  128. MONSTERINFO_WALK(infantry_walk) (edict_t *self) -> void
  129. {
  130. M_SetAnimation(self, &infantry_move_walk);
  131. }
  132. mframe_t infantry_frames_run[] = {
  133. { ai_run, 10 },
  134. { ai_run, 15, monster_footstep },
  135. { ai_run, 5 },
  136. { ai_run, 7, monster_done_dodge },
  137. { ai_run, 18 },
  138. { ai_run, 20, monster_footstep },
  139. { ai_run, 2 },
  140. { ai_run, 6 }
  141. };
  142. MMOVE_T(infantry_move_run) = { FRAME_run01, FRAME_run08, infantry_frames_run, nullptr };
  143. MONSTERINFO_RUN(infantry_run) (edict_t *self) -> void
  144. {
  145. monster_done_dodge(self);
  146. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  147. M_SetAnimation(self, &infantry_move_stand);
  148. else
  149. M_SetAnimation(self, &infantry_move_run);
  150. }
  151. mframe_t infantry_frames_pain1[] = {
  152. { ai_move, -3 },
  153. { ai_move, -2 },
  154. { ai_move, -1 },
  155. { ai_move, -2 },
  156. { ai_move, -1, monster_footstep },
  157. { ai_move, 1 },
  158. { ai_move, -1 },
  159. { ai_move, 1 },
  160. { ai_move, 6 },
  161. { ai_move, 2, monster_footstep }
  162. };
  163. MMOVE_T(infantry_move_pain1) = { FRAME_pain101, FRAME_pain110, infantry_frames_pain1, infantry_run };
  164. mframe_t infantry_frames_pain2[] = {
  165. { ai_move, -3 },
  166. { ai_move, -3 },
  167. { ai_move },
  168. { ai_move, -1 },
  169. { ai_move, -2, monster_footstep },
  170. { ai_move },
  171. { ai_move },
  172. { ai_move, 2 },
  173. { ai_move, 5 },
  174. { ai_move, 2, monster_footstep }
  175. };
  176. MMOVE_T(infantry_move_pain2) = { FRAME_pain201, FRAME_pain210, infantry_frames_pain2, infantry_run };
  177. extern const mmove_t infantry_move_jump;
  178. extern const mmove_t infantry_move_jump2;
  179. PAIN(infantry_pain) (edict_t *self, edict_t *other, float kick, int damage, const mod_t &mod) -> void
  180. {
  181. int n;
  182. // allow turret to pain
  183. if ((self->monsterinfo.active_move == &infantry_move_jump ||
  184. self->monsterinfo.active_move == &infantry_move_jump2) && self->think == monster_think)
  185. return;
  186. monster_done_dodge(self);
  187. if (level.time < self->pain_debounce_time)
  188. {
  189. if (self->think == monster_think && frandom() < 0.33f)
  190. self->monsterinfo.dodge(self, other, FRAME_TIME_S, nullptr, false);
  191. return;
  192. }
  193. self->pain_debounce_time = level.time + 3_sec;
  194. n = brandom();
  195. if (n == 0)
  196. gi.sound(self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  197. else
  198. gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  199. if (self->think != monster_think)
  200. return;
  201. if (!M_ShouldReactToPain(self, mod))
  202. {
  203. if (self->think == monster_think && frandom() < 0.33f)
  204. self->monsterinfo.dodge(self, other, FRAME_TIME_S, nullptr, false);
  205. return; // no pain anims in nightmare
  206. }
  207. if (n == 0)
  208. M_SetAnimation(self, &infantry_move_pain1);
  209. else
  210. M_SetAnimation(self, &infantry_move_pain2);
  211. // PMM - clear duck flag
  212. if (self->monsterinfo.aiflags & AI_DUCKED)
  213. monster_duck_up(self);
  214. }
  215. MONSTERINFO_SETSKIN(infantry_setskin) (edict_t *self) -> void
  216. {
  217. if (self->health < (self->max_health / 2))
  218. self->s.skinnum = 1;
  219. else
  220. self->s.skinnum = 0;
  221. }
  222. constexpr vec3_t aimangles[] = {
  223. { 0.0f, 5.0f, 0.0f },
  224. { 10.0f, 15.0f, 0.0f },
  225. { 20.0f, 25.0f, 0.0f },
  226. { 25.0f, 35.0f, 0.0f },
  227. { 30.0f, 40.0f, 0.0f },
  228. { 30.0f, 45.0f, 0.0f },
  229. { 25.0f, 50.0f, 0.0f },
  230. { 20.0f, 40.0f, 0.0f },
  231. { 15.0f, 35.0f, 0.0f },
  232. { 40.0f, 35.0f, 0.0f },
  233. { 70.0f, 35.0f, 0.0f },
  234. { 90.0f, 35.0f, 0.0f }
  235. };
  236. void InfantryMachineGun(edict_t *self)
  237. {
  238. vec3_t start;
  239. vec3_t forward, right;
  240. vec3_t vec;
  241. monster_muzzleflash_id_t flash_number;
  242. if (!self->enemy || !self->enemy->inuse) // PGM
  243. return; // PGM
  244. bool is_run_attack = (self->s.frame >= FRAME_run201 && self->s.frame <= FRAME_run208);
  245. if (self->s.frame == FRAME_attak103 || self->s.frame == FRAME_attak311 || is_run_attack || self->s.frame == FRAME_attak416)
  246. {
  247. if (is_run_attack)
  248. flash_number = static_cast<monster_muzzleflash_id_t>(MZ2_INFANTRY_MACHINEGUN_14 + (self->s.frame - MZ2_INFANTRY_MACHINEGUN_14));
  249. else if (self->s.frame == FRAME_attak416)
  250. flash_number = MZ2_INFANTRY_MACHINEGUN_22;
  251. else
  252. flash_number = MZ2_INFANTRY_MACHINEGUN_1;
  253. AngleVectors(self->s.angles, forward, right, nullptr);
  254. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  255. if (self->enemy)
  256. PredictAim(self, self->enemy, start, 0, true, -0.2f, &forward, nullptr);
  257. else
  258. {
  259. AngleVectors(self->s.angles, forward, right, nullptr);
  260. }
  261. }
  262. else
  263. {
  264. flash_number = static_cast<monster_muzzleflash_id_t>(MZ2_INFANTRY_MACHINEGUN_2 + (self->s.frame - FRAME_death211));
  265. AngleVectors(self->s.angles, forward, right, nullptr);
  266. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  267. vec = self->s.angles - aimangles[flash_number - MZ2_INFANTRY_MACHINEGUN_2];
  268. AngleVectors(vec, forward, nullptr, nullptr);
  269. }
  270. monster_fire_bullet(self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
  271. }
  272. MONSTERINFO_SIGHT(infantry_sight) (edict_t *self, edict_t *other) -> void
  273. {
  274. if (brandom())
  275. gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  276. else
  277. gi.sound(self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  278. }
  279. void infantry_dead(edict_t *self)
  280. {
  281. self->mins = { -16, -16, -24 };
  282. self->maxs = { 16, 16, -8 };
  283. monster_dead(self);
  284. }
  285. static void infantry_shrink(edict_t *self)
  286. {
  287. self->maxs[2] = 0;
  288. self->svflags |= SVF_DEADMONSTER;
  289. gi.linkentity(self);
  290. }
  291. mframe_t infantry_frames_death1[] = {
  292. { ai_move, -4, nullptr, FRAME_death102 },
  293. { ai_move },
  294. { ai_move },
  295. { ai_move, -1 },
  296. { ai_move, -4, monster_footstep },
  297. { ai_move },
  298. { ai_move },
  299. { ai_move },
  300. { ai_move, -1, monster_footstep },
  301. { ai_move, 3 },
  302. { ai_move, 1 },
  303. { ai_move, 1 },
  304. { ai_move, -2 },
  305. { ai_move, 2 },
  306. { ai_move, 2 },
  307. { ai_move, 9, [](edict_t *self) { infantry_shrink(self); monster_footstep(self); } },
  308. { ai_move, 9 },
  309. { ai_move, 5, monster_footstep },
  310. { ai_move, -3 },
  311. { ai_move, -3 }
  312. };
  313. MMOVE_T(infantry_move_death1) = { FRAME_death101, FRAME_death120, infantry_frames_death1, infantry_dead };
  314. // Off with his head
  315. mframe_t infantry_frames_death2[] = {
  316. { ai_move, 0, nullptr, FRAME_death202 },
  317. { ai_move, 1 },
  318. { ai_move, 5 },
  319. { ai_move, -1 },
  320. { ai_move },
  321. { ai_move, 1, monster_footstep },
  322. { ai_move, 1, monster_footstep },
  323. { ai_move, 4 },
  324. { ai_move, 3 },
  325. { ai_move },
  326. { ai_move, -2, InfantryMachineGun },
  327. { ai_move, -2, InfantryMachineGun },
  328. { ai_move, -3, InfantryMachineGun },
  329. { ai_move, -1, InfantryMachineGun },
  330. { ai_move, -2, InfantryMachineGun },
  331. { ai_move, 0, InfantryMachineGun },
  332. { ai_move, 2, InfantryMachineGun },
  333. { ai_move, 2, InfantryMachineGun },
  334. { ai_move, 3, InfantryMachineGun },
  335. { ai_move, -10, InfantryMachineGun },
  336. { ai_move, -7, InfantryMachineGun },
  337. { ai_move, -8, InfantryMachineGun },
  338. { ai_move, -6, [](edict_t *self) { infantry_shrink(self); monster_footstep(self); } },
  339. { ai_move, 4 },
  340. { ai_move }
  341. };
  342. MMOVE_T(infantry_move_death2) = { FRAME_death201, FRAME_death225, infantry_frames_death2, infantry_dead };
  343. mframe_t infantry_frames_death3[] = {
  344. { ai_move, 0 },
  345. { ai_move },
  346. { ai_move, 0, [](edict_t *self) { infantry_shrink(self); monster_footstep(self); } },
  347. { ai_move, -6 },
  348. { ai_move, -11, [](edict_t *self) { self->monsterinfo.nextframe = FRAME_death307; } },
  349. { ai_move, -3 },
  350. { ai_move, -11 },
  351. { ai_move, 0, monster_footstep },
  352. { ai_move }
  353. };
  354. MMOVE_T(infantry_move_death3) = { FRAME_death301, FRAME_death309, infantry_frames_death3, infantry_dead };
  355. DIE(infantry_die) (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void
  356. {
  357. int n;
  358. // check for gib
  359. if (M_CheckGib(self, mod))
  360. {
  361. gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
  362. const char *head_gib = (self->monsterinfo.active_move != &infantry_move_death3) ? "models/objects/gibs/sm_meat/tris.md2" : "models/monsters/infantry/gibs/head.md2";
  363. self->s.skinnum /= 2;
  364. ThrowGibs(self, damage, {
  365. { "models/objects/gibs/bone/tris.md2" },
  366. { 3, "models/objects/gibs/sm_meat/tris.md2" },
  367. { "models/monsters/infantry/gibs/chest.md2", GIB_SKINNED },
  368. { "models/monsters/infantry/gibs/gun.md2", GIB_SKINNED | GIB_UPRIGHT },
  369. { 2, "models/monsters/infantry/gibs/foot.md2", GIB_SKINNED },
  370. { 2, "models/monsters/infantry/gibs/arm.md2", GIB_SKINNED },
  371. { head_gib, GIB_HEAD | GIB_SKINNED }
  372. });
  373. self->deadflag = true;
  374. return;
  375. }
  376. if (self->deadflag)
  377. return;
  378. // regular death
  379. self->deadflag = true;
  380. self->takedamage = true;
  381. n = irandom(3);
  382. if (n == 0)
  383. {
  384. M_SetAnimation(self, &infantry_move_death1);
  385. gi.sound(self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
  386. }
  387. else if (n == 1)
  388. {
  389. M_SetAnimation(self, &infantry_move_death2);
  390. gi.sound(self, CHAN_VOICE, sound_die1, 1, ATTN_NORM, 0);
  391. }
  392. else
  393. {
  394. M_SetAnimation(self, &infantry_move_death3);
  395. gi.sound(self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
  396. }
  397. // don't always pop a head gib, it gets old
  398. if (n != 2 && frandom() <= 0.25f)
  399. {
  400. edict_t *head = ThrowGib(self, "models/monsters/infantry/gibs/head.md2", damage, GIB_NONE, self->s.scale);
  401. if (head)
  402. {
  403. head->s.angles = self->s.angles;
  404. head->s.origin = self->s.origin + vec3_t{0, 0, 32.f};
  405. vec3_t headDir = (self->s.origin - inflictor->s.origin);
  406. head->velocity = headDir / headDir.length() * 100.0f;
  407. head->velocity[2] = 200.0f;
  408. head->avelocity *= 0.15f;
  409. head->s.skinnum = 0;
  410. gi.linkentity(head);
  411. }
  412. }
  413. }
  414. mframe_t infantry_frames_duck[] = {
  415. { ai_move, -2, monster_duck_down },
  416. { ai_move, -5, monster_duck_hold },
  417. { ai_move, 3 },
  418. { ai_move, 4, monster_duck_up },
  419. { ai_move }
  420. };
  421. MMOVE_T(infantry_move_duck) = { FRAME_duck01, FRAME_duck05, infantry_frames_duck, infantry_run };
  422. // PMM - dodge code moved below so I can see the attack frames
  423. extern const mmove_t infantry_move_attack4;
  424. void infantry_set_firetime(edict_t *self)
  425. {
  426. self->monsterinfo.fire_wait = level.time + random_time(0.7_sec, 2_sec);
  427. if (!(self->monsterinfo.aiflags & AI_STAND_GROUND) && self->enemy && range_to(self, self->enemy) >= RANGE_RUN_ATTACK && ai_check_move(self, 8.0f))
  428. M_SetAnimation(self, &infantry_move_attack4, false);
  429. }
  430. void infantry_cock_gun(edict_t *self)
  431. {
  432. gi.sound(self, CHAN_WEAPON, sound_weapon_cock, 1, ATTN_NORM, 0);
  433. // gun cocked
  434. self->count = 1;
  435. }
  436. void infantry_fire(edict_t *self);
  437. // cock-less attack, used if he has already cocked his gun
  438. mframe_t infantry_frames_attack1[] = {
  439. { ai_charge },
  440. { ai_charge, 6, [](edict_t *self) { infantry_set_firetime(self); monster_footstep(self); } },
  441. { ai_charge, 0, infantry_fire },
  442. { ai_charge },
  443. { ai_charge, 1 },
  444. { ai_charge, -7 },
  445. { ai_charge, -6, [](edict_t *self) { self->monsterinfo.nextframe = FRAME_attak114; monster_footstep(self); } },
  446. // dead frames start
  447. { ai_charge, -1 },
  448. { ai_charge, 0, infantry_cock_gun },
  449. { ai_charge },
  450. { ai_charge },
  451. { ai_charge },
  452. { ai_charge },
  453. // dead frames end
  454. { ai_charge, -1 },
  455. { ai_charge, -1 }
  456. };
  457. MMOVE_T(infantry_move_attack1) = { FRAME_attak101, FRAME_attak115, infantry_frames_attack1, infantry_run };
  458. // old animation, full cock + shoot
  459. mframe_t infantry_frames_attack3[] = {
  460. { ai_charge, 4, NULL },
  461. { ai_charge, -1, NULL },
  462. { ai_charge, -1, NULL },
  463. { ai_charge, 0, infantry_cock_gun },
  464. { ai_charge, -1, NULL },
  465. { ai_charge, 1, NULL },
  466. { ai_charge, 1, NULL },
  467. { ai_charge, 2, NULL },
  468. { ai_charge, -2, NULL },
  469. { ai_charge, -3, [](edict_t *self) { infantry_set_firetime(self); monster_footstep(self); } },
  470. { ai_charge, 1, infantry_fire },
  471. { ai_charge, 5, NULL },
  472. { ai_charge, -1, NULL },
  473. { ai_charge, -2, NULL },
  474. { ai_charge, -3, NULL },
  475. };
  476. MMOVE_T(infantry_move_attack3) = { FRAME_attak301, FRAME_attak315, infantry_frames_attack3, infantry_run };
  477. // even older animation, full cock + shoot
  478. mframe_t infantry_frames_attack5[] = {
  479. // skipped frames
  480. { ai_charge, 0, NULL },
  481. { ai_charge, 0, NULL },
  482. { ai_charge, 0, NULL },
  483. { ai_charge, 0, NULL },
  484. { ai_charge, 0, NULL },
  485. { ai_charge, 0, nullptr },
  486. { ai_charge, 0, monster_footstep },
  487. { ai_charge, 0, infantry_cock_gun },
  488. { ai_charge, 0, NULL },
  489. { ai_charge, 0, NULL },
  490. { ai_charge, 0, [](edict_t *self) { self->monsterinfo.nextframe = self->s.frame + 1; } },
  491. { ai_charge, 0, NULL }, // skipped frame
  492. { ai_charge, 0, NULL },
  493. { ai_charge, 0, nullptr },
  494. { ai_charge, 0, infantry_set_firetime },
  495. { ai_charge, 0, infantry_fire },
  496. // skipped frames
  497. { ai_charge, 0, NULL },
  498. { ai_charge, 0, NULL },
  499. { ai_charge, 0, NULL },
  500. { ai_charge, 0, NULL },
  501. { ai_charge, 0, NULL },
  502. { ai_charge, 0, NULL },
  503. { ai_charge, 0, monster_footstep }
  504. };
  505. MMOVE_T(infantry_move_attack5) = { FRAME_attak401, FRAME_attak423, infantry_frames_attack5, infantry_run };
  506. extern const mmove_t infantry_move_attack4;
  507. void infantry_fire(edict_t *self)
  508. {
  509. InfantryMachineGun(self);
  510. // we fired, so we must cock again before firing
  511. self->count = 0;
  512. // check if we ran out of firing time
  513. if (self->monsterinfo.active_move == &infantry_move_attack4)
  514. {
  515. if (level.time >= self->monsterinfo.fire_wait)
  516. {
  517. monster_done_dodge(self);
  518. M_SetAnimation(self, &infantry_move_attack1, false);
  519. self->monsterinfo.nextframe = FRAME_attak114;
  520. }
  521. // got close to an edge
  522. else if (!ai_check_move(self, 8.0f))
  523. {
  524. M_SetAnimation(self, &infantry_move_attack1, false);
  525. self->monsterinfo.nextframe = FRAME_attak103;
  526. monster_done_dodge(self);
  527. self->monsterinfo.attack_state = AS_STRAIGHT;
  528. }
  529. }
  530. else if ((self->s.frame >= FRAME_attak101 && self->s.frame <= FRAME_attak115) ||
  531. (self->s.frame >= FRAME_attak301 && self->s.frame <= FRAME_attak315) ||
  532. (self->s.frame >= FRAME_attak401 && self->s.frame <= FRAME_attak424))
  533. {
  534. if (level.time >= self->monsterinfo.fire_wait)
  535. {
  536. self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
  537. if (self->s.frame == FRAME_attak416)
  538. self->monsterinfo.nextframe = FRAME_attak420;
  539. }
  540. else
  541. self->monsterinfo.aiflags |= AI_HOLD_FRAME;
  542. }
  543. }
  544. void infantry_swing(edict_t *self)
  545. {
  546. gi.sound(self, CHAN_WEAPON, sound_punch_swing, 1, ATTN_NORM, 0);
  547. }
  548. void infantry_smack(edict_t *self)
  549. {
  550. vec3_t aim = { MELEE_DISTANCE, 0, 0 };
  551. if (fire_hit(self, aim, irandom(5, 10), 50))
  552. gi.sound(self, CHAN_WEAPON, sound_punch_hit, 1, ATTN_NORM, 0);
  553. else
  554. self->monsterinfo.melee_debounce_time = level.time + 1.5_sec;
  555. }
  556. mframe_t infantry_frames_attack2[] = {
  557. { ai_charge, 3 },
  558. { ai_charge, 6 },
  559. { ai_charge, 0, infantry_swing },
  560. { ai_charge, 8, monster_footstep },
  561. { ai_charge, 5 },
  562. { ai_charge, 8, infantry_smack },
  563. { ai_charge, 6 },
  564. { ai_charge, 3 }
  565. };
  566. MMOVE_T(infantry_move_attack2) = { FRAME_attak201, FRAME_attak208, infantry_frames_attack2, infantry_run };
  567. // [Paril-KEX] run-attack, inspired by q2test
  568. void infantry_attack4_refire(edict_t *self)
  569. {
  570. // ran out of firing time
  571. if (level.time >= self->monsterinfo.fire_wait)
  572. {
  573. monster_done_dodge(self);
  574. M_SetAnimation(self, &infantry_move_attack1, false);
  575. self->monsterinfo.nextframe = FRAME_attak114;
  576. }
  577. // we got too close, or we can't move forward, switch us back to regular attack
  578. else if ((self->monsterinfo.aiflags & AI_STAND_GROUND) || (self->enemy && (range_to(self, self->enemy) < RANGE_RUN_ATTACK || !ai_check_move(self, 8.0f))))
  579. {
  580. M_SetAnimation(self, &infantry_move_attack1, false);
  581. self->monsterinfo.nextframe = FRAME_attak103;
  582. monster_done_dodge(self);
  583. self->monsterinfo.attack_state = AS_STRAIGHT;
  584. }
  585. else
  586. self->monsterinfo.nextframe = FRAME_run201;
  587. infantry_fire(self);
  588. }
  589. mframe_t infantry_frames_attack4[] = {
  590. { ai_charge, 16, infantry_fire },
  591. { ai_charge, 16, [](edict_t *self) { monster_footstep(self); infantry_fire(self); } },
  592. { ai_charge, 13, infantry_fire },
  593. { ai_charge, 10, infantry_fire },
  594. { ai_charge, 16, infantry_fire },
  595. { ai_charge, 16, [](edict_t *self) { monster_footstep(self); infantry_fire(self); } },
  596. { ai_charge, 16, infantry_fire },
  597. { ai_charge, 16, infantry_attack4_refire }
  598. };
  599. MMOVE_T(infantry_move_attack4) = { FRAME_run201, FRAME_run208, infantry_frames_attack4, infantry_run, 0.5f };
  600. MONSTERINFO_ATTACK(infantry_attack) (edict_t *self) -> void
  601. {
  602. monster_done_dodge(self);
  603. float r = range_to(self, self->enemy);
  604. if (r <= RANGE_MELEE && self->monsterinfo.melee_debounce_time <= level.time)
  605. M_SetAnimation(self, &infantry_move_attack2);
  606. else if (M_CheckClearShot(self, monster_flash_offset[MZ2_INFANTRY_MACHINEGUN_1]))
  607. {
  608. if (self->count)
  609. M_SetAnimation(self, &infantry_move_attack1);
  610. else
  611. {
  612. M_SetAnimation(self, frandom() <= 0.1f ? &infantry_move_attack5 : &infantry_move_attack3);
  613. self->monsterinfo.nextframe = FRAME_attak405;
  614. }
  615. }
  616. }
  617. //===========
  618. // PGM
  619. void infantry_jump_now(edict_t *self)
  620. {
  621. vec3_t forward, up;
  622. AngleVectors(self->s.angles, forward, nullptr, up);
  623. self->velocity += (forward * 100);
  624. self->velocity += (up * 300);
  625. }
  626. void infantry_jump2_now(edict_t *self)
  627. {
  628. vec3_t forward, up;
  629. AngleVectors(self->s.angles, forward, nullptr, up);
  630. self->velocity += (forward * 150);
  631. self->velocity += (up * 400);
  632. }
  633. void infantry_jump_wait_land(edict_t *self)
  634. {
  635. if (self->groundentity == nullptr)
  636. {
  637. self->monsterinfo.nextframe = self->s.frame;
  638. if (monster_jump_finished(self))
  639. self->monsterinfo.nextframe = self->s.frame + 1;
  640. }
  641. else
  642. self->monsterinfo.nextframe = self->s.frame + 1;
  643. }
  644. mframe_t infantry_frames_jump[] = {
  645. { ai_move },
  646. { ai_move },
  647. { ai_move },
  648. { ai_move, 0, infantry_jump_now },
  649. { ai_move },
  650. { ai_move },
  651. { ai_move },
  652. { ai_move, 0, infantry_jump_wait_land },
  653. { ai_move },
  654. { ai_move }
  655. };
  656. MMOVE_T(infantry_move_jump) = { FRAME_jump01, FRAME_jump10, infantry_frames_jump, infantry_run };
  657. mframe_t infantry_frames_jump2[] = {
  658. { ai_move, -8 },
  659. { ai_move, -4 },
  660. { ai_move, -4 },
  661. { ai_move, 0, infantry_jump2_now },
  662. { ai_move },
  663. { ai_move },
  664. { ai_move },
  665. { ai_move, 0, infantry_jump_wait_land },
  666. { ai_move },
  667. { ai_move }
  668. };
  669. MMOVE_T(infantry_move_jump2) = { FRAME_jump01, FRAME_jump10, infantry_frames_jump2, infantry_run };
  670. void infantry_jump(edict_t *self, blocked_jump_result_t result)
  671. {
  672. if (!self->enemy)
  673. return;
  674. monster_done_dodge(self);
  675. if (result == blocked_jump_result_t::JUMP_JUMP_UP)
  676. M_SetAnimation(self, &infantry_move_jump2);
  677. else
  678. M_SetAnimation(self, &infantry_move_jump);
  679. }
  680. MONSTERINFO_BLOCKED(infantry_blocked) (edict_t *self, float dist) -> bool
  681. {
  682. if (auto result = blocked_checkjump(self, dist); result != blocked_jump_result_t::NO_JUMP)
  683. {
  684. if (result != blocked_jump_result_t::JUMP_TURN)
  685. infantry_jump(self, result);
  686. return true;
  687. }
  688. if (blocked_checkplat(self, dist))
  689. return true;
  690. return false;
  691. }
  692. MONSTERINFO_DUCK(infantry_duck) (edict_t *self, gtime_t eta) -> bool
  693. {
  694. // if we're jumping, don't dodge
  695. if ((self->monsterinfo.active_move == &infantry_move_jump) ||
  696. (self->monsterinfo.active_move == &infantry_move_jump2))
  697. {
  698. return false;
  699. }
  700. // don't duck during our firing or melee frames
  701. if (self->s.frame == FRAME_attak103 ||
  702. self->s.frame == FRAME_attak315 ||
  703. (self->monsterinfo.active_move == &infantry_move_attack2))
  704. {
  705. self->monsterinfo.unduck(self);
  706. return false;
  707. }
  708. M_SetAnimation(self, &infantry_move_duck);
  709. return true;
  710. }
  711. MONSTERINFO_SIDESTEP(infantry_sidestep) (edict_t *self) -> bool
  712. {
  713. // if we're jumping, don't dodge
  714. if ((self->monsterinfo.active_move == &infantry_move_jump) ||
  715. (self->monsterinfo.active_move == &infantry_move_jump2))
  716. {
  717. return false;
  718. }
  719. if (self->monsterinfo.active_move == &infantry_move_run)
  720. return true;
  721. // Don't sidestep if we're already sidestepping, and def not unless we're actually shooting
  722. // or if we already cocked
  723. if (self->monsterinfo.active_move != &infantry_move_attack4 &&
  724. self->monsterinfo.next_move != &infantry_move_attack4 &&
  725. ((self->s.frame == FRAME_attak103 ||
  726. self->s.frame == FRAME_attak311 ||
  727. self->s.frame == FRAME_attak416) &&
  728. !self->count))
  729. {
  730. // give us a fire time boost so we don't end up firing for 1 frame
  731. self->monsterinfo.fire_wait += random_time(300_ms, 600_ms);
  732. M_SetAnimation(self, &infantry_move_attack4, false);
  733. }
  734. return true;
  735. }
  736. void InfantryPrecache()
  737. {
  738. sound_pain1.assign("infantry/infpain1.wav");
  739. sound_pain2.assign("infantry/infpain2.wav");
  740. sound_die1.assign("infantry/infdeth1.wav");
  741. sound_die2.assign("infantry/infdeth2.wav");
  742. sound_gunshot.assign("infantry/infatck1.wav");
  743. sound_weapon_cock.assign("infantry/infatck3.wav");
  744. sound_punch_swing.assign("infantry/infatck2.wav");
  745. sound_punch_hit.assign("infantry/melee2.wav");
  746. sound_sight.assign("infantry/infsght1.wav");
  747. sound_search.assign("infantry/infsrch1.wav");
  748. sound_idle.assign("infantry/infidle1.wav");
  749. }
  750. constexpr spawnflags_t SPAWNFLAG_INFANTRY_NOJUMPING = 8_spawnflag;
  751. /*QUAKED monster_infantry (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight NoJumping
  752. */
  753. void SP_monster_infantry(edict_t *self)
  754. {
  755. if ( !M_AllowSpawn( self ) ) {
  756. G_FreeEdict( self );
  757. return;
  758. }
  759. InfantryPrecache();
  760. self->monsterinfo.aiflags |= AI_STINKY;
  761. self->movetype = MOVETYPE_STEP;
  762. self->solid = SOLID_BBOX;
  763. self->s.modelindex = gi.modelindex("models/monsters/infantry/tris.md2");
  764. gi.modelindex("models/monsters/infantry/gibs/head.md2");
  765. gi.modelindex("models/monsters/infantry/gibs/chest.md2");
  766. gi.modelindex("models/monsters/infantry/gibs/gun.md2");
  767. gi.modelindex("models/monsters/infantry/gibs/arm.md2");
  768. gi.modelindex("models/monsters/infantry/gibs/foot.md2");
  769. self->mins = { -16, -16, -24 };
  770. self->maxs = { 16, 16, 32 };
  771. self->health = 100 * st.health_multiplier;
  772. self->gib_health = -65;
  773. self->mass = 200;
  774. self->pain = infantry_pain;
  775. self->die = infantry_die;
  776. self->monsterinfo.combat_style = COMBAT_MIXED;
  777. self->monsterinfo.stand = infantry_stand;
  778. self->monsterinfo.walk = infantry_walk;
  779. self->monsterinfo.run = infantry_run;
  780. // pmm
  781. self->monsterinfo.dodge = M_MonsterDodge;
  782. self->monsterinfo.duck = infantry_duck;
  783. self->monsterinfo.unduck = monster_duck_up;
  784. self->monsterinfo.sidestep = infantry_sidestep;
  785. self->monsterinfo.blocked = infantry_blocked;
  786. // pmm
  787. self->monsterinfo.attack = infantry_attack;
  788. self->monsterinfo.melee = nullptr;
  789. self->monsterinfo.sight = infantry_sight;
  790. self->monsterinfo.idle = infantry_fidget;
  791. self->monsterinfo.setskin = infantry_setskin;
  792. gi.linkentity(self);
  793. M_SetAnimation(self, &infantry_move_stand);
  794. self->monsterinfo.scale = MODEL_SCALE;
  795. self->monsterinfo.can_jump = !self->spawnflags.has(SPAWNFLAG_INFANTRY_NOJUMPING);
  796. self->monsterinfo.drop_height = 192;
  797. self->monsterinfo.jump_height = 40;
  798. walkmonster_start(self);
  799. }