]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hlac.qc
Set weapons to fully loaded on respawn in each weapon file instead of cl_client....
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hlac.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HLAC, w_hlac, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hlac", "hlac", _("Heavy Laser Assault Cannon"))
3 #else
4 #ifdef SVQC
5
6 void W_HLAC_SetAmmoCounter()
7 {
8         // set clip_load to the weapon we have switched to, if the gun uses reloading
9         if(!autocvar_g_balance_hlac_reload_ammo)
10                 self.clip_load = 0; // also keeps crosshair ammo from displaying
11         else
12         {
13                 self.clip_load = self.hlac_load;
14                 self.clip_size = autocvar_g_balance_hlac_reload_ammo; // for the crosshair ammo display
15         }
16 }
17
18 void W_HLAC_ReloadedAndReady()
19 {
20         float t;
21
22         // now do the ammo transfer
23         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
24         while(self.clip_load < autocvar_g_balance_hlac_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
25         {
26                 self.clip_load += 1;
27                 self.ammo_cells -= 1;
28         }
29         self.hlac_load = self.clip_load;
30
31         t = ATTACK_FINISHED(self) - autocvar_g_balance_hlac_reload_time - 1;
32         ATTACK_FINISHED(self) = t;
33         w_ready();
34 }
35
36 void W_HLAC_Reload()
37 {
38         // return if reloading is disabled for this weapon
39         if(!autocvar_g_balance_hlac_reload_ammo)
40                 return;
41
42         if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo)))
43                 return;
44
45         float t;
46
47         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
48
49         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_hlac_reload_time + 1;
50         ATTACK_FINISHED(self) = t;
51
52         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_hlac_reload_time, W_HLAC_ReloadedAndReady);
53
54         self.old_clip_load = self.clip_load;
55         self.clip_load = -1;
56 }
57
58 void W_HLAC_Touch (void)
59 {
60         PROJECTILE_TOUCH;
61
62         self.event_damage = SUB_Null;
63         
64         if(self.projectiledeathtype & HITTYPE_SECONDARY)
65                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_secondary_damage, autocvar_g_balance_hlac_secondary_edgedamage, autocvar_g_balance_hlac_secondary_radius, world, autocvar_g_balance_hlac_secondary_force, self.projectiledeathtype, other);
66         else
67                 RadiusDamage (self, self.owner, autocvar_g_balance_hlac_primary_damage, autocvar_g_balance_hlac_primary_edgedamage, autocvar_g_balance_hlac_primary_radius, world, autocvar_g_balance_hlac_primary_force, self.projectiledeathtype, other);
68
69         remove (self);
70 }
71
72 void W_HLAC_Attack (void)
73 {
74         local entity missile;
75     float spread;
76
77         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
78         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
79         {
80                 if(autocvar_g_balance_hlac_reload_ammo)
81                 {
82                         self.clip_load -= autocvar_g_balance_hlac_primary_ammo;
83                         self.hlac_load = self.clip_load;
84                 }
85                 else
86                         self.ammo_cells -= autocvar_g_balance_hlac_primary_ammo;
87         }
88
89     spread = autocvar_g_balance_hlac_primary_spread_min + (autocvar_g_balance_hlac_primary_spread_add * self.misc_bulletcounter);
90     spread = min(spread,autocvar_g_balance_hlac_primary_spread_max);
91     if(self.crouch)
92         spread = spread * autocvar_g_balance_hlac_primary_spread_crouchmod;
93
94         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_primary_damage);
95         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
96         if (!g_norecoil)
97         {
98                 self.punchangle_x = random () - 0.5;
99                 self.punchangle_y = random () - 0.5;
100         }
101
102         missile = spawn ();
103         missile.owner = self;
104         missile.classname = "hlacbolt";
105         missile.bot_dodge = TRUE;
106
107     missile.bot_dodgerating = autocvar_g_balance_hlac_primary_damage;
108
109         missile.movetype = MOVETYPE_FLY;
110         PROJECTILE_MAKETRIGGER(missile);
111
112         setorigin (missile, w_shotorg);
113         setsize(missile, '0 0 0', '0 0 0');
114
115         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_primary_speed, spread);
116         //missile.angles = vectoangles (missile.velocity); // csqc
117
118         missile.touch = W_HLAC_Touch;
119         missile.think = SUB_Remove;
120
121     missile.nextthink = time + autocvar_g_balance_hlac_primary_lifetime;
122
123         missile.flags = FL_PROJECTILE;
124         missile.projectiledeathtype = WEP_HLAC;
125
126         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
127
128         other = missile; MUTATOR_CALLHOOK(EditProjectile);
129 }
130
131 void W_HLAC_Attack2f (void)
132 {
133         local entity missile;
134     float spread;
135
136     spread = autocvar_g_balance_hlac_secondary_spread;
137
138
139     if(self.crouch)
140         spread = spread * autocvar_g_balance_hlac_secondary_spread_crouchmod;
141
142         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CHAN_WEAPON, autocvar_g_balance_hlac_secondary_damage);
143         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
144
145         missile = spawn ();
146         missile.owner = self;
147         missile.classname = "hlacbolt";
148         missile.bot_dodge = TRUE;
149
150     missile.bot_dodgerating = autocvar_g_balance_hlac_secondary_damage;
151
152         missile.movetype = MOVETYPE_FLY;
153         PROJECTILE_MAKETRIGGER(missile);
154
155         setorigin (missile, w_shotorg);
156         setsize(missile, '0 0 0', '0 0 0');
157
158         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_secondary_speed, spread);
159         //missile.angles = vectoangles (missile.velocity); // csqc
160
161         missile.touch = W_HLAC_Touch;
162         missile.think = SUB_Remove;
163
164     missile.nextthink = time + autocvar_g_balance_hlac_secondary_lifetime;
165
166         missile.flags = FL_PROJECTILE;
167         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
168
169         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
170
171         other = missile; MUTATOR_CALLHOOK(EditProjectile);
172 }
173
174 void W_HLAC_Attack2 (void)
175 {
176     float i;
177
178         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
179         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
180         {
181                 if(autocvar_g_balance_hlac_reload_ammo)
182                 {
183                         self.clip_load -= autocvar_g_balance_hlac_secondary_ammo;
184                         self.hlac_load = self.clip_load;
185                 }
186                 else
187                         self.ammo_cells -= autocvar_g_balance_hlac_secondary_ammo;
188         }
189
190     for(i=autocvar_g_balance_hlac_secondary_shots;i>0;--i)
191         W_HLAC_Attack2f();
192
193         if (!g_norecoil)
194         {
195                 self.punchangle_x = random () - 0.5;
196                 self.punchangle_y = random () - 0.5;
197         }
198 }
199
200 // weapon frames
201 void HLAC_fire1_02()
202 {
203         if(self.weapon != self.switchweapon) // abort immediately if switching
204         {
205                 w_ready();
206                 return;
207         }
208
209         if (self.BUTTON_ATCK)
210         {
211                 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
212                 {
213                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
214                         w_ready();
215                         return;
216                 }
217
218                 ATTACK_FINISHED(self) = time + autocvar_g_balance_hlac_primary_refire * W_WeaponRateFactor();
219                 W_HLAC_Attack();
220                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
221         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
222         }
223         else
224         {
225                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_animtime, w_ready);
226         }
227 };
228
229 void spawnfunc_weapon_hlac (void)
230 {
231         weapon_defaultspawnfunc(WEP_HLAC);
232 }
233
234 float w_hlac(float req)
235 {
236         float ammo_amount;
237         if (req == WR_AIM)
238         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hlac_primary_speed, 0, autocvar_g_balance_hlac_primary_lifetime, FALSE);
239         else if (req == WR_THINK)
240         {
241                 if(autocvar_g_balance_hlac_reload_ammo && self.clip_load < min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo)) // forced reload
242                         W_HLAC_Reload();
243                 else if (self.BUTTON_ATCK)
244                 {
245                         if (weapon_prepareattack(0, autocvar_g_balance_hlac_primary_refire))
246                         {
247                                 self.misc_bulletcounter = 0;
248                                 W_HLAC_Attack();
249                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
250                         }
251                 }
252
253                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hlac_secondary)
254                 {
255                         if (weapon_prepareattack(1, autocvar_g_balance_hlac_secondary_refire))
256                         {
257                                 W_HLAC_Attack2();
258                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hlac_secondary_animtime, w_ready);
259                         }
260                 }
261         }
262         else if (req == WR_PRECACHE)
263         {
264         precache_model ("models/weapons/g_hlac.md3");
265                 precache_model ("models/weapons/v_hlac.md3");
266                 precache_model ("models/weapons/h_hlac.iqm");
267                 precache_sound ("weapons/lasergun_fire.wav");
268                 precache_sound ("weapons/reload.wav");
269
270         }
271         else if (req == WR_SETUP)
272         {
273                 weapon_setup(WEP_HLAC);
274                 W_HLAC_SetAmmoCounter();
275         }
276         else if (req == WR_CHECKAMMO1)
277         {
278                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_primary_ammo;
279                 ammo_amount += (autocvar_g_balance_hlac_reload_ammo && self.hlac_load >= autocvar_g_balance_hlac_primary_ammo);
280                 return ammo_amount;
281         }
282         else if (req == WR_CHECKAMMO2)
283         {
284                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_secondary_ammo;
285                 ammo_amount += (autocvar_g_balance_hlac_reload_ammo && self.hlac_load >= autocvar_g_balance_hlac_secondary_ammo);
286                 return ammo_amount;
287         }
288         else if (req == WR_RESETPLAYER)
289         {
290                 // all weapons must be fully loaded when we spawn
291                 self.hlac_load = autocvar_g_balance_hlac_reload_ammo;
292         }
293         else if (req == WR_RELOAD)
294         {
295                 W_HLAC_Reload();
296         }
297         return TRUE;
298 };
299 #endif
300 #ifdef CSQC
301 float w_hlac(float req)
302 {
303         if(req == WR_IMPACTEFFECT)
304         {
305                 vector org2;
306                 org2 = w_org + w_backoff * 6;
307                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
308                 if(!w_issilent)
309                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
310         }
311         else if(req == WR_PRECACHE)
312         {
313                 precache_sound("weapons/laserimpact.wav");
314         }
315         else if (req == WR_SUICIDEMESSAGE)
316                 w_deathtypestring = "%s should have used a smaller gun";
317         else if (req == WR_KILLMESSAGE)
318                 w_deathtypestring = "%s was cut down by %s";
319         return TRUE;
320 }
321 #endif
322 #endif