]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_damage.c
give kill credit for hazard deaths to whoever pushed you into the hazard, 15 second...
[divverent/nexuiz.git] / qcsrc / gamec / g_damage.c
1
2 float checkrules_firstblood;
3 void Obituary (entity attacker, entity targ, float deathtype)
4 {
5         string  s;
6
7         if (targ.classname == "player" || targ.classname == "corpse")
8         {
9                 if (targ.classname == "corpse")
10                         s = "A corpse";
11                 else
12                         s = targ.netname;
13
14                 if (targ == attacker)
15                 {
16                         if (deathtype == IT_GRENADE_LAUNCHER)
17                                 bprint ("^1",s, " detonated\n");
18                         else if (deathtype == IT_ELECTRO)
19                                 bprint ("^1",s, " played with plasma\n");
20                         else if (deathtype == IT_ROCKET_LAUNCHER)
21                                 bprint ("^1",s, " exploded\n");
22                         else if (deathtype == DEATH_KILL)
23                                 bprint ("^1",s, " couldn't take it anymore\n");
24                         else
25                                 bprint ("^1",s, " couldn't resist the urge to self immolate\n");
26                         targ.frags = targ.frags - 1;
27                         if (targ.killcount > 2)
28                                 bprint ("^1",s," ended it all with a ",ftos(targ.killcount)," kill spree\n");
29                 }
30                 else if (teamplay && attacker.team == targ.team)
31                 {
32                         bprint ("^1", attacker.netname, " mows down a teammate\n");
33                         attacker.frags = attacker.frags - 1;
34                         if (targ.killcount > 2)
35                                 bprint ("^1",s,"'s ",ftos(targ.killcount)," kill spree was endeded by a teammate!\n");
36                         if (attacker.killcount > 2)
37                                 bprint ("^1",attacker.netname," ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
38                         attacker.killcount = 0;
39                 }
40                 else if (attacker.classname == "player" || attacker.classname == "gib")
41                 {
42                         if (!checkrules_firstblood)
43                         {
44                                 checkrules_firstblood = TRUE;
45                                 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
46                                 bprint("^1",attacker.netname, " drew first blood", "\n");
47                         }
48
49                         if (deathtype == IT_LASER)
50                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
51                         else if (deathtype == IT_UZI)
52                                 bprint ("^1",s, " was riddled full of holes by ", attacker.netname, "\n");
53                         else if (deathtype == IT_SHOTGUN)
54                                 bprint ("^1",s, " was gunned by ", attacker.netname, "\n");
55                         else if (deathtype == IT_GRENADE_LAUNCHER)
56                                 bprint ("^1", s, " was blasted by ", attacker.netname, "\n");
57                         else if (deathtype == IT_ELECTRO)
58                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
59                         else if (deathtype == IT_CRYLINK)
60                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
61                         else if (deathtype == IT_NEX)
62                                 bprint ("^1",s, " has been vaporized by ", attacker.netname, "\n");
63                         else if (deathtype == IT_HAGAR)
64                                 bprint ("^1",s, " was pummeled by ", attacker.netname, "\n");
65                         else if (deathtype == IT_ROCKET_LAUNCHER)
66                                 bprint ("^1",s, " was blasted by ", attacker.netname, "\n");
67                         else if (deathtype == DEATH_TELEFRAG)
68                                 bprint ("^1",s, " was telefragged by ", attacker.netname, "\n");
69                         else if (deathtype == DEATH_DROWN)
70                                 bprint ("^1",s, " was drowned by ", attacker.netname, "\n");
71                         else if (deathtype == DEATH_SLIME)
72                                 bprint ("^1",s, " was slimed by ", attacker.netname, "\n");
73                         else if (deathtype == DEATH_LAVA)
74                                 bprint ("^1",s, " was cooked by ", attacker.netname, "\n");
75                         else if (deathtype == DEATH_FALL)
76                                 bprint ("^1",s, " was grounded by ", attacker.netname, "\n");
77                         else if (deathtype == DEATH_HURTTRIGGER)
78                                 bprint ("^1",s, " was thrown into a world of hurt by ", attacker.netname, "\n");
79                         else
80                                 bprint ("^1",s, " was killed by ", attacker.netname, "\n");
81
82                         attacker.frags = attacker.frags + 1;
83                         if (targ.killcount > 2)
84                                 bprint ("^1",s,"'s ", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
85                         attacker.killcount = attacker.killcount + 1;
86                         if (attacker.killcount > 2)
87                                 bprint ("^1",attacker.netname," has ",ftos(attacker.killcount)," kills in a row\n");
88                 }
89                 else
90                 {
91                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
92                                 bprint ("^1",s, " ", attacker.message, "\n");
93                         else if (deathtype == DEATH_DROWN)
94                                 bprint ("^1",s, " drowned\n");
95                         else if (deathtype == DEATH_SLIME)
96                                 bprint ("^1",s, " was slimed\n");
97                         else if (deathtype == DEATH_LAVA)
98                                 bprint ("^1",s, " turned into hot slag\n");
99                         else if (deathtype == DEATH_FALL)
100                                 bprint ("^1",s, " hit the ground with a crunch\n");
101                         else
102                                 bprint ("^1",s, " died\n");
103                         targ.frags = targ.frags - 1;
104                         if (targ.killcount > 2)
105                                 bprint ("^1",s," died with a ",ftos(targ.killcount)," kill spree\n");
106                 }
107                 // FIXME: this should go in PutClientInServer
108                 if (targ.killcount)
109                         targ.killcount = 0;
110         }
111 }
112
113 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
114 {
115         local entity oldself;
116         oldself = self;
117         self = targ;
118         // nullify damage if teamplay is on
119         if (teamplay)
120         if (attacker.team)
121         if (attacker.team == targ.team)
122         if (teamplay == 1 || (teamplay == 3 && attacker != targ))
123                 damage = 0;
124         // apply strength multiplier
125         if (attacker.items & IT_STRENGTH)
126         {
127                 damage = damage * cvar("g_balance_powerup_strength_damage");
128                 force = force * cvar("g_balance_powerup_strength_force");
129         }
130         // apply invincibility multiplier
131         if (targ.items & IT_INVINCIBLE)
132                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
133         // apply push
134         if (self.damageforcescale)
135         {
136                 self.velocity = self.velocity + self.damageforcescale * force;
137                 self.flags = self.flags - (self.flags & FL_ONGROUND);
138         }
139         // apply damage
140         if (self.event_damage)
141                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
142         self = oldself;
143
144         // Savage: vampire mode
145         if(cvar("g_vampire") && targ.classname == "player" && attacker.classname == "player" && attacker != targ) {
146                 attacker.health += damage;
147         }
148 }
149
150 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
151 {
152         entity  targ;
153         float   finaldmg;
154         float   power;
155         vector  blastorigin;
156         vector  force;
157         vector  m1;
158         vector  m2;
159         vector  nearest;
160         vector  diff;
161
162         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
163
164         targ = findradius (blastorigin, rad);
165         while (targ)
166         {
167                 if (targ != inflictor)
168                         if (ignore != targ)
169                         {
170                                 // LordHavoc: measure distance to nearest point on target (not origin)
171                                 // (this guarentees 100% damage on a touch impact)
172                                 nearest = blastorigin;
173                                 m1 = targ.origin + targ.mins;
174                                 m2 = targ.origin + targ.maxs;
175                                 if (nearest_x < m1_x) nearest_x = m1_x;
176                                 if (nearest_y < m1_y) nearest_y = m1_y;
177                                 if (nearest_z < m1_z) nearest_z = m1_z;
178                                 if (nearest_x > m2_x) nearest_x = m2_x;
179                                 if (nearest_y > m2_y) nearest_y = m2_y;
180                                 if (nearest_z > m2_z) nearest_z = m2_z;
181                                 diff = nearest - blastorigin;
182                                 // round up a little on the damage to ensure full damage on impacts
183                                 // and turn the distance into a fraction of the radius
184                                 power = 1 - ((vlen (diff) - 2) / rad);
185                                 //bprint(" ");
186                                 //bprint(ftos(power));
187                                 if (power > 0)
188                                 {
189                                         if (power > 1)
190                                                 power = 1;
191                                         finaldmg = coredamage * power + edgedamage * (1 - power);
192                                         if (finaldmg > 0)
193                                         {
194                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
195                                                 if (targ == attacker)
196                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
197                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
198                                         }
199                                 }
200                         }
201                 targ = targ.chain;
202         }
203 }
204
205 /*
206 entity  multi_ent;
207 float   multi_damage;
208 vector  multi_force;
209
210 void ClearMultiDamage (void)
211 {
212         multi_ent = world;
213         multi_damage = 0;
214         multi_force = '0 0 0';
215 }
216
217 void ApplyMultiDamage (void)
218 {
219         if (!multi_ent)
220                 return;
221
222         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
223 }
224
225 void AddMultiDamage (entity hit, float damage, vector force)
226 {
227         if (!hit)
228                 return;
229
230         if (hit != multi_ent)
231         {
232                 ApplyMultiDamage ();
233                 ClearMultiDamage ();
234                 multi_ent = hit;
235         }
236         multi_damage = multi_damage + damage;
237         multi_force = multi_force + force;
238 }
239
240 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
241 {
242         vector  direction;
243         vector  source;
244         vector  vel;
245         vector  org;
246
247         makevectors (self.v_angle);
248
249         source = self.origin + v_forward * 10;  // FIXME
250         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
251
252         // LordHavoc: better to use normal damage
253         //ClearMultiDamage ();
254         while (shotcount > 0)
255         {
256                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
257
258                 traceline (source, source + direction * 2048, FALSE, self);
259                 if (trace_fraction != 1.0)
260                 {
261                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
262                         vel = vel + 2 * trace_plane_normal;
263                         vel = vel * 200;
264
265                         org = trace_endpos - direction * 4;
266
267                         if (!trace_ent.takedamage)
268                                 te_gunshot (org);
269                         // LordHavoc: better to use normal damage
270                         //AddMultiDamage (trace_ent, 4, direction * 4);
271                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
272                 }
273
274                 shotcount = shotcount + 1;
275         }
276
277         // LordHavoc: better to use normal damage
278         //ApplyMultiDamage ();
279 }
280 */