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