m_tank.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /*
  16. ==============================================================================
  17. TANK
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_tank.h"
  22. void tank_refire_rocket (edict_t *self);
  23. void tank_doattack_rocket (edict_t *self);
  24. void tank_reattack_blaster (edict_t *self);
  25. static int sound_thud;
  26. static int sound_pain;
  27. static int sound_idle;
  28. static int sound_die;
  29. static int sound_step;
  30. static int sound_sight;
  31. static int sound_windup;
  32. static int sound_strike;
  33. //
  34. // misc
  35. //
  36. void tank_sight (edict_t *self, edict_t *other)
  37. {
  38. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  39. }
  40. void tank_footstep (edict_t *self)
  41. {
  42. gi.sound (self, CHAN_BODY, sound_step, 1, ATTN_NORM, 0);
  43. }
  44. void tank_thud (edict_t *self)
  45. {
  46. gi.sound (self, CHAN_BODY, sound_thud, 1, ATTN_NORM, 0);
  47. }
  48. void tank_windup (edict_t *self)
  49. {
  50. gi.sound (self, CHAN_WEAPON, sound_windup, 1, ATTN_NORM, 0);
  51. }
  52. void tank_idle (edict_t *self)
  53. {
  54. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  55. }
  56. //
  57. // stand
  58. //
  59. mframe_t tank_frames_stand []=
  60. {
  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. ai_stand, 0, NULL,
  80. ai_stand, 0, NULL,
  81. ai_stand, 0, NULL,
  82. ai_stand, 0, NULL,
  83. ai_stand, 0, NULL,
  84. ai_stand, 0, NULL,
  85. ai_stand, 0, NULL,
  86. ai_stand, 0, NULL,
  87. ai_stand, 0, NULL,
  88. ai_stand, 0, NULL,
  89. ai_stand, 0, NULL,
  90. ai_stand, 0, NULL
  91. };
  92. mmove_t tank_move_stand = {FRAME_stand01, FRAME_stand30, tank_frames_stand, NULL};
  93. void tank_stand (edict_t *self)
  94. {
  95. self->monsterinfo.currentmove = &tank_move_stand;
  96. }
  97. //
  98. // walk
  99. //
  100. void tank_walk (edict_t *self);
  101. mframe_t tank_frames_start_walk [] =
  102. {
  103. ai_walk, 0, NULL,
  104. ai_walk, 6, NULL,
  105. ai_walk, 6, NULL,
  106. ai_walk, 11, tank_footstep
  107. };
  108. mmove_t tank_move_start_walk = {FRAME_walk01, FRAME_walk04, tank_frames_start_walk, tank_walk};
  109. mframe_t tank_frames_walk [] =
  110. {
  111. ai_walk, 4, NULL,
  112. ai_walk, 5, NULL,
  113. ai_walk, 3, NULL,
  114. ai_walk, 2, NULL,
  115. ai_walk, 5, NULL,
  116. ai_walk, 5, NULL,
  117. ai_walk, 4, NULL,
  118. ai_walk, 4, tank_footstep,
  119. ai_walk, 3, NULL,
  120. ai_walk, 5, NULL,
  121. ai_walk, 4, NULL,
  122. ai_walk, 5, NULL,
  123. ai_walk, 7, NULL,
  124. ai_walk, 7, NULL,
  125. ai_walk, 6, NULL,
  126. ai_walk, 6, tank_footstep
  127. };
  128. mmove_t tank_move_walk = {FRAME_walk05, FRAME_walk20, tank_frames_walk, NULL};
  129. mframe_t tank_frames_stop_walk [] =
  130. {
  131. ai_walk, 3, NULL,
  132. ai_walk, 3, NULL,
  133. ai_walk, 2, NULL,
  134. ai_walk, 2, NULL,
  135. ai_walk, 4, tank_footstep
  136. };
  137. mmove_t tank_move_stop_walk = {FRAME_walk21, FRAME_walk25, tank_frames_stop_walk, tank_stand};
  138. void tank_walk (edict_t *self)
  139. {
  140. self->monsterinfo.currentmove = &tank_move_walk;
  141. }
  142. //
  143. // run
  144. //
  145. void tank_run (edict_t *self);
  146. mframe_t tank_frames_start_run [] =
  147. {
  148. ai_run, 0, NULL,
  149. ai_run, 6, NULL,
  150. ai_run, 6, NULL,
  151. ai_run, 11, tank_footstep
  152. };
  153. mmove_t tank_move_start_run = {FRAME_walk01, FRAME_walk04, tank_frames_start_run, tank_run};
  154. mframe_t tank_frames_run [] =
  155. {
  156. ai_run, 4, NULL,
  157. ai_run, 5, NULL,
  158. ai_run, 3, NULL,
  159. ai_run, 2, NULL,
  160. ai_run, 5, NULL,
  161. ai_run, 5, NULL,
  162. ai_run, 4, NULL,
  163. ai_run, 4, tank_footstep,
  164. ai_run, 3, NULL,
  165. ai_run, 5, NULL,
  166. ai_run, 4, NULL,
  167. ai_run, 5, NULL,
  168. ai_run, 7, NULL,
  169. ai_run, 7, NULL,
  170. ai_run, 6, NULL,
  171. ai_run, 6, tank_footstep
  172. };
  173. mmove_t tank_move_run = {FRAME_walk05, FRAME_walk20, tank_frames_run, NULL};
  174. mframe_t tank_frames_stop_run [] =
  175. {
  176. ai_run, 3, NULL,
  177. ai_run, 3, NULL,
  178. ai_run, 2, NULL,
  179. ai_run, 2, NULL,
  180. ai_run, 4, tank_footstep
  181. };
  182. mmove_t tank_move_stop_run = {FRAME_walk21, FRAME_walk25, tank_frames_stop_run, tank_walk};
  183. void tank_run (edict_t *self)
  184. {
  185. if (self->enemy && self->enemy->client)
  186. self->monsterinfo.aiflags |= AI_BRUTAL;
  187. else
  188. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  189. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  190. {
  191. self->monsterinfo.currentmove = &tank_move_stand;
  192. return;
  193. }
  194. if (self->monsterinfo.currentmove == &tank_move_walk ||
  195. self->monsterinfo.currentmove == &tank_move_start_run)
  196. {
  197. self->monsterinfo.currentmove = &tank_move_run;
  198. }
  199. else
  200. {
  201. self->monsterinfo.currentmove = &tank_move_start_run;
  202. }
  203. }
  204. //
  205. // pain
  206. //
  207. mframe_t tank_frames_pain1 [] =
  208. {
  209. ai_move, 0, NULL,
  210. ai_move, 0, NULL,
  211. ai_move, 0, NULL,
  212. ai_move, 0, NULL
  213. };
  214. mmove_t tank_move_pain1 = {FRAME_pain101, FRAME_pain104, tank_frames_pain1, tank_run};
  215. mframe_t tank_frames_pain2 [] =
  216. {
  217. ai_move, 0, NULL,
  218. ai_move, 0, NULL,
  219. ai_move, 0, NULL,
  220. ai_move, 0, NULL,
  221. ai_move, 0, NULL
  222. };
  223. mmove_t tank_move_pain2 = {FRAME_pain201, FRAME_pain205, tank_frames_pain2, tank_run};
  224. mframe_t tank_frames_pain3 [] =
  225. {
  226. ai_move, -7, NULL,
  227. ai_move, 0, NULL,
  228. ai_move, 0, NULL,
  229. ai_move, 0, NULL,
  230. ai_move, 2, NULL,
  231. ai_move, 0, NULL,
  232. ai_move, 0, NULL,
  233. ai_move, 3, NULL,
  234. ai_move, 0, NULL,
  235. ai_move, 2, NULL,
  236. ai_move, 0, NULL,
  237. ai_move, 0, NULL,
  238. ai_move, 0, NULL,
  239. ai_move, 0, NULL,
  240. ai_move, 0, NULL,
  241. ai_move, 0, tank_footstep
  242. };
  243. mmove_t tank_move_pain3 = {FRAME_pain301, FRAME_pain316, tank_frames_pain3, tank_run};
  244. void tank_pain (edict_t *self, edict_t *other, float kick, int damage)
  245. {
  246. if (self->health < (self->max_health / 2))
  247. self->s.skinnum |= 1;
  248. if (damage <= 10)
  249. return;
  250. if (level.time < self->pain_debounce_time)
  251. return;
  252. if (damage <= 30)
  253. if (random() > 0.2)
  254. return;
  255. // If hard or nightmare, don't go into pain while attacking
  256. if ( skill->value >= 2)
  257. {
  258. if ( (self->s.frame >= FRAME_attak301) && (self->s.frame <= FRAME_attak330) )
  259. return;
  260. if ( (self->s.frame >= FRAME_attak101) && (self->s.frame <= FRAME_attak116) )
  261. return;
  262. }
  263. self->pain_debounce_time = level.time + 3;
  264. gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  265. if (skill->value == 3)
  266. return; // no pain anims in nightmare
  267. if (damage <= 30)
  268. self->monsterinfo.currentmove = &tank_move_pain1;
  269. else if (damage <= 60)
  270. self->monsterinfo.currentmove = &tank_move_pain2;
  271. else
  272. self->monsterinfo.currentmove = &tank_move_pain3;
  273. };
  274. //
  275. // attacks
  276. //
  277. void TankBlaster (edict_t *self)
  278. {
  279. vec3_t forward, right;
  280. vec3_t start;
  281. vec3_t end;
  282. vec3_t dir;
  283. int flash_number;
  284. if (self->s.frame == FRAME_attak110)
  285. flash_number = MZ2_TANK_BLASTER_1;
  286. else if (self->s.frame == FRAME_attak113)
  287. flash_number = MZ2_TANK_BLASTER_2;
  288. else // (self->s.frame == FRAME_attak116)
  289. flash_number = MZ2_TANK_BLASTER_3;
  290. AngleVectors (self->s.angles, forward, right, NULL);
  291. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  292. VectorCopy (self->enemy->s.origin, end);
  293. end[2] += self->enemy->viewheight;
  294. VectorSubtract (end, start, dir);
  295. monster_fire_blaster (self, start, dir, 30, 800, flash_number, EF_BLASTER);
  296. }
  297. void TankStrike (edict_t *self)
  298. {
  299. gi.sound (self, CHAN_WEAPON, sound_strike, 1, ATTN_NORM, 0);
  300. }
  301. void TankRocket (edict_t *self)
  302. {
  303. vec3_t forward, right;
  304. vec3_t start;
  305. vec3_t dir;
  306. vec3_t vec;
  307. int flash_number;
  308. if (self->s.frame == FRAME_attak324)
  309. flash_number = MZ2_TANK_ROCKET_1;
  310. else if (self->s.frame == FRAME_attak327)
  311. flash_number = MZ2_TANK_ROCKET_2;
  312. else // (self->s.frame == FRAME_attak330)
  313. flash_number = MZ2_TANK_ROCKET_3;
  314. AngleVectors (self->s.angles, forward, right, NULL);
  315. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  316. VectorCopy (self->enemy->s.origin, vec);
  317. vec[2] += self->enemy->viewheight;
  318. VectorSubtract (vec, start, dir);
  319. VectorNormalize (dir);
  320. monster_fire_rocket (self, start, dir, 50, 550, flash_number);
  321. }
  322. void TankMachineGun (edict_t *self)
  323. {
  324. vec3_t dir;
  325. vec3_t vec;
  326. vec3_t start;
  327. vec3_t forward, right;
  328. int flash_number;
  329. flash_number = MZ2_TANK_MACHINEGUN_1 + (self->s.frame - FRAME_attak406);
  330. AngleVectors (self->s.angles, forward, right, NULL);
  331. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  332. if (self->enemy)
  333. {
  334. VectorCopy (self->enemy->s.origin, vec);
  335. vec[2] += self->enemy->viewheight;
  336. VectorSubtract (vec, start, vec);
  337. vectoangles (vec, vec);
  338. dir[0] = vec[0];
  339. }
  340. else
  341. {
  342. dir[0] = 0;
  343. }
  344. if (self->s.frame <= FRAME_attak415)
  345. dir[1] = self->s.angles[1] - 8 * (self->s.frame - FRAME_attak411);
  346. else
  347. dir[1] = self->s.angles[1] + 8 * (self->s.frame - FRAME_attak419);
  348. dir[2] = 0;
  349. AngleVectors (dir, forward, NULL, NULL);
  350. monster_fire_bullet (self, start, forward, 20, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
  351. }
  352. mframe_t tank_frames_attack_blast [] =
  353. {
  354. ai_charge, 0, NULL,
  355. ai_charge, 0, NULL,
  356. ai_charge, 0, NULL,
  357. ai_charge, 0, NULL,
  358. ai_charge, -1, NULL,
  359. ai_charge, -2, NULL,
  360. ai_charge, -1, NULL,
  361. ai_charge, -1, NULL,
  362. ai_charge, 0, NULL,
  363. ai_charge, 0, TankBlaster, // 10
  364. ai_charge, 0, NULL,
  365. ai_charge, 0, NULL,
  366. ai_charge, 0, TankBlaster,
  367. ai_charge, 0, NULL,
  368. ai_charge, 0, NULL,
  369. ai_charge, 0, TankBlaster // 16
  370. };
  371. mmove_t tank_move_attack_blast = {FRAME_attak101, FRAME_attak116, tank_frames_attack_blast, tank_reattack_blaster};
  372. mframe_t tank_frames_reattack_blast [] =
  373. {
  374. ai_charge, 0, NULL,
  375. ai_charge, 0, NULL,
  376. ai_charge, 0, TankBlaster,
  377. ai_charge, 0, NULL,
  378. ai_charge, 0, NULL,
  379. ai_charge, 0, TankBlaster // 16
  380. };
  381. mmove_t tank_move_reattack_blast = {FRAME_attak111, FRAME_attak116, tank_frames_reattack_blast, tank_reattack_blaster};
  382. mframe_t tank_frames_attack_post_blast [] =
  383. {
  384. ai_move, 0, NULL, // 17
  385. ai_move, 0, NULL,
  386. ai_move, 2, NULL,
  387. ai_move, 3, NULL,
  388. ai_move, 2, NULL,
  389. ai_move, -2, tank_footstep // 22
  390. };
  391. mmove_t tank_move_attack_post_blast = {FRAME_attak117, FRAME_attak122, tank_frames_attack_post_blast, tank_run};
  392. void tank_reattack_blaster (edict_t *self)
  393. {
  394. if (skill->value >= 2)
  395. if (visible (self, self->enemy))
  396. if (self->enemy->health > 0)
  397. if (random() <= 0.6)
  398. {
  399. self->monsterinfo.currentmove = &tank_move_reattack_blast;
  400. return;
  401. }
  402. self->monsterinfo.currentmove = &tank_move_attack_post_blast;
  403. }
  404. void tank_poststrike (edict_t *self)
  405. {
  406. self->enemy = NULL;
  407. tank_run (self);
  408. }
  409. mframe_t tank_frames_attack_strike [] =
  410. {
  411. ai_move, 3, NULL,
  412. ai_move, 2, NULL,
  413. ai_move, 2, NULL,
  414. ai_move, 1, NULL,
  415. ai_move, 6, NULL,
  416. ai_move, 7, NULL,
  417. ai_move, 9, tank_footstep,
  418. ai_move, 2, NULL,
  419. ai_move, 1, NULL,
  420. ai_move, 2, NULL,
  421. ai_move, 2, tank_footstep,
  422. ai_move, 2, NULL,
  423. ai_move, 0, NULL,
  424. ai_move, 0, NULL,
  425. ai_move, 0, NULL,
  426. ai_move, 0, NULL,
  427. ai_move, -2, NULL,
  428. ai_move, -2, NULL,
  429. ai_move, 0, tank_windup,
  430. ai_move, 0, NULL,
  431. ai_move, 0, NULL,
  432. ai_move, 0, NULL,
  433. ai_move, 0, NULL,
  434. ai_move, 0, NULL,
  435. ai_move, 0, NULL,
  436. ai_move, 0, TankStrike,
  437. ai_move, 0, NULL,
  438. ai_move, -1, NULL,
  439. ai_move, -1, NULL,
  440. ai_move, -1, NULL,
  441. ai_move, -1, NULL,
  442. ai_move, -1, NULL,
  443. ai_move, -3, NULL,
  444. ai_move, -10, NULL,
  445. ai_move, -10, NULL,
  446. ai_move, -2, NULL,
  447. ai_move, -3, NULL,
  448. ai_move, -2, tank_footstep
  449. };
  450. mmove_t tank_move_attack_strike = {FRAME_attak201, FRAME_attak238, tank_frames_attack_strike, tank_poststrike};
  451. mframe_t tank_frames_attack_pre_rocket [] =
  452. {
  453. ai_charge, 0, NULL,
  454. ai_charge, 0, NULL,
  455. ai_charge, 0, NULL,
  456. ai_charge, 0, NULL,
  457. ai_charge, 0, NULL,
  458. ai_charge, 0, NULL,
  459. ai_charge, 0, NULL,
  460. ai_charge, 0, NULL,
  461. ai_charge, 0, NULL,
  462. ai_charge, 0, NULL, // 10
  463. ai_charge, 0, NULL,
  464. ai_charge, 1, NULL,
  465. ai_charge, 2, NULL,
  466. ai_charge, 7, NULL,
  467. ai_charge, 7, NULL,
  468. ai_charge, 7, tank_footstep,
  469. ai_charge, 0, NULL,
  470. ai_charge, 0, NULL,
  471. ai_charge, 0, NULL,
  472. ai_charge, 0, NULL, // 20
  473. ai_charge, -3, NULL
  474. };
  475. mmove_t tank_move_attack_pre_rocket = {FRAME_attak301, FRAME_attak321, tank_frames_attack_pre_rocket, tank_doattack_rocket};
  476. mframe_t tank_frames_attack_fire_rocket [] =
  477. {
  478. ai_charge, -3, NULL, // Loop Start 22
  479. ai_charge, 0, NULL,
  480. ai_charge, 0, TankRocket, // 24
  481. ai_charge, 0, NULL,
  482. ai_charge, 0, NULL,
  483. ai_charge, 0, TankRocket,
  484. ai_charge, 0, NULL,
  485. ai_charge, 0, NULL,
  486. ai_charge, -1, TankRocket // 30 Loop End
  487. };
  488. mmove_t tank_move_attack_fire_rocket = {FRAME_attak322, FRAME_attak330, tank_frames_attack_fire_rocket, tank_refire_rocket};
  489. mframe_t tank_frames_attack_post_rocket [] =
  490. {
  491. ai_charge, 0, NULL, // 31
  492. ai_charge, -1, NULL,
  493. ai_charge, -1, NULL,
  494. ai_charge, 0, NULL,
  495. ai_charge, 2, NULL,
  496. ai_charge, 3, NULL,
  497. ai_charge, 4, NULL,
  498. ai_charge, 2, NULL,
  499. ai_charge, 0, NULL,
  500. ai_charge, 0, NULL, // 40
  501. ai_charge, 0, NULL,
  502. ai_charge, -9, NULL,
  503. ai_charge, -8, NULL,
  504. ai_charge, -7, NULL,
  505. ai_charge, -1, NULL,
  506. ai_charge, -1, tank_footstep,
  507. ai_charge, 0, NULL,
  508. ai_charge, 0, NULL,
  509. ai_charge, 0, NULL,
  510. ai_charge, 0, NULL, // 50
  511. ai_charge, 0, NULL,
  512. ai_charge, 0, NULL,
  513. ai_charge, 0, NULL
  514. };
  515. mmove_t tank_move_attack_post_rocket = {FRAME_attak331, FRAME_attak353, tank_frames_attack_post_rocket, tank_run};
  516. mframe_t tank_frames_attack_chain [] =
  517. {
  518. ai_charge, 0, NULL,
  519. ai_charge, 0, NULL,
  520. ai_charge, 0, NULL,
  521. ai_charge, 0, NULL,
  522. ai_charge, 0, NULL,
  523. NULL, 0, TankMachineGun,
  524. NULL, 0, TankMachineGun,
  525. NULL, 0, TankMachineGun,
  526. NULL, 0, TankMachineGun,
  527. NULL, 0, TankMachineGun,
  528. NULL, 0, TankMachineGun,
  529. NULL, 0, TankMachineGun,
  530. NULL, 0, TankMachineGun,
  531. NULL, 0, TankMachineGun,
  532. NULL, 0, TankMachineGun,
  533. NULL, 0, TankMachineGun,
  534. NULL, 0, TankMachineGun,
  535. NULL, 0, TankMachineGun,
  536. NULL, 0, TankMachineGun,
  537. NULL, 0, TankMachineGun,
  538. NULL, 0, TankMachineGun,
  539. NULL, 0, TankMachineGun,
  540. NULL, 0, TankMachineGun,
  541. NULL, 0, TankMachineGun,
  542. ai_charge, 0, NULL,
  543. ai_charge, 0, NULL,
  544. ai_charge, 0, NULL,
  545. ai_charge, 0, NULL,
  546. ai_charge, 0, NULL
  547. };
  548. mmove_t tank_move_attack_chain = {FRAME_attak401, FRAME_attak429, tank_frames_attack_chain, tank_run};
  549. void tank_refire_rocket (edict_t *self)
  550. {
  551. // Only on hard or nightmare
  552. if ( skill->value >= 2 )
  553. if (self->enemy->health > 0)
  554. if (visible(self, self->enemy) )
  555. if (random() <= 0.4)
  556. {
  557. self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
  558. return;
  559. }
  560. self->monsterinfo.currentmove = &tank_move_attack_post_rocket;
  561. }
  562. void tank_doattack_rocket (edict_t *self)
  563. {
  564. self->monsterinfo.currentmove = &tank_move_attack_fire_rocket;
  565. }
  566. void tank_attack(edict_t *self)
  567. {
  568. vec3_t vec;
  569. float range;
  570. float r;
  571. if (self->enemy->health < 0)
  572. {
  573. self->monsterinfo.currentmove = &tank_move_attack_strike;
  574. self->monsterinfo.aiflags &= ~AI_BRUTAL;
  575. return;
  576. }
  577. VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
  578. range = VectorLength (vec);
  579. r = random();
  580. if (range <= 125)
  581. {
  582. if (r < 0.4)
  583. self->monsterinfo.currentmove = &tank_move_attack_chain;
  584. else
  585. self->monsterinfo.currentmove = &tank_move_attack_blast;
  586. }
  587. else if (range <= 250)
  588. {
  589. if (r < 0.5)
  590. self->monsterinfo.currentmove = &tank_move_attack_chain;
  591. else
  592. self->monsterinfo.currentmove = &tank_move_attack_blast;
  593. }
  594. else
  595. {
  596. if (r < 0.33)
  597. self->monsterinfo.currentmove = &tank_move_attack_chain;
  598. else if (r < 0.66)
  599. {
  600. self->monsterinfo.currentmove = &tank_move_attack_pre_rocket;
  601. self->pain_debounce_time = level.time + 5.0; // no pain for a while
  602. }
  603. else
  604. self->monsterinfo.currentmove = &tank_move_attack_blast;
  605. }
  606. }
  607. //
  608. // death
  609. //
  610. void tank_dead (edict_t *self)
  611. {
  612. VectorSet (self->mins, -16, -16, -16);
  613. VectorSet (self->maxs, 16, 16, -0);
  614. self->movetype = MOVETYPE_TOSS;
  615. self->svflags |= SVF_DEADMONSTER;
  616. self->nextthink = 0;
  617. gi.linkentity (self);
  618. }
  619. mframe_t tank_frames_death1 [] =
  620. {
  621. ai_move, -7, NULL,
  622. ai_move, -2, NULL,
  623. ai_move, -2, NULL,
  624. ai_move, 1, NULL,
  625. ai_move, 3, NULL,
  626. ai_move, 6, NULL,
  627. ai_move, 1, NULL,
  628. ai_move, 1, NULL,
  629. ai_move, 2, NULL,
  630. ai_move, 0, NULL,
  631. ai_move, 0, NULL,
  632. ai_move, 0, NULL,
  633. ai_move, -2, NULL,
  634. ai_move, 0, NULL,
  635. ai_move, 0, NULL,
  636. ai_move, -3, NULL,
  637. ai_move, 0, NULL,
  638. ai_move, 0, NULL,
  639. ai_move, 0, NULL,
  640. ai_move, 0, NULL,
  641. ai_move, 0, NULL,
  642. ai_move, 0, NULL,
  643. ai_move, -4, NULL,
  644. ai_move, -6, NULL,
  645. ai_move, -4, NULL,
  646. ai_move, -5, NULL,
  647. ai_move, -7, NULL,
  648. ai_move, -15, tank_thud,
  649. ai_move, -5, NULL,
  650. ai_move, 0, NULL,
  651. ai_move, 0, NULL,
  652. ai_move, 0, NULL
  653. };
  654. mmove_t tank_move_death = {FRAME_death101, FRAME_death132, tank_frames_death1, tank_dead};
  655. void tank_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  656. {
  657. int n;
  658. // check for gib
  659. if (self->health <= self->gib_health)
  660. {
  661. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  662. for (n= 0; n < 1 /*4*/; n++)
  663. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  664. for (n= 0; n < 4; n++)
  665. ThrowGib (self, "models/objects/gibs/sm_metal/tris.md2", damage, GIB_METALLIC);
  666. ThrowGib (self, "models/objects/gibs/chest/tris.md2", damage, GIB_ORGANIC);
  667. ThrowHead (self, "models/objects/gibs/gear/tris.md2", damage, GIB_METALLIC);
  668. self->deadflag = DEAD_DEAD;
  669. return;
  670. }
  671. if (self->deadflag == DEAD_DEAD)
  672. return;
  673. // regular death
  674. gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  675. self->deadflag = DEAD_DEAD;
  676. self->takedamage = DAMAGE_YES;
  677. self->monsterinfo.currentmove = &tank_move_death;
  678. }
  679. //
  680. // monster_tank
  681. //
  682. /*QUAKED monster_tank (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
  683. */
  684. /*QUAKED monster_tank_commander (1 .5 0) (-32 -32 -16) (32 32 72) Ambush Trigger_Spawn Sight
  685. */
  686. void SP_monster_tank (edict_t *self)
  687. {
  688. if (deathmatch->value)
  689. {
  690. G_FreeEdict (self);
  691. return;
  692. }
  693. self->s.modelindex = gi.modelindex ("models/monsters/tank/tris.md2");
  694. VectorSet (self->mins, -32, -32, -16);
  695. VectorSet (self->maxs, 32, 32, 72);
  696. self->movetype = MOVETYPE_STEP;
  697. self->solid = SOLID_BBOX;
  698. sound_pain = gi.soundindex ("tank/tnkpain2.wav");
  699. sound_thud = gi.soundindex ("tank/tnkdeth2.wav");
  700. sound_idle = gi.soundindex ("tank/tnkidle1.wav");
  701. sound_die = gi.soundindex ("tank/death.wav");
  702. sound_step = gi.soundindex ("tank/step.wav");
  703. sound_windup = gi.soundindex ("tank/tnkatck4.wav");
  704. sound_strike = gi.soundindex ("tank/tnkatck5.wav");
  705. sound_sight = gi.soundindex ("tank/sight1.wav");
  706. gi.soundindex ("tank/tnkatck1.wav");
  707. gi.soundindex ("tank/tnkatk2a.wav");
  708. gi.soundindex ("tank/tnkatk2b.wav");
  709. gi.soundindex ("tank/tnkatk2c.wav");
  710. gi.soundindex ("tank/tnkatk2d.wav");
  711. gi.soundindex ("tank/tnkatk2e.wav");
  712. gi.soundindex ("tank/tnkatck3.wav");
  713. if (strcmp(self->classname, "monster_tank_commander") == 0)
  714. {
  715. self->health = 1000;
  716. self->gib_health = -225;
  717. }
  718. else
  719. {
  720. self->health = 750;
  721. self->gib_health = -200;
  722. }
  723. self->mass = 500;
  724. self->pain = tank_pain;
  725. self->die = tank_die;
  726. self->monsterinfo.stand = tank_stand;
  727. self->monsterinfo.walk = tank_walk;
  728. self->monsterinfo.run = tank_run;
  729. self->monsterinfo.dodge = NULL;
  730. self->monsterinfo.attack = tank_attack;
  731. self->monsterinfo.melee = NULL;
  732. self->monsterinfo.sight = tank_sight;
  733. self->monsterinfo.idle = tank_idle;
  734. gi.linkentity (self);
  735. self->monsterinfo.currentmove = &tank_move_stand;
  736. self->monsterinfo.scale = MODEL_SCALE;
  737. walkmonster_start(self);
  738. if (strcmp(self->classname, "monster_tank_commander") == 0)
  739. self->s.skinnum = 2;
  740. }