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