]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
Weapons: require explicit `Weapons_from` call
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hlac.qc
1 #ifndef IMPLEMENTATION
2 CLASS(HLAC, Weapon)
3 /* ammotype  */ ATTRIB(HLAC, ammo_field, .int, ammo_cells)
4 /* impulse   */ ATTRIB(HLAC, impulse, int, 6)
5 /* flags     */ ATTRIB(HLAC, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
6 /* rating    */ ATTRIB(HLAC, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color     */ ATTRIB(HLAC, wpcolor, vector, '0 1 0');
8 /* modelname */ ATTRIB(HLAC, mdl, string, "hlac");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(HLAC, m_model, Model, MDL_HLAC_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(HLAC, w_crosshair, string, "gfx/crosshairhlac");
13 /* crosshair */ ATTRIB(HLAC, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(HLAC, model2, string, "weaponhlac");
15 /* refname   */ ATTRIB(HLAC, netname, string, "hlac");
16 /* wepname   */ ATTRIB(HLAC, m_name, string, _("Heavy Laser Assault Cannon"));
17 ENDCLASS(HLAC)
18 REGISTER_WEAPON(HLAC, NEW(HLAC));
19
20 #define HLAC_SETTINGS(w_cvar,w_prop) HLAC_SETTINGS_LIST(w_cvar, w_prop, HLAC, hlac)
21 #define HLAC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, BOTH, ammo) \
23         w_cvar(id, sn, BOTH, animtime) \
24         w_cvar(id, sn, BOTH, damage) \
25         w_cvar(id, sn, BOTH, edgedamage) \
26         w_cvar(id, sn, BOTH, force) \
27         w_cvar(id, sn, BOTH, lifetime) \
28         w_cvar(id, sn, BOTH, radius) \
29         w_cvar(id, sn, BOTH, refire) \
30         w_cvar(id, sn, BOTH, speed) \
31         w_cvar(id, sn, BOTH, spread_crouchmod) \
32         w_cvar(id, sn, PRI,  spread_add) \
33         w_cvar(id, sn, PRI,  spread_max) \
34         w_cvar(id, sn, PRI,  spread_min) \
35         w_cvar(id, sn, NONE, secondary) \
36         w_cvar(id, sn, SEC,  shots) \
37         w_cvar(id, sn, SEC,  spread) \
38         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
39         w_prop(id, sn, float,  reloading_time, reload_time) \
40         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
41         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
42         w_prop(id, sn, string, weaponreplace, weaponreplace) \
43         w_prop(id, sn, float,  weaponstart, weaponstart) \
44         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
45         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
46
47 #ifdef SVQC
48 HLAC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
49 #endif
50 #endif
51 #ifdef IMPLEMENTATION
52 #ifdef SVQC
53 spawnfunc(weapon_hlac) { weapon_defaultspawnfunc(this, WEP_HLAC); }
54
55 void W_HLAC_Touch()
56 {SELFPARAM();
57         float isprimary;
58
59         PROJECTILE_TOUCH;
60
61         self.event_damage = func_null;
62
63         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
64
65         RadiusDamage(self, self.realowner, WEP_CVAR_BOTH(hlac, isprimary, damage), WEP_CVAR_BOTH(hlac, isprimary, edgedamage), WEP_CVAR_BOTH(hlac, isprimary, radius), world, world, WEP_CVAR_BOTH(hlac, isprimary, force), self.projectiledeathtype, other);
66
67         remove(self);
68 }
69
70 void W_HLAC_Attack(Weapon thiswep)
71 {SELFPARAM();
72         entity missile;
73     float spread;
74
75         W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(hlac, ammo));
76
77     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
78     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
79     if(self.crouch)
80         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
81
82         W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
83         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
84         if(!autocvar_g_norecoil)
85         {
86                 self.punchangle_x = random() - 0.5;
87                 self.punchangle_y = random() - 0.5;
88         }
89
90         missile = new(hlacbolt);
91         missile.owner = missile.realowner = self;
92         missile.bot_dodge = true;
93
94     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
95
96         missile.movetype = MOVETYPE_FLY;
97         PROJECTILE_MAKETRIGGER(missile);
98
99         setorigin(missile, w_shotorg);
100         setsize(missile, '0 0 0', '0 0 0');
101
102         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
103         //missile.angles = vectoangles(missile.velocity); // csqc
104
105         missile.touch = W_HLAC_Touch;
106         missile.think = SUB_Remove_self;
107
108     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
109
110         missile.flags = FL_PROJECTILE;
111         missile.projectiledeathtype = WEP_HLAC.m_id;
112
113         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
114
115         MUTATOR_CALLHOOK(EditProjectile, self, missile);
116 }
117
118 void W_HLAC_Attack2()
119 {SELFPARAM();
120         entity missile;
121     float spread;
122
123     spread = WEP_CVAR_SEC(hlac, spread);
124
125
126     if(self.crouch)
127         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
128
129         W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
130         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
131
132         missile = new(hlacbolt);
133         missile.owner = missile.realowner = self;
134         missile.bot_dodge = true;
135
136     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
137
138         missile.movetype = MOVETYPE_FLY;
139         PROJECTILE_MAKETRIGGER(missile);
140
141         setorigin(missile, w_shotorg);
142         setsize(missile, '0 0 0', '0 0 0');
143
144         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
145         //missile.angles = vectoangles(missile.velocity); // csqc
146
147         missile.touch = W_HLAC_Touch;
148         missile.think = SUB_Remove_self;
149
150     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
151
152         missile.flags = FL_PROJECTILE;
153         missile.missile_flags = MIF_SPLASH;
154         missile.projectiledeathtype = WEP_HLAC.m_id | HITTYPE_SECONDARY;
155
156         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
157
158         MUTATOR_CALLHOOK(EditProjectile, self, missile);
159 }
160
161 // weapon frames
162 void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
163 {
164         if(actor.weapon != actor.switchweapon) // abort immediately if switching
165         {
166                 w_ready(thiswep, actor, weaponentity, fire);
167                 return;
168         }
169
170         if(actor.BUTTON_ATCK)
171         {
172                 if(!thiswep.wr_checkammo1(thiswep))
173                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
174                 {
175                         W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
176                         w_ready(thiswep, actor, weaponentity, fire);
177                         return;
178                 }
179
180                 int slot = weaponslot(weaponentity);
181                 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
182                 W_HLAC_Attack(WEP_HLAC);
183                 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
184         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
185         }
186         else
187         {
188                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
189         }
190 }
191
192 void W_HLAC_Attack2_Frame(Weapon thiswep)
193 {SELFPARAM();
194     float i;
195
196         W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hlac, ammo));
197
198     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
199         W_HLAC_Attack2();
200
201         if(!autocvar_g_norecoil)
202         {
203                 self.punchangle_x = random() - 0.5;
204                 self.punchangle_y = random() - 0.5;
205         }
206 }
207
208                 METHOD(HLAC, wr_aim, void(entity thiswep))
209                 {
210                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
211                 }
212                 METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
213                 {
214                         if(autocvar_g_balance_hlac_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) { // forced reload
215                                 thiswep.wr_reload(thiswep);
216                         } else if(fire & 1)
217                         {
218                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hlac, refire)))
219                                 {
220                                         actor.misc_bulletcounter = 0;
221                                         W_HLAC_Attack(thiswep);
222                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
223                                 }
224                         }
225
226                         else if((fire & 2) && WEP_CVAR(hlac, secondary))
227                         {
228                                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hlac, refire)))
229                                 {
230                                         W_HLAC_Attack2_Frame(thiswep);
231                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
232                                 }
233                         }
234                 }
235                 METHOD(HLAC, wr_init, void(entity thiswep))
236                 {
237                         HLAC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
238                 }
239                 METHOD(HLAC, wr_checkammo1, bool(entity thiswep))
240                 {
241                         float ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_PRI(hlac, ammo);
242                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
243                         return ammo_amount;
244                 }
245                 METHOD(HLAC, wr_checkammo2, bool(entity thiswep))
246                 {
247                         float ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_SEC(hlac, ammo);
248                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
249                         return ammo_amount;
250                 }
251                 METHOD(HLAC, wr_config, void(entity thiswep))
252                 {
253                         HLAC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
254                 }
255                 METHOD(HLAC, wr_reload, void(entity thiswep))
256                 {
257                         W_Reload(self, min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), SND(RELOAD));
258                 }
259                 METHOD(HLAC, wr_suicidemessage, int(entity thiswep))
260                 {
261                         return WEAPON_HLAC_SUICIDE;
262                 }
263                 METHOD(HLAC, wr_killmessage, int(entity thiswep))
264                 {
265                         return WEAPON_HLAC_MURDER;
266                 }
267
268 #endif
269 #ifdef CSQC
270
271                 METHOD(HLAC, wr_impacteffect, void(entity thiswep))
272                 {
273                         vector org2;
274                         org2 = w_org + w_backoff * 6;
275                         pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
276                         if(!w_issilent)
277                                 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
278                 }
279
280 #endif
281 #endif