m_actor.c 13 KB

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