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