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