]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
Merge branch 'master' into TimePath/global_self
[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 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhlac 0.6",
13 /* wepimg    */ "weaponhlac",
14 /* refname   */ "hlac",
15 /* wepname   */ _("Heavy Laser Assault Cannon")
16 );
17
18 #define HLAC_SETTINGS(w_cvar,w_prop) HLAC_SETTINGS_LIST(w_cvar, w_prop, HLAC, hlac)
19 #define HLAC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, BOTH, ammo) \
21         w_cvar(id, sn, BOTH, animtime) \
22         w_cvar(id, sn, BOTH, damage) \
23         w_cvar(id, sn, BOTH, edgedamage) \
24         w_cvar(id, sn, BOTH, force) \
25         w_cvar(id, sn, BOTH, lifetime) \
26         w_cvar(id, sn, BOTH, radius) \
27         w_cvar(id, sn, BOTH, refire) \
28         w_cvar(id, sn, BOTH, speed) \
29         w_cvar(id, sn, BOTH, spread_crouchmod) \
30         w_cvar(id, sn, PRI,  spread_add) \
31         w_cvar(id, sn, PRI,  spread_max) \
32         w_cvar(id, sn, PRI,  spread_min) \
33         w_cvar(id, sn, NONE, secondary) \
34         w_cvar(id, sn, SEC,  shots) \
35         w_cvar(id, sn, SEC,  spread) \
36         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
37         w_prop(id, sn, float,  reloading_time, reload_time) \
38         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
39         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
40         w_prop(id, sn, string, weaponreplace, weaponreplace) \
41         w_prop(id, sn, float,  weaponstart, weaponstart) \
42         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
43         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
44
45 #ifdef SVQC
46 HLAC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
47 #endif
48 #endif
49 #ifdef IMPLEMENTATION
50 #ifdef SVQC
51 void spawnfunc_weapon_hlac(void) { weapon_defaultspawnfunc(WEP_HLAC.m_id); }
52
53 void W_HLAC_Touch(void)
54 {SELFPARAM();
55         float isprimary;
56
57         PROJECTILE_TOUCH;
58
59         self.event_damage = func_null;
60
61         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
62
63         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);
64
65         remove(self);
66 }
67
68 void W_HLAC_Attack(void)
69 {SELFPARAM();
70         entity missile;
71     float spread;
72
73         W_DecreaseAmmo(WEP_CVAR_PRI(hlac, ammo));
74
75     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
76     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
77     if(self.crouch)
78         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
79
80         W_SetupShot(self, false, 3, W_Sound("lasergun_fire"), CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
81         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
82         if(!autocvar_g_norecoil)
83         {
84                 self.punchangle_x = random() - 0.5;
85                 self.punchangle_y = random() - 0.5;
86         }
87
88         missile = spawn();
89         missile.owner = missile.realowner = self;
90         missile.classname = "hlacbolt";
91         missile.bot_dodge = true;
92
93     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
94
95         missile.movetype = MOVETYPE_FLY;
96         PROJECTILE_MAKETRIGGER(missile);
97
98         setorigin(missile, w_shotorg);
99         setsize(missile, '0 0 0', '0 0 0');
100
101         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
102         //missile.angles = vectoangles(missile.velocity); // csqc
103
104         missile.touch = W_HLAC_Touch;
105         missile.think = SUB_Remove;
106
107     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
108
109         missile.flags = FL_PROJECTILE;
110         missile.projectiledeathtype = WEP_HLAC.m_id;
111
112         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
113
114         MUTATOR_CALLHOOK(EditProjectile, self, missile);
115 }
116
117 void W_HLAC_Attack2(void)
118 {SELFPARAM();
119         entity missile;
120     float spread;
121
122     spread = WEP_CVAR_SEC(hlac, spread);
123
124
125     if(self.crouch)
126         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
127
128         W_SetupShot(self, false, 3, W_Sound("lasergun_fire"), CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
129         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
130
131         missile = spawn();
132         missile.owner = missile.realowner = self;
133         missile.classname = "hlacbolt";
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;
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(void)
163 {SELFPARAM();
164         if(self.weapon != self.switchweapon) // abort immediately if switching
165         {
166                 w_ready();
167                 return;
168         }
169
170         if(self.BUTTON_ATCK)
171         {
172                 if(!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
173                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
174                 {
175                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
176                         w_ready();
177                         return;
178                 }
179
180                 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
181                 W_HLAC_Attack();
182                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
183         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
184         }
185         else
186         {
187                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
188         }
189 }
190
191 void W_HLAC_Attack2_Frame(void)
192 {SELFPARAM();
193     float i;
194
195         W_DecreaseAmmo(WEP_CVAR_SEC(hlac, ammo));
196
197     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
198         W_HLAC_Attack2();
199
200         if(!autocvar_g_norecoil)
201         {
202                 self.punchangle_x = random() - 0.5;
203                 self.punchangle_y = random() - 0.5;
204         }
205 }
206
207 bool W_HLAC(int req)
208 {SELFPARAM();
209         float ammo_amount;
210         switch(req)
211         {
212                 case WR_AIM:
213                 {
214                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
215                         return true;
216                 }
217                 case WR_THINK:
218                 {
219                         if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) // forced reload
220                                 WEP_ACTION(self.weapon, WR_RELOAD);
221                         else if(self.BUTTON_ATCK)
222                         {
223                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(hlac, refire)))
224                                 {
225                                         self.misc_bulletcounter = 0;
226                                         W_HLAC_Attack();
227                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
228                                 }
229                         }
230
231                         else if(self.BUTTON_ATCK2 && WEP_CVAR(hlac, secondary))
232                         {
233                                 if(weapon_prepareattack(1, WEP_CVAR_SEC(hlac, refire)))
234                                 {
235                                         W_HLAC_Attack2_Frame();
236                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
237                                 }
238                         }
239
240                         return true;
241                 }
242                 case WR_INIT:
243                 {
244                         precache_model(W_Model("g_hlac.md3"));
245                         precache_model(W_Model("v_hlac.md3"));
246                         precache_model(W_Model("h_hlac.iqm"));
247                         precache_sound(W_Sound("lasergun_fire"));
248                         HLAC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
249                         return true;
250                 }
251                 case WR_CHECKAMMO1:
252                 {
253                         ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_PRI(hlac, ammo);
254                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
255                         return ammo_amount;
256                 }
257                 case WR_CHECKAMMO2:
258                 {
259                         ammo_amount = self.WEP_AMMO(HLAC) >= WEP_CVAR_SEC(hlac, ammo);
260                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
261                         return ammo_amount;
262                 }
263                 case WR_CONFIG:
264                 {
265                         HLAC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
266                         return true;
267                 }
268                 case WR_RELOAD:
269                 {
270                         W_Reload(min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), W_Sound("reload"));
271                         return true;
272                 }
273                 case WR_SUICIDEMESSAGE:
274                 {
275                         return WEAPON_HLAC_SUICIDE;
276                 }
277                 case WR_KILLMESSAGE:
278                 {
279                         return WEAPON_HLAC_MURDER;
280                 }
281         }
282         return false;
283 }
284 #endif
285 #ifdef CSQC
286 bool W_HLAC(int req)
287 {SELFPARAM();
288         switch(req)
289         {
290                 case WR_IMPACTEFFECT:
291                 {
292                         vector org2;
293                         org2 = w_org + w_backoff * 6;
294                         pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), org2, w_backoff * 1000, 1);
295                         if(!w_issilent)
296                                 sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTN_NORM);
297
298                         return true;
299                 }
300                 case WR_INIT:
301                 {
302                         precache_sound(W_Sound("laserimpact"));
303                         return true;
304                 }
305                 case WR_ZOOMRETICLE:
306                 {
307                         // no weapon specific image for this weapon
308                         return false;
309                 }
310         }
311         return false;
312 }
313 #endif
314 #endif