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.
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 114 of file sv_turrets.qh.

114{ g_turrets = IL_NEW(); }
#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 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
vector
Definition self.qh:92
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_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 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}
float turret_tag_fire_update(entity this)
Definition util.qc:9
vector real_origin(entity ent)
Definition util.qc:148
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 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 time
#define NULL
Definition post.qh:14
entity enemy
Definition sv_ctf.qh:153
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
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
int shoot_flags
Definition turret.qh:126
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
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_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 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
#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.
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
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_setup()
(BOTH) setup turret data
Definition turret.qh:33
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
const float SOLID_NOT
float effects
float nextthink
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
solid
Definition ent_cs.qc:165
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_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:69
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:87
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
bool teamplay
Definition teams.qh:59
string target
Definition triggers.qh:55
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_AIM_LEAD
Definition turret.qh:99
const int TFL_TARGETSELECT_PLAYERS
Definition turret.qh:82
const int TFL_AIM_SPLASH
Definition turret.qh:98
int track_flags
Definition turret.qh:105
const int TUR_FLAG_PLAYER
Definition turret.qh:145
int turret_flags
Definition turret.qh:135
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_AIM_SHOTTIMECOMPENSATE
Definition turret.qh:100
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
int damage_flags
Definition turret.qh:164
const int TFL_DMG_DEATH_NORESPAWN
Definition turret.qh:173
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
int aim_flags
Definition turret.qh:96
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_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
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
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 setthink(e, f)
#define settouch(e, f)
Definition self.qh:73
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 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}
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:981
#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 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
vector origin
float EF_LOWPRECISION
int SendFlags
Definition net.qh:118
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:193
#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 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_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
#define angleofs(from, to)
Definition angle.qc:90
ERASEABLE vector shortangle_vxy(vector ang1, vector ang2)
Definition angle.qc:58
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_CLIENT(s)
Definition player.qh:242
float checkpvs(vector viewpos, entity viewee)
#define LOG_TRACE(...)
Definition log.qh:76
vector tvt_thadv
float tvt_thadf
vector tvt_tadv
float tvt_dist
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_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 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:191

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.

◆ tvt_dist

◆ tvt_tadv

vector tvt_tadv

Definition at line 109 of file sv_turrets.qh.

Referenced by turret_validate_target().

◆ tvt_thadf

float tvt_thadf

Definition at line 110 of file sv_turrets.qh.

Referenced by turret_targetscore_generic(), and turret_validate_target().

◆ tvt_thadv

vector tvt_thadv

Definition at line 108 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().