]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/plats.qc
Plat.qc added
[divverent/nexuiz.git] / qcsrc / plats.qc
1 void() plat_center_touch;
2 void() plat_outside_touch;
3 void() plat_trigger_use;
4 void() plat_go_up;
5 void() plat_go_down;
6 void() plat_crush;
7 float PLAT_LOW_TRIGGER = 1;
8
9 .float state;
10 .float          t_length, t_width;
11
12 void() plat_spawn_inside_trigger =
13 {
14         local entity trigger;
15         local vector tmin, tmax;
16
17         trigger = spawn();
18         trigger.touch = plat_center_touch;
19         trigger.movetype = MOVETYPE_NONE;
20         trigger.solid = SOLID_TRIGGER;
21         trigger.enemy = self;
22         
23         tmin = self.mins + '25 25 0';
24         tmax = self.maxs - '25 25 -8';
25         tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8);
26         if (self.spawnflags & PLAT_LOW_TRIGGER)
27                 tmax_z = tmin_z + 8;
28         
29         if (self.size_x <= 50)
30         {
31                 tmin_x = (self.mins_x + self.maxs_x) / 2;
32                 tmax_x = tmin_x + 1;
33         }
34         if (self.size_y <= 50)
35         {
36                 tmin_y = (self.mins_y + self.maxs_y) / 2;
37                 tmax_y = tmin_y + 1;
38         }
39         
40         setsize (trigger, tmin, tmax);
41 };
42
43 void() plat_hit_top =
44 {
45         sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
46         self.state = 1;
47         self.think = plat_go_down;
48         self.nextthink = self.ltime + 3;
49 };
50
51 void() plat_hit_bottom =
52 {
53         sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
54         self.state = 2;
55 };
56
57 void() plat_go_down =
58 {
59         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
60         self.state = 3;
61         SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
62 };
63
64 void() plat_go_up =
65 {
66         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
67         self.state = 4;
68         SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
69 };
70
71 void() plat_center_touch =
72 {
73         if (other.classname != "player")
74                 return;
75                 
76         if (other.health <= 0)
77                 return;
78
79         self = self.enemy;
80         if (self.state == 2)
81                 plat_go_up ();
82         else if (self.state == 1)
83                 self.nextthink = self.ltime + 1;        // delay going down
84 };
85
86 void() plat_outside_touch =
87 {
88         if (other.classname != "player")
89                 return;
90
91         if (other.health <= 0)
92                 return;
93                 
94         self = self.enemy;
95         if (self.state == 1)
96                 plat_go_down ();
97 };
98
99 void() plat_trigger_use =
100 {
101         if (self.think)
102                 return;         // allready activated
103         plat_go_down();
104 };
105
106
107 void() plat_crush =
108 {
109         if (self.state == 4)
110                 plat_go_down ();
111         else if (self.state == 3)
112                 plat_go_up ();
113         else
114                 objerror ("plat_crush: bad self.state\n");
115 };
116
117 void() plat_use =
118 {
119         self.use = SUB_Null;
120         if (self.state != 4)
121                 objerror ("plat_use: not in up state");
122         plat_go_down();
123 };
124
125
126 .string sound1, sound2;
127
128 void() func_plat =
129 {
130         if (!self.t_length)
131                 self.t_length = 80;
132         if (!self.t_width)
133                 self.t_width = 10;
134
135         if (self.sounds == 0)
136                 self.sounds = 2;
137
138         if (self.sounds == 1)
139         {
140                 precache_sound ("plats/plat1.wav");
141                 precache_sound ("plats/plat2.wav");
142                 self.noise = "plats/plat1.wav";
143                 self.noise1 = "plats/plat2.wav";
144         }
145
146         if (self.sounds == 2)
147         {
148                 precache_sound ("plats/medplat1.wav");
149                 precache_sound ("plats/medplat2.wav");
150                 self.noise = "plats/medplat1.wav";
151                 self.noise1 = "plats/medplat2.wav";
152         }
153
154         if (self.sound1)
155         {
156                 precache_sound (self.sound1);
157                 self.noise = self.sound1;
158         }
159         if (self.sound2)
160         {
161                 precache_sound (self.sound2);
162                 self.noise1 = self.sound2;
163         }
164
165         self.mangle = self.angles;
166         self.angles = '0 0 0';
167
168         self.classname = "plat";
169         self.solid = SOLID_BSP;
170         self.movetype = MOVETYPE_PUSH;
171         setorigin (self, self.origin);  
172         setmodel (self, self.model);
173         setsize (self, self.mins , self.maxs);
174
175         self.blocked = plat_crush;
176         if (!self.speed)
177                 self.speed = 150;
178         self.pos1 = self.origin;
179         self.pos2 = self.origin;
180         self.pos2_z = self.origin_z - self.size_z + 8;
181
182         self.use = plat_trigger_use;
183
184         plat_spawn_inside_trigger ();   // the "start moving" trigger   
185
186         if (self.targetname)
187         {
188                 self.state = 4;
189                 self.use = plat_use;
190         }
191         else
192         {
193                 setorigin (self, self.pos2);
194                 self.state = 2;
195         }
196 };
197
198
199
200 void() train_next;
201 void() func_train_find;
202
203 void() train_blocked =
204 {
205         if (time < self.attack_finished)
206                 return;
207         self.attack_finished = time + 0.5;
208 };
209 void() train_use =
210 {
211         if (self.think != func_train_find)
212                 return;
213         train_next();
214 };
215
216 void() train_wait =
217 {
218         if (self.wait)
219         {
220                 self.nextthink = self.ltime + self.wait;
221                 sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
222         }
223         else
224                 self.nextthink = self.ltime + 0.1;
225         
226         self.think = train_next;
227 };
228
229 void() train_next =
230 {
231         local entity targ;
232
233         targ = find (world, targetname, self.target);
234         self.target = targ.target;
235         if (!self.target)
236                 objerror ("train_next: no next target");
237         if (targ.wait)
238                 self.wait = targ.wait;
239         else
240                 self.wait = 0;
241         sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
242         SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait);
243 };
244
245 void() func_train_find =
246 {
247         local entity targ;
248
249         targ = find (world, targetname, self.target);
250         self.target = targ.target;
251         setorigin (self, targ.origin - self.mins);
252         if (!self.targetname)
253         {       // not triggered, so start immediately
254                 self.nextthink = self.ltime + 0.1;
255                 self.think = train_next;
256         }
257 };
258
259
260 void() func_train =
261 {       
262         if (!self.speed)
263                 self.speed = 100;
264         if (!self.target)
265                 objerror ("func_train without a target");
266
267         if (self.sounds == 0)
268         {
269                 self.noise = ("misc/null.wav");
270                 precache_sound ("misc/null.wav");
271                 self.noise1 = ("misc/null.wav");
272                 precache_sound ("misc/null.wav");
273         }
274
275         if (self.sounds == 1)
276         {
277                 self.noise = ("plats/train2.wav");
278                 precache_sound ("plats/train2.wav");
279                 self.noise1 = ("plats/train1.wav");
280                 precache_sound ("plats/train1.wav");
281         }
282
283         self.solid = SOLID_BSP;
284         self.movetype = MOVETYPE_PUSH;
285         self.blocked = train_blocked;
286         self.use = train_use;
287         self.classname = "train";
288
289         setmodel (self, self.model);
290         setsize (self, self.mins , self.maxs);
291         setorigin (self, self.origin);
292         self.nextthink = self.ltime + 0.1;
293         self.think = func_train_find;
294 };