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 this.moveto = this.origin + this.steerto * 128;
65
66 if (this.tur_dist_enemy > this.target_range_optimal)
67 {
68 if (this.tur_head.spawnshieldtime < 1)
69 {
70 newframe = ewheel_anim_fwd_fast;
72 }
73 else if (this.tur_head.spawnshieldtime < 2)
74 {
75 newframe = ewheel_anim_fwd_slow;
77 }
78 else
79 {
80 newframe = ewheel_anim_fwd_slow;
82 }
83 }
84 else if (this.tur_dist_enemy < this.target_range_optimal * 0.5)
85 {
86 newframe = ewheel_anim_bck_slow;
88 }
89 else
90 {
91 newframe = ewheel_anim_stop;
93 }
94
95 turrets_setframe(this, newframe, false);
96}
97
99{
100 if (this.frame != 0)
101 {
102 this.SendFlags |= TNSF_ANIM;
103 this.anim_start_time = time;
104 this.frame = 0;
105 }
106
107 if (this.velocity)
109}
110
112{
113 entity e = find(NULL, targetname, this.target);
114 if (!e)
115 {
116 LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
117 this.target = "";
118 }
119
120 if (e.classname != "turret_checkpoint")
121 LOG_TRACE("Warning: not a turret path");
122 else
123 {
124
125#ifdef EWHEEL_FANCYPATH
126 this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
127 this.pathgoal = e;
128#else
129 this.pathcurrent = e;
130#endif
131 }
132}
133
134spawnfunc(turret_ewheel)
135{
136 if (!turret_initialize(this, TUR_EWHEEL))
137 delete(this);
138}
139
140METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
141{
142 vector wish_angle, real_angle;
143
144 float vz = it.velocity.z;
145 it.angles.x = anglemods(it.angles.x);
146 it.angles.y = anglemods(it.angles.y);
147
148 fixedmakevectors(it.angles);
149
150 wish_angle = normalize(it.steerto);
151 wish_angle = vectoangles(wish_angle);
152 real_angle = wish_angle - it.angles;
153 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
154
155 it.tur_head.spawnshieldtime = fabs(real_angle.y);
156
157 float f = it.tur_head.aim_speed * frametime;
158 real_angle.y = bound(-f, real_angle.y, f);
159 it.angles.y += real_angle.y;
160
161 if (it.enemy)
163 else if (it.pathcurrent)
165 else
167
168 it.velocity.z = vz;
169
170 if (it.velocity)
171 it.SendFlags |= TNSF_MOVE;
172}
173
174METHOD(EWheel, tr_death, void(EWheel this, entity it))
175{
176 it.velocity = '0 0 0';
177
178#ifdef EWHEEL_FANCYPATH
179 if (it.pathcurrent)
180 pathlib_deletepath(it.pathcurrent.owner);
181#endif
182 it.pathcurrent = NULL;
183}
184
185METHOD(EWheel, tr_setup, void(EWheel this, entity it))
186{
187 if (it.move_movetype == MOVETYPE_WALK)
188 {
189 it.velocity = '0 0 0';
190 it.enemy = NULL;
191
192 setorigin(it, it.pos1);
193
194 if (it.target != "")
196 }
197
198 it.iscreature = true;
199 it.teleportable = TELEPORT_NORMAL;
200 if (!it.damagedbycontents)
202 it.damagedbycontents = true;
204 it.solid = SOLID_SLIDEBOX;
205 it.takedamage = DAMAGE_AIM;
206 it.idle_aim = '0 0 0';
207 it.pos1 = it.origin;
210 it.frame = 1;
211 it.tur_head.frame = 1;
213
214 it.tur_head.aim_speed = autocvar_g_turrets_unit_ewheel_turnrate;
215}
216
217#endif // SVQC
218#ifdef CSQC
219
221{
222 float dt = time - this.move_time;
223 this.move_time = time;
224 if (dt <= 0)
225 return;
226
228 setorigin(this, this.origin + this.velocity * dt);
229 this.tur_head.angles += dt * this.tur_head.avelocity;
230
231 if (GetResource(this, RES_HEALTH) < 127
232 && random() < 0.05)
233 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
234}
235
236METHOD(EWheel, tr_setup, void(EWheel this, entity it))
237{
238 it.gravity = 1;
240 it.move_time = time;
241 it.draw = ewheel_draw;
242}
243
244#endif // CSQC
245#ifdef MENUQC
247
248METHOD(EWheel, describe, string(EWheel this))
249{
250 TC(Ewheel, this);
252 PAR(_("The %s is a mobile turret that rolls around, attacking its targets when they enter its line of sight."), COLORED_NAME(this));
253 PAR(_("It attacks by shooting laser beams similar to those of the %s, from both of its two cannons."), COLORED_NAME(WEP_BLASTER));
254 return PAGE_TEXT;
255}
256
257#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:143
ent angles
Definition ent_cs.qc:121
const int ewheel_anim_stop
Definition ewheel.qc:11
void ewheel_findtarget(entity this)
Definition ewheel.qc:111
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:98
void ewheel_draw(entity this)
Definition ewheel.qc:220
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:159
#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:163
vector moveto
Definition movelib.qc:4
#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:351
#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:642
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:648
#define PAGE_TEXT_INIT()
Definition string.qh:641
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
don't attack teammates
Definition turret.qh:88
const int TFL_TARGETSELECT_PLAYERS
target players
Definition turret.qh:83
const int TFL_TARGETSELECT_RANGELIMITS
limit target selection range
Definition turret.qh:87
const int TFL_AMMO_ENERGY
uses power
Definition turret.qh:158
const int TNSF_MOVE
Definition turret.qh:190
const int TFL_TARGETSELECT_LOS
require line of sight to find targets
Definition turret.qh:82
const int TNSF_ANIM
Definition turret.qh:192
const int TFL_AMMO_RECHARGE
regenerates ammo
Definition turret.qh:161
const int TFL_AMMO_RECIEVE
can recieve ammo from support units
Definition turret.qh:162
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2230