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 #define TSF_SUSPENDED 1
32 /// Spawn a pillar model under the turret to make it look ok on uneven ground surfaces
33 #define TSF_TERRAINBASE 2
34 /// Disable builtin ammo regeneration
35 #define TSF_NO_AMMO_REGEN 4
36 /// Dont break path to chase enemys. will still fire at them if possible.
37 #define TSF_NO_PATHBREAK 8
39 #define TSL_NO_RESPAWN 16
41 /// target selection flags
42 .float target_select_flags;
43 /// target validatoin flags
44 .float target_validate_flags;
45 /// Dont select a target on its own.
46 #define TFL_TARGETSELECT_NO 2
47 /// Need line of sight
48 #define TFL_TARGETSELECT_LOS 4
49 /// Players are valid targets
50 #define TFL_TARGETSELECT_PLAYERS 8
51 /// Missiles are valid targets
52 #define TFL_TARGETSELECT_MISSILES 16
53 /// Responds to turret_trigger_target events
54 #define TFL_TARGETSELECT_TRIGGERTARGET 32
55 /// Angular limitations of turret head limits target selection
56 #define TFL_TARGETSELECT_ANGLELIMITS 64
57 /// Range limits apply in targetselection
58 #define TFL_TARGETSELECT_RANGELIMTS 128
59 /// DOnt select targets with a .team matching its own
60 #define TFL_TARGETSELECT_TEAMCHECK 256
61 /// Cant select targets on its own. needs to be triggerd or slaved.
62 #define TFL_TARGETSELECT_NOBUILTIN 512
63 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
64 #define TFL_TARGETSELECT_OWNTEAM 1024
65 /// Turrets aren't valid targets
66 #define TFL_TARGETSELECT_NOTURRETS 2048
68 #define TFL_TARGETSELECT_FOV 4096
70 #define TFL_TARGETSELECT_MISSILESONLY 8192
76 /// Go for ground, not direct hit
77 #define TFL_AIM_GROUND 2
78 /// Go for ground, not direct hit, but only if target is on ground.
79 #define TFL_AIM_GROUND2 4
80 /// Use balistic aim. FIXME: not implemented
81 #define TFL_AIM_BALISTIC 8
82 /// Try to predict target movement (does not account for gravity)
83 #define TFL_AIM_LEAD 16
84 /// Compensate for shot traveltime when lead
85 #define TFL_AIM_SHOTTIMECOMPENSATE 32
86 /// Aim slightly in front of target
87 #define TFL_AIM_INFRONT 64
88 /// Aim slightly behind target
89 #define TFL_AIM_BEHIND 128
90 /// blend real and predicted z positions. (fake bounce prediction)
91 #define TFL_AIM_ZEASE 256
92 /// Try to do real prediction of targets z pos at impact.
93 #define TFL_AIM_ZPREDICT 512
94 /// Simply aim at target's current location
95 #define TFL_AIM_SIMPLE 1024
97 /// track (turn and pitch head) flags
100 #define TFL_TRACK_NO 2
102 #define TFL_TRACK_PITCH 4
104 #define TFL_TRACK_ROT 8
106 /// How tracking is preformed
108 /// Hard angle increments. Ugly for fast turning, best accuracy.
109 #define TFL_TRACKTYPE_STEPMOTOR 1
110 /// Smoth absolute movement. Looks ok, fair accuracy.
111 #define TFL_TRACKTYPE_FLUIDPRECISE 2
112 /// Simulated inertia. "Wobbly mode" Looks kool, can mean really bad accuracy depending on how the feilds below are set
113 #define TFL_TRACKTYPE_FLUIDINERTIA 3
114 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
115 .float track_accel_pitch;
116 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
117 .float track_accel_rot;
118 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1 = only old, 0 = only new
119 .float track_blendrate;
121 /// How prefire check is preformed
122 .float firecheck_flags;
123 /// Dont kill the world
124 #define TFL_FIRECHECK_WORLD 2
125 /// Dont kill the dead
126 #define TFL_FIRECHECK_DEAD 4
127 /// Range limits apply
128 #define TFL_FIRECHECK_DISTANCES 8
129 /// Line Of Sight needs to be clear
130 #define TFL_FIRECHECK_LOS 16
131 /// Consider distance inpactpoint<->aimspot
132 #define TFL_FIRECHECK_AIMDIST 32
133 /// Consider enemy origin<->impactpoint
134 #define TFL_FIRECHECK_REALDIST 64
135 /// Consider angular diff head<->aimspot
136 #define TFL_FIRECHECK_ANGLEDIST 128
137 /// (re)consider target.team<->self.team
138 #define TFL_FIRECHECK_TEAMCECK 256
139 /// Try to avoid friendly fire
140 #define TFL_FIRECHECK_AFF 512
141 /// Own .ammo needs to be >= then own .shot_dmg
142 #define TFL_FIRECHECK_OWM_AMMO 1024
143 /// Others ammo need to be < others .ammo_max
144 #define TFL_FIRECHECK_OTHER_AMMO 2048
145 /// Check own .attack_finished_single vs time
146 #define TFL_FIRECHECK_REFIRE 4096
147 /// Move the acctual target to aimspot before tracing impact (and back after)
148 #define TFL_FIRECHECK_VERIFIED 8192
149 /// Dont do any chekcs
150 #define TFL_FIRECHECK_NO 16384
152 /// How shooting is done
155 #define TFL_SHOOT_NO 64
156 /// Fire in vollys (partial implementation through .shot_volly)
157 #define TFL_SHOOT_VOLLY 2
158 /// Always do a full volly, even if target is lost or dead. (not implemented)
159 #define TFL_SHOOT_VOLLYALWAYS 4
160 /// Loop though all valid tarters, and hit them.
161 #define TFL_SHOOT_HITALLVALID 8
162 /// Fiering makes unit loose target (after volly is done, if in volly mode)
163 #define TFL_SHOOT_CLEARTARGET 16
165 #define TFL_SHOOT_CUSTOM 32
167 /// Information aboute the units capabilities
168 .float turrcaps_flags;
169 /// No kown capabilities
170 #define TFL_TURRCAPS_NONE 0
171 /// Capable of sniping
172 #define TFL_TURRCAPS_SNIPER 2
173 /// Capable of splasdamage
174 #define TFL_TURRCAPS_RADIUSDMG 4
175 /// Has one or more cannons with zero shot traveltime
176 #define TFL_TURRCAPS_HITSCAN 8
177 /// More then one (type of) gun
178 #define TFL_TURRCAPS_MULTIGUN 16
179 /// Carries at least one guided weapon
180 #define TFL_TURRCAPS_GUIDED 32
181 /// At least one gun fiers slow projectiles
182 #define TFL_TURRCAPS_SLOWPROJ 64
183 /// At least one gun fiers medium speed projectiles
184 #define TFL_TURRCAPS_MEDPROJ 128
185 /// At least one gun fiers fast projectiles
186 #define TFL_TURRCAPS_FASTPROJ 256
187 /// At least one gun capable of damaging players
188 #define TFL_TURRCAPS_PLAYERKILL 512
189 /// At least one gun that can shoot town missiles
190 #define TFL_TURRCAPS_MISSILEKILL 1024
191 /// Has support capabilities. powerplants and sutch.
192 #define TFL_TURRCAPS_SUPPORT 2048
193 /// Proveides at least one type of ammmo
194 #define TFL_TURRCAPS_AMMOSOURCE 4096
195 /// Can recive targets from external sources
196 #define TFL_TURRCAPS_RECIVETARGETS 8192
197 /// Capable of self-transport
198 #define TFL_TURRCAPS_MOVE 16384
199 /// Will roam arround even if not chasing anyting
200 #define TFL_TURRCAPS_ROAM 32768
201 #define TFL_TURRCAPS_ISTURRET 65536
203 /// Ammo types needed and/or provided
205 /// Has and needs no ammo
206 #define TFL_AMMO_NONE 64
208 #define TFL_AMMO_ENERGY 2
210 #define TFL_AMMO_BULLETS 4
212 #define TFL_AMMO_ROCKETS 8
213 /// Regenerates ammo on its own
214 #define TFL_AMMO_RECHARGE 16
215 /// Can recive ammo from others
216 #define TFL_AMMO_RECIVE 32
218 /// How incomming damage is handeld
221 #define TFL_DMG_NO 256
223 #define TFL_DMG_YES 2
224 /// Can be damaged by teammates
225 #define TFL_DMG_TAKEFROMTEAM 4
227 #define TFL_DMG_RETALIATE 8
228 /// Target attackers, even is on own team
229 #define TFL_DMG_RETALIATEONTEAM 16
230 /// Loses target when damaged
231 #define TFL_DMG_TARGETLOSS 32
232 /// Reciving damage trows off aim (pointless atm, aim gets recalculated to fast). not implemented.
233 #define TFL_DMG_AIMSHAKE 64
234 /// Reciving damage slaps the head arround
235 #define TFL_DMG_HEADSHAKE 128
236 /// Die and stay dead.
237 #define TFL_DMG_DEATH_NORESPAWN 256
238 /// Supress std turret gibs on death
239 #define TFL_DMG_DEATH_NOGIBS 512
242 /// Spawn in teambased modes
243 #define TFL_SPAWN_TEAM 2
244 /// Spawn in FFA modes
245 #define TFL_SPAWN_FFA 4
249 * Fields used by turrets
251 /// Turrets internal ai speed
254 /// Where to point the when no target
257 /// Top part of turret
260 /// Start/respawn health
263 /// Defend this entity (or ratehr this entitys position)
269 // Aim from this point,
270 //.vector tur_aimorg;
272 /// and shoot from here. (can be non constant, think MLRS)
278 /// Predicted time the round will impact
279 .float tur_impacttime;
281 // Predicted place the round will impact
282 //.vector tur_impactpoint; // unused
284 /// What entity the aimtrace hit, if any.
285 .entity tur_impactent;
287 /// Distance to enemy
288 .float tur_dist_enemy;
290 /// Distance to aimspot
291 .float tur_dist_aimpos;
293 /// Distance impact<->aim
294 .float tur_dist_impact_to_aimpos;
296 /// Decresment counter form .shot_volly to 0.
297 .float volly_counter;
300 * Projectile/missile. its up to the individual turret implementation to
301 ** deal the damage, blow upp the missile or whatever.
303 /// Track then refireing is possible
304 //.float attack_finished; = attack_finished_single
307 /// Shots travel this fast, when appliable
311 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
313 /// If radius dmg, this is how big that radius is.
315 /// Max force exserted by round impact
317 /// < 1 = shoot # times at target (if possible)
319 /// Refire after a compleated volly.
320 .float shot_volly_refire;
322 /// Consider targets within this range
324 /// Dont consider targets closer then
325 .float target_range_min;
326 // Engage fire routine on targets within
327 //.float target_range_fire; // no practical use aymore, work with target_range insted.
328 /// Targets closer to this are prefered
329 .float target_range_optimal;
332 * The standard targetselection tries to select a target based on
333 * range, angle offset, target type, "is old target"
334 * Thise biases will allow score scaling to (dis)favor diffrent targets
336 /// (dis)Favor best range this mutch
337 .float target_select_rangebias;
338 /// (dis)Favor targeting my old enemy this mutch
339 .float target_select_samebias;
340 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
341 .float target_select_anglebias;
342 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
343 .float target_select_missilebias;
344 /// (dis)Favot living players (-1 to diable targeting compleatly)
345 .float target_select_playerbias;
347 //.float target_select_fov;
348 /// Last thimestamp this surret aquierd a valid target
349 .float target_select_time;
352 * Aim refers to real aiming, not gun pos (thats done by track)
354 /// Maximum offset between impact and aim spot to fire
355 .float aim_firetolerance_dist;
356 // Maximum angular offset between head and aimspot to fire
357 //.float aim_firetolerance_angle;
358 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
360 /// cant aim higher/lower then this
362 /// I cant rotate more then this
365 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
366 /// Staring & current ammo
368 /// Regenerate this mutch ammo (per second)
369 .float ammo_recharge;
370 /// Max amount of ammo i can hold
374 // Uncomment below to enable various debug output.
375 //#define TURRET_DEBUG
376 //#define TURRET_DEBUG_TARGETVALIDATE
377 //#define TURRET_DEBUG_TARGETSELECT
380 .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.
381 .float tur_dbg_dmg_t_f; // Total damage spent
382 .float tur_dbg_start; // When did i go online?
383 .float tur_dbg_tmr1; // timer for random use
384 .float tur_dbg_tmr2; // timer for random use
385 .float tur_dbg_tmr3; // timer for random use
386 .vector tur_dbg_rvec; // Random vector, mainly for coloruing stuff'
392 /// Prefire checks and sutch
396 /// implements the actual fiering
397 .void() turret_firefunc;
398 /// prefire checks go here. return 1 to go bang, 0 not to.
399 .float() turret_firecheckfunc;
400 // Execure BEFORE main ai loop. return 0 to cancel any following proccessing.
401 //.float() turret_prethink;
402 /// Execure AFTER main AI loop
403 .void() turret_postthink;
406 .float(entity e_target,entity e_sender) turret_addtarget;
408 //.float call_diehook;
409 //.float call_respwnhook;
410 .void() turret_diehook;
411 .void() turret_respawnhook;
417 #define TEH_RESPAWN 16
420 #define TEH_SELECT 128
421 .float(float event_id) turret_eventhook;
425 * Some turrets need other aimsystems then other.
426 * This should return the place to aim at, not acctualy turn or
429 * use turret_stdproc_aim* or Make your own.
430 * Make sure you update tur_enemy_dist and tur_enemy_adist
431 * with the apropriate info, if you do.
435 // function used to aim, usualy turret_stdproc_aim_generic
436 //.vector() turret_aim;
439 * This is where the acctual turret turning should take place
440 * Use turret_stdproc_track or make your own.
443 // Function used to turn and pitch the .tur_head usualy turret_stdproc_track
444 //.void() turret_track;
447 * Target selection, preferably but not nessesarely
448 * return a normalized result.
450 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
451 .float(entity e_turret, entity e_target) turret_score_target;
454 * Damage, death and respawn.
456 //void turret_gibs_precash();
457 // generalized so save mem (on fields)
458 // Function to handle incomming damage. usualy turret_stdproc_damage
459 //.void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce) turret_damagefunc;
460 // Function to handle the event of death. usualy turret_stdproc_die
461 //.void() turret_diefunc;
462 // Function that handles rebirth. usualy turret_stdproc_respawn
463 //.void() turret_spawnfunc;
466 * Stuff to plug into requierd but unused callbacks.
469 //float turret_stdproc_true();
471 //float turret_stdproc_false();
472 /// Always return nothing at all
473 //void turret_stdproc_nothing();
478 // noting uses the following atm.
479 // "closeer is beter" selection
480 //float turret_stdproc_targetscore_close(entity e_turret, entity e_target);
481 // "further is beter" selection
482 //float turret_stdproc_targetscore_far(entity e_turret, entity e_target);
483 // only target_range_optimal
484 //float turret_stdproc_targetscore_optimal(entity e_turret, entity e_target);
486 //float turret_stdproc_targetscore_defend(entity e_turret, entity e_target);
487 /// Generic fairly smart bias-aware target selection.
488 float turret_stdproc_targetscore_generic(entity e_turret, entity e_target);
489 /// Experimental supportunits targetselector
490 float turret_stdproc_targetscore_support(entity e_turret,entity e_target);
495 /// Generic aimer guided by self.aim_flags
496 vector turret_stdproc_aim_generic()
497 // Straight line, current location
498 //vector turret_stdproc_aim_simple()
501 * Turret turning & pitch
503 /// Tries to line up the turret head with the aimpos
504 void turret_stdproc_track();
506 /// Generic damage handeling. blows up the turret when health <= 0
507 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
508 /// Spawns a explotion, does some damage & trows bits arround.
509 void turret_stdproc_die();
510 /// reassembles the turret.
511 void turret_stdproc_respawn();
513 /// Evaluate target validity
514 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
515 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
517 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
519 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
521 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
523 /// Distance. updated by a sucsessfull call to turret_validate_target
526 /// updates aim org, shot org, shot dir and enemy org for selected turret
527 void turret_do_updates(entity e_turret);
528 //.vector tur_aimorg_updated; // creates to much aim issues. using tur_shotorg_updated insted.
529 //.vector tur_shotorg_updated; // DP8815 fixes gettaginfo, no longer needed.
530 .vector tur_shotdir_updated;
532 void turrets_precash();
536 #endif // TTURRETS_ENABLED