m_tank.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. /*
  4. ==============================================================================
  5. TANK
  6. ==============================================================================
  7. */
  8. #include "g_local.h"
  9. #include "m_tank.h"
  10. #include "m_flash.h"
  11. void tank_refire_rocket(edict_t *self);
  12. void tank_doattack_rocket(edict_t *self);
  13. void tank_reattack_blaster(edict_t *self);
  14. static cached_soundindex sound_thud;
  15. static cached_soundindex sound_pain, sound_pain2;
  16. static cached_soundindex sound_idle;
  17. static cached_soundindex sound_die;
  18. static cached_soundindex sound_step;
  19. static cached_soundindex sound_sight;
  20. static cached_soundindex sound_windup;
  21. static cached_soundindex sound_strike;
  22. constexpr spawnflags_t SPAWNFLAG_TANK_COMMANDER_GUARDIAN = 8_spawnflag;
  23. constexpr spawnflags_t SPAWNFLAG_TANK_COMMANDER_HEAT_SEEKING = 16_spawnflag;
  24. //
  25. // misc
  26. //
  27. MONSTERINFO_SIGHT(tank_sight) (edict_t *self, edict_t *other) -> void
  28. {
  29. gi.sound(self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  30. }
  31. void tank_footstep(edict_t *self)
  32. {
  33. gi.sound(self, CHAN_BODY, sound_step, 1, ATTN_NORM, 0);
  34. }
  35. void tank_thud(edict_t *self)
  36. {
  37. gi.sound(self, CHAN_BODY, sound_thud, 1, ATTN_NORM, 0);
  38. }
  39. void tank_windup(edict_t *self)
  40. {
  41. gi.sound(self, CHAN_WEAPON, sound_windup, 1, ATTN_NORM, 0);
  42. }
  43. MONSTERINFO_IDLE(tank_idle) (edict_t *self) -> void
  44. {
  45. gi.sound(self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  46. }
  47. //
  48. // stand
  49. //
  50. mframe_t tank_frames_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. };
  82. MMOVE_T(tank_move_stand) = { FRAME_stand01, FRAME_stand30, tank_frames_stand, nullptr };
  83. MONSTERINFO_STAND(tank_stand) (edict_t *self) -> void
  84. {
  85. M_SetAnimation(self, &tank_move_stand);
  86. }
  87. //
  88. // walk
  89. //
  90. void tank_walk(edict_t *self);
  91. #if 0
  92. mframe_t tank_frames_start_walk[] = {
  93. { ai_walk },
  94. { ai_walk, 6 },
  95. { ai_walk, 6 },
  96. { ai_walk, 11, tank_footstep }
  97. };
  98. MMOVE_T(tank_move_start_walk) = { FRAME_walk01, FRAME_walk04, tank_frames_start_walk, tank_walk };
  99. #endif
  100. mframe_t tank_frames_walk[] = {
  101. { ai_walk, 4 },
  102. { ai_walk, 5 },
  103. { ai_walk, 3 },
  104. { ai_walk, 2 },
  105. { ai_walk, 5 },
  106. { ai_walk, 5 },
  107. { ai_walk, 4 },
  108. { ai_walk, 4, tank_footstep },
  109. { ai_walk, 3 },
  110. { ai_walk, 5 },
  111. { ai_walk, 4 },
  112. { ai_walk, 5 },
  113. { ai_walk, 7 },
  114. { ai_walk, 7 },
  115. { ai_walk, 6 },
  116. { ai_walk, 6, tank_footstep }
  117. };
  118. MMOVE_T(tank_move_walk) = { FRAME_walk05, FRAME_walk20, tank_frames_walk, nullptr };
  119. #if 0
  120. mframe_t tank_frames_stop_walk[] = {
  121. { ai_walk, 3 },
  122. { ai_walk, 3 },
  123. { ai_walk, 2 },
  124. { ai_walk, 2 },
  125. { ai_walk, 4, tank_footstep }
  126. };
  127. MMOVE_T(tank_move_stop_walk) = { FRAME_walk21, FRAME_walk25, tank_frames_stop_walk, tank_stand };
  128. #endif
  129. MONSTERINFO_WALK(tank_walk) (edict_t *self) -> void
  130. {
  131. M_SetAnimation(self, &tank_move_walk);
  132. }
  133. //
  134. // run
  135. //
  136. void tank_run(edict_t *self);
  137. mframe_t tank_frames_start_run[] = {
  138. { ai_run },
  139. { ai_run, 6 },
  140. { ai_run, 6 },
  141. { ai_run, 11, tank_footstep }
  142. };
  143. MMOVE_T(tank_move_start_run) = { FRAME_walk01, FRAME_walk04, tank_frames_start_run, tank_run };
  144. mframe_t tank_frames_run[] = {
  145. { ai_run, 4 },
  146. { ai_run, 5 },
  147. { ai_run, 3 },
  148. { ai_run, 2 },
  149. { ai_run, 5 },
  150. { ai_run, 5 },
  151. { ai_run, 4 },
  152. { ai_run, 4, tank_footstep },
  153. { ai_run, 3 },
  154. { ai_run, 5 },
  155. { ai_run, 4 },
  156. { ai_run, 5 },
  157. { ai_run, 7 },
  158. { ai_run, 7 },
  159. { ai_run, 6 },
  160. { ai_run, 6, tank_footstep }
  161. };
  162. MMOVE_T(tank_move_run) = { FRAME_walk05, FRAME_walk20, tank_frames_run, nullptr };
  163. #if 0
  164. mframe_t tank_frames_stop_run[] = {
  165. { ai_run, 3 },
  166. { ai_run, 3 },
  167. { ai_run, 2 },
  168. { ai_run, 2 },
  169. { ai_run, 4, tank_footstep }
  170. };
  171. MMOVE_T(tank_move_stop_run) = { FRAME_walk21, FRAME_walk25, tank_frames_stop_run, tank_walk };
  172. #endif
  173. MONSTERINFO_RUN(tank_run) (edict_t *self) -> void
  174. {
  175. if (self->enemy && self->enemy->client)
  176. self->monsterinfo.aiflags |= AI_BRUTAL;
  177. else
  178. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  179. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  180. {
  181. M_SetAnimation(self, &tank_move_stand);
  182. return;
  183. }
  184. if (self->monsterinfo.active_move == &tank_move_walk ||
  185. self->monsterinfo.active_move == &tank_move_start_run)
  186. {
  187. M_SetAnimation(self, &tank_move_run);
  188. }
  189. else
  190. {
  191. M_SetAnimation(self, &tank_move_start_run);
  192. }
  193. }
  194. //
  195. // pain
  196. //
  197. mframe_t tank_frames_pain1[] = {
  198. { ai_move },
  199. { ai_move },
  200. { ai_move },
  201. { ai_move }
  202. };
  203. MMOVE_T(tank_move_pain1) = { FRAME_pain101, FRAME_pain104, tank_frames_pain1, tank_run };
  204. mframe_t tank_frames_pain2[] = {
  205. { ai_move },
  206. { ai_move },
  207. { ai_move },
  208. { ai_move },
  209. { ai_move }
  210. };
  211. MMOVE_T(tank_move_pain2) = { FRAME_pain201, FRAME_pain205, tank_frames_pain2, tank_run };
  212. mframe_t tank_frames_pain3[] = {
  213. { ai_move, -7 },
  214. { ai_move },
  215. { ai_move },
  216. { ai_move },
  217. { ai_move, 2 },
  218. { ai_move },
  219. { ai_move },
  220. { ai_move, 3 },
  221. { ai_move },
  222. { ai_move, 2 },
  223. { ai_move },
  224. { ai_move },
  225. { ai_move },
  226. { ai_move },
  227. { ai_move },
  228. { ai_move, 0, tank_footstep }
  229. };
  230. MMOVE_T(tank_move_pain3) = { FRAME_pain301, FRAME_pain316, tank_frames_pain3, tank_run };
  231. PAIN(tank_pain) (edict_t *self, edict_t *other, float kick, int damage, const mod_t &mod) -> void
  232. {
  233. if (mod.id != MOD_CHAINFIST && damage <= 10)
  234. return;
  235. if (level.time < self->pain_debounce_time)
  236. return;
  237. if (mod.id != MOD_CHAINFIST)
  238. {
  239. if (damage <= 30)
  240. if (frandom() > 0.2f)
  241. return;
  242. // don't go into pain while attacking
  243. if ((self->s.frame >= FRAME_attak301) && (self->s.frame <= FRAME_attak330))
  244. return;
  245. if ((self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak116))
  246. return;
  247. }
  248. self->pain_debounce_time = level.time + 3_sec;
  249. if (self->count)
  250. gi.sound(self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  251. else
  252. gi.sound(self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  253. if (!M_ShouldReactToPain(self, mod))
  254. return; // no pain anims in nightmare
  255. // PMM - blindfire cleanup
  256. self->monsterinfo.aiflags &= ~AI_MANUAL_STEERING;
  257. // pmm
  258. if (damage <= 30)
  259. M_SetAnimation(self, &tank_move_pain1);
  260. else if (damage <= 60)
  261. M_SetAnimation(self, &tank_move_pain2);
  262. else
  263. M_SetAnimation(self, &tank_move_pain3);
  264. }
  265. MONSTERINFO_SETSKIN(tank_setskin) (edict_t *self) -> void
  266. {
  267. if (self->health < (self->max_health / 2))
  268. self->s.skinnum |= 1;
  269. else
  270. self->s.skinnum &= ~1;
  271. }
  272. // [Paril-KEX]
  273. bool M_AdjustBlindfireTarget(edict_t *self, const vec3_t &start, const vec3_t &target, const vec3_t &right, vec3_t &out_dir)
  274. {
  275. trace_t trace = gi.traceline(start, target, self, MASK_PROJECTILE);
  276. // blindfire has different fail criteria for the trace
  277. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5f)))
  278. {
  279. out_dir = target - start;
  280. out_dir.normalize();
  281. return true;
  282. }
  283. // try shifting the target to the left a little (to help counter large offset)
  284. vec3_t left_target = target + (right * -20);
  285. trace = gi.traceline(start, left_target, self, MASK_PROJECTILE);
  286. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5f)))
  287. {
  288. out_dir = left_target - start;
  289. out_dir.normalize();
  290. return true;
  291. }
  292. // ok, that failed. try to the right
  293. vec3_t right_target = target + (right * 20);
  294. trace = gi.traceline(start, right_target, self, MASK_PROJECTILE);
  295. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5f)))
  296. {
  297. out_dir = right_target - start;
  298. out_dir.normalize();
  299. return true;
  300. }
  301. return false;
  302. }
  303. //
  304. // attacks
  305. //
  306. void TankBlaster(edict_t *self)
  307. {
  308. vec3_t forward, right;
  309. vec3_t start;
  310. vec3_t dir;
  311. monster_muzzleflash_id_t flash_number;
  312. if (!self->enemy || !self->enemy->inuse) // PGM
  313. return; // PGM
  314. bool blindfire = self->monsterinfo.aiflags & AI_MANUAL_STEERING;
  315. if (self->s.frame == FRAME_attak110)
  316. flash_number = MZ2_TANK_BLASTER_1;
  317. else if (self->s.frame == FRAME_attak113)
  318. flash_number = MZ2_TANK_BLASTER_2;
  319. else // (self->s.frame == FRAME_attak116)
  320. flash_number = MZ2_TANK_BLASTER_3;
  321. AngleVectors(self->s.angles, forward, right, nullptr);
  322. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  323. // pmm - blindfire support
  324. vec3_t target;
  325. // PMM
  326. if (blindfire)
  327. {
  328. target = self->monsterinfo.blind_fire_target;
  329. if (!M_AdjustBlindfireTarget(self, start, target, right, dir))
  330. return;
  331. }
  332. else
  333. PredictAim(self, self->enemy, start, 0, false, 0.f, &dir, nullptr);
  334. // pmm
  335. monster_fire_blaster(self, start, dir, 30, 800, flash_number, EF_BLASTER);
  336. }
  337. void TankStrike(edict_t *self)
  338. {
  339. gi.sound(self, CHAN_WEAPON, sound_strike, 1, ATTN_NORM, 0);
  340. }
  341. void TankRocket(edict_t *self)
  342. {
  343. vec3_t forward, right;
  344. vec3_t start;
  345. vec3_t dir;
  346. vec3_t vec;
  347. monster_muzzleflash_id_t flash_number;
  348. int rocketSpeed; // PGM
  349. // pmm - blindfire support
  350. vec3_t target;
  351. if (!self->enemy || !self->enemy->inuse) // PGM
  352. return; // PGM
  353. bool blindfire = self->monsterinfo.aiflags & AI_MANUAL_STEERING;
  354. if (self->s.frame == FRAME_attak324)
  355. flash_number = MZ2_TANK_ROCKET_1;
  356. else if (self->s.frame == FRAME_attak327)
  357. flash_number = MZ2_TANK_ROCKET_2;
  358. else // (self->s.frame == FRAME_attak330)
  359. flash_number = MZ2_TANK_ROCKET_3;
  360. AngleVectors(self->s.angles, forward, right, nullptr);
  361. // [Paril-KEX] scale
  362. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  363. if (self->speed)
  364. rocketSpeed = self->speed;
  365. else if (self->spawnflags.has(SPAWNFLAG_TANK_COMMANDER_HEAT_SEEKING))
  366. rocketSpeed = 500;
  367. else
  368. rocketSpeed = 650;
  369. // PMM
  370. if (blindfire)
  371. target = self->monsterinfo.blind_fire_target;
  372. else
  373. target = self->enemy->s.origin;
  374. // pmm
  375. // PGM
  376. // PMM - blindfire shooting
  377. if (blindfire)
  378. {
  379. vec = target;
  380. dir = vec - start;
  381. }
  382. // pmm
  383. // don't shoot at feet if they're above me.
  384. else if (frandom() < 0.66f || (start[2] < self->enemy->absmin[2]))
  385. {
  386. vec = self->enemy->s.origin;
  387. vec[2] += self->enemy->viewheight;
  388. dir = vec - start;
  389. }
  390. else
  391. {
  392. vec = self->enemy->s.origin;
  393. vec[2] = self->enemy->absmin[2] + 1;
  394. dir = vec - start;
  395. }
  396. // PGM
  397. //======
  398. // PMM - lead target (not when blindfiring)
  399. // 20, 35, 50, 65 chance of leading
  400. if ((!blindfire) && ((frandom() < (0.2f + ((3 - skill->integer) * 0.15f)))))
  401. PredictAim(self, self->enemy, start, rocketSpeed, false, 0, &dir, &vec);
  402. // PMM - lead target
  403. //======
  404. dir.normalize();
  405. // pmm blindfire doesn't check target (done in checkattack)
  406. // paranoia, make sure we're not shooting a target right next to us
  407. if (blindfire)
  408. {
  409. // blindfire has different fail criteria for the trace
  410. if (M_AdjustBlindfireTarget(self, start, vec, right, dir))
  411. {
  412. if (self->spawnflags.has(SPAWNFLAG_TANK_COMMANDER_HEAT_SEEKING))
  413. monster_fire_heat(self, start, dir, 50, rocketSpeed, flash_number, self->accel);
  414. else
  415. monster_fire_rocket(self, start, dir, 50, rocketSpeed, flash_number);
  416. }
  417. }
  418. else
  419. {
  420. trace_t trace = gi.traceline(start, vec, self, MASK_PROJECTILE);
  421. if (trace.fraction > 0.5f || trace.ent->solid != SOLID_BSP)
  422. {
  423. if (self->spawnflags.has(SPAWNFLAG_TANK_COMMANDER_HEAT_SEEKING))
  424. monster_fire_heat(self, start, dir, 50, rocketSpeed, flash_number, self->accel);
  425. else
  426. monster_fire_rocket(self, start, dir, 50, rocketSpeed, flash_number);
  427. }
  428. }
  429. }
  430. void TankMachineGun(edict_t *self)
  431. {
  432. vec3_t dir;
  433. vec3_t vec;
  434. vec3_t start;
  435. vec3_t forward, right;
  436. monster_muzzleflash_id_t flash_number;
  437. if (!self->enemy || !self->enemy->inuse) // PGM
  438. return; // PGM
  439. flash_number = static_cast<monster_muzzleflash_id_t>(MZ2_TANK_MACHINEGUN_1 + (self->s.frame - FRAME_attak406));
  440. AngleVectors(self->s.angles, forward, right, nullptr);
  441. start = M_ProjectFlashSource(self, monster_flash_offset[flash_number], forward, right);
  442. if (self->enemy)
  443. {
  444. vec = self->enemy->s.origin;
  445. vec[2] += self->enemy->viewheight;
  446. vec -= start;
  447. vec = vectoangles(vec);
  448. dir[0] = vec[0];
  449. }
  450. else
  451. {
  452. dir[0] = 0;
  453. }
  454. if (self->s.frame <= FRAME_attak415)
  455. dir[1] = self->s.angles[1] - 8 * (self->s.frame - FRAME_attak411);
  456. else
  457. dir[1] = self->s.angles[1] + 8 * (self->s.frame - FRAME_attak419);
  458. dir[2] = 0;
  459. AngleVectors(dir, forward, nullptr, nullptr);
  460. monster_fire_bullet(self, start, forward, 20, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
  461. }
  462. static void tank_blind_check(edict_t *self)
  463. {
  464. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  465. {
  466. vec3_t aim = self->monsterinfo.blind_fire_target - self->s.origin;
  467. self->ideal_yaw = vectoyaw(aim);
  468. }
  469. }
  470. mframe_t tank_frames_attack_blast[] = {
  471. { ai_charge },
  472. { ai_charge },
  473. { ai_charge },
  474. { ai_charge },
  475. { ai_charge, -1 },
  476. { ai_charge, -2 },
  477. { ai_charge, -1 },
  478. { ai_charge, -1, tank_blind_check },
  479. { ai_charge },
  480. { ai_charge, 0, TankBlaster }, // 10
  481. { ai_charge },
  482. { ai_charge },
  483. { ai_charge, 0, TankBlaster },
  484. { ai_charge },
  485. { ai_charge },
  486. { ai_charge, 0, TankBlaster } // 16
  487. };
  488. MMOVE_T(tank_move_attack_blast) = { FRAME_attak101, FRAME_attak116, tank_frames_attack_blast, tank_reattack_blaster };
  489. mframe_t tank_frames_reattack_blast[] = {
  490. { ai_charge },
  491. { ai_charge },
  492. { ai_charge, 0, TankBlaster },
  493. { ai_charge },
  494. { ai_charge },
  495. { ai_charge, 0, TankBlaster } // 16
  496. };
  497. MMOVE_T(tank_move_reattack_blast) = { FRAME_attak111, FRAME_attak116, tank_frames_reattack_blast, tank_reattack_blaster };
  498. mframe_t tank_frames_attack_post_blast[] = {
  499. { ai_move }, // 17
  500. { ai_move },
  501. { ai_move, 2 },
  502. { ai_move, 3 },
  503. { ai_move, 2 },
  504. { ai_move, -2, tank_footstep } // 22
  505. };
  506. MMOVE_T(tank_move_attack_post_blast) = { FRAME_attak117, FRAME_attak122, tank_frames_attack_post_blast, tank_run };
  507. void tank_reattack_blaster(edict_t *self)
  508. {
  509. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  510. {
  511. self->monsterinfo.aiflags &= ~AI_MANUAL_STEERING;
  512. M_SetAnimation(self, &tank_move_attack_post_blast);
  513. return;
  514. }
  515. if (visible(self, self->enemy))
  516. if (self->enemy->health > 0)
  517. if (frandom() <= 0.6f)
  518. {
  519. M_SetAnimation(self, &tank_move_reattack_blast);
  520. return;
  521. }
  522. M_SetAnimation(self, &tank_move_attack_post_blast);
  523. }
  524. void tank_poststrike(edict_t *self)
  525. {
  526. self->enemy = nullptr;
  527. // [Paril-KEX]
  528. self->monsterinfo.pausetime = HOLD_FOREVER;
  529. self->monsterinfo.stand(self);
  530. }
  531. mframe_t tank_frames_attack_strike[] = {
  532. { ai_move, 3 },
  533. { ai_move, 2 },
  534. { ai_move, 2 },
  535. { ai_move, 1 },
  536. { ai_move, 6 },
  537. { ai_move, 7 },
  538. { ai_move, 9, tank_footstep },
  539. { ai_move, 2 },
  540. { ai_move, 1 },
  541. { ai_move, 2 },
  542. { ai_move, 2, tank_footstep },
  543. { ai_move, 2 },
  544. { ai_move },
  545. { ai_move },
  546. { ai_move },
  547. { ai_move },
  548. { ai_move, -2 },
  549. { ai_move, -2 },
  550. { ai_move, 0, tank_windup },
  551. { ai_move },
  552. { ai_move },
  553. { ai_move },
  554. { ai_move },
  555. { ai_move },
  556. { ai_move },
  557. { ai_move, 0, TankStrike },
  558. { ai_move },
  559. { ai_move, -1 },
  560. { ai_move, -1 },
  561. { ai_move, -1 },
  562. { ai_move, -1 },
  563. { ai_move, -1 },
  564. { ai_move, -3 },
  565. { ai_move, -10 },
  566. { ai_move, -10 },
  567. { ai_move, -2 },
  568. { ai_move, -3 },
  569. { ai_move, -2, tank_footstep }
  570. };
  571. MMOVE_T(tank_move_attack_strike) = { FRAME_attak201, FRAME_attak238, tank_frames_attack_strike, tank_poststrike };
  572. mframe_t tank_frames_attack_pre_rocket[] = {
  573. { ai_charge },
  574. { ai_charge },
  575. { ai_charge },
  576. { ai_charge },
  577. { ai_charge },
  578. { ai_charge },
  579. { ai_charge },
  580. { ai_charge },
  581. { ai_charge },
  582. { ai_charge }, // 10
  583. { ai_charge },
  584. { ai_charge, 1 },
  585. { ai_charge, 2 },
  586. { ai_charge, 7 },
  587. { ai_charge, 7 },
  588. { ai_charge, 7, tank_footstep },
  589. { ai_charge },
  590. { ai_charge },
  591. { ai_charge },
  592. { ai_charge }, // 20
  593. { ai_charge, -3 }
  594. };
  595. MMOVE_T(tank_move_attack_pre_rocket) = { FRAME_attak301, FRAME_attak321, tank_frames_attack_pre_rocket, tank_doattack_rocket };
  596. mframe_t tank_frames_attack_fire_rocket[] = {
  597. { ai_charge, -3, tank_blind_check }, // Loop Start 22
  598. { ai_charge },
  599. { ai_charge, 0, TankRocket }, // 24
  600. { ai_charge },
  601. { ai_charge },
  602. { ai_charge, 0, TankRocket },
  603. { ai_charge },
  604. { ai_charge },
  605. { ai_charge, -1, TankRocket } // 30 Loop End
  606. };
  607. MMOVE_T(tank_move_attack_fire_rocket) = { FRAME_attak322, FRAME_attak330, tank_frames_attack_fire_rocket, tank_refire_rocket };
  608. mframe_t tank_frames_attack_post_rocket[] = {
  609. { ai_charge }, // 31
  610. { ai_charge, -1 },
  611. { ai_charge, -1 },
  612. { ai_charge },
  613. { ai_charge, 2 },
  614. { ai_charge, 3 },
  615. { ai_charge, 4 },
  616. { ai_charge, 2 },
  617. { ai_charge },
  618. { ai_charge }, // 40
  619. { ai_charge },
  620. { ai_charge, -9 },
  621. { ai_charge, -8 },
  622. { ai_charge, -7 },
  623. { ai_charge, -1 },
  624. { ai_charge, -1, tank_footstep },
  625. { ai_charge },
  626. { ai_charge },
  627. { ai_charge },
  628. { ai_charge }, // 50
  629. { ai_charge },
  630. { ai_charge },
  631. { ai_charge }
  632. };
  633. MMOVE_T(tank_move_attack_post_rocket) = { FRAME_attak331, FRAME_attak353, tank_frames_attack_post_rocket, tank_run };
  634. mframe_t tank_frames_attack_chain[] = {
  635. { ai_charge },
  636. { ai_charge },
  637. { ai_charge },
  638. { ai_charge },
  639. { ai_charge },
  640. { nullptr, 0, TankMachineGun },
  641. { nullptr, 0, TankMachineGun },
  642. { nullptr, 0, TankMachineGun },
  643. { nullptr, 0, TankMachineGun },
  644. { nullptr, 0, TankMachineGun },
  645. { nullptr, 0, TankMachineGun },
  646. { nullptr, 0, TankMachineGun },
  647. { nullptr, 0, TankMachineGun },
  648. { nullptr, 0, TankMachineGun },
  649. { nullptr, 0, TankMachineGun },
  650. { nullptr, 0, TankMachineGun },
  651. { nullptr, 0, TankMachineGun },
  652. { nullptr, 0, TankMachineGun },
  653. { nullptr, 0, TankMachineGun },
  654. { nullptr, 0, TankMachineGun },
  655. { nullptr, 0, TankMachineGun },
  656. { nullptr, 0, TankMachineGun },
  657. { nullptr, 0, TankMachineGun },
  658. { nullptr, 0, TankMachineGun },
  659. { ai_charge },
  660. { ai_charge },
  661. { ai_charge },
  662. { ai_charge },
  663. { ai_charge }
  664. };
  665. MMOVE_T(tank_move_attack_chain) = { FRAME_attak401, FRAME_attak429, tank_frames_attack_chain, tank_run };
  666. void tank_refire_rocket(edict_t *self)
  667. {
  668. // PMM - blindfire cleanup
  669. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  670. {
  671. self->monsterinfo.aiflags &= ~AI_MANUAL_STEERING;
  672. M_SetAnimation(self, &tank_move_attack_post_rocket);
  673. return;
  674. }
  675. // pmm
  676. if (self->enemy->health > 0)
  677. if (visible(self, self->enemy))
  678. if (frandom() <= 0.4f)
  679. {
  680. M_SetAnimation(self, &tank_move_attack_fire_rocket);
  681. return;
  682. }
  683. M_SetAnimation(self, &tank_move_attack_post_rocket);
  684. }
  685. void tank_doattack_rocket(edict_t *self)
  686. {
  687. M_SetAnimation(self, &tank_move_attack_fire_rocket);
  688. }
  689. MONSTERINFO_ATTACK(tank_attack) (edict_t *self) -> void
  690. {
  691. vec3_t vec;
  692. float range;
  693. float r;
  694. // PMM
  695. float chance;
  696. // PMM
  697. if (!self->enemy || !self->enemy->inuse)
  698. return;
  699. if (self->enemy->health <= 0)
  700. {
  701. M_SetAnimation(self, &tank_move_attack_strike);
  702. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  703. return;
  704. }
  705. // PMM
  706. if (self->monsterinfo.attack_state == AS_BLIND)
  707. {
  708. // setup shot probabilities
  709. if (self->monsterinfo.blind_fire_delay < 1_sec)
  710. chance = 1.0f;
  711. else if (self->monsterinfo.blind_fire_delay < 7.5_sec)
  712. chance = 0.4f;
  713. else
  714. chance = 0.1f;
  715. r = frandom();
  716. self->monsterinfo.blind_fire_delay += 5.2_sec + random_time(3_sec);
  717. // don't shoot at the origin
  718. if (!self->monsterinfo.blind_fire_target)
  719. return;
  720. // don't shoot if the dice say not to
  721. if (r > chance)
  722. return;
  723. bool rocket_visible = M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_ROCKET_1]);
  724. bool blaster_visible = M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_BLASTER_1]);
  725. if (!rocket_visible && !blaster_visible)
  726. return;
  727. bool use_rocket = (rocket_visible && blaster_visible) ? brandom() : rocket_visible;
  728. // turn on manual steering to signal both manual steering and blindfire
  729. self->monsterinfo.aiflags |= AI_MANUAL_STEERING;
  730. if (use_rocket)
  731. M_SetAnimation(self, &tank_move_attack_fire_rocket);
  732. else
  733. {
  734. M_SetAnimation(self, &tank_move_attack_blast);
  735. self->monsterinfo.nextframe = FRAME_attak108;
  736. }
  737. self->monsterinfo.attack_finished = level.time + random_time(3_sec, 5_sec);
  738. self->pain_debounce_time = level.time + 5_sec; // no pain for a while
  739. return;
  740. }
  741. // pmm
  742. vec = self->enemy->s.origin - self->s.origin;
  743. range = vec.length();
  744. r = frandom();
  745. if (range <= 125)
  746. {
  747. bool can_machinegun = (!self->enemy->classname || strcmp(self->enemy->classname, "tesla_mine")) && M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_MACHINEGUN_5]);
  748. if (can_machinegun && r < 0.5f)
  749. M_SetAnimation(self, &tank_move_attack_chain);
  750. else if (M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_BLASTER_1]))
  751. M_SetAnimation(self, &tank_move_attack_blast);
  752. }
  753. else if (range <= 250)
  754. {
  755. bool can_machinegun = (!self->enemy->classname || strcmp(self->enemy->classname, "tesla_mine")) && M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_MACHINEGUN_5]);
  756. if (can_machinegun && r < 0.25f)
  757. M_SetAnimation(self, &tank_move_attack_chain);
  758. else if (M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_BLASTER_1]))
  759. M_SetAnimation(self, &tank_move_attack_blast);
  760. }
  761. else
  762. {
  763. bool can_machinegun = M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_MACHINEGUN_5]);
  764. bool can_rocket = M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_ROCKET_1]);
  765. if (can_machinegun && r < 0.33f)
  766. M_SetAnimation(self, &tank_move_attack_chain);
  767. else if (can_rocket && r < 0.66f)
  768. {
  769. M_SetAnimation(self, &tank_move_attack_pre_rocket);
  770. self->pain_debounce_time = level.time + 5_sec; // no pain for a while
  771. }
  772. else if (M_CheckClearShot(self, monster_flash_offset[MZ2_TANK_BLASTER_1]))
  773. M_SetAnimation(self, &tank_move_attack_blast);
  774. }
  775. }
  776. //
  777. // death
  778. //
  779. void tank_dead(edict_t *self)
  780. {
  781. self->mins = { -16, -16, -16 };
  782. self->maxs = { 16, 16, -0 };
  783. monster_dead(self);
  784. }
  785. static void tank_shrink(edict_t *self)
  786. {
  787. self->maxs[2] = 0;
  788. self->svflags |= SVF_DEADMONSTER;
  789. gi.linkentity(self);
  790. }
  791. mframe_t tank_frames_death1[] = {
  792. { ai_move, -7 },
  793. { ai_move, -2 },
  794. { ai_move, -2 },
  795. { ai_move, 1 },
  796. { ai_move, 3 },
  797. { ai_move, 6 },
  798. { ai_move, 1 },
  799. { ai_move, 1 },
  800. { ai_move, 2 },
  801. { ai_move },
  802. { ai_move },
  803. { ai_move },
  804. { ai_move, -2 },
  805. { ai_move },
  806. { ai_move },
  807. { ai_move, -3 },
  808. { ai_move },
  809. { ai_move },
  810. { ai_move },
  811. { ai_move },
  812. { ai_move },
  813. { ai_move },
  814. { ai_move, -4 },
  815. { ai_move, -6 },
  816. { ai_move, -4 },
  817. { ai_move, -5 },
  818. { ai_move, -7, tank_shrink },
  819. { ai_move, -15, tank_thud },
  820. { ai_move, -5 },
  821. { ai_move },
  822. { ai_move },
  823. { ai_move }
  824. };
  825. MMOVE_T(tank_move_death) = { FRAME_death101, FRAME_death132, tank_frames_death1, tank_dead };
  826. DIE(tank_die) (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void
  827. {
  828. // check for gib
  829. if (M_CheckGib(self, mod))
  830. {
  831. gi.sound(self, CHAN_VOICE, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
  832. self->s.skinnum /= 2;
  833. ThrowGibs(self, damage, {
  834. { "models/objects/gibs/sm_meat/tris.md2" },
  835. { 3, "models/objects/gibs/sm_metal/tris.md2", GIB_METALLIC },
  836. { "models/objects/gibs/gear/tris.md2", GIB_METALLIC },
  837. { 2, "models/monsters/tank/gibs/foot.md2", GIB_SKINNED | GIB_METALLIC },
  838. { 2, "models/monsters/tank/gibs/thigh.md2", GIB_SKINNED | GIB_METALLIC },
  839. { "models/monsters/tank/gibs/chest.md2", GIB_SKINNED },
  840. { "models/monsters/tank/gibs/head.md2", GIB_HEAD | GIB_SKINNED }
  841. });
  842. if (!self->style)
  843. ThrowGib(self, "models/monsters/tank/gibs/barm.md2", damage, GIB_SKINNED | GIB_UPRIGHT, self->s.scale);
  844. self->deadflag = true;
  845. return;
  846. }
  847. if (self->deadflag)
  848. return;
  849. // [Paril-KEX] dropped arm
  850. if (!self->style)
  851. {
  852. self->style = 1;
  853. auto [ fwd, rgt, up] = AngleVectors(self->s.angles);
  854. edict_t *arm_gib = ThrowGib(self, "models/monsters/tank/gibs/barm.md2", damage, GIB_SKINNED | GIB_UPRIGHT, self->s.scale);
  855. arm_gib->s.origin = self->s.origin + (rgt * -16.f) + (up * 23.f);
  856. arm_gib->s.old_origin = arm_gib->s.origin;
  857. arm_gib->avelocity = { crandom() * 15.f, crandom() * 15.f, 180.f };
  858. arm_gib->velocity = (up * 100.f) + (rgt * -120.f);
  859. arm_gib->s.angles = self->s.angles;
  860. arm_gib->s.angles[2] = -90.f;
  861. arm_gib->s.skinnum /= 2;
  862. gi.linkentity(arm_gib);
  863. }
  864. // regular death
  865. gi.sound(self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  866. self->deadflag = true;
  867. self->takedamage = true;
  868. M_SetAnimation(self, &tank_move_death);
  869. }
  870. //===========
  871. // PGM
  872. MONSTERINFO_BLOCKED(tank_blocked) (edict_t *self, float dist) -> bool
  873. {
  874. if (blocked_checkplat(self, dist))
  875. return true;
  876. return false;
  877. }
  878. // PGM
  879. //===========
  880. //
  881. // monster_tank
  882. //
  883. /*QUAKED monster_tank (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
  884. model="models/monsters/tank/tris.md2"
  885. */
  886. /*QUAKED monster_tank_commander (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight Guardian HeatSeeking
  887. */
  888. void SP_monster_tank(edict_t *self)
  889. {
  890. if ( !M_AllowSpawn( self ) ) {
  891. G_FreeEdict( self );
  892. return;
  893. }
  894. self->s.modelindex = gi.modelindex("models/monsters/tank/tris.md2");
  895. self->mins = { -32, -32, -16 };
  896. self->maxs = { 32, 32, 64 };
  897. self->movetype = MOVETYPE_STEP;
  898. self->solid = SOLID_BBOX;
  899. gi.modelindex("models/monsters/tank/gibs/barm.md2");
  900. gi.modelindex("models/monsters/tank/gibs/head.md2");
  901. gi.modelindex("models/monsters/tank/gibs/chest.md2");
  902. gi.modelindex("models/monsters/tank/gibs/foot.md2");
  903. gi.modelindex("models/monsters/tank/gibs/thigh.md2");
  904. sound_thud.assign("tank/tnkdeth2.wav");
  905. sound_idle.assign("tank/tnkidle1.wav");
  906. sound_die.assign("tank/death.wav");
  907. sound_step.assign("tank/step.wav");
  908. sound_windup.assign("tank/tnkatck4.wav");
  909. sound_strike.assign("tank/tnkatck5.wav");
  910. sound_sight.assign("tank/sight1.wav");
  911. gi.soundindex("tank/tnkatck1.wav");
  912. gi.soundindex("tank/tnkatk2a.wav");
  913. gi.soundindex("tank/tnkatk2b.wav");
  914. gi.soundindex("tank/tnkatk2c.wav");
  915. gi.soundindex("tank/tnkatk2d.wav");
  916. gi.soundindex("tank/tnkatk2e.wav");
  917. gi.soundindex("tank/tnkatck3.wav");
  918. if (strcmp(self->classname, "monster_tank_commander") == 0)
  919. {
  920. self->health = 1000 * st.health_multiplier;
  921. self->gib_health = -225;
  922. self->count = 1;
  923. sound_pain2.assign("tank/pain.wav");
  924. }
  925. else
  926. {
  927. self->health = 750 * st.health_multiplier;
  928. self->gib_health = -200;
  929. sound_pain.assign("tank/tnkpain2.wav");
  930. }
  931. self->monsterinfo.scale = MODEL_SCALE;
  932. // [Paril-KEX] N64 tank commander is a chonky boy
  933. if (self->spawnflags.has(SPAWNFLAG_TANK_COMMANDER_GUARDIAN))
  934. {
  935. if (!self->s.scale)
  936. self->s.scale = 1.5f;
  937. self->health = 1500 * st.health_multiplier;
  938. }
  939. // heat seekingness
  940. if (!self->accel)
  941. self->accel = 0.075f;
  942. self->mass = 500;
  943. self->pain = tank_pain;
  944. self->die = tank_die;
  945. self->monsterinfo.stand = tank_stand;
  946. self->monsterinfo.walk = tank_walk;
  947. self->monsterinfo.run = tank_run;
  948. self->monsterinfo.dodge = nullptr;
  949. self->monsterinfo.attack = tank_attack;
  950. self->monsterinfo.melee = nullptr;
  951. self->monsterinfo.sight = tank_sight;
  952. self->monsterinfo.idle = tank_idle;
  953. self->monsterinfo.blocked = tank_blocked; // PGM
  954. self->monsterinfo.setskin = tank_setskin;
  955. gi.linkentity(self);
  956. M_SetAnimation(self, &tank_move_stand);
  957. walkmonster_start(self);
  958. // PMM
  959. self->monsterinfo.aiflags |= AI_IGNORE_SHOTS;
  960. self->monsterinfo.blindfire = true;
  961. // pmm
  962. if (strcmp(self->classname, "monster_tank_commander") == 0)
  963. self->s.skinnum = 2;
  964. }
  965. void Use_Boss3(edict_t *ent, edict_t *other, edict_t *activator);
  966. THINK(Think_TankStand) (edict_t *ent) -> void
  967. {
  968. if (ent->s.frame == FRAME_stand30)
  969. ent->s.frame = FRAME_stand01;
  970. else
  971. ent->s.frame++;
  972. ent->nextthink = level.time + 10_hz;
  973. }
  974. /*QUAKED monster_tank_stand (1 .5 0) (-32 -32 0) (32 32 90)
  975. Just stands and cycles in one place until targeted, then teleports away.
  976. N64 edition!
  977. */
  978. void SP_monster_tank_stand(edict_t *self)
  979. {
  980. if( !M_AllowSpawn( self ) ) {
  981. G_FreeEdict( self );
  982. return;
  983. }
  984. self->movetype = MOVETYPE_STEP;
  985. self->solid = SOLID_BBOX;
  986. self->model = "models/monsters/tank/tris.md2";
  987. self->s.modelindex = gi.modelindex(self->model);
  988. self->s.frame = FRAME_stand01;
  989. self->s.skinnum = 2;
  990. gi.soundindex("misc/bigtele.wav");
  991. self->mins = { -32, -32, -16 };
  992. self->maxs = { 32, 32, 64 };
  993. if (!self->s.scale)
  994. self->s.scale = 1.5f;
  995. self->mins *= self->s.scale;
  996. self->maxs *= self->s.scale;
  997. self->use = Use_Boss3;
  998. self->think = Think_TankStand;
  999. self->nextthink = level.time + 10_hz;
  1000. gi.linkentity(self);
  1001. }