]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/include/turrets_early.qh
#include this
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / include / turrets_early.qh
1 #ifndef TURRETS_EARLY_H
2 #define TURRETS_EARLY_H
3
4 #if defined(CSQC)
5     #include "../../../common/util-pre.qh"
6     #include "../../../client/sys-pre.qh"
7     #include "../../../dpdefs/csprogsdefs.qc"
8     #include "../../../client/sys-post.qh"
9     #include "../../../client/Defs.qc"
10     #include "../../../dpdefs/keycodes.qc"
11     #include "../../../common/constants.qh"
12     #include "../../../common/stats.qh"
13     #include "../../../warpzonelib/anglestransform.qh"
14     #include "../../../warpzonelib/mathlib.qh"
15     #include "../../../warpzonelib/common.qh"
16     #include "../../../warpzonelib/client.qh"
17     #include "../../../common/playerstats.qh"
18     #include "../../../common/teams.qh"
19     #include "../../../common/util.qh"
20     #include "../../../common/nades.qh"
21     #include "../../../common/buffs.qh"
22     #include "../../../common/test.qh"
23     #include "../../../common/counting.qh"
24     #include "../../../common/weapons/weapons.qh"
25     #include "../../../common/mapinfo.qh"
26     #include "../../../common/command/markup.qh"
27     #include "../../../common/command/rpn.qh"
28     #include "../../../common/command/generic.qh"
29     #include "../../../common/command/shared_defs.qh"
30     #include "../../../common/urllib.qh"
31     #include "../../../common/animdecide.qh"
32     #include "../../../client/command/cl_cmd.qh"
33     #include "../../../common/monsters/monsters.qh"
34     #include "../../../client/autocvars.qh"
35     #include "../../../common/notifications.qh"
36     #include "../../../common/deathtypes.qh"
37     #include "../../../client/damage.qh"
38     #include "../../../csqcmodellib/interpolate.qh"
39     #include "../../../client/teamradar.qh"
40     #include "../../../client/hud.qh"
41     #include "../../../client/scoreboard.qh"
42     #include "../../../client/waypointsprites.qh"
43     #include "../../../client/movetypes.qh"
44     #include "../../../client/prandom.qh"
45     #include "../../../client/bgmscript.qh"
46     #include "../../../client/noise.qh"
47     #include "../../../client/tturrets.qh"
48 #elif defined(MENUQC)
49 #elif defined(SVQC)
50     #include "../../../common/util-pre.qh"
51     #include "../../sys-pre.qh"
52     #include "../../../dpdefs/progsdefs.qc"
53     #include "../../../dpdefs/dpextensions.qc"
54     #include "../../sys-post.qh"
55     #include "../../../warpzonelib/anglestransform.qh"
56     #include "../../../warpzonelib/mathlib.qh"
57     #include "../../../warpzonelib/common.qh"
58     #include "../../../warpzonelib/util_server.qh"
59     #include "../../../warpzonelib/server.qh"
60     #include "../../../common/constants.qh"
61     #include "../../../common/stats.qh"
62     #include "../../../common/teams.qh"
63     #include "../../../common/util.qh"
64     #include "../../../common/nades.qh"
65     #include "../../../common/buffs.qh"
66     #include "../../../common/test.qh"
67     #include "../../../common/counting.qh"
68     #include "../../../common/urllib.qh"
69     #include "../../../common/command/markup.qh"
70     #include "../../../common/command/rpn.qh"
71     #include "../../../common/command/generic.qh"
72     #include "../../../common/command/shared_defs.qh"
73     #include "../../../common/net_notice.qh"
74     #include "../../../common/animdecide.qh"
75     #include "../../../common/monsters/monsters.qh"
76     #include "../../../common/monsters/sv_monsters.qh"
77     #include "../../../common/monsters/spawn.qh"
78     #include "../../../common/weapons/config.qh"
79     #include "../../../common/weapons/weapons.qh"
80     #include "../../weapons/accuracy.qh"
81     #include "../../weapons/common.qh"
82     #include "../../weapons/csqcprojectile.qh"
83     #include "../../weapons/hitplot.qh"
84     #include "../../weapons/selection.qh"
85     #include "../../weapons/spawning.qh"
86     #include "../../weapons/throwing.qh"
87     #include "../../weapons/tracing.qh"
88     #include "../../weapons/weaponstats.qh"
89     #include "../../weapons/weaponsystem.qh"
90     #include "../../t_items.qh"
91     #include "../../autocvars.qh"
92     #include "../../constants.qh"
93     #include "../../defs.qh"
94     #include "../../../common/notifications.qh"
95     #include "../../../common/deathtypes.qh"
96     #include "../../mutators/mutators_include.qh"
97 #endif
98
99 // Comment out below to skip turrets
100 #define TTURRETS_ENABLED
101
102 #ifdef TTURRETS_ENABLED
103 #ifdef SVQC
104 //#message "with tZork turrets"
105
106 float turret_count;
107
108 vector real_origin(entity ent);
109
110 /// Map time control over pain inflicted
111 .float turret_scale_damage;
112 /// Map time control targetting range
113 .float turret_scale_range;
114 /// Map time control refire
115 .float turret_scale_refire;
116 /// Map time control ammo held and recharged
117 .float turret_scale_ammo;
118 /// Map time control aim speed
119 .float turret_scale_aim;
120 /// Map time control health
121 .float turret_scale_health;
122 /// Map time control respawn time
123 .float turret_scale_respawn;
124
125 /// Used for cvar reloading
126 .string cvar_basename;
127
128 //.float spawnflags
129 const float TSF_SUSPENDED     = 1;
130 /// Spawn a pillar model under the turret to make it look ok on uneven ground surfaces
131 const float TSF_TERRAINBASE   = 2;
132 /// Disable builtin ammo regeneration
133 const float TSF_NO_AMMO_REGEN = 4;
134 /// Dont break path to chase enemys. will still fire at them if possible.
135 const float TSF_NO_PATHBREAK  = 8;
136 /// Dont respawn
137 const float TSL_NO_RESPAWN    = 16;
138 /// Let this turret roam when idle.
139 const float TSL_ROAM          = 32;
140
141 /// target selection flags
142 .float target_select_flags;
143 /// target validatoin flags
144 .float target_validate_flags;
145 /// Dont select a target on its own.
146 const float TFL_TARGETSELECT_NO            = 2;
147 /// Need line of sight
148 const float TFL_TARGETSELECT_LOS           = 4;
149 /// Players are valid targets
150 const float TFL_TARGETSELECT_PLAYERS       = 8;
151 /// Missiles are valid targets
152 const float TFL_TARGETSELECT_MISSILES      = 16;
153 /// Responds to turret_trigger_target events
154 const float TFL_TARGETSELECT_TRIGGERTARGET = 32;
155 /// Angular limitations of turret head limits target selection
156 const float TFL_TARGETSELECT_ANGLELIMITS   = 64;
157 /// Range limits apply in targetselection
158 const float TFL_TARGETSELECT_RANGELIMTS    = 128;
159 /// DOnt select targets with a .team matching its own
160 const float TFL_TARGETSELECT_TEAMCHECK     = 256;
161 /// Cant select targets on its own. needs to be triggerd or slaved.
162 const float TFL_TARGETSELECT_NOBUILTIN     = 512;
163 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
164 const float TFL_TARGETSELECT_OWNTEAM       = 1024;
165 /// Turrets aren't valid targets
166 const float TFL_TARGETSELECT_NOTURRETS     = 2048;
167 /// Use feild of view
168 const float TFL_TARGETSELECT_FOV           = 4096;
169
170 const float TFL_TARGETSELECT_MISSILESONLY  = 8192;
171
172 /// aim flags
173 .float aim_flags;
174 /// Dont aim.
175 const float TFL_AIM_NO                  = 1;
176 /// Go for ground, not direct hit, but only if target is on ground.
177 const float TFL_AIM_GROUNDGROUND        = 2;
178 /// Try to predict target movement (does not account for gravity)
179 const float TFL_AIM_LEAD                = 4;
180 /// Compensate for shot traveltime when lead
181 const float TFL_AIM_SHOTTIMECOMPENSATE  = 8;
182 /// Try to do real prediction of targets z pos at impact.
183 const float TFL_AIM_ZPREDICT            = 16;
184 /// Simply aim at target's current location
185 const float TFL_AIM_SIMPLE              = 32;
186
187 /// track (turn and pitch head) flags
188 .float track_flags;
189 /// Dont move head
190 const float TFL_TRACK_NO    = 2;
191 /// Pitch the head
192 const float TFL_TRACK_PITCH = 4;
193 /// Rotate the head
194 const float TFL_TRACK_ROT   = 8;
195
196 /// How tracking is preformed
197 .float track_type;
198 /// Hard angle increments. Ugly for fast turning, best accuracy.
199 const float TFL_TRACKTYPE_STEPMOTOR    = 1;
200 /// Smoth absolute movement. Looks ok, fair accuracy.
201 const float TFL_TRACKTYPE_FLUIDPRECISE = 2;
202 /// Simulated inertia. "Wobbly mode" Looks kool, can mean really bad accuracy depending on how the fields below are set
203 const float TFL_TRACKTYPE_FLUIDINERTIA = 3;
204 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
205 .float track_accel_pitch;
206 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
207 .float  track_accel_rot;
208 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1  = only old, 0 = only new
209 .float  track_blendrate;
210
211 /// How prefire check is preformed
212 .float firecheck_flags;
213 /// Dont kill the dead
214 const float TFL_FIRECHECK_DEAD        = 4;
215 /// Range limits apply
216 const float TFL_FIRECHECK_DISTANCES   = 8;
217 /// Line Of Sight needs to be clear
218 const float TFL_FIRECHECK_LOS         = 16;
219 /// Consider distance inpactpoint<->aimspot
220 const float TFL_FIRECHECK_AIMDIST     = 32;
221 /// Consider enemy origin<->impactpoint
222 const float TFL_FIRECHECK_REALDIST    = 64;
223 /// Consider angular diff head<->aimspot
224 const float TFL_FIRECHECK_ANGLEDIST  = 128;
225 /// (re)consider target.team<->self.team
226 const float TFL_FIRECHECK_TEAMCECK   = 256;
227 /// Try to avoid friendly fire
228 const float TFL_FIRECHECK_AFF        = 512;
229 /// Own .ammo needs to be >= then own .shot_dmg
230 const float TFL_FIRECHECK_OWM_AMMO   = 1024;
231 /// Others ammo need to be < others .ammo_max
232 const float TFL_FIRECHECK_OTHER_AMMO = 2048;
233 /// Check own .attack_finished_single vs time
234 const float TFL_FIRECHECK_REFIRE     = 4096;
235 /// Move the acctual target to aimspot before tracing impact (and back after)
236 //#define TFL_FIRECHECK_VERIFIED   8192
237 /// Dont do any chekcs
238 const float TFL_FIRECHECK_NO         = 16384;
239
240 /// How shooting is done
241 .float shoot_flags;
242 /// Dont shoot
243 const float  TFL_SHOOT_NO          = 64;
244 /// Fire in vollys (partial implementation through .shot_volly)
245 const float  TFL_SHOOT_VOLLY       = 2;
246 /// Always do a full volly, even if target is lost or dead. (not implemented)
247 const float  TFL_SHOOT_VOLLYALWAYS = 4;
248 /// Loop though all valid tarters, and hit them.
249 const float  TFL_SHOOT_HITALLVALID = 8;
250 /// Fiering makes unit loose target (after volly is done, if in volly mode)
251 const float  TFL_SHOOT_CLEARTARGET = 16;
252 ///Custom shooting;
253 const float  TFL_SHOOT_CUSTOM = 32;
254
255 /// Information aboute the units capabilities
256 .float turrcaps_flags;
257 /// No kown capabilities
258 const float  TFL_TURRCAPS_NONE        = 0;
259 /// Capable of sniping
260 const float  TFL_TURRCAPS_SNIPER      = 2;
261 /// Capable of splasdamage
262 const float  TFL_TURRCAPS_RADIUSDMG   = 4;
263 /// Has one or more cannons with zero shot traveltime
264 const float  TFL_TURRCAPS_HITSCAN     = 8;
265 /// More then one (type of) gun
266 const float  TFL_TURRCAPS_MULTIGUN    = 16;
267 /// Carries at least one guided weapon
268 const float  TFL_TURRCAPS_GUIDED      = 32;
269 /// At least one gun fiers slow projectiles
270 const float  TFL_TURRCAPS_SLOWPROJ    = 64;
271 /// At least one gun fiers medium speed projectiles
272 const float  TFL_TURRCAPS_MEDPROJ     = 128;
273 /// At least one gun fiers fast projectiles
274 const float  TFL_TURRCAPS_FASTPROJ    = 256;
275 /// At least one gun capable of damaging players
276 const float  TFL_TURRCAPS_PLAYERKILL  = 512;
277 /// At least one gun that can shoot town missiles
278 const float  TFL_TURRCAPS_MISSILEKILL = 1024;
279 /// Has support capabilities. powerplants and sutch.
280 const float  TFL_TURRCAPS_SUPPORT     = 2048;
281 /// Proveides at least one type of ammmo
282 const float  TFL_TURRCAPS_AMMOSOURCE  = 4096;
283 /// Can recive targets from external sources
284 const float TFL_TURRCAPS_RECIVETARGETS = 8192;
285 /// Capable of self-transport
286 const float TFL_TURRCAPS_MOVE = 16384;
287 /// Will roam arround even if not chasing anyting
288 const float TFL_TURRCAPS_ROAM = 32768;
289 const float TFL_TURRCAPS_ISTURRET = 65536;
290
291 /// Ammo types needed and/or provided
292 //.float ammo_flags;
293 #define ammo_flags currentammo
294 /// Has and needs no ammo
295 const float  TFL_AMMO_NONE     = 64;
296 /// Uses power
297 const float  TFL_AMMO_ENERGY   = 2;
298 /// Uses bullets
299 const float  TFL_AMMO_BULLETS  = 4;
300 /// Uses explosives
301 const float  TFL_AMMO_ROCKETS  = 8;
302 /// Regenerates ammo on its own
303 const float  TFL_AMMO_RECHARGE = 16;
304 /// Can recive ammo from others
305 const float  TFL_AMMO_RECIVE   = 32;
306
307 /// How incomming damage is handeld
308 .float damage_flags;
309 /// Cant be hurt
310 const float  TFL_DMG_NO              = 256;
311 /// Can be damaged
312 const float  TFL_DMG_YES             = 2;
313 /// Can be damaged  by teammates
314 const float  TFL_DMG_TAKEFROMTEAM    = 4;
315 /// Traget attackers
316 const float  TFL_DMG_RETALIATE       = 8;
317 /// Target attackers, even is on own team
318 const float  TFL_DMG_RETALIATEONTEAM = 16;
319 /// Loses target when damaged
320 const float  TFL_DMG_TARGETLOSS      = 32;
321 /// Reciving damage trows off aim (pointless atm, aim gets recalculated to fast). not implemented.
322 const float  TFL_DMG_AIMSHAKE        = 64;
323 /// Reciving damage slaps the head arround
324 const float  TFL_DMG_HEADSHAKE       = 128;
325 /// Die and stay dead.
326 const float  TFL_DMG_DEATH_NORESPAWN = 256;
327
328 // Spawnflags
329 /// Spawn in teambased modes
330 const float TFL_SPAWN_TEAM      = 2;
331 /// Spawn in FFA modes
332 const float TFL_SPAWN_FFA       = 4;
333
334
335 /*
336 * Fields used by turrets
337 */
338 /// Turrets internal ai speed
339 .float      ticrate;
340
341 /// Where to point the when no target
342 .vector     idle_aim;
343
344 /// Top part of turret
345 .entity     tur_head;
346
347 /// Start/respawn health
348 .float      tur_health;
349
350 /// Defend this entity (or ratehr this entitys position)
351 .entity     tur_defend;
352
353 /// and shoot from here. (can be non constant, think MLRS)
354 .vector     tur_shotorg;
355
356 /// Aim at this spot
357 .vector     tur_aimpos;
358
359 /// Predicted time the round will impact
360 .float      tur_impacttime;
361
362 // Predicted place the round will impact
363 //.vector     tur_impactpoint; // unused
364
365 /// What entity the aimtrace hit, if any.
366 .entity     tur_impactent;
367
368 /// Distance to enemy
369 .float      tur_dist_enemy;
370
371 /// Distance to aimspot
372 .float      tur_dist_aimpos;
373
374 /// Distance impact<->aim
375 .float      tur_dist_impact_to_aimpos;
376
377 /// Decresment counter form .shot_volly to 0.
378 .float      volly_counter;
379
380 /*
381 * Projectile/missile. its up to the individual turret implementation to
382 ** deal the damage, blow upp the missile or whatever.
383 */
384 /// Track then refireing is possible
385 //.float attack_finished; = attack_finished_single
386 /// Shoot this often
387 .float shot_refire;
388 /// Shots travel this fast, when appliable
389 .float shot_speed;
390 /// Inaccuracy
391 .float shot_spread;
392 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
393 .float shot_dmg;
394 /// If radius dmg, this is how big that radius is.
395 .float shot_radius;
396 /// Max force exserted by round impact
397 .float shot_force;
398 /// < 1 = shoot # times at target (if possible)
399 .float shot_volly;
400 /// Refire after a compleated volly.
401 .float shot_volly_refire;
402
403 /// Consider targets within this range
404 .float target_range;
405 /// Dont consider targets closer then
406 .float target_range_min;
407 /// Targets closer to this are prefered
408 .float target_range_optimal;
409
410 /*
411 * The standard targetselection tries to select a target based on
412 * range, angle offset, target type, "is old target"
413 * Thise biases will allow score scaling to (dis)favor diffrent targets
414 */
415 /// (dis)Favor best range this mutch
416 .float target_select_rangebias;
417 /// (dis)Favor targeting my old enemy this mutch
418 .float target_select_samebias;
419 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
420 .float target_select_anglebias;
421 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
422 .float target_select_missilebias;
423 /// (dis)Favot living players (-1 to diable targeting compleatly)
424 .float target_select_playerbias;
425 /// Field of view
426 //.float target_select_fov;
427 /// Last timestamp this turret aquierd a valid target
428 .float target_select_time;
429 /// Throttle re-validation of current target
430 .float target_validate_time;
431 /*
432 * Aim refers to real aiming, not gun pos (thats done by track)
433 */
434 /// Maximum offset between impact and aim spot to fire
435 .float aim_firetolerance_dist;
436 /// How fast can i rotate/pitch (per second in stepmotor mode, base force in smooth modes)
437 .float aim_speed;
438 /// cant aim higher/lower then this
439 .float aim_maxpitch;
440 /// I cant rotate more then this
441 .float aim_maxrot;
442
443 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
444 /// Staring & current ammo
445 .float ammo;
446 /// Regenerate this mutch ammo (per second)
447 .float ammo_recharge;
448 /// Max amount of ammo i can hold
449 .float ammo_max;
450
451
452 // Uncomment below to enable various debug output.
453 //#define TURRET_DEBUG
454 //#define TURRET_DEBUG_TARGETVALIDATE
455 //#define TURRET_DEBUG_TARGETSELECT
456
457 #ifdef TURRET_DEBUG
458 .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.
459 .float tur_dbg_dmg_t_f; // Total damage spent
460 .float tur_dbg_start;   // When did i go online?
461 .float tur_dbg_tmr1;    // timer for random use
462 .float tur_dbg_tmr2;    // timer for random use
463 .float tur_dbg_tmr3;    // timer for random use
464 .vector tur_dbg_rvec;   // Random vector, mainly for coloruing stuff'
465 #endif
466
467 // System main's
468 /// Main AI loop
469 void turret_think();
470 /// Prefire checks and sutch
471 void turret_fire();
472
473 // Callbacks
474 /// implements the actual fiering
475 .void()  turret_firefunc;
476 /// prefire checks go here. return 1 to go bang, 0 not to.
477 .float() turret_firecheckfunc;
478 /// Execure AFTER main AI loop
479 .void()  turret_postthink;
480
481 /// Add a target
482 .float(entity e_target,entity e_sender) turret_addtarget;
483
484 .void() turret_diehook;
485 .void() turret_respawnhook;
486
487 /*
488 * Target selection, preferably but not nessesarely
489 * return a normalized result.
490 */
491 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
492 .float(entity _turret, entity _target) turret_score_target;
493
494 /*
495 * Target selection
496 */
497 /// Generic, fairly smart, bias-aware target selection.
498 float   turret_stdproc_targetscore_generic(entity _turret, entity _target);
499 /// Experimental supportunits targetselector
500 float   turret_stdproc_targetscore_support(entity _turret,entity _target);
501
502 /*
503 * Aim functions
504 */
505 /// Generic aimer guided by self.aim_flags
506 vector turret_stdproc_aim_generic();
507
508 /*
509 * Turret turning & pitch
510 */
511 /// Tries to line up the turret head with the aimpos
512 void turret_stdproc_track();
513
514 /// Generic damage handeling. blows up the turret when health <= 0
515 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
516 /// Spawns a explotion, does some damage & trows bits arround.
517 void turret_stdproc_die();
518 /// reassembles the turret.
519 void turret_stdproc_respawn();
520
521 /// Evaluate target validity
522 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
523 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
524 vector tvt_thadv;
525 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
526 vector tvt_tadv;
527 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
528 float  tvt_thadf;
529 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
530 float  tvt_tadf;
531 /// Distance. updated by a sucsessfull call to turret_validate_target
532 float  tvt_dist;
533
534 /// updates aim org, shot org, shot dir and enemy org for selected turret
535 void turret_do_updates(entity e_turret);
536 .vector tur_shotdir_updated;
537
538 void turrets_precash();
539 #endif // SVQC
540
541 // common
542 .int turret_type;
543 const int TID_COMMON        = 1;
544 const int TID_EWHEEL        = 2;
545 const int TID_FLAC          = 3;
546 const int TID_FUSION        = 4;
547 const int TID_HELLION       = 5;
548 const int TID_HK            = 6;
549 const int TID_MACHINEGUN    = 7;
550 const int TID_MLRS          = 8;
551 const int TID_PHASER        = 9;
552 const int TID_PLASMA        = 10;
553 const int TID_PLASMA_DUAL   = 11;
554 const int TID_TESLA         = 12;
555 const int TID_WALKER        = 13;
556 const int TID_LAST          = 13;
557
558 const int TNSF_UPDATE       = 2;
559 const int TNSF_STATUS       = 4;
560 const int TNSF_SETUP        = 8;
561 const int TNSF_ANG          = 16;
562 const int TNSF_AVEL         = 32;
563 const int TNSF_MOVE         = 64;
564 .float anim_start_time;
565 const int TNSF_ANIM         = 128;
566
567 const int TNSF_FULL_UPDATE  = 16777215;
568
569 #endif // TTURRETS_ENABLED
570 #endif