]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/units/unit_ewheel.qc
Merge remote branch 'origin/terencehill/small_cleanup'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / units / unit_ewheel.qc
1 #define ewheel_amin_stop 0
2 #define ewheel_amin_fwd_slow 1
3 #define ewheel_amin_fwd_fast 2
4 #define ewheel_amin_bck_slow 3
5 #define ewheel_amin_bck_fast 4
6
7 float ewheel_speed_fast;
8 float ewheel_speed_slow;
9 float ewheel_speed_slower;
10 float ewheel_speed_stop;
11
12 void turret_ewheel_loadcvars()
13 {
14     ewheel_speed_fast   = autocvar_g_turrets_unit_ewheel_speed_fast;
15     ewheel_speed_slow   = autocvar_g_turrets_unit_ewheel_speed_slow;
16     ewheel_speed_slower = autocvar_g_turrets_unit_ewheel_speed_slower;
17     ewheel_speed_stop   = autocvar_g_turrets_unit_ewheel_speed_stop;
18 }
19
20 void turret_ewheel_projectile_explode()
21 {
22     vector org2;
23
24     org2 = findbetterlocation (self.origin, 8);
25     pointparticles(particleeffectnum("laser_impact"), org2, trace_plane_normal * 1000, 1);
26     //w_deathtypestring = "saw the eweel. to late.";
27 #ifdef TURRET_DEBUG
28     float d;
29
30     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);
31     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d;
32     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;
33 #else
34     RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);
35 #endif
36     sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
37
38     remove (self);
39 }
40
41
42 void ewheel_attack()
43 {
44     entity proj;
45     float i;
46
47     for (i = 0; i < 1; ++i)
48     {
49         turret_do_updates(self);
50
51         sound (self, CHAN_WEAPON, "weapons/lasergun_fire.wav", VOL_BASE, ATTN_NORM);
52         pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
53
54         proj                    = spawn ();
55         setorigin(proj, self.tur_shotorg);
56         proj.classname       = "ewheel bolt";
57         proj.owner           = self;
58         proj.bot_dodge       = FALSE;
59         proj.bot_dodgerating = self.shot_dmg;
60         proj.think           = turret_ewheel_projectile_explode;
61         proj.nextthink       = time + 9;
62         //proj.solid           = SOLID_TRIGGER;
63         proj.movetype        = MOVETYPE_FLYMISSILE;
64         proj.velocity        = normalize(self.tur_shotdir_updated + randomvec() * self.shot_spread) * self.shot_speed;
65         proj.touch           = turret_ewheel_projectile_explode;
66         proj.enemy           = self.enemy;
67         proj.flags           = FL_PROJECTILE | FL_NOTARGET;
68         PROJECTILE_MAKETRIGGER(proj);
69
70         CSQCProjectile(proj, TRUE, PROJECTILE_LASER, TRUE);
71
72         self.tur_head.frame += 2;
73
74         if (self.tur_head.frame > 3)
75             self.tur_head.frame = 0;
76     }
77
78 }
79
80 void ewheel_move_path()
81 {
82
83     // Are we close enougth to a path node to switch to the next?
84     if (vlen(self.origin  - self.pathcurrent.origin) < 64)
85         if (self.pathcurrent.path_next == world)
86         {
87             // Path endpoint reached
88             pathlib_deletepath(self.pathcurrent.owner);
89             self.pathcurrent = world;
90
91             if (self.pathgoal)
92             {
93                 if (self.pathgoal.use)
94                     self.pathgoal.use();
95
96                 if (self.pathgoal.enemy)
97                 {
98                     self.pathcurrent = pathlib_astar(self.pathgoal.origin,self.pathgoal.enemy.origin);
99                     self.pathgoal = self.pathgoal.enemy;
100                 }
101             }
102             else
103                 self.pathgoal = world;
104         }
105         else
106             self.pathcurrent = self.pathcurrent.path_next;
107
108
109
110     if (self.pathcurrent)
111     {
112
113         self.moveto = self.pathcurrent.origin;
114         self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
115
116         movelib_move_simple(v_forward, ewheel_speed_fast, 0.4);
117
118         return;
119     }
120 }
121
122 void  ewheel_move_enemy()
123 {
124
125     self.steerto = steerlib_arrive(self.enemy.origin,self.target_range_optimal);
126
127     //self.steerto = steerlib_standoff(self.enemy.origin,self.target_range_optimal);
128     //self.steerto = steerlib_beamsteer(self.steerto,1024,64,68,256);
129     self.moveto  = self.origin + self.steerto * 128;
130
131     if (self.tur_dist_enemy > self.target_range_optimal)
132     {
133         if ( self.tur_head.spawnshieldtime < 1 )
134         {
135             self.frame = ewheel_amin_fwd_fast;
136             movelib_move_simple(v_forward, ewheel_speed_fast, 0.4);
137         }
138         else if (self.tur_head.spawnshieldtime < 2)
139         {
140
141             self.frame = ewheel_amin_fwd_slow;
142             movelib_move_simple(v_forward, ewheel_speed_slow, 0.4);
143        }
144         else
145         {
146             self.frame = ewheel_amin_fwd_slow;
147             movelib_move_simple(v_forward, ewheel_speed_slower, 0.4);
148         }
149     }
150     else if (self.tur_dist_enemy < self.target_range_optimal * 0.5)
151     {
152         self.frame = ewheel_amin_bck_slow;
153         movelib_move_simple(v_forward * -1, ewheel_speed_slow, 0.4);
154     }
155     else
156     {
157         self.frame = ewheel_amin_stop;
158         movelib_beak_simple(ewheel_speed_stop);
159     }
160 }
161
162
163 void ewheel_move_idle()
164 {
165     self.frame = 0;
166     if (vlen(self.velocity))
167         movelib_beak_simple(ewheel_speed_stop);
168 }
169
170 void ewheel_postthink()
171 {
172     float vz;
173     vector wish_angle,real_angle;
174
175     /*
176     if(self.enemy)
177         dprint("enemy!\n");
178     else
179         dprint("nothign =(!\n");
180     */
181
182     vz = self.velocity_z;
183
184     self.angles_x = anglemods(self.angles_x);
185     self.angles_y = anglemods(self.angles_y);
186
187     //self.angles_x *= -1;
188     fixedmakevectors(self.angles);
189     //self.angles_x *= -1;
190
191     wish_angle = normalize(self.steerto);
192     wish_angle = vectoangles(wish_angle);
193     real_angle = wish_angle - self.angles;
194     real_angle = shortangle_vxy(real_angle,self.tur_head.angles);
195
196     self.tur_head.spawnshieldtime = fabs(real_angle_y);
197     real_angle_y  = bound(-self.tur_head.aim_speed,real_angle_y,self.tur_head.aim_speed);
198     self.angles_y = (self.angles_y + real_angle_y);
199
200     // Simulate banking
201     self.angles_z -= self.angles_z * frametime * 2;
202     self.angles_z = bound(-45,self.angles_z  + ((real_angle_y * -25) * frametime),45);
203
204     if(self.enemy)
205         ewheel_move_enemy();
206     else if(self.pathcurrent)
207         ewheel_move_path();
208     else
209         ewheel_move_idle();
210
211
212     self.velocity_z = vz;
213 }
214
215 void ewheel_respawnhook()
216 {
217     entity e;
218
219     // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
220     if(self.movetype  != MOVETYPE_WALK)
221                 return;
222                 
223     self.velocity = '0 0 0';
224     self.enemy = world;
225
226     setorigin(self, self.pos1);
227
228     if (self.target != "")
229     {
230         e = find(world,targetname,self.target);
231         if (!e)
232         {
233             dprint("Initital waypoint for ewheel does NOT exsist, fix your map!\n");
234             self.target = "";
235         }
236
237         if (e.classname != "turret_checkpoint")
238             dprint("Warning: not a turrret path\n");
239         else
240         {
241             self.pathcurrent = WALKER_PATH(self.origin,e.origin);
242             self.pathgoal = e;
243         }
244     }
245 }
246
247 void ewheel_diehook()
248 {
249     self.velocity = '0 0 0';
250
251     turret_trowgib2(self.origin, self.velocity + '0 0 400', '-0.6 -0.2 -02', self, 3 + time + random() * 2);
252
253     if (self.pathcurrent)
254         pathlib_deletepath(self.pathcurrent.owner);
255
256     self.pathcurrent = world;
257 }
258
259 void turret_ewheel_dinit()
260 {
261     entity e;
262
263     if (self.netname == "")      self.netname     = "eWheel Turret";
264
265     if (self.target != "")
266     {
267         e = find(world,targetname,self.target);
268         if (!e)
269         {
270             bprint("Warning! initital waypoint for ewheel does NOT exsist!\n");
271             self.target = "";
272         }
273
274         if (e.classname != "turret_checkpoint")
275             dprint("Warning: not a turrret path\n");
276         else
277             self.goalcurrent = e;
278     }
279
280     self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
281     self.turrcaps_flags = TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MOVE | TFL_TURRCAPS_ROAM ;
282     self.turret_respawnhook = ewheel_respawnhook;
283
284     self.turret_diehook = ewheel_diehook;
285
286     if (turret_stdproc_init("ewheel_std",0,"models/turrets/ewheel-base2.md3","models/turrets/ewheel-gun1.md3") == 0)
287     {
288         remove(self);
289         return;
290     }
291
292     self.target_select_flags   = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
293     self.target_select_flags   = TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
294     self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;// | TFL_TARGETSELECT_LOS;
295     self.target_validate_flags = TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;// | TFL_TARGETSELECT_LOS;
296     self.damage_flags          |= TFL_DMG_DEATH_NOGIBS;
297
298     self.iscreature = TRUE;
299     self.movetype   = MOVETYPE_WALK;
300     self.solid      = SOLID_SLIDEBOX;
301     self.takedamage = DAMAGE_AIM;
302
303     setsize(self, '-32 -32 0', '32 32 48');
304     self.idle_aim = '0 0 0';
305
306     self.pos1 = self.origin;
307
308     // Our fire routine
309     self.turret_firefunc  = ewheel_attack;
310     self.turret_postthink = ewheel_postthink;
311     self.tur_head.frame = 1;
312
313     // Convert from dgr / sec to dgr / tic
314     self.tur_head.aim_speed = autocvar_g_turrets_unit_ewheel_turnrate;
315     self.tur_head.aim_speed = self.tur_head.aim_speed / (1 / self.ticrate);
316
317     if (!turret_tag_fire_update())
318         dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");
319
320     //setorigin(self,self.origin + '0 0 128');
321     if (self.target != "")
322     {
323         e = find(world,targetname,self.target);
324         if (!e)
325         {
326             dprint("Initital waypoint for ewheel does NOT exsist, fix your map!\n");
327             self.target = "";
328         }
329
330         if (e.classname != "turret_checkpoint")
331             dprint("Warning: not a turrret path\n");
332         else
333         {
334             self.pathcurrent = WALKER_PATH(self.origin, e.origin);
335             self.pathgoal = e;
336         }
337     }
338 }
339
340 void spawnfunc_turret_ewheel()
341 {
342     g_turrets_common_precash();
343
344     precache_model ("models/turrets/ewheel-base2.md3");
345     precache_model ("models/turrets/ewheel-gun1.md3");
346
347     precache_model ("models/pathlib/goodsquare.md3");
348     precache_model ("models/pathlib/badsquare.md3");
349     precache_model ("models/pathlib/square.md3");
350
351     turret_ewheel_loadcvars();
352
353     self.think = turret_ewheel_dinit;
354     self.nextthink = time + 0.5;
355 }