]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/ewheel.qc
Merge branch 'terencehill/hud_no_joypad_keys' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / ewheel.qc
1 #ifndef TURRET_EWHEEL_H
2 #define TURRET_EWHEEL_H
3
4 //#define EWHEEL_FANCYPATH
5
6 #include "ewheel_weapon.qh"
7
8 CLASS(EWheel, Turret)
9 /* spawnflags */ ATTRIB(EWheel, spawnflags, int, TUR_FLAG_PLAYER | TUR_FLAG_MOVE | TUR_FLAG_ROAM);
10 /* mins       */ ATTRIB(EWheel, mins, vector, '-32 -32 0');
11 /* maxs       */ ATTRIB(EWheel, maxs, vector, '32 32 48');
12 /* modelname  */ ATTRIB(EWheel, mdl, string, "ewheel-base2.md3");
13 /* model      */ ATTRIB_STRZONE(EWheel, model, string, strcat("models/turrets/", this.mdl));
14 /* head_model */ ATTRIB_STRZONE(EWheel, head_model, string, strcat("models/turrets/", "ewheel-gun1.md3"));
15 /* netname    */ ATTRIB(EWheel, netname, string, "ewheel");
16 /* fullname   */ ATTRIB(EWheel, turret_name, string, _("eWheel Turret"));
17     ATTRIB(EWheel, m_weapon, Weapon, WEP_EWHEEL);
18 ENDCLASS(EWheel)
19 REGISTER_TURRET(EWHEEL, NEW(EWheel));
20
21 #endif
22
23 #ifdef IMPLEMENTATION
24
25 #ifdef SVQC
26
27 float autocvar_g_turrets_unit_ewheel_speed_fast;
28 float autocvar_g_turrets_unit_ewheel_speed_slow;
29 float autocvar_g_turrets_unit_ewheel_speed_slower;
30 float autocvar_g_turrets_unit_ewheel_speed_stop;
31 float autocvar_g_turrets_unit_ewheel_turnrate;
32
33 const float ewheel_anim_stop = 0;
34 const float ewheel_anim_fwd_slow = 1;
35 const float ewheel_anim_fwd_fast = 2;
36 const float ewheel_anim_bck_slow = 3;
37 const float ewheel_anim_bck_fast = 4;
38
39 void ewheel_move_path()
40 {SELFPARAM();
41 #ifdef EWHEEL_FANCYPATH
42     // Are we close enougth to a path node to switch to the next?
43     if(vdist(self.origin - self.pathcurrent.origin, <, 64))
44         if (self.pathcurrent.path_next == world)
45         {
46             // Path endpoint reached
47             pathlib_deletepath(self.pathcurrent.owner);
48             self.pathcurrent = world;
49
50             if (self.pathgoal)
51             {
52                 if (self.pathgoal.use)
53                     self.pathgoal.use(self.pathgoal, NULL, NULL);
54
55                 if (self.pathgoal.enemy)
56                 {
57                     self.pathcurrent = pathlib_astar(self, self.pathgoal.origin,self.pathgoal.enemy.origin);
58                     self.pathgoal = self.pathgoal.enemy;
59                 }
60             }
61             else
62                 self.pathgoal = world;
63         }
64         else
65             self.pathcurrent = self.pathcurrent.path_next;
66
67 #else
68     if(vdist(self.origin - self.pathcurrent.origin, <, 64))
69         self.pathcurrent = self.pathcurrent.enemy;
70 #endif
71
72     if (self.pathcurrent)
73     {
74
75         self.moveto = self.pathcurrent.origin;
76         self.steerto = steerlib_attract2(self, self.moveto, 0.5, 500, 0.95);
77
78         movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
79     }
80 }
81
82 void ewheel_move_enemy()
83 {SELFPARAM();
84     float newframe;
85
86     self.steerto = steerlib_arrive(self, self.enemy.origin,self.target_range_optimal);
87
88     self.moveto  = self.origin + self.steerto * 128;
89
90     if (self.tur_dist_enemy > self.target_range_optimal)
91     {
92         if ( self.tur_head.spawnshieldtime < 1 )
93         {
94             newframe = ewheel_anim_fwd_fast;
95             movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
96         }
97         else if (self.tur_head.spawnshieldtime < 2)
98         {
99
100             newframe = ewheel_anim_fwd_slow;
101             movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
102        }
103         else
104         {
105             newframe = ewheel_anim_fwd_slow;
106             movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4);
107         }
108     }
109     else if (self.tur_dist_enemy < self.target_range_optimal * 0.5)
110     {
111         newframe = ewheel_anim_bck_slow;
112         movelib_move_simple(self, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
113     }
114     else
115     {
116         newframe = ewheel_anim_stop;
117         movelib_brake_simple(self, (autocvar_g_turrets_unit_ewheel_speed_stop));
118     }
119
120     turrets_setframe(newframe, false);
121 }
122
123 void ewheel_move_idle()
124 {SELFPARAM();
125     if(self.frame != 0)
126     {
127         self.SendFlags |= TNSF_ANIM;
128         self.anim_start_time = time;
129     }
130
131     self.frame = 0;
132     if(self.velocity)
133         movelib_brake_simple(self, (autocvar_g_turrets_unit_ewheel_speed_stop));
134 }
135
136 spawnfunc(turret_ewheel) { if(!turret_initialize(TUR_EWHEEL)) remove(this); }
137
138 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
139 {
140     SELFPARAM();
141     float vz;
142     vector wish_angle, real_angle;
143
144     vz = self.velocity_z;
145
146     self.angles_x = anglemods(self.angles_x);
147     self.angles_y = anglemods(self.angles_y);
148
149     fixedmakevectors(self.angles);
150
151     wish_angle = normalize(self.steerto);
152     wish_angle = vectoangles(wish_angle);
153     real_angle = wish_angle - self.angles;
154     real_angle = shortangle_vxy(real_angle, self.tur_head.angles);
155
156     self.tur_head.spawnshieldtime = fabs(real_angle_y);
157     real_angle_y  = bound(-self.tur_head.aim_speed, real_angle_y, self.tur_head.aim_speed);
158     self.angles_y = (self.angles_y + real_angle_y);
159
160     if(self.enemy)
161         ewheel_move_enemy();
162     else if(self.pathcurrent)
163         ewheel_move_path();
164     else
165         ewheel_move_idle();
166
167     self.velocity_z = vz;
168
169     if(self.velocity)
170         self.SendFlags |= TNSF_MOVE;
171 }
172
173 METHOD(EWheel, tr_death, void(EWheel this, entity it))
174 {
175     it.velocity = '0 0 0';
176
177 #ifdef EWHEEL_FANCYPATH
178     if (self.pathcurrent)
179         pathlib_deletepath(it.pathcurrent.owner);
180 #endif
181     it.pathcurrent = NULL;
182 }
183
184 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
185 {
186     entity e;
187
188     if(it.movetype == MOVETYPE_WALK)
189     {
190         it.velocity = '0 0 0';
191         it.enemy = world;
192
193         setorigin(it, it.pos1);
194
195         if (it.target != "")
196         {
197             e = find(world, targetname, it.target);
198             if (!e)
199             {
200                 LOG_TRACE("Initital waypoint for ewheel does NOT exsist, fix your map!\n");
201                 it.target = "";
202             }
203
204             if (e.classname != "turret_checkpoint")
205                 LOG_TRACE("Warning: not a turrret path\n");
206             else
207             {
208
209 #ifdef EWHEEL_FANCYPATH
210                 it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
211                 it.pathgoal = e;
212 #else
213                 it.pathcurrent  = e;
214 #endif
215             }
216         }
217     }
218
219     it.iscreature                               = true;
220     it.teleportable                     = TELEPORT_NORMAL;
221     it.damagedbycontents                = true;
222     it.movetype                         = MOVETYPE_WALK;
223     it.solid                                    = SOLID_SLIDEBOX;
224     it.takedamage                               = DAMAGE_AIM;
225     it.idle_aim                         = '0 0 0';
226     it.pos1                                     = it.origin;
227     it.target_select_flags      = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
228     it.target_validate_flags    = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
229     it.frame                                    = it.tur_head.frame = 1;
230     it.ammo_flags                               = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
231
232     // Convert from dgr / sec to dgr / tic
233     it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate);
234     it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate);
235 }
236
237 #endif // SVQC
238 #ifdef CSQC
239
240 void ewheel_draw(entity this)
241 {
242     float dt;
243
244     dt = time - this.move_time;
245     this.move_time = time;
246     if(dt <= 0)
247         return;
248
249     fixedmakevectors(this.angles);
250     setorigin(this, this.origin + this.velocity * dt);
251     this.tur_head.angles += dt * this.tur_head.move_avelocity;
252     this.angles_y = this.move_angles_y;
253
254     if (this.health < 127)
255     if(random() < 0.05)
256         te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
257 }
258
259         METHOD(EWheel, tr_setup, void(EWheel this, entity it))
260         {
261             it.gravity          = 1;
262             it.movetype         = MOVETYPE_BOUNCE;
263             it.move_movetype    = MOVETYPE_BOUNCE;
264             it.move_origin      = it.origin;
265             it.move_time                = time;
266             it.draw                     = ewheel_draw;
267         }
268
269 #endif // CSQC
270 #endif