1 // Comment out below to skip turrets
\r
2 #define TTURRETS_ENABLED
\r
4 #ifdef TTURRETS_ENABLED
\r
6 #message "with tZork turrets rc2"
\r
8 vector real_origin(entity ent);
\r
10 /// target selection flags
\r
11 .float target_select_flags;
\r
12 .float target_validate_flags;
\r
13 /// Dont select a target on its own.
\r
14 #define TFL_TARGETSELECT_NO 1024
\r
15 /// Need line of sight
\r
16 #define TFL_TARGETSELECT_LOS 2
\r
17 /// Players are valid targets
\r
18 #define TFL_TARGETSELECT_PLAYERS 4
\r
19 /// Missiles are valid targets
\r
20 #define TFL_TARGETSELECT_MISSILES 8
\r
21 /// Responds to turret_trigger_target events
\r
22 #define TFL_TARGETSELECT_TRIGGERTARGET 16
\r
23 /// Angular limitations of turret head limits target selection
\r
24 #define TFL_TARGETSELECT_ANGLELIMITS 32
\r
25 /// Range limits apply in targetselection
\r
26 #define TFL_TARGETSELECT_RANGELIMTS 64
\r
27 /// DOnt select targets with a .team matching its own
\r
28 #define TFL_TARGETSELECT_TEAMCHECK 4096
\r
29 /// Cant select targets on its own. needs to be triggerd or slaved.
\r
30 #define TFL_TARGETSELECT_NOBUILTIN 256
\r
31 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
\r
32 #define TFL_TARGETSELECT_OWNTEAM 2048
\r
33 /// Turrets aren't valid targets
\r
34 #define TFL_TARGETSELECT_NOTURRETS 128
\r
39 #define TFL_AIM_NO 1
\r
40 /// Go for ground, not direct hit
\r
41 #define TFL_AIM_GROUND 2
\r
42 /// Go for ground, not direct hit if target is on ground too
\r
43 #define TFL_AIM_GROUND2 4
\r
44 /// Use balistic aim (not implemented)
\r
45 #define TFL_AIM_BALISTIC 8
\r
46 /// Try to predict target movement (does not account for gravity)
\r
47 #define TFL_AIM_LEAD 16
\r
48 /// Compensate for shot traveltime when lead
\r
49 #define TFL_AIM_SHOTTIMECOMPENSATE 32
\r
50 /// Aim slightly in front of target
\r
51 #define TFL_AIM_INFRONT 64
\r
52 /// Aim slightly behind target
\r
53 #define TFL_AIM_BEHIND 128
\r
54 /// blend real and predicted z positions. (fake bounce prediction)
\r
55 #define TFL_AIM_ZEASE 256
\r
56 /// Try to do real prediction of targets z pos at impact.
\r
57 //#define TFL_AIM_ZPREDICT 256
\r
58 /// Just poitn at target's current location
\r
59 #define TFL_AIM_SIMPLE 512
\r
61 /// track (turn and pitch head) flags
\r
64 #define TFL_TRACK_NO 2
\r
66 #define TFL_TRACK_PITCH 4
\r
68 #define TFL_TRACK_ROT 8
\r
70 /// How tracking is preformed
\r
72 /// Hard angle increments. Ugly for fast turning, best accuracy.
\r
73 #define TFL_TRACKTYPE_STEPMOTOR 1
\r
74 /// Smoth absolute movement. Looks ok, fair accuracy.
\r
75 #define TFL_TRACKTYPE_FLUIDPRECISE 2
\r
76 /// Simulated inertia. "Wobbly mode" Looks kool, can mean terrible accuracy depending on how the feilds below are set
\r
77 #define TFL_TRACKTYPE_FLUIDINERTIA 3
\r
78 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
\r
79 .float track_accel_pitch;
\r
80 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
\r
81 .float track_accel_rot;
\r
82 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1 = only old, 0 = only new
\r
83 .float track_blendrate;
\r
85 /// How prefire check is preformed
\r
86 .float firecheck_flags;
\r
87 /// Dont do any chekcs
\r
88 #define TFL_FIRECHECK_NO 8192
\r
89 /// Dont kill the world
\r
90 #define TFL_FIRECHECK_WORLD 2
\r
91 /// Dont kill the dead
\r
92 #define TFL_FIRECHECK_DEAD 4
\r
93 /// Range limits apply
\r
94 #define TFL_FIRECHECK_DISTANCES 8
\r
95 /// Line Of Sight needs to be clear
\r
96 #define TFL_FIRECHECK_LOS 16
\r
97 /// Consider distance inpactpoint<->aimspot
\r
98 #define TFL_FIRECHECK_AIMDIST 32
\r
99 /// Consider enemy origin<->impactpoint
\r
100 #define TFL_FIRECHECK_REALDIST 64
\r
101 /// Consider angular diff head<->aimspot
\r
102 #define TFL_FIRECHECK_ANGLEDIST 128
\r
103 /// (re)consider target.team<->self.team
\r
104 #define TFL_FIRECHECK_TEAMCECK 256
\r
105 /// Try to avoid friendly fire
\r
106 #define TFL_FIRECHECK_AFF 512
\r
107 /// Own .ammo needs to be >= then own .shot_dmg
\r
108 #define TFL_FIRECHECK_OWM_AMMO 1024
\r
109 /// Others ammo need to be < others .ammo_max
\r
110 #define TFL_FIRECHECK_OTHER_AMMO 2048
\r
111 /// Check own .attack_finished_single vs time
\r
112 #define TFL_FIRECHECK_REFIRE 4096
\r
114 /// How shooting is done
\r
115 .float shoot_flags;
\r
117 #define TFL_SHOOT_NO 64
\r
118 /// Fire in vollys (partial implementation through .shot_volly)
\r
119 #define TFL_SHOOT_VOLLY 2
\r
120 /// Always do a full volly, even if target is lost or dead. (not implemented)
\r
121 #define TFL_SHOOT_VOLLYALWAYS 4
\r
122 /// Loop though all valid tarters, and hit them.
\r
123 #define TFL_SHOOT_HITALLVALID 8
\r
124 /// Fiering makes unit loose target (after volly is done, if in volly mode)
\r
125 #define TFL_SHOOT_CLEARTARGET 16
\r
126 ///Custom shooting;
\r
127 #define TFL_SHOOT_CUSTOM 32
\r
129 /// Information aboute the units capabilities
\r
130 .float turrcaps_flags;
\r
131 /// No kown capabilities
\r
132 #define TFL_TURRCAPS_NONE 0
\r
133 /// Capable of sniping
\r
134 #define TFL_TURRCAPS_SNIPER 2
\r
135 /// Capable of splasdamage
\r
136 #define TFL_TURRCAPS_RADIUSDMG 4
\r
137 /// Has one or more cannons with zero shot traveltime
\r
138 #define TFL_TURRCAPS_HITSCAN 8
\r
139 /// More then one (type of) gun
\r
140 #define TFL_TURRCAPS_MULTIGUN 16
\r
141 /// Carries at least one guided weapon
\r
142 #define TFL_TURRCAPS_GUIDED 32
\r
143 /// At least one gun fiers slow projectiles
\r
144 #define TFL_TURRCAPS_SLOWPROJ 64
\r
145 /// At least one gun fiers medium speed projectiles
\r
146 #define TFL_TURRCAPS_MEDPROJ 128
\r
147 /// At least one gun fiers fast projectiles
\r
148 #define TFL_TURRCAPS_FASTPROJ 256
\r
149 /// At least one gun capable of damaging players
\r
150 #define TFL_TURRCAPS_PLAYERKILL 512
\r
151 /// At least one gun that can shoot town missiles
\r
152 #define TFL_TURRCAPS_MISSILEKILL 1024
\r
153 /// Has support capabilities. powerplants and sutch.
\r
154 #define TFL_TURRCAPS_SUPPORT 2048
\r
155 /// Proveides at least one type of ammmo
\r
156 #define TFL_TURRCAPS_AMMOSOURCE 4096
\r
157 /// Can recive targets from external sources
\r
158 #define TFL_TURRCAPS_RECIVETARGETS 8192
\r
159 /// Capable of self-transport
\r
160 #define TFL_TURRCAPS_MOVE 16384
\r
161 /// Will roam arround even if not chasing anyting
\r
162 #define TFL_TURRCAPS_ROAM 32768
\r
163 #define TFL_TURRCAPS_LINKED 65536
\r
165 /// Ammo types needed and/or provided
\r
167 /// Has and needs no ammo
\r
168 #define TFL_AMMO_NONE 64
\r
170 #define TFL_AMMO_ENERGY 2
\r
172 #define TFL_AMMO_BULLETS 4
\r
173 /// Uses explosives
\r
174 #define TFL_AMMO_ROCKETS 8
\r
175 /// Regenerates ammo on its own
\r
176 #define TFL_AMMO_RECHARGE 16
\r
177 /// Can recive ammo from others
\r
178 #define TFL_AMMO_RECIVE 32
\r
180 /// How incomming damage is handeld
\r
181 .float damage_flags;
\r
183 #define TFL_DMG_NO 256
\r
185 #define TFL_DMG_YES 2
\r
186 /// Can be damaged by teammates
\r
187 #define TFL_DMG_TAKEFROMTEAM 4
\r
188 /// Traget attackers
\r
189 #define TFL_DMG_RETALIATE 8
\r
190 /// Target attackers, even is on own team
\r
191 #define TFL_DMG_RETALIATEONTEAM 16
\r
192 /// Loses target when damaged
\r
193 #define TFL_DMG_TARGETLOSS 32
\r
194 /// Reciving damage trows off aim
\r
195 #define TFL_DMG_AIMSHAKE 64
\r
196 /// Reciving damage slaps the head arround
\r
197 #define TFL_DMG_HEADSHAKE 128
\r
200 /// Spawn in teambased modes
\r
201 #define TFL_SPAWN_TEAM 2
\r
202 /// Spawn in FFA modes
\r
203 #define TFL_SPAWN_FFA 4
\r
204 /// Respawn after death
\r
205 #define TFL_SPAWN_RESPAWN 8
\r
208 * Fields commnly used by turrets
\r
210 /// Turrets internal ai speed
\r
212 /// Where to point the head when no target
\r
214 /// Top part of turret
\r
216 /// Start/respawn health
\r
218 /// Defend this entity (or ratehr this entitys position)
\r
219 .entity tur_defend;
\r
222 /// Aim from this point,
\r
223 .vector tur_aimorg;
\r
224 /// and shoot from here. (could be non constant, think MLRS)
\r
225 .vector tur_shotorg;
\r
226 /// Aim at this spot
\r
227 .vector tur_aimpos;
\r
228 /// Predicted time the round will impact
\r
229 .float tur_impacttime;
\r
230 /// Predicted place the round will impact
\r
231 .vector tur_impactpoint;
\r
232 /// What entity the aimtrace hit, if any.
\r
233 .entity tur_impactent;
\r
234 /// Distance to enemy
\r
235 .float tur_dist_enemy;
\r
236 /// Distance impact<->aim
\r
237 .float tur_dist_toaimpos;
\r
238 /// Decresment counter form .shot_volly to 0.
\r
239 .float volly_counter;
\r
242 * Projectile/missile. its up to the individual turret implementation to
\r
243 ** deal the damage, blow upp the missile or whatever.
\r
245 /// Track then refireing is possible
\r
246 //.float attack_finished; = attack_finished_single
\r
247 /// Shoot this often
\r
248 .float shot_refire;
\r
249 /// Shots travel this fast, when appliable
\r
252 .float shot_spread;
\r
253 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
\r
255 /// If radius dmg, this is how big that radius is.
\r
256 .float shot_radius;
\r
257 /// Max force exserted by round impact
\r
259 /// < 1 = shoot # times at target (if possible)
\r
261 /// Refire after a compleated or borken volly.
\r
262 .float shot_volly_refire;
\r
264 /// Consider targets within this range
\r
265 .float target_range;
\r
266 /// Dont consider targets closer then
\r
267 .float target_range_min;
\r
268 /// Engage fire routine on targets within
\r
269 .float target_range_fire;
\r
270 /// Targets closer to this are prefered
\r
271 .float target_range_optimal;
\r
274 * The standard targetselection tries to select a target based on
\r
275 * range, angle offset, target type, "is old target"
\r
276 * Thise biases will allow score scaling to (dis)favor diffrent targets
\r
278 /// (dis)Favor best range this mutch
\r
279 .float target_select_rangebias;
\r
280 /// (dis)Favor targeting my old enemy this mutch
\r
281 .float target_select_samebias;
\r
282 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
\r
283 .float target_select_anglebias;
\r
284 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
\r
285 .float target_select_missilebias;
\r
286 /// (dis)Favot living players (-1 to diable targeting compleatly)
\r
287 .float target_select_playerbias;
\r
290 * Aim refers to real aiming, not gun pos (thats done by track)
\r
292 /// Maximum offset between impact and aim spot to fire
\r
293 .float aim_firetolerance_dist;
\r
294 /// Maximum angular offset between head and aimspot to fire
\r
295 //.float aim_firetolerance_angle;
\r
296 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
\r
298 /// cant aim higher/lower then this
\r
299 .float aim_maxpitch;
\r
300 /// I cant rotate more then this
\r
303 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
\r
304 /// Staring & current ammo
\r
306 /// Regenerate this mutch ammo (per second)
\r
307 .float ammo_recharge;
\r
308 /// Max amount of ammo i can hold
\r
312 // Uncomment below to enable various debug output.
\r
313 //#define TURRET_DEBUG
\r
314 //#define TURRET_DEBUG_TARGETVALIDATE
\r
315 //#define TURRET_DEBUG_TARGETSELECT
\r
317 #ifdef TURRET_DEBUG
\r
318 .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.
\r
319 .float tur_dbg_dmg_t_f; // Total damage spent
\r
320 .float tur_dbg_start; // When did i go online?
\r
321 .float tur_dbg_tmr1; // timer for random use
\r
322 .float tur_dbg_tmr2; // timer for random use
\r
323 .float tur_dbg_tmr3; // timer for random use
\r
324 .vector tur_dbg_rvec; // Random vector, mainly for coloruing stuff'
\r
329 void turret_think();
\r
330 /// Prefire checks and sutch
\r
331 void turret_fire();
\r
334 /// implements the actual fiering
\r
335 .void() turret_firefunc;
\r
336 /// prefire checks go here. return 1 to go bang, 0 not to.
\r
337 .float() turret_firecheckfunc;
\r
338 // Execure BEFORE main ai loop. return 0 to cancel any following proccessing.
\r
339 //.float() turret_prethink;
\r
340 /// Execure AFTER main AI loop UNLESS turret_prethink returnd 0
\r
341 .void() turret_postthink;
\r
344 .float(entity e_target,entity e_sender) turret_addtarget;
\r
346 //.float call_diehook;
\r
347 //.float call_respwnhook;
\r
348 .void() turret_diehook;
\r
349 .void() turret_respawnhook;
\r
352 #define TEH_THINK 2
\r
353 #define TEH_DAMAGE 4
\r
355 #define TEH_RESPAWN 16
\r
356 #define TEH_TRACK 32
\r
358 #define TEH_SELECT 128
\r
359 .float(float event_id) turret_eventhook;
\r
363 * Some turrets need other aimsystems then other.
\r
364 * This should return the place to aim at, not acctualy turn or
\r
367 * use turret_stdproc_aim* or Make your own.
\r
368 * Make sure you update tur_enemy_dist and tur_enemy_adist
\r
369 * with the apropriate info, if you do.
\r
373 /// function used to aim, usualy turret_stdproc_aim_generic
\r
374 //.vector() turret_aim;
\r
377 * This is where the acctual turret turning should take place
\r
378 * Use turret_stdproc_track or make your own.
\r
379 wkacked to save mem.
\r
381 // Function used to turn and pitch the .tur_head usualy turret_stdproc_track
\r
382 //.void() turret_track;
\r
385 * Target selection, preferably but not nessesarely
\r
386 * return a normalized result.
\r
388 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
\r
389 .float(entity e_turret, entity e_target) turret_score_target;
\r
392 * Damage, death and respawn.
\r
394 //void turret_gibs_precash();
\r
395 // generalized so save mem (on fields)
\r
396 // Function to handle incomming damage. usualy turret_stdproc_damage
\r
397 //.void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce) turret_damagefunc;
\r
398 // Function to handle the event of death. usualy turret_stdproc_die
\r
399 //.void() turret_diefunc;
\r
400 // Function that handles rebirth. usualy turret_stdproc_respawn
\r
401 //.void() turret_spawnfunc;
\r
404 * Stuff to plug into requierd but unused callbacks.
\r
406 /// Always return 1
\r
407 float turret_stdproc_true();
\r
408 /// Always return 0
\r
409 float turret_stdproc_false();
\r
410 /// Always return nothing at all
\r
411 void turret_stdproc_nothing();
\r
416 /// "closeer is beter" selection
\r
417 float turret_stdproc_targetscore_close(entity e_turret, entity e_target);
\r
418 /// "further is beter" selection
\r
419 float turret_stdproc_targetscore_far(entity e_turret, entity e_target);
\r
420 /// only target_range_optimal
\r
421 float turret_stdproc_targetscore_optimal(entity e_turret, entity e_target);
\r
423 float turret_stdproc_targetscore_defend(entity e_turret, entity e_target);
\r
424 /// Generic fairly smart bias-aware target selection.
\r
425 float turret_stdproc_targetscore_generic(entity e_turret, entity e_target);
\r
426 /// Experimental supportunits targetselector
\r
427 float turret_stdproc_targetscore_support(entity e_turret,entity e_target);
\r
432 /// Generic aimer guided by self.aim_flags
\r
433 vector turret_stdproc_aim_generic()
\r
434 // Straight line, current location
\r
435 //vector turret_stdproc_aim_simple()
\r
438 * Turret turning & pitch
\r
440 /// Tries to line up the turret head with the aimpos
\r
441 void turret_stdproc_track();
\r
443 /// Generic damage handeling. blows up the turret when health <= 0
\r
444 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
\r
445 /// Spawns a explotion, does some damage & trows bits arround.
\r
446 void turret_stdproc_die();
\r
447 /// reassembles the turret.
\r
448 void turret_stdproc_respawn();
\r
450 /// Evaluate target validity
\r
451 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
\r
452 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
\r
454 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
\r
456 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
\r
458 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
\r
460 /// Distance. updated by a sucsessfull call to turret_validate_target
\r
463 /// updates aim org, shot org, shot dir and enemy org for selected turret
\r
464 void turret_do_updates(entity e_turret);
\r
465 .vector tur_aimorg_updated;
\r
466 .vector tur_shotorg_updated;
\r
467 .vector tur_shotdir_updated;
\r
469 void turrets_precash();
\r
470 #endif // TTURRETS_ENABLED
\r