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