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