]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/include/turrets_early.qh
Merge remote branch 'origin/master' into fruitiex/animations
[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 /// Let this turret roam when idle.
41 #define TSL_ROAM          32
42
43 /// target selection flags
44 .float target_select_flags;
45 /// target validatoin flags
46 .float target_validate_flags;
47 /// Dont select a target on its own.
48 #define TFL_TARGETSELECT_NO            2
49 /// Need line of sight
50 #define TFL_TARGETSELECT_LOS           4
51 /// Players are valid targets
52 #define TFL_TARGETSELECT_PLAYERS       8
53 /// Missiles are valid targets
54 #define TFL_TARGETSELECT_MISSILES      16
55 /// Responds to turret_trigger_target events
56 #define TFL_TARGETSELECT_TRIGGERTARGET 32
57 /// Angular limitations of turret head limits target selection
58 #define TFL_TARGETSELECT_ANGLELIMITS   64
59 /// Range limits apply in targetselection
60 #define TFL_TARGETSELECT_RANGELIMTS    128
61 /// DOnt select targets with a .team matching its own
62 #define TFL_TARGETSELECT_TEAMCHECK     256
63 /// Cant select targets on its own. needs to be triggerd or slaved.
64 #define TFL_TARGETSELECT_NOBUILTIN     512
65 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
66 #define TFL_TARGETSELECT_OWNTEAM       1024
67 /// Turrets aren't valid targets
68 #define TFL_TARGETSELECT_NOTURRETS     2048
69 /// Use feild of view
70 #define TFL_TARGETSELECT_FOV           4096
71
72 #define TFL_TARGETSELECT_MISSILESONLY  8192
73
74 /// aim flags
75 .float aim_flags;
76 /// Dont aim.
77 #define TFL_AIM_NO                  1
78 /// Go for ground, not direct hit
79 //#define TFL_AIM_GROUND              2
80 /// Go for ground, not direct hit, but only if target is on ground.
81 #define TFL_AIM_GROUND2             4
82 /// Use balistic aim. FIXME: not implemented
83 #define TFL_AIM_BALISTIC            8
84 /// Try to predict target movement (does not account for gravity)
85 #define TFL_AIM_LEAD                16
86 /// Compensate for shot traveltime when lead
87 #define TFL_AIM_SHOTTIMECOMPENSATE  32
88 /// Aim slightly in front of target
89 #define TFL_AIM_INFRONT             64
90 /// Aim slightly behind target
91 #define TFL_AIM_BEHIND              128
92 /// blend real and predicted z positions. (fake bounce prediction) 
93 // #define TFL_AIM_ZEASE               256 
94 /// Try to do real prediction of targets z pos at impact.
95 #define TFL_AIM_ZPREDICT            512
96 /// Simply aim at target's current location
97 #define TFL_AIM_SIMPLE              1024
98
99 /// track (turn and pitch head) flags
100 .float track_flags;
101 /// Dont move head
102 #define TFL_TRACK_NO    2
103 /// Pitch the head
104 #define TFL_TRACK_PITCH 4
105 /// Rotate the head
106 #define TFL_TRACK_ROT   8
107
108 /// How tracking is preformed
109 .float track_type;
110 /// Hard angle increments. Ugly for fast turning, best accuracy.
111 #define TFL_TRACKTYPE_STEPMOTOR    1
112 /// Smoth absolute movement. Looks ok, fair accuracy.
113 #define TFL_TRACKTYPE_FLUIDPRECISE 2
114 /// Simulated inertia. "Wobbly mode" Looks kool, can mean really bad accuracy depending on how the feilds below are set
115 #define TFL_TRACKTYPE_FLUIDINERTIA 3
116 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
117 .float track_accel_pitch;
118 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
119 .float  track_accel_rot;
120 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1  = only old, 0 = only new
121 .float  track_blendrate;
122
123 /// How prefire check is preformed
124 .float firecheck_flags;
125 /// Dont kill the world
126 #define TFL_FIRECHECK_WORLD       2
127 /// Dont kill the dead
128 #define TFL_FIRECHECK_DEAD        4
129 /// Range limits apply
130 #define TFL_FIRECHECK_DISTANCES   8
131 /// Line Of Sight needs to be clear
132 #define TFL_FIRECHECK_LOS         16
133 /// Consider distance inpactpoint<->aimspot
134 #define TFL_FIRECHECK_AIMDIST     32
135 /// Consider enemy origin<->impactpoint
136 #define TFL_FIRECHECK_REALDIST    64
137 /// Consider angular diff head<->aimspot
138 #define TFL_FIRECHECK_ANGLEDIST  128
139 /// (re)consider target.team<->self.team
140 #define TFL_FIRECHECK_TEAMCECK   256
141 /// Try to avoid friendly fire
142 #define TFL_FIRECHECK_AFF        512
143 /// Own .ammo needs to be >= then own .shot_dmg
144 #define TFL_FIRECHECK_OWM_AMMO   1024
145 /// Others ammo need to be < others .ammo_max
146 #define TFL_FIRECHECK_OTHER_AMMO 2048
147 /// Check own .attack_finished_single vs time
148 #define TFL_FIRECHECK_REFIRE     4096
149 /// Move the acctual target to aimspot before tracing impact (and back after)
150 #define TFL_FIRECHECK_VERIFIED   8192
151 /// Dont do any chekcs
152 #define TFL_FIRECHECK_NO         16384
153
154 /// How shooting is done
155 .float shoot_flags;
156 /// Dont shoot
157 #define  TFL_SHOOT_NO          64
158 /// Fire in vollys (partial implementation through .shot_volly)
159 #define  TFL_SHOOT_VOLLY       2
160 /// Always do a full volly, even if target is lost or dead. (not implemented)
161 #define  TFL_SHOOT_VOLLYALWAYS 4
162 /// Loop though all valid tarters, and hit them.
163 #define  TFL_SHOOT_HITALLVALID 8
164 /// Fiering makes unit loose target (after volly is done, if in volly mode)
165 #define  TFL_SHOOT_CLEARTARGET 16
166 ///Custom shooting;
167 #define  TFL_SHOOT_CUSTOM 32
168
169 /// Information aboute the units capabilities
170 .float turrcaps_flags;
171 /// No kown capabilities
172 #define  TFL_TURRCAPS_NONE        0
173 /// Capable of sniping
174 #define  TFL_TURRCAPS_SNIPER      2
175 /// Capable of splasdamage
176 #define  TFL_TURRCAPS_RADIUSDMG   4
177 /// Has one or more cannons with zero shot traveltime
178 #define  TFL_TURRCAPS_HITSCAN     8
179 /// More then one (type of) gun
180 #define  TFL_TURRCAPS_MULTIGUN    16
181 /// Carries at least one guided weapon
182 #define  TFL_TURRCAPS_GUIDED      32
183 /// At least one gun fiers slow projectiles
184 #define  TFL_TURRCAPS_SLOWPROJ    64
185 /// At least one gun fiers medium speed projectiles
186 #define  TFL_TURRCAPS_MEDPROJ     128
187 /// At least one gun fiers fast projectiles
188 #define  TFL_TURRCAPS_FASTPROJ    256
189 /// At least one gun capable of damaging players
190 #define  TFL_TURRCAPS_PLAYERKILL  512
191 /// At least one gun that can shoot town missiles
192 #define  TFL_TURRCAPS_MISSILEKILL 1024
193 /// Has support capabilities. powerplants and sutch.
194 #define  TFL_TURRCAPS_SUPPORT     2048
195 /// Proveides at least one type of ammmo
196 #define  TFL_TURRCAPS_AMMOSOURCE  4096
197 /// Can recive targets from external sources
198 #define TFL_TURRCAPS_RECIVETARGETS 8192
199 /// Capable of self-transport
200 #define TFL_TURRCAPS_MOVE 16384
201 /// Will roam arround even if not chasing anyting
202 #define TFL_TURRCAPS_ROAM 32768
203 #define TFL_TURRCAPS_ISTURRET 65536
204
205 /// Ammo types needed and/or provided
206 .float ammo_flags;
207 /// Has and needs no ammo
208 #define  TFL_AMMO_NONE     64
209 /// Uses power
210 #define  TFL_AMMO_ENERGY   2
211 /// Uses bullets
212 #define  TFL_AMMO_BULLETS  4
213 /// Uses explosives
214 #define  TFL_AMMO_ROCKETS  8
215 /// Regenerates ammo on its own
216 #define  TFL_AMMO_RECHARGE 16
217 /// Can recive ammo from others
218 #define  TFL_AMMO_RECIVE   32
219
220 /// How incomming damage is handeld
221 .float damage_flags;
222 /// Cant be hurt
223 #define  TFL_DMG_NO              256
224 /// Can be damaged
225 #define  TFL_DMG_YES             2
226 /// Can be damaged  by teammates
227 #define  TFL_DMG_TAKEFROMTEAM    4
228 /// Traget attackers
229 #define  TFL_DMG_RETALIATE       8
230 /// Target attackers, even is on own team
231 #define  TFL_DMG_RETALIATEONTEAM 16
232 /// Loses target when damaged
233 #define  TFL_DMG_TARGETLOSS      32
234 /// Reciving damage trows off aim (pointless atm, aim gets recalculated to fast). not implemented.
235 #define  TFL_DMG_AIMSHAKE        64
236 /// Reciving damage slaps the head arround
237 #define  TFL_DMG_HEADSHAKE       128
238 /// Die and stay dead.
239 #define  TFL_DMG_DEATH_NORESPAWN 256
240 /// Supress std turret gibs on death
241 #define  TFL_DMG_DEATH_NOGIBS    512
242
243 // Spawnflags
244 /// Spawn in teambased modes
245 #define TFL_SPAWN_TEAM      2
246 /// Spawn in FFA modes
247 #define TFL_SPAWN_FFA       4
248
249
250 /*
251 * Fields used by turrets
252 */
253 /// Turrets internal ai speed
254 .float      ticrate;
255
256 /// Where to point the when no target
257 .vector     idle_aim;
258
259 /// Top part of turret
260 .entity     tur_head;
261
262 /// Start/respawn health
263 .float      tur_health;
264
265 /// Defend this entity (or ratehr this entitys position)
266 .entity     tur_defend;
267
268 /// on/off toggle.
269 .float      tur_active;
270
271 /// and shoot from here. (can be non constant, think MLRS)
272 .vector     tur_shotorg;
273
274 /// Aim at this spot
275 .vector     tur_aimpos;
276
277 /// Predicted time the round will impact
278 .float      tur_impacttime;
279
280 // Predicted place the round will impact
281 //.vector     tur_impactpoint; // unused
282
283 /// What entity the aimtrace hit, if any.
284 .entity     tur_impactent;
285
286 /// Distance to enemy
287 .float      tur_dist_enemy;
288
289 /// Distance to aimspot
290 .float      tur_dist_aimpos;
291
292 /// Distance impact<->aim
293 .float      tur_dist_impact_to_aimpos;
294
295 /// Decresment counter form .shot_volly to 0.
296 .float      volly_counter;
297
298 /*
299 * Projectile/missile. its up to the individual turret implementation to
300 ** deal the damage, blow upp the missile or whatever.
301 */
302 /// Track then refireing is possible
303 //.float attack_finished; = attack_finished_single
304 /// Shoot this often
305 .float shot_refire;
306 /// Shots travel this fast, when appliable
307 .float shot_speed;
308 /// Inaccuracy
309 .float shot_spread;
310 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
311 .float shot_dmg;
312 /// If radius dmg, this is how big that radius is.
313 .float shot_radius;
314 /// Max force exserted by round impact
315 .float shot_force;
316 /// < 1 = shoot # times at target (if possible)
317 .float shot_volly;
318 /// Refire after a compleated volly.
319 .float shot_volly_refire;
320
321 /// Consider targets within this range
322 .float target_range;
323 /// Dont consider targets closer then
324 .float target_range_min;
325 /// Targets closer to this are prefered
326 .float target_range_optimal;
327
328 /*
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
332 */
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;
343 /// Field of view
344 //.float target_select_fov;
345 /// Last timestamp this turret aquierd a valid target
346 .float target_select_time;
347 /// Throttle re-validation of current target
348 .float target_validate_time;
349 /*
350 * Aim refers to real aiming, not gun pos (thats done by track)
351 */
352 /// Maximum offset between impact and aim spot to fire
353 .float aim_firetolerance_dist;
354 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
355 .float aim_speed;
356 /// cant aim higher/lower then this
357 .float aim_maxpitch;
358 /// I cant rotate more then this
359 .float aim_maxrot;
360
361 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
362 /// Staring & current ammo
363 .float ammo;
364 /// Regenerate this mutch ammo (per second)
365 .float ammo_recharge;
366 /// Max amount of ammo i can hold
367 .float ammo_max;
368
369
370 // Uncomment below to enable various debug output.
371 //#define TURRET_DEBUG
372 //#define TURRET_DEBUG_TARGETVALIDATE
373 //#define TURRET_DEBUG_TARGETSELECT
374
375 #ifdef TURRET_DEBUG
376 .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.
377 .float tur_dbg_dmg_t_f; // Total damage spent
378 .float tur_dbg_start;   // When did i go online?
379 .float tur_dbg_tmr1;    // timer for random use
380 .float tur_dbg_tmr2;    // timer for random use
381 .float tur_dbg_tmr3;    // timer for random use
382 .vector tur_dbg_rvec;   // Random vector, mainly for coloruing stuff'
383 #endif
384
385 // System main's
386 /// Main AI loop
387 void turret_think();
388 /// Prefire checks and sutch
389 void turret_fire();
390
391 // Callbacks
392 /// implements the actual fiering
393 .void()  turret_firefunc;
394 /// prefire checks go here. return 1 to go bang, 0 not to.
395 .float() turret_firecheckfunc;
396 /// Execure AFTER main AI loop
397 .void()  turret_postthink;
398
399 /// Add a target
400 .float(entity e_target,entity e_sender) turret_addtarget;
401
402 .void() turret_diehook;
403 .void() turret_respawnhook;
404
405 /*
406 * Target selection, preferably but not nessesarely
407 * return a normalized result.
408 */
409 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
410 .float(entity _turret, entity _target) turret_score_target;
411
412 /*
413 * Target selection
414 */
415 /// Generic, fairly smart, bias-aware target selection.
416 float   turret_stdproc_targetscore_generic(entity _turret, entity _target);
417 /// Experimental supportunits targetselector
418 float   turret_stdproc_targetscore_support(entity _turret,entity _target);
419
420 /*
421 * Aim functions
422 */
423 /// Generic aimer guided by self.aim_flags
424 vector turret_stdproc_aim_generic();
425
426 /*
427 * Turret turning & pitch
428 */
429 /// Tries to line up the turret head with the aimpos
430 void turret_stdproc_track();
431
432 /// Generic damage handeling. blows up the turret when health <= 0
433 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
434 /// Spawns a explotion, does some damage & trows bits arround.
435 void turret_stdproc_die();
436 /// reassembles the turret.
437 void turret_stdproc_respawn();
438
439 /// Evaluate target validity
440 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
441 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
442 vector tvt_thadv;
443 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
444 vector tvt_tadv;
445 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
446 float  tvt_thadf;
447 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
448 float  tvt_tadf;
449 /// Distance. updated by a sucsessfull call to turret_validate_target
450 float  tvt_dist;
451
452 /// updates aim org, shot org, shot dir and enemy org for selected turret
453 void turret_do_updates(entity e_turret);
454 .vector tur_shotdir_updated;
455
456 void turrets_precash();
457 #endif // SVQC
458
459 // common
460 .float turret_type;
461 float TID_COMMON        = 1;
462 float TID_EWHEEL        = 2;
463 float TID_FLAC          = 3;
464 float TID_FUSION        = 4;
465 float TID_HELLION       = 5;
466 float TID_HK            = 6;
467 float TID_MACHINEGUN    = 7;
468 float TID_MLRS          = 8;
469 float TID_PHASER        = 9;
470 float TID_PLASMA        = 10;
471 float TID_PLASMA_DUAL   = 11;
472 float TID_TESLA         = 12;
473 float TID_WALKER        = 13;
474 float TID_LAST          = 13;
475
476 float TNSF_UPDATE       = 2;
477 float TNSF_STATUS       = 4;
478 float TNSF_SETUP        = 8;
479 float TNSF_ANG          = 16;
480 float TNSF_AVEL         = 32;
481 float TNSF_MOVE         = 64;
482 .float anim_start_time;
483 float TNSF_ANIM         = 128;
484
485 float TNSF_FULL_UPDATE  = 16777215;
486
487 #endif // TTURRETS_ENABLED
488
489