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