1 // Comment out below to skip turrets
2 #define TTURRETS_ENABLED
4 #ifdef TTURRETS_ENABLED
6 //#message "with tZork turrets"
10 vector real_origin(entity ent);
12 /// Map time control over pain inflicted
13 .float turret_scale_damage;
14 /// Map time control targetting range
15 .float turret_scale_range;
16 /// Map time control refire
17 .float turret_scale_refire;
18 /// Map time control ammo held and recharged
19 .float turret_scale_ammo;
20 /// Map time control aim speed
21 .float turret_scale_aim;
22 /// Map time control health
23 .float turret_scale_health;
24 /// Map time control respawn time
25 .float turret_scale_respawn;
27 /// Used for cvar reloading
28 .string cvar_basename;
31 const float TSF_SUSPENDED = 1;
32 /// Spawn a pillar model under the turret to make it look ok on uneven ground surfaces
33 const float TSF_TERRAINBASE = 2;
34 /// Disable builtin ammo regeneration
35 const float TSF_NO_AMMO_REGEN = 4;
36 /// Dont break path to chase enemys. will still fire at them if possible.
37 const float TSF_NO_PATHBREAK = 8;
39 const float TSL_NO_RESPAWN = 16;
40 /// Let this turret roam when idle.
41 const float TSL_ROAM = 32;
43 /// target selection flags
44 .float target_select_flags;
45 /// target validatoin flags
46 .float target_validate_flags;
47 /// Dont select a target on its own.
48 const float TFL_TARGETSELECT_NO = 2;
49 /// Need line of sight
50 const float TFL_TARGETSELECT_LOS = 4;
51 /// Players are valid targets
52 const float TFL_TARGETSELECT_PLAYERS = 8;
53 /// Missiles are valid targets
54 const float TFL_TARGETSELECT_MISSILES = 16;
55 /// Responds to turret_trigger_target events
56 const float TFL_TARGETSELECT_TRIGGERTARGET = 32;
57 /// Angular limitations of turret head limits target selection
58 const float TFL_TARGETSELECT_ANGLELIMITS = 64;
59 /// Range limits apply in targetselection
60 const float TFL_TARGETSELECT_RANGELIMTS = 128;
61 /// DOnt select targets with a .team matching its own
62 const float TFL_TARGETSELECT_TEAMCHECK = 256;
63 /// Cant select targets on its own. needs to be triggerd or slaved.
64 const float TFL_TARGETSELECT_NOBUILTIN = 512;
65 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
66 const float TFL_TARGETSELECT_OWNTEAM = 1024;
67 /// Turrets aren't valid targets
68 const float TFL_TARGETSELECT_NOTURRETS = 2048;
70 const float TFL_TARGETSELECT_FOV = 4096;
72 const float TFL_TARGETSELECT_MISSILESONLY = 8192;
77 const float TFL_AIM_NO = 1;
78 /// Go for ground, not direct hit, but only if target is on ground.
79 const float TFL_AIM_GROUNDGROUND = 2;
80 /// Try to predict target movement (does not account for gravity)
81 const float TFL_AIM_LEAD = 4;
82 /// Compensate for shot traveltime when lead
83 const float TFL_AIM_SHOTTIMECOMPENSATE = 8;
84 /// Try to do real prediction of targets z pos at impact.
85 const float TFL_AIM_ZPREDICT = 16;
86 /// Simply aim at target's current location
87 const float TFL_AIM_SIMPLE = 32;
89 /// track (turn and pitch head) flags
92 const float TFL_TRACK_NO = 2;
94 const float TFL_TRACK_PITCH = 4;
96 const float TFL_TRACK_ROT = 8;
98 /// How tracking is preformed
100 /// Hard angle increments. Ugly for fast turning, best accuracy.
101 const float TFL_TRACKTYPE_STEPMOTOR = 1;
102 /// Smoth absolute movement. Looks ok, fair accuracy.
103 const float TFL_TRACKTYPE_FLUIDPRECISE = 2;
104 /// Simulated inertia. "Wobbly mode" Looks kool, can mean really bad accuracy depending on how the fields below are set
105 const float TFL_TRACKTYPE_FLUIDINERTIA = 3;
106 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
107 .float track_accel_pitch;
108 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
109 .float track_accel_rot;
110 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1 = only old, 0 = only new
111 .float track_blendrate;
113 /// How prefire check is preformed
114 .float firecheck_flags;
115 /// Dont kill the dead
116 const float TFL_FIRECHECK_DEAD = 4;
117 /// Range limits apply
118 const float TFL_FIRECHECK_DISTANCES = 8;
119 /// Line Of Sight needs to be clear
120 const float TFL_FIRECHECK_LOS = 16;
121 /// Consider distance inpactpoint<->aimspot
122 const float TFL_FIRECHECK_AIMDIST = 32;
123 /// Consider enemy origin<->impactpoint
124 const float TFL_FIRECHECK_REALDIST = 64;
125 /// Consider angular diff head<->aimspot
126 const float TFL_FIRECHECK_ANGLEDIST = 128;
127 /// (re)consider target.team<->self.team
128 const float TFL_FIRECHECK_TEAMCECK = 256;
129 /// Try to avoid friendly fire
130 const float TFL_FIRECHECK_AFF = 512;
131 /// Own .ammo needs to be >= then own .shot_dmg
132 const float TFL_FIRECHECK_OWM_AMMO = 1024;
133 /// Others ammo need to be < others .ammo_max
134 const float TFL_FIRECHECK_OTHER_AMMO = 2048;
135 /// Check own .attack_finished_single vs time
136 const float TFL_FIRECHECK_REFIRE = 4096;
137 /// Move the acctual target to aimspot before tracing impact (and back after)
138 //#define TFL_FIRECHECK_VERIFIED 8192
139 /// Dont do any chekcs
140 const float TFL_FIRECHECK_NO = 16384;
142 /// How shooting is done
145 const float TFL_SHOOT_NO = 64;
146 /// Fire in vollys (partial implementation through .shot_volly)
147 const float TFL_SHOOT_VOLLY = 2;
148 /// Always do a full volly, even if target is lost or dead. (not implemented)
149 const float TFL_SHOOT_VOLLYALWAYS = 4;
150 /// Loop though all valid tarters, and hit them.
151 const float TFL_SHOOT_HITALLVALID = 8;
152 /// Fiering makes unit loose target (after volly is done, if in volly mode)
153 const float TFL_SHOOT_CLEARTARGET = 16;
155 const float TFL_SHOOT_CUSTOM = 32;
157 /// Information aboute the units capabilities
158 .float turrcaps_flags;
159 /// No kown capabilities
160 const float TFL_TURRCAPS_NONE = 0;
161 /// Capable of sniping
162 const float TFL_TURRCAPS_SNIPER = 2;
163 /// Capable of splasdamage
164 const float TFL_TURRCAPS_RADIUSDMG = 4;
165 /// Has one or more cannons with zero shot traveltime
166 const float TFL_TURRCAPS_HITSCAN = 8;
167 /// More then one (type of) gun
168 const float TFL_TURRCAPS_MULTIGUN = 16;
169 /// Carries at least one guided weapon
170 const float TFL_TURRCAPS_GUIDED = 32;
171 /// At least one gun fiers slow projectiles
172 const float TFL_TURRCAPS_SLOWPROJ = 64;
173 /// At least one gun fiers medium speed projectiles
174 const float TFL_TURRCAPS_MEDPROJ = 128;
175 /// At least one gun fiers fast projectiles
176 const float TFL_TURRCAPS_FASTPROJ = 256;
177 /// At least one gun capable of damaging players
178 const float TFL_TURRCAPS_PLAYERKILL = 512;
179 /// At least one gun that can shoot town missiles
180 const float TFL_TURRCAPS_MISSILEKILL = 1024;
181 /// Has support capabilities. powerplants and sutch.
182 const float TFL_TURRCAPS_SUPPORT = 2048;
183 /// Proveides at least one type of ammmo
184 const float TFL_TURRCAPS_AMMOSOURCE = 4096;
185 /// Can recive targets from external sources
186 const float TFL_TURRCAPS_RECIVETARGETS = 8192;
187 /// Capable of self-transport
188 const float TFL_TURRCAPS_MOVE = 16384;
189 /// Will roam arround even if not chasing anyting
190 const float TFL_TURRCAPS_ROAM = 32768;
191 const float TFL_TURRCAPS_ISTURRET = 65536;
193 /// Ammo types needed and/or provided
195 #define ammo_flags currentammo
196 /// Has and needs no ammo
197 const float TFL_AMMO_NONE = 64;
199 const float TFL_AMMO_ENERGY = 2;
201 const float TFL_AMMO_BULLETS = 4;
203 const float TFL_AMMO_ROCKETS = 8;
204 /// Regenerates ammo on its own
205 const float TFL_AMMO_RECHARGE = 16;
206 /// Can recive ammo from others
207 const float TFL_AMMO_RECIVE = 32;
209 /// How incomming damage is handeld
212 const float TFL_DMG_NO = 256;
214 const float TFL_DMG_YES = 2;
215 /// Can be damaged by teammates
216 const float TFL_DMG_TAKEFROMTEAM = 4;
218 const float TFL_DMG_RETALIATE = 8;
219 /// Target attackers, even is on own team
220 const float TFL_DMG_RETALIATEONTEAM = 16;
221 /// Loses target when damaged
222 const float TFL_DMG_TARGETLOSS = 32;
223 /// Reciving damage trows off aim (pointless atm, aim gets recalculated to fast). not implemented.
224 const float TFL_DMG_AIMSHAKE = 64;
225 /// Reciving damage slaps the head arround
226 const float TFL_DMG_HEADSHAKE = 128;
227 /// Die and stay dead.
228 const float TFL_DMG_DEATH_NORESPAWN = 256;
231 /// Spawn in teambased modes
232 const float TFL_SPAWN_TEAM = 2;
233 /// Spawn in FFA modes
234 const float TFL_SPAWN_FFA = 4;
238 * Fields used by turrets
240 /// Turrets internal ai speed
243 /// Where to point the when no target
246 /// Top part of turret
249 /// Start/respawn health
252 /// Defend this entity (or ratehr this entitys position)
255 /// and shoot from here. (can be non constant, think MLRS)
261 /// Predicted time the round will impact
262 .float tur_impacttime;
264 // Predicted place the round will impact
265 //.vector tur_impactpoint; // unused
267 /// What entity the aimtrace hit, if any.
268 .entity tur_impactent;
270 /// Distance to enemy
271 .float tur_dist_enemy;
273 /// Distance to aimspot
274 .float tur_dist_aimpos;
276 /// Distance impact<->aim
277 .float tur_dist_impact_to_aimpos;
279 /// Decresment counter form .shot_volly to 0.
280 .float volly_counter;
283 * Projectile/missile. its up to the individual turret implementation to
284 ** deal the damage, blow upp the missile or whatever.
286 /// Track then refireing is possible
287 //.float attack_finished; = attack_finished_single
290 /// Shots travel this fast, when appliable
294 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
296 /// If radius dmg, this is how big that radius is.
298 /// Max force exserted by round impact
300 /// < 1 = shoot # times at target (if possible)
302 /// Refire after a compleated volly.
303 .float shot_volly_refire;
305 /// Consider targets within this range
307 /// Dont consider targets closer then
308 .float target_range_min;
309 /// Targets closer to this are prefered
310 .float target_range_optimal;
313 * The standard targetselection tries to select a target based on
314 * range, angle offset, target type, "is old target"
315 * Thise biases will allow score scaling to (dis)favor diffrent targets
317 /// (dis)Favor best range this mutch
318 .float target_select_rangebias;
319 /// (dis)Favor targeting my old enemy this mutch
320 .float target_select_samebias;
321 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
322 .float target_select_anglebias;
323 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
324 .float target_select_missilebias;
325 /// (dis)Favot living players (-1 to diable targeting compleatly)
326 .float target_select_playerbias;
328 //.float target_select_fov;
329 /// Last timestamp this turret aquierd a valid target
330 .float target_select_time;
331 /// Throttle re-validation of current target
332 .float target_validate_time;
334 * Aim refers to real aiming, not gun pos (thats done by track)
336 /// Maximum offset between impact and aim spot to fire
337 .float aim_firetolerance_dist;
338 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
340 /// cant aim higher/lower then this
342 /// I cant rotate more then this
345 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
346 /// Staring & current ammo
348 /// Regenerate this mutch ammo (per second)
349 .float ammo_recharge;
350 /// Max amount of ammo i can hold
354 // Uncomment below to enable various debug output.
355 //#define TURRET_DEBUG
356 //#define TURRET_DEBUG_TARGETVALIDATE
357 //#define TURRET_DEBUG_TARGETSELECT
360 .float tur_dbg_dmg_t_h; // Total dmg that hit something (can be more then tur_dbg_dmg_t_f since it should count radius dmg.
361 .float tur_dbg_dmg_t_f; // Total damage spent
362 .float tur_dbg_start; // When did i go online?
363 .float tur_dbg_tmr1; // timer for random use
364 .float tur_dbg_tmr2; // timer for random use
365 .float tur_dbg_tmr3; // timer for random use
366 .vector tur_dbg_rvec; // Random vector, mainly for coloruing stuff'
372 /// Prefire checks and sutch
376 /// implements the actual fiering
377 .void() turret_firefunc;
378 /// prefire checks go here. return 1 to go bang, 0 not to.
379 .float() turret_firecheckfunc;
380 /// Execure AFTER main AI loop
381 .void() turret_postthink;
384 .float(entity e_target,entity e_sender) turret_addtarget;
386 .void() turret_diehook;
387 .void() turret_respawnhook;
390 * Target selection, preferably but not nessesarely
391 * return a normalized result.
393 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
394 .float(entity _turret, entity _target) turret_score_target;
399 /// Generic, fairly smart, bias-aware target selection.
400 float turret_stdproc_targetscore_generic(entity _turret, entity _target);
401 /// Experimental supportunits targetselector
402 float turret_stdproc_targetscore_support(entity _turret,entity _target);
407 /// Generic aimer guided by self.aim_flags
408 vector turret_stdproc_aim_generic();
411 * Turret turning & pitch
413 /// Tries to line up the turret head with the aimpos
414 void turret_stdproc_track();
416 /// Generic damage handeling. blows up the turret when health <= 0
417 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
418 /// Spawns a explotion, does some damage & trows bits arround.
419 void turret_stdproc_die();
420 /// reassembles the turret.
421 void turret_stdproc_respawn();
423 /// Evaluate target validity
424 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
425 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
427 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
429 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
431 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
433 /// Distance. updated by a sucsessfull call to turret_validate_target
436 /// updates aim org, shot org, shot dir and enemy org for selected turret
437 void turret_do_updates(entity e_turret);
438 .vector tur_shotdir_updated;
440 void turrets_precash();
445 const int TID_COMMON = 1;
446 const int TID_EWHEEL = 2;
447 const int TID_FLAC = 3;
448 const int TID_FUSION = 4;
449 const int TID_HELLION = 5;
450 const int TID_HK = 6;
451 const int TID_MACHINEGUN = 7;
452 const int TID_MLRS = 8;
453 const int TID_PHASER = 9;
454 const int TID_PLASMA = 10;
455 const int TID_PLASMA_DUAL = 11;
456 const int TID_TESLA = 12;
457 const int TID_WALKER = 13;
458 const int TID_LAST = 13;
460 const int TNSF_UPDATE = 2;
461 const int TNSF_STATUS = 4;
462 const int TNSF_SETUP = 8;
463 const int TNSF_ANG = 16;
464 const int TNSF_AVEL = 32;
465 const int TNSF_MOVE = 64;
466 .float anim_start_time;
467 const int TNSF_ANIM = 128;
469 const int TNSF_FULL_UPDATE = 16777215;
471 #endif // TTURRETS_ENABLED