]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/damage.qc
Fixed two minor bugs.
[divverent/nexuiz.git] / qcsrc / damage.qc
1
2 void Obituary (entity attacker, entity targ, float deathtype)
3 {
4         local string s;
5         if (targ.classname == "player" || targ.classname == "corpse")
6         {
7                 s = targ.netname; 
8                 if (targ.classname == "corpse")
9                         s = "A corpse";
10                 if (targ == attacker)
11                 {
12                         if (deathtype == IT_LASER) {bprint(s);bprint(" was unable to resist the urge to self-immolate\n");}
13                         else if (deathtype == IT_GRENADE_LAUNCHER) {bprint(s);bprint(" detonated\n");}
14                         else if (deathtype == IT_ELECTRO) {bprint(s);bprint(" played with plasma\n");}
15                         else if (deathtype == IT_HAGAR) {bprint(s);bprint(" should have used a different weapon\n");}
16                         else if (deathtype == IT_ROCKET_LAUNCHER) {bprint(s);bprint(" exploded\n");}
17                         else {bprint(s);bprint(" competes for the darwin awards\n");}
18                 }
19                 else if (attacker.classname == "player")
20                 {
21                         if (deathtype == IT_LASER) {bprint(s);bprint(" was a victim of laser surgeon ");bprint(attacker.netname);bprint("\n");}
22                         else if (deathtype == IT_UZI) {bprint(s);bprint(" was gunned down by ");bprint(attacker.netname);bprint("\n");}
23                         else if (deathtype == IT_SHOTGUN) {bprint(s);bprint(" was gunned down by ");bprint(attacker.netname);bprint("\n");}
24                         else if (deathtype == IT_GRENADE_LAUNCHER) {bprint(s);bprint(" was blasted by ");bprint(attacker.netname);bprint("\n");}
25                         else if (deathtype == IT_ELECTRO) {bprint(s);bprint(" bathed in plasma from ");bprint(attacker.netname);bprint("\n");}
26                         else if (deathtype == IT_CRYLINK) {bprint(s);bprint(" was zapped by ");bprint(attacker.netname);bprint("\n");}
27                         else if (deathtype == IT_NEX) {bprint(s);bprint(" sports a new hole from ");bprint(attacker.netname);bprint("\n");}
28                         else if (deathtype == IT_HAGAR) {bprint(s);bprint(" was pummeled by ");bprint(attacker.netname);bprint("\n");}
29                         else if (deathtype == IT_ROCKET_LAUNCHER) {bprint(s);bprint(" was given a lesson in rocketry by ");bprint(attacker.netname);bprint("\n");}
30                         else {bprint(s);bprint(" was killed by ");bprint(attacker.netname);bprint("\n");}
31                 }
32                 else
33                 {
34                         {bprint(s);bprint(" died\n");}
35                 }
36         }
37 }
38
39 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
40 {
41         local entity oldself;
42         oldself = self;
43         self = targ;
44         // apply push
45         if (self.damageforcescale)
46         {
47                 self.velocity = self.velocity + self.damageforcescale * force;
48                 self.flags = self.flags - (self.flags & FL_ONGROUND);
49         }
50         // apply damage
51         if (self.event_damage)
52                 self.event_damage (hitloc, damage, inflictor, attacker, deathtype);
53         self = oldself;
54
55         // Sajt - added this, but I'm not sure the powerups are even implemented? This might act strange because
56         //        there is no code handled to disable powerups when their time is up...
57         if (game & GAME_STRENGTH_GAIN)
58         {
59                 if (attacker.strength_finished < time)
60                         attacker.strength_finished = time + 5;
61                 else
62                         attacker.strength_finished = attacker.strength_finished + 5;
63
64                 attacker.items = attacker.items | IT_STRENGTH;
65         }
66 }
67
68 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
69 {
70         entity  targ;
71         float   finaldmg;
72         float   power;
73         vector  blastorigin;
74         vector  force;
75         vector  m1;
76         vector  m2;
77         vector  nearest;
78         vector  diff;
79
80         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
81
82         targ = findradius (blastorigin, rad);
83         while (targ)
84         {
85                 if (targ != inflictor)
86                         if (ignore != targ)
87                         {
88                                 // LordHavoc: measure distance to nearest point on target (not origin)
89                                 // (this guarentees 100% damage on a touch impact)
90                                 nearest = blastorigin;
91                                 m1 = targ.origin + targ.mins;
92                                 m2 = targ.origin + targ.maxs;
93                                 if (nearest_x < m1_x) nearest_x = m1_x;
94                                 if (nearest_y < m1_y) nearest_y = m1_y;
95                                 if (nearest_z < m1_z) nearest_z = m1_z;
96                                 if (nearest_x > m2_x) nearest_x = m2_x;
97                                 if (nearest_y > m2_y) nearest_y = m2_y;
98                                 if (nearest_z > m2_z) nearest_z = m2_z;
99                                 diff = nearest - blastorigin;
100                                 // round up a little on the damage to ensure full damage on impacts
101                                 // and turn the distance into a fraction of the radius
102                                 power = 1 - ((vlen (diff) - 2) / rad);
103                                 //bprint(" ");
104                                 //bprint(ftos(power));
105                                 if (power > 0)
106                                 {
107                                         if (power > 1)
108                                                 power = 1;
109                                         finaldmg = coredamage * power + edgedamage * (1 - power);
110                                         force = normalize(diff) * (finaldmg / coredamage) * forceintensity;
111                                         if (targ == attacker)
112                                                 finaldmg = finaldmg * 0.6;      // Partial damage if the attacker hits himself
113                                         if (finaldmg > 0)
114                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
115                                 }
116                         }
117                 targ = targ.chain;
118         }
119 }
120
121 /*
122 entity  multi_ent;
123 float   multi_damage;
124 vector  multi_force;
125
126 void ClearMultiDamage (void)
127 {
128         multi_ent = world;
129         multi_damage = 0;
130         multi_force = '0 0 0';
131 }
132
133 void ApplyMultiDamage (void)
134 {
135         if (!multi_ent)
136                 return;
137
138         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
139 }
140
141 void AddMultiDamage (entity hit, float damage, vector force)
142 {
143         if (!hit)
144                 return;
145
146         if (hit != multi_ent)
147         {
148                 ApplyMultiDamage ();
149                 ClearMultiDamage ();
150                 multi_ent = hit;
151         }
152         multi_damage = multi_damage + damage;
153         multi_force = multi_force + force;
154 }
155
156 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
157 {
158         vector  direction;
159         vector  source;
160         vector  vel;
161         vector  org;
162
163         makevectors (self.v_angle);
164
165         source = self.origin + v_forward * 10;  // FIXME
166         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
167
168         // LordHavoc: better to use normal damage
169         //ClearMultiDamage ();
170         while (shotcount > 0)
171         {
172                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
173
174                 traceline (source, source + direction * 2048, FALSE, self);
175                 if (trace_fraction != 1.0)
176                 {
177                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
178                         vel = vel + 2 * trace_plane_normal;
179                         vel = vel * 200;
180
181                         org = trace_endpos - direction * 4;
182
183                         if (!trace_ent.takedamage)
184                                 te_gunshot (org);
185                         // LordHavoc: better to use normal damage
186                         //AddMultiDamage (trace_ent, 4, direction * 4);
187                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
188                 }
189
190                 shotcount = shotcount + 1;
191         }
192
193         // LordHavoc: better to use normal damage
194         //ApplyMultiDamage ();
195 }
196 */