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