]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/gamec/g_damage.c
apply KadaverJack's patch to avoid slime damage when gameover
[divverent/nexuiz.git] / data / qcsrc / gamec / g_damage.c
1
2 float checkrules_firstblood;
3
4 void GiveFrags (entity attacker, entity targ, float f)
5 {
6         if(f > 0 && cvar("g_domination") && cvar("g_domination_disable_frags"))
7                 return;
8         else if(f > 0 && cvar("g_runematch"))
9                 f = RunematchHandleFrags(attacker, targ, f);
10
11         if(f)
12                 attacker.frags = attacker.frags + f;
13 }
14
15 void Obituary (entity attacker, entity targ, float deathtype)
16 {
17         string  s;
18
19         if (targ.classname == "player" || targ.classname == "corpse")
20         {
21                 if (targ.classname == "corpse")
22                         s = "A corpse";
23                 else
24                         s = targ.netname;
25
26                 if (targ == attacker)
27                 {
28                         if (deathtype == IT_GRENADE_LAUNCHER)
29                                 bprint ("^1",s, " detonated\n");
30                         else if (deathtype == IT_ELECTRO)
31                                 bprint ("^1",s, " played with plasma\n");
32                         else if (deathtype == IT_ROCKET_LAUNCHER)
33                                 bprint ("^1",s, " exploded\n");
34                         else if (deathtype == DEATH_KILL)
35                                 bprint ("^1",s, " couldn't take it anymore\n");
36                         else
37                                 bprint ("^1",s, " couldn't resist the urge to self-destruct\n");
38                         GiveFrags(attacker, targ, -1);
39                         //targ.frags = targ.frags - 1;
40                         if (targ.killcount > 2)
41                                 bprint ("^1",s," ended it all with a ",ftos(targ.killcount)," kill spree\n");
42                 }
43                 else if (teamplay && attacker.team == targ.team)
44                 {
45                         bprint ("^1", attacker.netname, " mows down a teammate\n");
46                         GiveFrags(attacker, targ, -1);
47                         //attacker.frags = attacker.frags - 1;
48                         if (targ.killcount > 2)
49                                 bprint ("^1",s,"'s ",ftos(targ.killcount)," kill spree was endeded by a teammate!\n");
50                         if (attacker.killcount > 2)
51                                 bprint ("^1",attacker.netname," ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
52                         attacker.killcount = 0;
53                 }
54                 else if (attacker.classname == "player" || attacker.classname == "gib")
55                 {
56                         if (!checkrules_firstblood)
57                         {
58                                 checkrules_firstblood = TRUE;
59                                 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
60                                 bprint("^1",attacker.netname, " drew first blood", "\n");
61                         }
62
63                         if (deathtype == IT_LASER)
64                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
65                         else if (deathtype == IT_UZI)
66                                 bprint ("^1",s, " was riddled full of holes by ", attacker.netname, "\n");
67                         else if (deathtype == IT_SHOTGUN)
68                                 bprint ("^1",s, " was gunned by ", attacker.netname, "\n");
69                         else if (deathtype == IT_GRENADE_LAUNCHER)
70                                 bprint ("^1", s, " was blasted by ", attacker.netname, "\n");
71                         else if (deathtype == IT_ELECTRO)
72                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
73                         else if (deathtype == IT_CRYLINK)
74                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
75                         else if (deathtype == IT_NEX)
76                                 bprint ("^1",s, " has been vaporized by ", attacker.netname, "\n");
77                         else if (deathtype == IT_HAGAR)
78                                 bprint ("^1",s, " was pummeled by ", attacker.netname, "\n");
79                         else if (deathtype == IT_ROCKET_LAUNCHER)
80                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
81                         else if (deathtype == DEATH_TELEFRAG)
82                                 bprint ("^1",s, " was telefragged by ", attacker.netname, "\n");
83                         else if (deathtype == DEATH_DROWN)
84                                 bprint ("^1",s, " was drowned by ", attacker.netname, "\n");
85                         else if (deathtype == DEATH_SLIME)
86                                 bprint ("^1",s, " was slimed by ", attacker.netname, "\n");
87                         else if (deathtype == DEATH_LAVA)
88                                 bprint ("^1",s, " was cooked by ", attacker.netname, "\n");
89                         else if (deathtype == DEATH_FALL)
90                                 bprint ("^1",s, " was grounded by ", attacker.netname, "\n");
91                         else if (deathtype == DEATH_HURTTRIGGER)
92                                 bprint ("^1",s, " was thrown into a world of hurt by ", attacker.netname, "\n");
93                         else
94                                 bprint ("^1",s, " was killed by ", attacker.netname, "\n");
95
96                         GiveFrags(attacker, targ, 1);
97                         //attacker.frags = attacker.frags + 1;
98                         if (targ.killcount > 2)
99                                 bprint ("^1",s,"'s ", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
100                         attacker.killcount = attacker.killcount + 1;
101                         if (attacker.killcount > 2)
102                                 bprint ("^1",attacker.netname," has ",ftos(attacker.killcount)," kills in a row\n");
103                 }
104                 else
105                 {
106                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
107                                 bprint ("^1",s, " ", attacker.message, "\n");
108                         else if (deathtype == DEATH_DROWN)
109                                 bprint ("^1",s, " drowned\n");
110                         else if (deathtype == DEATH_SLIME)
111                                 bprint ("^1",s, " was slimed\n");
112                         else if (deathtype == DEATH_LAVA)
113                                 bprint ("^1",s, " turned into hot slag\n");
114                         else if (deathtype == DEATH_FALL)
115                                 bprint ("^1",s, " hit the ground with a crunch\n");
116                         else
117                                 bprint ("^1",s, " died\n");
118                         GiveFrags(targ, targ, -1);
119                         //targ.frags = targ.frags - 1;
120                         if (targ.killcount > 2)
121                                 bprint ("^1",s," died with a ",ftos(targ.killcount)," kill spree\n");
122                 }
123                 // FIXME: this should go in PutClientInServer
124                 if (targ.killcount)
125                         targ.killcount = 0;
126         }
127 }
128
129 // these are updated by each Damage call for use in button triggering and such
130 entity damage_targ;
131 entity damage_inflictor;
132 entity damage_attacker;
133
134 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
135 {
136
137
138         if (gameover && deathtype != DEATH_KILL)
139                 return;
140
141         local entity oldself;
142         oldself = self;
143         self = targ;
144         damage_targ = targ;
145         damage_inflictor = inflictor;
146         damage_attacker = attacker;     
147         // nullify damage if teamplay is on
148         if (teamplay)
149         if (attacker.team)
150         if (attacker.team == targ.team)
151         if (teamplay == 1 || (teamplay == 3 && attacker != targ))
152                 damage = 0;
153
154         // midair gamemode: damage only while in the air
155         if (cvar("g_midair")
156             && self.classname == "player" // e.g. grenades take damage
157             && self.flags & FL_ONGROUND) {
158                 damage = 0;
159         }
160
161         // apply strength multiplier
162         if (attacker.items & IT_STRENGTH)
163         {
164                 damage = damage * cvar("g_balance_powerup_strength_damage");
165                 force = force * cvar("g_balance_powerup_strength_force");
166         }
167         // apply invincibility multiplier
168         if (targ.items & IT_INVINCIBLE)
169                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
170
171
172         if(cvar("g_runematch"))
173         {
174                 // apply strength rune
175                 if (attacker.runes & RUNE_STRENGTH)
176                 {
177                         if(attacker.runes & CURSE_WEAK) // have both curse & rune
178                         {
179                                 damage = damage * cvar("g_balance_rune_strength_combo_damage");
180                                 force = force * cvar("g_balance_rune_strength_combo_force");
181                         }
182                         else
183                         {
184                                 damage = damage * cvar("g_balance_rune_strength_damage");
185                                 force = force * cvar("g_balance_rune_strength_force");
186                         }
187                 }
188                 else if (attacker.runes & CURSE_WEAK)
189                 {
190                         damage = damage * cvar("g_balance_curse_weak_damage");
191                         force = force * cvar("g_balance_curse_weak_force");
192                 }
193
194                 // apply defense rune
195                 if (targ.runes & RUNE_DEFENSE)
196                 {
197                         if (targ.runes & CURSE_VULNER) // have both curse & rune
198                                 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
199                         else
200                                 damage = damage * cvar("g_balance_rune_defense_takedamage");
201                 }
202                 else if (targ.runes & CURSE_VULNER)
203                         damage = damage * cvar("g_balance_curse_vulner_takedamage");
204         }
205
206         // apply push
207         if (self.damageforcescale)
208         {
209                 self.velocity = self.velocity + self.damageforcescale * force;
210                 self.flags = self.flags - (self.flags & FL_ONGROUND);
211         }
212         // apply damage
213         if (self.event_damage)
214                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
215         self = oldself;
216
217         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
218         {
219                 // Savage: vampire mode
220                 if(cvar("g_vampire"))
221                 {
222                         attacker.health += damage;
223                 }
224                 if(cvar("g_runematch"))
225                 {
226                         if (attacker.runes & RUNE_VAMPIRE)
227                         {
228                         // apply vampire rune
229                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
230                                 {
231                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
232                                         attacker.health = bound(
233                                                 3, 
234                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"), 
235                                                 1000);
236                                 }
237                                 else
238                                 {
239                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
240                                         attacker.health = bound(
241                                                 3, 
242                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"), 
243                                                 1000);
244                                 }
245                         }
246                         // apply empathy curse
247                         else if (attacker.runes & CURSE_EMPATHY)
248                         {
249                                 attacker.health = bound(
250                                         3, 
251                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"), 
252                                         attacker.health);
253                         }
254                 }
255         }
256 }
257
258 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
259 {
260         entity  targ;
261         float   finaldmg;
262         float   power;
263         vector  blastorigin;
264         vector  force;
265         vector  m1;
266         vector  m2;
267         vector  nearest;
268         vector  diff;
269
270         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
271
272         targ = findradius (blastorigin, rad);
273         while (targ)
274         {
275                 if (targ != inflictor)
276                         if (ignore != targ)
277                         {
278                                 // LordHavoc: measure distance to nearest point on target (not origin)
279                                 // (this guarentees 100% damage on a touch impact)
280                                 nearest = blastorigin;
281                                 m1 = targ.origin + targ.mins;
282                                 m2 = targ.origin + targ.maxs;
283                                 if (nearest_x < m1_x) nearest_x = m1_x;
284                                 if (nearest_y < m1_y) nearest_y = m1_y;
285                                 if (nearest_z < m1_z) nearest_z = m1_z;
286                                 if (nearest_x > m2_x) nearest_x = m2_x;
287                                 if (nearest_y > m2_y) nearest_y = m2_y;
288                                 if (nearest_z > m2_z) nearest_z = m2_z;
289                                 diff = nearest - blastorigin;
290                                 // round up a little on the damage to ensure full damage on impacts
291                                 // and turn the distance into a fraction of the radius
292                                 power = 1 - ((vlen (diff) - 2) / rad);
293                                 //bprint(" ");
294                                 //bprint(ftos(power));
295                                 if (power > 0)
296                                 {
297                                         if (power > 1)
298                                                 power = 1;
299                                         finaldmg = coredamage * power + edgedamage * (1 - power);
300                                         if (finaldmg > 0)
301                                         {
302                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
303                                                 if (targ == attacker)
304                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
305                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
306                                         }
307                                 }
308                         }
309                 targ = targ.chain;
310         }
311 }
312
313 /*
314 entity  multi_ent;
315 float   multi_damage;
316 vector  multi_force;
317
318 void ClearMultiDamage (void)
319 {
320         multi_ent = world;
321         multi_damage = 0;
322         multi_force = '0 0 0';
323 }
324
325 void ApplyMultiDamage (void)
326 {
327         if (!multi_ent)
328                 return;
329
330         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
331 }
332
333 void AddMultiDamage (entity hit, float damage, vector force)
334 {
335         if (!hit)
336                 return;
337
338         if (hit != multi_ent)
339         {
340                 ApplyMultiDamage ();
341                 ClearMultiDamage ();
342                 multi_ent = hit;
343         }
344         multi_damage = multi_damage + damage;
345         multi_force = multi_force + force;
346 }
347
348 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
349 {
350         vector  direction;
351         vector  source;
352         vector  vel;
353         vector  org;
354
355         makevectors (self.v_angle);
356
357         source = self.origin + v_forward * 10;  // FIXME
358         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
359
360         // LordHavoc: better to use normal damage
361         //ClearMultiDamage ();
362         while (shotcount > 0)
363         {
364                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
365
366                 traceline (source, source + direction * 2048, FALSE, self);
367                 if (trace_fraction != 1.0)
368                 {
369                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
370                         vel = vel + 2 * trace_plane_normal;
371                         vel = vel * 200;
372
373                         org = trace_endpos - direction * 4;
374
375                         if (!trace_ent.takedamage)
376                                 te_gunshot (org);
377                         // LordHavoc: better to use normal damage
378                         //AddMultiDamage (trace_ent, 4, direction * 4);
379                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
380                 }
381
382                 shotcount = shotcount + 1;
383         }
384
385         // LordHavoc: better to use normal damage
386         //ApplyMultiDamage ();
387 }
388 */