]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_damage.c
disabled the 'has taken the lead' till it works
[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")
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
70                                 bprint ("^1",s, " was killed by ", attacker.netname, "\n");
71
72                         attacker.frags = attacker.frags + 1;
73                         if (targ.killcount > 2)
74                                 bprint ("^1",s,"'s ", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
75                         attacker.killcount = attacker.killcount + 1;
76                         if (attacker.killcount > 2)
77                                 bprint ("^1",attacker.netname," has ",ftos(attacker.killcount)," kills in a row\n");
78                 }
79                 else
80                 {
81                         if (deathtype == DEATH_HURTTRIGGER)
82                                 bprint ("^1",s, " ", attacker.message, "\n");
83                         else if (deathtype == DEATH_DROWN)
84                                 bprint ("^1",s, " drowned\n");
85                         else if (deathtype == DEATH_SLIME)
86                                 bprint ("^1",s, " was slimed\n");
87                         else if (deathtype == DEATH_LAVA)
88                                 bprint ("^1",s, " turned into hot slag\n");
89                         else if (deathtype == DEATH_FALL)
90                                 bprint ("^1",s, " hit the ground with a crunch\n");
91                         targ.frags = targ.frags - 1;
92                         if (targ.killcount > 2)
93                                 bprint ("^1",s," died with a ",ftos(targ.killcount)," kill spree\n");
94                 }
95                 // FIXME: this should go in PutClientInServer
96                 if (targ.killcount)
97                         targ.killcount = 0;
98         }
99 }
100
101 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
102 {
103         local entity oldself;
104         oldself = self;
105         self = targ;
106         // nullify damage if teamplay is on
107         if (teamplay)
108         if (attacker.team)
109         if (attacker.team == targ.team)
110         if (teamplay == 1 || (teamplay == 3 && attacker != targ))
111                 damage = 0;
112         // apply strength multiplier
113         if (attacker.items & IT_STRENGTH)
114         {
115                 damage = damage * cvar("g_balance_powerup_strength_damage");
116                 force = force * cvar("g_balance_powerup_strength_force");
117         }
118         // apply invincibility multiplier
119         if (targ.items & IT_INVINCIBLE)
120                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
121         // apply push
122         if (self.damageforcescale)
123         {
124                 self.velocity = self.velocity + self.damageforcescale * force;
125                 self.flags = self.flags - (self.flags & FL_ONGROUND);
126         }
127         // apply damage
128         if (self.event_damage)
129                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
130         self = oldself;
131 }
132
133 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
134 {
135         entity  targ;
136         float   finaldmg;
137         float   power;
138         vector  blastorigin;
139         vector  force;
140         vector  m1;
141         vector  m2;
142         vector  nearest;
143         vector  diff;
144
145         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
146
147         targ = findradius (blastorigin, rad);
148         while (targ)
149         {
150                 if (targ != inflictor)
151                         if (ignore != targ)
152                         {
153                                 // LordHavoc: measure distance to nearest point on target (not origin)
154                                 // (this guarentees 100% damage on a touch impact)
155                                 nearest = blastorigin;
156                                 m1 = targ.origin + targ.mins;
157                                 m2 = targ.origin + targ.maxs;
158                                 if (nearest_x < m1_x) nearest_x = m1_x;
159                                 if (nearest_y < m1_y) nearest_y = m1_y;
160                                 if (nearest_z < m1_z) nearest_z = m1_z;
161                                 if (nearest_x > m2_x) nearest_x = m2_x;
162                                 if (nearest_y > m2_y) nearest_y = m2_y;
163                                 if (nearest_z > m2_z) nearest_z = m2_z;
164                                 diff = nearest - blastorigin;
165                                 // round up a little on the damage to ensure full damage on impacts
166                                 // and turn the distance into a fraction of the radius
167                                 power = 1 - ((vlen (diff) - 2) / rad);
168                                 //bprint(" ");
169                                 //bprint(ftos(power));
170                                 if (power > 0)
171                                 {
172                                         if (power > 1)
173                                                 power = 1;
174                                         finaldmg = coredamage * power + edgedamage * (1 - power);
175                                         force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
176                                         if (targ == attacker)
177                                                 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
178                                         if (finaldmg > 0)
179                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
180                                 }
181                         }
182                 targ = targ.chain;
183         }
184 }
185
186 /*
187 entity  multi_ent;
188 float   multi_damage;
189 vector  multi_force;
190
191 void ClearMultiDamage (void)
192 {
193         multi_ent = world;
194         multi_damage = 0;
195         multi_force = '0 0 0';
196 }
197
198 void ApplyMultiDamage (void)
199 {
200         if (!multi_ent)
201                 return;
202
203         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
204 }
205
206 void AddMultiDamage (entity hit, float damage, vector force)
207 {
208         if (!hit)
209                 return;
210
211         if (hit != multi_ent)
212         {
213                 ApplyMultiDamage ();
214                 ClearMultiDamage ();
215                 multi_ent = hit;
216         }
217         multi_damage = multi_damage + damage;
218         multi_force = multi_force + force;
219 }
220
221 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
222 {
223         vector  direction;
224         vector  source;
225         vector  vel;
226         vector  org;
227
228         makevectors (self.v_angle);
229
230         source = self.origin + v_forward * 10;  // FIXME
231         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
232
233         // LordHavoc: better to use normal damage
234         //ClearMultiDamage ();
235         while (shotcount > 0)
236         {
237                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
238
239                 traceline (source, source + direction * 2048, FALSE, self);
240                 if (trace_fraction != 1.0)
241                 {
242                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
243                         vel = vel + 2 * trace_plane_normal;
244                         vel = vel * 200;
245
246                         org = trace_endpos - direction * 4;
247
248                         if (!trace_ent.takedamage)
249                                 te_gunshot (org);
250                         // LordHavoc: better to use normal damage
251                         //AddMultiDamage (trace_ent, 4, direction * 4);
252                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
253                 }
254
255                 shotcount = shotcount + 1;
256         }
257
258         // LordHavoc: better to use normal damage
259         //ApplyMultiDamage ();
260 }
261 */