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