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

Go to the source code of this file.

Macros

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

Functions

 bool (entity this, entity e_target, entity e_sender) turret_addtarget
 float (entity _turret, entity _target) turret_score_target
 Function to use for target evaluation. usualy turret_targetscore_generic.
 float (entity this) turret_firecheckfunc
 STATIC_INIT (g_turrets)
bool turret_closetotarget (entity this, vector targ, float range)
void turret_do_updates (entity e_turret)
 updates aim org, shot org, shot dir and enemy org for selected turret
bool turret_firecheck (entity this)
 Preforms pre-fire checks based on the uints firecheck_flags.
bool turret_initialize (entity this, Turret tur)
entity turret_projectile (entity actor, Sound _snd, float _size, float _health, float _death, float _proj_type, float _cull, float _cli_anim)
void turret_projectile_explode (entity this)
void turret_respawn (entity this)
entity turret_select_target (entity this)
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_setframe (entity this, float _frame, float client_only)

Variables

float ammo
bool autocvar_g_turrets
float autocvar_g_turrets_aimidle_delay
bool autocvar_g_turrets_nofire
bool autocvar_g_turrets_reloadcvars
float autocvar_g_turrets_targetscan_maxdelay
float autocvar_g_turrets_targetscan_mindelay
IntrusiveList g_turrets
vector idle_aim
entity pathcurrent
entity pathgoal
float target_select_time
float target_validate_time
const float TFL_TRACKTYPE_FLUIDINERTIA = 3
const float TFL_TRACKTYPE_FLUIDPRECISE = 2
const float TFL_TRACKTYPE_STEPMOTOR = 1
vector tur_aimpos
entity tur_defend
float tur_dist_aimpos
float tur_dist_enemy
float tur_dist_impact_to_aimpos
entity tur_head
entity tur_impactent
float tur_impacttime
vector tur_shotdir_updated
vector tur_shotorg
float turret_count
float turret_scale_aim
 Map time control aim speed.
float turret_scale_ammo
 Map time control ammo held and recharged.
float turret_scale_damage
 Map time control over pain inflicted.
float turret_scale_health
 Map time control health.
float turret_scale_range
 Map time control targetting range.
float turret_scale_refire
 Map time control refire.
float turret_scale_respawn
 Map time control respawn time.
const int TURRET_TEAM = 256
float tvt_dist
vector tvt_tadv
float tvt_thadf
vector tvt_thadv
float volly_counter

Macro Definition Documentation

◆ X

#define X ( class,
prefix,
fld,
type )
Value:
.type fld;

Definition at line 20 of file sv_turrets.qh.

Function Documentation

◆ bool()

bool ( entity this,
entity e_target,
entity e_sender )

References entity().

◆ float() [1/2]

float ( entity _turret,
entity _target )

Function to use for target evaluation. usualy turret_targetscore_generic.

References entity().

◆ float() [2/2]

float ( entity this)

References entity(), and vector.

◆ STATIC_INIT()

STATIC_INIT ( g_turrets )

Definition at line 119 of file sv_turrets.qh.

120{
121 g_turrets = IL_NEW();
122}
#define IL_NEW()
IntrusiveList g_turrets

References g_turrets, and IL_NEW.

◆ turret_closetotarget()

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

Definition at line 1215 of file sv_turrets.qc.

1216{
1217 vector path_extra_size = '1 1 1' * range;
1218 return boxesoverlap(targ - path_extra_size, targ + path_extra_size, this.absmin - path_extra_size, this.absmax + path_extra_size);
1219}
vector absmax
vector absmin
vector
Definition self.qh:96
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:72

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

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

◆ turret_do_updates()

void turret_do_updates ( entity t_turret)

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

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

Definition at line 496 of file sv_turrets.qc.

497{
498 vector enemy_pos = real_origin(t_turret.enemy);
499
500 turret_tag_fire_update(t_turret);
501
502 t_turret.tur_shotdir_updated = v_forward;
503 t_turret.tur_dist_enemy = vlen(t_turret.tur_shotorg - enemy_pos);
504 t_turret.tur_dist_aimpos = vlen(t_turret.tur_shotorg - t_turret.tur_aimpos);
505
506 /*if ((t_turret.firecheck_flags & TFL_FIRECHECK_VERIFIED) && t_turret.enemy)
507 {
508 oldpos = t_turret.enemy.origin;
509 setorigin(t_turret.enemy, t_turret.tur_aimpos);
510 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);
511 setorigin(t_turret.enemy, oldpos);
512
513 if (trace_ent == t_turret.enemy)
514 t_turret.tur_dist_impact_to_aimpos = 0;
515 else
516 t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos);
517 }
518 else*/
519 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);
520
521 t_turret.tur_dist_impact_to_aimpos = vlen(trace_endpos - t_turret.tur_aimpos) - 0.5 * vlen(t_turret.enemy.maxs - t_turret.enemy.mins);
522 t_turret.tur_impactent = trace_ent;
523 t_turret.tur_impacttime = vlen(t_turret.tur_shotorg - trace_endpos) / t_turret.shot_speed;
524}
float turret_tag_fire_update(entity this)
Update this.tur_shotorg by getting up2date bone info NOTICE this func overwrites the global v_forward...
Definition util.qc:9
vector real_origin(entity ent)
Definition util.qc:147
entity trace_ent
const float MOVE_NORMAL
vector trace_endpos
vector v_forward
float vlen(vector v)

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_firecheck()

bool turret_firecheck ( entity this)

Preforms pre-fire checks based on the uints firecheck_flags.

Definition at line 874 of file sv_turrets.qc.

875{
876 // This one just dont care =)
878 return true;
879
880 if (this.enemy == NULL)
881 return false;
882
883 // Ready?
885 && this.attack_finished_single[0] > time)
886 return false;
887
888 // Special case: volly fire turret that has to fire a full volly if a shot was fired.
890 && this.volly_counter != this.shot_volly
891 && this.ammo >= this.shot_dmg)
892 return true;
893
894 // Lack of zombies makes shooting dead things unnecessary :P
896 && IS_DEAD(this.enemy))
897 return false;
898
899 // Own ammo?
901 && this.ammo < this.shot_dmg)
902 return false;
903
904 // Other's ammo? (support-supply units)
906 && this.enemy.ammo >= this.enemy.ammo_max)
907 return false;
908
909 // Target of opertunity?
911 {
912 this.enemy = this.tur_impactent;
913 return true;
914 }
915
917 {
918 // To close?
919 if (this.tur_dist_aimpos < this.target_range_min)
920 {
922 return true; // Target of opertunity?
923 return false;
924 }
925 }
926
927 // Try to avoid FF?
929 && TURRET_SAME_TEAM(this.tur_impactent, this))
930 return false;
931
932 // aim<->predicted impact
934 && this.tur_dist_impact_to_aimpos > this.aim_firetolerance_dist)
935 return false;
936
937 // Volly status
938 if (this.shot_volly > 1
939 && this.volly_counter == this.shot_volly
940 && this.ammo < this.shot_dmg * this.shot_volly)
941 return false;
942
943 /*
944 if ((this.firecheck_flags & TFL_FIRECHECK_VERIFIED)
945 && this.tur_impactent != this.enemy)
946 return false;
947 */
948
949 return true;
950}
#define IS_DEAD(s)
Definition player.qh:244
float time
#define NULL
Definition post.qh:14
entity enemy
Definition sv_ctf.qh:152
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 ...
float volly_counter
Definition sv_turrets.qh:37
entity tur_impactent
Definition sv_turrets.qh:33
float tur_dist_aimpos
Definition sv_turrets.qh:35
float ammo
Definition sv_turrets.qh:43
float tur_dist_impact_to_aimpos
Definition sv_turrets.qh:36
const int TFL_FIRECHECK_DISTANCES
another range check
Definition turret.qh:117
const int TFL_FIRECHECK_AMMO_OWN
own ammo needs to be larger than damage dealt
Definition turret.qh:124
int target_validate_flags
Definition turret.qh:83
const int TFL_SHOOT_VOLLYALWAYS
always do a full volly, even if target is lost
Definition turret.qh:133
const int TFL_FIRECHECK_DEAD
don't attack dead targets (zombies?)
Definition turret.qh:116
#define TURRET_SAME_TEAM(a, b)
Definition turret.qh:75
const int TFL_FIRECHECK_AIMDIST
consider distance impactpoint<->aimspot
Definition turret.qh:119
const int TFL_FIRECHECK_AMMO_OTHER
target's ammo needs to be less than max
Definition turret.qh:125
int shoot_flags
Definition turret.qh:130
const int TFL_FIRECHECK_REFIRE
check single attack finished delays
Definition turret.qh:126
const int TFL_FIRECHECK_NO
no prefire checks
Definition turret.qh:127
int firecheck_flags
Definition turret.qh:115
const int TFL_FIRECHECK_AFF
try to avoid any friendly fire
Definition turret.qh:123
float attack_finished_single[MAX_WEAPONSLOTS]

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_SAME_TEAM, turret_validate_target(), and volly_counter.

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

◆ turret_initialize()

bool turret_initialize ( entity this,
Turret tur )

Definition at line 1250 of file sv_turrets.qc.

1251{
1252 if (!autocvar_g_turrets)
1253 return false;
1254
1255 if (tur.m_id == 0)
1256 return false; // invalid turret
1257
1258 // if tur_head exists, we can assume this turret re-spawned
1259 if (!this.tur_head)
1260 {
1261 tur.tr_precache(tur);
1262 IL_PUSH(g_turrets, this);
1263 IL_PUSH(g_bot_targets, this);
1264 }
1265
1266 if (!(this.spawnflags & TSF_SUSPENDED))
1268
1269 this.netname = tur.netname;
1270 load_unit_settings(this, 0);
1271
1272 // Group all turrets into the same team, so they don't shoot eachother
1273 if (!this.team || !teamplay) this.team = TURRET_TEAM;
1274 if (!GetResource(this, RES_HEALTH)) SetResourceExplicit(this, RES_HEALTH, 1000);
1275 if (!this.shot_refire) this.shot_refire = 1;
1276 if (!this.tur_shotorg) this.tur_shotorg = '50 0 50';
1280 if (!this.track_type) this.track_type = TFL_TRACKTYPE_STEPMOTOR;
1286
1287 if (this.track_type != TFL_TRACKTYPE_STEPMOTOR)
1288 {
1289 // Fluid / Ineria mode. Looks mutch nicer.
1290 // Can reduce aim preformance alot, needs a bit diffrent aimspeed
1291
1292 this.aim_speed = bound(0.1, (!this.aim_speed ? 180 : this.aim_speed), 1000);
1293
1294 if (!this.track_accel_pitch)
1295 this.track_accel_pitch = 0.5;
1296 if (!this.track_accel_rot)
1297 this.track_accel_rot = 0.5;
1298 if (!this.track_blendrate)
1299 this.track_blendrate = 0.35;
1300 }
1301
1302 turret_initparams(this);
1303
1305
1306 if (this.turret_flags & TUR_FLAG_SPLASH)
1307 this.aim_flags |= TFL_AIM_SPLASH;
1308
1309 if (this.turret_flags & TUR_FLAG_MISSILE)
1311
1312 if (this.turret_flags & TUR_FLAG_PLAYER)
1314
1315 if (this.spawnflags & TSL_NO_RESPAWN)
1317
1318 if (this.turret_flags & TUR_FLAG_SUPPORT)
1319 this.turret_score_target = turret_targetscore_support;
1320 else
1321 this.turret_score_target = turret_targetscore_generic;
1322
1323 ++turret_count;
1324
1325 _setmodel(this, tur.model);
1326 setsize(this, tur.m_mins, tur.m_maxs);
1327
1328 this.m_id = tur.m_id;
1329 this.active = ACTIVE_ACTIVE;
1330 this.effects = EF_NODRAW;
1331 this.netname = tur.m_name;
1332 this.max_health = GetResource(this, RES_HEALTH);
1334 this.ammo = this.ammo_max;
1335 this.solid = SOLID_BBOX;
1336 this.takedamage = DAMAGE_AIM;
1338 this.view_ofs = '0 0 0';
1339 this.idle_aim = '0 0 0';
1340 this.turret_firecheckfunc = turret_firecheck;
1341 this.event_damage = turret_damage;
1342 this.event_heal = turret_heal;
1343 this.use = turret_use;
1344 this.bot_attack = true;
1345 this.nextthink = time + 1;
1346 this.reset = turret_reset;
1347
1348 this.tur_head = new(turret_head);
1349 _setmodel(this.tur_head, tur.head_model);
1350 setsize(this.tur_head, '0 0 0', '0 0 0');
1351 setorigin(this.tur_head, '0 0 0');
1352 setattachment(this.tur_head, this, "tag_head");
1353
1354 this.tur_head.netname = this.tur_head.classname;
1355 this.tur_head.team = this.team;
1356 this.tur_head.owner = this;
1357 this.tur_head.takedamage = DAMAGE_NO;
1358 this.tur_head.solid = SOLID_NOT;
1360
1361 this.weaponentities[0] = this; // lol
1362
1363 if (!this.tur_defend && this.target != "")
1365
1366#ifdef TURRET_DEBUG
1367 this.tur_debug_start = this.nextthink;
1368 while (vdist(this.tur_debug_rvec, <, 2))
1369 this.tur_debug_rvec = randomvec() * 4;
1370
1371 this.tur_debug_rvec.x = fabs(this.tur_debug_rvec.x);
1372 this.tur_debug_rvec.y = fabs(this.tur_debug_rvec.y);
1373 this.tur_debug_rvec.z = fabs(this.tur_debug_rvec.z);
1374#endif
1375
1376 turret_link(this);
1377 turret_respawn(this);
1379
1380 tur.tr_setup(tur, this);
1381
1382 if (MUTATOR_CALLHOOK(TurretSpawn, this))
1383 return false;
1384
1385 return true;
1386}
float bot_attack
Definition api.qh:38
IntrusiveList g_bot_targets
Definition api.qh:149
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
float max_health
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
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:31
virtual void tr_setup()
(BOTH) setup turret data
Definition turret.qh:36
virtual void tr_precache()
(BOTH) precaches models/sounds used by this turret
Definition turret.qh:46
vector m_mins
turret hitbox size
Definition turret.qh:29
int spawnflags
Definition turret.qh:27
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:87
const float SOLID_BBOX
const float SOLID_NOT
float effects
float nextthink
float solid
const float EF_NODRAW
#define use
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
int m_id
Definition effect.qh:19
SetResourceExplicit(ent, RES_ARMOR, ReadByte() *DEC_FACTOR)) ENTCS_PROP(NAME
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:80
const int MOVETYPE_NOCLIP
Definition movetypes.qh:141
vector view_ofs
Definition progsdefs.qc:151
const int DAMAGE_NO
Definition subs.qh:79
const int DAMAGE_AIM
Definition subs.qh:81
float takedamage
Definition subs.qh:78
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:64
void turret_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector vforce)
void turret_respawn(entity this)
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:78
void turret_initparams(entity tur)
void load_unit_settings(entity ent, bool is_reload)
vector idle_aim
Definition sv_turrets.qh:44
entity tur_defend
Definition sv_turrets.qh:29
bool autocvar_g_turrets
Definition sv_turrets.qh:5
float turret_count
Definition sv_turrets.qh:90
vector tur_shotorg
Definition sv_turrets.qh:30
const float TFL_TRACKTYPE_STEPMOTOR
Definition sv_turrets.qh:62
entity tur_head
Definition sv_turrets.qh:28
const int TURRET_TEAM
Definition sv_turrets.qh:95
bool teamplay
Definition teams.qh:59
string target
Definition triggers.qh:55
const int TFL_TARGETSELECT_ANGLELIMITS
apply extra angular limits to target selection
Definition turret.qh:89
const int TUR_FLAG_SUPPORT
supports other units
Definition turret.qh:151
const int TSF_SUSPENDED
Definition turret.qh:180
const int TFL_TARGETSELECT_TEAMCHECK
don't attack teammates
Definition turret.qh:91
const int TUR_FLAG_MISSILE
can damage missiles
Definition turret.qh:150
const int TFL_DMG_YES
can be damaged
Definition turret.qh:170
const int TUR_FLAG_ISTURRET
identifies this unit as a turret
Definition turret.qh:156
const int TFL_AIM_LEAD
try to predict target movement
Definition turret.qh:103
const int TFL_TARGETSELECT_PLAYERS
target players
Definition turret.qh:86
const int TFL_AIM_SPLASH
aim for ground around the target's feet
Definition turret.qh:102
int track_flags
Definition turret.qh:109
const int TUR_FLAG_PLAYER
can damage players
Definition turret.qh:149
int turret_flags
Definition turret.qh:139
const int TFL_TARGETSELECT_RANGELIMITS
limit target selection range
Definition turret.qh:90
const int TFL_TRACK_ROTATE
rotate head
Definition turret.qh:112
int target_select_flags
Definition turret.qh:82
const int TFL_DMG_AIMSHAKE
damage throws off aim
Definition turret.qh:175
const int TSL_NO_RESPAWN
don't re-spawn
Definition turret.qh:184
const int TFL_AIM_SHOTTIMECOMPENSATE
compensate for shot traveltime when leading
Definition turret.qh:104
const int TFL_AMMO_ENERGY
uses power
Definition turret.qh:161
const int TFL_FIRECHECK_LOS
line of sight
Definition turret.qh:118
const int TFL_DMG_RETALIATE
target attackers
Definition turret.qh:172
const int TFL_TARGETSELECT_LOS
require line of sight to find targets
Definition turret.qh:85
const int TFL_AMMO_RECHARGE
regenerates ammo
Definition turret.qh:164
int damage_flags
Definition turret.qh:168
const int TFL_DMG_DEATH_NORESPAWN
no re-spawning
Definition turret.qh:177
const int TFL_FIRECHECK_TEAMCHECK
don't attack teammates
Definition turret.qh:122
const int TFL_TRACK_PITCH
pitch head
Definition turret.qh:111
const int TUR_FLAG_SPLASH
can deal splash damage
Definition turret.qh:142
int aim_flags
Definition turret.qh:100
const int TFL_TARGETSELECT_MISSILES
target projectiles
Definition turret.qh:87
const int TUR_FLAG_MEDPROJ
turret fires medium projectiles
Definition turret.qh:147
#define ammo_flags
Definition turret.qh:159
#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:2427
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2229

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, 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_TEAM, turret_use(), use, vdist, view_ofs, and weaponentities.

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

◆ 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 455 of file sv_turrets.qc.

456{
457 TC(Sound, _snd);
458
459 sound(actor, CH_WEAPON_A, _snd, VOL_BASE, ATTEN_NORM);
460 entity proj = spawn();
461 setorigin(proj, actor.tur_shotorg);
462 setsize(proj, '-0.5 -0.5 -0.5' * _size, '0.5 0.5 0.5' * _size);
463 proj.owner = actor;
464 proj.realowner = actor;
465 proj.bot_dodge = true;
466 proj.bot_dodgerating = actor.shot_dmg;
469 proj.nextthink = time + 9;
471 proj.velocity = normalize(actor.tur_shotdir_updated + randomvec() * actor.shot_spread) * actor.shot_speed;
472 proj.flags = FL_PROJECTILE;
473 IL_PUSH(g_projectiles, proj);
474 IL_PUSH(g_bot_dodge, proj);
475 proj.enemy = actor.enemy;
476 proj.projectiledeathtype = _death;
478 if (_health)
479 {
480 SetResourceExplicit(proj, RES_HEALTH, _health);
481 proj.takedamage = DAMAGE_YES;
482 proj.event_damage = turret_projectile_damage;
483 }
484 else
485 proj.flags |= FL_NOTARGET;
486
487 CSQCProjectile(proj, _cli_anim, _proj_type, _cull);
488
489 return proj;
490}
IntrusiveList g_bot_dodge
Definition api.qh:150
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
const int FL_PROJECTILE
Definition constants.qh:76
const int FL_NOTARGET
Definition constants.qh:67
#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:142
#define setthink(e, f)
#define settouch(e, f)
Definition self.qh:77
IntrusiveList g_projectiles
Definition common.qh:58
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:34
const float VOL_BASE
Definition sound.qh:36
const int CH_WEAPON_A
Definition sound.qh:7
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
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_explode()

void turret_projectile_explode ( entity this)

Definition at line 412 of file sv_turrets.qc.

413{
414 this.takedamage = DAMAGE_NO;
415 this.event_damage = func_null;
416
417#ifdef TURRET_DEBUG
418 float d = RadiusDamage(this, this.owner,
419#else
420 RadiusDamage(this, this.realowner,
421#endif
422 this.owner.shot_dmg,
423 0,
424 this.owner.shot_radius,
425 this,
426 NULL,
427 this.owner.shot_force,
428 this.projectiledeathtype,
429 DMG_NOWEP,
430 NULL
431 );
432#ifdef TURRET_DEBUG
433 this.owner.tur_debug_dmg_t_h += d;
434 this.owner.tur_debug_dmg_t_f += this.owner.shot_dmg;
435#endif
436
437 delete(this);
438}
entity owner
Definition main.qh:87
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:934
#define DMG_NOWEP
Definition damage.qh:104
var void func_null()
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_respawn()

void turret_respawn ( entity this)

Definition at line 265 of file sv_turrets.qc.

266{
267 // Make sure all parts belong to the same team since
268 // this function doubles as "teamchange" function.
269 this.tur_head.team = this.team;
270 this.effects &= ~EF_NODRAW;
271 this.deadflag = DEAD_NO;
273 this.solid = SOLID_BBOX;
274 this.takedamage = DAMAGE_AIM;
275 this.event_damage = turret_damage;
276 this.event_heal = turret_heal;
277 this.avelocity = '0 0 0';
278 this.tur_head.avelocity = this.avelocity;
279 this.tur_head.angles = this.idle_aim;
280 SetResourceExplicit(this, RES_HEALTH, this.max_health);
281 this.enemy = NULL;
282 this.volly_counter = this.shot_volly;
283 this.ammo = this.ammo_max;
284
285 this.nextthink = time;
286 setthink(this, turret_think);
287
289
290 Turret tur = get_turretinfo(this.m_id);
291 tur.tr_setup(tur, this);
292
293 setorigin(this, this.origin); // make sure it's linked to the area grid
294}
vector avelocity
vector origin
float EF_LOWPRECISION
int SendFlags
Definition net.qh:159
float DEAD_NO
Definition progsdefs.qc:274
float deadflag
Definition progsdefs.qc:149
void turret_think(entity this)
const int TNSF_FULL_UPDATE
Definition turret.qh:197
#define get_turretinfo(i)
Definition all.qh:9

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 809 of file sv_turrets.qc.

810{
811 entity e; // target looper entity
812 float score; // target looper entity score
813 entity e_enemy; // currently best scoreing target
814 float m_score; // currently best scoreing target's score
815
816 m_score = 0;
817 if (this.enemy && this.enemy.takedamage && turret_validate_target(this, this.enemy, this.target_validate_flags) > 0)
818 {
819 e_enemy = this.enemy;
820 m_score = this.turret_score_target(this, e_enemy) * this.target_select_samebias;
821 }
822 else
823 e_enemy = this.enemy = NULL;
824
825 e = findradius(this.origin, this.target_range);
826
827 // Nothing to aim at?
828 if (!e)
829 return NULL;
830
831 float f;
832 for (; e; e = e.chain)
833 if (e.takedamage)
834 {
836 //dprint("F is: ", ftos(f), "\n");
837 if (f > 0)
838 {
839 score = this.turret_score_target(this, e);
840 if (score > m_score && score > 0)
841 {
842 e_enemy = e;
843 m_score = score;
844 }
845 }
846 }
847
848 return e_enemy;
849}

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

Referenced by turret_tesla_firecheck(), and turret_think().

◆ 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 677 of file sv_turrets.qc.

678{
679 //if (!validate_flags & TFL_TARGETSELECT_NOBUILTIN)
680 // return -0.5;
681
682 if (!e_target)
683 return -2;
684
685 if (e_target.owner == e_turret || e_target == e_turret.realowner) // Don't attack against owner
686 return -0.5;
687
688 if (!checkpvs(e_target.origin, e_turret))
689 return -1;
690 if (e_target.alpha != 0 && e_target.alpha <= 0.3)
691 return -1;
692
693 if (MUTATOR_CALLHOOK(TurretValidateTarget, e_turret, e_target, validate_flags))
694 return M_ARGV(3, float);
695
696 if (validate_flags & TFL_TARGETSELECT_NO)
697 return -4;
698
699 if (e_target.flags & FL_NOTARGET) // If only this was used more..
700 return -5;
701
702 if (GetResource(e_target, RES_HEALTH) <= 0) // Cant touch this
703 return -6;
704
705 // vehicle
706 if (IS_VEHICLE(e_target)
707 && (validate_flags & TFL_TARGETSELECT_VEHICLES) && !e_target.owner)
708 return -7;
709
710 if (IS_CLIENT(e_target)) // player
711 {
712 if (!(validate_flags & TFL_TARGETSELECT_PLAYERS))
713 return -7;
714 if (IS_DEAD(e_target))
715 return -8;
716 }
717
718 // enemy turrets
719 if ((validate_flags & TFL_TARGETSELECT_NOTURRETS)
720 && e_target.owner.tur_head == e_target
721 && TURRET_DIFF_TEAM(e_target, e_turret)) // Dont break support units.
722 return -9;
723
724 // Missile
725 if ((e_target.flags & FL_PROJECTILE)
726 && !(validate_flags & TFL_TARGETSELECT_MISSILES))
727 return -10;
728
729 if ((validate_flags & TFL_TARGETSELECT_MISSILESONLY)
730 && !(e_target.flags & FL_PROJECTILE))
731 return -10.5;
732
733 // Team check
734 if (validate_flags & TFL_TARGETSELECT_TEAMCHECK)
735 {
736 if (validate_flags & TFL_TARGETSELECT_OWNTEAM)
737 {
738 if (TURRET_DIFF_TEAM(e_target, e_turret))
739 return -11;
740 if (TURRET_DIFF_TEAM(e_turret, e_target.owner))
741 return -12;
742 if (TURRET_DIFF_TEAM(e_turret, e_target.aiment))
743 return -12; // portals
744 }
745 else
746 {
747 if (TURRET_SAME_TEAM(e_target, e_turret))
748 return -13;
749 if (TURRET_SAME_TEAM(e_turret, e_target.owner))
750 return -14;
751 if (TURRET_SAME_TEAM(e_turret, e_target.aiment))
752 return -14; // portals
753 }
754 }
755
756 // Range limits?
757 tvt_dist = vlen(e_turret.origin - real_origin(e_target));
758 if (validate_flags & TFL_TARGETSELECT_RANGELIMITS)
759 {
760 if (tvt_dist < e_turret.target_range_min)
761 return -15;
762 if (tvt_dist > e_turret.target_range)
763 return -16;
764 }
765
766 // Can we even aim this thing?
767 tvt_thadv = angleofs3(e_turret.tur_head.origin, e_turret.angles + e_turret.tur_head.angles, e_target.origin);
768 tvt_tadv = shortangle_vxy(angleofs(e_turret, e_target), e_turret.angles);
770
771 /*
772 if ((validate_flags & TFL_TARGETSELECT_FOV)
773 && e_turret.target_select_fov < tvt_thadf)
774 return -21;
775 */
776
777 if (validate_flags & TFL_TARGETSELECT_ANGLELIMITS)
778 {
779 if (fabs(tvt_tadv.x) > e_turret.aim_maxpitch)
780 return -17;
781 if (fabs(tvt_tadv.y) > e_turret.aim_maxrot)
782 return -18;
783 }
784
785 // Line of sight?
786 if (validate_flags & TFL_TARGETSELECT_LOS)
787 {
788 vector v_tmp = real_origin(e_target) + 0.5 * (e_target.mins + e_target.maxs);
789
790 traceline(e_turret.origin + '0 0 16', v_tmp, 0, e_turret);
791 if (vdist(v_tmp - trace_endpos, >, e_turret.aim_firetolerance_dist))
792 return -19;
793 }
794
795 if (e_target.classname == "grapplinghook")
796 return -20;
797 /*
798 if (e_target.classname == "func_button")
799 return -21;
800 */
801
802#ifdef TURRET_DEBUG_TARGETSELECT
803 LOG_TRACE("Target:", e_target.netname, " is a valid target for ", e_turret.netname);
804#endif
805
806 return 1;
807}
ERASEABLE vector angleofs3(vector from, vector ang, vector to)
Return the angle offset between angle ang and angle of the vector from->to.
Definition angle.qc:60
#define angleofs(from, to)
Definition angle.qc:74
ERASEABLE vector shortangle_vxy(vector ang1, vector ang2)
Definition angle.qc:49
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_CLIENT(s)
Definition player.qh:241
float checkpvs(vector viewpos, entity viewee)
#define LOG_TRACE(...)
Definition log.qh:74
vector tvt_thadv
float tvt_thadf
vector tvt_tadv
float tvt_dist
const int TFL_TARGETSELECT_NO
don't automatically find targets
Definition turret.qh:84
const int TFL_TARGETSELECT_VEHICLES
target manned vehicles
Definition turret.qh:97
const int TFL_TARGETSELECT_NOTURRETS
don't attack other turrets
Definition turret.qh:94
const int TFL_TARGETSELECT_OWNTEAM
only attack teammates
Definition turret.qh:93
const int TFL_TARGETSELECT_MISSILESONLY
only attack missiles
Definition turret.qh:96
#define TURRET_DIFF_TEAM(a, b)
Definition turret.qh:76
#define IS_VEHICLE(v)
Definition utils.qh:24

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, TURRET_DIFF_TEAM, TURRET_SAME_TEAM, 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_setframe()

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

Definition at line 299 of file sv_turrets.qc.

300{
301 if ((client_only ? this.clientframe : this.frame) != _frame)
302 {
303 this.SendFlags |= TNSF_ANIM;
304 this.anim_start_time = time;
305 }
306
307 if (client_only)
308 this.clientframe = _frame;
309 else
310 this.frame = _frame;
311
312}
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
float anim_start_time
Definition items.qc:15
float clientframe
const int TNSF_ANIM
Definition turret.qh:195

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

Referenced by ewheel_move_enemy(), and walker_setnoanim().

Variable Documentation

◆ ammo

◆ autocvar_g_turrets

bool autocvar_g_turrets

Definition at line 5 of file sv_turrets.qh.

Referenced by spawnfunc(), and turret_initialize().

◆ autocvar_g_turrets_aimidle_delay

float autocvar_g_turrets_aimidle_delay

Definition at line 6 of file sv_turrets.qh.

Referenced by turret_think().

◆ autocvar_g_turrets_nofire

bool autocvar_g_turrets_nofire

Definition at line 7 of file sv_turrets.qh.

Referenced by turret_fire().

◆ autocvar_g_turrets_reloadcvars

bool autocvar_g_turrets_reloadcvars

Definition at line 8 of file sv_turrets.qh.

Referenced by turrets_manager_think().

◆ autocvar_g_turrets_targetscan_maxdelay

float autocvar_g_turrets_targetscan_maxdelay

Definition at line 9 of file sv_turrets.qh.

Referenced by turret_tesla_firecheck(), and turret_think().

◆ autocvar_g_turrets_targetscan_mindelay

float autocvar_g_turrets_targetscan_mindelay

Definition at line 10 of file sv_turrets.qh.

Referenced by turret_tesla_firecheck(), and turret_think().

◆ g_turrets

◆ idle_aim

vector idle_aim

Definition at line 44 of file sv_turrets.qh.

Referenced by turret_findtarget(), turret_initialize(), turret_respawn(), and turret_track().

◆ pathcurrent

entity pathcurrent

◆ pathgoal

entity pathgoal

◆ target_select_time

float target_select_time

Definition at line 39 of file sv_turrets.qh.

Referenced by turret_tesla_firecheck(), and turret_think().

◆ target_validate_time

float target_validate_time

Definition at line 40 of file sv_turrets.qh.

Referenced by turret_tesla_firecheck(), and turret_think().

◆ TFL_TRACKTYPE_FLUIDINERTIA

const float TFL_TRACKTYPE_FLUIDINERTIA = 3

Definition at line 64 of file sv_turrets.qh.

Referenced by turret_track().

◆ TFL_TRACKTYPE_FLUIDPRECISE

const float TFL_TRACKTYPE_FLUIDPRECISE = 2

Definition at line 63 of file sv_turrets.qh.

Referenced by turret_track().

◆ TFL_TRACKTYPE_STEPMOTOR

const float TFL_TRACKTYPE_STEPMOTOR = 1

Definition at line 62 of file sv_turrets.qh.

Referenced by turret_initialize(), and turret_track().

◆ tur_aimpos

vector tur_aimpos

Definition at line 31 of file sv_turrets.qh.

Referenced by turret_fire(), turret_think(), and turret_track().

◆ tur_defend

entity tur_defend

Definition at line 29 of file sv_turrets.qh.

Referenced by turret_findtarget(), and turret_initialize().

◆ tur_dist_aimpos

float tur_dist_aimpos

Definition at line 35 of file sv_turrets.qh.

Referenced by turret_firecheck().

◆ tur_dist_enemy

float tur_dist_enemy

Definition at line 34 of file sv_turrets.qh.

Referenced by ewheel_move_enemy().

◆ tur_dist_impact_to_aimpos

float tur_dist_impact_to_aimpos

Definition at line 36 of file sv_turrets.qh.

Referenced by turret_firecheck().

◆ tur_head

◆ tur_impactent

entity tur_impactent

Definition at line 33 of file sv_turrets.qh.

Referenced by turret_firecheck().

◆ tur_impacttime

float tur_impacttime

Definition at line 32 of file sv_turrets.qh.

Referenced by raptor_flare_think(), and turret_fire().

◆ tur_shotdir_updated

vector tur_shotdir_updated

Definition at line 70 of file sv_turrets.qh.

◆ tur_shotorg

◆ turret_count

float turret_count

Definition at line 90 of file sv_turrets.qh.

Referenced by turret_initialize().

◆ turret_scale_aim

float turret_scale_aim

Map time control aim speed.

Definition at line 55 of file sv_turrets.qh.

◆ turret_scale_ammo

float turret_scale_ammo

Map time control ammo held and recharged.

Definition at line 53 of file sv_turrets.qh.

◆ turret_scale_damage

float turret_scale_damage

Map time control over pain inflicted.

Definition at line 47 of file sv_turrets.qh.

◆ turret_scale_health

float turret_scale_health

Map time control health.

Definition at line 57 of file sv_turrets.qh.

◆ turret_scale_range

float turret_scale_range

Map time control targetting range.

Definition at line 49 of file sv_turrets.qh.

◆ turret_scale_refire

float turret_scale_refire

Map time control refire.

Definition at line 51 of file sv_turrets.qh.

◆ turret_scale_respawn

float turret_scale_respawn

Map time control respawn time.

Definition at line 59 of file sv_turrets.qh.

◆ TURRET_TEAM

const int TURRET_TEAM = 256

Definition at line 95 of file sv_turrets.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and turret_initialize().

◆ tvt_dist

◆ tvt_tadv

vector tvt_tadv

Definition at line 114 of file sv_turrets.qh.

Referenced by turret_validate_target().

◆ tvt_thadf

float tvt_thadf

Definition at line 115 of file sv_turrets.qh.

Referenced by turret_targetscore_generic(), and turret_validate_target().

◆ tvt_thadv

vector tvt_thadv

Definition at line 113 of file sv_turrets.qh.

Referenced by turret_validate_target().

◆ volly_counter

float volly_counter

Definition at line 37 of file sv_turrets.qh.

Referenced by turret_fire(), turret_firecheck(), turret_respawn(), and turret_think().