Merge remote-tracking branch 'origin/master' into samual/spawn_weapons
[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_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "hlac", "hlac", _("Heavy Laser Assault Cannon"))
3 #else
4 #ifdef SVQC
5
6 void W_HLAC_Touch (void)
7 {
8         PROJECTILE_TOUCH;
9
10         self.event_damage = SUB_Null;
11         
12         if(self.projectiledeathtype & HITTYPE_SECONDARY)
13                 RadiusDamage (self, self.realowner, autocvar_g_balance_hlac_secondary_damage, autocvar_g_balance_hlac_secondary_edgedamage, autocvar_g_balance_hlac_secondary_radius, world, world, autocvar_g_balance_hlac_secondary_force, self.projectiledeathtype, other);
14         else
15                 RadiusDamage (self, self.realowner, autocvar_g_balance_hlac_primary_damage, autocvar_g_balance_hlac_primary_edgedamage, autocvar_g_balance_hlac_primary_radius, world, world, autocvar_g_balance_hlac_primary_force, self.projectiledeathtype, other);
16
17         remove (self);
18 }
19
20 void W_HLAC_Attack (void)
21 {
22         entity missile;
23     float spread;
24
25         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_reload_ammo);
26
27     spread = autocvar_g_balance_hlac_primary_spread_min + (autocvar_g_balance_hlac_primary_spread_add * self.misc_bulletcounter);
28     spread = min(spread,autocvar_g_balance_hlac_primary_spread_max);
29     if(self.crouch)
30         spread = spread * autocvar_g_balance_hlac_primary_spread_crouchmod;
31
32         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, autocvar_g_balance_hlac_primary_damage);
33         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
34         if (!g_norecoil)
35         {
36                 self.punchangle_x = random () - 0.5;
37                 self.punchangle_y = random () - 0.5;
38         }
39
40         missile = spawn ();
41         missile.owner = missile.realowner = self;
42         missile.classname = "hlacbolt";
43         missile.bot_dodge = TRUE;
44
45     missile.bot_dodgerating = autocvar_g_balance_hlac_primary_damage;
46
47         missile.movetype = MOVETYPE_FLY;
48         PROJECTILE_MAKETRIGGER(missile);
49
50         setorigin (missile, w_shotorg);
51         setsize(missile, '0 0 0', '0 0 0');
52
53         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_primary_speed, spread);
54         //missile.angles = vectoangles (missile.velocity); // csqc
55
56         missile.touch = W_HLAC_Touch;
57         missile.think = SUB_Remove;
58
59     missile.nextthink = time + autocvar_g_balance_hlac_primary_lifetime;
60
61         missile.flags = FL_PROJECTILE;
62         missile.projectiledeathtype = WEP_HLAC;
63
64         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
65
66         other = missile; MUTATOR_CALLHOOK(EditProjectile);
67 }
68
69 void W_HLAC_Attack2f (void)
70 {
71         entity missile;
72     float spread;
73
74     spread = autocvar_g_balance_hlac_secondary_spread;
75
76
77     if(self.crouch)
78         spread = spread * autocvar_g_balance_hlac_secondary_spread_crouchmod;
79
80         W_SetupShot (self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_A, autocvar_g_balance_hlac_secondary_damage);
81         pointparticles(particleeffectnum("laser_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
82
83         missile = spawn ();
84         missile.owner = missile.realowner = self;
85         missile.classname = "hlacbolt";
86         missile.bot_dodge = TRUE;
87
88     missile.bot_dodgerating = autocvar_g_balance_hlac_secondary_damage;
89
90         missile.movetype = MOVETYPE_FLY;
91         PROJECTILE_MAKETRIGGER(missile);
92
93         setorigin (missile, w_shotorg);
94         setsize(missile, '0 0 0', '0 0 0');
95
96         W_SetupProjectileVelocity(missile, autocvar_g_balance_hlac_secondary_speed, spread);
97         //missile.angles = vectoangles (missile.velocity); // csqc
98
99         missile.touch = W_HLAC_Touch;
100         missile.think = SUB_Remove;
101
102     missile.nextthink = time + autocvar_g_balance_hlac_secondary_lifetime;
103
104         missile.flags = FL_PROJECTILE;
105         missile.missile_flags = MIF_SPLASH; 
106         missile.projectiledeathtype = WEP_HLAC | HITTYPE_SECONDARY;
107
108         CSQCProjectile(missile, TRUE, PROJECTILE_HLAC, TRUE);
109
110         other = missile; MUTATOR_CALLHOOK(EditProjectile);
111 }
112
113 void W_HLAC_Attack2 (void)
114 {
115     float i;
116
117         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hlac_secondary_ammo, autocvar_g_balance_hlac_reload_ammo);
118
119     for(i=autocvar_g_balance_hlac_secondary_shots;i>0;--i)
120         W_HLAC_Attack2f();
121
122         if (!g_norecoil)
123         {
124                 self.punchangle_x = random () - 0.5;
125                 self.punchangle_y = random () - 0.5;
126         }
127 }
128
129 // weapon frames
130 void HLAC_fire1_02()
131 {
132         if(self.weapon != self.switchweapon) // abort immediately if switching
133         {
134                 w_ready();
135                 return;
136         }
137
138         if (self.BUTTON_ATCK)
139         {
140                 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
141                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
142                 {
143                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
144                         w_ready();
145                         return;
146                 }
147
148                 ATTACK_FINISHED(self) = time + autocvar_g_balance_hlac_primary_refire * W_WeaponRateFactor();
149                 W_HLAC_Attack();
150                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
151         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
152         }
153         else
154         {
155                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_animtime, w_ready);
156         }
157 }
158
159 void spawnfunc_weapon_hlac (void)
160 {
161         weapon_defaultspawnfunc(WEP_HLAC);
162 }
163
164 float w_hlac(float req)
165 {
166         float ammo_amount;
167         if (req == WR_AIM)
168         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_hlac_primary_speed, 0, autocvar_g_balance_hlac_primary_lifetime, FALSE);
169         else if (req == WR_THINK)
170         {
171                 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
172                         weapon_action(self.weapon, WR_RELOAD);
173                 else if (self.BUTTON_ATCK)
174                 {
175                         if (weapon_prepareattack(0, autocvar_g_balance_hlac_primary_refire))
176                         {
177                                 self.misc_bulletcounter = 0;
178                                 W_HLAC_Attack();
179                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hlac_primary_refire, HLAC_fire1_02);
180                         }
181                 }
182
183                 else if (self.BUTTON_ATCK2 && autocvar_g_balance_hlac_secondary)
184                 {
185                         if (weapon_prepareattack(1, autocvar_g_balance_hlac_secondary_refire))
186                         {
187                                 W_HLAC_Attack2();
188                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hlac_secondary_animtime, w_ready);
189                         }
190                 }
191         }
192         else if (req == WR_PRECACHE)
193         {
194         precache_model ("models/weapons/g_hlac.md3");
195                 precache_model ("models/weapons/v_hlac.md3");
196                 precache_model ("models/weapons/h_hlac.iqm");
197                 precache_sound ("weapons/lasergun_fire.wav");
198                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
199
200         }
201         else if (req == WR_SETUP)
202         {
203                 weapon_setup(WEP_HLAC);
204                 self.current_ammo = ammo_cells;
205         }
206         else if (req == WR_CHECKAMMO1)
207         {
208                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_primary_ammo;
209                 ammo_amount += self.(weapon_load[WEP_HLAC]) >= autocvar_g_balance_hlac_primary_ammo;
210                 return ammo_amount;
211         }
212         else if (req == WR_CHECKAMMO2)
213         {
214                 ammo_amount = self.ammo_cells >= autocvar_g_balance_hlac_secondary_ammo;
215                 ammo_amount += self.(weapon_load[WEP_HLAC]) >= autocvar_g_balance_hlac_secondary_ammo;
216                 return ammo_amount;
217         }
218         else if (req == WR_RELOAD)
219         {
220                 W_Reload(min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo), autocvar_g_balance_hlac_reload_ammo, autocvar_g_balance_hlac_reload_time, "weapons/reload.wav");
221         }
222         return TRUE;
223 }
224 #endif
225 #ifdef CSQC
226 float w_hlac(float req)
227 {
228         if(req == WR_IMPACTEFFECT)
229         {
230                 vector org2;
231                 org2 = w_org + w_backoff * 6;
232                 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
233                 if(!w_issilent)
234                         sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
235         }
236         else if(req == WR_PRECACHE)
237         {
238                 precache_sound("weapons/laserimpact.wav");
239         }
240         else if (req == WR_SUICIDEMESSAGE)
241                 w_deathtypestring = _("%s should have used a smaller gun");
242         else if (req == WR_KILLMESSAGE)
243                 w_deathtypestring = _("%s was cut down with a HLAC by %s");
244         return TRUE;
245 }
246 #endif
247 #endif