m_infantry.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. INFANTRY
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_infantry.h"
  22. void InfantryMachineGun (edict_t *self);
  23. static int sound_pain1;
  24. static int sound_pain2;
  25. static int sound_die1;
  26. static int sound_die2;
  27. static int sound_gunshot;
  28. static int sound_weapon_cock;
  29. static int sound_punch_swing;
  30. static int sound_punch_hit;
  31. static int sound_sight;
  32. static int sound_search;
  33. static int sound_idle;
  34. mframe_t infantry_frames_stand [] =
  35. {
  36. ai_stand, 0, NULL,
  37. ai_stand, 0, NULL,
  38. ai_stand, 0, NULL,
  39. ai_stand, 0, NULL,
  40. ai_stand, 0, NULL,
  41. ai_stand, 0, NULL,
  42. ai_stand, 0, NULL,
  43. ai_stand, 0, NULL,
  44. ai_stand, 0, NULL,
  45. ai_stand, 0, NULL,
  46. ai_stand, 0, NULL,
  47. ai_stand, 0, NULL,
  48. ai_stand, 0, NULL,
  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. };
  59. mmove_t infantry_move_stand = {FRAME_stand50, FRAME_stand71, infantry_frames_stand, NULL};
  60. void infantry_stand (edict_t *self)
  61. {
  62. self->monsterinfo.currentmove = &infantry_move_stand;
  63. }
  64. mframe_t infantry_frames_fidget [] =
  65. {
  66. ai_stand, 1, NULL,
  67. ai_stand, 0, NULL,
  68. ai_stand, 1, NULL,
  69. ai_stand, 3, NULL,
  70. ai_stand, 6, NULL,
  71. ai_stand, 3, NULL,
  72. ai_stand, 0, NULL,
  73. ai_stand, 0, NULL,
  74. ai_stand, 0, NULL,
  75. ai_stand, 0, NULL,
  76. ai_stand, 1, NULL,
  77. ai_stand, 0, NULL,
  78. ai_stand, 0, NULL,
  79. ai_stand, 0, NULL,
  80. ai_stand, 0, NULL,
  81. ai_stand, 1, NULL,
  82. ai_stand, 0, NULL,
  83. ai_stand, -1, NULL,
  84. ai_stand, 0, NULL,
  85. ai_stand, 0, NULL,
  86. ai_stand, 1, NULL,
  87. ai_stand, 0, NULL,
  88. ai_stand, -2, NULL,
  89. ai_stand, 1, NULL,
  90. ai_stand, 1, NULL,
  91. ai_stand, 1, NULL,
  92. ai_stand, -1, NULL,
  93. ai_stand, 0, NULL,
  94. ai_stand, 0, NULL,
  95. ai_stand, -1, NULL,
  96. ai_stand, 0, NULL,
  97. ai_stand, 0, NULL,
  98. ai_stand, 0, NULL,
  99. ai_stand, 0, NULL,
  100. ai_stand, 0, NULL,
  101. ai_stand, -1, NULL,
  102. ai_stand, 0, NULL,
  103. ai_stand, 0, NULL,
  104. ai_stand, 1, NULL,
  105. ai_stand, 0, NULL,
  106. ai_stand, 0, NULL,
  107. ai_stand, -1, NULL,
  108. ai_stand, -1, NULL,
  109. ai_stand, 0, NULL,
  110. ai_stand, -3, NULL,
  111. ai_stand, -2, NULL,
  112. ai_stand, -3, NULL,
  113. ai_stand, -3, NULL,
  114. ai_stand, -2, NULL
  115. };
  116. mmove_t infantry_move_fidget = {FRAME_stand01, FRAME_stand49, infantry_frames_fidget, infantry_stand};
  117. void infantry_fidget (edict_t *self)
  118. {
  119. self->monsterinfo.currentmove = &infantry_move_fidget;
  120. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  121. }
  122. mframe_t infantry_frames_walk [] =
  123. {
  124. ai_walk, 5, NULL,
  125. ai_walk, 4, NULL,
  126. ai_walk, 4, NULL,
  127. ai_walk, 5, NULL,
  128. ai_walk, 4, NULL,
  129. ai_walk, 5, NULL,
  130. ai_walk, 6, NULL,
  131. ai_walk, 4, NULL,
  132. ai_walk, 4, NULL,
  133. ai_walk, 4, NULL,
  134. ai_walk, 4, NULL,
  135. ai_walk, 5, NULL
  136. };
  137. mmove_t infantry_move_walk = {FRAME_walk03, FRAME_walk14, infantry_frames_walk, NULL};
  138. void infantry_walk (edict_t *self)
  139. {
  140. self->monsterinfo.currentmove = &infantry_move_walk;
  141. }
  142. mframe_t infantry_frames_run [] =
  143. {
  144. ai_run, 10, NULL,
  145. ai_run, 20, NULL,
  146. ai_run, 5, NULL,
  147. ai_run, 7, NULL,
  148. ai_run, 30, NULL,
  149. ai_run, 35, NULL,
  150. ai_run, 2, NULL,
  151. ai_run, 6, NULL
  152. };
  153. mmove_t infantry_move_run = {FRAME_run01, FRAME_run08, infantry_frames_run, NULL};
  154. void infantry_run (edict_t *self)
  155. {
  156. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  157. self->monsterinfo.currentmove = &infantry_move_stand;
  158. else
  159. self->monsterinfo.currentmove = &infantry_move_run;
  160. }
  161. mframe_t infantry_frames_pain1 [] =
  162. {
  163. ai_move, -3, NULL,
  164. ai_move, -2, NULL,
  165. ai_move, -1, NULL,
  166. ai_move, -2, NULL,
  167. ai_move, -1, NULL,
  168. ai_move, 1, NULL,
  169. ai_move, -1, NULL,
  170. ai_move, 1, NULL,
  171. ai_move, 6, NULL,
  172. ai_move, 2, NULL
  173. };
  174. mmove_t infantry_move_pain1 = {FRAME_pain101, FRAME_pain110, infantry_frames_pain1, infantry_run};
  175. mframe_t infantry_frames_pain2 [] =
  176. {
  177. ai_move, -3, NULL,
  178. ai_move, -3, NULL,
  179. ai_move, 0, NULL,
  180. ai_move, -1, NULL,
  181. ai_move, -2, NULL,
  182. ai_move, 0, NULL,
  183. ai_move, 0, NULL,
  184. ai_move, 2, NULL,
  185. ai_move, 5, NULL,
  186. ai_move, 2, NULL
  187. };
  188. mmove_t infantry_move_pain2 = {FRAME_pain201, FRAME_pain210, infantry_frames_pain2, infantry_run};
  189. void infantry_pain (edict_t *self, edict_t *other, float kick, int damage)
  190. {
  191. int n;
  192. if (self->health < (self->max_health / 2))
  193. self->s.skinnum = 1;
  194. if (level.time < self->pain_debounce_time)
  195. return;
  196. self->pain_debounce_time = level.time + 3;
  197. if (skill->value == 3)
  198. return; // no pain anims in nightmare
  199. n = rand() % 2;
  200. if (n == 0)
  201. {
  202. self->monsterinfo.currentmove = &infantry_move_pain1;
  203. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  204. }
  205. else
  206. {
  207. self->monsterinfo.currentmove = &infantry_move_pain2;
  208. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  209. }
  210. }
  211. vec3_t aimangles[] =
  212. {
  213. 0.0, 5.0, 0.0,
  214. 10.0, 15.0, 0.0,
  215. 20.0, 25.0, 0.0,
  216. 25.0, 35.0, 0.0,
  217. 30.0, 40.0, 0.0,
  218. 30.0, 45.0, 0.0,
  219. 25.0, 50.0, 0.0,
  220. 20.0, 40.0, 0.0,
  221. 15.0, 35.0, 0.0,
  222. 40.0, 35.0, 0.0,
  223. 70.0, 35.0, 0.0,
  224. 90.0, 35.0, 0.0
  225. };
  226. void InfantryMachineGun (edict_t *self)
  227. {
  228. vec3_t start, target;
  229. vec3_t forward, right;
  230. vec3_t vec;
  231. int flash_number;
  232. if (self->s.frame == FRAME_attak111)
  233. {
  234. flash_number = MZ2_INFANTRY_MACHINEGUN_1;
  235. AngleVectors (self->s.angles, forward, right, NULL);
  236. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  237. if (self->enemy)
  238. {
  239. VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
  240. target[2] += self->enemy->viewheight;
  241. VectorSubtract (target, start, forward);
  242. VectorNormalize (forward);
  243. }
  244. else
  245. {
  246. AngleVectors (self->s.angles, forward, right, NULL);
  247. }
  248. }
  249. else
  250. {
  251. flash_number = MZ2_INFANTRY_MACHINEGUN_2 + (self->s.frame - FRAME_death211);
  252. AngleVectors (self->s.angles, forward, right, NULL);
  253. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  254. VectorSubtract (self->s.angles, aimangles[flash_number-MZ2_INFANTRY_MACHINEGUN_2], vec);
  255. AngleVectors (vec, forward, NULL, NULL);
  256. }
  257. monster_fire_bullet (self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, flash_number);
  258. }
  259. void infantry_sight (edict_t *self, edict_t *other)
  260. {
  261. gi.sound (self, CHAN_BODY, sound_sight, 1, ATTN_NORM, 0);
  262. }
  263. void infantry_dead (edict_t *self)
  264. {
  265. VectorSet (self->mins, -16, -16, -24);
  266. VectorSet (self->maxs, 16, 16, -8);
  267. self->movetype = MOVETYPE_TOSS;
  268. self->svflags |= SVF_DEADMONSTER;
  269. gi.linkentity (self);
  270. M_FlyCheck (self);
  271. }
  272. mframe_t infantry_frames_death1 [] =
  273. {
  274. ai_move, -4, NULL,
  275. ai_move, 0, NULL,
  276. ai_move, 0, NULL,
  277. ai_move, -1, NULL,
  278. ai_move, -4, NULL,
  279. ai_move, 0, NULL,
  280. ai_move, 0, NULL,
  281. ai_move, 0, NULL,
  282. ai_move, -1, NULL,
  283. ai_move, 3, NULL,
  284. ai_move, 1, NULL,
  285. ai_move, 1, NULL,
  286. ai_move, -2, NULL,
  287. ai_move, 2, NULL,
  288. ai_move, 2, NULL,
  289. ai_move, 9, NULL,
  290. ai_move, 9, NULL,
  291. ai_move, 5, NULL,
  292. ai_move, -3, NULL,
  293. ai_move, -3, NULL
  294. };
  295. mmove_t infantry_move_death1 = {FRAME_death101, FRAME_death120, infantry_frames_death1, infantry_dead};
  296. // Off with his head
  297. mframe_t infantry_frames_death2 [] =
  298. {
  299. ai_move, 0, NULL,
  300. ai_move, 1, NULL,
  301. ai_move, 5, NULL,
  302. ai_move, -1, NULL,
  303. ai_move, 0, NULL,
  304. ai_move, 1, NULL,
  305. ai_move, 1, NULL,
  306. ai_move, 4, NULL,
  307. ai_move, 3, NULL,
  308. ai_move, 0, NULL,
  309. ai_move, -2, InfantryMachineGun,
  310. ai_move, -2, InfantryMachineGun,
  311. ai_move, -3, InfantryMachineGun,
  312. ai_move, -1, InfantryMachineGun,
  313. ai_move, -2, InfantryMachineGun,
  314. ai_move, 0, InfantryMachineGun,
  315. ai_move, 2, InfantryMachineGun,
  316. ai_move, 2, InfantryMachineGun,
  317. ai_move, 3, InfantryMachineGun,
  318. ai_move, -10, InfantryMachineGun,
  319. ai_move, -7, InfantryMachineGun,
  320. ai_move, -8, InfantryMachineGun,
  321. ai_move, -6, NULL,
  322. ai_move, 4, NULL,
  323. ai_move, 0, NULL
  324. };
  325. mmove_t infantry_move_death2 = {FRAME_death201, FRAME_death225, infantry_frames_death2, infantry_dead};
  326. mframe_t infantry_frames_death3 [] =
  327. {
  328. ai_move, 0, NULL,
  329. ai_move, 0, NULL,
  330. ai_move, 0, NULL,
  331. ai_move, -6, NULL,
  332. ai_move, -11, NULL,
  333. ai_move, -3, NULL,
  334. ai_move, -11, NULL,
  335. ai_move, 0, NULL,
  336. ai_move, 0, NULL
  337. };
  338. mmove_t infantry_move_death3 = {FRAME_death301, FRAME_death309, infantry_frames_death3, infantry_dead};
  339. void infantry_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  340. {
  341. int n;
  342. // check for gib
  343. if (self->health <= self->gib_health)
  344. {
  345. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  346. for (n= 0; n < 2; n++)
  347. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  348. for (n= 0; n < 4; n++)
  349. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  350. ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  351. self->deadflag = DEAD_DEAD;
  352. return;
  353. }
  354. if (self->deadflag == DEAD_DEAD)
  355. return;
  356. // regular death
  357. self->deadflag = DEAD_DEAD;
  358. self->takedamage = DAMAGE_YES;
  359. n = rand() % 3;
  360. if (n == 0)
  361. {
  362. self->monsterinfo.currentmove = &infantry_move_death1;
  363. gi.sound (self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
  364. }
  365. else if (n == 1)
  366. {
  367. self->monsterinfo.currentmove = &infantry_move_death2;
  368. gi.sound (self, CHAN_VOICE, sound_die1, 1, ATTN_NORM, 0);
  369. }
  370. else
  371. {
  372. self->monsterinfo.currentmove = &infantry_move_death3;
  373. gi.sound (self, CHAN_VOICE, sound_die2, 1, ATTN_NORM, 0);
  374. }
  375. }
  376. void infantry_duck_down (edict_t *self)
  377. {
  378. if (self->monsterinfo.aiflags & AI_DUCKED)
  379. return;
  380. self->monsterinfo.aiflags |= AI_DUCKED;
  381. self->maxs[2] -= 32;
  382. self->takedamage = DAMAGE_YES;
  383. self->monsterinfo.pausetime = level.time + 1;
  384. gi.linkentity (self);
  385. }
  386. void infantry_duck_hold (edict_t *self)
  387. {
  388. if (level.time >= self->monsterinfo.pausetime)
  389. self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
  390. else
  391. self->monsterinfo.aiflags |= AI_HOLD_FRAME;
  392. }
  393. void infantry_duck_up (edict_t *self)
  394. {
  395. self->monsterinfo.aiflags &= ~AI_DUCKED;
  396. self->maxs[2] += 32;
  397. self->takedamage = DAMAGE_AIM;
  398. gi.linkentity (self);
  399. }
  400. mframe_t infantry_frames_duck [] =
  401. {
  402. ai_move, -2, infantry_duck_down,
  403. ai_move, -5, infantry_duck_hold,
  404. ai_move, 3, NULL,
  405. ai_move, 4, infantry_duck_up,
  406. ai_move, 0, NULL
  407. };
  408. mmove_t infantry_move_duck = {FRAME_duck01, FRAME_duck05, infantry_frames_duck, infantry_run};
  409. void infantry_dodge (edict_t *self, edict_t *attacker, float eta)
  410. {
  411. if (random() > 0.25)
  412. return;
  413. if (!self->enemy)
  414. self->enemy = attacker;
  415. self->monsterinfo.currentmove = &infantry_move_duck;
  416. }
  417. void infantry_cock_gun (edict_t *self)
  418. {
  419. int n;
  420. gi.sound (self, CHAN_WEAPON, sound_weapon_cock, 1, ATTN_NORM, 0);
  421. n = (rand() & 15) + 3 + 7;
  422. self->monsterinfo.pausetime = level.time + n * FRAMETIME;
  423. }
  424. void infantry_fire (edict_t *self)
  425. {
  426. InfantryMachineGun (self);
  427. if (level.time >= self->monsterinfo.pausetime)
  428. self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
  429. else
  430. self->monsterinfo.aiflags |= AI_HOLD_FRAME;
  431. }
  432. mframe_t infantry_frames_attack1 [] =
  433. {
  434. ai_charge, 4, NULL,
  435. ai_charge, -1, NULL,
  436. ai_charge, -1, NULL,
  437. ai_charge, 0, infantry_cock_gun,
  438. ai_charge, -1, NULL,
  439. ai_charge, 1, NULL,
  440. ai_charge, 1, NULL,
  441. ai_charge, 2, NULL,
  442. ai_charge, -2, NULL,
  443. ai_charge, -3, NULL,
  444. ai_charge, 1, infantry_fire,
  445. ai_charge, 5, NULL,
  446. ai_charge, -1, NULL,
  447. ai_charge, -2, NULL,
  448. ai_charge, -3, NULL
  449. };
  450. mmove_t infantry_move_attack1 = {FRAME_attak101, FRAME_attak115, infantry_frames_attack1, infantry_run};
  451. void infantry_swing (edict_t *self)
  452. {
  453. gi.sound (self, CHAN_WEAPON, sound_punch_swing, 1, ATTN_NORM, 0);
  454. }
  455. void infantry_smack (edict_t *self)
  456. {
  457. vec3_t aim;
  458. VectorSet (aim, MELEE_DISTANCE, 0, 0);
  459. if (fire_hit (self, aim, (5 + (rand() % 5)), 50))
  460. gi.sound (self, CHAN_WEAPON, sound_punch_hit, 1, ATTN_NORM, 0);
  461. }
  462. mframe_t infantry_frames_attack2 [] =
  463. {
  464. ai_charge, 3, NULL,
  465. ai_charge, 6, NULL,
  466. ai_charge, 0, infantry_swing,
  467. ai_charge, 8, NULL,
  468. ai_charge, 5, NULL,
  469. ai_charge, 8, infantry_smack,
  470. ai_charge, 6, NULL,
  471. ai_charge, 3, NULL,
  472. };
  473. mmove_t infantry_move_attack2 = {FRAME_attak201, FRAME_attak208, infantry_frames_attack2, infantry_run};
  474. void infantry_attack(edict_t *self)
  475. {
  476. if (range (self, self->enemy) == RANGE_MELEE)
  477. self->monsterinfo.currentmove = &infantry_move_attack2;
  478. else
  479. self->monsterinfo.currentmove = &infantry_move_attack1;
  480. }
  481. /*QUAKED monster_infantry (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  482. */
  483. void SP_monster_infantry (edict_t *self)
  484. {
  485. if (deathmatch->value)
  486. {
  487. G_FreeEdict (self);
  488. return;
  489. }
  490. sound_pain1 = gi.soundindex ("infantry/infpain1.wav");
  491. sound_pain2 = gi.soundindex ("infantry/infpain2.wav");
  492. sound_die1 = gi.soundindex ("infantry/infdeth1.wav");
  493. sound_die2 = gi.soundindex ("infantry/infdeth2.wav");
  494. sound_gunshot = gi.soundindex ("infantry/infatck1.wav");
  495. sound_weapon_cock = gi.soundindex ("infantry/infatck3.wav");
  496. sound_punch_swing = gi.soundindex ("infantry/infatck2.wav");
  497. sound_punch_hit = gi.soundindex ("infantry/melee2.wav");
  498. sound_sight = gi.soundindex ("infantry/infsght1.wav");
  499. sound_search = gi.soundindex ("infantry/infsrch1.wav");
  500. sound_idle = gi.soundindex ("infantry/infidle1.wav");
  501. self->movetype = MOVETYPE_STEP;
  502. self->solid = SOLID_BBOX;
  503. self->s.modelindex = gi.modelindex("models/monsters/infantry/tris.md2");
  504. VectorSet (self->mins, -16, -16, -24);
  505. VectorSet (self->maxs, 16, 16, 32);
  506. self->health = 100;
  507. self->gib_health = -40;
  508. self->mass = 200;
  509. self->pain = infantry_pain;
  510. self->die = infantry_die;
  511. self->monsterinfo.stand = infantry_stand;
  512. self->monsterinfo.walk = infantry_walk;
  513. self->monsterinfo.run = infantry_run;
  514. self->monsterinfo.dodge = infantry_dodge;
  515. self->monsterinfo.attack = infantry_attack;
  516. self->monsterinfo.melee = NULL;
  517. self->monsterinfo.sight = infantry_sight;
  518. self->monsterinfo.idle = infantry_fidget;
  519. gi.linkentity (self);
  520. self->monsterinfo.currentmove = &infantry_move_stand;
  521. self->monsterinfo.scale = MODEL_SCALE;
  522. walkmonster_start (self);
  523. }