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