]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turrets.qh
5491746e9c32dc0728a77d33b8111e22e34ccd63
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turrets.qh
1 // turret requests
2 #define TR_SETUP          1 // (BOTH) setup turret data
3 #define TR_THINK                  2 // (SERVER) logic to run every frame
4 #define TR_DEATH          3 // (SERVER) called when turret dies
5 #define TR_PRECACHE       4 // (BOTH) precaches models/sounds used by this turret
6 #define TR_ATTACK         5 // (SERVER) called when turret attacks
7 #define TR_CONFIG         6 // (ALL)
8
9 // functions:
10 entity get_turretinfo(float id);
11
12 // fields:
13 .entity tur_head;
14
15 // target selection flags
16 .float target_select_flags;
17 .float target_validate_flags;
18 const float TFL_TARGETSELECT_NO = 2; // don't automatically find targets
19 const float TFL_TARGETSELECT_LOS = 4; // require line of sight to find targets
20 const float TFL_TARGETSELECT_PLAYERS = 8; // target players
21 const float TFL_TARGETSELECT_MISSILES = 16; // target projectiles
22 const float TFL_TARGETSELECT_TRIGGERTARGET = 32; // respond to turret_trigger_target events
23 const float TFL_TARGETSELECT_ANGLELIMITS = 64; // apply extra angular limits to target selection
24 const float TFL_TARGETSELECT_RANGELIMITS = 128; // limit target selection range
25 const float TFL_TARGETSELECT_TEAMCHECK = 256; // don't attack teammates
26 const float TFL_TARGETSELECT_NOBUILTIN = 512; // only attack targets when triggered
27 const float TFL_TARGETSELECT_OWNTEAM = 1024; // only attack teammates
28 const float TFL_TARGETSELECT_NOTURRETS = 2048; // don't attack other turrets
29 const float TFL_TARGETSELECT_FOV = 4096; // extra limits to attack range
30 const float TFL_TARGETSELECT_MISSILESONLY = 8192; // only attack missiles
31
32 // aim flags
33 .float aim_flags;
34 const float TFL_AIM_NO = 1; // no aiming
35 const float TFL_AIM_SPLASH = 2; // aim for ground around the target's feet
36 const float TFL_AIM_LEAD = 4; // try to predict target movement
37 const float TFL_AIM_SHOTTIMECOMPENSATE = 8; // compensate for shot traveltime when leading
38 const float TFL_AIM_ZPREDICT = 16; // predict target's z position at impact
39 const float TFL_AIM_SIMPLE = 32; // aim at player's current location
40
41 // tracking flags
42 .float track_flags;
43 const float TFL_TRACK_NO = 2; // don't move head
44 const float TFL_TRACK_PITCH = 4; // pitch head
45 const float TFL_TRACK_ROTATE = 8; // rotate head
46
47 // prefire checks
48 .float firecheck_flags;
49 const float TFL_FIRECHECK_DEAD = 4; // don't attack dead targets (zombies?)
50 const float TFL_FIRECHECK_DISTANCES = 8; // another range check
51 const float TFL_FIRECHECK_LOS = 16; // line of sight
52 const float TFL_FIRECHECK_AIMDIST = 32; // consider distance impactpoint<->aimspot
53 const float TFL_FIRECHECK_REALDIST = 64; // consider enemy origin<->impactpoint
54 const float TFL_FIRECHECK_ANGLEDIST = 128; // consider angular diff head<->aimspot
55 const float TFL_FIRECHECK_TEAMCHECK = 256; // don't attack teammates
56 const float TFL_FIRECHECK_AFF = 512; // try to avoid any friendly fire
57 const float TFL_FIRECHECK_AMMO_OWN = 1024; // own ammo needs to be larger than damage dealt
58 const float TFL_FIRECHECK_AMMO_OTHER = 2048; // target's ammo needs to be less than max
59 const float TFL_FIRECHECK_REFIRE = 4096; // check single attack finished delays
60 const float TFL_FIRECHECK_NO = 16384; // no prefire checks
61
62 // attack flags
63 .float shoot_flags;
64 const float TFL_SHOOT_NO = 64; // no attacking
65 const float TFL_SHOOT_VOLLY = 2; // fire in vollies
66 const float TFL_SHOOT_VOLLYALWAYS = 4; // always do a full volly, even if target is lost
67 const float TFL_SHOOT_HITALLVALID = 8; // loop through all valid targets
68 const float TFL_SHOOT_CLEARTARGET = 16; // lose target after attack (after volly is done if in volly mode)
69 const float TFL_SHOOT_CUSTOM = 32; // custom attacking
70
71 // turret capabilities
72 .float turret_flags;
73 const float TUR_FLAG_NONE = 0; // no abilities
74 const float TUR_FLAG_SNIPER = 2; // sniping turret
75 const float TUR_FLAG_SPLASH = 4; // can deal splash damage
76 const float TUR_FLAG_HITSCAN = 8; // hit scan
77 const float TUR_FLAG_MULTIGUN = 16; // multiple guns
78 const float TUR_FLAG_GUIDED = 32; // laser guided projectiles
79 const float TUR_FLAG_SLOWPROJ = 64; // turret fires slow projectiles
80 const float TUR_FLAG_MEDPROJ = 128; // turret fires medium projectiles
81 const float TUR_FLAG_FASTPROJ = 256; // turret fires fast projectiles
82 const float TUR_FLAG_PLAYER = 512; // can damage players
83 const float TUR_FLAG_MISSILE = 1024; // can damage missiles
84 const float TUR_FLAG_SUPPORT = 2048; // supports other units
85 const float TUR_FLAG_AMMOSOURCE = 4096; // can provide ammunition
86 const float TUR_FLAG_RECIEVETARGETS = 8192; // can recieve targets from external sources
87 const float TUR_FLAG_MOVE = 16384; // can move
88 const float TUR_FLAG_ROAM = 32768; // roams around if not attacking
89 const float TUR_FLAG_ISTURRET = 65536; // identifies this unit as a turret
90
91 // ammo types
92 #define ammo_flags currentammo
93 const float TFL_AMMO_NONE = 64; // doesn't use ammo
94 const float TFL_AMMO_ENERGY = 2; // uses power
95 const float TFL_AMMO_BULLETS = 4; // uses bullets
96 const float TFL_AMMO_ROCKETS = 8; // uses explosives
97 const float TFL_AMMO_RECHARGE = 16; // regenerates ammo
98 const float TFL_AMMO_RECIEVE = 32; // can recieve ammo from support units
99
100 // damage flags
101 .float damage_flags;
102 const float TFL_DMG_NO = 256; // doesn't take damage
103 const float TFL_DMG_YES = 2; // can be damaged
104 const float TFL_DMG_TEAM = 4; // can be damaged by teammates
105 const float TFL_DMG_RETALIATE = 8; // target attackers
106 const float TFL_DMG_RETALIATE_TEAM = 16; // target attackers, even if on same team
107 const float TFL_DMG_TARGETLOSS = 32; // loses target when damaged
108 const float TFL_DMG_AIMSHAKE = 64; // damage throws off aim
109 const float TFL_DMG_HEADSHAKE = 128; // damage shakes head
110 const float TFL_DMG_DEATH_NORESPAWN = 256; // no re-spawning
111
112 // spawn flags
113 const float TSF_SUSPENDED = 1;
114 const float TSF_TERRAINBASE = 2; // currently unused
115 const float TSF_NO_AMMO_REGEN = 4; // disable builtin ammo regeneration
116 const float TSF_NO_PATHBREAK = 8; // don't break path to chase enemies, will still fire at them if possible
117 const float TSL_NO_RESPAWN = 16; // don't re-spawn
118 const float TSL_ROAM = 32; // roam while idle
119
120 // send flags
121 const float TNSF_UPDATE       = 2;
122 const float TNSF_STATUS       = 4;
123 const float TNSF_SETUP        = 8;
124 const float TNSF_ANG          = 16;
125 const float TNSF_AVEL         = 32;
126 const float TNSF_MOVE         = 64;
127 .float anim_start_time;
128 const float TNSF_ANIM         = 128;
129
130 const float TNSF_FULL_UPDATE  = 16777215;
131
132
133 // entity properties of turretinfo:
134 .float turretid; // TUR_...
135 .string netname; // short name
136 .string turret_name; // human readable name
137 .float(float) turret_func; // m_...
138 .string mdl; // currently a copy of the model
139 .string model; // full name of model
140 .string head_model; // full name of tur_head model
141 .string cvar_basename; // TODO: deprecate!
142 .float spawnflags;
143 .vector mins, maxs; // turret hitbox size
144
145 // other useful macros
146 #define TUR_ACTION(turrettype,mrequest) (get_turretinfo(turrettype)).turret_func(mrequest)
147 #define TUR_NAME(turrettype) (get_turretinfo(turrettype)).turret_name
148
149 // =====================
150 //  Turret Registration
151 // =====================
152
153 float t_null(float dummy);
154 void register_turret(float id, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname);
155 void register_turrets_done();
156
157 const float TUR_MAXCOUNT = 24;
158 #define TUR_FIRST 1
159 float TUR_COUNT;
160 float TUR_LAST;
161
162 #define REGISTER_TURRET_2(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
163         float id; \
164         float func(float); \
165         void RegisterTurrets_##id() \
166         { \
167                 TUR_LAST = (id = TUR_FIRST + TUR_COUNT); \
168                 ++TUR_COUNT; \
169                 register_turret(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname); \
170         } \
171         ACCUMULATE_FUNCTION(RegisterTurrets, RegisterTurrets_##id)
172 #ifdef MENUQC
173 #define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
174         REGISTER_TURRET_2(TUR_##id,t_null,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
175 #else
176 #define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
177         REGISTER_TURRET_2(TUR_##id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
178 #endif
179
180 #define TUR_DUPECHECK(dupecheck,cvar) \
181         #ifndef dupecheck \
182                 #define dupecheck \
183                 float cvar; \
184         #else \
185                 #error DUPLICATE TURRET CVAR: cvar \
186         #endif
187
188 #define TUR_ADD_CVAR(turret,name) \
189                 TUR_DUPECHECK(TUR_CVAR_##turret##_##name, autocvar_g_turrets_unit_##turret##_##name)
190
191 #define TUR_CVAR(turret,name) autocvar_g_turrets_unit_##turret##_##name
192
193 #include "all.qh"
194
195 #undef TUR_ADD_CVAR
196 #undef REGISTER_TURRET
197 ACCUMULATE_FUNCTION(RegisterTurrets, register_turrets_done);