]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/include/turrets_early.qh
Merge branch 'master' into terencehill/weapon_panel_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / include / turrets_early.qh
1 #ifndef TURRETS_EARLY_H
2 #define TURRETS_EARLY_H
3
4 // Comment out below to skip turrets
5 #define TTURRETS_ENABLED
6
7 #ifdef TTURRETS_ENABLED
8 #ifdef SVQC
9 //#message "with tZork turrets"
10
11 float turret_count;
12
13 vector real_origin(entity ent);
14
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;
29
30 /// Used for cvar reloading
31 .string cvar_basename;
32
33 //.float spawnflags
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;
41 /// Dont respawn
42 const float TSL_NO_RESPAWN    = 16;
43 /// Let this turret roam when idle.
44 const float TSL_ROAM          = 32;
45
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;
72 /// Use feild of view
73 const float TFL_TARGETSELECT_FOV           = 4096;
74
75 const float TFL_TARGETSELECT_MISSILESONLY  = 8192;
76
77 /// aim flags
78 .float aim_flags;
79 /// Dont aim.
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;
91
92 /// track (turn and pitch head) flags
93 .float track_flags;
94 /// Dont move head
95 const float TFL_TRACK_NO    = 2;
96 /// Pitch the head
97 const float TFL_TRACK_PITCH = 4;
98 /// Rotate the head
99 const float TFL_TRACK_ROT   = 8;
100
101 /// How tracking is preformed
102 .float track_type;
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;
115
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;
144
145 /// How shooting is done
146 .float shoot_flags;
147 /// Dont shoot
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;
157 ///Custom shooting;
158 const float  TFL_SHOOT_CUSTOM = 32;
159
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;
195
196 /// Ammo types needed and/or provided
197 //.float ammo_flags;
198 #define ammo_flags currentammo
199 /// Has and needs no ammo
200 const float  TFL_AMMO_NONE     = 64;
201 /// Uses power
202 const float  TFL_AMMO_ENERGY   = 2;
203 /// Uses bullets
204 const float  TFL_AMMO_BULLETS  = 4;
205 /// Uses explosives
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;
211
212 /// How incomming damage is handeld
213 .float damage_flags;
214 /// Cant be hurt
215 const float  TFL_DMG_NO              = 256;
216 /// Can be damaged
217 const float  TFL_DMG_YES             = 2;
218 /// Can be damaged  by teammates
219 const float  TFL_DMG_TAKEFROMTEAM    = 4;
220 /// Traget attackers
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;
232
233 // Spawnflags
234 /// Spawn in teambased modes
235 const float TFL_SPAWN_TEAM      = 2;
236 /// Spawn in FFA modes
237 const float TFL_SPAWN_FFA       = 4;
238
239
240 /*
241 * Fields used by turrets
242 */
243 /// Turrets internal ai speed
244 .float      ticrate;
245
246 /// Where to point the when no target
247 .vector     idle_aim;
248
249 /// Top part of turret
250 .entity     tur_head;
251
252 /// Start/respawn health
253 .float      tur_health;
254
255 /// Defend this entity (or ratehr this entitys position)
256 .entity     tur_defend;
257
258 /// and shoot from here. (can be non constant, think MLRS)
259 .vector     tur_shotorg;
260
261 /// Aim at this spot
262 .vector     tur_aimpos;
263
264 /// Predicted time the round will impact
265 .float      tur_impacttime;
266
267 // Predicted place the round will impact
268 //.vector     tur_impactpoint; // unused
269
270 /// What entity the aimtrace hit, if any.
271 .entity     tur_impactent;
272
273 /// Distance to enemy
274 .float      tur_dist_enemy;
275
276 /// Distance to aimspot
277 .float      tur_dist_aimpos;
278
279 /// Distance impact<->aim
280 .float      tur_dist_impact_to_aimpos;
281
282 /// Decresment counter form .shot_volly to 0.
283 .float      volly_counter;
284
285 /*
286 * Projectile/missile. its up to the individual turret implementation to
287 ** deal the damage, blow upp the missile or whatever.
288 */
289 /// Track then refireing is possible
290 //.float attack_finished; = attack_finished_single
291 /// Shoot this often
292 .float shot_refire;
293 /// Shots travel this fast, when appliable
294 .float shot_speed;
295 /// Inaccuracy
296 .float shot_spread;
297 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
298 .float shot_dmg;
299 /// If radius dmg, this is how big that radius is.
300 .float shot_radius;
301 /// Max force exserted by round impact
302 .float shot_force;
303 /// < 1 = shoot # times at target (if possible)
304 .float shot_volly;
305 /// Refire after a compleated volly.
306 .float shot_volly_refire;
307
308 /// Consider targets within this range
309 .float target_range;
310 /// Dont consider targets closer then
311 .float target_range_min;
312 /// Targets closer to this are prefered
313 .float target_range_optimal;
314
315 /*
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
319 */
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;
330 /// Field of view
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;
336 /*
337 * Aim refers to real aiming, not gun pos (thats done by track)
338 */
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)
342 .float aim_speed;
343 /// cant aim higher/lower then this
344 .float aim_maxpitch;
345 /// I cant rotate more then this
346 .float aim_maxrot;
347
348 // Ammo/power. keeping dmg and ammo on a one to one ratio is preferable (for rating)
349 /// Staring & current ammo
350 .float ammo;
351 /// Regenerate this mutch ammo (per second)
352 .float ammo_recharge;
353 /// Max amount of ammo i can hold
354 .float ammo_max;
355
356
357 // Uncomment below to enable various debug output.
358 //#define TURRET_DEBUG
359 //#define TURRET_DEBUG_TARGETVALIDATE
360 //#define TURRET_DEBUG_TARGETSELECT
361
362 #ifdef TURRET_DEBUG
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'
370 #endif
371
372 // System main's
373 /// Main AI loop
374 void turret_think();
375 /// Prefire checks and sutch
376 void turret_fire();
377
378 // Callbacks
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;
385
386 /// Add a target
387 .float(entity e_target,entity e_sender) turret_addtarget;
388
389 .void() turret_diehook;
390 .void() turret_respawnhook;
391
392 /*
393 * Target selection, preferably but not nessesarely
394 * return a normalized result.
395 */
396 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
397 .float(entity _turret, entity _target) turret_score_target;
398
399 /*
400 * Target selection
401 */
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);
406
407 /*
408 * Aim functions
409 */
410 /// Generic aimer guided by self.aim_flags
411 vector turret_stdproc_aim_generic();
412
413 /*
414 * Turret turning & pitch
415 */
416 /// Tries to line up the turret head with the aimpos
417 void turret_stdproc_track();
418
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();
425
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
429 vector tvt_thadv;
430 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
431 vector tvt_tadv;
432 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
433 float  tvt_thadf;
434 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
435 float  tvt_tadf;
436 /// Distance. updated by a sucsessfull call to turret_validate_target
437 float  tvt_dist;
438
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;
442
443 void turrets_precash();
444 #endif // SVQC
445
446 // common
447 .int turret_type;
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;
462
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;
471
472 const int TNSF_FULL_UPDATE  = 16777215;
473
474 #endif // TTURRETS_ENABLED
475 #endif