combat.qc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /* Copyright (C) 1996-2022 id Software LLC
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. See file, 'COPYING', for details.
  14. */
  15. // Yoder Sept24 2021 Horde Merge
  16. void() horde_spawn_powerup;
  17. void() T_MissileTouch;
  18. void() info_player_start;
  19. void(entity targ, entity attacker) ClientObituary;
  20. void() monster_death_use;
  21. //============================================================================
  22. /*
  23. ============
  24. CanDamage
  25. Returns true if the inflictor can directly damage the target. Used for
  26. explosions and melee attacks.
  27. ============
  28. */
  29. float(entity targ, entity inflictor) CanDamage =
  30. {
  31. // bmodels need special checking because their origin is 0,0,0
  32. if (targ.movetype == MOVETYPE_PUSH)
  33. {
  34. traceline(inflictor.origin, 0.5 * (targ.absmin + targ.absmax), TRUE, self);
  35. if (trace_fraction == 1)
  36. return TRUE;
  37. if (trace_ent == targ)
  38. return TRUE;
  39. return FALSE;
  40. }
  41. traceline(inflictor.origin, targ.origin, TRUE, self);
  42. if (trace_fraction == 1)
  43. return TRUE;
  44. traceline(inflictor.origin, targ.origin + '15 15 0', TRUE, self);
  45. if (trace_fraction == 1)
  46. return TRUE;
  47. traceline(inflictor.origin, targ.origin + '-15 -15 0', TRUE, self);
  48. if (trace_fraction == 1)
  49. return TRUE;
  50. traceline(inflictor.origin, targ.origin + '-15 15 0', TRUE, self);
  51. if (trace_fraction == 1)
  52. return TRUE;
  53. traceline(inflictor.origin, targ.origin + '15 -15 0', TRUE, self);
  54. if (trace_fraction == 1)
  55. return TRUE;
  56. return FALSE;
  57. };
  58. /*
  59. ============
  60. Killed
  61. ============
  62. */
  63. void(entity targ, entity attacker) Killed =
  64. {
  65. local entity oself;
  66. oself = self;
  67. self = targ;
  68. if (self.health < -99)
  69. self.health = -99; // don't let sbar look bad if a player
  70. if (self.movetype == MOVETYPE_PUSH || self.movetype == MOVETYPE_NONE)
  71. { // doors, triggers, etc
  72. if (self.classname == "misc_explobox" || self.classname == "misc_explobox2") // yoder add, 27/09/202 to let the SUB_UseTarges work
  73. self.enemy = attacker;
  74. self.th_die ();
  75. self = oself;
  76. return;
  77. }
  78. self.enemy = attacker;
  79. // Yoder March04 2022, punish team killspree
  80. if (cvar("horde") && (attacker.classname) == "player" && (targ.classname == "player"))
  81. {
  82. dprint("punish teamkill\n");
  83. attacker.killtime = 0;
  84. attacker.frags -= 2;
  85. }
  86. // bump the monster counter
  87. if (self.flags & FL_MONSTER)
  88. {
  89. // Yoder Sept24, 2021 Horde Merge
  90. if (horde_ent)
  91. {
  92. if (self.classname != "monster_zombie") // zombies don't count
  93. {
  94. killed_monsters = killed_monsters + 1;
  95. WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
  96. }
  97. // check kill spree
  98. if (attacker.classname == "player")
  99. {
  100. attacker.killspree++;
  101. attacker.killtime = time + KILLSPREE_GAP;
  102. if (time < attacker.killtime)
  103. {
  104. if (attacker.killspree >= 14)
  105. sprint(attacker, "$qc_horde_streak_generic", ftos(attacker.killspree));
  106. else if (attacker.killspree == 13)
  107. sprint(attacker, "$qc_horde_streak_13");
  108. else if (attacker.killspree == 12)
  109. sprint(attacker, "$qc_horde_streak_12");
  110. else if (attacker.killspree == 11)
  111. sprint(attacker, "$qc_horde_streak_11");
  112. else if (attacker.killspree == 10)
  113. sprint(attacker, "$qc_horde_streak_10");
  114. else if (attacker.killspree == 9)
  115. sprint(attacker, "$qc_horde_streak_9");
  116. else if (attacker.killspree == 8)
  117. sprint(attacker, "$qc_horde_streak_8");
  118. else if (attacker.killspree == 7)
  119. sprint(attacker, "$qc_horde_streak_7");
  120. else if (attacker.killspree == 6)
  121. sprint(attacker, "$qc_horde_streak_6");
  122. else if (attacker.killspree == 5)
  123. sprint(attacker, "$qc_horde_streak_5");
  124. else if (attacker.killspree == 4)
  125. sprint(attacker, "$qc_horde_streak_4");
  126. else if (attacker.killspree == 3)
  127. sprint(attacker, "$qc_horde_streak_3");
  128. else if (attacker.killspree == 2)
  129. sprint(attacker, "$qc_horde_streak_2");
  130. }
  131. }
  132. // check to see about spawning a powerup
  133. horde_spawn_powerup();
  134. }
  135. else // standard behavior
  136. {
  137. killed_monsters = killed_monsters + 1;
  138. WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
  139. }
  140. if (attacker.classname == "player")
  141. attacker.frags = attacker.frags + 1;
  142. if (attacker != self && attacker.flags & FL_MONSTER)
  143. {
  144. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  145. WriteString(MSG_ALL, "ACH_FRIENDLY_FIRE");
  146. }
  147. }
  148. ClientObituary(self, attacker);
  149. self.takedamage = DAMAGE_NO;
  150. self.touch = SUB_Null;
  151. monster_death_use();
  152. self.th_die ();
  153. self = oself;
  154. };
  155. /*
  156. ============
  157. T_Damage
  158. The damage is coming from inflictor, but get mad at attacker
  159. This should be the only function that ever reduces health.
  160. ============
  161. */
  162. void(entity targ, entity inflictor, entity attacker, float damage) T_Damage=
  163. {
  164. local vector dir;
  165. local entity oldself;
  166. local float save;
  167. local float take;
  168. if (!targ.takedamage)
  169. return;
  170. // Yoder add, September 9 2020
  171. if (targ.is_frozen)
  172. return;
  173. // used by buttons and triggers to set activator for target firing
  174. damage_attacker = attacker;
  175. // check for quad damage powerup on the attacker
  176. if (attacker.super_damage_finished > time)
  177. damage = damage * 4;
  178. // save damage based on the target's armor level
  179. save = ceil(targ.armortype*damage);
  180. if (save >= targ.armorvalue)
  181. {
  182. save = targ.armorvalue;
  183. targ.armortype = 0; // lost all armor
  184. targ.items = targ.items - (targ.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
  185. }
  186. targ.armorvalue = targ.armorvalue - save;
  187. take = ceil(damage-save);
  188. // add to the damage total for clients, which will be sent as a single
  189. // message at the end of the frame
  190. if (targ.flags & FL_CLIENT)
  191. {
  192. targ.dmg_take = targ.dmg_take + take;
  193. targ.dmg_save = targ.dmg_save + save;
  194. targ.dmg_inflictor = inflictor;
  195. }
  196. // figure momentum add
  197. if ( (inflictor != world) && (targ.movetype == MOVETYPE_WALK) )
  198. {
  199. dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
  200. dir = normalize(dir);
  201. targ.velocity = targ.velocity + dir*damage*8;
  202. }
  203. // check for godmode or invincibility
  204. if (targ.flags & FL_GODMODE)
  205. return;
  206. if (targ.invincible_finished >= time)
  207. {
  208. if (self.invincible_sound < time)
  209. {
  210. sound (targ, CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM);
  211. self.invincible_sound = time + 2;
  212. }
  213. return;
  214. }
  215. // team play damage avoidance
  216. if ( (teamplay == 1 && targ != attacker) && (targ.team > 0)&&(targ.team == attacker.team) )
  217. return;
  218. // special case for killable chthon (yoder, december 16 2020)
  219. if ((targ.classname == "monster_boss") && (targ.spawnflags & 2)) // is killable chthon
  220. {
  221. if (attacker.weapon == IT_LIGHTNING)
  222. {
  223. // TODO: Spawn blood
  224. dprint("Player has LG! Damage Chthon!\n");
  225. }
  226. else
  227. {
  228. dprint("player attacked with non-lightning weapon. Do nothing.\n");
  229. return;
  230. }
  231. }
  232. // do the damage
  233. targ.health = targ.health - take;
  234. if (targ.health <= 0)
  235. {
  236. Killed (targ, attacker);
  237. return;
  238. }
  239. // react to the damage
  240. oldself = self;
  241. self = targ;
  242. if ( (self.flags & FL_MONSTER) && attacker != world)
  243. {
  244. // get mad unless of the same class (except for soldiers)
  245. if (self != attacker && attacker != self.enemy)
  246. {
  247. if ( (self.classname != attacker.classname)
  248. || (self.classname == "monster_army" ) )
  249. {
  250. // yoder Sept24, 2021
  251. // if in horde mode, have enemies obey a reaggro time
  252. // TODO: Evaluate if we want this as default in co-op?
  253. if (cvar("horde"))
  254. {
  255. if ((self.enemy.classname == "player") && // current and new enemy are both players, check reaggro times
  256. (attacker.classname == "player"))
  257. {
  258. // check reaggro times
  259. if ((!self.aggro_time) ||
  260. (self.aggro_time + AGGRO_MIN + (random() * AGGRO_ADD < time)))
  261. {
  262. self.oldenemy = self.enemy;
  263. self.enemy = attacker;
  264. self.aggro_time = time;
  265. FoundTarget ();
  266. }
  267. else
  268. {
  269. // ignore new aggro from this hit
  270. dprint("ignore new aggro\n");
  271. }
  272. }
  273. else // immediately aggro, store the player if previous was player
  274. {
  275. if (self.enemy.classname == "player")
  276. self.oldenemy = self.enemy;
  277. self.enemy = attacker;
  278. FoundTarget ();
  279. }
  280. }
  281. else // original behavior
  282. {
  283. if (self.enemy.classname == "player")
  284. self.oldenemy = self.enemy;
  285. self.enemy = attacker;
  286. FoundTarget ();
  287. }
  288. }
  289. }
  290. }
  291. if (self.th_pain)
  292. {
  293. self.th_pain (attacker, take);
  294. // nightmare mode monsters don't go into pain frames often
  295. if (skill == 3)
  296. self.pain_finished = time + 5;
  297. }
  298. self = oldself;
  299. };
  300. /*
  301. ============
  302. T_RadiusDamage
  303. ============
  304. */
  305. void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
  306. {
  307. local float points;
  308. local entity head;
  309. local vector org;
  310. #ifdef GIB_DOWNED_ZOMBIES
  311. //Look for downed zombies and gib them if possible
  312. if(damage >= 60)
  313. {
  314. head = find(world, classname, "monster_zombie");
  315. while(head)
  316. {
  317. if(head.solid == SOLID_NOT)
  318. {
  319. org = head.origin + (head.mins + head.maxs)*0.5;
  320. points = 0.5*vlen (inflictor.origin - org);
  321. if (points < 0)
  322. {
  323. points = 0;
  324. }
  325. points = damage - points;
  326. if (points > 60)
  327. {
  328. if (CanDamage (head, inflictor))
  329. {
  330. Killed (head, attacker);
  331. }
  332. }
  333. }
  334. head = find(head, classname, "monster_zombie");
  335. }
  336. }
  337. #endif
  338. head = findradius(inflictor.origin, damage+40);
  339. while (head)
  340. {
  341. if (head != ignore)
  342. {
  343. if (head.takedamage)
  344. {
  345. org = head.origin + (head.mins + head.maxs)*0.5;
  346. points = 0.5*vlen (inflictor.origin - org);
  347. if (points < 0)
  348. points = 0;
  349. points = damage - points;
  350. if (head == attacker)
  351. points = points * 0.5;
  352. if (points > 0)
  353. {
  354. if (CanDamage (head, inflictor))
  355. { // shambler takes half damage from all explosions
  356. if (head.classname == "monster_shambler")
  357. T_Damage (head, inflictor, attacker, points*0.5);
  358. else
  359. T_Damage (head, inflictor, attacker, points);
  360. }
  361. }
  362. }
  363. }
  364. head = head.chain;
  365. }
  366. };
  367. /*
  368. ============
  369. T_BeamDamage
  370. ============
  371. */
  372. void(entity attacker, float damage) T_BeamDamage =
  373. {
  374. local float points;
  375. local entity head;
  376. head = findradius(attacker.origin, damage+40);
  377. while (head)
  378. {
  379. if (head.takedamage)
  380. {
  381. points = 0.5*vlen (attacker.origin - head.origin);
  382. if (points < 0)
  383. points = 0;
  384. points = damage - points;
  385. if (head == attacker)
  386. points = points * 0.5;
  387. if (points > 0)
  388. {
  389. if (CanDamage (head, attacker))
  390. {
  391. if (head.classname == "monster_shambler")
  392. T_Damage (head, attacker, attacker, points*0.5);
  393. else
  394. T_Damage (head, attacker, attacker, points);
  395. }
  396. }
  397. }
  398. head = head.chain;
  399. }
  400. };