m_actor.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. // g_actor.c
  16. #include "g_local.h"
  17. #include "m_actor.h"
  18. #define MAX_ACTOR_NAMES 8
  19. char *actor_names[MAX_ACTOR_NAMES] =
  20. {
  21. "Hellrot",
  22. "Tokay",
  23. "Killme",
  24. "Disruptor",
  25. "Adrianator",
  26. "Rambear",
  27. "Titus",
  28. "Bitterman"
  29. };
  30. mframe_t actor_frames_stand [] =
  31. {
  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. 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. };
  73. mmove_t actor_move_stand = {FRAME_stand101, FRAME_stand140, actor_frames_stand, NULL};
  74. void actor_stand (edict_t *self)
  75. {
  76. self->monsterinfo.currentmove = &actor_move_stand;
  77. // randomize on startup
  78. if (level.time < 1.0)
  79. self->s.frame = self->monsterinfo.currentmove->firstframe + (rand() % (self->monsterinfo.currentmove->lastframe - self->monsterinfo.currentmove->firstframe + 1));
  80. }
  81. mframe_t actor_frames_walk [] =
  82. {
  83. ai_walk, 0, NULL,
  84. ai_walk, 6, NULL,
  85. ai_walk, 10, NULL,
  86. ai_walk, 3, NULL,
  87. ai_walk, 2, NULL,
  88. ai_walk, 7, NULL,
  89. ai_walk, 10, NULL,
  90. ai_walk, 1, NULL,
  91. ai_walk, 4, NULL,
  92. ai_walk, 0, NULL,
  93. ai_walk, 0, NULL
  94. };
  95. mmove_t actor_move_walk = {FRAME_walk01, FRAME_walk08, actor_frames_walk, NULL};
  96. void actor_walk (edict_t *self)
  97. {
  98. self->monsterinfo.currentmove = &actor_move_walk;
  99. }
  100. mframe_t actor_frames_run [] =
  101. {
  102. ai_run, 4, NULL,
  103. ai_run, 15, NULL,
  104. ai_run, 15, NULL,
  105. ai_run, 8, NULL,
  106. ai_run, 20, NULL,
  107. ai_run, 15, NULL,
  108. ai_run, 8, NULL,
  109. ai_run, 17, NULL,
  110. ai_run, 12, NULL,
  111. ai_run, -2, NULL,
  112. ai_run, -2, NULL,
  113. ai_run, -1, NULL
  114. };
  115. mmove_t actor_move_run = {FRAME_run02, FRAME_run07, actor_frames_run, NULL};
  116. void actor_run (edict_t *self)
  117. {
  118. if ((level.time < self->pain_debounce_time) && (!self->enemy))
  119. {
  120. if (self->movetarget)
  121. actor_walk(self);
  122. else
  123. actor_stand(self);
  124. return;
  125. }
  126. if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  127. {
  128. actor_stand(self);
  129. return;
  130. }
  131. self->monsterinfo.currentmove = &actor_move_run;
  132. }
  133. mframe_t actor_frames_pain1 [] =
  134. {
  135. ai_move, -5, NULL,
  136. ai_move, 4, NULL,
  137. ai_move, 1, NULL
  138. };
  139. mmove_t actor_move_pain1 = {FRAME_pain101, FRAME_pain103, actor_frames_pain1, actor_run};
  140. mframe_t actor_frames_pain2 [] =
  141. {
  142. ai_move, -4, NULL,
  143. ai_move, 4, NULL,
  144. ai_move, 0, NULL
  145. };
  146. mmove_t actor_move_pain2 = {FRAME_pain201, FRAME_pain203, actor_frames_pain2, actor_run};
  147. mframe_t actor_frames_pain3 [] =
  148. {
  149. ai_move, -1, NULL,
  150. ai_move, 1, NULL,
  151. ai_move, 0, NULL
  152. };
  153. mmove_t actor_move_pain3 = {FRAME_pain301, FRAME_pain303, actor_frames_pain3, actor_run};
  154. mframe_t actor_frames_flipoff [] =
  155. {
  156. ai_turn, 0, NULL,
  157. ai_turn, 0, NULL,
  158. ai_turn, 0, NULL,
  159. ai_turn, 0, NULL,
  160. ai_turn, 0, NULL,
  161. ai_turn, 0, NULL,
  162. ai_turn, 0, NULL,
  163. ai_turn, 0, NULL,
  164. ai_turn, 0, NULL,
  165. ai_turn, 0, NULL,
  166. ai_turn, 0, NULL,
  167. ai_turn, 0, NULL,
  168. ai_turn, 0, NULL,
  169. ai_turn, 0, NULL
  170. };
  171. mmove_t actor_move_flipoff = {FRAME_flip01, FRAME_flip14, actor_frames_flipoff, actor_run};
  172. mframe_t actor_frames_taunt [] =
  173. {
  174. ai_turn, 0, NULL,
  175. ai_turn, 0, NULL,
  176. ai_turn, 0, NULL,
  177. ai_turn, 0, NULL,
  178. ai_turn, 0, NULL,
  179. ai_turn, 0, NULL,
  180. ai_turn, 0, NULL,
  181. ai_turn, 0, NULL,
  182. ai_turn, 0, NULL,
  183. ai_turn, 0, NULL,
  184. ai_turn, 0, NULL,
  185. ai_turn, 0, NULL,
  186. ai_turn, 0, NULL,
  187. ai_turn, 0, NULL,
  188. ai_turn, 0, NULL,
  189. ai_turn, 0, NULL,
  190. ai_turn, 0, NULL
  191. };
  192. mmove_t actor_move_taunt = {FRAME_taunt01, FRAME_taunt17, actor_frames_taunt, actor_run};
  193. char *messages[] =
  194. {
  195. "Watch it",
  196. "#$@*&",
  197. "Idiot",
  198. "Check your targets"
  199. };
  200. void actor_pain (edict_t *self, edict_t *other, float kick, int damage)
  201. {
  202. int n;
  203. if (self->health < (self->max_health / 2))
  204. self->s.skinnum = 1;
  205. if (level.time < self->pain_debounce_time)
  206. return;
  207. self->pain_debounce_time = level.time + 3;
  208. // gi.sound (self, CHAN_VOICE, actor.sound_pain, 1, ATTN_NORM, 0);
  209. if ((other->client) && (random() < 0.4))
  210. {
  211. vec3_t v;
  212. char *name;
  213. VectorSubtract (other->s.origin, self->s.origin, v);
  214. self->ideal_yaw = vectoyaw (v);
  215. if (random() < 0.5)
  216. self->monsterinfo.currentmove = &actor_move_flipoff;
  217. else
  218. self->monsterinfo.currentmove = &actor_move_taunt;
  219. name = actor_names[(self - g_edicts)%MAX_ACTOR_NAMES];
  220. gi.cprintf (other, PRINT_CHAT, "%s: %s!\n", name, messages[rand()%3]);
  221. return;
  222. }
  223. n = rand() % 3;
  224. if (n == 0)
  225. self->monsterinfo.currentmove = &actor_move_pain1;
  226. else if (n == 1)
  227. self->monsterinfo.currentmove = &actor_move_pain2;
  228. else
  229. self->monsterinfo.currentmove = &actor_move_pain3;
  230. }
  231. void actorMachineGun (edict_t *self)
  232. {
  233. vec3_t start, target;
  234. vec3_t forward, right;
  235. AngleVectors (self->s.angles, forward, right, NULL);
  236. G_ProjectSource (self->s.origin, monster_flash_offset[MZ2_ACTOR_MACHINEGUN_1], forward, right, start);
  237. if (self->enemy)
  238. {
  239. if (self->enemy->health > 0)
  240. {
  241. VectorMA (self->enemy->s.origin, -0.2, self->enemy->velocity, target);
  242. target[2] += self->enemy->viewheight;
  243. }
  244. else
  245. {
  246. VectorCopy (self->enemy->absmin, target);
  247. target[2] += (self->enemy->size[2] / 2);
  248. }
  249. VectorSubtract (target, start, forward);
  250. VectorNormalize (forward);
  251. }
  252. else
  253. {
  254. AngleVectors (self->s.angles, forward, NULL, NULL);
  255. }
  256. monster_fire_bullet (self, start, forward, 3, 4, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MZ2_ACTOR_MACHINEGUN_1);
  257. }
  258. void actor_dead (edict_t *self)
  259. {
  260. VectorSet (self->mins, -16, -16, -24);
  261. VectorSet (self->maxs, 16, 16, -8);
  262. self->movetype = MOVETYPE_TOSS;
  263. self->svflags |= SVF_DEADMONSTER;
  264. self->nextthink = 0;
  265. gi.linkentity (self);
  266. }
  267. mframe_t actor_frames_death1 [] =
  268. {
  269. ai_move, 0, NULL,
  270. ai_move, 0, NULL,
  271. ai_move, -13, NULL,
  272. ai_move, 14, NULL,
  273. ai_move, 3, NULL,
  274. ai_move, -2, NULL,
  275. ai_move, 1, NULL
  276. };
  277. mmove_t actor_move_death1 = {FRAME_death101, FRAME_death107, actor_frames_death1, actor_dead};
  278. mframe_t actor_frames_death2 [] =
  279. {
  280. ai_move, 0, NULL,
  281. ai_move, 7, NULL,
  282. ai_move, -6, NULL,
  283. ai_move, -5, NULL,
  284. ai_move, 1, NULL,
  285. ai_move, 0, NULL,
  286. ai_move, -1, NULL,
  287. ai_move, -2, NULL,
  288. ai_move, -1, NULL,
  289. ai_move, -9, NULL,
  290. ai_move, -13, NULL,
  291. ai_move, -13, NULL,
  292. ai_move, 0, NULL
  293. };
  294. mmove_t actor_move_death2 = {FRAME_death201, FRAME_death213, actor_frames_death2, actor_dead};
  295. void actor_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  296. {
  297. int n;
  298. // check for gib
  299. if (self->health <= -80)
  300. {
  301. // gi.sound (self, CHAN_VOICE, actor.sound_gib, 1, ATTN_NORM, 0);
  302. for (n= 0; n < 2; n++)
  303. ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
  304. for (n= 0; n < 4; n++)
  305. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  306. ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
  307. self->deadflag = DEAD_DEAD;
  308. return;
  309. }
  310. if (self->deadflag == DEAD_DEAD)
  311. return;
  312. // regular death
  313. // gi.sound (self, CHAN_VOICE, actor.sound_die, 1, ATTN_NORM, 0);
  314. self->deadflag = DEAD_DEAD;
  315. self->takedamage = DAMAGE_YES;
  316. n = rand() % 2;
  317. if (n == 0)
  318. self->monsterinfo.currentmove = &actor_move_death1;
  319. else
  320. self->monsterinfo.currentmove = &actor_move_death2;
  321. }
  322. void actor_fire (edict_t *self)
  323. {
  324. actorMachineGun (self);
  325. if (level.time >= self->monsterinfo.pausetime)
  326. self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
  327. else
  328. self->monsterinfo.aiflags |= AI_HOLD_FRAME;
  329. }
  330. mframe_t actor_frames_attack [] =
  331. {
  332. ai_charge, -2, actor_fire,
  333. ai_charge, -2, NULL,
  334. ai_charge, 3, NULL,
  335. ai_charge, 2, NULL
  336. };
  337. mmove_t actor_move_attack = {FRAME_attak01, FRAME_attak04, actor_frames_attack, actor_run};
  338. void actor_attack(edict_t *self)
  339. {
  340. int n;
  341. self->monsterinfo.currentmove = &actor_move_attack;
  342. n = (rand() & 15) + 3 + 7;
  343. self->monsterinfo.pausetime = level.time + n * FRAMETIME;
  344. }
  345. void actor_use (edict_t *self, edict_t *other, edict_t *activator)
  346. {
  347. vec3_t v;
  348. self->goalentity = self->movetarget = G_PickTarget(self->target);
  349. if ((!self->movetarget) || (strcmp(self->movetarget->classname, "target_actor") != 0))
  350. {
  351. gi.dprintf ("%s has bad target %s at %s\n", self->classname, self->target, vtos(self->s.origin));
  352. self->target = NULL;
  353. self->monsterinfo.pausetime = 100000000;
  354. self->monsterinfo.stand (self);
  355. return;
  356. }
  357. VectorSubtract (self->goalentity->s.origin, self->s.origin, v);
  358. self->ideal_yaw = self->s.angles[YAW] = vectoyaw(v);
  359. self->monsterinfo.walk (self);
  360. self->target = NULL;
  361. }
  362. /*QUAKED misc_actor (1 .5 0) (-16 -16 -24) (16 16 32)
  363. */
  364. void SP_misc_actor (edict_t *self)
  365. {
  366. if (deathmatch->value)
  367. {
  368. G_FreeEdict (self);
  369. return;
  370. }
  371. if (!self->targetname)
  372. {
  373. gi.dprintf("untargeted %s at %s\n", self->classname, vtos(self->s.origin));
  374. G_FreeEdict (self);
  375. return;
  376. }
  377. if (!self->target)
  378. {
  379. gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin));
  380. G_FreeEdict (self);
  381. return;
  382. }
  383. self->movetype = MOVETYPE_STEP;
  384. self->solid = SOLID_BBOX;
  385. self->s.modelindex = gi.modelindex("players/male/tris.md2");
  386. VectorSet (self->mins, -16, -16, -24);
  387. VectorSet (self->maxs, 16, 16, 32);
  388. if (!self->health)
  389. self->health = 100;
  390. self->mass = 200;
  391. self->pain = actor_pain;
  392. self->die = actor_die;
  393. self->monsterinfo.stand = actor_stand;
  394. self->monsterinfo.walk = actor_walk;
  395. self->monsterinfo.run = actor_run;
  396. self->monsterinfo.attack = actor_attack;
  397. self->monsterinfo.melee = NULL;
  398. self->monsterinfo.sight = NULL;
  399. self->monsterinfo.aiflags |= AI_GOOD_GUY;
  400. gi.linkentity (self);
  401. self->monsterinfo.currentmove = &actor_move_stand;
  402. self->monsterinfo.scale = MODEL_SCALE;
  403. walkmonster_start (self);
  404. // actors always start in a dormant state, they *must* be used to get going
  405. self->use = actor_use;
  406. }
  407. /*QUAKED target_actor (.5 .3 0) (-8 -8 -8) (8 8 8) JUMP SHOOT ATTACK x HOLD BRUTAL
  408. JUMP jump in set direction upon reaching this target
  409. SHOOT take a single shot at the pathtarget
  410. ATTACK attack pathtarget until it or actor is dead
  411. "target" next target_actor
  412. "pathtarget" target of any action to be taken at this point
  413. "wait" amount of time actor should pause at this point
  414. "message" actor will "say" this to the player
  415. for JUMP only:
  416. "speed" speed thrown forward (default 200)
  417. "height" speed thrown upwards (default 200)
  418. */
  419. void target_actor_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
  420. {
  421. vec3_t v;
  422. if (other->movetarget != self)
  423. return;
  424. if (other->enemy)
  425. return;
  426. other->goalentity = other->movetarget = NULL;
  427. if (self->message)
  428. {
  429. int n;
  430. edict_t *ent;
  431. for (n = 1; n <= game.maxclients; n++)
  432. {
  433. ent = &g_edicts[n];
  434. if (!ent->inuse)
  435. continue;
  436. gi.cprintf (ent, PRINT_CHAT, "%s: %s\n", actor_names[(other - g_edicts)%MAX_ACTOR_NAMES], self->message);
  437. }
  438. }
  439. if (self->spawnflags & 1) //jump
  440. {
  441. other->velocity[0] = self->movedir[0] * self->speed;
  442. other->velocity[1] = self->movedir[1] * self->speed;
  443. if (other->groundentity)
  444. {
  445. other->groundentity = NULL;
  446. other->velocity[2] = self->movedir[2];
  447. gi.sound(other, CHAN_VOICE, gi.soundindex("player/male/jump1.wav"), 1, ATTN_NORM, 0);
  448. }
  449. }
  450. if (self->spawnflags & 2) //shoot
  451. {
  452. }
  453. else if (self->spawnflags & 4) //attack
  454. {
  455. other->enemy = G_PickTarget(self->pathtarget);
  456. if (other->enemy)
  457. {
  458. other->goalentity = other->enemy;
  459. if (self->spawnflags & 32)
  460. other->monsterinfo.aiflags |= AI_BRUTAL;
  461. if (self->spawnflags & 16)
  462. {
  463. other->monsterinfo.aiflags |= AI_STAND_GROUND;
  464. actor_stand (other);
  465. }
  466. else
  467. {
  468. actor_run (other);
  469. }
  470. }
  471. }
  472. if (!(self->spawnflags & 6) && (self->pathtarget))
  473. {
  474. char *savetarget;
  475. savetarget = self->target;
  476. self->target = self->pathtarget;
  477. G_UseTargets (self, other);
  478. self->target = savetarget;
  479. }
  480. other->movetarget = G_PickTarget(self->target);
  481. if (!other->goalentity)
  482. other->goalentity = other->movetarget;
  483. if (!other->movetarget && !other->enemy)
  484. {
  485. other->monsterinfo.pausetime = level.time + 100000000;
  486. other->monsterinfo.stand (other);
  487. }
  488. else if (other->movetarget == other->goalentity)
  489. {
  490. VectorSubtract (other->movetarget->s.origin, other->s.origin, v);
  491. other->ideal_yaw = vectoyaw (v);
  492. }
  493. }
  494. void SP_target_actor (edict_t *self)
  495. {
  496. if (!self->targetname)
  497. gi.dprintf ("%s with no targetname at %s\n", self->classname, vtos(self->s.origin));
  498. self->solid = SOLID_TRIGGER;
  499. self->touch = target_actor_touch;
  500. VectorSet (self->mins, -8, -8, -8);
  501. VectorSet (self->maxs, 8, 8, 8);
  502. self->svflags = SVF_NOCLIENT;
  503. if (self->spawnflags & 1)
  504. {
  505. if (!self->speed)
  506. self->speed = 200;
  507. if (!st.height)
  508. st.height = 200;
  509. if (self->s.angles[YAW] == 0)
  510. self->s.angles[YAW] = 360;
  511. G_SetMovedir (self->s.angles, self->movedir);
  512. self->movedir[2] = st.height;
  513. }
  514. gi.linkentity (self);
  515. }