m_tank.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. void tank_refire_rocket (edict_t *self);
  11. void tank_doattack_rocket (edict_t *self);
  12. void tank_reattack_blaster (edict_t *self);
  13. static int sound_thud;
  14. static int sound_pain;
  15. static int sound_idle;
  16. static int sound_die;
  17. static int sound_step;
  18. static int sound_sight;
  19. static int sound_windup;
  20. static int sound_strike;
  21. //
  22. // misc
  23. //
  24. void tank_sight (edict_t *self, edict_t *other)
  25. {
  26. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  27. }
  28. void tank_footstep (edict_t *self)
  29. {
  30. gi.sound (self, CHAN_BODY, sound_step, 1, ATTN_NORM, 0);
  31. }
  32. void tank_thud (edict_t *self)
  33. {
  34. gi.sound (self, CHAN_BODY, sound_thud, 1, ATTN_NORM, 0);
  35. }
  36. void tank_windup (edict_t *self)
  37. {
  38. gi.sound (self, CHAN_WEAPON, sound_windup, 1, ATTN_NORM, 0);
  39. }
  40. void tank_idle (edict_t *self)
  41. {
  42. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  43. }
  44. //
  45. // stand
  46. //
  47. mframe_t tank_frames_stand []=
  48. {
  49. ai_stand, 0, NULL,
  50. ai_stand, 0, NULL,
  51. ai_stand, 0, NULL,
  52. ai_stand, 0, NULL,
  53. ai_stand, 0, NULL,
  54. ai_stand, 0, NULL,
  55. ai_stand, 0, NULL,
  56. ai_stand, 0, NULL,
  57. ai_stand, 0, NULL,
  58. ai_stand, 0, NULL,
  59. ai_stand, 0, NULL,
  60. ai_stand, 0, NULL,
  61. ai_stand, 0, NULL,
  62. ai_stand, 0, NULL,
  63. ai_stand, 0, NULL,
  64. ai_stand, 0, NULL,
  65. ai_stand, 0, NULL,
  66. ai_stand, 0, NULL,
  67. ai_stand, 0, NULL,
  68. ai_stand, 0, NULL,
  69. ai_stand, 0, NULL,
  70. ai_stand, 0, NULL,
  71. ai_stand, 0, NULL,
  72. ai_stand, 0, NULL,
  73. ai_stand, 0, NULL,
  74. ai_stand, 0, NULL,
  75. ai_stand, 0, NULL,
  76. ai_stand, 0, NULL,
  77. ai_stand, 0, NULL,
  78. ai_stand, 0, NULL
  79. };
  80. mmove_t tank_move_stand = {FRAME_stand01, FRAME_stand30, tank_frames_stand, NULL};
  81. void tank_stand (edict_t *self)
  82. {
  83. self->monsterinfo.currentmove = &tank_move_stand;
  84. }
  85. //
  86. // walk
  87. //
  88. void tank_walk (edict_t *self);
  89. mframe_t tank_frames_start_walk [] =
  90. {
  91. ai_walk, 0, NULL,
  92. ai_walk, 6, NULL,
  93. ai_walk, 6, NULL,
  94. ai_walk, 11, tank_footstep
  95. };
  96. mmove_t tank_move_start_walk = {FRAME_walk01, FRAME_walk04, tank_frames_start_walk, tank_walk};
  97. mframe_t tank_frames_walk [] =
  98. {
  99. ai_walk, 4, NULL,
  100. ai_walk, 5, NULL,
  101. ai_walk, 3, NULL,
  102. ai_walk, 2, NULL,
  103. ai_walk, 5, NULL,
  104. ai_walk, 5, NULL,
  105. ai_walk, 4, NULL,
  106. ai_walk, 4, tank_footstep,
  107. ai_walk, 3, NULL,
  108. ai_walk, 5, NULL,
  109. ai_walk, 4, NULL,
  110. ai_walk, 5, NULL,
  111. ai_walk, 7, NULL,
  112. ai_walk, 7, NULL,
  113. ai_walk, 6, NULL,
  114. ai_walk, 6, tank_footstep
  115. };
  116. mmove_t tank_move_walk = {FRAME_walk05, FRAME_walk20, tank_frames_walk, NULL};
  117. mframe_t tank_frames_stop_walk [] =
  118. {
  119. ai_walk, 3, NULL,
  120. ai_walk, 3, NULL,
  121. ai_walk, 2, NULL,
  122. ai_walk, 2, NULL,
  123. ai_walk, 4, tank_footstep
  124. };
  125. mmove_t tank_move_stop_walk = {FRAME_walk21, FRAME_walk25, tank_frames_stop_walk, tank_stand};
  126. void tank_walk (edict_t *self)
  127. {
  128. self->monsterinfo.currentmove = &tank_move_walk;
  129. }
  130. //
  131. // run
  132. //
  133. void tank_run (edict_t *self);
  134. mframe_t tank_frames_start_run [] =
  135. {
  136. ai_run, 0, NULL,
  137. ai_run, 6, NULL,
  138. ai_run, 6, NULL,
  139. ai_run, 11, tank_footstep
  140. };
  141. mmove_t tank_move_start_run = {FRAME_walk01, FRAME_walk04, tank_frames_start_run, tank_run};
  142. mframe_t tank_frames_run [] =
  143. {
  144. ai_run, 4, NULL,
  145. ai_run, 5, NULL,
  146. ai_run, 3, NULL,
  147. ai_run, 2, NULL,
  148. ai_run, 5, NULL,
  149. ai_run, 5, NULL,
  150. ai_run, 4, NULL,
  151. ai_run, 4, tank_footstep,
  152. ai_run, 3, NULL,
  153. ai_run, 5, NULL,
  154. ai_run, 4, NULL,
  155. ai_run, 5, NULL,
  156. ai_run, 7, NULL,
  157. ai_run, 7, NULL,
  158. ai_run, 6, NULL,
  159. ai_run, 6, tank_footstep
  160. };
  161. mmove_t tank_move_run = {FRAME_walk05, FRAME_walk20, tank_frames_run, NULL};
  162. mframe_t tank_frames_stop_run [] =
  163. {
  164. ai_run, 3, NULL,
  165. ai_run, 3, NULL,
  166. ai_run, 2, NULL,
  167. ai_run, 2, NULL,
  168. ai_run, 4, tank_footstep
  169. };
  170. mmove_t tank_move_stop_run = {FRAME_walk21, FRAME_walk25, tank_frames_stop_run, tank_walk};
  171. void tank_run (edict_t *self)
  172. {
  173. if (self->enemy && self->enemy->client)
  174. self->monsterinfo.aiflags |= AI_BRUTAL;
  175. else
  176. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  177. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  178. {
  179. self->monsterinfo.currentmove = &tank_move_stand;
  180. return;
  181. }
  182. if (self->monsterinfo.currentmove == &tank_move_walk ||
  183. self->monsterinfo.currentmove == &tank_move_start_run)
  184. {
  185. self->monsterinfo.currentmove = &tank_move_run;
  186. }
  187. else
  188. {
  189. self->monsterinfo.currentmove = &tank_move_start_run;
  190. }
  191. }
  192. //
  193. // pain
  194. //
  195. mframe_t tank_frames_pain1 [] =
  196. {
  197. ai_move, 0, NULL,
  198. ai_move, 0, NULL,
  199. ai_move, 0, NULL,
  200. ai_move, 0, NULL
  201. };
  202. mmove_t tank_move_pain1 = {FRAME_pain101, FRAME_pain104, tank_frames_pain1, tank_run};
  203. mframe_t tank_frames_pain2 [] =
  204. {
  205. ai_move, 0, NULL,
  206. ai_move, 0, NULL,
  207. ai_move, 0, NULL,
  208. ai_move, 0, NULL,
  209. ai_move, 0, NULL
  210. };
  211. mmove_t tank_move_pain2 = {FRAME_pain201, FRAME_pain205, tank_frames_pain2, tank_run};
  212. mframe_t tank_frames_pain3 [] =
  213. {
  214. ai_move, -7, NULL,
  215. ai_move, 0, NULL,
  216. ai_move, 0, NULL,
  217. ai_move, 0, NULL,
  218. ai_move, 2, NULL,
  219. ai_move, 0, NULL,
  220. ai_move, 0, NULL,
  221. ai_move, 3, NULL,
  222. ai_move, 0, NULL,
  223. ai_move, 2, NULL,
  224. ai_move, 0, NULL,
  225. ai_move, 0, NULL,
  226. ai_move, 0, NULL,
  227. ai_move, 0, NULL,
  228. ai_move, 0, NULL,
  229. ai_move, 0, tank_footstep
  230. };
  231. mmove_t tank_move_pain3 = {FRAME_pain301, FRAME_pain316, tank_frames_pain3, tank_run};
  232. void tank_pain (edict_t *self, edict_t *other, float kick, int damage)
  233. {
  234. if (self->health < (self->max_health / 2))
  235. self->s.skinnum |= 1;
  236. if (damage <= 10)
  237. return;
  238. if (level.time < self->pain_debounce_time)
  239. return;
  240. if (damage <= 30)
  241. if (random() > 0.2)
  242. return;
  243. // If hard or nightmare, don't go into pain while attacking
  244. if ( skill->value >= 2)
  245. {
  246. if ( (self->s.frame >= FRAME_attak301) && (self->s.frame <= FRAME_attak330) )
  247. return;
  248. if ( (self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak116) )
  249. return;
  250. }
  251. self->pain_debounce_time = level.time + 3;
  252. gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  253. if (skill->value == 3)
  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. self->monsterinfo.currentmove = &tank_move_pain1;
  260. else if (damage <= 60)
  261. self->monsterinfo.currentmove = &tank_move_pain2;
  262. else
  263. self->monsterinfo.currentmove = &tank_move_pain3;
  264. };
  265. //
  266. // attacks
  267. //
  268. void TankBlaster (edict_t *self)
  269. {
  270. vec3_t forward, right;
  271. vec3_t start;
  272. vec3_t end;
  273. vec3_t dir;
  274. int flash_number;
  275. if(!self->enemy || !self->enemy->inuse) //PGM
  276. return; //PGM
  277. if (self->s.frame == FRAME_attak110)
  278. flash_number = MZ2_TANK_BLASTER_1;
  279. else if (self->s.frame == FRAME_attak113)
  280. flash_number = MZ2_TANK_BLASTER_2;
  281. else // (self->s.frame == FRAME_attak116)
  282. flash_number = MZ2_TANK_BLASTER_3;
  283. AngleVectors (self->s.angles, forward, right, NULL);
  284. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  285. VectorCopy (self->enemy->s.origin, end);
  286. end[2] += self->enemy->viewheight;
  287. VectorSubtract (end, start, dir);
  288. monster_fire_blaster (self, start, dir, 30, 800, flash_number, EF_BLASTER);
  289. }
  290. void TankStrike (edict_t *self)
  291. {
  292. gi.sound (self, CHAN_WEAPON, sound_strike, 1, ATTN_NORM, 0);
  293. }
  294. void TankRocket (edict_t *self)
  295. {
  296. vec3_t forward, right;
  297. vec3_t start;
  298. vec3_t dir;
  299. vec3_t vec;
  300. int flash_number;
  301. trace_t trace; // PGM
  302. int rocketSpeed; // PGM
  303. // pmm - blindfire support
  304. vec3_t target;
  305. qboolean blindfire = false;
  306. if(!self->enemy || !self->enemy->inuse) //PGM
  307. return; //PGM
  308. // pmm - blindfire check
  309. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  310. blindfire = true;
  311. else
  312. blindfire = false;
  313. if (self->s.frame == FRAME_attak324)
  314. flash_number = MZ2_TANK_ROCKET_1;
  315. else if (self->s.frame == FRAME_attak327)
  316. flash_number = MZ2_TANK_ROCKET_2;
  317. else // (self->s.frame == FRAME_attak330)
  318. flash_number = MZ2_TANK_ROCKET_3;
  319. AngleVectors (self->s.angles, forward, right, NULL);
  320. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  321. rocketSpeed = 500 + (100 * skill->value); // PGM rock & roll.... :)
  322. // PMM
  323. if (blindfire)
  324. VectorCopy (self->monsterinfo.blind_fire_target, target);
  325. else
  326. VectorCopy (self->enemy->s.origin, target);
  327. // pmm
  328. // VectorCopy (self->enemy->s.origin, vec);
  329. // vec[2] += self->enemy->viewheight;
  330. // VectorSubtract (vec, start, dir);
  331. //PGM
  332. // PMM - blindfire shooting
  333. if (blindfire)
  334. {
  335. VectorCopy (target, vec);
  336. VectorSubtract (vec, start, dir);
  337. }
  338. // pmm
  339. // don't shoot at feet if they're above me.
  340. else if(random() < 0.66 || (start[2] < self->enemy->absmin[2]))
  341. {
  342. // gi.dprintf("normal shot\n");
  343. VectorCopy (self->enemy->s.origin, vec);
  344. vec[2] += self->enemy->viewheight;
  345. VectorSubtract (vec, start, dir);
  346. }
  347. else
  348. {
  349. // gi.dprintf("shooting at feet!\n");
  350. VectorCopy (self->enemy->s.origin, vec);
  351. vec[2] = self->enemy->absmin[2];
  352. VectorSubtract (vec, start, dir);
  353. }
  354. //PGM
  355. //======
  356. //PMM - lead target (not when blindfiring)
  357. // 20, 35, 50, 65 chance of leading
  358. if((!blindfire) && ((random() < (0.2 + ((3 - skill->value) * 0.15)))))
  359. {
  360. float dist;
  361. float time;
  362. // gi.dprintf ("leading target\n");
  363. dist = VectorLength (dir);
  364. time = dist/rocketSpeed;
  365. VectorMA(vec, time, self->enemy->velocity, vec);
  366. VectorSubtract(vec, start, dir);
  367. }
  368. //PMM - lead target
  369. //======
  370. VectorNormalize (dir);
  371. // gi.WriteByte (svc_temp_entity);
  372. // gi.WriteByte (TE_DEBUGTRAIL);
  373. // gi.WritePosition (start);
  374. // gi.WritePosition (vec);
  375. // gi.multicast (start, MULTICAST_ALL);
  376. // pmm blindfire doesn't check target (done in checkattack)
  377. // paranoia, make sure we're not shooting a target right next to us
  378. trace = gi.trace(start, vec3_origin, vec3_origin, vec, self, MASK_SHOT);
  379. if (blindfire)
  380. {
  381. // blindfire has different fail criteria for the trace
  382. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5)))
  383. monster_fire_rocket (self, start, dir, 50, rocketSpeed, flash_number);
  384. else
  385. {
  386. // try shifting the target to the left a little (to help counter large offset)
  387. VectorCopy (target, vec);
  388. VectorMA (vec, -20, right, vec);
  389. VectorSubtract(vec, start, dir);
  390. VectorNormalize (dir);
  391. trace = gi.trace(start, vec3_origin, vec3_origin, vec, self, MASK_SHOT);
  392. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5)))
  393. monster_fire_rocket (self, start, dir, 50, rocketSpeed, flash_number);
  394. else
  395. {
  396. // ok, that failed. try to the right
  397. VectorCopy (target, vec);
  398. VectorMA (vec, 20, right, vec);
  399. VectorSubtract(vec, start, dir);
  400. VectorNormalize (dir);
  401. trace = gi.trace(start, vec3_origin, vec3_origin, vec, self, MASK_SHOT);
  402. if (!(trace.startsolid || trace.allsolid || (trace.fraction < 0.5)))
  403. monster_fire_rocket (self, start, dir, 50, rocketSpeed, flash_number);
  404. else if ((g_showlogic) && (g_showlogic->value))
  405. // ok, I give up
  406. gi.dprintf ("tank avoiding blindfire shot\n");
  407. }
  408. }
  409. }
  410. else
  411. {
  412. trace = gi.trace(start, vec3_origin, vec3_origin, vec, self, MASK_SHOT);
  413. if(trace.ent == self->enemy || trace.ent == world)
  414. {
  415. if(trace.fraction > 0.5 || (trace.ent && trace.ent->client))
  416. monster_fire_rocket (self, start, dir, 50, rocketSpeed, MZ2_CHICK_ROCKET_1);
  417. // else
  418. // gi.dprintf("didn't make it halfway to target...aborting\n");
  419. }
  420. }
  421. }
  422. void TankMachineGun (edict_t *self)
  423. {
  424. vec3_t dir;
  425. vec3_t vec;
  426. vec3_t start;
  427. vec3_t forward, right;
  428. int flash_number;
  429. if(!self->enemy || !self->enemy->inuse) //PGM
  430. return; //PGM
  431. flash_number = MZ2_TANK_MACHINEGUN_1 + (self->s.frame - FRAME_attak406);
  432. AngleVectors (self->s.angles, forward, right, NULL);
  433. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  434. if (self->enemy)
  435. {
  436. VectorCopy (self->enemy->s.origin, vec);
  437. vec[2] += self->enemy->viewheight;
  438. VectorSubtract (vec, start, vec);
  439. vectoangles (vec, vec);
  440. dir[0] = vec[0];
  441. }
  442. else
  443. {
  444. dir[0] = 0;
  445. }
  446. if (self->s.frame <= FRAME_attak415)
  447. dir[1] = self->s.angles[1] - 8 * (self->s.frame - FRAME_attak411);
  448. else
  449. dir[1] = self->s.angles[1] + 8 * (self->s.frame - FRAME_attak419);
  450. dir[2] = 0;
  451. AngleVectors (dir, forward, NULL, NULL);
  452. monster_fire_bullet (self, start, forward, 20, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
  453. }
  454. mframe_t tank_frames_attack_blast [] =
  455. {
  456. ai_charge, 0, NULL,
  457. ai_charge, 0, NULL,
  458. ai_charge, 0, NULL,
  459. ai_charge, 0, NULL,
  460. ai_charge, -1, NULL,
  461. ai_charge, -2, NULL,
  462. ai_charge, -1, NULL,
  463. ai_charge, -1, NULL,
  464. ai_charge, 0, NULL,
  465. ai_charge, 0, TankBlaster, // 10
  466. ai_charge, 0, NULL,
  467. ai_charge, 0, NULL,
  468. ai_charge, 0, TankBlaster,
  469. ai_charge, 0, NULL,
  470. ai_charge, 0, NULL,
  471. ai_charge, 0, TankBlaster // 16
  472. };
  473. mmove_t tank_move_attack_blast = {FRAME_attak101, FRAME_attak116, tank_frames_attack_blast, tank_reattack_blaster};
  474. mframe_t tank_frames_reattack_blast [] =
  475. {
  476. ai_charge, 0, NULL,
  477. ai_charge, 0, NULL,
  478. ai_charge, 0, TankBlaster,
  479. ai_charge, 0, NULL,
  480. ai_charge, 0, NULL,
  481. ai_charge, 0, TankBlaster // 16
  482. };
  483. mmove_t tank_move_reattack_blast = {FRAME_attak111, FRAME_attak116, tank_frames_reattack_blast, tank_reattack_blaster};
  484. mframe_t tank_frames_attack_post_blast [] =
  485. {
  486. ai_move, 0, NULL, // 17
  487. ai_move, 0, NULL,
  488. ai_move, 2, NULL,
  489. ai_move, 3, NULL,
  490. ai_move, 2, NULL,
  491. ai_move, -2, tank_footstep // 22
  492. };
  493. mmove_t tank_move_attack_post_blast = {FRAME_attak117, FRAME_attak122, tank_frames_attack_post_blast, tank_run};
  494. void tank_reattack_blaster (edict_t *self)
  495. {
  496. if (skill->value >= 2)
  497. if (visible (self, self->enemy))
  498. if (self->enemy->health > 0)
  499. if (random() <= 0.6)
  500. {
  501. self->monsterinfo.currentmove = &tank_move_reattack_blast;
  502. return;
  503. }
  504. self->monsterinfo.currentmove = &tank_move_attack_post_blast;
  505. }
  506. void tank_poststrike (edict_t *self)
  507. {
  508. self->enemy = NULL;
  509. tank_run (self);
  510. }
  511. mframe_t tank_frames_attack_strike [] =
  512. {
  513. ai_move, 3, NULL,
  514. ai_move, 2, NULL,
  515. ai_move, 2, NULL,
  516. ai_move, 1, NULL,
  517. ai_move, 6, NULL,
  518. ai_move, 7, NULL,
  519. ai_move, 9, tank_footstep,
  520. ai_move, 2, NULL,
  521. ai_move, 1, NULL,
  522. ai_move, 2, NULL,
  523. ai_move, 2, tank_footstep,
  524. ai_move, 2, NULL,
  525. ai_move, 0, NULL,
  526. ai_move, 0, NULL,
  527. ai_move, 0, NULL,
  528. ai_move, 0, NULL,
  529. ai_move, -2, NULL,
  530. ai_move, -2, NULL,
  531. ai_move, 0, tank_windup,
  532. ai_move, 0, NULL,
  533. ai_move, 0, NULL,
  534. ai_move, 0, NULL,
  535. ai_move, 0, NULL,
  536. ai_move, 0, NULL,
  537. ai_move, 0, NULL,
  538. ai_move, 0, TankStrike,
  539. ai_move, 0, NULL,
  540. ai_move, -1, NULL,
  541. ai_move, -1, NULL,
  542. ai_move, -1, NULL,
  543. ai_move, -1, NULL,
  544. ai_move, -1, NULL,
  545. ai_move, -3, NULL,
  546. ai_move, -10, NULL,
  547. ai_move, -10, NULL,
  548. ai_move, -2, NULL,
  549. ai_move, -3, NULL,
  550. ai_move, -2, tank_footstep
  551. };
  552. mmove_t tank_move_attack_strike = {FRAME_attak201, FRAME_attak238, tank_frames_attack_strike, tank_poststrike};
  553. mframe_t tank_frames_attack_pre_rocket [] =
  554. {
  555. ai_charge, 0, NULL,
  556. ai_charge, 0, NULL,
  557. ai_charge, 0, NULL,
  558. ai_charge, 0, NULL,
  559. ai_charge, 0, NULL,
  560. ai_charge, 0, NULL,
  561. ai_charge, 0, NULL,
  562. ai_charge, 0, NULL,
  563. ai_charge, 0, NULL,
  564. ai_charge, 0, NULL, // 10
  565. ai_charge, 0, NULL,
  566. ai_charge, 1, NULL,
  567. ai_charge, 2, NULL,
  568. ai_charge, 7, NULL,
  569. ai_charge, 7, NULL,
  570. ai_charge, 7, tank_footstep,
  571. ai_charge, 0, NULL,
  572. ai_charge, 0, NULL,
  573. ai_charge, 0, NULL,
  574. ai_charge, 0, NULL, // 20
  575. ai_charge, -3, NULL
  576. };
  577. mmove_t tank_move_attack_pre_rocket = {FRAME_attak301, FRAME_attak321, tank_frames_attack_pre_rocket, tank_doattack_rocket};
  578. mframe_t tank_frames_attack_fire_rocket [] =
  579. {
  580. ai_charge, -3, NULL, // Loop Start 22
  581. ai_charge, 0, NULL,
  582. ai_charge, 0, TankRocket, // 24
  583. ai_charge, 0, NULL,
  584. ai_charge, 0, NULL,
  585. ai_charge, 0, TankRocket,
  586. ai_charge, 0, NULL,
  587. ai_charge, 0, NULL,
  588. ai_charge, -1, TankRocket // 30 Loop End
  589. };
  590. mmove_t tank_move_attack_fire_rocket = {FRAME_attak322, FRAME_attak330, tank_frames_attack_fire_rocket, tank_refire_rocket};
  591. mframe_t tank_frames_attack_post_rocket [] =
  592. {
  593. ai_charge, 0, NULL, // 31
  594. ai_charge, -1, NULL,
  595. ai_charge, -1, NULL,
  596. ai_charge, 0, NULL,
  597. ai_charge, 2, NULL,
  598. ai_charge, 3, NULL,
  599. ai_charge, 4, NULL,
  600. ai_charge, 2, NULL,
  601. ai_charge, 0, NULL,
  602. ai_charge, 0, NULL, // 40
  603. ai_charge, 0, NULL,
  604. ai_charge, -9, NULL,
  605. ai_charge, -8, NULL,
  606. ai_charge, -7, NULL,
  607. ai_charge, -1, NULL,
  608. ai_charge, -1, tank_footstep,
  609. ai_charge, 0, NULL,
  610. ai_charge, 0, NULL,
  611. ai_charge, 0, NULL,
  612. ai_charge, 0, NULL, // 50
  613. ai_charge, 0, NULL,
  614. ai_charge, 0, NULL,
  615. ai_charge, 0, NULL
  616. };
  617. mmove_t tank_move_attack_post_rocket = {FRAME_attak331, FRAME_attak353, tank_frames_attack_post_rocket, tank_run};
  618. mframe_t tank_frames_attack_chain [] =
  619. {
  620. ai_charge, 0, NULL,
  621. ai_charge, 0, NULL,
  622. ai_charge, 0, NULL,
  623. ai_charge, 0, NULL,
  624. ai_charge, 0, NULL,
  625. NULL, 0, TankMachineGun,
  626. NULL, 0, TankMachineGun,
  627. NULL, 0, TankMachineGun,
  628. NULL, 0, TankMachineGun,
  629. NULL, 0, TankMachineGun,
  630. NULL, 0, TankMachineGun,
  631. NULL, 0, TankMachineGun,
  632. NULL, 0, TankMachineGun,
  633. NULL, 0, TankMachineGun,
  634. NULL, 0, TankMachineGun,
  635. NULL, 0, TankMachineGun,
  636. NULL, 0, TankMachineGun,
  637. NULL, 0, TankMachineGun,
  638. NULL, 0, TankMachineGun,
  639. NULL, 0, TankMachineGun,
  640. NULL, 0, TankMachineGun,
  641. NULL, 0, TankMachineGun,
  642. NULL, 0, TankMachineGun,
  643. NULL, 0, TankMachineGun,
  644. ai_charge, 0, NULL,
  645. ai_charge, 0, NULL,
  646. ai_charge, 0, NULL,
  647. ai_charge, 0, NULL,
  648. ai_charge, 0, NULL
  649. };
  650. mmove_t tank_move_attack_chain = {FRAME_attak401, FRAME_attak429, tank_frames_attack_chain, tank_run};
  651. void tank_refire_rocket (edict_t *self)
  652. {
  653. // PMM - blindfire cleanup
  654. if (self->monsterinfo.aiflags & AI_MANUAL_STEERING)
  655. {
  656. self->monsterinfo.aiflags &= ~AI_MANUAL_STEERING;
  657. self->monsterinfo.currentmove = &tank_move_attack_post_rocket;
  658. return;
  659. }
  660. // pmm
  661. // Only on hard or nightmare
  662. if ( skill->value >= 2 )
  663. if (self->enemy->health > 0)
  664. if (visible(self, self->enemy) )
  665. if (random() <= 0.4)
  666. {
  667. self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
  668. return;
  669. }
  670. self->monsterinfo.currentmove = &tank_move_attack_post_rocket;
  671. }
  672. void tank_doattack_rocket (edict_t *self)
  673. {
  674. self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
  675. }
  676. void tank_attack(edict_t *self)
  677. {
  678. vec3_t vec;
  679. float range;
  680. float r;
  681. // PMM
  682. float chance;
  683. // PMM
  684. if (!self->enemy || !self->enemy->inuse)
  685. return;
  686. if (self->enemy->health < 0)
  687. {
  688. self->monsterinfo.currentmove = &tank_move_attack_strike;
  689. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  690. return;
  691. }
  692. // PMM
  693. if (self->monsterinfo.attack_state == AS_BLIND)
  694. {
  695. // setup shot probabilities
  696. if (self->monsterinfo.blind_fire_delay < 1.0)
  697. chance = 1.0;
  698. else if (self->monsterinfo.blind_fire_delay < 7.5)
  699. chance = 0.4;
  700. else
  701. chance = 0.1;
  702. r = random();
  703. self->monsterinfo.blind_fire_delay += 3.2 + 2.0 + random()*3.0;
  704. // don't shoot at the origin
  705. if (VectorCompare (self->monsterinfo.blind_fire_target, vec3_origin))
  706. return;
  707. // don't shoot if the dice say not to
  708. if (r > chance)
  709. {
  710. // if ((g_showlogic) && (g_showlogic->value))
  711. // gi.dprintf ("blindfire - NO SHOT\n");
  712. return;
  713. }
  714. // turn on manual steering to signal both manual steering and blindfire
  715. self->monsterinfo.aiflags |= AI_MANUAL_STEERING;
  716. self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
  717. self->monsterinfo.attack_finished = level.time + 3.0 + 2*random();
  718. self->pain_debounce_time = level.time + 5.0; // no pain for a while
  719. return;
  720. }
  721. // pmm
  722. VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
  723. range = VectorLength (vec);
  724. r = random();
  725. if (range <= 125)
  726. {
  727. if (r < 0.4)
  728. self->monsterinfo.currentmove = &tank_move_attack_chain;
  729. else
  730. self->monsterinfo.currentmove = &tank_move_attack_blast;
  731. }
  732. else if (range <= 250)
  733. {
  734. if (r < 0.5)
  735. self->monsterinfo.currentmove = &tank_move_attack_chain;
  736. else
  737. self->monsterinfo.currentmove = &tank_move_attack_blast;
  738. }
  739. else
  740. {
  741. if (r < 0.33)
  742. self->monsterinfo.currentmove = &tank_move_attack_chain;
  743. else if (r < 0.66)
  744. {
  745. self->monsterinfo.currentmove = &tank_move_attack_pre_rocket;
  746. self->pain_debounce_time = level.time + 5.0; // no pain for a while
  747. }
  748. else
  749. self->monsterinfo.currentmove = &tank_move_attack_blast;
  750. }
  751. }
  752. //
  753. // death
  754. //
  755. void tank_dead (edict_t *self)
  756. {
  757. VectorSet (self->mins, -16, -16, -16);
  758. VectorSet (self->maxs, 16, 16, -0);
  759. self->movetype = MOVETYPE_TOSS;
  760. self->svflags |= SVF_DEADMONSTER;
  761. self->nextthink = 0;
  762. gi.linkentity (self);
  763. }
  764. mframe_t tank_frames_death1 [] =
  765. {
  766. ai_move, -7, NULL,
  767. ai_move, -2, NULL,
  768. ai_move, -2, NULL,
  769. ai_move, 1, NULL,
  770. ai_move, 3, NULL,
  771. ai_move, 6, NULL,
  772. ai_move, 1, NULL,
  773. ai_move, 1, NULL,
  774. ai_move, 2, NULL,
  775. ai_move, 0, NULL,
  776. ai_move, 0, NULL,
  777. ai_move, 0, NULL,
  778. ai_move, -2, NULL,
  779. ai_move, 0, NULL,
  780. ai_move, 0, NULL,
  781. ai_move, -3, NULL,
  782. ai_move, 0, NULL,
  783. ai_move, 0, NULL,
  784. ai_move, 0, NULL,
  785. ai_move, 0, NULL,
  786. ai_move, 0, NULL,
  787. ai_move, 0, NULL,
  788. ai_move, -4, NULL,
  789. ai_move, -6, NULL,
  790. ai_move, -4, NULL,
  791. ai_move, -5, NULL,
  792. ai_move, -7, NULL,
  793. ai_move, -15, tank_thud,
  794. ai_move, -5, NULL,
  795. ai_move, 0, NULL,
  796. ai_move, 0, NULL,
  797. ai_move, 0, NULL
  798. };
  799. mmove_t tank_move_death = {FRAME_death101, FRAME_death132, tank_frames_death1, tank_dead};
  800. void tank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  801. {
  802. int n;
  803. // check for gib
  804. if (self->health <= self->gib_health)
  805. {
  806. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  807. for (n= 0; n < 1 /*4*/; n++)
  808. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  809. for (n= 0; n < 4; n++)
  810. ThrowGib (self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
  811. ThrowGib (self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
  812. ThrowHead (self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
  813. self->deadflag = DEAD_DEAD;
  814. return;
  815. }
  816. if (self->deadflag == DEAD_DEAD)
  817. return;
  818. // regular death
  819. gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  820. self->deadflag = DEAD_DEAD;
  821. self->takedamage = DAMAGE_YES;
  822. self->monsterinfo.currentmove = &tank_move_death;
  823. }
  824. //===========
  825. //PGM
  826. qboolean tank_blocked (edict_t *self, float dist)
  827. {
  828. if(blocked_checkshot (self, 0.25 + (0.05 * skill->value) ))
  829. return true;
  830. if(blocked_checkplat (self, dist))
  831. return true;
  832. return false;
  833. }
  834. //PGM
  835. //===========
  836. //
  837. // monster_tank
  838. //
  839. /*QUAKED monster_tank (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
  840. */
  841. /*QUAKED monster_tank_commander (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
  842. */
  843. void SP_monster_tank (edict_t *self)
  844. {
  845. if (deathmatch->value)
  846. {
  847. G_FreeEdict (self);
  848. return;
  849. }
  850. self->s.modelindex = gi.modelindex ("models/monsters/tank/tris.md2");
  851. VectorSet (self->mins, -32, -32, -16);
  852. VectorSet (self->maxs, 32, 32, 72);
  853. self->movetype = MOVETYPE_STEP;
  854. self->solid = SOLID_BBOX;
  855. sound_pain = gi.soundindex ("tank/tnkpain2.wav");
  856. sound_thud = gi.soundindex ("tank/tnkdeth2.wav");
  857. sound_idle = gi.soundindex ("tank/tnkidle1.wav");
  858. sound_die = gi.soundindex ("tank/death.wav");
  859. sound_step = gi.soundindex ("tank/step.wav");
  860. sound_windup = gi.soundindex ("tank/tnkatck4.wav");
  861. sound_strike = gi.soundindex ("tank/tnkatck5.wav");
  862. sound_sight = gi.soundindex ("tank/sight1.wav");
  863. gi.soundindex ("tank/tnkatck1.wav");
  864. gi.soundindex ("tank/tnkatk2a.wav");
  865. gi.soundindex ("tank/tnkatk2b.wav");
  866. gi.soundindex ("tank/tnkatk2c.wav");
  867. gi.soundindex ("tank/tnkatk2d.wav");
  868. gi.soundindex ("tank/tnkatk2e.wav");
  869. gi.soundindex ("tank/tnkatck3.wav");
  870. if (strcmp(self->classname, "monster_tank_commander") == 0)
  871. {
  872. self->health = 1000;
  873. self->gib_health = -225;
  874. }
  875. else
  876. {
  877. self->health = 750;
  878. self->gib_health = -200;
  879. }
  880. self->mass = 500;
  881. self->pain = tank_pain;
  882. self->die = tank_die;
  883. self->monsterinfo.stand = tank_stand;
  884. self->monsterinfo.walk = tank_walk;
  885. self->monsterinfo.run = tank_run;
  886. self->monsterinfo.dodge = NULL;
  887. self->monsterinfo.attack = tank_attack;
  888. self->monsterinfo.melee = NULL;
  889. self->monsterinfo.sight = tank_sight;
  890. self->monsterinfo.idle = tank_idle;
  891. self->monsterinfo.blocked = tank_blocked; // PGM
  892. gi.linkentity (self);
  893. self->monsterinfo.currentmove = &tank_move_stand;
  894. self->monsterinfo.scale = MODEL_SCALE;
  895. walkmonster_start(self);
  896. // PMM
  897. self->monsterinfo.aiflags |= AI_IGNORE_SHOTS;
  898. self->monsterinfo.blindfire = true;
  899. //pmm
  900. if (strcmp(self->classname, "monster_tank_commander") == 0)
  901. self->s.skinnum = 2;
  902. }