m_flipper.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. FLIPPER
  18. ==============================================================================
  19. */
  20. #include "g_local.h"
  21. #include "m_flipper.h"
  22. static int sound_chomp;
  23. static int sound_attack;
  24. static int sound_pain1;
  25. static int sound_pain2;
  26. static int sound_death;
  27. static int sound_idle;
  28. static int sound_search;
  29. static int sound_sight;
  30. void flipper_stand (edict_t *self);
  31. mframe_t flipper_frames_stand [] =
  32. {
  33. ai_stand, 0, NULL
  34. };
  35. mmove_t flipper_move_stand = {FRAME_flphor01, FRAME_flphor01, flipper_frames_stand, NULL};
  36. void flipper_stand (edict_t *self)
  37. {
  38. self->monsterinfo.currentmove = &flipper_move_stand;
  39. }
  40. #define FLIPPER_RUN_SPEED 24
  41. mframe_t flipper_frames_run [] =
  42. {
  43. ai_run, FLIPPER_RUN_SPEED, NULL, // 6
  44. ai_run, FLIPPER_RUN_SPEED, NULL,
  45. ai_run, FLIPPER_RUN_SPEED, NULL,
  46. ai_run, FLIPPER_RUN_SPEED, NULL,
  47. ai_run, FLIPPER_RUN_SPEED, NULL, // 10
  48. ai_run, FLIPPER_RUN_SPEED, NULL,
  49. ai_run, FLIPPER_RUN_SPEED, NULL,
  50. ai_run, FLIPPER_RUN_SPEED, NULL,
  51. ai_run, FLIPPER_RUN_SPEED, NULL,
  52. ai_run, FLIPPER_RUN_SPEED, NULL,
  53. ai_run, FLIPPER_RUN_SPEED, NULL,
  54. ai_run, FLIPPER_RUN_SPEED, NULL,
  55. ai_run, FLIPPER_RUN_SPEED, NULL,
  56. ai_run, FLIPPER_RUN_SPEED, NULL,
  57. ai_run, FLIPPER_RUN_SPEED, NULL, // 20
  58. ai_run, FLIPPER_RUN_SPEED, NULL,
  59. ai_run, FLIPPER_RUN_SPEED, NULL,
  60. ai_run, FLIPPER_RUN_SPEED, NULL,
  61. ai_run, FLIPPER_RUN_SPEED, NULL,
  62. ai_run, FLIPPER_RUN_SPEED, NULL,
  63. ai_run, FLIPPER_RUN_SPEED, NULL,
  64. ai_run, FLIPPER_RUN_SPEED, NULL,
  65. ai_run, FLIPPER_RUN_SPEED, NULL,
  66. ai_run, FLIPPER_RUN_SPEED, NULL // 29
  67. };
  68. mmove_t flipper_move_run_loop = {FRAME_flpver06, FRAME_flpver29, flipper_frames_run, NULL};
  69. void flipper_run_loop (edict_t *self)
  70. {
  71. self->monsterinfo.currentmove = &flipper_move_run_loop;
  72. }
  73. mframe_t flipper_frames_run_start [] =
  74. {
  75. ai_run, 8, NULL,
  76. ai_run, 8, NULL,
  77. ai_run, 8, NULL,
  78. ai_run, 8, NULL,
  79. ai_run, 8, NULL,
  80. ai_run, 8, NULL
  81. };
  82. mmove_t flipper_move_run_start = {FRAME_flpver01, FRAME_flpver06, flipper_frames_run_start, flipper_run_loop};
  83. void flipper_run (edict_t *self)
  84. {
  85. self->monsterinfo.currentmove = &flipper_move_run_start;
  86. }
  87. /* Standard Swimming */
  88. mframe_t flipper_frames_walk [] =
  89. {
  90. ai_walk, 4, NULL,
  91. ai_walk, 4, NULL,
  92. ai_walk, 4, NULL,
  93. ai_walk, 4, NULL,
  94. ai_walk, 4, NULL,
  95. ai_walk, 4, NULL,
  96. ai_walk, 4, NULL,
  97. ai_walk, 4, NULL,
  98. ai_walk, 4, NULL,
  99. ai_walk, 4, NULL,
  100. ai_walk, 4, NULL,
  101. ai_walk, 4, NULL,
  102. ai_walk, 4, NULL,
  103. ai_walk, 4, NULL,
  104. ai_walk, 4, NULL,
  105. ai_walk, 4, NULL,
  106. ai_walk, 4, NULL,
  107. ai_walk, 4, NULL,
  108. ai_walk, 4, NULL,
  109. ai_walk, 4, NULL,
  110. ai_walk, 4, NULL,
  111. ai_walk, 4, NULL,
  112. ai_walk, 4, NULL,
  113. ai_walk, 4, NULL
  114. };
  115. mmove_t flipper_move_walk = {FRAME_flphor01, FRAME_flphor24, flipper_frames_walk, NULL};
  116. void flipper_walk (edict_t *self)
  117. {
  118. self->monsterinfo.currentmove = &flipper_move_walk;
  119. }
  120. mframe_t flipper_frames_start_run [] =
  121. {
  122. ai_run, 8, NULL,
  123. ai_run, 8, NULL,
  124. ai_run, 8, NULL,
  125. ai_run, 8, NULL,
  126. ai_run, 8, flipper_run
  127. };
  128. mmove_t flipper_move_start_run = {FRAME_flphor01, FRAME_flphor05, flipper_frames_start_run, NULL};
  129. void flipper_start_run (edict_t *self)
  130. {
  131. self->monsterinfo.currentmove = &flipper_move_start_run;
  132. }
  133. mframe_t flipper_frames_pain2 [] =
  134. {
  135. ai_move, 0, NULL,
  136. ai_move, 0, NULL,
  137. ai_move, 0, NULL,
  138. ai_move, 0, NULL,
  139. ai_move, 0, NULL
  140. };
  141. mmove_t flipper_move_pain2 = {FRAME_flppn101, FRAME_flppn105, flipper_frames_pain2, flipper_run};
  142. mframe_t flipper_frames_pain1 [] =
  143. {
  144. ai_move, 0, NULL,
  145. ai_move, 0, NULL,
  146. ai_move, 0, NULL,
  147. ai_move, 0, NULL,
  148. ai_move, 0, NULL
  149. };
  150. mmove_t flipper_move_pain1 = {FRAME_flppn201, FRAME_flppn205, flipper_frames_pain1, flipper_run};
  151. void flipper_bite (edict_t *self)
  152. {
  153. vec3_t aim;
  154. VectorSet (aim, MELEE_DISTANCE, 0, 0);
  155. fire_hit (self, aim, 5, 0);
  156. }
  157. void flipper_preattack (edict_t *self)
  158. {
  159. gi.sound (self, CHAN_WEAPON, sound_chomp, 1, ATTN_NORM, 0);
  160. }
  161. mframe_t flipper_frames_attack [] =
  162. {
  163. ai_charge, 0, flipper_preattack,
  164. ai_charge, 0, NULL,
  165. ai_charge, 0, NULL,
  166. ai_charge, 0, NULL,
  167. ai_charge, 0, NULL,
  168. ai_charge, 0, NULL,
  169. ai_charge, 0, NULL,
  170. ai_charge, 0, NULL,
  171. ai_charge, 0, NULL,
  172. ai_charge, 0, NULL,
  173. ai_charge, 0, NULL,
  174. ai_charge, 0, NULL,
  175. ai_charge, 0, NULL,
  176. ai_charge, 0, flipper_bite,
  177. ai_charge, 0, NULL,
  178. ai_charge, 0, NULL,
  179. ai_charge, 0, NULL,
  180. ai_charge, 0, NULL,
  181. ai_charge, 0, flipper_bite,
  182. ai_charge, 0, NULL
  183. };
  184. mmove_t flipper_move_attack = {FRAME_flpbit01, FRAME_flpbit20, flipper_frames_attack, flipper_run};
  185. void flipper_melee(edict_t *self)
  186. {
  187. self->monsterinfo.currentmove = &flipper_move_attack;
  188. }
  189. void flipper_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() + 1) % 2;
  200. if (n == 0)
  201. {
  202. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  203. self->monsterinfo.currentmove = &flipper_move_pain1;
  204. }
  205. else
  206. {
  207. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  208. self->monsterinfo.currentmove = &flipper_move_pain2;
  209. }
  210. }
  211. void flipper_dead (edict_t *self)
  212. {
  213. VectorSet (self->mins, -16, -16, -24);
  214. VectorSet (self->maxs, 16, 16, -8);
  215. self->movetype = MOVETYPE_TOSS;
  216. self->svflags |= SVF_DEADMONSTER;
  217. self->nextthink = 0;
  218. gi.linkentity (self);
  219. }
  220. mframe_t flipper_frames_death [] =
  221. {
  222. ai_move, 0, NULL,
  223. ai_move, 0, NULL,
  224. ai_move, 0, NULL,
  225. ai_move, 0, NULL,
  226. ai_move, 0, NULL,
  227. ai_move, 0, NULL,
  228. ai_move, 0, NULL,
  229. ai_move, 0, NULL,
  230. ai_move, 0, NULL,
  231. ai_move, 0, NULL,
  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. ai_move, 0, NULL,
  255. ai_move, 0, NULL,
  256. ai_move, 0, NULL,
  257. ai_move, 0, NULL,
  258. ai_move, 0, NULL,
  259. ai_move, 0, NULL,
  260. ai_move, 0, NULL,
  261. ai_move, 0, NULL,
  262. ai_move, 0, NULL,
  263. ai_move, 0, NULL,
  264. ai_move, 0, NULL,
  265. ai_move, 0, NULL,
  266. ai_move, 0, NULL,
  267. ai_move, 0, NULL,
  268. ai_move, 0, NULL,
  269. ai_move, 0, NULL,
  270. ai_move, 0, NULL,
  271. ai_move, 0, NULL,
  272. ai_move, 0, NULL,
  273. ai_move, 0, NULL,
  274. ai_move, 0, NULL,
  275. ai_move, 0, NULL,
  276. ai_move, 0, NULL,
  277. ai_move, 0, NULL
  278. };
  279. mmove_t flipper_move_death = {FRAME_flpdth01, FRAME_flpdth56, flipper_frames_death, flipper_dead};
  280. void flipper_sight (edict_t *self, edict_t *other)
  281. {
  282. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  283. }
  284. void flipper_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  285. {
  286. int n;
  287. // check for gib
  288. if (self->health <= self->gib_health)
  289. {
  290. gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  291. for (n= 0; n < 2; n++)
  292. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  293. for (n= 0; n < 2; n++)
  294. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  295. ThrowHead (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  296. self->deadflag = DEAD_DEAD;
  297. return;
  298. }
  299. if (self->deadflag == DEAD_DEAD)
  300. return;
  301. // regular death
  302. gi.sound (self, CHAN_VOICE, sound_death, 1, ATTN_NORM, 0);
  303. self->deadflag = DEAD_DEAD;
  304. self->takedamage = DAMAGE_YES;
  305. self->monsterinfo.currentmove = &flipper_move_death;
  306. }
  307. /*QUAKED monster_flipper (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  308. */
  309. void SP_monster_flipper (edict_t *self)
  310. {
  311. if (deathmatch->value)
  312. {
  313. G_FreeEdict (self);
  314. return;
  315. }
  316. sound_pain1 = gi.soundindex ("flipper/flppain1.wav");
  317. sound_pain2 = gi.soundindex ("flipper/flppain2.wav");
  318. sound_death = gi.soundindex ("flipper/flpdeth1.wav");
  319. sound_chomp = gi.soundindex ("flipper/flpatck1.wav");
  320. sound_attack = gi.soundindex ("flipper/flpatck2.wav");
  321. sound_idle = gi.soundindex ("flipper/flpidle1.wav");
  322. sound_search = gi.soundindex ("flipper/flpsrch1.wav");
  323. sound_sight = gi.soundindex ("flipper/flpsght1.wav");
  324. self->movetype = MOVETYPE_STEP;
  325. self->solid = SOLID_BBOX;
  326. self->s.modelindex = gi.modelindex ("models/monsters/flipper/tris.md2");
  327. VectorSet (self->mins, -16, -16, 0);
  328. VectorSet (self->maxs, 16, 16, 32);
  329. self->health = 50;
  330. self->gib_health = -30;
  331. self->mass = 100;
  332. self->pain = flipper_pain;
  333. self->die = flipper_die;
  334. self->monsterinfo.stand = flipper_stand;
  335. self->monsterinfo.walk = flipper_walk;
  336. self->monsterinfo.run = flipper_start_run;
  337. self->monsterinfo.melee = flipper_melee;
  338. self->monsterinfo.sight = flipper_sight;
  339. gi.linkentity (self);
  340. self->monsterinfo.currentmove = &flipper_move_stand;
  341. self->monsterinfo.scale = MODEL_SCALE;
  342. swimmonster_start (self);
  343. }