]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/include/turrets_early.qh
Make csqc turrets work. moving ones still do not
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / include / turrets_early.qh
1 // Comment out below to skip turrets
2 #define TTURRETS_ENABLED
3 //#define TTURRETS_CSQC
4
5 #ifdef TTURRETS_ENABLED
6 #ifdef SVQC
7 //#message "with tZork turrets"
8
9 float turret_count;
10
11 vector real_origin(entity ent);
12
13 /// Map time control over pain inflicted
14 .float turret_scale_damage;
15 /// Map time control targetting range
16 .float turret_scale_range;
17 /// Map time control refire
18 .float turret_scale_refire;
19 /// Map time control ammo held and recharged
20 .float turret_scale_ammo;
21 /// Map time control aim speed
22 .float turret_scale_aim;
23 /// Map time control health
24 .float turret_scale_health;
25 /// Map time control respawn time
26 .float turret_scale_respawn;
27
28 /// Used for cvar reloading
29 .string cvar_basename;
30
31 //.float spawnflags
32 #define TSF_SUSPENDED     1
33 /// Spawn a pillar model under the turret to make it look ok on uneven ground surfaces
34 #define TSF_TERRAINBASE   2
35 /// Disable builtin ammo regeneration
36 #define TSF_NO_AMMO_REGEN 4
37 /// Dont break path to chase enemys. will still fire at them if possible.
38 #define TSF_NO_PATHBREAK  8
39 /// Dont respawn
40 #define TSL_NO_RESPAWN    16
41
42 /// target selection flags
43 .float target_select_flags;
44 /// target validatoin flags
45 .float target_validate_flags;
46 /// Dont select a target on its own.
47 #define TFL_TARGETSELECT_NO            2
48 /// Need line of sight
49 #define TFL_TARGETSELECT_LOS           4
50 /// Players are valid targets
51 #define TFL_TARGETSELECT_PLAYERS       8
52 /// Missiles are valid targets
53 #define TFL_TARGETSELECT_MISSILES      16
54 /// Responds to turret_trigger_target events
55 #define TFL_TARGETSELECT_TRIGGERTARGET 32
56 /// Angular limitations of turret head limits target selection
57 #define TFL_TARGETSELECT_ANGLELIMITS   64
58 /// Range limits apply in targetselection
59 #define TFL_TARGETSELECT_RANGELIMTS    128
60 /// DOnt select targets with a .team matching its own
61 #define TFL_TARGETSELECT_TEAMCHECK     256
62 /// Cant select targets on its own. needs to be triggerd or slaved.
63 #define TFL_TARGETSELECT_NOBUILTIN     512
64 /// TFL_TARGETSELECT_TEAMCHECK is inverted (selects only mebers of own .team)
65 #define TFL_TARGETSELECT_OWNTEAM       1024
66 /// Turrets aren't valid targets
67 #define TFL_TARGETSELECT_NOTURRETS     2048
68 /// Use feild of view
69 #define TFL_TARGETSELECT_FOV           4096
70
71 #define TFL_TARGETSELECT_MISSILESONLY  8192
72
73 /// aim flags
74 .float aim_flags;
75 /// Dont aim.
76 #define TFL_AIM_NO                  1
77 /// Go for ground, not direct hit
78 //#define TFL_AIM_GROUND              2
79 /// Go for ground, not direct hit, but only if target is on ground.
80 #define TFL_AIM_GROUND2             4
81 /// Use balistic aim. FIXME: not implemented
82 #define TFL_AIM_BALISTIC            8
83 /// Try to predict target movement (does not account for gravity)
84 #define TFL_AIM_LEAD                16
85 /// Compensate for shot traveltime when lead
86 #define TFL_AIM_SHOTTIMECOMPENSATE  32
87 /// Aim slightly in front of target
88 #define TFL_AIM_INFRONT             64
89 /// Aim slightly behind target
90 #define TFL_AIM_BEHIND              128
91 /// blend real and predicted z positions. (fake bounce prediction) 
92 // #define TFL_AIM_ZEASE               256 
93 /// Try to do real prediction of targets z pos at impact.
94 #define TFL_AIM_ZPREDICT            512
95 /// Simply aim at target's current location
96 #define TFL_AIM_SIMPLE              1024
97
98 /// track (turn and pitch head) flags
99 .float track_flags;
100 /// Dont move head
101 #define TFL_TRACK_NO    2
102 /// Pitch the head
103 #define TFL_TRACK_PITCH 4
104 /// Rotate the head
105 #define TFL_TRACK_ROT   8
106
107 /// How tracking is preformed
108 .float track_type;
109 /// Hard angle increments. Ugly for fast turning, best accuracy.
110 #define TFL_TRACKTYPE_STEPMOTOR    1
111 /// Smoth absolute movement. Looks ok, fair accuracy.
112 #define TFL_TRACKTYPE_FLUIDPRECISE 2
113 /// Simulated inertia. "Wobbly mode" Looks kool, can mean really bad accuracy depending on how the feilds below are set
114 #define TFL_TRACKTYPE_FLUIDINERTIA 3
115 /// TFL_TRACKTYPE_FLUIDINERTIA: pitch multiplier
116 .float track_accel_pitch;
117 /// TFL_TRACKTYPE_FLUIDINERTIA: rotation multiplier
118 .float  track_accel_rot;
119 /// TFL_TRACKTYPE_FLUIDINERTIA: Blendrate with old rotation (inertia simulation) 1  = only old, 0 = only new
120 .float  track_blendrate;
121
122 /// How prefire check is preformed
123 .float firecheck_flags;
124 /// Dont kill the world
125 #define TFL_FIRECHECK_WORLD       2
126 /// Dont kill the dead
127 #define TFL_FIRECHECK_DEAD        4
128 /// Range limits apply
129 #define TFL_FIRECHECK_DISTANCES   8
130 /// Line Of Sight needs to be clear
131 #define TFL_FIRECHECK_LOS         16
132 /// Consider distance inpactpoint<->aimspot
133 #define TFL_FIRECHECK_AIMDIST     32
134 /// Consider enemy origin<->impactpoint
135 #define TFL_FIRECHECK_REALDIST    64
136 /// Consider angular diff head<->aimspot
137 #define TFL_FIRECHECK_ANGLEDIST  128
138 /// (re)consider target.team<->self.team
139 #define TFL_FIRECHECK_TEAMCECK   256
140 /// Try to avoid friendly fire
141 #define TFL_FIRECHECK_AFF        512
142 /// Own .ammo needs to be >= then own .shot_dmg
143 #define TFL_FIRECHECK_OWM_AMMO   1024
144 /// Others ammo need to be < others .ammo_max
145 #define TFL_FIRECHECK_OTHER_AMMO 2048
146 /// Check own .attack_finished_single vs time
147 #define TFL_FIRECHECK_REFIRE     4096
148 /// Move the acctual target to aimspot before tracing impact (and back after)
149 #define TFL_FIRECHECK_VERIFIED   8192
150 /// Dont do any chekcs
151 #define TFL_FIRECHECK_NO         16384
152
153 /// How shooting is done
154 .float shoot_flags;
155 /// Dont shoot
156 #define  TFL_SHOOT_NO          64
157 /// Fire in vollys (partial implementation through .shot_volly)
158 #define  TFL_SHOOT_VOLLY       2
159 /// Always do a full volly, even if target is lost or dead. (not implemented)
160 #define  TFL_SHOOT_VOLLYALWAYS 4
161 /// Loop though all valid tarters, and hit them.
162 #define  TFL_SHOOT_HITALLVALID 8
163 /// Fiering makes unit loose target (after volly is done, if in volly mode)
164 #define  TFL_SHOOT_CLEARTARGET 16
165 ///Custom shooting;
166 #define  TFL_SHOOT_CUSTOM 32
167
168 /// Information aboute the units capabilities
169 .float turrcaps_flags;
170 /// No kown capabilities
171 #define  TFL_TURRCAPS_NONE        0
172 /// Capable of sniping
173 #define  TFL_TURRCAPS_SNIPER      2
174 /// Capable of splasdamage
175 #define  TFL_TURRCAPS_RADIUSDMG   4
176 /// Has one or more cannons with zero shot traveltime
177 #define  TFL_TURRCAPS_HITSCAN     8
178 /// More then one (type of) gun
179 #define  TFL_TURRCAPS_MULTIGUN    16
180 /// Carries at least one guided weapon
181 #define  TFL_TURRCAPS_GUIDED      32
182 /// At least one gun fiers slow projectiles
183 #define  TFL_TURRCAPS_SLOWPROJ    64
184 /// At least one gun fiers medium speed projectiles
185 #define  TFL_TURRCAPS_MEDPROJ     128
186 /// At least one gun fiers fast projectiles
187 #define  TFL_TURRCAPS_FASTPROJ    256
188 /// At least one gun capable of damaging players
189 #define  TFL_TURRCAPS_PLAYERKILL  512
190 /// At least one gun that can shoot town missiles
191 #define  TFL_TURRCAPS_MISSILEKILL 1024
192 /// Has support capabilities. powerplants and sutch.
193 #define  TFL_TURRCAPS_SUPPORT     2048
194 /// Proveides at least one type of ammmo
195 #define  TFL_TURRCAPS_AMMOSOURCE  4096
196 /// Can recive targets from external sources
197 #define TFL_TURRCAPS_RECIVETARGETS 8192
198 /// Capable of self-transport
199 #define TFL_TURRCAPS_MOVE 16384
200 /// Will roam arround even if not chasing anyting
201 #define TFL_TURRCAPS_ROAM 32768
202 #define TFL_TURRCAPS_ISTURRET 65536
203
204 /// Ammo types needed and/or provided
205 .float ammo_flags;
206 /// Has and needs no ammo
207 #define  TFL_AMMO_NONE     64
208 /// Uses power
209 #define  TFL_AMMO_ENERGY   2
210 /// Uses bullets
211 #define  TFL_AMMO_BULLETS  4
212 /// Uses explosives
213 #define  TFL_AMMO_ROCKETS  8
214 /// Regenerates ammo on its own
215 #define  TFL_AMMO_RECHARGE 16
216 /// Can recive ammo from others
217 #define  TFL_AMMO_RECIVE   32
218
219 /// How incomming damage is handeld
220 .float damage_flags;
221 /// Cant be hurt
222 #define  TFL_DMG_NO              256
223 /// Can be damaged
224 #define  TFL_DMG_YES             2
225 /// Can be damaged  by teammates
226 #define  TFL_DMG_TAKEFROMTEAM    4
227 /// Traget attackers
228 #define  TFL_DMG_RETALIATE       8
229 /// Target attackers, even is on own team
230 #define  TFL_DMG_RETALIATEONTEAM 16
231 /// Loses target when damaged
232 #define  TFL_DMG_TARGETLOSS      32
233 /// Reciving damage trows off aim (pointless atm, aim gets recalculated to fast). not implemented.
234 #define  TFL_DMG_AIMSHAKE        64
235 /// Reciving damage slaps the head arround
236 #define  TFL_DMG_HEADSHAKE       128
237 /// Die and stay dead.
238 #define  TFL_DMG_DEATH_NORESPAWN 256
239 /// Supress std turret gibs on death
240 #define  TFL_DMG_DEATH_NOGIBS    512
241
242 // Spawnflags
243 /// Spawn in teambased modes
244 #define TFL_SPAWN_TEAM      2
245 /// Spawn in FFA modes
246 #define TFL_SPAWN_FFA       4
247
248
249 /*
250 * Fields used by turrets
251 */
252 /// Turrets internal ai speed
253 .float      ticrate;
254
255 /// Where to point the when no target
256 .vector     idle_aim;
257
258 /// Top part of turret
259 .entity     tur_head;
260
261 /// Start/respawn health
262 .float      tur_health;
263
264 /// Defend this entity (or ratehr this entitys position)
265 .entity     tur_defend;
266
267 /// on/off toggle.
268 .float      tur_active;
269
270 /// and shoot from here. (can be non constant, think MLRS)
271 .vector     tur_shotorg;
272
273 /// Aim at this spot
274 .vector     tur_aimpos;
275
276 /// Predicted time the round will impact
277 .float      tur_impacttime;
278
279 // Predicted place the round will impact
280 //.vector     tur_impactpoint; // unused
281
282 /// What entity the aimtrace hit, if any.
283 .entity     tur_impactent;
284
285 /// Distance to enemy
286 .float      tur_dist_enemy;
287
288 /// Distance to aimspot
289 .float      tur_dist_aimpos;
290
291 /// Distance impact<->aim
292 .float      tur_dist_impact_to_aimpos;
293
294 /// Decresment counter form .shot_volly to 0.
295 .float      volly_counter;
296
297 /*
298 * Projectile/missile. its up to the individual turret implementation to
299 ** deal the damage, blow upp the missile or whatever.
300 */
301 /// Track then refireing is possible
302 //.float attack_finished; = attack_finished_single
303 /// Shoot this often
304 .float shot_refire;
305 /// Shots travel this fast, when appliable
306 .float shot_speed;
307 /// Inaccuracy
308 .float shot_spread;
309 /// Estimated (core) damage of projectiles. also reduce on ammo with this amount when fiering
310 .float shot_dmg;
311 /// If radius dmg, this is how big that radius is.
312 .float shot_radius;
313 /// Max force exserted by round impact
314 .float shot_force;
315 /// < 1 = shoot # times at target (if possible)
316 .float shot_volly;
317 /// Refire after a compleated volly.
318 .float shot_volly_refire;
319
320 /// Consider targets within this range
321 .float target_range;
322 /// Dont consider targets closer then
323 .float target_range_min;
324 /// Targets closer to this are prefered
325 .float target_range_optimal;
326
327 /*
328 * The standard targetselection tries to select a target based on
329 * range, angle offset, target type, "is old target"
330 * Thise biases will allow score scaling to (dis)favor diffrent targets
331 */
332 /// (dis)Favor best range this mutch
333 .float target_select_rangebias;
334 /// (dis)Favor targeting my old enemy this mutch
335 .float target_select_samebias;
336 /// (dis)Favor targeting the enemy closest to my guns current angle this mutch
337 .float target_select_anglebias;
338 /// (dis)Favor Missiles? (-1 to diable targeting compleatly)
339 .float target_select_missilebias;
340 /// (dis)Favot living players (-1 to diable targeting compleatly)
341 .float target_select_playerbias;
342 /// Field of view
343 //.float target_select_fov;
344 /// Last thimestamp this surret aquierd a valid target
345 .float target_select_time;
346
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 #define TEH_THINK 2
405 #define TEH_DAMAGE 4
406 #define TEH_DIE 8
407 #define TEH_RESPAWN 16
408 #define TEH_TRACK 32
409 #define TEH_AIM 64
410 #define TEH_SELECT 128
411 .float(float event_id) turret_eventhook;
412 */
413
414
415 /*
416 * Target selection, preferably but not nessesarely
417 * return a normalized result.
418 */
419 /// Function to use for target evaluation. usualy turret_stdproc_targetscore_generic
420 .float(entity e_turret, entity e_target) turret_score_target;
421
422
423 /*
424 * Target selection
425 */
426 /// Generic, fairly smart, bias-aware target selection.
427 float   turret_stdproc_targetscore_generic(entity e_turret, entity e_target);
428 /// Experimental supportunits targetselector
429 float   turret_stdproc_targetscore_support(entity e_turret,entity e_target);
430
431 /*
432 * Aim functions
433 */
434 /// Generic aimer guided by self.aim_flags
435 vector turret_stdproc_aim_generic();
436
437 /*
438 * Turret turning & pitch
439 */
440 /// Tries to line up the turret head with the aimpos
441 void turret_stdproc_track();
442
443 /// Generic damage handeling. blows up the turret when health <= 0
444 void turret_stdproc_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce);
445 /// Spawns a explotion, does some damage & trows bits arround.
446 void turret_stdproc_die();
447 /// reassembles the turret.
448 void turret_stdproc_respawn();
449
450 /// Evaluate target validity
451 float turret_validate_target(entity e_turret,entity e_target,float validate_flags);
452 /// Turret Head Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
453 vector tvt_thadv;
454 /// Turret Angle Diff Vector. updated by a sucsessfull call to turret_validate_target
455 vector tvt_tadv;
456 /// Turret Head Angle Diff Float. updated by a sucsessfull call to turret_validate_target
457 float  tvt_thadf;
458 /// Turret Angle Diff Float. updated by a sucsessfull call to turret_validate_target
459 float  tvt_tadf;
460 /// Distance. updated by a sucsessfull call to turret_validate_target
461 float  tvt_dist;
462
463 /// updates aim org, shot org, shot dir and enemy org for selected turret
464 void turret_do_updates(entity e_turret);
465 .vector tur_shotdir_updated;
466
467 void turrets_precash();
468 #endif // SVQC
469
470 // common
471 .float turret_type;
472 float TID_EWHEEL        = 1;
473 float TID_FLAC          = 2;
474 float TID_FUSION        = 3;
475 float TID_HELLION       = 4;
476 float TID_HK            = 5;
477 float TID_MACHINEGUN    = 6;
478 float TID_MLRS          = 7;
479 float TID_PHASER        = 8;
480 float TID_PLASMA        = 9;
481 float TID_PLASMA_DUAL   = 10;
482 float TID_TESLA         = 11;
483 float TID_WALKER        = 12;
484 float TID_LAST          = 12;
485
486 float TNSF_UPDATE       = 2;
487 float TNSF_STATUS       = 4;
488 float TNSF_SETUP        = 8;
489 float TNSF_ANG          = 16;
490 float TNSF_AVEL         = 32;
491 float TNSF_FAR          = 64;
492 float TNSF_FULL_UPDATE  = 16777215;
493
494 #endif // TTURRETS_ENABLED
495
496