]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_damage.c
Disable dlight shadows by default
[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         // Savage: vampire mode
133         if(cvar("g_vampire") && targ.classname == "player" && attacker.classname == "player" && attacker != targ) {
134                 attacker.health += damage;              
135         }
136 }
137
138 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
139 {
140         entity  targ;
141         float   finaldmg;
142         float   power;
143         vector  blastorigin;
144         vector  force;
145         vector  m1;
146         vector  m2;
147         vector  nearest;
148         vector  diff;
149
150         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
151
152         targ = findradius (blastorigin, rad);
153         while (targ)
154         {
155                 if (targ != inflictor)
156                         if (ignore != targ)
157                         {
158                                 // LordHavoc: measure distance to nearest point on target (not origin)
159                                 // (this guarentees 100% damage on a touch impact)
160                                 nearest = blastorigin;
161                                 m1 = targ.origin + targ.mins;
162                                 m2 = targ.origin + targ.maxs;
163                                 if (nearest_x < m1_x) nearest_x = m1_x;
164                                 if (nearest_y < m1_y) nearest_y = m1_y;
165                                 if (nearest_z < m1_z) nearest_z = m1_z;
166                                 if (nearest_x > m2_x) nearest_x = m2_x;
167                                 if (nearest_y > m2_y) nearest_y = m2_y;
168                                 if (nearest_z > m2_z) nearest_z = m2_z;
169                                 diff = nearest - blastorigin;
170                                 // round up a little on the damage to ensure full damage on impacts
171                                 // and turn the distance into a fraction of the radius
172                                 power = 1 - ((vlen (diff) - 2) / rad);
173                                 //bprint(" ");
174                                 //bprint(ftos(power));
175                                 if (power > 0)
176                                 {
177                                         if (power > 1)
178                                                 power = 1;
179                                         finaldmg = coredamage * power + edgedamage * (1 - power);
180                                         if (finaldmg > 0)
181                                         {
182                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
183                                                 if (targ == attacker)
184                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
185                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
186                                         }
187                                 }
188                         }
189                 targ = targ.chain;
190         }
191 }
192
193 /*
194 entity  multi_ent;
195 float   multi_damage;
196 vector  multi_force;
197
198 void ClearMultiDamage (void)
199 {
200         multi_ent = world;
201         multi_damage = 0;
202         multi_force = '0 0 0';
203 }
204
205 void ApplyMultiDamage (void)
206 {
207         if (!multi_ent)
208                 return;
209
210         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
211 }
212
213 void AddMultiDamage (entity hit, float damage, vector force)
214 {
215         if (!hit)
216                 return;
217
218         if (hit != multi_ent)
219         {
220                 ApplyMultiDamage ();
221                 ClearMultiDamage ();
222                 multi_ent = hit;
223         }
224         multi_damage = multi_damage + damage;
225         multi_force = multi_force + force;
226 }
227
228 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
229 {
230         vector  direction;
231         vector  source;
232         vector  vel;
233         vector  org;
234
235         makevectors (self.v_angle);
236
237         source = self.origin + v_forward * 10;  // FIXME
238         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
239
240         // LordHavoc: better to use normal damage
241         //ClearMultiDamage ();
242         while (shotcount > 0)
243         {
244                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
245
246                 traceline (source, source + direction * 2048, FALSE, self);
247                 if (trace_fraction != 1.0)
248                 {
249                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
250                         vel = vel + 2 * trace_plane_normal;
251                         vel = vel * 200;
252
253                         org = trace_endpos - direction * 4;
254
255                         if (!trace_ent.takedamage)
256                                 te_gunshot (org);
257                         // LordHavoc: better to use normal damage
258                         //AddMultiDamage (trace_ent, 4, direction * 4);
259                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
260                 }
261
262                 shotcount = shotcount + 1;
263         }
264
265         // LordHavoc: better to use normal damage
266         //ApplyMultiDamage ();
267 }
268 */