]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/damage.qc
gibbing sound added
[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
56 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float radius, entity ignore, float forceintensity, float deathtype)
57 {
58         entity  targ;
59         float   finaldmg;
60         float   power;
61         vector  blastorigin;
62         vector  force;
63         vector  m1;
64         vector  m2;
65         vector  nearest;
66         vector  diff;
67
68         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
69
70         targ = findradius (blastorigin, radius);
71         while (targ)
72         {
73                 if (targ != inflictor)
74                         if (ignore != targ)
75                         {
76                                 // LordHavoc: measure distance to nearest point on target (not origin)
77                                 // (this guarentees 100% damage on a touch impact)
78                                 nearest = blastorigin;
79                                 m1 = targ.origin + targ.mins;
80                                 m2 = targ.origin + targ.maxs;
81                                 if (nearest_x < m1_x) nearest_x = m1_x;
82                                 if (nearest_y < m1_y) nearest_y = m1_y;
83                                 if (nearest_z < m1_z) nearest_z = m1_z;
84                                 if (nearest_x > m2_x) nearest_x = m2_x;
85                                 if (nearest_y > m2_y) nearest_y = m2_y;
86                                 if (nearest_z > m2_z) nearest_z = m2_z;
87                                 diff = nearest - blastorigin;
88                                 // round up a little on the damage to ensure full damage on impacts
89                                 // and turn the distance into a fraction of the radius
90                                 power = 1 - ((vlen (diff) - 2) / radius);
91                                 //bprint(" ");
92                                 //bprint(ftos(power));
93                                 if (power > 0)
94                                 {
95                                         if (power > 1)
96                                                 power = 1;
97                                         finaldmg = coredamage * power + edgedamage * (1 - power);
98                                         force = normalize(diff) * (finaldmg / coredamage) * forceintensity;
99                                         if (targ == attacker)
100                                                 finaldmg = finaldmg * 0.6;      // Partial damage if the attacker hits himself
101                                         if (finaldmg > 0)
102                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, inflictor.origin, force);
103                                 }
104                         }
105                 targ = targ.chain;
106         }
107 }
108
109 /*
110 entity  multi_ent;
111 float   multi_damage;
112 vector  multi_force;
113
114 void ClearMultiDamage (void)
115 {
116         multi_ent = world;
117         multi_damage = 0;
118         multi_force = '0 0 0';
119 }
120
121 void ApplyMultiDamage (void)
122 {
123         if (!multi_ent)
124                 return;
125
126         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
127 }
128
129 void AddMultiDamage (entity hit, float damage, vector force)
130 {
131         if (!hit)
132                 return;
133
134         if (hit != multi_ent)
135         {
136                 ApplyMultiDamage ();
137                 ClearMultiDamage ();
138                 multi_ent = hit;
139         }
140         multi_damage = multi_damage + damage;
141         multi_force = multi_force + force;
142 }
143
144 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
145 {
146         vector  direction;
147         vector  source;
148         vector  vel;
149         vector  org;
150
151         makevectors (self.v_angle);
152
153         source = self.origin + v_forward * 10;  // FIXME
154         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
155
156         // LordHavoc: better to use normal damage
157         //ClearMultiDamage ();
158         while (shotcount > 0)
159         {
160                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
161
162                 traceline (source, source + direction * 2048, FALSE, self);
163                 if (trace_fraction != 1.0)
164                 {
165                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
166                         vel = vel + 2 * trace_plane_normal;
167                         vel = vel * 200;
168
169                         org = trace_endpos - direction * 4;
170
171                         if (!trace_ent.takedamage)
172                                 te_gunshot (org);
173                         // LordHavoc: better to use normal damage
174                         //AddMultiDamage (trace_ent, 4, direction * 4);
175                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
176                 }
177
178                 shotcount = shotcount + 1;
179         }
180
181         // LordHavoc: better to use normal damage
182         //ApplyMultiDamage ();
183 }
184 */