]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/damage.qc
supajoes new stuff
[divverent/nexuiz.git] / qcsrc / damage.qc
1
2 void Obituary (entity attacker, entity targ, float deathtype)
3 {
4         if (targ.classname == "player" || targ.classname == "corpse")
5         {
6                 if (targ.classname == "corpse")
7                         bprint ("A corpse");
8                 else
9                         bprint (targ.netname);
10                 bprint (" was killed by ");
11                 bprint (attacker.netname);
12                 bprint ("\n");
13         }
14 }
15
16 void Damage (entity attacker, vector hitloc, entity targ, float deathtype, float damage)
17 {
18         entity  oldself;
19         
20         if (targ.takedamage)
21         {
22                 targ.health = targ.health - damage;
23
24                 oldself = self;
25                 self = targ;
26
27                 if (targ.health <= 0)
28                 {
29                         Obituary (attacker, targ, deathtype);
30                         if (targ.event_die)
31                                 targ.event_die (hitloc, damage);
32                         //return;       // self = oldself;return;
33                 }
34                 else if (targ.event_hurt)
35                         targ.event_hurt (hitloc, damage);
36
37                 self = oldself;
38         }
39         else if (targ.event_hurt)       // For casings, etc that aren't damageable (cheap, I know :P)
40         {
41                 oldself = self;
42                 self = targ;
43
44                 targ.event_hurt (hitloc, damage);
45
46                 self = oldself;
47         }
48 }
49
50 void RadiusDamage (entity attacker, entity inflictor, float deathtype, float damage, entity ignore)
51 {
52         entity  targ;
53         float   finaldmg;
54
55         targ = findradius (inflictor.origin, damage);
56         while (targ)
57         {
58                 if (targ != inflictor)
59                         if (ignore != targ)
60                         {
61                                 finaldmg = damage - max (0, 0.5 * vlen (inflictor.origin - targ.origin));
62                                 if (targ == attacker)
63                                         finaldmg = finaldmg * 0.6;      // Partial damage if the attacker hits himself
64                                 if (finaldmg > 0)
65                                         Damage (attacker, inflictor.origin, targ, deathtype, finaldmg);
66                         }
67                 targ = targ.chain;
68         }
69 }
70
71 entity  multi_ent;
72 float   multi_damage;
73
74 void ClearMultiDamage (void)
75 {
76         multi_ent = world;
77         multi_damage = 0;
78 }
79
80 void ApplyMultiDamage (void)
81 {
82         if (!multi_ent)
83                 return;
84
85         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage);
86 }
87
88 void AddMultiDamage (entity hit, float damage)
89 {
90         if (!hit)
91                 return;
92                 
93         if (hit != multi_ent)
94         {
95                 ApplyMultiDamage ();
96                 multi_damage = damage;
97                 multi_ent = hit;
98         }
99         else
100                 multi_damage = multi_damage + damage;
101 }
102
103 void FireBullets (float shotcount, vector dir, vector spread)
104 {
105         vector  direction;
106         vector  source;
107         vector  vel;
108         vector  org;
109         
110         makevectors (self.v_angle);
111         
112         source = self.origin + v_forward * 10;  // FIXME
113         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
114         
115         ClearMultiDamage ();
116         while (shotcount > 0)
117         {
118                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
119                 
120                 traceline (source, source + direction * 2048, FALSE, self);
121                 if (trace_fraction != 1.0)
122                 {
123                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
124                         vel = vel + 2 * trace_plane_normal;
125                         vel = vel * 200;
126                         
127                         org = trace_endpos - direction * 4;
128                         
129                         if (trace_ent.takedamage)
130                         {
131                                 //te_blood (
132                                 AddMultiDamage (trace_ent, 4);
133                         }
134                         else
135                                 te_gunshot (org);
136                 }
137                 
138                 shotcount = shotcount + 1;
139         }
140         
141         ApplyMultiDamage ();
142 }