]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/include/turrets_early.qh
Trottle target re-validation to save a bit server preformance
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / include / turrets_early.qh
1 // Comment out below to skip turrets
2 #define TTURRETS_ENABLED
3
4 #ifdef TTURRETS_ENABLED
5 #ifdef SVQC
6 //#message "with tZork turrets"
7
8 float turret_count;
9
10 vector real_origin(entity ent);
11
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;
26
27 /// Used for cvar reloading
28 .string cvar_basename;
29
30 //.float spawnflags
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
38 /// Dont respawn
39 #define TSL_NO_RESPAWN    16
40
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
67 /// Use feild of view
68 #define TFL_TARGETSELECT_FOV           4096
69
70 #define TFL_TARGETSELECT_MISSILESONLY  8192
71
72 /// aim flags
73 .float aim_flags;
74 /// Dont aim.
75 #define TFL_AIM_NO                  1
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
96
97 /// track (turn and pitch head) flags
98 .float track_flags;
99 /// Dont move head
100 #define TFL_TRACK_NO    2
101 /// Pitch the head
102 #define TFL_TRACK_PITCH 4
103 /// Rotate the head
104 #define TFL_TRACK_ROT   8
105
106 /// How tracking is preformed
107 .float track_type;
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;
120
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
151
152 /// How shooting is done
153 .float shoot_flags;
154 /// Dont shoot
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
164 ///Custom shooting;
165 #define  TFL_SHOOT_CUSTOM 32
166
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
202
203 /// Ammo types needed and/or provided
204 .float ammo_flags;
205 /// Has and needs no ammo
206 #define  TFL_AMMO_NONE     64
207 /// Uses power
208 #define  TFL_AMMO_ENERGY   2
209 /// Uses bullets
210 #define  TFL_AMMO_BULLETS  4
211 /// Uses explosives
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
217
218 /// How incomming damage is handeld
219 .float damage_flags;
220 /// Cant be hurt
221 #define  TFL_DMG_NO              256
222 /// Can be damaged
223 #define  TFL_DMG_YES             2
224 /// Can be damaged  by teammates
225 #define  TFL_DMG_TAKEFROMTEAM    4
226 /// Traget attackers
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
240
241 // Spawnflags
242 /// Spawn in teambased modes
243 #define TFL_SPAWN_TEAM      2
244 /// Spawn in FFA modes
245 #define TFL_SPAWN_FFA       4
246
247
248 /*
249 * Fields used by turrets
250 */
251 /// Turrets internal ai speed
252 .float      ticrate;
253
254 /// Where to point the when no target
255 .vector     idle_aim;
256
257 /// Top part of turret
258 .entity     tur_head;
259
260 /// Start/respawn health
261 .float      tur_health;
262
263 /// Defend this entity (or ratehr this entitys position)
264 .entity     tur_defend;
265
266 /// on/off toggle.
267 .float      tur_active;
268
269 /// and shoot from here. (can be non constant, think MLRS)
270 .vector     tur_shotorg;
271
272 /// Aim at this spot
273 .vector     tur_aimpos;
274
275 /// Predicted time the round will impact
276 .float      tur_impacttime;
277
278 // Predicted place the round will impact
279 //.vector     tur_impactpoint; // unused
280
281 /// What entity the aimtrace hit, if any.
282 .entity     tur_impactent;
283
284 /// Distance to enemy
285 .float      tur_dist_enemy;
286
287 /// Distance to aimspot
288 .float      tur_dist_aimpos;
289
290 /// Distance impact<->aim
291 .float      tur_dist_impact_to_aimpos;
292
293 /// Decresment counter form .shot_volly to 0.
294 .float      volly_counter;
295
296 /*
297 * Projectile/missile. its up to the individual turret implementation to
298 ** deal the damage, blow upp the missile or whatever.
299 */
300 /// Track then refireing is possible
301 //.float attack_finished; = attack_finished_single
302 /// Shoot this often
303 .float shot_refire;
304 /// Shots travel this fast, when appliable
305 .float shot_speed;
306 /// Inaccuracy
307 .float shot_spread;
308 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
309 .float shot_dmg;
310 /// If radius dmg, this is how big that radius is.
311 .float shot_radius;
312 /// Max force exserted by round impact
313 .float shot_force;
314 /// < 1 = shoot # times at target (if possible)
315 .float shot_volly;
316 /// Refire after a compleated volly.
317 .float shot_volly_refire;
318
319 /// Consider targets within this range
320 .float target_range;
321 /// Dont consider targets closer then
322 .float target_range_min;
323 /// Targets closer to this are prefered
324 .float target_range_optimal;
325
326 /*
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
330 */
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;
341 /// Field of view
342 //.float target_select_fov;
343 /// Last timestamp this turret aquierd a valid target
344 .float target_select_time;
345 /// Throttle re-validation of current target
346 .float target_validate_time;
347 /*
348 * Aim refers to real aiming, not gun pos (thats done by track)
349 */
350 /// Maximum offset between impact and aim spot to fire
351 .float aim_firetolerance_dist;
352 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
353 .float aim_speed;
354 /// cant aim higher/lower then this
355 .float aim_maxpitch;
356 /// I cant rotate more then this
357 .float aim_maxrot;
358
359 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
360 /// Staring & current ammo
361 .float ammo;
362 /// Regenerate this mutch ammo (per second)
363 .float ammo_recharge;
364 /// Max amount of ammo i can hold
365 .float ammo_max;
366
367
368 // Uncomment below to enable various debug output.
369 //#define TURRET_DEBUG
370 //#define TURRET_DEBUG_TARGETVALIDATE
371 //#define TURRET_DEBUG_TARGETSELECT
372
373 #ifdef TURRET_DEBUG
374 .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.
375 .float tur_dbg_dmg_t_f; // Total damage spent
376 .float tur_dbg_start;   // When did i go online?
377 .float tur_dbg_tmr1;    // timer for random use
378 .float tur_dbg_tmr2;    // timer for random use
379 .float tur_dbg_tmr3;    // timer for random use
380 .vector tur_dbg_rvec;   // Random vector, mainly for coloruing stuff'
381 #endif
382
383 // System main's
384 /// Main AI loop
385 void turret_think();
386 /// Prefire checks and sutch
387 void turret_fire();
388
389 // Callbacks
390 /// implements the actual fiering
391 .void()  turret_firefunc;
392 /// prefire checks go here. return 1 to go bang, 0 not to.
393 .float() turret_firecheckfunc;
394 /// Execure AFTER main AI loop
395 .void()  turret_postthink;
396
397 /// Add a target
398 .float(entity e_target,entity e_sender) turret_addtarget;
399
400 .void() turret_diehook;
401 .void() turret_respawnhook;
402
403 /*
404 * Target selection, preferably but not nessesarely
405 * return a normalized result.
406 */
407 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
408 .float(entity _turret, entity _target) turret_score_target;
409
410 /*
411 * Target selection
412 */
413 /// Generic, fairly smart, bias-aware target selection.
414 float   turret_stdproc_targetscore_generic(entity _turret, entity _target);
415 /// Experimental supportunits targetselector
416 float   turret_stdproc_targetscore_support(entity _turret,entity _target);
417
418 /*
419 * Aim functions
420 */
421 /// Generic aimer guided by self.aim_flags
422 vector turret_stdproc_aim_generic();
423
424 /*
425 * Turret turning & pitch
426 */
427 /// Tries to line up the turret head with the aimpos
428 void turret_stdproc_track();
429
430 /// Generic damage handeling. blows up the turret when health <= 0
431 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
432 /// Spawns a explotion, does some damage & trows bits arround.
433 void turret_stdproc_die();
434 /// reassembles the turret.
435 void turret_stdproc_respawn();
436
437 /// Evaluate target validity
438 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
439 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
440 vector tvt_thadv;
441 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
442 vector tvt_tadv;
443 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
444 float  tvt_thadf;
445 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
446 float  tvt_tadf;
447 /// Distance. updated by a sucsessfull call to turret_validate_target
448 float  tvt_dist;
449
450 /// updates aim org, shot org, shot dir and enemy org for selected turret
451 void turret_do_updates(entity e_turret);
452 .vector tur_shotdir_updated;
453
454 void turrets_precash();
455 #endif // SVQC
456
457 // common
458 .float turret_type;
459 float TID_COMMON        = 1;
460 float TID_EWHEEL        = 2;
461 float TID_FLAC          = 3;
462 float TID_FUSION        = 4;
463 float TID_HELLION       = 5;
464 float TID_HK            = 6;
465 float TID_MACHINEGUN    = 7;
466 float TID_MLRS          = 8;
467 float TID_PHASER        = 9;
468 float TID_PLASMA        = 10;
469 float TID_PLASMA_DUAL   = 11;
470 float TID_TESLA         = 12;
471 float TID_WALKER        = 13;
472 float TID_LAST          = 13;
473
474 float TNSF_UPDATE       = 2;
475 float TNSF_STATUS       = 4;
476 float TNSF_SETUP        = 8;
477 float TNSF_ANG          = 16;
478 float TNSF_AVEL         = 32;
479 float TNSF_MOVE         = 64;
480 .float anim_start_time;
481 float TNSF_ANIM         = 128;
482
483 float TNSF_FULL_UPDATE  = 16777215;
484
485 #endif // TTURRETS_ENABLED
486
487