m_gladiator.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. GLADIATOR
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_gladiator.h"
  22. static int sound_pain1;
  23. static int sound_pain2;
  24. static int sound_die;
  25. static int sound_gun;
  26. static int sound_cleaver_swing;
  27. static int sound_cleaver_hit;
  28. static int sound_cleaver_miss;
  29. static int sound_idle;
  30. static int sound_search;
  31. static int sound_sight;
  32. void gladiator_idle (edict_t *self)
  33. {
  34. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  35. }
  36. void gladiator_sight (edict_t *self, edict_t *other)
  37. {
  38. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  39. }
  40. void gladiator_search (edict_t *self)
  41. {
  42. gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  43. }
  44. void gladiator_cleaver_swing (edict_t *self)
  45. {
  46. gi.sound (self, CHAN_WEAPON, sound_cleaver_swing, 1, ATTN_NORM, 0);
  47. }
  48. mframe_t gladiator_frames_stand [] =
  49. {
  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. };
  58. mmove_t gladiator_move_stand = {FRAME_stand1, FRAME_stand7, gladiator_frames_stand, NULL};
  59. void gladiator_stand (edict_t *self)
  60. {
  61. self->monsterinfo.currentmove = &gladiator_move_stand;
  62. }
  63. mframe_t gladiator_frames_walk [] =
  64. {
  65. ai_walk, 15, NULL,
  66. ai_walk, 7, NULL,
  67. ai_walk, 6, NULL,
  68. ai_walk, 5, NULL,
  69. ai_walk, 2, NULL,
  70. ai_walk, 0, NULL,
  71. ai_walk, 2, NULL,
  72. ai_walk, 8, NULL,
  73. ai_walk, 12, NULL,
  74. ai_walk, 8, NULL,
  75. ai_walk, 5, NULL,
  76. ai_walk, 5, NULL,
  77. ai_walk, 2, NULL,
  78. ai_walk, 2, NULL,
  79. ai_walk, 1, NULL,
  80. ai_walk, 8, NULL
  81. };
  82. mmove_t gladiator_move_walk = {FRAME_walk1, FRAME_walk16, gladiator_frames_walk, NULL};
  83. void gladiator_walk (edict_t *self)
  84. {
  85. self->monsterinfo.currentmove = &gladiator_move_walk;
  86. }
  87. mframe_t gladiator_frames_run [] =
  88. {
  89. ai_run, 23, NULL,
  90. ai_run, 14, NULL,
  91. ai_run, 14, NULL,
  92. ai_run, 21, NULL,
  93. ai_run, 12, NULL,
  94. ai_run, 13, NULL
  95. };
  96. mmove_t gladiator_move_run = {FRAME_run1, FRAME_run6, gladiator_frames_run, NULL};
  97. void gladiator_run (edict_t *self)
  98. {
  99. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  100. self->monsterinfo.currentmove = &gladiator_move_stand;
  101. else
  102. self->monsterinfo.currentmove = &gladiator_move_run;
  103. }
  104. void GaldiatorMelee (edict_t *self)
  105. {
  106. vec3_t aim;
  107. VectorSet (aim, MELEE_DISTANCE, self->mins[0], -4);
  108. if (fire_hit (self, aim, (20 + (rand() %5)), 300))
  109. gi.sound (self, CHAN_AUTO, sound_cleaver_hit, 1, ATTN_NORM, 0);
  110. else
  111. gi.sound (self, CHAN_AUTO, sound_cleaver_miss, 1, ATTN_NORM, 0);
  112. }
  113. mframe_t gladiator_frames_attack_melee [] =
  114. {
  115. ai_charge, 0, NULL,
  116. ai_charge, 0, NULL,
  117. ai_charge, 0, NULL,
  118. ai_charge, 0, NULL,
  119. ai_charge, 0, gladiator_cleaver_swing,
  120. ai_charge, 0, NULL,
  121. ai_charge, 0, GaldiatorMelee,
  122. ai_charge, 0, NULL,
  123. ai_charge, 0, NULL,
  124. ai_charge, 0, NULL,
  125. ai_charge, 0, gladiator_cleaver_swing,
  126. ai_charge, 0, NULL,
  127. ai_charge, 0, NULL,
  128. ai_charge, 0, GaldiatorMelee,
  129. ai_charge, 0, NULL,
  130. ai_charge, 0, NULL,
  131. ai_charge, 0, NULL
  132. };
  133. mmove_t gladiator_move_attack_melee = {FRAME_melee1, FRAME_melee17, gladiator_frames_attack_melee, gladiator_run};
  134. void gladiator_melee(edict_t *self)
  135. {
  136. self->monsterinfo.currentmove = &gladiator_move_attack_melee;
  137. }
  138. void GladiatorGun (edict_t *self)
  139. {
  140. vec3_t start;
  141. vec3_t dir;
  142. vec3_t forward, right;
  143. AngleVectors (self->s.angles, forward, right, NULL);
  144. G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_GLADIATOR_RAILGUN_1], forward, right, start);
  145. // calc direction to where we targted
  146. VectorSubtract (self->pos1, start, dir);
  147. VectorNormalize (dir);
  148. monster_fire_railgun (self, start, dir, 50, 100, MZ2_GLADIATOR_RAILGUN_1);
  149. }
  150. mframe_t gladiator_frames_attack_gun [] =
  151. {
  152. ai_charge, 0, NULL,
  153. ai_charge, 0, NULL,
  154. ai_charge, 0, NULL,
  155. ai_charge, 0, GladiatorGun,
  156. ai_charge, 0, NULL,
  157. ai_charge, 0, NULL,
  158. ai_charge, 0, NULL,
  159. ai_charge, 0, NULL,
  160. ai_charge, 0, NULL
  161. };
  162. mmove_t gladiator_move_attack_gun = {FRAME_attack1, FRAME_attack9, gladiator_frames_attack_gun, gladiator_run};
  163. void gladiator_attack(edict_t *self)
  164. {
  165. float range;
  166. vec3_t v;
  167. // a small safe zone
  168. VectorSubtract (self->s.origin, self->enemy->s.origin, v);
  169. range = VectorLength(v);
  170. if (range <= (MELEE_DISTANCE + 32))
  171. return;
  172. // charge up the railgun
  173. gi.sound (self, CHAN_WEAPON, sound_gun, 1, ATTN_NORM, 0);
  174. VectorCopy (self->enemy->s.origin, self->pos1); //save for aiming the shot
  175. self->pos1[2] += self->enemy->viewheight;
  176. self->monsterinfo.currentmove = &gladiator_move_attack_gun;
  177. }
  178. mframe_t gladiator_frames_pain [] =
  179. {
  180. ai_move, 0, NULL,
  181. ai_move, 0, NULL,
  182. ai_move, 0, NULL,
  183. ai_move, 0, NULL,
  184. ai_move, 0, NULL,
  185. ai_move, 0, NULL
  186. };
  187. mmove_t gladiator_move_pain = {FRAME_pain1, FRAME_pain6, gladiator_frames_pain, gladiator_run};
  188. mframe_t gladiator_frames_pain_air [] =
  189. {
  190. ai_move, 0, NULL,
  191. ai_move, 0, NULL,
  192. ai_move, 0, NULL,
  193. ai_move, 0, NULL,
  194. ai_move, 0, NULL,
  195. ai_move, 0, NULL,
  196. ai_move, 0, NULL
  197. };
  198. mmove_t gladiator_move_pain_air = {FRAME_painup1, FRAME_painup7, gladiator_frames_pain_air, gladiator_run};
  199. void gladiator_pain (edict_t *self, edict_t *other, float kick, int damage)
  200. {
  201. if (self->health < (self->max_health / 2))
  202. self->s.skinnum = 1;
  203. if (level.time < self->pain_debounce_time)
  204. {
  205. if ((self->velocity[2] > 100) && (self->monsterinfo.currentmove == &gladiator_move_pain))
  206. self->monsterinfo.currentmove = &gladiator_move_pain_air;
  207. return;
  208. }
  209. self->pain_debounce_time = level.time + 3;
  210. if (random() < 0.5)
  211. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  212. else
  213. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  214. if (skill->value == 3)
  215. return; // no pain anims in nightmare
  216. if (self->velocity[2] > 100)
  217. self->monsterinfo.currentmove = &gladiator_move_pain_air;
  218. else
  219. self->monsterinfo.currentmove = &gladiator_move_pain;
  220. }
  221. void gladiator_dead (edict_t *self)
  222. {
  223. VectorSet (self->mins, -16, -16, -24);
  224. VectorSet (self->maxs, 16, 16, -8);
  225. self->movetype = MOVETYPE_TOSS;
  226. self->svflags |= SVF_DEADMONSTER;
  227. self->nextthink = 0;
  228. gi.linkentity (self);
  229. }
  230. mframe_t gladiator_frames_death [] =
  231. {
  232. ai_move, 0, NULL,
  233. ai_move, 0, NULL,
  234. ai_move, 0, NULL,
  235. ai_move, 0, 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, NULL,
  242. ai_move, 0, NULL,
  243. ai_move, 0, NULL,
  244. ai_move, 0, NULL,
  245. ai_move, 0, NULL,
  246. ai_move, 0, NULL,
  247. ai_move, 0, NULL,
  248. ai_move, 0, NULL,
  249. ai_move, 0, NULL,
  250. ai_move, 0, NULL,
  251. ai_move, 0, NULL,
  252. ai_move, 0, NULL,
  253. ai_move, 0, NULL
  254. };
  255. mmove_t gladiator_move_death = {FRAME_death1, FRAME_death22, gladiator_frames_death, gladiator_dead};
  256. void gladiator_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  257. {
  258. int n;
  259. // check for gib
  260. if (self->health <= self->gib_health)
  261. {
  262. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  263. for (n= 0; n < 2; n++)
  264. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  265. for (n= 0; n < 4; n++)
  266. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  267. ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  268. self->deadflag = DEAD_DEAD;
  269. return;
  270. }
  271. if (self->deadflag == DEAD_DEAD)
  272. return;
  273. // regular death
  274. gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  275. self->deadflag = DEAD_DEAD;
  276. self->takedamage = DAMAGE_YES;
  277. self->monsterinfo.currentmove = &gladiator_move_death;
  278. }
  279. /*QUAKED monster_gladiator (1 .5 0) (-32 -32 -24) (32 32 64) Ambush Trigger_Spawn Sight
  280. */
  281. void SP_monster_gladiator (edict_t *self)
  282. {
  283. if (deathmatch->value)
  284. {
  285. G_FreeEdict (self);
  286. return;
  287. }
  288. sound_pain1 = gi.soundindex ("gladiator/pain.wav");
  289. sound_pain2 = gi.soundindex ("gladiator/gldpain2.wav");
  290. sound_die = gi.soundindex ("gladiator/glddeth2.wav");
  291. sound_gun = gi.soundindex ("gladiator/railgun.wav");
  292. sound_cleaver_swing = gi.soundindex ("gladiator/melee1.wav");
  293. sound_cleaver_hit = gi.soundindex ("gladiator/melee2.wav");
  294. sound_cleaver_miss = gi.soundindex ("gladiator/melee3.wav");
  295. sound_idle = gi.soundindex ("gladiator/gldidle1.wav");
  296. sound_search = gi.soundindex ("gladiator/gldsrch1.wav");
  297. sound_sight = gi.soundindex ("gladiator/sight.wav");
  298. self->movetype = MOVETYPE_STEP;
  299. self->solid = SOLID_BBOX;
  300. self->s.modelindex = gi.modelindex ("models/monsters/gladiatr/tris.md2");
  301. VectorSet (self->mins, -32, -32, -24);
  302. VectorSet (self->maxs, 32, 32, 64);
  303. self->health = 400;
  304. self->gib_health = -175;
  305. self->mass = 400;
  306. self->pain = gladiator_pain;
  307. self->die = gladiator_die;
  308. self->monsterinfo.stand = gladiator_stand;
  309. self->monsterinfo.walk = gladiator_walk;
  310. self->monsterinfo.run = gladiator_run;
  311. self->monsterinfo.dodge = NULL;
  312. self->monsterinfo.attack = gladiator_attack;
  313. self->monsterinfo.melee = gladiator_melee;
  314. self->monsterinfo.sight = gladiator_sight;
  315. self->monsterinfo.idle = gladiator_idle;
  316. self->monsterinfo.search = gladiator_search;
  317. gi.linkentity (self);
  318. self->monsterinfo.currentmove = &gladiator_move_stand;
  319. self->monsterinfo.scale = MODEL_SCALE;
  320. walkmonster_start (self);
  321. }