m_flyer.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. /*
  4. ==============================================================================
  5. flyer
  6. ==============================================================================
  7. */
  8. #include "g_local.h"
  9. #include "m_flyer.h"
  10. qboolean visible (edict_t *self, edict_t *other);
  11. static int nextmove; // Used for start/stop frames
  12. static int sound_sight;
  13. static int sound_idle;
  14. static int sound_pain1;
  15. static int sound_pain2;
  16. static int sound_slash;
  17. static int sound_sproing;
  18. static int sound_die;
  19. void flyer_check_melee(edict_t *self);
  20. void flyer_loop_melee (edict_t *self);
  21. void flyer_melee (edict_t *self);
  22. void flyer_setstart (edict_t *self);
  23. void flyer_stand (edict_t *self);
  24. void flyer_nextmove (edict_t *self);
  25. void flyer_sight (edict_t *self, edict_t *other)
  26. {
  27. gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  28. }
  29. void flyer_idle (edict_t *self)
  30. {
  31. gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  32. }
  33. void flyer_pop_blades (edict_t *self)
  34. {
  35. gi.sound (self, CHAN_VOICE, sound_sproing, 1, ATTN_NORM, 0);
  36. }
  37. mframe_t flyer_frames_stand [] =
  38. {
  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. ai_stand, 0, NULL,
  59. ai_stand, 0, NULL,
  60. ai_stand, 0, NULL,
  61. ai_stand, 0, NULL,
  62. ai_stand, 0, NULL,
  63. ai_stand, 0, NULL,
  64. ai_stand, 0, NULL,
  65. ai_stand, 0, NULL,
  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,
  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. };
  85. mmove_t flyer_move_stand = {FRAME_stand01, FRAME_stand45, flyer_frames_stand, NULL};
  86. mframe_t flyer_frames_walk [] =
  87. {
  88. ai_walk, 5, NULL,
  89. ai_walk, 5, NULL,
  90. ai_walk, 5, NULL,
  91. ai_walk, 5, NULL,
  92. ai_walk, 5, NULL,
  93. ai_walk, 5, NULL,
  94. ai_walk, 5, NULL,
  95. ai_walk, 5, NULL,
  96. ai_walk, 5, NULL,
  97. ai_walk, 5, NULL,
  98. ai_walk, 5, NULL,
  99. ai_walk, 5, NULL,
  100. ai_walk, 5, NULL,
  101. ai_walk, 5, NULL,
  102. ai_walk, 5, NULL,
  103. ai_walk, 5, NULL,
  104. ai_walk, 5, NULL,
  105. ai_walk, 5, NULL,
  106. ai_walk, 5, NULL,
  107. ai_walk, 5, NULL,
  108. ai_walk, 5, NULL,
  109. ai_walk, 5, NULL,
  110. ai_walk, 5, NULL,
  111. ai_walk, 5, NULL,
  112. ai_walk, 5, NULL,
  113. ai_walk, 5, NULL,
  114. ai_walk, 5, NULL,
  115. ai_walk, 5, NULL,
  116. ai_walk, 5, NULL,
  117. ai_walk, 5, NULL,
  118. ai_walk, 5, NULL,
  119. ai_walk, 5, NULL,
  120. ai_walk, 5, NULL,
  121. ai_walk, 5, NULL,
  122. ai_walk, 5, NULL,
  123. ai_walk, 5, NULL,
  124. ai_walk, 5, NULL,
  125. ai_walk, 5, NULL,
  126. ai_walk, 5, NULL,
  127. ai_walk, 5, NULL,
  128. ai_walk, 5, NULL,
  129. ai_walk, 5, NULL,
  130. ai_walk, 5, NULL,
  131. ai_walk, 5, NULL,
  132. ai_walk, 5, NULL
  133. };
  134. mmove_t flyer_move_walk = {FRAME_stand01, FRAME_stand45, flyer_frames_walk, NULL};
  135. mframe_t flyer_frames_run [] =
  136. {
  137. ai_run, 10, NULL,
  138. ai_run, 10, NULL,
  139. ai_run, 10, NULL,
  140. ai_run, 10, NULL,
  141. ai_run, 10, NULL,
  142. ai_run, 10, NULL,
  143. ai_run, 10, NULL,
  144. ai_run, 10, NULL,
  145. ai_run, 10, NULL,
  146. ai_run, 10, NULL,
  147. ai_run, 10, NULL,
  148. ai_run, 10, NULL,
  149. ai_run, 10, NULL,
  150. ai_run, 10, NULL,
  151. ai_run, 10, NULL,
  152. ai_run, 10, NULL,
  153. ai_run, 10, NULL,
  154. ai_run, 10, NULL,
  155. ai_run, 10, NULL,
  156. ai_run, 10, NULL,
  157. ai_run, 10, NULL,
  158. ai_run, 10, NULL,
  159. ai_run, 10, NULL,
  160. ai_run, 10, NULL,
  161. ai_run, 10, NULL,
  162. ai_run, 10, NULL,
  163. ai_run, 10, NULL,
  164. ai_run, 10, NULL,
  165. ai_run, 10, NULL,
  166. ai_run, 10, NULL,
  167. ai_run, 10, NULL,
  168. ai_run, 10, NULL,
  169. ai_run, 10, NULL,
  170. ai_run, 10, NULL,
  171. ai_run, 10, NULL,
  172. ai_run, 10, NULL,
  173. ai_run, 10, NULL,
  174. ai_run, 10, NULL,
  175. ai_run, 10, NULL,
  176. ai_run, 10, NULL,
  177. ai_run, 10, NULL,
  178. ai_run, 10, NULL,
  179. ai_run, 10, NULL,
  180. ai_run, 10, NULL,
  181. ai_run, 10, NULL
  182. };
  183. mmove_t flyer_move_run = {FRAME_stand01, FRAME_stand45, flyer_frames_run, NULL};
  184. void flyer_run (edict_t *self)
  185. {
  186. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  187. self->monsterinfo.currentmove = &flyer_move_stand;
  188. else
  189. self->monsterinfo.currentmove = &flyer_move_run;
  190. }
  191. void flyer_walk (edict_t *self)
  192. {
  193. self->monsterinfo.currentmove = &flyer_move_walk;
  194. }
  195. void flyer_stand (edict_t *self)
  196. {
  197. self->monsterinfo.currentmove = &flyer_move_stand;
  198. }
  199. mframe_t flyer_frames_start [] =
  200. {
  201. ai_move, 0, NULL,
  202. ai_move, 0, NULL,
  203. ai_move, 0, NULL,
  204. ai_move, 0, NULL,
  205. ai_move, 0, NULL,
  206. ai_move, 0, flyer_nextmove
  207. };
  208. mmove_t flyer_move_start = {FRAME_start01, FRAME_start06, flyer_frames_start, NULL};
  209. mframe_t flyer_frames_stop [] =
  210. {
  211. ai_move, 0, NULL,
  212. ai_move, 0, NULL,
  213. ai_move, 0, NULL,
  214. ai_move, 0, NULL,
  215. ai_move, 0, NULL,
  216. ai_move, 0, NULL,
  217. ai_move, 0, flyer_nextmove
  218. };
  219. mmove_t flyer_move_stop = {FRAME_stop01, FRAME_stop07, flyer_frames_stop, NULL};
  220. void flyer_stop (edict_t *self)
  221. {
  222. self->monsterinfo.currentmove = &flyer_move_stop;
  223. }
  224. void flyer_start (edict_t *self)
  225. {
  226. self->monsterinfo.currentmove = &flyer_move_start;
  227. }
  228. mframe_t flyer_frames_rollright [] =
  229. {
  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. };
  240. mmove_t flyer_move_rollright = {FRAME_rollr01, FRAME_rollr09, flyer_frames_rollright, NULL};
  241. mframe_t flyer_frames_rollleft [] =
  242. {
  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. };
  253. mmove_t flyer_move_rollleft = {FRAME_rollf01, FRAME_rollf09, flyer_frames_rollleft, NULL};
  254. mframe_t flyer_frames_pain3 [] =
  255. {
  256. ai_move, 0, NULL,
  257. ai_move, 0, NULL,
  258. ai_move, 0, NULL,
  259. ai_move, 0, NULL
  260. };
  261. mmove_t flyer_move_pain3 = {FRAME_pain301, FRAME_pain304, flyer_frames_pain3, flyer_run};
  262. mframe_t flyer_frames_pain2 [] =
  263. {
  264. ai_move, 0, NULL,
  265. ai_move, 0, NULL,
  266. ai_move, 0, NULL,
  267. ai_move, 0, NULL
  268. };
  269. mmove_t flyer_move_pain2 = {FRAME_pain201, FRAME_pain204, flyer_frames_pain2, flyer_run};
  270. mframe_t flyer_frames_pain1 [] =
  271. {
  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. ai_move, 0, NULL,
  279. ai_move, 0, NULL,
  280. ai_move, 0, NULL
  281. };
  282. mmove_t flyer_move_pain1 = {FRAME_pain101, FRAME_pain109, flyer_frames_pain1, flyer_run};
  283. mframe_t flyer_frames_defense [] =
  284. {
  285. ai_move, 0, NULL,
  286. ai_move, 0, NULL,
  287. ai_move, 0, NULL, // Hold this frame
  288. ai_move, 0, NULL,
  289. ai_move, 0, NULL,
  290. ai_move, 0, NULL
  291. };
  292. mmove_t flyer_move_defense = {FRAME_defens01, FRAME_defens06, flyer_frames_defense, NULL};
  293. mframe_t flyer_frames_bankright [] =
  294. {
  295. ai_move, 0, NULL,
  296. ai_move, 0, NULL,
  297. ai_move, 0, NULL,
  298. ai_move, 0, NULL,
  299. ai_move, 0, NULL,
  300. ai_move, 0, NULL,
  301. ai_move, 0, NULL
  302. };
  303. mmove_t flyer_move_bankright = {FRAME_bankr01, FRAME_bankr07, flyer_frames_bankright, NULL};
  304. mframe_t flyer_frames_bankleft [] =
  305. {
  306. ai_move, 0, NULL,
  307. ai_move, 0, NULL,
  308. ai_move, 0, NULL,
  309. ai_move, 0, NULL,
  310. ai_move, 0, NULL,
  311. ai_move, 0, NULL,
  312. ai_move, 0, NULL
  313. };
  314. mmove_t flyer_move_bankleft = {FRAME_bankl01, FRAME_bankl07, flyer_frames_bankleft, NULL};
  315. void flyer_fire (edict_t *self, int flash_number)
  316. {
  317. vec3_t start;
  318. vec3_t forward, right;
  319. vec3_t end;
  320. vec3_t dir;
  321. int effect;
  322. if ((self->s.frame == FRAME_attak204) || (self->s.frame == FRAME_attak207) || (self->s.frame == FRAME_attak210))
  323. effect = EF_HYPERBLASTER;
  324. else
  325. effect = 0;
  326. AngleVectors (self->s.angles, forward, right, NULL);
  327. G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  328. VectorCopy (self->enemy->s.origin, end);
  329. end[2] += self->enemy->viewheight;
  330. VectorSubtract (end, start, dir);
  331. monster_fire_blaster (self, start, dir, 1, 1000, flash_number, effect);
  332. }
  333. void flyer_fireleft (edict_t *self)
  334. {
  335. flyer_fire (self, MZ2_FLYER_BLASTER_1);
  336. }
  337. void flyer_fireright (edict_t *self)
  338. {
  339. flyer_fire (self, MZ2_FLYER_BLASTER_2);
  340. }
  341. mframe_t flyer_frames_attack2 [] =
  342. {
  343. ai_charge, 0, NULL,
  344. ai_charge, 0, NULL,
  345. ai_charge, 0, NULL,
  346. ai_charge, -10, flyer_fireleft, // left gun
  347. ai_charge, -10, flyer_fireright, // right gun
  348. ai_charge, -10, flyer_fireleft, // left gun
  349. ai_charge, -10, flyer_fireright, // right gun
  350. ai_charge, -10, flyer_fireleft, // left gun
  351. ai_charge, -10, flyer_fireright, // right gun
  352. ai_charge, -10, flyer_fireleft, // left gun
  353. ai_charge, -10, flyer_fireright, // right gun
  354. ai_charge, 0, NULL,
  355. ai_charge, 0, NULL,
  356. ai_charge, 0, NULL,
  357. ai_charge, 0, NULL,
  358. ai_charge, 0, NULL,
  359. ai_charge, 0, NULL
  360. };
  361. mmove_t flyer_move_attack2 = {FRAME_attak201, FRAME_attak217, flyer_frames_attack2, flyer_run};
  362. void flyer_slash_left (edict_t *self)
  363. {
  364. vec3_t aim;
  365. VectorSet (aim, MELEE_DISTANCE, self->mins[0], 0);
  366. fire_hit (self, aim, 5, 0);
  367. gi.sound (self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
  368. }
  369. void flyer_slash_right (edict_t *self)
  370. {
  371. vec3_t aim;
  372. VectorSet (aim, MELEE_DISTANCE, self->maxs[0], 0);
  373. fire_hit (self, aim, 5, 0);
  374. gi.sound (self, CHAN_WEAPON, sound_slash, 1, ATTN_NORM, 0);
  375. }
  376. mframe_t flyer_frames_start_melee [] =
  377. {
  378. ai_charge, 0, flyer_pop_blades,
  379. ai_charge, 0, NULL,
  380. ai_charge, 0, NULL,
  381. ai_charge, 0, NULL,
  382. ai_charge, 0, NULL,
  383. ai_charge, 0, NULL
  384. };
  385. mmove_t flyer_move_start_melee = {FRAME_attak101, FRAME_attak106, flyer_frames_start_melee, flyer_loop_melee};
  386. mframe_t flyer_frames_end_melee [] =
  387. {
  388. ai_charge, 0, NULL,
  389. ai_charge, 0, NULL,
  390. ai_charge, 0, NULL
  391. };
  392. mmove_t flyer_move_end_melee = {FRAME_attak119, FRAME_attak121, flyer_frames_end_melee, flyer_run};
  393. mframe_t flyer_frames_loop_melee [] =
  394. {
  395. ai_charge, 0, NULL, // Loop Start
  396. ai_charge, 0, NULL,
  397. ai_charge, 0, flyer_slash_left, // Left Wing Strike
  398. ai_charge, 0, NULL,
  399. ai_charge, 0, NULL,
  400. ai_charge, 0, NULL,
  401. ai_charge, 0, NULL,
  402. ai_charge, 0, flyer_slash_right, // Right Wing Strike
  403. ai_charge, 0, NULL,
  404. ai_charge, 0, NULL,
  405. ai_charge, 0, NULL,
  406. ai_charge, 0, NULL // Loop Ends
  407. };
  408. mmove_t flyer_move_loop_melee = {FRAME_attak107, FRAME_attak118, flyer_frames_loop_melee, flyer_check_melee};
  409. void flyer_loop_melee (edict_t *self)
  410. {
  411. /* if (random() <= 0.5)
  412. self->monsterinfo.currentmove = &flyer_move_attack1;
  413. else */
  414. self->monsterinfo.currentmove = &flyer_move_loop_melee;
  415. }
  416. void flyer_attack (edict_t *self)
  417. {
  418. /* if (random() <= 0.5)
  419. self->monsterinfo.currentmove = &flyer_move_attack1;
  420. else */
  421. self->monsterinfo.currentmove = &flyer_move_attack2;
  422. }
  423. void flyer_setstart (edict_t *self)
  424. {
  425. nextmove = ACTION_run;
  426. self->monsterinfo.currentmove = &flyer_move_start;
  427. }
  428. void flyer_nextmove (edict_t *self)
  429. {
  430. if (nextmove == ACTION_attack1)
  431. self->monsterinfo.currentmove = &flyer_move_start_melee;
  432. else if (nextmove == ACTION_attack2)
  433. self->monsterinfo.currentmove = &flyer_move_attack2;
  434. else if (nextmove == ACTION_run)
  435. self->monsterinfo.currentmove = &flyer_move_run;
  436. }
  437. void flyer_melee (edict_t *self)
  438. {
  439. // flyer.nextmove = ACTION_attack1;
  440. // self->monsterinfo.currentmove = &flyer_move_stop;
  441. self->monsterinfo.currentmove = &flyer_move_start_melee;
  442. }
  443. void flyer_check_melee(edict_t *self)
  444. {
  445. if (range (self, self->enemy) == RANGE_MELEE)
  446. if (random() <= 0.8)
  447. self->monsterinfo.currentmove = &flyer_move_loop_melee;
  448. else
  449. self->monsterinfo.currentmove = &flyer_move_end_melee;
  450. else
  451. self->monsterinfo.currentmove = &flyer_move_end_melee;
  452. }
  453. void flyer_pain (edict_t *self, edict_t *other, float kick, int damage)
  454. {
  455. int n;
  456. if (self->health < (self->max_health / 2))
  457. self->s.skinnum = 1;
  458. if (level.time < self->pain_debounce_time)
  459. return;
  460. self->pain_debounce_time = level.time + 3;
  461. if (skill->value == 3)
  462. return; // no pain anims in nightmare
  463. n = rand() % 3;
  464. if (n == 0)
  465. {
  466. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  467. self->monsterinfo.currentmove = &flyer_move_pain1;
  468. }
  469. else if (n == 1)
  470. {
  471. gi.sound (self, CHAN_VOICE, sound_pain2, 1, ATTN_NORM, 0);
  472. self->monsterinfo.currentmove = &flyer_move_pain2;
  473. }
  474. else
  475. {
  476. gi.sound (self, CHAN_VOICE, sound_pain1, 1, ATTN_NORM, 0);
  477. self->monsterinfo.currentmove = &flyer_move_pain3;
  478. }
  479. }
  480. void flyer_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  481. {
  482. gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  483. BecomeExplosion1(self);
  484. }
  485. /*QUAKED monster_flyer (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  486. */
  487. void SP_monster_flyer (edict_t *self)
  488. {
  489. if (deathmatch->value)
  490. {
  491. G_FreeEdict (self);
  492. return;
  493. }
  494. // fix a map bug in jail5.bsp
  495. if (!stricmp(level.mapname, "jail5") && (self->s.origin[2] == -104))
  496. {
  497. self->targetname = self->target;
  498. self->target = NULL;
  499. }
  500. sound_sight = gi.soundindex ("flyer/flysght1.wav");
  501. sound_idle = gi.soundindex ("flyer/flysrch1.wav");
  502. sound_pain1 = gi.soundindex ("flyer/flypain1.wav");
  503. sound_pain2 = gi.soundindex ("flyer/flypain2.wav");
  504. sound_slash = gi.soundindex ("flyer/flyatck2.wav");
  505. sound_sproing = gi.soundindex ("flyer/flyatck1.wav");
  506. sound_die = gi.soundindex ("flyer/flydeth1.wav");
  507. gi.soundindex ("flyer/flyatck3.wav");
  508. self->s.modelindex = gi.modelindex ("models/monsters/flyer/tris.md2");
  509. VectorSet (self->mins, -16, -16, -24);
  510. VectorSet (self->maxs, 16, 16, 32);
  511. self->movetype = MOVETYPE_STEP;
  512. self->solid = SOLID_BBOX;
  513. self->s.sound = gi.soundindex ("flyer/flyidle1.wav");
  514. self->health = 50;
  515. self->mass = 50;
  516. self->pain = flyer_pain;
  517. self->die = flyer_die;
  518. self->monsterinfo.stand = flyer_stand;
  519. self->monsterinfo.walk = flyer_walk;
  520. self->monsterinfo.run = flyer_run;
  521. self->monsterinfo.attack = flyer_attack;
  522. self->monsterinfo.melee = flyer_melee;
  523. self->monsterinfo.sight = flyer_sight;
  524. self->monsterinfo.idle = flyer_idle;
  525. gi.linkentity (self);
  526. self->monsterinfo.currentmove = &flyer_move_stand;
  527. self->monsterinfo.scale = MODEL_SCALE;
  528. flymonster_start (self);
  529. }