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 /// 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 /// Targets closer to this are prefered
324 .float target_range_optimal;
327 * The standard targetselection tries to select a target based on
328 * range, angle offset, target type, "is old target"
329 * Thise biases will allow score scaling to (dis)favor diffrent targets
331 /// (dis)Favor best range this mutch
332 .float target_select_rangebias;
333 /// (dis)Favor targeting my old enemy this mutch
334 .float target_select_samebias;
335 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
336 .float target_select_anglebias;
337 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
338 .float target_select_missilebias;
339 /// (dis)Favot living players (-1 to diable targeting compleatly)
340 .float target_select_playerbias;
342 //.float target_select_fov;
343 /// Last thimestamp this surret aquierd a valid target
344 .float target_select_time;
347 * Aim refers to real aiming, not gun pos (thats done by track)
349 /// Maximum offset between impact and aim spot to fire
350 .float aim_firetolerance_dist;
351 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
353 /// cant aim higher/lower then this
355 /// I cant rotate more then this
358 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
359 /// Staring & current ammo
361 /// Regenerate this mutch ammo (per second)
362 .float ammo_recharge;
363 /// Max amount of ammo i can hold
367 // Uncomment below to enable various debug output.
368 //#define TURRET_DEBUG
369 //#define TURRET_DEBUG_TARGETVALIDATE
370 //#define TURRET_DEBUG_TARGETSELECT
373 .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.
374 .float tur_dbg_dmg_t_f; // Total damage spent
375 .float tur_dbg_start; // When did i go online?
376 .float tur_dbg_tmr1; // timer for random use
377 .float tur_dbg_tmr2; // timer for random use
378 .float tur_dbg_tmr3; // timer for random use
379 .vector tur_dbg_rvec; // Random vector, mainly for coloruing stuff'
385 /// Prefire checks and sutch
389 /// implements the actual fiering
390 .void() turret_firefunc;
391 /// prefire checks go here. return 1 to go bang, 0 not to.
392 .float() turret_firecheckfunc;
393 /// Execure AFTER main AI loop
394 .void() turret_postthink;
397 .float(entity e_target,entity e_sender) turret_addtarget;
399 .void() turret_diehook;
400 .void() turret_respawnhook;
406 #define TEH_RESPAWN 16
409 #define TEH_SELECT 128
410 .float(float event_id) turret_eventhook;
415 * Target selection, preferably but not nessesarely
416 * return a normalized result.
418 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
419 .float(entity e_turret, entity e_target) turret_score_target;
425 /// Generic, fairly smart, bias-aware target selection.
426 float turret_stdproc_targetscore_generic(entity e_turret, entity e_target);
427 /// Experimental supportunits targetselector
428 float turret_stdproc_targetscore_support(entity e_turret,entity e_target);
433 /// Generic aimer guided by self.aim_flags
434 vector turret_stdproc_aim_generic();
437 * Turret turning & pitch
439 /// Tries to line up the turret head with the aimpos
440 void turret_stdproc_track();
442 /// Generic damage handeling. blows up the turret when health <= 0
443 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
444 /// Spawns a explotion, does some damage & trows bits arround.
445 void turret_stdproc_die();
446 /// reassembles the turret.
447 void turret_stdproc_respawn();
449 /// Evaluate target validity
450 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
451 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
453 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
455 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
457 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
459 /// Distance. updated by a sucsessfull call to turret_validate_target
462 /// updates aim org, shot org, shot dir and enemy org for selected turret
463 void turret_do_updates(entity e_turret);
464 .vector tur_shotdir_updated;
466 void turrets_precash();
470 #endif // TTURRETS_ENABLED