Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_turrets.qc File Reference
Include dependency graph for sv_turrets.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TRY(x)
#define X(class, prefix, fld, type)

Functions

void load_unit_settings (entity ent, bool is_reload)
vector turret_aim_generic (entity this)
bool turret_checkfire (entity this)
bool turret_closetotarget (entity this, vector targ, float range)
void turret_damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector vforce)
void turret_die (entity this)
void turret_do_updates (entity t_turret)
 updates enemy distances, predicted impact point/time and updated aim<->predict impact distance.
void turret_findtarget (entity this)
void turret_fire (entity this)
bool turret_firecheck (entity this)
 Preforms pre-fire checks based on the uints firecheck_flags.
bool turret_heal (entity targ, entity inflictor, float amount, float limit)
void turret_hide (entity this)
bool turret_initialize (entity this, Turret tur)
void turret_initparams (entity tur)
void turret_link (entity this)
entity turret_projectile (entity actor, Sound _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
void turret_projectile_damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector vforce)
void turret_projectile_explode (entity this)
void turret_projectile_touch (entity this, entity toucher)
void turret_reset (entity this)
void turret_respawn (entity this)
entity turret_select_target (entity this)
bool turret_send (entity this, entity to, float sf)
float turret_targetscore_generic (entity _turret, entity _target)
float turret_targetscore_support (entity _turret, entity _target)
void turret_think (entity this)
void turret_track (entity this)
void turret_use (entity this, entity actor, entity trigger)
float turret_validate_target (entity e_turret, entity e_target, float validate_flags)
 Evaluate a entity for target valitity based on validate_flags NOTE: the caller must check takedamage before calling this, to inline this check.
void turrets_manager_think (entity this)
void turrets_setframe (entity this, float _frame, float client_only)

Variables

float clientframe
float turret_framecounter
 Handles head rotation according to the units .track_type and .track_flags.

Macro Definition Documentation

◆ TRY

#define TRY ( x)
Value:
(x) ? (x)

Referenced by turret_initparams().

◆ X

#define X ( class,
prefix,
fld,
type )
Value:
ent.fld = cvar(strcat("g_turrets_unit_", prefix, "_", #fld));
float cvar(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

Function Documentation

◆ load_unit_settings()

void load_unit_settings ( entity ent,
bool is_reload )

Definition at line 381 of file sv_turrets.qc.

382{
383 if (ent == NULL)
384 return;
385
386 if(!ent.turret_scale_damage) ent.turret_scale_damage = 1;
387 if(!ent.turret_scale_range) ent.turret_scale_range = 1;
388 if(!ent.turret_scale_refire) ent.turret_scale_refire = 1;
389 if(!ent.turret_scale_ammo) ent.turret_scale_ammo = 1;
390 if(!ent.turret_scale_aim) ent.turret_scale_aim = 1;
391 if(!ent.turret_scale_health) ent.turret_scale_health = 1;
392 if(!ent.turret_scale_respawn) ent.turret_scale_respawn = 1;
393
394 if (is_reload)
395 {
396 ent.enemy = NULL;
397 ent.tur_head.avelocity = '0 0 0';
398
399 ent.tur_head.angles = '0 0 0';
400 }
401
402 string unitname = ent.netname;
403 #define X(class, prefix, fld, type) ent.fld = cvar(strcat("g_turrets_unit_", prefix, "_", #fld));
404 TR_PROPS_COMMON(X, , unitname)
405 #undef X
406
407 ent.ammo_max *= ent.turret_scale_ammo;
408 ent.ammo_recharge *= ent.turret_scale_ammo;
409 ent.aim_speed *= ent.turret_scale_aim;
410 SetResourceExplicit(ent, RES_HEALTH, GetResource(ent, RES_HEALTH) * ent.turret_scale_health);
411 ent.respawntime *= ent.turret_scale_respawn;
412 ent.shot_dmg *= ent.turret_scale_damage;
413 ent.shot_refire *= ent.turret_scale_refire;
414 ent.shot_radius *= ent.turret_scale_damage;
415 ent.shot_force *= ent.turret_scale_damage;
416 ent.shot_volly_refire *= ent.turret_scale_refire;
417 ent.target_range *= ent.turret_scale_range;
418 ent.target_range_min *= ent.turret_scale_range;
419 ent.target_range_optimal *= ent.turret_scale_range;
420
421 if(is_reload) {
422 Turret tur = get_turretinfo(ent.m_id);
423 tur.tr_setup(tur, ent);
424 }
425}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
virtual void tr_setup()
(BOTH) setup turret data
Definition turret.qh:33
#define X()
#define NULL
Definition post.qh:14
#define get_turretinfo(i)
Definition all.qh:9
#define TR_PROPS_COMMON(P, class, prefix)
Definition all.qh:13

References entity(), get_turretinfo, GetResource(), NULL, SetResourceExplicit(), TR_PROPS_COMMON, Turret::tr_setup(), and X.

Referenced by turret_initialize(), and turrets_manager_think().

◆ turret_aim_generic()

vector turret_aim_generic ( entity this)

Definition at line 12 of file sv_turrets.qc.

13{
14 vector pre_pos, prep;
15 float distance, impact_time = 0, i, mintime;
16
18
19 if(this.aim_flags & TFL_AIM_SIMPLE)
20 return real_origin(this.enemy);
21
22 mintime = max(this.attack_finished_single[0] - time,0) + sys_frametime;
23
24 // Baseline
25 pre_pos = real_origin(this.enemy);
26
27 // Lead?
28 if (this.aim_flags & TFL_AIM_LEAD)
29 {
30 if (this.aim_flags & TFL_AIM_SHOTTIMECOMPENSATE) // Need to conpensate for shot traveltime
31 {
32 prep = pre_pos;
33
34 distance = vlen(prep - this.tur_shotorg);
35 impact_time = distance / this.shot_speed;
36
37 prep = pre_pos + (this.enemy.velocity * (impact_time + mintime));
38
40 if(!IS_ONGROUND(this.enemy))
41 if(this.enemy.move_movetype == MOVETYPE_WALK || this.enemy.move_movetype == MOVETYPE_TOSS || this.enemy.move_movetype == MOVETYPE_BOUNCE)
42 {
43 float vz;
44 prep_z = pre_pos_z;
45 vz = this.enemy.velocity_z;
46 for(i = 0; i < impact_time; i += sys_frametime)
47 {
49 prep_z = prep_z + vz * sys_frametime;
50 }
51 }
52 pre_pos = prep;
53 }
54 else
55 pre_pos = pre_pos + this.enemy.velocity * mintime;
56 }
57
58 if(this.aim_flags & TFL_AIM_SPLASH)
59 {
60 //tracebox(pre_pos + '0 0 32',this.enemy.mins,this.enemy.maxs,pre_pos -'0 0 64',MOVE_WORLDONLY,this.enemy);
61 traceline(pre_pos + '0 0 32',pre_pos -'0 0 64',MOVE_WORLDONLY,this.enemy);
62 if(trace_fraction != 1.0)
63 pre_pos = trace_endpos;
64 }
65
66 return pre_pos;
67}
#define autocvar_sv_gravity
Definition stats.qh:421
float turret_tag_fire_update(entity this)
Definition util.qc:9
vector real_origin(entity ent)
Definition util.qc:148
float time
vector trace_endpos
float MOVE_WORLDONLY
float trace_fraction
float vlen(vector v)
float max(float f,...)
const int MOVETYPE_WALK
Definition movetypes.qh:132
const int MOVETYPE_TOSS
Definition movetypes.qh:135
const int MOVETYPE_BOUNCE
Definition movetypes.qh:139
#define IS_ONGROUND(s)
Definition movetypes.qh:16
vector
Definition self.qh:92
float sys_frametime
Definition common.qh:57
entity enemy
Definition sv_ctf.qh:153
vector tur_shotorg
Definition sv_turrets.qh:30
const int TFL_AIM_LEAD
Definition turret.qh:99
const int TFL_AIM_SPLASH
Definition turret.qh:98
const int TFL_AIM_ZPREDICT
Definition turret.qh:101
const int TFL_AIM_SHOTTIMECOMPENSATE
Definition turret.qh:100
int aim_flags
Definition turret.qh:96
const int TFL_AIM_SIMPLE
Definition turret.qh:102
float attack_finished_single[MAX_WEAPONSLOTS]

References aim_flags, attack_finished_single, autocvar_sv_gravity, enemy, entity(), IS_ONGROUND, max(), MOVE_WORLDONLY, MOVETYPE_BOUNCE, MOVETYPE_TOSS, MOVETYPE_WALK, real_origin(), sys_frametime, TFL_AIM_LEAD, TFL_AIM_SHOTTIMECOMPENSATE, TFL_AIM_SIMPLE, TFL_AIM_SPLASH, TFL_AIM_ZPREDICT, time, trace_endpos, trace_fraction, tur_shotorg, turret_tag_fire_update(), vector, and vlen().

Referenced by turret_think().

◆ turret_checkfire()

bool turret_checkfire ( entity this)

Definition at line 980 of file sv_turrets.qc.

981{
982 if(MUTATOR_CALLHOOK(Turret_CheckFire, this))
983 return M_ARGV(1, bool);
984
985 return this.turret_firecheckfunc(this);
986}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
#define M_ARGV(x, type)
Definition events.qh:17

References entity(), M_ARGV, and MUTATOR_CALLHOOK.

Referenced by turret_think().

◆ turret_closetotarget()

bool turret_closetotarget ( entity this,
vector targ,
float range )

Definition at line 1246 of file sv_turrets.qc.

1247{
1248 vector path_extra_size = '1 1 1' * range;
1249 return boxesoverlap(targ - path_extra_size, targ + path_extra_size, this.absmin - path_extra_size, this.absmax + path_extra_size);
1250}
vector absmax
vector absmin
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition vector.qh:73

References absmax, absmin, boxesoverlap(), entity(), and vector.

Referenced by ewheel_move_path(), Monster_Move(), and walker_move_path().

◆ turret_damage()

void turret_damage ( entity this,
entity inflictor,
entity attacker,
float damage,
int deathtype,
.entity weaponentity,
vector hitloc,
vector vforce )

Definition at line 221 of file sv_turrets.qc.

222{
223 // Enough already!
224 if(this.deadflag == DEAD_DEAD)
225 return;
226
227 // Inactive turrets take no damage. (hm..)
228 if(!this.active)
229 return;
230
231 if(SAME_TEAM(this, attacker))
232 {
234 damage = damage * autocvar_g_friendlyfire;
235 else
236 return;
237 }
238
239 TakeResource(this, RES_HEALTH, damage);
240
241 // thorw head slightly off aim when hit?
243 {
244 this.tur_head.angles_x = this.tur_head.angles_x + (-0.5 + random()) * damage;
245 this.tur_head.angles_y = this.tur_head.angles_y + (-0.5 + random()) * damage;
246
247 this.SendFlags |= TNSF_ANG;
248 }
249
250 if (this.turret_flags & TUR_FLAG_MOVE)
251 this.velocity = this.velocity + vforce;
252
253 if (GetResource(this, RES_HEALTH) <= 0)
254 {
255 this.event_damage = func_null;
256 this.tur_head.event_damage = func_null;
257 this.event_heal = func_null;
258 this.tur_head.event_heal = func_null;
259 this.takedamage = DAMAGE_NO;
260 this.nextthink = time;
261 setthink(this, turret_die);
262 }
263
264 this.SendFlags |= TNSF_STATUS;
265}
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
void turret_die(entity this)
vector velocity
float nextthink
float autocvar_g_friendlyfire
Definition damage.qh:26
int active
Definition defs.qh:34
int SendFlags
Definition net.qh:118
float random(void)
var void func_null()
float deadflag
Definition progsdefs.qc:149
float DEAD_DEAD
Definition progsdefs.qc:276
#define setthink(e, f)
const int DAMAGE_NO
Definition subs.qh:79
float takedamage
Definition subs.qh:78
entity tur_head
Definition sv_turrets.qh:28
#define SAME_TEAM(a, b)
Definition teams.qh:241
const int TFL_DMG_HEADSHAKE
Definition turret.qh:172
const int TNSF_ANG
Definition turret.qh:187
int turret_flags
Definition turret.qh:135
int damage_flags
Definition turret.qh:164
const int TNSF_STATUS
Definition turret.qh:185
const int TUR_FLAG_MOVE
Definition turret.qh:150

References active, autocvar_g_friendlyfire, damage_flags, DAMAGE_NO, DEAD_DEAD, deadflag, entity(), func_null(), GetResource(), nextthink, random(), SAME_TEAM, SendFlags, setthink, takedamage, TakeResource(), TFL_DMG_HEADSHAKE, time, TNSF_ANG, TNSF_STATUS, TUR_FLAG_MOVE, tur_head, turret_die(), turret_flags, vector, and velocity.

Referenced by turret_initialize(), and turret_respawn().

◆ turret_die()

void turret_die ( entity this)

Definition at line 180 of file sv_turrets.qc.

181{
182 this.deadflag = DEAD_DEAD;
183 this.tur_head.deadflag = this.deadflag;
184
185 // Unsolidify and hide real parts
186 this.solid = SOLID_NOT;
187 this.tur_head.solid = this.solid;
188
189 this.event_damage = func_null;
190 this.event_heal = func_null;
191 this.takedamage = DAMAGE_NO;
192
193 SetResourceExplicit(this, RES_HEALTH, 0);
194
195 // Go boom
196 //RadiusDamage (this,this, min(this.ammo,50),min(this.ammo,50) * 0.25,250,NULL,min(this.ammo,50)*5,DEATH_TURRET,NULL);
197
198 Turret tur = get_turretinfo(this.m_id);
200 {
201 // do a simple explosion effect here, since CSQC can't do it on a to-be-removed entity
202 sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
203 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
204
205 tur.tr_death(tur, this);
206
207 delete(this.tur_head);
208 delete(this);
209 }
210 else
211 {
212 // Setup respawn
213 this.SendFlags |= TNSF_STATUS;
214 this.nextthink = time + 0.2;
215 setthink(this, turret_hide);
216
217 tur.tr_death(tur, this);
218 }
219}
virtual void tr_death()
(SERVER) called when turret dies
Definition turret.qh:41
const float SOLID_NOT
vector origin
int m_id
Definition effect.qh:19
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:124
solid
Definition ent_cs.qc:165
const float VOL_BASE
Definition sound.qh:36
const int CH_SHOTS
Definition sound.qh:14
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
void turret_hide(entity this)
const int TFL_DMG_DEATH_NORESPAWN
Definition turret.qh:173

References ATTEN_NORM, CH_SHOTS, damage_flags, DAMAGE_NO, DEAD_DEAD, deadflag, entity(), func_null(), get_turretinfo, m_id, nextthink, origin, Send_Effect(), SendFlags, SetResourceExplicit(), setthink, solid, SOLID_NOT, sound, takedamage, TFL_DMG_DEATH_NORESPAWN, time, TNSF_STATUS, Turret::tr_death(), tur_head, turret_hide(), and VOL_BASE.

◆ turret_do_updates()

void turret_do_updates ( entity t_turret)

updates enemy distances, predicted impact point/time and updated aim<->predict impact distance.

updates aim org, shot org, shot dir and enemy org for selected turret

Definition at line 499 of file sv_turrets.qc.

500{
501 vector enemy_pos = real_origin(t_turret.enemy);
502
503 turret_tag_fire_update(t_turret);
504
505 t_turret.tur_shotdir_updated = v_forward;
506 t_turret.tur_dist_enemy = vlen(t_turret.tur_shotorg - enemy_pos);
507 t_turret.tur_dist_aimpos = vlen(t_turret.tur_shotorg - t_turret.tur_aimpos);
508
509 /*if((t_turret.firecheck_flags & TFL_FIRECHECK_VERIFIED) && (t_turret.enemy))
510 {
511 oldpos = t_turret.enemy.origin;
512 setorigin(t_turret.enemy, t_turret.tur_aimpos);
513 tracebox(t_turret.tur_shotorg, '-1 -1 -1', '1 1 1', t_turret.tur_shotorg + (t_turret.tur_shotdir_updated * t_turret.tur_dist_aimpos), MOVE_NORMAL,t_turret);
514 setorigin(t_turret.enemy, oldpos);
515
516 if(trace_ent == t_turret.enemy)
517 t_turret.tur_dist_impact_to_aimpos = 0;
518 else
519 t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos);
520 }
521 else*/
522 tracebox(t_turret.tur_shotorg, '-1 -1 -1','1 1 1', t_turret.tur_shotorg + (t_turret.tur_shotdir_updated * t_turret.tur_dist_aimpos), MOVE_NORMAL,t_turret);
523
524 t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos) - (vlen(t_turret.enemy.maxs - t_turret.enemy.mins) * 0.5);
525 t_turret.tur_impactent = trace_ent;
526 t_turret.tur_impacttime = vlen(t_turret.tur_shotorg - trace_endpos) / t_turret.shot_speed;
527}
entity trace_ent
const float MOVE_NORMAL
vector v_forward

References entity(), MOVE_NORMAL, real_origin(), trace_endpos, trace_ent, turret_tag_fire_update(), v_forward, vector, and vlen().

Referenced by beam_think(), and turret_think().

◆ turret_findtarget()

void turret_findtarget ( entity this)

Definition at line 1252 of file sv_turrets.qc.

1253{
1254 entity e = find(NULL, classname, "turret_manager");
1255 if(!e)
1256 {
1257 e = new_pure(turret_manager);
1259 e.nextthink = time + 2;
1260 }
1261
1262 entity targ = find(NULL, targetname, this.target);
1263 if(targ.classname == "turret_checkpoint")
1264 return; // turrets don't defend checkpoints?
1265
1266 if (!targ)
1267 {
1268 this.target = "";
1269 LOG_TRACE("Turret has invalid defendpoint!");
1270 }
1271
1272 this.tur_defend = targ;
1273 this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, targ);
1274}
#define angleofs(from, to)
Definition angle.qc:90
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string classname
#define LOG_TRACE(...)
Definition log.qh:76
entity find(entity start,.string field, string match)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
void turrets_manager_think(entity this)
vector idle_aim
Definition sv_turrets.qh:44
entity tur_defend
Definition sv_turrets.qh:29
string targetname
Definition triggers.qh:56
string target
Definition triggers.qh:55

References angleofs, classname, entity(), find(), idle_aim, LOG_TRACE, new_pure, NULL, setthink, target, targetname, time, tur_defend, tur_head, and turrets_manager_think().

Referenced by turret_initialize().

◆ turret_fire()

void turret_fire ( entity this)

Definition at line 988 of file sv_turrets.qc.

989{
991 return;
992
993 if(MUTATOR_CALLHOOK(TurretFire, this))
994 return;
995
996 Turret info = get_turretinfo(this.m_id);
997 info.tr_attack(info, this);
998
999 this.attack_finished_single[0] = time + this.shot_refire;
1000 this.ammo -= this.shot_dmg;
1001 this.volly_counter = this.volly_counter - 1;
1002
1003 if (this.volly_counter <= 0)
1004 {
1005 this.volly_counter = this.shot_volly;
1006
1008 this.enemy = NULL;
1009
1010 if (this.shot_volly > 1)
1011 this.attack_finished_single[0] = time + this.shot_volly_refire;
1012 }
1013
1014#ifdef TURRET_DEBUG
1015 if (this.enemy) paint_target3(this.tur_aimpos, 64, this.tur_debug_rvec, this.tur_impacttime + 0.25);
1016#endif
1017}
virtual void tr_attack()
(SERVER) called when turret attacks
Definition turret.qh:51
float volly_counter
Definition sv_turrets.qh:37
bool autocvar_g_turrets_nofire
Definition sv_turrets.qh:7
float ammo
Definition sv_turrets.qh:43
vector tur_aimpos
Definition sv_turrets.qh:31
float tur_impacttime
Definition sv_turrets.qh:32
const int TFL_SHOOT_CLEARTARGET
Definition turret.qh:131
int shoot_flags
Definition turret.qh:126

References ammo, attack_finished_single, autocvar_g_turrets_nofire, enemy, entity(), get_turretinfo, m_id, MUTATOR_CALLHOOK, NULL, shoot_flags, TFL_SHOOT_CLEARTARGET, time, Turret::tr_attack(), tur_aimpos, tur_impacttime, and volly_counter.

Referenced by turret_think().

◆ turret_firecheck()

bool turret_firecheck ( entity this)

Preforms pre-fire checks based on the uints firecheck_flags.

Definition at line 905 of file sv_turrets.qc.

906{
907 // This one just dont care =)
909 return true;
910
911 if (this.enemy == NULL)
912 return false;
913
914 // Ready?
916 if (this.attack_finished_single[0] > time) return false;
917
918 // Special case: volly fire turret that has to fire a full volly if a shot was fired.
920 if (this.volly_counter != this.shot_volly)
921 if(this.ammo >= this.shot_dmg)
922 return true;
923
924 // Lack of zombies makes shooting dead things unnecessary :P
926 if (IS_DEAD(this.enemy))
927 return false;
928
929 // Own ammo?
931 if (this.ammo < this.shot_dmg)
932 return false;
933
934 // Other's ammo? (support-supply units)
936 if (this.enemy.ammo >= this.enemy.ammo_max)
937 return false;
938
939 // Target of opertunity?
941 {
942 this.enemy = this.tur_impactent;
943 return true;
944 }
945
947 {
948 // To close?
949 if (this.tur_dist_aimpos < this.target_range_min)
950 {
952 return true; // Target of opertunity?
953 return false;
954 }
955 }
956
957 // Try to avoid FF?
959 if (this.tur_impactent.team == this.team)
960 return false;
961
962 // aim<->predicted impact
964 if (this.tur_dist_impact_to_aimpos > this.aim_firetolerance_dist)
965 return false;
966
967 // Volly status
968 if (this.shot_volly > 1)
969 if (this.volly_counter == this.shot_volly)
970 if (this.ammo < (this.shot_dmg * this.shot_volly))
971 return false;
972
973 /*if(this.firecheck_flags & TFL_FIRECHECK_VERIFIED)
974 if(this.tur_impactent != this.enemy)
975 return false;*/
976
977 return true;
978}
#define IS_DEAD(s)
Definition player.qh:245
float turret_validate_target(entity e_turret, entity e_target, float validate_flags)
Evaluate a entity for target valitity based on validate_flags NOTE: the caller must check takedamage ...
entity tur_impactent
Definition sv_turrets.qh:33
float tur_dist_aimpos
Definition sv_turrets.qh:35
float tur_dist_impact_to_aimpos
Definition sv_turrets.qh:36
const int TFL_FIRECHECK_DISTANCES
Definition turret.qh:113
const int TFL_FIRECHECK_AMMO_OWN
Definition turret.qh:120
int target_validate_flags
Definition turret.qh:79
const int TFL_SHOOT_VOLLYALWAYS
Definition turret.qh:129
const int TFL_FIRECHECK_DEAD
Definition turret.qh:112
const int TFL_FIRECHECK_AIMDIST
Definition turret.qh:115
const int TFL_FIRECHECK_AMMO_OTHER
Definition turret.qh:121
const int TFL_FIRECHECK_REFIRE
Definition turret.qh:122
const int TFL_FIRECHECK_NO
Definition turret.qh:123
int firecheck_flags
Definition turret.qh:111
const int TFL_FIRECHECK_AFF
Definition turret.qh:119

References ammo, attack_finished_single, enemy, entity(), firecheck_flags, IS_DEAD, NULL, shoot_flags, target_validate_flags, TFL_FIRECHECK_AFF, TFL_FIRECHECK_AIMDIST, TFL_FIRECHECK_AMMO_OTHER, TFL_FIRECHECK_AMMO_OWN, TFL_FIRECHECK_DEAD, TFL_FIRECHECK_DISTANCES, TFL_FIRECHECK_NO, TFL_FIRECHECK_REFIRE, TFL_SHOOT_VOLLYALWAYS, time, tur_dist_aimpos, tur_dist_impact_to_aimpos, tur_impactent, turret_validate_target(), and volly_counter.

Referenced by turret_initialize(), turret_phaser_firecheck(), turret_tesla_firecheck(), and walker_firecheck().

◆ turret_heal()

bool turret_heal ( entity targ,
entity inflictor,
float amount,
float limit )

Definition at line 267 of file sv_turrets.qc.

268{
269 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
270 if(GetResource(targ, RES_HEALTH) <= 0 || GetResource(targ, RES_HEALTH) >= true_limit)
271 return false;
272
273 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
274 targ.SendFlags |= TNSF_STATUS;
275 return true;
276}
const int RES_LIMIT_NONE
Definition resources.qh:60
void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
Gives an entity some resource but not more than a limit.

References entity(), GetResource(), GiveResourceWithLimit(), RES_LIMIT_NONE, and TNSF_STATUS.

Referenced by turret_initialize(), and turret_respawn().

◆ turret_hide()

void turret_hide ( entity this)

Definition at line 173 of file sv_turrets.qc.

174{
175 this.effects |= EF_NODRAW;
176 this.nextthink = time + this.respawntime - 0.2;
178}
float effects
const float EF_NODRAW
float respawntime
Definition items.qh:30
void turret_respawn(entity this)

References EF_NODRAW, effects, entity(), nextthink, respawntime, setthink, time, and turret_respawn().

Referenced by turret_die().

◆ turret_initialize()

bool turret_initialize ( entity this,
Turret tur )

Definition at line 1281 of file sv_turrets.qc.

1282{
1284 return false;
1285
1286 if(tur.m_id == 0)
1287 return false; // invalid turret
1288
1289 // if tur_head exists, we can assume this turret re-spawned
1290 if(!this.tur_head) {
1291 tur.tr_precache(tur);
1292 IL_PUSH(g_turrets, this);
1293 IL_PUSH(g_bot_targets, this);
1294 }
1295
1296 if(!(this.spawnflags & TSF_SUSPENDED))
1298
1299 this.netname = tur.netname;
1300 load_unit_settings(this, 0);
1301
1302 if(!this.team || !teamplay) { this.team = FLOAT_MAX; }
1303 if(!GetResource(this, RES_HEALTH)) { SetResourceExplicit(this, RES_HEALTH, 1000); }
1304 if(!this.shot_refire) { this.shot_refire = 1; }
1305 if(!this.tur_shotorg) { this.tur_shotorg = '50 0 50'; }
1309 if(!this.track_type) { this.track_type = TFL_TRACKTYPE_STEPMOTOR; }
1315
1316 if(this.track_type != TFL_TRACKTYPE_STEPMOTOR)
1317 {
1318 // Fluid / Ineria mode. Looks mutch nicer.
1319 // Can reduce aim preformance alot, needs a bit diffrent aimspeed
1320
1321 this.aim_speed = bound(0.1, ((!this.aim_speed) ? 180 : this.aim_speed), 1000);
1322
1323 if(!this.track_accel_pitch) { this.track_accel_pitch = 0.5; }
1324 if(!this.track_accel_rot) { this.track_accel_rot = 0.5; }
1325 if(!this.track_blendrate) { this.track_blendrate = 0.35; }
1326 }
1327
1328 turret_initparams(this);
1329
1331
1332 if(this.turret_flags & TUR_FLAG_SPLASH)
1333 this.aim_flags |= TFL_AIM_SPLASH;
1334
1337
1338 if(this.turret_flags & TUR_FLAG_PLAYER)
1340
1341 if(this.spawnflags & TSL_NO_RESPAWN)
1343
1344 if (this.turret_flags & TUR_FLAG_SUPPORT)
1345 this.turret_score_target = turret_targetscore_support;
1346 else
1347 this.turret_score_target = turret_targetscore_generic;
1348
1349 ++turret_count;
1350
1351 _setmodel(this, tur.model);
1352 setsize(this, tur.m_mins, tur.m_maxs);
1353
1354 this.m_id = tur.m_id;
1355 this.active = ACTIVE_ACTIVE;
1356 this.effects = EF_NODRAW;
1357 this.netname = tur.m_name;
1358 this.max_health = GetResource(this, RES_HEALTH);
1360 this.ammo = this.ammo_max;
1361 this.solid = SOLID_BBOX;
1362 this.takedamage = DAMAGE_AIM;
1364 this.view_ofs = '0 0 0';
1365 this.idle_aim = '0 0 0';
1366 this.turret_firecheckfunc = turret_firecheck;
1367 this.event_damage = turret_damage;
1368 this.event_heal = turret_heal;
1369 this.use = turret_use;
1370 this.bot_attack = true;
1371 this.nextthink = time + 1;
1372 this.reset = turret_reset;
1373
1374 this.tur_head = new(turret_head);
1375 _setmodel(this.tur_head, tur.head_model);
1376 setsize(this.tur_head, '0 0 0', '0 0 0');
1377 setorigin(this.tur_head, '0 0 0');
1378 setattachment(this.tur_head, this, "tag_head");
1379
1380 this.tur_head.netname = this.tur_head.classname;
1381 this.tur_head.team = this.team;
1382 this.tur_head.owner = this;
1383 this.tur_head.takedamage = DAMAGE_NO;
1384 this.tur_head.solid = SOLID_NOT;
1386
1387 this.weaponentities[0] = this; // lol
1388
1389 if(!this.tur_defend && this.target != "")
1391
1392#ifdef TURRET_DEBUG
1393 this.tur_debug_start = this.nextthink;
1394 while(vdist(this.tur_debug_rvec, <, 2))
1395 this.tur_debug_rvec = randomvec() * 4;
1396
1397 this.tur_debug_rvec_x = fabs(this.tur_debug_rvec_x);
1398 this.tur_debug_rvec_y = fabs(this.tur_debug_rvec_y);
1399 this.tur_debug_rvec_z = fabs(this.tur_debug_rvec_z);
1400#endif
1401
1402 turret_link(this);
1403 turret_respawn(this);
1405
1406 tur.tr_setup(tur, this);
1407
1408 if(MUTATOR_CALLHOOK(TurretSpawn, this))
1409 return false;
1410
1411 return true;
1412}
float bot_attack
Definition api.qh:38
IntrusiveList g_bot_targets
Definition api.qh:149
float max_health
string m_name
human readable name
Definition turret.qh:16
int m_id
Definition turret.qh:9
vector m_maxs
turret hitbox size
Definition turret.qh:30
virtual void tr_precache()
(BOTH) precaches models/sounds used by this turret
Definition turret.qh:45
vector m_mins
turret hitbox size
Definition turret.qh:28
int spawnflags
Definition turret.qh:26
string netname
Definition powerups.qc:20
int team
Definition main.qh:188
int spawnflags
Definition ammo.qh:15
const int INITPRIO_FINDTARGET
Definition constants.qh:96
const float SOLID_BBOX
#define use
const int ACTIVE_ACTIVE
Definition defs.qh:37
const float FLOAT_MAX
Definition float.qh:3
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
float bound(float min, float value, float max)
vector randomvec(void)
float fabs(float f)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
float move_movetype
Definition movetypes.qh:76
const int MOVETYPE_NOCLIP
Definition movetypes.qh:137
vector view_ofs
Definition progsdefs.qc:151
const int DAMAGE_AIM
Definition subs.qh:81
bool turret_heal(entity targ, entity inflictor, float amount, float limit)
void turret_findtarget(entity this)
float turret_targetscore_support(entity _turret, entity _target)
Definition sv_turrets.qc:69
void turret_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector vforce)
bool turret_firecheck(entity this)
Preforms pre-fire checks based on the uints firecheck_flags.
void turret_link(entity this)
void turret_use(entity this, entity actor, entity trigger)
void turret_reset(entity this)
float turret_targetscore_generic(entity _turret, entity _target)
Definition sv_turrets.qc:87
void turret_initparams(entity tur)
void load_unit_settings(entity ent, bool is_reload)
bool autocvar_g_turrets
Definition sv_turrets.qh:5
float turret_count
Definition sv_turrets.qh:90
IntrusiveList g_turrets
const float TFL_TRACKTYPE_STEPMOTOR
Definition sv_turrets.qh:62
bool teamplay
Definition teams.qh:59
const int TFL_TARGETSELECT_ANGLELIMITS
Definition turret.qh:85
const int TUR_FLAG_SUPPORT
Definition turret.qh:147
const int TSF_SUSPENDED
Definition turret.qh:176
const int TFL_TARGETSELECT_TEAMCHECK
Definition turret.qh:87
const int TUR_FLAG_MISSILE
Definition turret.qh:146
const int TFL_DMG_YES
Definition turret.qh:166
const int TUR_FLAG_ISTURRET
Definition turret.qh:152
const int TFL_TARGETSELECT_PLAYERS
Definition turret.qh:82
int track_flags
Definition turret.qh:105
const int TUR_FLAG_PLAYER
Definition turret.qh:145
const int TFL_TARGETSELECT_RANGELIMITS
Definition turret.qh:86
const int TFL_TRACK_ROTATE
Definition turret.qh:108
int target_select_flags
Definition turret.qh:78
const int TFL_DMG_AIMSHAKE
Definition turret.qh:171
const int TSL_NO_RESPAWN
Definition turret.qh:180
const int TFL_AMMO_ENERGY
Definition turret.qh:157
const int TFL_FIRECHECK_LOS
Definition turret.qh:114
const int TFL_DMG_RETALIATE
Definition turret.qh:168
const int TFL_TARGETSELECT_LOS
Definition turret.qh:81
const int TFL_AMMO_RECHARGE
Definition turret.qh:160
const int TFL_FIRECHECK_TEAMCHECK
Definition turret.qh:118
const int TFL_TRACK_PITCH
Definition turret.qh:107
const int TUR_FLAG_SPLASH
Definition turret.qh:138
const int TFL_TARGETSELECT_MISSILES
Definition turret.qh:83
const int TUR_FLAG_MEDPROJ
Definition turret.qh:143
#define ammo_flags
Definition turret.qh:155
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
void DropToFloor_QC_DelayedInit(entity this)
Definition world.qc:2407
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2209

References active, ACTIVE_ACTIVE, aim_flags, ammo, ammo_flags, autocvar_g_turrets, bot_attack, bound(), DAMAGE_AIM, damage_flags, DAMAGE_NO, DropToFloor_QC_DelayedInit(), EF_NODRAW, effects, entity(), fabs(), firecheck_flags, FLOAT_MAX, g_bot_targets, g_turrets, GetResource(), idle_aim, IL_PUSH(), InitializeEntity(), INITPRIO_FINDTARGET, load_unit_settings(), m_id, Turret::m_id, Turret::m_maxs, Turret::m_mins, Turret::m_name, max_health, move_movetype, MOVETYPE_NOCLIP, MUTATOR_CALLHOOK, netname, nextthink, randomvec(), set_movetype(), SetResourceExplicit(), solid, SOLID_BBOX, SOLID_NOT, spawnflags, Turret::spawnflags, takedamage, target, target_select_flags, target_validate_flags, team, teamplay, TFL_AIM_LEAD, TFL_AIM_SHOTTIMECOMPENSATE, TFL_AIM_SPLASH, TFL_AMMO_ENERGY, TFL_AMMO_RECHARGE, TFL_DMG_AIMSHAKE, TFL_DMG_DEATH_NORESPAWN, TFL_DMG_RETALIATE, TFL_DMG_YES, TFL_FIRECHECK_AIMDIST, TFL_FIRECHECK_AMMO_OWN, TFL_FIRECHECK_DEAD, TFL_FIRECHECK_DISTANCES, TFL_FIRECHECK_LOS, TFL_FIRECHECK_REFIRE, TFL_FIRECHECK_TEAMCHECK, TFL_TARGETSELECT_ANGLELIMITS, TFL_TARGETSELECT_LOS, TFL_TARGETSELECT_MISSILES, TFL_TARGETSELECT_PLAYERS, TFL_TARGETSELECT_RANGELIMITS, TFL_TARGETSELECT_TEAMCHECK, TFL_TRACK_PITCH, TFL_TRACK_ROTATE, TFL_TRACKTYPE_STEPMOTOR, time, Turret::tr_precache(), Turret::tr_setup(), track_flags, TSF_SUSPENDED, TSL_NO_RESPAWN, tur_defend, TUR_FLAG_ISTURRET, TUR_FLAG_MEDPROJ, TUR_FLAG_MISSILE, TUR_FLAG_PLAYER, TUR_FLAG_SPLASH, TUR_FLAG_SUPPORT, tur_head, tur_shotorg, turret_count, turret_damage(), turret_findtarget(), turret_firecheck(), turret_flags, turret_heal(), turret_initparams(), turret_link(), turret_reset(), turret_respawn(), turret_tag_fire_update(), turret_targetscore_generic(), turret_targetscore_support(), turret_use(), use, vdist, view_ofs, and weaponentities.

Referenced by spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), and spawnfunc().

◆ turret_initparams()

void turret_initparams ( entity tur)

Definition at line 1217 of file sv_turrets.qc.

1218{
1219 #define TRY(x) (x) ? (x)
1220 tur.respawntime = max (-1, (TRY(tur.respawntime) : 60 ));
1221 tur.shot_refire = bound(0.01, (TRY(tur.shot_refire) : 1 ), 9999);
1222 tur.shot_dmg = max (1, (TRY(tur.shot_dmg) : tur.shot_refire * 50 ));
1223 tur.shot_radius = max (1, (TRY(tur.shot_radius) : tur.shot_dmg * 0.5 ));
1224 tur.shot_speed = max (1, (TRY(tur.shot_speed) : 2500 ));
1225 tur.shot_spread = bound(0.0001, (TRY(tur.shot_spread) : 0.0125 ), 500);
1226 tur.shot_force = bound(0.001, (TRY(tur.shot_force) : tur.shot_dmg * 0.5 + tur.shot_radius * 0.5 ), 5000);
1227 tur.shot_volly = bound(1, (TRY(tur.shot_volly) : 1 ), floor(tur.ammo_max / tur.shot_dmg));
1228 tur.shot_volly_refire = bound(tur.shot_refire, (TRY(tur.shot_volly_refire) : tur.shot_refire * tur.shot_volly ), 60);
1229 tur.target_range = bound(0, (TRY(tur.target_range) : tur.shot_speed * 0.5 ), max_shot_distance);
1230 tur.target_range_min = bound(0, (TRY(tur.target_range_min) : tur.shot_radius * 2 ), max_shot_distance);
1231 tur.target_range_optimal = bound(0, (TRY(tur.target_range_optimal) : tur.target_range * 0.5 ), max_shot_distance);
1232 tur.aim_maxrot = bound(0, (TRY(tur.aim_maxrot) : 90 ), 360);
1233 tur.aim_maxpitch = bound(0, (TRY(tur.aim_maxpitch) : 20 ), 90);
1234 tur.aim_speed = bound(0.1, (TRY(tur.aim_speed) : 36 ), 1000);
1235 tur.aim_firetolerance_dist = bound(0.1, (TRY(tur.aim_firetolerance_dist) : 5 + (tur.shot_radius * 2) ), max_shot_distance);
1236 tur.target_select_rangebias = bound(-10, (TRY(tur.target_select_rangebias) : 1 ), 10);
1237 tur.target_select_samebias = bound(-10, (TRY(tur.target_select_samebias) : 1 ), 10);
1238 tur.target_select_anglebias = bound(-10, (TRY(tur.target_select_anglebias) : 1 ), 10);
1239 tur.target_select_missilebias = bound(-10, (TRY(tur.target_select_missilebias) : 1 ), 10);
1240 tur.target_select_playerbias = bound(-10, (TRY(tur.target_select_playerbias) : 1 ), 10);
1241 tur.ammo_max = max (tur.shot_dmg, (TRY(tur.ammo_max) : tur.shot_dmg * 10 ));
1242 tur.ammo_recharge = max (0, (TRY(tur.ammo_recharge) : tur.shot_dmg * 0.5 ));
1243 #undef TRY
1244}
float floor(float f)
#define TRY(x)
int max_shot_distance
Definition weapon.qh:203

References bound(), entity(), floor(), max(), max_shot_distance, and TRY.

Referenced by turret_initialize().

◆ turret_link()

void turret_link ( entity this)

Definition at line 1193 of file sv_turrets.qc.

1194{
1195 Net_LinkEntity(this, true, 0, turret_send);
1196 setthink(this, turret_think);
1197 this.nextthink = time;
1198 this.tur_head.effects = EF_NODRAW;
1199}
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:123
void turret_think(entity this)
bool turret_send(entity this, entity to, float sf)

References EF_NODRAW, entity(), Net_LinkEntity(), nextthink, setthink, time, tur_head, turret_send(), and turret_think().

Referenced by turret_initialize().

◆ turret_projectile()

entity turret_projectile ( entity actor,
Sound _snd,
float _size,
float _health,
float _death,
float _proj_type,
float _cull,
float _cli_anim )

Definition at line 457 of file sv_turrets.qc.

458{
459 TC(Sound, _snd);
460 entity proj;
461
462 sound (actor, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
463 proj = spawn ();
464 setorigin(proj, actor.tur_shotorg);
465 setsize(proj, '-0.5 -0.5 -0.5' * _size, '0.5 0.5 0.5' * _size);
466 proj.owner = actor;
467 proj.realowner = actor;
468 proj.bot_dodge = true;
469 proj.bot_dodgerating = actor.shot_dmg;
472 proj.nextthink = time + 9;
474 proj.velocity = normalize(actor.tur_shotdir_updated + randomvec() * actor.shot_spread) * actor.shot_speed;
475 proj.flags = FL_PROJECTILE;
476 IL_PUSH(g_projectiles, proj);
477 IL_PUSH(g_bot_dodge, proj);
478 proj.enemy = actor.enemy;
479 proj.projectiledeathtype = _death;
481 if(_health)
482 {
483 SetResourceExplicit(proj, RES_HEALTH, _health);
484 proj.takedamage = DAMAGE_YES;
485 proj.event_damage = turret_projectile_damage;
486 }
487 else
488 proj.flags |= FL_NOTARGET;
489
490 CSQCProjectile(proj, _cli_anim, _proj_type, _cull);
491
492 return proj;
493}
IntrusiveList g_bot_dodge
Definition api.qh:150
const int FL_PROJECTILE
Definition constants.qh:85
const int FL_NOTARGET
Definition constants.qh:76
#define spawn
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
#define TC(T, sym)
Definition _all.inc:82
vector normalize(vector v)
const int MOVETYPE_FLYMISSILE
Definition movetypes.qh:138
#define settouch(e, f)
Definition self.qh:73
IntrusiveList g_projectiles
Definition common.qh:58
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:34
const int CH_WEAPON_A
Definition sound.qh:7
const int DAMAGE_YES
Definition subs.qh:80
void turret_projectile_touch(entity this, entity toucher)
void turret_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector vforce)
void turret_projectile_explode(entity this)

References ATTEN_NORM, CH_WEAPON_A, CSQCProjectile(), DAMAGE_YES, entity(), FL_NOTARGET, FL_PROJECTILE, g_bot_dodge, g_projectiles, IL_PUSH(), MOVETYPE_FLYMISSILE, normalize(), PROJECTILE_MAKETRIGGER, randomvec(), set_movetype(), SetResourceExplicit(), setthink, settouch, sound, spawn, TC, time, turret_projectile_damage(), turret_projectile_explode(), turret_projectile_touch(), and VOL_BASE.

◆ turret_projectile_damage()

void turret_projectile_damage ( entity this,
entity inflictor,
entity attacker,
float damage,
int deathtype,
.entity weaponentity,
vector hitloc,
vector vforce )

Definition at line 448 of file sv_turrets.qc.

449{
450 this.velocity += vforce;
451 TakeResource(this, RES_HEALTH, damage);
452 //this.realowner = attacker; // Dont change realowner, it does not make much sense for turrets
453 if(GetResource(this, RES_HEALTH) <= 0)
455}
entity owner
Definition main.qh:87
void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
Definition common.qc:87

References entity(), GetResource(), owner, TakeResource(), turret_projectile_explode(), vector, velocity, and W_PrepareExplosionByDamage().

Referenced by turret_projectile().

◆ turret_projectile_explode()

void turret_projectile_explode ( entity this)

Definition at line 427 of file sv_turrets.qc.

428{
429 this.takedamage = DAMAGE_NO;
430 this.event_damage = func_null;
431#ifdef TURRET_DEBUG
432 float d;
433 d = RadiusDamage (this, this.owner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.projectiledeathtype, DMG_NOWEP, NULL);
434 this.owner.tur_debug_dmg_t_h = this.owner.tur_debug_dmg_t_h + d;
435 this.owner.tur_debug_dmg_t_f = this.owner.tur_debug_dmg_t_f + this.owner.shot_dmg;
436#else
437 RadiusDamage (this, this.realowner, this.owner.shot_dmg, 0, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.projectiledeathtype, DMG_NOWEP, NULL);
438#endif
439 delete(this);
440}
float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype,.entity weaponentity, entity directhitentity)
Definition damage.qc:981
#define DMG_NOWEP
Definition damage.qh:104
entity realowner

References DAMAGE_NO, DMG_NOWEP, entity(), func_null(), NULL, owner, RadiusDamage(), realowner, and takedamage.

Referenced by turret_hellion_missile_think(), turret_hk_missile_think(), turret_projectile(), turret_projectile_damage(), and turret_projectile_touch().

◆ turret_projectile_touch()

void turret_projectile_touch ( entity this,
entity toucher )

Definition at line 442 of file sv_turrets.qc.

443{
446}
entity entity toucher
Definition self.qh:72
#define PROJECTILE_TOUCH(e, t)
Definition common.qh:28

References entity(), PROJECTILE_TOUCH, toucher, and turret_projectile_explode().

Referenced by turret_projectile().

◆ turret_reset()

void turret_reset ( entity this)

Definition at line 1276 of file sv_turrets.qc.

1277{
1278 turret_respawn(this);
1279}

References entity(), and turret_respawn().

Referenced by turret_initialize().

◆ turret_respawn()

void turret_respawn ( entity this)

Definition at line 279 of file sv_turrets.qc.

280{
281 // Make sure all parts belong to the same team since
282 // this function doubles as "teamchange" function.
283 this.tur_head.team = this.team;
284 this.effects &= ~EF_NODRAW;
285 this.deadflag = DEAD_NO;
287 this.solid = SOLID_BBOX;
288 this.takedamage = DAMAGE_AIM;
289 this.event_damage = turret_damage;
290 this.event_heal = turret_heal;
291 this.avelocity = '0 0 0';
292 this.tur_head.avelocity = this.avelocity;
293 this.tur_head.angles = this.idle_aim;
294 SetResourceExplicit(this, RES_HEALTH, this.max_health);
295 this.enemy = NULL;
296 this.volly_counter = this.shot_volly;
297 this.ammo = this.ammo_max;
298
299 this.nextthink = time;
300 setthink(this, turret_think);
301
303
304 Turret tur = get_turretinfo(this.m_id);
305 tur.tr_setup(tur, this);
306
307 setorigin(this, this.origin); // make sure it's linked to the area grid
308}
vector avelocity
float EF_LOWPRECISION
float DEAD_NO
Definition progsdefs.qc:274
const int TNSF_FULL_UPDATE
Definition turret.qh:193

References ammo, avelocity, DAMAGE_AIM, DEAD_NO, deadflag, EF_LOWPRECISION, EF_NODRAW, effects, enemy, entity(), get_turretinfo, idle_aim, m_id, max_health, nextthink, NULL, origin, SendFlags, SetResourceExplicit(), setthink, solid, SOLID_BBOX, takedamage, team, time, TNSF_FULL_UPDATE, Turret::tr_setup(), tur_head, turret_damage(), turret_heal(), turret_think(), and volly_counter.

Referenced by assault_roundstart_use(), MUTATOR_HOOKFUNCTION(), turret_hide(), turret_initialize(), and turret_reset().

◆ turret_select_target()

entity turret_select_target ( entity this)

Definition at line 838 of file sv_turrets.qc.

839{
840 entity e; // target looper entity
841 float score; // target looper entity score
842 entity e_enemy; // currently best scoreing target
843 float m_score; // currently best scoreing target's score
844
845 m_score = 0;
846 if(this.enemy && this.enemy.takedamage && turret_validate_target(this,this.enemy,this.target_validate_flags) > 0)
847 {
848 e_enemy = this.enemy;
849 m_score = this.turret_score_target(this,e_enemy) * this.target_select_samebias;
850 }
851 else
852 e_enemy = this.enemy = NULL;
853
854 e = findradius(this.origin, this.target_range);
855
856 // Nothing to aim at?
857 if (!e)
858 return NULL;
859
860 while (e)
861 {
862 if(e.takedamage)
863 {
864 float f = turret_validate_target(this, e, this.target_select_flags);
865 //dprint("F is: ", ftos(f), "\n");
866 if ( f > 0)
867 {
868 score = this.turret_score_target(this,e);
869 if ((score > m_score) && (score > 0))
870 {
871 e_enemy = e;
872 m_score = score;
873 }
874 }
875 }
876 e = e.chain;
877 }
878
879 return e_enemy;
880}

References enemy, entity(), NULL, origin, target_select_flags, target_validate_flags, and turret_validate_target().

Referenced by turret_tesla_firecheck(), and turret_think().

◆ turret_send()

bool turret_send ( entity this,
entity to,
float sf )

Definition at line 328 of file sv_turrets.qc.

329{
330 WriteHeader(MSG_ENTITY, ENT_CLIENT_TURRET);
332 if(sf & TNSF_SETUP)
333 {
335
336 WriteVector(MSG_ENTITY, this.origin);
337
338 WriteAngleVector2D(MSG_ENTITY, this.angles);
339 }
340
341 if(sf & TNSF_ANG)
342 {
343 WriteShort(MSG_ENTITY, rint(this.tur_head.angles_x));
344 WriteShort(MSG_ENTITY, rint(this.tur_head.angles_y));
345 }
346
347 if(sf & TNSF_AVEL)
348 {
349 WriteShort(MSG_ENTITY, rint(this.tur_head.avelocity_x));
350 WriteShort(MSG_ENTITY, rint(this.tur_head.avelocity_y));
351 }
352
353 if(sf & TNSF_MOVE)
354 {
355 WriteVector(MSG_ENTITY, this.origin);
356
357 WriteVector(MSG_ENTITY, this.velocity);
358
360 }
361
362 if(sf & TNSF_ANIM)
363 {
366 }
367
368 if(sf & TNSF_STATUS)
369 {
371
372 if(GetResource(this, RES_HEALTH) <= 0)
374 else
375 WriteByte(MSG_ENTITY, ceil((GetResource(this, RES_HEALTH) / this.max_health) * 255));
376 }
377
378 return true;
379}
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
float anim_start_time
Definition items.qc:15
ent angles
Definition ent_cs.qc:121
angles_y
Definition ent_cs.qc:119
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221
float ceil(float f)
void WriteShort(float data, float dest, float desto)
void WriteCoord(float data, float dest, float desto)
float rint(float f)
void WriteByte(float data, float dest, float desto)
const int TNSF_AVEL
Definition turret.qh:188
const int TNSF_SETUP
Definition turret.qh:186
const int TNSF_MOVE
Definition turret.qh:189
const int TNSF_ANIM
Definition turret.qh:191

References angles, angles_y, anim_start_time, ceil(), entity(), frame, GetResource(), m_id, max_health, MSG_ENTITY, origin, rint(), team, TNSF_ANG, TNSF_ANIM, TNSF_AVEL, TNSF_MOVE, TNSF_SETUP, TNSF_STATUS, tur_head, velocity, WriteByte(), WriteCoord(), WriteHeader, and WriteShort().

Referenced by turret_link().

◆ turret_targetscore_generic()

float turret_targetscore_generic ( entity _turret,
entity _target )

Definition at line 87 of file sv_turrets.qc.

88{
89 float d_dist; // Defendmode Distance
90 float score; // Total score
91 float d_score; // Distance score
92 float a_score; // Angular score
93 float m_score = 0; // missile score
94 float p_score = 0; // player score
95 float ikr; // ideal kill range
96
97 if (_turret.tur_defend)
98 {
99 d_dist = vlen(real_origin(_target) - _turret.tur_defend.origin);
100 ikr = vlen(_turret.origin - _turret.tur_defend.origin);
101 d_score = 1 - d_dist / _turret.target_range;
102 }
103 else
104 {
105 // Make a normlized value base on the targets distance from our optimal killzone
106 ikr = _turret.target_range_optimal;
107 d_score = min(ikr, tvt_dist) / max(ikr, tvt_dist);
108 }
109
110 a_score = 1 - tvt_thadf / _turret.aim_maxrot;
111
112 if ((_turret.target_select_missilebias > 0) && (_target.flags & FL_PROJECTILE))
113 m_score = 1;
114
115 if ((_turret.target_select_playerbias > 0) && IS_CLIENT(_target))
116 p_score = 1;
117
118 d_score = max(d_score, 0);
119 a_score = max(a_score, 0);
120 m_score = max(m_score, 0);
121 p_score = max(p_score, 0);
122
123 score = (d_score * _turret.target_select_rangebias) +
124 (a_score * _turret.target_select_anglebias) +
125 (m_score * _turret.target_select_missilebias) +
126 (p_score * _turret.target_select_playerbias);
127
128 if(vdist((_turret.tur_shotorg - real_origin(_target)), >, _turret.target_range))
129 {
130 //dprint("Wtf?\n");
131 score *= 0.001;
132 }
133
134#ifdef TURRET_DEBUG
135 string sd,sa,sm,sp,ss;
136 string sdt,sat,smt,spt;
137
138 sd = ftos(d_score);
139 d_score *= _turret.target_select_rangebias;
140 sdt = ftos(d_score);
141
142 //sv = ftos(v_score);
143 //v_score *= _turret.target_select_samebias;
144 //svt = ftos(v_score);
145
146 sa = ftos(a_score);
147 a_score *= _turret.target_select_anglebias;
148 sat = ftos(a_score);
149
150 sm = ftos(m_score);
151 m_score *= _turret.target_select_missilebias;
152 smt = ftos(m_score);
153
154 sp = ftos(p_score);
155 p_score *= _turret.target_select_playerbias;
156 spt = ftos(p_score);
157
158
159 ss = ftos(score);
160 bprint("^3Target scores^7 \[ ",_turret.netname, " \] ^3for^7 \[ ", _target.netname," \]\n");
161 bprint("^5Range:\[ ",sd, " \]^2+bias:\[ ",sdt," \]\n");
162 bprint("^5Angle:\[ ",sa, " \]^2+bias:\[ ",sat," \]\n");
163 bprint("^5Missile:\[ ",sm," \]^2+bias:\[ ",smt," \]\n");
164 bprint("^5Player:\[ ",sp, " \]^2+bias:\[ ",spt," \]\n");
165 bprint("^3Total (w/bias):\[^1",ss,"\]\n");
166
167#endif
168
169 return score;
170}
#define IS_CLIENT(s)
Definition player.qh:242
void bprint(string text,...)
float min(float f,...)
string ftos(float f)
float tvt_thadf
float tvt_dist

References bprint(), entity(), FL_PROJECTILE, ftos(), IS_CLIENT, max(), min(), real_origin(), tvt_dist, tvt_thadf, vdist, and vlen().

Referenced by turret_initialize().

◆ turret_targetscore_support()

float turret_targetscore_support ( entity _turret,
entity _target )

Definition at line 69 of file sv_turrets.qc.

70{
71 float score; // Total score
72 float s_score = 0, d_score;
73
74 if (_turret.enemy == _target) s_score = 1;
75
76 d_score = min(_turret.target_range_optimal,tvt_dist) / max(_turret.target_range_optimal,tvt_dist);
77
78 score = (d_score * _turret.target_select_rangebias) +
79 (s_score * _turret.target_select_samebias);
80
81 return score;
82}

References entity(), max(), min(), and tvt_dist.

Referenced by turret_initialize().

◆ turret_think()

void turret_think ( entity this)

Definition at line 1019 of file sv_turrets.qc.

1020{
1021 this.nextthink = time;
1022
1023 MUTATOR_CALLHOOK(TurretThink, this);
1024
1025#ifdef TURRET_DEBUG
1026 if (this.tur_debug_tmr1 < time)
1027 {
1028 if (this.enemy) paint_target (this.enemy,128,this.tur_debug_rvec,0.9);
1029 paint_target(this,256,this.tur_debug_rvec,0.9);
1030 this.tur_debug_tmr1 = time + 1;
1031 }
1032#endif
1033
1034 // Handle ammo
1035 if (!(this.spawnflags & TSF_NO_AMMO_REGEN))
1036 if (this.ammo < this.ammo_max)
1037 this.ammo = min(this.ammo + this.ammo_recharge * frametime, this.ammo_max);
1038
1039 // Inactive turrets needs to run the think loop,
1040 // So they can handle animation and wake up if need be.
1041 if(!this.active)
1042 {
1043 turret_track(this);
1044 return;
1045 }
1046
1047 // This is typicaly used for zaping every target in range
1048 // turret_fusionreactor uses this to recharge friendlys.
1050 {
1051 // Do a this.turret_fire for every valid target.
1052 entity e = findradius(this.origin,this.target_range);
1053 while (e)
1054 {
1055 if(e.takedamage)
1056 {
1058 {
1059 this.enemy = e;
1060
1061 turret_do_updates(this);
1062
1063 if (turret_checkfire(this))
1064 turret_fire(this);
1065 }
1066 }
1067
1068 e = e.chain;
1069 }
1070 this.enemy = NULL;
1071 }
1072 else if(this.shoot_flags & TFL_SHOOT_CUSTOM)
1073 {
1074 // This one is doing something.. oddball. assume its handles what needs to be handled.
1075
1076 // Predict?
1077 if(!(this.aim_flags & TFL_AIM_NO))
1078 this.tur_aimpos = turret_aim_generic(this);
1079
1080 // Turn & pitch?
1081 if(!(this.track_flags & TFL_TRACK_NO))
1082 turret_track(this);
1083
1084 turret_do_updates(this);
1085
1086 // Fire?
1087 if (turret_checkfire(this))
1088 turret_fire(this);
1089 }
1090 else
1091 {
1092 // Special case for volly always. if it fired once it must compleate the volly.
1094 if(this.volly_counter != this.shot_volly)
1095 {
1096 // Predict or whatnot
1097 if(!(this.aim_flags & TFL_AIM_NO))
1098 this.tur_aimpos = turret_aim_generic(this);
1099
1100 // Turn & pitch
1101 if(!(this.track_flags & TFL_TRACK_NO))
1102 turret_track(this);
1103
1104 turret_do_updates(this);
1105
1106 // Fire!
1107 if (turret_checkfire(this))
1108 turret_fire(this);
1109
1110 Turret tur = get_turretinfo(this.m_id);
1111 tur.tr_think(tur, this);
1112
1113 return;
1114 }
1115
1116 // Check if we have a vailid enemy, and try to find one if we dont.
1117
1118 // g_turrets_targetscan_maxdelay forces a target re-scan at least this often
1119 float do_target_scan = 0;
1121 do_target_scan = 1;
1122
1123 // Old target (if any) invalid?
1124 if(this.target_validate_time < time)
1125 if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
1126 {
1127 this.enemy = NULL;
1128 this.target_validate_time = time + 0.5;
1129 do_target_scan = 1;
1130 }
1131
1132 // But never more often then g_turrets_targetscan_mindelay!
1134 do_target_scan = 0;
1135
1136 if(do_target_scan)
1137 {
1138 this.enemy = turret_select_target(this);
1139 this.target_select_time = time;
1140 }
1141
1142 // No target, just go to idle, do any custom stuff and bail.
1143 if (this.enemy == NULL)
1144 {
1145 // Turn & pitch
1146 if(!(this.track_flags & TFL_TRACK_NO))
1147 turret_track(this);
1148
1149 Turret tur = get_turretinfo(this.m_id);
1150 tur.tr_think(tur, this);
1151
1152 // And bail.
1153 return;
1154 }
1155 else
1156 this.lip = time + autocvar_g_turrets_aimidle_delay; // Keep track of the last time we had a target.
1157
1158 // Predict?
1159 if(!(this.aim_flags & TFL_AIM_NO))
1160 this.tur_aimpos = turret_aim_generic(this);
1161
1162 // Turn & pitch?
1163 if(!(this.track_flags & TFL_TRACK_NO))
1164 turret_track(this);
1165
1166 turret_do_updates(this);
1167
1168 // Fire?
1169 if (turret_checkfire(this))
1170 turret_fire(this);
1171 }
1172
1173 Turret tur = get_turretinfo(this.m_id);
1174 tur.tr_think(tur, this);
1175}
virtual void tr_think()
(SERVER) logic to run every frame
Definition turret.qh:37
float frametime
float lip
Definition subs.qh:40
bool turret_checkfire(entity this)
entity turret_select_target(entity this)
void turret_fire(entity this)
vector turret_aim_generic(entity this)
Definition sv_turrets.qc:12
void turret_do_updates(entity t_turret)
updates enemy distances, predicted impact point/time and updated aim<->predict impact distance.
void turret_track(entity this)
float target_validate_time
Definition sv_turrets.qh:40
float autocvar_g_turrets_targetscan_maxdelay
Definition sv_turrets.qh:9
float autocvar_g_turrets_targetscan_mindelay
Definition sv_turrets.qh:10
float target_select_time
Definition sv_turrets.qh:39
float autocvar_g_turrets_aimidle_delay
Definition sv_turrets.qh:6
const int TFL_TRACK_NO
Definition turret.qh:106
const int TSF_NO_AMMO_REGEN
Definition turret.qh:178
const int TFL_AIM_NO
Definition turret.qh:97
const int TFL_SHOOT_CUSTOM
Definition turret.qh:132
const int TFL_SHOOT_HITALLVALID
Definition turret.qh:130

References active, aim_flags, ammo, autocvar_g_turrets_aimidle_delay, autocvar_g_turrets_targetscan_maxdelay, autocvar_g_turrets_targetscan_mindelay, enemy, entity(), frametime, get_turretinfo, lip, m_id, min(), MUTATOR_CALLHOOK, nextthink, NULL, origin, shoot_flags, spawnflags, target_select_time, target_validate_flags, target_validate_time, TFL_AIM_NO, TFL_SHOOT_CUSTOM, TFL_SHOOT_HITALLVALID, TFL_SHOOT_VOLLYALWAYS, TFL_TRACK_NO, time, Turret::tr_think(), track_flags, TSF_NO_AMMO_REGEN, tur_aimpos, turret_aim_generic(), turret_checkfire(), turret_do_updates(), turret_fire(), turret_select_target(), turret_track(), turret_validate_target(), and volly_counter.

Referenced by turret_link(), and turret_respawn().

◆ turret_track()

void turret_track ( entity this)

Definition at line 534 of file sv_turrets.qc.

535{
536 vector target_angle; // This is where we want to aim
537 vector move_angle; // This is where we can aim
538 float f_tmp;
539 vector v1, v2;
540 v1 = this.tur_head.angles;
541 v2 = this.tur_head.avelocity;
542
543 if (this.track_flags == TFL_TRACK_NO)
544 return;
545
546 if(!this.active)
547 target_angle = this.idle_aim - ('1 0 0' * this.aim_maxpitch);
548 else if (this.enemy == NULL)
549 {
550 if(time > this.lip)
551 target_angle = this.idle_aim + this.angles;
552 else
553 target_angle = vectoangles(normalize(this.tur_aimpos - this.tur_shotorg));
554 }
555 else
556 {
557 target_angle = vectoangles(normalize(this.tur_aimpos - this.tur_shotorg));
558 }
559
560 this.tur_head.angles_x = anglemods(this.tur_head.angles_x);
561 this.tur_head.angles_y = anglemods(this.tur_head.angles_y);
562
563 // Find the diffrence between where we currently aim and where we want to aim
564 //move_angle = target_angle - (this.angles + this.tur_head.angles);
565 //move_angle = shortangle_vxy(move_angle,(this.angles + this.tur_head.angles));
566
568 move_angle = shortangle_vxy(move_angle, this.tur_head.angles);
569
570 switch(this.track_type)
571 {
573 f_tmp = this.aim_speed * frametime;
574 if (this.track_flags & TFL_TRACK_PITCH)
575 {
576 this.tur_head.angles_x += bound(-f_tmp, move_angle_x, f_tmp);
577 if(this.tur_head.angles_x > this.aim_maxpitch)
578 this.tur_head.angles_x = this.aim_maxpitch;
579
580 if(this.tur_head.angles_x < -this.aim_maxpitch)
581 this.tur_head.angles_x = this.aim_maxpitch;
582 }
583
584 if (this.track_flags & TFL_TRACK_ROTATE)
585 {
586 this.tur_head.angles_y += bound(-f_tmp, move_angle_y, f_tmp);
587 if(this.tur_head.angles_y > this.aim_maxrot)
588 this.tur_head.angles_y = this.aim_maxrot;
589
590 if(this.tur_head.angles_y < -this.aim_maxrot)
591 this.tur_head.angles_y = this.aim_maxrot;
592 }
593
594 // CSQC
595 this.SendFlags |= TNSF_ANG;
596
597 return;
598
600 f_tmp = this.aim_speed * frametime;
601 move_angle_x = bound(-this.aim_speed, move_angle_x * this.track_accel_pitch * f_tmp, this.aim_speed);
602 move_angle_y = bound(-this.aim_speed, move_angle_y * this.track_accel_rot * f_tmp, this.aim_speed);
603 move_angle = (this.tur_head.avelocity * this.track_blendrate) + (move_angle * (1 - this.track_blendrate));
604 break;
605
607
608 move_angle_y = bound(-this.aim_speed, move_angle_y, this.aim_speed);
609 move_angle_x = bound(-this.aim_speed, move_angle_x, this.aim_speed);
610
611 break;
612 }
613
614 // pitch
615 if (this.track_flags & TFL_TRACK_PITCH)
616 {
617 this.tur_head.avelocity_x = move_angle_x;
618 if((this.tur_head.angles_x + this.tur_head.avelocity_x * frametime) > this.aim_maxpitch)
619 {
620 this.tur_head.avelocity_x = 0;
621 this.tur_head.angles_x = this.aim_maxpitch;
622
623 this.SendFlags |= TNSF_ANG;
624 }
625
626 if((this.tur_head.angles_x + this.tur_head.avelocity_x * frametime) < -this.aim_maxpitch)
627 {
628 this.tur_head.avelocity_x = 0;
629 this.tur_head.angles_x = -this.aim_maxpitch;
630
631 this.SendFlags |= TNSF_ANG;
632 }
633 }
634
635 // rot
636 if (this.track_flags & TFL_TRACK_ROTATE)
637 {
638 this.tur_head.avelocity_y = move_angle_y;
639
640 if((this.tur_head.angles_y + this.tur_head.avelocity_y * frametime) > this.aim_maxrot)
641 {
642 this.tur_head.avelocity_y = 0;
643 this.tur_head.angles_y = this.aim_maxrot;
644
645 this.SendFlags |= TNSF_ANG;
646 }
647
648 if((this.tur_head.angles_y + this.tur_head.avelocity_y * frametime) < -this.aim_maxrot)
649 {
650 this.tur_head.avelocity_y = 0;
651 this.tur_head.angles_y = -this.aim_maxrot;
652
653 this.SendFlags |= TNSF_ANG;
654 }
655 }
656
657 this.SendFlags |= TNSF_AVEL;
658
659 // Force a angle update every 10'th frame
660 this.turret_framecounter += 1;
661 if(this.turret_framecounter >= 10)
662 {
663 this.SendFlags |= TNSF_ANG;
664 this.turret_framecounter = 0;
665 }
666}
ERASEABLE float anglemods(float v)
Definition angle.qc:13
ERASEABLE vector shortangle_vxy(vector ang1, vector ang2)
Definition angle.qc:58
vector AnglesTransform_ToAngles(vector v)
vector AnglesTransform_LeftDivide(vector from_transform, vector to_transform)
vector AnglesTransform_FromAngles(vector v)
vector vectoangles(vector v)
float turret_framecounter
Handles head rotation according to the units .track_type and .track_flags.
const float TFL_TRACKTYPE_FLUIDINERTIA
Definition sv_turrets.qh:64
const float TFL_TRACKTYPE_FLUIDPRECISE
Definition sv_turrets.qh:63

References active, anglemods(), angles, AnglesTransform_FromAngles(), AnglesTransform_LeftDivide(), AnglesTransform_ToAngles(), bound(), enemy, entity(), frametime, idle_aim, lip, normalize(), NULL, SendFlags, shortangle_vxy(), TFL_TRACK_NO, TFL_TRACK_PITCH, TFL_TRACK_ROTATE, TFL_TRACKTYPE_FLUIDINERTIA, TFL_TRACKTYPE_FLUIDPRECISE, TFL_TRACKTYPE_STEPMOTOR, time, TNSF_ANG, TNSF_AVEL, track_flags, tur_aimpos, tur_head, tur_shotorg, turret_framecounter, vectoangles(), and vector.

Referenced by turret_think().

◆ turret_use()

void turret_use ( entity this,
entity actor,
entity trigger )

Definition at line 1181 of file sv_turrets.qc.

1182{
1183 LOG_TRACE("Turret ", this.netname, " used by ", actor.classname);
1184
1185 this.team = actor.team;
1186
1187 if(this.team == 0)
1188 this.active = ACTIVE_NOT;
1189 else
1190 this.active = ACTIVE_ACTIVE;
1191}
const int ACTIVE_NOT
Definition defs.qh:36

References active, ACTIVE_ACTIVE, ACTIVE_NOT, entity(), LOG_TRACE, netname, and team.

Referenced by turret_initialize().

◆ turret_validate_target()

float turret_validate_target ( entity e_turret,
entity e_target,
float validate_flags )

Evaluate a entity for target valitity based on validate_flags NOTE: the caller must check takedamage before calling this, to inline this check.

Definition at line 686 of file sv_turrets.qc.

687{
688 vector v_tmp;
689
690 //if(!validate_flags & TFL_TARGETSELECT_NOBUILTIN)
691 // return -0.5;
692
693 if(!e_target)
694 return -2;
695
696 // Don't attack against owner
697 if(e_target.owner == e_turret || e_target == e_turret.realowner)
698 return -0.5;
699
700 if(!checkpvs(e_target.origin, e_turret))
701 return -1;
702
703 if(e_target.alpha != 0 && e_target.alpha <= 0.3)
704 return -1;
705
706 if(MUTATOR_CALLHOOK(TurretValidateTarget, e_turret, e_target, validate_flags))
707 return M_ARGV(3, float);
708
709 if (validate_flags & TFL_TARGETSELECT_NO)
710 return -4;
711
712 // If only this was used more..
713 if (e_target.flags & FL_NOTARGET)
714 return -5;
715
716 // Cant touch this
717 if (GetResource(e_target, RES_HEALTH) <= 0)
718 return -6;
719
720 // vehicle
721 if(IS_VEHICLE(e_target))
722 {
723 if ((validate_flags & TFL_TARGETSELECT_VEHICLES) && !e_target.owner)
724 return -7;
725 }
726
727 // player
728 if (IS_CLIENT(e_target))
729 {
730 if(!(validate_flags & TFL_TARGETSELECT_PLAYERS))
731 return -7;
732
733 if (IS_DEAD(e_target))
734 return -8;
735 }
736
737 // enemy turrets
738 if(validate_flags & TFL_TARGETSELECT_NOTURRETS)
739 if(e_target.owner.tur_head == e_target)
740 if(e_target.team != e_turret.team) // Dont break support units.
741 return -9;
742
743 // Missile
744 if (e_target.flags & FL_PROJECTILE)
745 if(!(validate_flags & TFL_TARGETSELECT_MISSILES))
746 return -10;
747
748 if (validate_flags & TFL_TARGETSELECT_MISSILESONLY)
749 if(!(e_target.flags & FL_PROJECTILE))
750 return -10.5;
751
752 // Team check
753 if (validate_flags & TFL_TARGETSELECT_TEAMCHECK)
754 {
755 if (validate_flags & TFL_TARGETSELECT_OWNTEAM)
756 {
757 if (e_target.team != e_turret.team)
758 return -11;
759
760 if (e_turret.team != e_target.owner.team)
761 return -12;
762
763 if (e_turret.team != e_target.aiment.team)
764 return -12; // portals
765 }
766 else
767 {
768 if (e_target.team == e_turret.team)
769 return -13;
770
771 if (e_turret.team == e_target.owner.team)
772 return -14;
773
774 if (e_turret.team == e_target.aiment.team)
775 return -14; // portals
776 }
777 }
778
779 // Range limits?
780 tvt_dist = vlen(e_turret.origin - real_origin(e_target));
781 if (validate_flags & TFL_TARGETSELECT_RANGELIMITS)
782 {
783 if (tvt_dist < e_turret.target_range_min)
784 return -15;
785
786 if (tvt_dist > e_turret.target_range)
787 return -16;
788 }
789
790 // Can we even aim this thing?
791 tvt_thadv = angleofs3(e_turret.tur_head.origin, e_turret.angles + e_turret.tur_head.angles, e_target.origin);
792 tvt_tadv = shortangle_vxy(angleofs(e_turret, e_target), e_turret.angles);
794
795 /*
796 if(validate_flags & TFL_TARGETSELECT_FOV)
797 {
798 if(e_turret.target_select_fov < tvt_thadf)
799 return -21;
800 }
801 */
802
803 if (validate_flags & TFL_TARGETSELECT_ANGLELIMITS)
804 {
805 if (fabs(tvt_tadv_x) > e_turret.aim_maxpitch)
806 return -17;
807
808 if (fabs(tvt_tadv_y) > e_turret.aim_maxrot)
809 return -18;
810 }
811
812 // Line of sight?
813 if (validate_flags & TFL_TARGETSELECT_LOS)
814 {
815 v_tmp = real_origin(e_target) + ((e_target.mins + e_target.maxs) * 0.5);
816
817 traceline(e_turret.origin + '0 0 16', v_tmp, 0, e_turret);
818
819 if(vdist(v_tmp - trace_endpos, >, e_turret.aim_firetolerance_dist))
820 return -19;
821 }
822
823 if (e_target.classname == "grapplinghook")
824 return -20;
825
826 /*
827 if (e_target.classname == "func_button")
828 return -21;
829 */
830
831#ifdef TURRET_DEBUG_TARGETSELECT
832 LOG_TRACE("Target:",e_target.netname," is a valid target for ",e_turret.netname);
833#endif
834
835 return 1;
836}
ERASEABLE vector angleofs3(vector from, vector ang, vector to)
Definition angle.qc:73
float checkpvs(vector viewpos, entity viewee)
vector tvt_thadv
vector tvt_tadv
const int TFL_TARGETSELECT_NO
Definition turret.qh:80
const int TFL_TARGETSELECT_VEHICLES
Definition turret.qh:93
const int TFL_TARGETSELECT_NOTURRETS
Definition turret.qh:90
const int TFL_TARGETSELECT_OWNTEAM
Definition turret.qh:89
const int TFL_TARGETSELECT_MISSILESONLY
Definition turret.qh:92
#define IS_VEHICLE(v)
Definition utils.qh:22

References angleofs, angleofs3(), checkpvs(), entity(), fabs(), FL_NOTARGET, FL_PROJECTILE, GetResource(), IS_CLIENT, IS_DEAD, IS_VEHICLE, LOG_TRACE, M_ARGV, MUTATOR_CALLHOOK, real_origin(), shortangle_vxy(), TFL_TARGETSELECT_ANGLELIMITS, TFL_TARGETSELECT_LOS, TFL_TARGETSELECT_MISSILES, TFL_TARGETSELECT_MISSILESONLY, TFL_TARGETSELECT_NO, TFL_TARGETSELECT_NOTURRETS, TFL_TARGETSELECT_OWNTEAM, TFL_TARGETSELECT_PLAYERS, TFL_TARGETSELECT_RANGELIMITS, TFL_TARGETSELECT_TEAMCHECK, TFL_TARGETSELECT_VEHICLES, trace_endpos, tvt_dist, tvt_tadv, tvt_thadf, tvt_thadv, vdist, vector, and vlen().

Referenced by turret_firecheck(), turret_hk_addtarget(), turret_select_target(), turret_tesla_firecheck(), turret_think(), and walker_melee_do_dmg().

◆ turrets_manager_think()

void turrets_manager_think ( entity this)

Definition at line 1201 of file sv_turrets.qc.

1202{
1203 this.nextthink = time + 1;
1204
1206 {
1207 IL_EACH(g_turrets, true,
1208 {
1209 load_unit_settings(it, true);
1210 Turret tur = get_turretinfo(it.m_id);
1211 tur.tr_think(tur, it);
1212 });
1213 cvar_set("g_turrets_reloadcvars", "0");
1214 }
1215}
#define IL_EACH(this, cond, body)
void cvar_set(string name, string value)
bool autocvar_g_turrets_reloadcvars
Definition sv_turrets.qh:8

References autocvar_g_turrets_reloadcvars, cvar_set(), entity(), g_turrets, get_turretinfo, IL_EACH, load_unit_settings(), nextthink, time, and Turret::tr_think().

Referenced by turret_findtarget().

◆ turrets_setframe()

void turrets_setframe ( entity this,
float _frame,
float client_only )

Definition at line 313 of file sv_turrets.qc.

314{
315 if((client_only ? this.clientframe : this.frame ) != _frame)
316 {
317 this.SendFlags |= TNSF_ANIM;
318 this.anim_start_time = time;
319 }
320
321 if(client_only)
322 this.clientframe = _frame;
323 else
324 this.frame = _frame;
325
326}
float clientframe

References anim_start_time, clientframe, entity(), frame, SendFlags, time, and TNSF_ANIM.

Referenced by ewheel_move_enemy(), and walker_setnoanim().

Variable Documentation

◆ clientframe

float clientframe

Definition at line 312 of file sv_turrets.qc.

Referenced by turrets_setframe().

◆ turret_framecounter

float turret_framecounter

Handles head rotation according to the units .track_type and .track_flags.

Definition at line 533 of file sv_turrets.qc.

Referenced by turret_track().