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