m_infantry.c 14 KB

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