m_mutant.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. mutant
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_mutant.h"
  22. static int sound_swing;
  23. static int sound_hit;
  24. static int sound_hit2;
  25. static int sound_death;
  26. static int sound_idle;
  27. static int sound_pain1;
  28. static int sound_pain2;
  29. static int sound_sight;
  30. static int sound_search;
  31. static int sound_step1;
  32. static int sound_step2;
  33. static int sound_step3;
  34. static int sound_thud;
  35. //
  36. // SOUNDS
  37. //
  38. void mutant_step (edict_t *self)
  39. {
  40. int n;
  41. n = (rand() + 1) % 3;
  42. if (n == 0)
  43. gi.sound (self, CHAN_VOICE, sound_step1, 1, ATTN_NORM, 0);
  44. else if (n == 1)
  45. gi.sound (self, CHAN_VOICE, sound_step2, 1, ATTN_NORM, 0);
  46. else
  47. gi.sound (self, CHAN_VOICE, sound_step3, 1, ATTN_NORM, 0);
  48. }
  49. void mutant_sight (edict_t *self, edict_t *other)
  50. {
  51. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  52. }
  53. void mutant_search (edict_t *self)
  54. {
  55. gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  56. }
  57. void mutant_swing (edict_t *self)
  58. {
  59. gi.sound (self, CHAN_VOICE, sound_swing, 1, ATTN_NORM, 0);
  60. }
  61. //
  62. // STAND
  63. //
  64. mframe_t mutant_frames_stand [] =
  65. {
  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, // 10
  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, // 20
  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. ai_stand, 0, NULL,
  92. ai_stand, 0, NULL,
  93. ai_stand, 0, NULL,
  94. ai_stand, 0, NULL,
  95. ai_stand, 0, NULL, // 30
  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, 0, NULL,
  102. ai_stand, 0, NULL,
  103. ai_stand, 0, NULL,
  104. ai_stand, 0, NULL,
  105. ai_stand, 0, NULL, // 40
  106. ai_stand, 0, NULL,
  107. ai_stand, 0, NULL,
  108. ai_stand, 0, NULL,
  109. ai_stand, 0, NULL,
  110. ai_stand, 0, NULL,
  111. ai_stand, 0, NULL,
  112. ai_stand, 0, NULL,
  113. ai_stand, 0, NULL,
  114. ai_stand, 0, NULL,
  115. ai_stand, 0, NULL, // 50
  116. ai_stand, 0, NULL
  117. };
  118. mmove_t mutant_move_stand = {FRAME_stand101, FRAME_stand151, mutant_frames_stand, NULL};
  119. void mutant_stand (edict_t *self)
  120. {
  121. self->monsterinfo.currentmove = &mutant_move_stand;
  122. }
  123. //
  124. // IDLE
  125. //
  126. void mutant_idle_loop (edict_t *self)
  127. {
  128. if (random() < 0.75)
  129. self->monsterinfo.nextframe = FRAME_stand155;
  130. }
  131. mframe_t mutant_frames_idle [] =
  132. {
  133. ai_stand, 0, NULL,
  134. ai_stand, 0, NULL,
  135. ai_stand, 0, NULL,
  136. ai_stand, 0, NULL, // scratch loop start
  137. ai_stand, 0, NULL,
  138. ai_stand, 0, NULL,
  139. ai_stand, 0, mutant_idle_loop, // scratch loop end
  140. ai_stand, 0, NULL,
  141. ai_stand, 0, NULL,
  142. ai_stand, 0, NULL,
  143. ai_stand, 0, NULL,
  144. ai_stand, 0, NULL,
  145. ai_stand, 0, NULL
  146. };
  147. mmove_t mutant_move_idle = {FRAME_stand152, FRAME_stand164, mutant_frames_idle, mutant_stand};
  148. void mutant_idle (edict_t *self)
  149. {
  150. self->monsterinfo.currentmove = &mutant_move_idle;
  151. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  152. }
  153. //
  154. // WALK
  155. //
  156. void mutant_walk (edict_t *self);
  157. mframe_t mutant_frames_walk [] =
  158. {
  159. ai_walk, 3, NULL,
  160. ai_walk, 1, NULL,
  161. ai_walk, 5, NULL,
  162. ai_walk, 10, NULL,
  163. ai_walk, 13, NULL,
  164. ai_walk, 10, NULL,
  165. ai_walk, 0, NULL,
  166. ai_walk, 5, NULL,
  167. ai_walk, 6, NULL,
  168. ai_walk, 16, NULL,
  169. ai_walk, 15, NULL,
  170. ai_walk, 6, NULL
  171. };
  172. mmove_t mutant_move_walk = {FRAME_walk05, FRAME_walk16, mutant_frames_walk, NULL};
  173. void mutant_walk_loop (edict_t *self)
  174. {
  175. self->monsterinfo.currentmove = &mutant_move_walk;
  176. }
  177. mframe_t mutant_frames_start_walk [] =
  178. {
  179. ai_walk, 5, NULL,
  180. ai_walk, 5, NULL,
  181. ai_walk, -2, NULL,
  182. ai_walk, 1, NULL
  183. };
  184. mmove_t mutant_move_start_walk = {FRAME_walk01, FRAME_walk04, mutant_frames_start_walk, mutant_walk_loop};
  185. void mutant_walk (edict_t *self)
  186. {
  187. self->monsterinfo.currentmove = &mutant_move_start_walk;
  188. }
  189. //
  190. // RUN
  191. //
  192. mframe_t mutant_frames_run [] =
  193. {
  194. ai_run, 40, NULL,
  195. ai_run, 40, mutant_step,
  196. ai_run, 24, NULL,
  197. ai_run, 5, mutant_step,
  198. ai_run, 17, NULL,
  199. ai_run, 10, NULL
  200. };
  201. mmove_t mutant_move_run = {FRAME_run03, FRAME_run08, mutant_frames_run, NULL};
  202. void mutant_run (edict_t *self)
  203. {
  204. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  205. self->monsterinfo.currentmove = &mutant_move_stand;
  206. else
  207. self->monsterinfo.currentmove = &mutant_move_run;
  208. }
  209. //
  210. // MELEE
  211. //
  212. void mutant_hit_left (edict_t *self)
  213. {
  214. vec3_t aim;
  215. VectorSet (aim, MELEE_DISTANCE, self->mins[0], 8);
  216. if (fire_hit (self, aim, (10 + (rand() %5)), 100))
  217. gi.sound (self, CHAN_WEAPON, sound_hit, 1, ATTN_NORM, 0);
  218. else
  219. gi.sound (self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
  220. }
  221. void mutant_hit_right (edict_t *self)
  222. {
  223. vec3_t aim;
  224. VectorSet (aim, MELEE_DISTANCE, self->maxs[0], 8);
  225. if (fire_hit (self, aim, (10 + (rand() %5)), 100))
  226. gi.sound (self, CHAN_WEAPON, sound_hit2, 1, ATTN_NORM, 0);
  227. else
  228. gi.sound (self, CHAN_WEAPON, sound_swing, 1, ATTN_NORM, 0);
  229. }
  230. void mutant_check_refire (edict_t *self)
  231. {
  232. if (!self->enemy || !self->enemy->inuse || self->enemy->health <= 0)
  233. return;
  234. if ( ((skill->value == 3) && (random() < 0.5)) || (range(self, self->enemy) == RANGE_MELEE) )
  235. self->monsterinfo.nextframe = FRAME_attack09;
  236. }
  237. mframe_t mutant_frames_attack [] =
  238. {
  239. ai_charge, 0, NULL,
  240. ai_charge, 0, NULL,
  241. ai_charge, 0, mutant_hit_left,
  242. ai_charge, 0, NULL,
  243. ai_charge, 0, NULL,
  244. ai_charge, 0, mutant_hit_right,
  245. ai_charge, 0, mutant_check_refire
  246. };
  247. mmove_t mutant_move_attack = {FRAME_attack09, FRAME_attack15, mutant_frames_attack, mutant_run};
  248. void mutant_melee (edict_t *self)
  249. {
  250. self->monsterinfo.currentmove = &mutant_move_attack;
  251. }
  252. //
  253. // ATTACK
  254. //
  255. void mutant_jump_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  256. {
  257. if (self->health <= 0)
  258. {
  259. self->touch = NULL;
  260. return;
  261. }
  262. if (other->takedamage)
  263. {
  264. if (VectorLength(self->velocity) > 400)
  265. {
  266. vec3_t point;
  267. vec3_t normal;
  268. int damage;
  269. VectorCopy (self->velocity, normal);
  270. VectorNormalize(normal);
  271. VectorMA (self->s.origin, self->maxs[0], normal, point);
  272. damage = 40 + 10 * random();
  273. T_Damage (other, self, self, self->velocity, point, normal, damage, damage, 0, MOD_UNKNOWN);
  274. }
  275. }
  276. if (!M_CheckBottom (self))
  277. {
  278. if (self->groundentity)
  279. {
  280. self->monsterinfo.nextframe = FRAME_attack02;
  281. self->touch = NULL;
  282. }
  283. return;
  284. }
  285. self->touch = NULL;
  286. }
  287. void mutant_jump_takeoff (edict_t *self)
  288. {
  289. vec3_t forward;
  290. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  291. AngleVectors (self->s.angles, forward, NULL, NULL);
  292. self->s.origin[2] += 1;
  293. VectorScale (forward, 600, self->velocity);
  294. self->velocity[2] = 250;
  295. self->groundentity = NULL;
  296. self->monsterinfo.aiflags |= AI_DUCKED;
  297. self->monsterinfo.attack_finished = level.time + 3;
  298. self->touch = mutant_jump_touch;
  299. }
  300. void mutant_check_landing (edict_t *self)
  301. {
  302. if (self->groundentity)
  303. {
  304. gi.sound (self, CHAN_WEAPON, sound_thud, 1, ATTN_NORM, 0);
  305. self->monsterinfo.attack_finished = 0;
  306. self->monsterinfo.aiflags &= ~AI_DUCKED;
  307. return;
  308. }
  309. if (level.time > self->monsterinfo.attack_finished)
  310. self->monsterinfo.nextframe = FRAME_attack02;
  311. else
  312. self->monsterinfo.nextframe = FRAME_attack05;
  313. }
  314. mframe_t mutant_frames_jump [] =
  315. {
  316. ai_charge, 0, NULL,
  317. ai_charge, 17, NULL,
  318. ai_charge, 15, mutant_jump_takeoff,
  319. ai_charge, 15, NULL,
  320. ai_charge, 15, mutant_check_landing,
  321. ai_charge, 0, NULL,
  322. ai_charge, 3, NULL,
  323. ai_charge, 0, NULL
  324. };
  325. mmove_t mutant_move_jump = {FRAME_attack01, FRAME_attack08, mutant_frames_jump, mutant_run};
  326. void mutant_jump (edict_t *self)
  327. {
  328. self->monsterinfo.currentmove = &mutant_move_jump;
  329. }
  330. //
  331. // CHECKATTACK
  332. //
  333. qboolean mutant_check_melee (edict_t *self)
  334. {
  335. if (range (self, self->enemy) == RANGE_MELEE)
  336. return true;
  337. return false;
  338. }
  339. qboolean mutant_check_jump (edict_t *self)
  340. {
  341. vec3_t v;
  342. float distance;
  343. if (self->absmin[2] > (self->enemy->absmin[2] + 0.75 * self->enemy->size[2]))
  344. return false;
  345. if (self->absmax[2] < (self->enemy->absmin[2] + 0.25 * self->enemy->size[2]))
  346. return false;
  347. v[0] = self->s.origin[0] - self->enemy->s.origin[0];
  348. v[1] = self->s.origin[1] - self->enemy->s.origin[1];
  349. v[2] = 0;
  350. distance = VectorLength(v);
  351. if (distance < 100)
  352. return false;
  353. if (distance > 100)
  354. {
  355. if (random() < 0.9)
  356. return false;
  357. }
  358. return true;
  359. }
  360. qboolean mutant_checkattack (edict_t *self)
  361. {
  362. if (!self->enemy || self->enemy->health <= 0)
  363. return false;
  364. if (mutant_check_melee(self))
  365. {
  366. self->monsterinfo.attack_state = AS_MELEE;
  367. return true;
  368. }
  369. if (mutant_check_jump(self))
  370. {
  371. self->monsterinfo.attack_state = AS_MISSILE;
  372. // FIXME play a jump sound here
  373. return true;
  374. }
  375. return false;
  376. }
  377. //
  378. // PAIN
  379. //
  380. mframe_t mutant_frames_pain1 [] =
  381. {
  382. ai_move, 4, NULL,
  383. ai_move, -3, NULL,
  384. ai_move, -8, NULL,
  385. ai_move, 2, NULL,
  386. ai_move, 5, NULL
  387. };
  388. mmove_t mutant_move_pain1 = {FRAME_pain101, FRAME_pain105, mutant_frames_pain1, mutant_run};
  389. mframe_t mutant_frames_pain2 [] =
  390. {
  391. ai_move, -24,NULL,
  392. ai_move, 11, NULL,
  393. ai_move, 5, NULL,
  394. ai_move, -2, NULL,
  395. ai_move, 6, NULL,
  396. ai_move, 4, NULL
  397. };
  398. mmove_t mutant_move_pain2 = {FRAME_pain201, FRAME_pain206, mutant_frames_pain2, mutant_run};
  399. mframe_t mutant_frames_pain3 [] =
  400. {
  401. ai_move, -22,NULL,
  402. ai_move, 3, NULL,
  403. ai_move, 3, NULL,
  404. ai_move, 2, NULL,
  405. ai_move, 1, NULL,
  406. ai_move, 1, NULL,
  407. ai_move, 6, NULL,
  408. ai_move, 3, NULL,
  409. ai_move, 2, NULL,
  410. ai_move, 0, NULL,
  411. ai_move, 1, NULL
  412. };
  413. mmove_t mutant_move_pain3 = {FRAME_pain301, FRAME_pain311, mutant_frames_pain3, mutant_run};
  414. void mutant_pain (edict_t *self, edict_t *other, float kick, int damage)
  415. {
  416. float r;
  417. if (self->health < (self->max_health / 2))
  418. self->s.skinnum = 1;
  419. if (level.time < self->pain_debounce_time)
  420. return;
  421. self->pain_debounce_time = level.time + 3;
  422. if (skill->value == 3)
  423. return; // no pain anims in nightmare
  424. r = random();
  425. if (r < 0.33)
  426. {
  427. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  428. self->monsterinfo.currentmove = &mutant_move_pain1;
  429. }
  430. else if (r < 0.66)
  431. {
  432. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  433. self->monsterinfo.currentmove = &mutant_move_pain2;
  434. }
  435. else
  436. {
  437. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  438. self->monsterinfo.currentmove = &mutant_move_pain3;
  439. }
  440. }
  441. //
  442. // DEATH
  443. //
  444. void mutant_dead (edict_t *self)
  445. {
  446. VectorSet (self->mins, -16, -16, -24);
  447. VectorSet (self->maxs, 16, 16, -8);
  448. self->movetype = MOVETYPE_TOSS;
  449. self->svflags |= SVF_DEADMONSTER;
  450. gi.linkentity (self);
  451. M_FlyCheck (self);
  452. }
  453. mframe_t mutant_frames_death1 [] =
  454. {
  455. ai_move, 0, NULL,
  456. ai_move, 0, NULL,
  457. ai_move, 0, NULL,
  458. ai_move, 0, NULL,
  459. ai_move, 0, NULL,
  460. ai_move, 0, NULL,
  461. ai_move, 0, NULL,
  462. ai_move, 0, NULL,
  463. ai_move, 0, NULL
  464. };
  465. mmove_t mutant_move_death1 = {FRAME_death101, FRAME_death109, mutant_frames_death1, mutant_dead};
  466. mframe_t mutant_frames_death2 [] =
  467. {
  468. ai_move, 0, NULL,
  469. ai_move, 0, NULL,
  470. ai_move, 0, NULL,
  471. ai_move, 0, NULL,
  472. ai_move, 0, NULL,
  473. ai_move, 0, NULL,
  474. ai_move, 0, NULL,
  475. ai_move, 0, NULL,
  476. ai_move, 0, NULL,
  477. ai_move, 0, NULL
  478. };
  479. mmove_t mutant_move_death2 = {FRAME_death201, FRAME_death210, mutant_frames_death2, mutant_dead};
  480. void mutant_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  481. {
  482. int n;
  483. if (self->health <= self->gib_health)
  484. {
  485. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  486. for (n= 0; n < 2; n++)
  487. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  488. for (n= 0; n < 4; n++)
  489. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  490. ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  491. self->deadflag = DEAD_DEAD;
  492. return;
  493. }
  494. if (self->deadflag == DEAD_DEAD)
  495. return;
  496. gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
  497. self->deadflag = DEAD_DEAD;
  498. self->takedamage = DAMAGE_YES;
  499. self->s.skinnum = 1;
  500. if (random() < 0.5)
  501. self->monsterinfo.currentmove = &mutant_move_death1;
  502. else
  503. self->monsterinfo.currentmove = &mutant_move_death2;
  504. }
  505. //
  506. // SPAWN
  507. //
  508. /*QUAKED monster_mutant (1 .5 0) (-32 -32 -24) (32 32 32) Ambush Trigger_Spawn Sight
  509. */
  510. void SP_monster_mutant (edict_t *self)
  511. {
  512. if (deathmatch->value)
  513. {
  514. G_FreeEdict (self);
  515. return;
  516. }
  517. sound_swing = gi.soundindex ("mutant/mutatck1.wav");
  518. sound_hit = gi.soundindex ("mutant/mutatck2.wav");
  519. sound_hit2 = gi.soundindex ("mutant/mutatck3.wav");
  520. sound_death = gi.soundindex ("mutant/mutdeth1.wav");
  521. sound_idle = gi.soundindex ("mutant/mutidle1.wav");
  522. sound_pain1 = gi.soundindex ("mutant/mutpain1.wav");
  523. sound_pain2 = gi.soundindex ("mutant/mutpain2.wav");
  524. sound_sight = gi.soundindex ("mutant/mutsght1.wav");
  525. sound_search = gi.soundindex ("mutant/mutsrch1.wav");
  526. sound_step1 = gi.soundindex ("mutant/step1.wav");
  527. sound_step2 = gi.soundindex ("mutant/step2.wav");
  528. sound_step3 = gi.soundindex ("mutant/step3.wav");
  529. sound_thud = gi.soundindex ("mutant/thud1.wav");
  530. self->movetype = MOVETYPE_STEP;
  531. self->solid = SOLID_BBOX;
  532. self->s.modelindex = gi.modelindex ("models/monsters/mutant/tris.md2");
  533. VectorSet (self->mins, -32, -32, -24);
  534. VectorSet (self->maxs, 32, 32, 48);
  535. self->health = 300;
  536. self->gib_health = -120;
  537. self->mass = 300;
  538. self->pain = mutant_pain;
  539. self->die = mutant_die;
  540. self->monsterinfo.stand = mutant_stand;
  541. self->monsterinfo.walk = mutant_walk;
  542. self->monsterinfo.run = mutant_run;
  543. self->monsterinfo.dodge = NULL;
  544. self->monsterinfo.attack = mutant_jump;
  545. self->monsterinfo.melee = mutant_melee;
  546. self->monsterinfo.sight = mutant_sight;
  547. self->monsterinfo.search = mutant_search;
  548. self->monsterinfo.idle = mutant_idle;
  549. self->monsterinfo.checkattack = mutant_checkattack;
  550. gi.linkentity (self);
  551. self->monsterinfo.currentmove = &mutant_move_stand;
  552. self->monsterinfo.scale = MODEL_SCALE;
  553. walkmonster_start (self);
  554. }