]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_common.qc
support for announcer/male/impressive and announcer/male/headshot ;)
[divverent/nexuiz.git] / data / qcsrc / server / w_common.qc
1
2 void W_GiveWeapon (entity e, float wep, string name)
3 {
4         entity oldself;
5
6         if (!wep)
7                 return;
8
9         e.weapons = e.weapons | W_WeaponBit(wep);
10
11         oldself = self;
12         self = e;
13
14         if (other.classname == "player")
15         {
16                 sprint (other, "You got the ^2");
17                 sprint (other, name);
18                 sprint (other, "\n");
19         }
20
21
22         self = oldself;
23 }
24
25 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float deathtype)
26 {
27         local vector hitloc, force, endpoint, dir;
28         local entity ent, endent;
29         local float endq3surfaceflags;
30         //local entity explosion;
31         
32         railgun_start = start;
33         railgun_end = end;
34
35         dir = normalize(end - start);
36         force = dir * bforce;
37
38         // go a little bit into the wall because we need to hit this wall later
39         end = end + dir;
40
41         // trace multiple times until we hit a wall, each obstacle will be made
42         // non-solid so we can hit the next, while doing this we spawn effects and
43         // note down which entities were hit so we can damage them later
44         while (1)
45         {
46                 if(self.antilag_debug)
47                         traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
48                 else
49                         traceline_antilag (self, start, end, FALSE, self, self.ping * 0.001);
50
51                 // if it is world we can't hurt it so stop now
52                 if (trace_ent == world || trace_fraction == 1)
53                         break;
54
55                 // make the entity non-solid so we can hit the next one
56                 trace_ent.railgunhit = TRUE;
57                 trace_ent.railgunhitloc = end;
58                 trace_ent.railgunhitsolidbackup = trace_ent.solid;
59
60                 // stop if this is a wall
61                 if (trace_ent.solid == SOLID_BSP)
62                         break;
63
64                 // make the entity non-solid
65                 trace_ent.solid = SOLID_NOT;
66         }
67
68         endpoint = trace_endpos;
69         endent = trace_ent;
70         endq3surfaceflags = trace_dphitq3surfaceflags;
71
72         // find all the entities the railgun hit and restore their solid state
73         ent = findfloat(world, railgunhit, TRUE);
74         while (ent)
75         {
76                 // restore their solid type
77                 ent.solid = ent.railgunhitsolidbackup;
78                 ent = findfloat(ent, railgunhit, TRUE);
79         }
80
81         // spawn a temporary explosion entity for RadiusDamage calls
82         //explosion = spawn();
83
84         // find all the entities the railgun hit and hurt them
85         ent = findfloat(world, railgunhit, TRUE);
86         while (ent)
87         {
88                 // get the details we need to call the damage function
89                 hitloc = ent.railgunhitloc;
90                 ent.railgunhitloc = '0 0 0';
91                 ent.railgunhitsolidbackup = SOLID_NOT;
92                 ent.railgunhit = FALSE;
93
94                 // apply the damage
95                 if (ent.takedamage || ent.classname == "case")
96                         Damage (ent, self, self, bdamage, deathtype, hitloc, force);
97
98                 // create a small explosion to throw gibs around (if applicable)
99                 //setorigin (explosion, hitloc);
100                 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
101
102                 // advance to the next entity
103                 ent = findfloat(ent, railgunhit, TRUE);
104         }
105
106         // we're done with the explosion entity, remove it
107         //remove(explosion);
108
109         trace_endpos = endpoint;
110         trace_ent = endent;
111         trace_dphitq3surfaceflags = endq3surfaceflags;
112 }
113
114 void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
115 {
116         vector  end;
117         local entity e;
118
119         dir = dir + randomvec() * spread;
120         end = start + dir * MAX_SHOT_DISTANCE;
121         if(self.antilag_debug)
122                 traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
123         else
124                 traceline_antilag (self, start, end, FALSE, self, self.ping * 0.001);
125
126         if (tracer)
127         {
128                 e = spawn();
129                 e.owner = self;
130                 e.movetype = MOVETYPE_FLY;
131                 e.solid = SOLID_NOT;
132                 e.think = SUB_Remove;
133                 e.nextthink = time + vlen(trace_endpos - start) / 6000;
134                 e.velocity = dir * 6000;
135                 e.angles = vectoangles(e.velocity);
136                 setmodel (e, "models/tracer.mdl"); // precision set below
137                 setsize (e, '0 0 0', '0 0 0');
138                 setorigin (e, start);
139                 e.effects = EF_LOWPRECISION;
140                 e.flags = FL_PROJECTILE;
141         }
142
143         if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
144         {
145                 if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
146                 {
147                         if (dtype < DEATH_SPECIAL_START && (dtype & DEATH_WEAPONMASK) == WEP_SHOTGUN)
148                                 pointparticles(particleeffectnum("shotgun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
149                         else
150                                 pointparticles(particleeffectnum("machinegun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
151                 }
152                 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
153         }
154 }