]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_damage.c
made kill command work
[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                 // Suicides
14                 if (targ == attacker)
15                 {
16                         if (deathtype == IT_LASER)
17                                 bprint (s, " was unable to resist the urge to self-immolate\n");
18                         else if (deathtype == IT_GRENADE_LAUNCHER)
19                                 bprint (s, " detonated\n");
20                         else if (deathtype == IT_ELECTRO)
21                                 bprint (s, " played with plasma\n");
22                         else if (deathtype == IT_HAGAR)
23                                 bprint (s, " should have used a different weapon\n");
24                         else if (deathtype == IT_ROCKET_LAUNCHER)
25                                 bprint (s, " exploded\n");
26                         else if (deathtype == DEATH_KILL)
27                                 bprint (s, " couldn't take it anymore\n");
28                         else
29                                 bprint (s, " competes for the Darwin awards\n");
30
31                         self.frags = self.frags - 1;
32                 }
33                 // Kills
34                 else if (attacker.classname == "player")
35                 {
36                         if (deathtype == IT_LASER)
37                                 bprint (s, " was a victim of laser surgeon ", attacker.netname, "\n");
38                         else if (deathtype == IT_UZI)
39                                 bprint (s, " was riddled full of holes by ", attacker.netname, "\n");
40                         else if (deathtype == IT_SHOTGUN)
41                                 bprint (s, " was gunned by ", attacker.netname, "\n");
42                         else if (deathtype == IT_GRENADE_LAUNCHER)
43                                 bprint (s, " was blasted by ", attacker.netname, "\n");
44                         else if (deathtype == IT_ELECTRO)
45                                 bprint (s, " bathed in ", attacker.netname, "'s plasma\n");
46                         else if (deathtype == IT_CRYLINK)
47                                 bprint (s, " was zapped by ", attacker.netname, "\n");
48                         else if (deathtype == IT_NEX)
49                                 bprint (s, " has been vaporized by ", attacker.netname, "\n");
50                         else if (deathtype == IT_HAGAR)
51                                 bprint (s, " was pummeled by ", attacker.netname, "\n");
52                         else if (deathtype == IT_ROCKET_LAUNCHER)
53                                 bprint (s, " was given a lesson in rocketry by ", attacker.netname, "\n");
54                         else
55                                 bprint (s, " was killed by ", attacker.netname, "\n");
56
57                         attacker.frags = attacker.frags + 1;
58                 }
59                 else if (deathtype == DEATH_HURTTRIGGER)
60                         bprint (s, " ", attacker.message, "\n");
61                 else if (deathtype == DEATH_FALL)
62                         bprint (s, " hit the ground with a crunch\n");
63                 else if (deathtype == DEATH_BIGFALL)
64                         bprint (s, " fell into oblivion\n");
65                 else if (deathtype == DEATH_DROWN)
66                         bprint (s, " wished he had gills\n");
67                 else
68                         bprint (s, " died\n");
69         }
70 }
71
72 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
73 {
74         local entity oldself;
75         oldself = self;
76         self = targ;
77         if (attacker.items & IT_STRENGTH)
78         {
79                 damage = damage * POWERUP_STRENGTH_DAMAGE;
80                 force = force * POWERUP_STRENGTH_FORCE;
81         }
82         if (targ.items & IT_INVINCIBLE)
83                 damage = damage * POWERUP_INVINCIBLE_TAKEDAMAGE;
84         // apply push
85         if (self.damageforcescale)
86         {
87                 self.velocity = self.velocity + self.damageforcescale * force;
88                 self.flags = self.flags - (self.flags & FL_ONGROUND);
89         }
90         // apply damage
91         if (self.event_damage)
92                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
93         self = oldself;
94 }
95
96 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
97 {
98         entity  targ;
99         float   finaldmg;
100         float   power;
101         vector  blastorigin;
102         vector  force;
103         vector  m1;
104         vector  m2;
105         vector  nearest;
106         vector  diff;
107
108         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
109
110         targ = findradius (blastorigin, rad);
111         while (targ)
112         {
113                 if (targ != inflictor)
114                         if (ignore != targ)
115                         {
116                                 // LordHavoc: measure distance to nearest point on target (not origin)
117                                 // (this guarentees 100% damage on a touch impact)
118                                 nearest = blastorigin;
119                                 m1 = targ.origin + targ.mins;
120                                 m2 = targ.origin + targ.maxs;
121                                 if (nearest_x < m1_x) nearest_x = m1_x;
122                                 if (nearest_y < m1_y) nearest_y = m1_y;
123                                 if (nearest_z < m1_z) nearest_z = m1_z;
124                                 if (nearest_x > m2_x) nearest_x = m2_x;
125                                 if (nearest_y > m2_y) nearest_y = m2_y;
126                                 if (nearest_z > m2_z) nearest_z = m2_z;
127                                 diff = nearest - blastorigin;
128                                 // round up a little on the damage to ensure full damage on impacts
129                                 // and turn the distance into a fraction of the radius
130                                 power = 1 - ((vlen (diff) - 2) / rad);
131                                 //bprint(" ");
132                                 //bprint(ftos(power));
133                                 if (power > 0)
134                                 {
135                                         if (power > 1)
136                                                 power = 1;
137                                         finaldmg = coredamage * power + edgedamage * (1 - power);
138                                         force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
139                                         if (targ == attacker)
140                                                 finaldmg = finaldmg * 0.6;      // Partial damage if the attacker hits himself
141                                         if (finaldmg > 0)
142                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
143                                 }
144                         }
145                 targ = targ.chain;
146         }
147 }
148
149 /*
150 entity  multi_ent;
151 float   multi_damage;
152 vector  multi_force;
153
154 void ClearMultiDamage (void)
155 {
156         multi_ent = world;
157         multi_damage = 0;
158         multi_force = '0 0 0';
159 }
160
161 void ApplyMultiDamage (void)
162 {
163         if (!multi_ent)
164                 return;
165
166         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
167 }
168
169 void AddMultiDamage (entity hit, float damage, vector force)
170 {
171         if (!hit)
172                 return;
173
174         if (hit != multi_ent)
175         {
176                 ApplyMultiDamage ();
177                 ClearMultiDamage ();
178                 multi_ent = hit;
179         }
180         multi_damage = multi_damage + damage;
181         multi_force = multi_force + force;
182 }
183
184 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
185 {
186         vector  direction;
187         vector  source;
188         vector  vel;
189         vector  org;
190
191         makevectors (self.v_angle);
192
193         source = self.origin + v_forward * 10;  // FIXME
194         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
195
196         // LordHavoc: better to use normal damage
197         //ClearMultiDamage ();
198         while (shotcount > 0)
199         {
200                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
201
202                 traceline (source, source + direction * 2048, FALSE, self);
203                 if (trace_fraction != 1.0)
204                 {
205                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
206                         vel = vel + 2 * trace_plane_normal;
207                         vel = vel * 200;
208
209                         org = trace_endpos - direction * 4;
210
211                         if (!trace_ent.takedamage)
212                                 te_gunshot (org);
213                         // LordHavoc: better to use normal damage
214                         //AddMultiDamage (trace_ent, 4, direction * 4);
215                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
216                 }
217
218                 shotcount = shotcount + 1;
219         }
220
221         // LordHavoc: better to use normal damage
222         //ApplyMultiDamage ();
223 }
224 */