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