]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_casings.qc
csqc casings
[divverent/nexuiz.git] / data / qcsrc / server / g_casings.qc
1 #if 0
2 void casingtouch()
3 {
4         PROJECTILE_TOUCH;
5
6         if (other.solid == SOLID_BSP)
7         if (vlen(self.velocity) >= 50)
8         if (time >= self.attack_finished_single)
9         {
10                 string s;
11                 float f;
12
13                 f = floor(random() * 3) + 1;
14                 if(self.state == 1)
15                         s = strcat("weapons/casings", ftos(f), ".wav");
16                 else if(self.state == 2)
17                         s = strcat("weapons/steel", ftos(f), ".wav");
18                 else
19                         s = strcat("weapons/brass", ftos(f), ".wav");
20                 sound (self, CHAN_PROJECTILE, s, VOL_BASE, ATTN_NORM);
21         }
22         self.attack_finished_single = time + 0.2;
23         //self.touch = SUB_Null; // one tink is enough
24         //self.dest = self.origin - self.groundentity.origin;
25 };
26
27 void casingthink()
28 {
29         local   float   p;
30         self.nextthink = time + 0.1;
31         if (self.flags & FL_ONGROUND)
32         {
33         // just keep the yaw angle
34                 self.angles_x = 0;
35                 self.angles_z = 0;
36                 self.flags = self.flags - FL_ONGROUND;
37                 self.nextthink = time + 0.5;
38         }
39         p = pointcontents(self.origin);
40         if (p == CONTENT_SOLID || p == CONTENT_LAVA || p == CONTENT_SKY)
41         {
42                 removedecor(self);
43                 return;
44         }
45         if (time > self.cnt)
46         {
47                 self.nextthink = time;
48                 self.alpha = self.alpha - frametime;
49                 if (self.alpha < 0.0625)
50                         removedecor(self);
51         }
52 };
53
54 // knock loose the casing when disturbed
55 void casingknockedloosefunc()
56 {
57         self.movetype = MOVETYPE_BOUNCE;
58         self.flags = self.flags - (self.flags & FL_ONGROUND);
59         self.avelocity = randomvec() * 300;
60         self.nextthink = time + 0.1;
61         self.touch = casingtouch;
62 };
63
64 void SpawnCasing(vector org, vector vel, float randomvel, vector ang, vector avel, float randomavel, float casingtype)
65 {
66         local entity e;
67         if (cvar("temp1") & 2048)
68                 return;
69
70         e = newdecor();
71         e.isdecor = TRUE;
72         e.alpha = 1;
73         e.state = casingtype;
74         //e.forcescale = 15;
75         e.movetype = MOVETYPE_BOUNCE;
76         e.solid = SOLID_TRIGGER;
77         e.velocity = vel + randomvec() * randomvel;
78         e.angles = ang;
79         e.avelocity = avel + randomvec() * randomavel;
80         e.nextthink = time;
81         e.think = casingthink;
82         e.touch = casingtouch;
83         //e.knockedloosefunc = casingknockedloosefunc;
84         e.effects = EF_LOWPRECISION;
85         e.createdtime = time;
86         if (casingtype == 1)
87         {
88                 setmodel (e, "models/casing_shell.mdl"); // precision set above
89                 e.cnt = time + 30;
90                 // bias to make these be considered more important than other things
91                 e.createdtime = time + 1;
92         }
93         else if (casingtype == 2)
94         {
95                 // FIXME: this is not used and not precached, uncomment if you need it
96                 //setmodel (e, "models/casing_steel.mdl"); // precision set above
97                 e.cnt = time + 10;
98         }
99         else
100         {
101                 setmodel (e, "models/casing_bronze.mdl"); // precision set above
102                 e.cnt = time + 10;
103         }
104         if (maxclients == 1)
105                 e.cnt = time + 3000;
106         setsize (e, '0 0 -1', '0 0 -1');
107         setorigin (e, org);
108 };
109 #endif
110
111 float Casing_SendEntity(entity to, float sf)
112 {
113         WriteByte(MSG_ENTITY, ENT_CLIENT_CASING);
114         WriteByte(MSG_ENTITY, self.state); // actually type
115         WriteCoord(MSG_ENTITY, self.origin_x);
116         WriteCoord(MSG_ENTITY, self.origin_y);
117         WriteCoord(MSG_ENTITY, self.origin_z);
118         WriteShort(MSG_ENTITY, self.oldorigin_x); // acrually compressed velocity
119         WriteByte(MSG_ENTITY, self.angles_x * 256 / 360);
120         WriteByte(MSG_ENTITY, self.angles_y * 256 / 360);
121         WriteByte(MSG_ENTITY, self.angles_z * 256 / 360);
122         return TRUE;
123 }
124
125 void SpawnCasing(vector org, vector vel, float randomvel, vector ang, vector avel, float randomavel, float casingtype)
126 {
127         entity e;
128
129         e = spawn();
130         e.state = casingtype;
131         e.origin = org;
132         e.velocity = vel;
133         e.angles = ang;
134
135         e.oldorigin_x = compressShortVector(e.velocity);
136
137         setmodel(e, "null");
138         e.SendEntity = Casing_SendEntity;
139
140         e.nextthink = time + 0.2;
141         e.think = SUB_Remove;
142                 // 0.2s should be enough time for all clients to receive this ent once, do the gibbage and be done with it
143 }