]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
c3e9668addd0b38bc61f28168638cda7f69377f7
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hlac.qc
1 #ifndef IMPLEMENTATION
2 REGISTER_WEAPON(
3 /* WEP_##id  */ HLAC,
4 /* function  */ W_HLAC,
5 /* ammotype  */ ammo_cells,
6 /* impulse   */ 6,
7 /* flags     */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating    */ BOT_PICKUP_RATING_MID,
9 /* color     */ '0 1 0',
10 /* modelname */ "hlac",
11 /* model     */ MDL_HLAC_ITEM,
12 /* simplemdl */ "foobar",
13 /* crosshair */ "gfx/crosshairhlac 0.6",
14 /* wepimg    */ "weaponhlac",
15 /* refname   */ "hlac",
16 /* wepname   */ _("Heavy Laser Assault Cannon")
17 );
18
19 #define HLAC_SETTINGS(w_cvar,w_prop) HLAC_SETTINGS_LIST(w_cvar, w_prop, HLAC, hlac)
20 #define HLAC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
21         w_cvar(id, sn, BOTH, ammo) \
22         w_cvar(id, sn, BOTH, animtime) \
23         w_cvar(id, sn, BOTH, damage) \
24         w_cvar(id, sn, BOTH, edgedamage) \
25         w_cvar(id, sn, BOTH, force) \
26         w_cvar(id, sn, BOTH, lifetime) \
27         w_cvar(id, sn, BOTH, radius) \
28         w_cvar(id, sn, BOTH, refire) \
29         w_cvar(id, sn, BOTH, speed) \
30         w_cvar(id, sn, BOTH, spread_crouchmod) \
31         w_cvar(id, sn, PRI,  spread_add) \
32         w_cvar(id, sn, PRI,  spread_max) \
33         w_cvar(id, sn, PRI,  spread_min) \
34         w_cvar(id, sn, NONE, secondary) \
35         w_cvar(id, sn, SEC,  shots) \
36         w_cvar(id, sn, SEC,  spread) \
37         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
38         w_prop(id, sn, float,  reloading_time, reload_time) \
39         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
40         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
41         w_prop(id, sn, string, weaponreplace, weaponreplace) \
42         w_prop(id, sn, float,  weaponstart, weaponstart) \
43         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
44         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
45
46 #ifdef SVQC
47 HLAC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
48 #endif
49 #endif
50 #ifdef IMPLEMENTATION
51 #ifdef SVQC
52 void spawnfunc_weapon_hlac(void) { weapon_defaultspawnfunc(WEP_HLAC.m_id); }
53
54 void W_HLAC_Touch(void)
55 {SELFPARAM();
56         float isprimary;
57
58         PROJECTILE_TOUCH;
59
60         self.event_damage = func_null;
61
62         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
63
64         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);
65
66         remove(self);
67 }
68
69 void W_HLAC_Attack(void)
70 {SELFPARAM();
71         entity missile;
72     float spread;
73
74         W_DecreaseAmmo(WEP_CVAR_PRI(hlac, ammo));
75
76     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
77     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
78     if(self.crouch)
79         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
80
81         W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
82         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
83         if(!autocvar_g_norecoil)
84         {
85                 self.punchangle_x = random() - 0.5;
86                 self.punchangle_y = random() - 0.5;
87         }
88
89         missile = spawn();
90         missile.owner = missile.realowner = self;
91         missile.classname = "hlacbolt";
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;
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(void)
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 = spawn();
133         missile.owner = missile.realowner = self;
134         missile.classname = "hlacbolt";
135         missile.bot_dodge = true;
136
137     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
138
139         missile.movetype = MOVETYPE_FLY;
140         PROJECTILE_MAKETRIGGER(missile);
141
142         setorigin(missile, w_shotorg);
143         setsize(missile, '0 0 0', '0 0 0');
144
145         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
146         //missile.angles = vectoangles(missile.velocity); // csqc
147
148         missile.touch = W_HLAC_Touch;
149         missile.think = SUB_Remove;
150
151     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
152
153         missile.flags = FL_PROJECTILE;
154         missile.missile_flags = MIF_SPLASH;
155         missile.projectiledeathtype = WEP_HLAC.m_id | HITTYPE_SECONDARY;
156
157         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
158
159         MUTATOR_CALLHOOK(EditProjectile, self, missile);
160 }
161
162 // weapon frames
163 void W_HLAC_Attack_Frame(void)
164 {SELFPARAM();
165         if(self.weapon != self.switchweapon) // abort immediately if switching
166         {
167                 w_ready();
168                 return;
169         }
170
171         if(self.BUTTON_ATCK)
172         {
173                 if(!_WEP_ACTION(self.weapon, WR_CHECKAMMO1))
174                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
175                 {
176                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
177                         w_ready();
178                         return;
179                 }
180
181                 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
182                 W_HLAC_Attack();
183                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
184         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
185         }
186         else
187         {
188                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
189         }
190 }
191
192 void W_HLAC_Attack2_Frame(void)
193 {SELFPARAM();
194     float i;
195
196         W_DecreaseAmmo(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 bool W_HLAC(entity thiswep, int req)
209 {SELFPARAM();
210         float ammo_amount;
211         switch(req)
212         {
213                 case WR_AIM:
214                 {
215                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
216                         return true;
217                 }
218                 case WR_THINK:
219                 {
220                         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) // forced reload
221                                 _WEP_ACTION(self.weapon, WR_RELOAD);
222                         else if(self.BUTTON_ATCK)
223                         {
224                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(hlac, refire)))
225                                 {
226                                         self.misc_bulletcounter = 0;
227                                         W_HLAC_Attack();
228                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
229                                 }
230                         }
231
232                         else if(self.BUTTON_ATCK2 && WEP_CVAR(hlac, secondary))
233                         {
234                                 if(weapon_prepareattack(1, WEP_CVAR_SEC(hlac, refire)))
235                                 {
236                                         W_HLAC_Attack2_Frame();
237                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
238                                 }
239                         }
240
241                         return true;
242                 }
243                 case WR_INIT:
244                 {
245                         HLAC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
246                         return true;
247                 }
248                 case WR_CHECKAMMO1:
249                 {
250                         ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_PRI(hlac, ammo);
251                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
252                         return ammo_amount;
253                 }
254                 case WR_CHECKAMMO2:
255                 {
256                         ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_SEC(hlac, ammo);
257                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
258                         return ammo_amount;
259                 }
260                 case WR_CONFIG:
261                 {
262                         HLAC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
263                         return true;
264                 }
265                 case WR_RELOAD:
266                 {
267                         W_Reload(min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), SND(RELOAD));
268                         return true;
269                 }
270                 case WR_SUICIDEMESSAGE:
271                 {
272                         return WEAPON_HLAC_SUICIDE;
273                 }
274                 case WR_KILLMESSAGE:
275                 {
276                         return WEAPON_HLAC_MURDER;
277                 }
278         }
279         return false;
280 }
281 #endif
282 #ifdef CSQC
283 bool W_HLAC(entity thiswep, int req)
284 {SELFPARAM();
285         switch(req)
286         {
287                 case WR_IMPACTEFFECT:
288                 {
289                         vector org2;
290                         org2 = w_org + w_backoff * 6;
291                         pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), org2, w_backoff * 1000, 1);
292                         if(!w_issilent)
293                                 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
294
295                         return true;
296                 }
297                 case WR_INIT:
298                 {
299                         return true;
300                 }
301                 case WR_ZOOMRETICLE:
302                 {
303                         // no weapon specific image for this weapon
304                         return false;
305                 }
306         }
307         return false;
308 }
309 #endif
310 #endif