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