]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_common.qc
removing this makefile also
[divverent/nexuiz.git] / data / qcsrc / server / w_common.qc
1
2 // increments sprite frame, loops when end is hit.. simple
3
4 float TE_SMOKE =77;
5 void (vector vec) WriteVec =
6 {
7                 WriteCoord (MSG_BROADCAST, vec_x);
8                 WriteCoord (MSG_BROADCAST, vec_y);
9                 WriteCoord (MSG_BROADCAST, vec_z);
10 }
11 void (vector org, vector dir, float counts) W_Smoke =
12 {
13                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
14                 WriteByte (MSG_BROADCAST, TE_SMOKE);
15                 WriteVec (org);
16                 WriteVec (dir);
17                 WriteByte (MSG_BROADCAST, counts);
18 }
19
20 // increments sprite frame, loops when end is hit.. simple
21 void animate_sprite (float startframe, float frame_count)
22 {
23         if ((self.frame - startframe) >= (frame_count - 1 ))
24                 self.frame = startframe;
25         else
26                 self.frame = self.frame + 1;
27 }
28
29 void W_GiveWeapon (entity e, float wep, string name)
30 {
31         entity oldself;
32
33         if (!wep)
34                 return;
35
36         e.items = e.items | wep;
37
38         oldself = self;
39         self = e;
40
41         if (other.classname == "player")
42         {
43                 sprint (other, "You got the ^2");
44                 sprint (other, name);
45                 sprint (other, "\n");
46         }
47
48
49         self = oldself;
50 }
51
52 float W_CheckAmmo (void)
53 {
54         if (!cvar("g_use_ammunition"))
55                 return TRUE;
56
57         if (self.weapon == IT_LASER)
58                 return TRUE;
59         else if (self.currentammo)
60                 return TRUE;
61
62         return FALSE;
63 }
64
65 void FireRailgunBullet (vector start, vector end, float bdamage, float deathtype)
66 {
67         local vector hitloc, force, endpoint, dir;
68         local entity ent;
69         //local entity explosion;
70
71         dir = normalize(end - start);
72         force = dir * 800; //(bdamage * 10);
73
74         // go a little bit into the wall because we need to hit this wall later
75         end = end + dir;
76
77         // trace multiple times until we hit a wall, each obstacle will be made
78         // non-solid so we can hit the next, while doing this we spawn effects and
79         // note down which entities were hit so we can damage them later
80         while (1)
81         {
82                 traceline_hitcorpse (self, start, end, FALSE, self);
83
84                 //if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
85                 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
86                         te_plasmaburn (trace_endpos - dir * 6);
87
88                 // if it is world we can't hurt it so stop now
89                 if (trace_ent == world || trace_fraction == 1)
90                         break;
91
92                 // make the entity non-solid so we can hit the next one
93                 trace_ent.railgunhit = TRUE;
94                 trace_ent.railgunhitloc = end;
95                 trace_ent.railgunhitsolidbackup = trace_ent.solid;
96
97                 // stop if this is a wall
98                 if (trace_ent.solid == SOLID_BSP)
99                         break;
100
101                 // make the entity non-solid
102                 trace_ent.solid = SOLID_NOT;
103         }
104
105         endpoint = trace_endpos;
106
107         // find all the entities the railgun hit and restore their solid state
108         ent = findfloat(world, railgunhit, TRUE);
109         while (ent)
110         {
111                 // restore their solid type
112                 ent.solid = ent.railgunhitsolidbackup;
113                 ent = findfloat(ent, railgunhit, TRUE);
114         }
115
116         // spawn a temporary explosion entity for RadiusDamage calls
117         //explosion = spawn();
118
119         // find all the entities the railgun hit and hurt them
120         ent = findfloat(world, railgunhit, TRUE);
121         while (ent)
122         {
123                 // get the details we need to call the damage function
124                 hitloc = ent.railgunhitloc;
125                 ent.railgunhitloc = '0 0 0';
126                 ent.railgunhitsolidbackup = SOLID_NOT;
127                 ent.railgunhit = FALSE;
128
129                 // apply the damage
130                 if (ent.takedamage || ent.classname == "case")
131                         Damage (ent, self, self, bdamage, deathtype, hitloc, force);
132
133                 // create a small explosion to throw gibs around (if applicable)
134                 //setorigin (explosion, hitloc);
135                 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
136
137                 // advance to the next entity
138                 ent = findfloat(ent, railgunhit, TRUE);
139         }
140
141         // we're done with the explosion entity, remove it
142         //remove(explosion);
143
144         trace_endpos = endpoint;
145 }
146
147 void fireBullet (vector start, vector dir, float spread, float damage, float dtype, float tracer)
148 {
149         vector  end;
150         float r;
151         local entity e;
152
153         // use traceline_hitcorpse to make sure it can hit gibs and corpses too
154         dir = dir + randomvec() * spread;
155         end = start + dir * 8192;
156         traceline_hitcorpse (self, start, end, FALSE, self);
157
158         if (tracer)
159         {
160                 e = spawn();
161                 e.owner = self;
162                 e.movetype = MOVETYPE_FLY;
163                 e.solid = SOLID_NOT;
164                 e.think = SUB_Remove;
165                 e.nextthink = time + vlen(trace_endpos - start) / 6000;
166                 e.velocity = dir * 6000;
167                 e.angles = vectoangles(e.velocity);
168                 setmodel (e, "models/tracer.mdl");
169                 setsize (e, '0 0 0', '0 0 0');
170                 setorigin (e, start);
171                 e.effects = e.effects | EF_ADDITIVE | EF_FULLBRIGHT | EF_NOSHADOW;
172                 e.flags = FL_PROJECTILE;
173         }
174
175         if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
176         {
177                 if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
178                 {
179                         if (dtype == IT_SHOTGUN)
180                                 te_gunshot (trace_endpos);
181                         else
182                                 te_spike (trace_endpos);
183                         r = random ();
184                         if (r < 0.10)
185                                 PointSound (trace_endpos, "weapons/ric1.ogg", 1, ATTN_NORM);
186                         else if (r < 0.20)
187                                 PointSound (trace_endpos, "weapons/ric2.ogg", 1, ATTN_NORM);
188                         else if (r < 0.30)
189                                 PointSound (trace_endpos, "weapons/ric3.ogg", 1, ATTN_NORM);
190                 }
191                 //else if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
192                         //stuffcmd(self, "play2 misc/hit.wav\n");
193                         //sound (self, CHAN_BODY, "misc/hit.wav", 1, ATTN_NORM);
194                 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * damage * 5);
195         }
196 }