combat.qc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. // combat.qc
  16. float IsExplosionDamage;
  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. self.th_die ();
  73. self = oself;
  74. return;
  75. }
  76. self.enemy = attacker;
  77. // bump the monster counter
  78. if (self.flags & FL_MONSTER)
  79. {
  80. killed_monsters = killed_monsters + 1;
  81. WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
  82. if (attacker.classname == "player")
  83. {
  84. attacker.frags = attacker.frags + 1;
  85. }
  86. if (attacker != self && attacker.flags & FL_MONSTER)
  87. {
  88. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  89. WriteString(MSG_ALL, "ACH_FRIENDLY_FIRE");
  90. }
  91. }
  92. // PGM - guarantee gib if killed by buzzsaw.
  93. if (attacker.classname == "buzzsaw" ||
  94. attacker.classname == "Vengeance" ||
  95. attacker.classname == "pendulum")
  96. self.health = -99;
  97. // PGM - gravity fix!
  98. self.gravity = 1.0;
  99. ClientObituary(self, attacker);
  100. self.takedamage = DAMAGE_NO;
  101. self.touch = SUB_Null;
  102. monster_death_use();
  103. self.th_die ();
  104. self = oself;
  105. };
  106. // ====
  107. // Function prototype for shield impact handler.
  108. // ====
  109. float(entity targ, entity inflictor, entity attacker, float damage) shield_hit;
  110. /*
  111. ============
  112. T_Damage
  113. The damage is coming from inflictor, but get mad at attacker
  114. This should be the only function that ever reduces health.
  115. ============
  116. */
  117. void(entity targ, entity inflictor, entity attacker, float damage) T_Damage=
  118. {
  119. local vector dir;
  120. local entity oldself;
  121. local float save;
  122. local float take;
  123. if (!targ.takedamage)
  124. return;
  125. // mal: in Coop, don't let bots hurt human teammates - that would be REALLY annoying...
  126. if ( coop && targ != attacker && targ.classname == "player" && attacker.classname == "player" ) {
  127. if ( attacker.flags & FL_ISBOT && !( targ.flags & FL_ISBOT ) ) {
  128. return;
  129. }
  130. }
  131. if (targ.classname == "trigger_explosion")
  132. {
  133. if ( IsExplosionDamage != 1)
  134. return;
  135. }
  136. IsExplosionDamage = 0;
  137. if (targ.items2 & IT2_SHIELD)
  138. {
  139. // Allow some damage to pass through.
  140. damage = shield_hit(targ, inflictor, attacker, damage);
  141. if (damage == 0)
  142. return;
  143. }
  144. // used by buttons and triggers to set activator for target firing
  145. damage_attacker = attacker;
  146. // check for quad damage powerup on the attacker
  147. if (attacker.super_damage_finished > time)
  148. damage = damage * 4;
  149. // rune power up (Black Magic)
  150. if (deathmatch)
  151. damage = RuneApplyBlack(damage, attacker);
  152. // save damage based on the target's armor level
  153. //ZOID--
  154. if (TeamArmorDam(targ, inflictor, attacker, damage))
  155. save = ceil(targ.armortype*damage);
  156. else
  157. save = 0;
  158. //--ZOID
  159. if (save >= targ.armorvalue)
  160. {
  161. save = targ.armorvalue;
  162. targ.armortype = 0; // lost all armor
  163. targ.items2 = targ.items2 -
  164. (targ.items2 & (IT2_ARMOR1 | IT2_ARMOR2 | IT2_ARMOR3));
  165. }
  166. targ.armorvalue = targ.armorvalue - save;
  167. take = ceil(damage-save);
  168. // add to the damage total for clients, which will be sent as a single
  169. // message at the end of the frame
  170. // FIXME: remove after combining shotgun blasts?
  171. if (targ.flags & FL_CLIENT)
  172. {
  173. targ.dmg_take = targ.dmg_take + take;
  174. targ.dmg_save = targ.dmg_save + save;
  175. targ.dmg_inflictor = inflictor;
  176. }
  177. // figure momentum add
  178. if ( (inflictor != world) && (targ.movetype == MOVETYPE_WALK) )
  179. {
  180. dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
  181. dir = normalize(dir);
  182. targ.velocity = targ.velocity + dir*damage*8;
  183. }
  184. // check for godmode or invincibility
  185. if (targ.flags & FL_GODMODE)
  186. return;
  187. if (targ.invincible_finished >= time)
  188. {
  189. if (targ.invincible_sound < time)
  190. {
  191. sound (targ, CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM);
  192. targ.invincible_sound = time + 2;
  193. }
  194. return;
  195. }
  196. // team play damage avoidance
  197. // if ( (teamplay == 1) && (targ.team > 0)&&(targ.team == attacker.team) )
  198. // return;
  199. //ZOID--
  200. if (!TeamHealthDam(targ, inflictor, attacker, damage))
  201. return; // same team
  202. //--ZOID
  203. // rune power up (Earth Magic)
  204. if (deathmatch)
  205. take = RuneApplyEarth(take, targ);
  206. // do the damage
  207. targ.health = targ.health - take;
  208. if (targ.health <= 0)
  209. {
  210. Killed (targ, attacker);
  211. return;
  212. }
  213. // react to the damage
  214. oldself = self;
  215. self = targ;
  216. if ( (self.flags & FL_MONSTER) && attacker != world)
  217. {
  218. // get mad unless of the same class (except for soldiers)
  219. if (self != attacker && attacker != self.enemy)
  220. {
  221. if ( (self.classname != attacker.classname)
  222. || (self.classname == "monster_army" ) )
  223. {
  224. if ( self.classname != "monster_dragon")
  225. {
  226. if (self.enemy.classname == "player")
  227. self.oldenemy = self.enemy;
  228. self.enemy = attacker;
  229. FoundTarget ();
  230. }
  231. }
  232. }
  233. }
  234. if (self.th_pain)
  235. {
  236. self.th_pain (attacker, take);
  237. // nightmare mode monsters don't go into pain frames often
  238. if (skill == 3)
  239. self.pain_finished = time + 5;
  240. }
  241. self = oldself;
  242. };
  243. /*
  244. ============
  245. T_EELZap
  246. ============
  247. */
  248. void(entity inflictor, entity attacker, float damage) T_EELZap =
  249. {
  250. local float points;
  251. local entity head;
  252. local vector org;
  253. head = findradius(inflictor.origin, damage+40);
  254. while (head)
  255. {
  256. if (head.takedamage)
  257. {
  258. org = head.origin + (head.mins + head.maxs)*0.5;
  259. points = 0.5*vlen (inflictor.origin - org);
  260. if (points < 0)
  261. points = 0;
  262. points = damage - points;
  263. if (head == attacker)
  264. points = points * 0.5;
  265. if (points > 0)
  266. {
  267. if (CanDamage (head, inflictor))
  268. { // eels take no damage from this attack
  269. if (head.classname != "monster_eel" &&
  270. (head.flags & FL_INWATER))
  271. T_Damage (head, inflictor, attacker, points);
  272. }
  273. }
  274. }
  275. head = head.chain;
  276. }
  277. };
  278. /*
  279. ============
  280. T_RadiusDamage
  281. ============
  282. */
  283. void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
  284. {
  285. local float points;
  286. local entity head;
  287. local vector org;
  288. IsExplosionDamage = 1;
  289. head = findradius(inflictor.origin, damage+40);
  290. while (head)
  291. {
  292. if (head != ignore)
  293. {
  294. if (head.takedamage)
  295. {
  296. org = head.origin + (head.mins + head.maxs)*0.5;
  297. points = 0.5*vlen (inflictor.origin - org);
  298. if (points < 0)
  299. points = 0;
  300. points = damage - points;
  301. if (head == attacker)
  302. points = points * 0.5;
  303. if (points > 0)
  304. {
  305. if (CanDamage (head, inflictor))
  306. { // shambler takes half damage from all explosions
  307. if (head.classname == "monster_shambler")
  308. T_Damage (head, inflictor, attacker, points*0.5);
  309. else
  310. T_Damage (head, inflictor, attacker, points);
  311. }
  312. }
  313. }
  314. }
  315. head = head.chain;
  316. }
  317. };
  318. /*
  319. ============
  320. T_BeamDamage
  321. ============
  322. */
  323. void(entity attacker, float damage) T_BeamDamage =
  324. {
  325. local float points;
  326. local entity head;
  327. head = findradius(attacker.origin, damage+40);
  328. while (head)
  329. {
  330. if (head.takedamage)
  331. {
  332. points = 0.5*vlen (attacker.origin - head.origin);
  333. if (points < 0)
  334. points = 0;
  335. points = damage - points;
  336. if (head == attacker)
  337. points = points * 0.5;
  338. if (points > 0)
  339. {
  340. if (CanDamage (head, attacker))
  341. {
  342. if (head.classname == "monster_shambler")
  343. T_Damage (head, attacker, attacker, points*0.5);
  344. else
  345. T_Damage (head, attacker, attacker, points);
  346. }
  347. }
  348. }
  349. head = head.chain;
  350. }
  351. };