]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_damage.c
added bot_number cvar
[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 // these are updated by each Damage call for use in button triggering and such
114 entity damage_targ;
115 entity damage_inflictor;
116 entity damage_attacker;
117
118 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
119 {
120         local entity oldself;
121         oldself = self;
122         self = targ;
123         damage_targ = targ;
124         damage_inflictor = inflictor;
125         damage_attacker = attacker;
126         // nullify damage if teamplay is on
127         if (teamplay)
128         if (attacker.team)
129         if (attacker.team == targ.team)
130         if (teamplay == 1 || (teamplay == 3 && attacker != targ))
131                 damage = 0;
132         // apply strength multiplier
133         if (attacker.items & IT_STRENGTH)
134         {
135                 damage = damage * cvar("g_balance_powerup_strength_damage");
136                 force = force * cvar("g_balance_powerup_strength_force");
137         }
138         // apply invincibility multiplier
139         if (targ.items & IT_INVINCIBLE)
140                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
141         // apply push
142         if (self.damageforcescale)
143         {
144                 self.velocity = self.velocity + self.damageforcescale * force;
145                 self.flags = self.flags - (self.flags & FL_ONGROUND);
146         }
147         // apply damage
148         if (self.event_damage)
149                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
150         self = oldself;
151
152         // Savage: vampire mode
153         if(cvar("g_vampire") && targ.classname == "player" && attacker.classname == "player" && attacker != targ) {
154                 attacker.health += damage;
155         }
156 }
157
158 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
159 {
160         entity  targ;
161         float   finaldmg;
162         float   power;
163         vector  blastorigin;
164         vector  force;
165         vector  m1;
166         vector  m2;
167         vector  nearest;
168         vector  diff;
169
170         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
171
172         targ = findradius (blastorigin, rad);
173         while (targ)
174         {
175                 if (targ != inflictor)
176                         if (ignore != targ)
177                         {
178                                 // LordHavoc: measure distance to nearest point on target (not origin)
179                                 // (this guarentees 100% damage on a touch impact)
180                                 nearest = blastorigin;
181                                 m1 = targ.origin + targ.mins;
182                                 m2 = targ.origin + targ.maxs;
183                                 if (nearest_x < m1_x) nearest_x = m1_x;
184                                 if (nearest_y < m1_y) nearest_y = m1_y;
185                                 if (nearest_z < m1_z) nearest_z = m1_z;
186                                 if (nearest_x > m2_x) nearest_x = m2_x;
187                                 if (nearest_y > m2_y) nearest_y = m2_y;
188                                 if (nearest_z > m2_z) nearest_z = m2_z;
189                                 diff = nearest - blastorigin;
190                                 // round up a little on the damage to ensure full damage on impacts
191                                 // and turn the distance into a fraction of the radius
192                                 power = 1 - ((vlen (diff) - 2) / rad);
193                                 //bprint(" ");
194                                 //bprint(ftos(power));
195                                 if (power > 0)
196                                 {
197                                         if (power > 1)
198                                                 power = 1;
199                                         finaldmg = coredamage * power + edgedamage * (1 - power);
200                                         if (finaldmg > 0)
201                                         {
202                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
203                                                 if (targ == attacker)
204                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
205                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
206                                         }
207                                 }
208                         }
209                 targ = targ.chain;
210         }
211 }
212
213 /*
214 entity  multi_ent;
215 float   multi_damage;
216 vector  multi_force;
217
218 void ClearMultiDamage (void)
219 {
220         multi_ent = world;
221         multi_damage = 0;
222         multi_force = '0 0 0';
223 }
224
225 void ApplyMultiDamage (void)
226 {
227         if (!multi_ent)
228                 return;
229
230         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
231 }
232
233 void AddMultiDamage (entity hit, float damage, vector force)
234 {
235         if (!hit)
236                 return;
237
238         if (hit != multi_ent)
239         {
240                 ApplyMultiDamage ();
241                 ClearMultiDamage ();
242                 multi_ent = hit;
243         }
244         multi_damage = multi_damage + damage;
245         multi_force = multi_force + force;
246 }
247
248 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
249 {
250         vector  direction;
251         vector  source;
252         vector  vel;
253         vector  org;
254
255         makevectors (self.v_angle);
256
257         source = self.origin + v_forward * 10;  // FIXME
258         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
259
260         // LordHavoc: better to use normal damage
261         //ClearMultiDamage ();
262         while (shotcount > 0)
263         {
264                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
265
266                 traceline (source, source + direction * 2048, FALSE, self);
267                 if (trace_fraction != 1.0)
268                 {
269                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
270                         vel = vel + 2 * trace_plane_normal;
271                         vel = vel * 200;
272
273                         org = trace_endpos - direction * 4;
274
275                         if (!trace_ent.takedamage)
276                                 te_gunshot (org);
277                         // LordHavoc: better to use normal damage
278                         //AddMultiDamage (trace_ent, 4, direction * 4);
279                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
280                 }
281
282                 shotcount = shotcount + 1;
283         }
284
285         // LordHavoc: better to use normal damage
286         //ApplyMultiDamage ();
287 }
288 */