Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
ewheel.qc
Go to the documentation of this file.
1#include "ewheel.qh"
2
3#ifdef SVQC
4
10
11const int ewheel_anim_stop = 0;
16
18{
19 // Are we close enough to a path node to switch to the next?
20 if(turret_closetotarget(this, this.pathcurrent.origin, 64))
21 {
22#ifdef EWHEEL_FANCYPATH
23 if (this.pathcurrent.path_next == NULL)
24 {
25 // Path endpoint reached
27 this.pathcurrent = NULL;
28
29 if (this.pathgoal)
30 {
31 if (this.pathgoal.use)
32 this.pathgoal.use(this.pathgoal, NULL, NULL);
33
34 if (this.pathgoal.enemy)
35 {
36 this.pathcurrent = pathlib_astar(this, this.pathgoal.origin,this.pathgoal.enemy.origin);
37 this.pathgoal = this.pathgoal.enemy;
38 }
39 }
40 else
41 this.pathgoal = NULL;
42 }
43 else
44 this.pathcurrent = this.pathcurrent.path_next;
45#else
46 this.pathcurrent = this.pathcurrent.enemy;
47#endif
48 }
49
50 if (this.pathcurrent)
51 {
52 this.moveto = this.pathcurrent.origin;
53 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
54
56 }
57}
58
60{
61 int newframe;
62
63 this.steerto = steerlib_arrive(this, this.enemy.origin,this.target_range_optimal);
64
65 this.moveto = this.origin + this.steerto * 128;
66
67 if (this.tur_dist_enemy > this.target_range_optimal)
68 {
69 if ( this.tur_head.spawnshieldtime < 1 )
70 {
71 newframe = ewheel_anim_fwd_fast;
73 }
74 else if (this.tur_head.spawnshieldtime < 2)
75 {
76 newframe = ewheel_anim_fwd_slow;
78 }
79 else
80 {
81 newframe = ewheel_anim_fwd_slow;
83 }
84 }
85 else if (this.tur_dist_enemy < this.target_range_optimal * 0.5)
86 {
87 newframe = ewheel_anim_bck_slow;
89 }
90 else
91 {
92 newframe = ewheel_anim_stop;
94 }
95
96 turrets_setframe(this, newframe, false);
97}
98
100{
101 if(this.frame != 0)
102 {
103 this.SendFlags |= TNSF_ANIM;
104 this.anim_start_time = time;
105 }
106
107 this.frame = 0;
108 if(this.velocity)
110}
111
113{
114 entity e = find(NULL, targetname, this.target);
115 if (!e)
116 {
117 LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
118 this.target = "";
119 }
120
121 if (e.classname != "turret_checkpoint")
122 LOG_TRACE("Warning: not a turret path");
123 else
124 {
125
126#ifdef EWHEEL_FANCYPATH
127 this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
128 this.pathgoal = e;
129#else
130 this.pathcurrent = e;
131#endif
132 }
133}
134
135spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
136
137METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
138{
139 vector wish_angle, real_angle;
140
141 float vz = it.velocity_z;
142
143 it.angles_x = anglemods(it.angles_x);
144 it.angles_y = anglemods(it.angles_y);
145
146 fixedmakevectors(it.angles);
147
148 wish_angle = normalize(it.steerto);
149 wish_angle = vectoangles(wish_angle);
150 real_angle = wish_angle - it.angles;
151 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
152
153 it.tur_head.spawnshieldtime = fabs(real_angle_y);
154
155 float f = it.tur_head.aim_speed * frametime;
156 real_angle_y = bound(-f, real_angle_y, f);
157 it.angles_y = (it.angles_y + real_angle_y);
158
159 if(it.enemy)
161 else if(it.pathcurrent)
163 else
165
166 it.velocity_z = vz;
167
168 if(it.velocity)
169 it.SendFlags |= TNSF_MOVE;
170}
171
172METHOD(EWheel, tr_death, void(EWheel this, entity it))
173{
174 it.velocity = '0 0 0';
175
176#ifdef EWHEEL_FANCYPATH
177 if (it.pathcurrent)
178 pathlib_deletepath(it.pathcurrent.owner);
179#endif
180 it.pathcurrent = NULL;
181}
182
183METHOD(EWheel, tr_setup, void(EWheel this, entity it))
184{
185 if(it.move_movetype == MOVETYPE_WALK)
186 {
187 it.velocity = '0 0 0';
188 it.enemy = NULL;
189
190 setorigin(it, it.pos1);
191
192 if (it.target != "")
194 }
195
196 it.iscreature = true;
197 it.teleportable = TELEPORT_NORMAL;
198 if(!it.damagedbycontents)
200 it.damagedbycontents = true;
202 it.solid = SOLID_SLIDEBOX;
203 it.takedamage = DAMAGE_AIM;
204 it.idle_aim = '0 0 0';
205 it.pos1 = it.origin;
208 it.frame = it.tur_head.frame = 1;
210
211 it.tur_head.aim_speed = autocvar_g_turrets_unit_ewheel_turnrate;
212}
213
214#endif // SVQC
215#ifdef CSQC
216
218{
219 float dt;
220
221 dt = time - this.move_time;
222 this.move_time = time;
223 if(dt <= 0)
224 return;
225
227 setorigin(this, this.origin + this.velocity * dt);
228 this.tur_head.angles += dt * this.tur_head.avelocity;
229
230 if(GetResource(this, RES_HEALTH) < 127)
231 if(random() < 0.05)
232 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
233}
234
235METHOD(EWheel, tr_setup, void(EWheel this, entity it))
236{
237 it.gravity = 1;
239 it.move_time = time;
240 it.draw = ewheel_draw;
241}
242
243#endif // CSQC
244#ifdef MENUQC
246
247METHOD(EWheel, describe, string(EWheel this))
248{
249 TC(Ewheel, this);
251 PAR(_("The %s is a mobile turret that rolls around, attacking its targets when they enter its line of sight."), COLORED_NAME(this));
252 PAR(_("It attacks by shooting laser beams similar to those of the %s, from both of its two cannons."), COLORED_NAME(WEP_BLASTER));
253 return PAGE_TEXT;
254}
255
256#endif // MENUQC
ERASEABLE float anglemods(float v)
Definition angle.qc:13
ERASEABLE vector shortangle_vxy(vector ang1, vector ang2)
Definition angle.qc:58
void fixedmakevectors(vector a)
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
float anim_start_time
Definition items.qc:15
#define COLORED_NAME(this)
Definition color.qh:195
const int INITPRIO_FINDTARGET
Definition constants.qh:96
const float SOLID_SLIDEBOX
float frametime
vector velocity
float time
vector v_forward
vector origin
IntrusiveList g_damagedbycontents
Definition damage.qh:135
ent angles
Definition ent_cs.qc:121
const int ewheel_anim_stop
Definition ewheel.qc:11
void ewheel_findtarget(entity this)
Definition ewheel.qc:112
float autocvar_g_turrets_unit_ewheel_speed_slow
Definition ewheel.qc:6
void ewheel_move_path(entity this)
Definition ewheel.qc:17
float autocvar_g_turrets_unit_ewheel_turnrate
Definition ewheel.qc:9
float autocvar_g_turrets_unit_ewheel_speed_stop
Definition ewheel.qc:8
float autocvar_g_turrets_unit_ewheel_speed_slower
Definition ewheel.qc:7
float autocvar_g_turrets_unit_ewheel_speed_fast
Definition ewheel.qc:5
const int ewheel_anim_bck_fast
Definition ewheel.qc:15
void ewheel_move_enemy(entity this)
Definition ewheel.qc:59
const int ewheel_anim_fwd_slow
Definition ewheel.qc:12
void ewheel_move_idle(entity this)
Definition ewheel.qc:99
void ewheel_draw(entity this)
Definition ewheel.qc:217
const int ewheel_anim_fwd_fast
Definition ewheel.qc:13
const int ewheel_anim_bck_slow
Definition ewheel.qc:14
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define TC(T, sym)
Definition _all.inc:82
int SendFlags
Definition net.qh:118
#define LOG_TRACE(...)
Definition log.qh:76
float bound(float min, float value, float max)
entity find(entity start,.string field, string match)
float random(void)
vector vectoangles(vector v)
vector randomvec(void)
vector normalize(vector v)
float fabs(float f)
void movelib_brake_simple(entity this, float force)
Definition movelib.qc:167
#define movelib_move_simple(e, newdir, velo, blendrate)
Definition movelib.qh:36
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_WALK
Definition movetypes.qh:132
float move_time
Definition movetypes.qh:77
const int MOVETYPE_BOUNCE
Definition movetypes.qh:139
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
void pathlib_deletepath(entity start)
Definition main.qc:10
entity pathlib_astar(entity this, vector from, vector to)
Definition main.qc:353
#define spawnfunc(id)
Definition spawnfunc.qh:96
vector steerlib_arrive(entity this, vector point, float maximal_distance)
Pull toward a point, The further away, the stronger the pull.
Definition steerlib.qc:27
vector steerlib_attract2(entity this, vector point, float min_influense, float max_distance, float max_influense)
Definition steerlib.qc:45
vector steerto
Definition steerlib.qh:3
#define PAGE_TEXT
Definition string.qh:643
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:649
#define PAGE_TEXT_INIT()
Definition string.qh:642
const int DAMAGE_AIM
Definition subs.qh:81
entity enemy
Definition sv_ctf.qh:153
bool turret_closetotarget(entity this, vector targ, float range)
bool turret_initialize(entity this, Turret tur)
void turrets_setframe(entity this, float _frame, float client_only)
entity pathcurrent
Definition sv_turrets.qh:86
entity pathgoal
Definition sv_turrets.qh:88
entity tur_head
Definition sv_turrets.qh:28
float tur_dist_enemy
Definition sv_turrets.qh:34
const int TELEPORT_NORMAL
string targetname
Definition triggers.qh:56
string target
Definition triggers.qh:55
const int TFL_TARGETSELECT_TEAMCHECK
Definition turret.qh:87
const int TFL_TARGETSELECT_PLAYERS
Definition turret.qh:82
const int TFL_TARGETSELECT_RANGELIMITS
Definition turret.qh:86
const int TFL_AMMO_ENERGY
Definition turret.qh:157
const int TNSF_MOVE
Definition turret.qh:189
const int TFL_TARGETSELECT_LOS
Definition turret.qh:81
const int TNSF_ANIM
Definition turret.qh:191
const int TFL_AMMO_RECHARGE
Definition turret.qh:160
const int TFL_AMMO_RECIEVE
Definition turret.qh:161
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2209
vector moveto
Definition zombie.qc:17