]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_common.qc
no setorigin in waypoint sprites (havoc);
[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 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float deathtype)
53 {
54         local vector hitloc, force, endpoint, dir;
55         local entity ent;
56         //local entity explosion;
57
58         dir = normalize(end - start);
59         force = dir * bforce;
60
61         // go a little bit into the wall because we need to hit this wall later
62         end = end + dir;
63
64         // trace multiple times until we hit a wall, each obstacle will be made
65         // non-solid so we can hit the next, while doing this we spawn effects and
66         // note down which entities were hit so we can damage them later
67         while (1)
68         {
69                 traceline_hitcorpse (self, start, end, FALSE, self);
70
71                 //if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
72                 //if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
73                 //      te_plasmaburn (trace_endpos - dir * 6);
74
75                 // if it is world we can't hurt it so stop now
76                 if (trace_ent == world || trace_fraction == 1)
77                         break;
78
79                 // make the entity non-solid so we can hit the next one
80                 trace_ent.railgunhit = TRUE;
81                 trace_ent.railgunhitloc = end;
82                 trace_ent.railgunhitsolidbackup = trace_ent.solid;
83
84                 // stop if this is a wall
85                 if (trace_ent.solid == SOLID_BSP)
86                         break;
87
88                 // make the entity non-solid
89                 trace_ent.solid = SOLID_NOT;
90         }
91
92         endpoint = trace_endpos;
93
94         // find all the entities the railgun hit and restore their solid state
95         ent = findfloat(world, railgunhit, TRUE);
96         while (ent)
97         {
98                 // restore their solid type
99                 ent.solid = ent.railgunhitsolidbackup;
100                 ent = findfloat(ent, railgunhit, TRUE);
101         }
102
103         // spawn a temporary explosion entity for RadiusDamage calls
104         //explosion = spawn();
105
106         // find all the entities the railgun hit and hurt them
107         ent = findfloat(world, railgunhit, TRUE);
108         while (ent)
109         {
110                 // get the details we need to call the damage function
111                 hitloc = ent.railgunhitloc;
112                 ent.railgunhitloc = '0 0 0';
113                 ent.railgunhitsolidbackup = SOLID_NOT;
114                 ent.railgunhit = FALSE;
115
116                 // apply the damage
117                 if (ent.takedamage || ent.classname == "case")
118                         Damage (ent, self, self, bdamage, deathtype, hitloc, force);
119
120                 // create a small explosion to throw gibs around (if applicable)
121                 //setorigin (explosion, hitloc);
122                 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
123
124                 // advance to the next entity
125                 ent = findfloat(ent, railgunhit, TRUE);
126         }
127
128         // we're done with the explosion entity, remove it
129         //remove(explosion);
130
131         trace_endpos = endpoint;
132 }
133
134 void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
135 {
136         vector  end;
137         local entity e;
138
139         // use traceline_hitcorpse to make sure it can hit gibs and corpses too
140         dir = dir + randomvec() * spread;
141         end = start + dir * MAX_SHOT_DISTANCE;
142         traceline_hitcorpse (self, start, end, FALSE, self);
143
144         if (tracer)
145         {
146                 e = spawn();
147                 e.owner = self;
148                 e.movetype = MOVETYPE_FLY;
149                 e.solid = SOLID_NOT;
150                 e.think = SUB_Remove;
151                 e.nextthink = time + vlen(trace_endpos - start) / 6000;
152                 e.velocity = dir * 6000;
153                 e.angles = vectoangles(e.velocity);
154                 setmodel (e, "models/tracer.mdl");
155                 setsize (e, '0 0 0', '0 0 0');
156                 setorigin (e, start);
157                 e.effects = e.effects | EF_ADDITIVE | EF_FULLBRIGHT | EF_NOSHADOW;
158                 e.flags = FL_PROJECTILE;
159         }
160
161         if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
162         {
163                 if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
164                 {
165                         if (dtype == IT_SHOTGUN)
166                                 te_gunshot (trace_endpos);
167                         else
168                                 te_spike (trace_endpos);
169                 }
170                 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
171         }
172 }