]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hlac.qc
1 #ifndef IMPLEMENTATION
2 CLASS(HLAC, Weapon)
3 /* ammotype  */ ATTRIB(HLAC, ammo_field, .int, ammo_cells)
4 /* impulse   */ ATTRIB(HLAC, impulse, int, 6)
5 /* flags     */ ATTRIB(HLAC, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
6 /* rating    */ ATTRIB(HLAC, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color     */ ATTRIB(HLAC, wpcolor, vector, '0 1 0');
8 /* modelname */ ATTRIB(HLAC, mdl, string, "hlac");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(HLAC, m_model, Model, MDL_HLAC_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(HLAC, w_crosshair, string, "gfx/crosshairhlac");
13 /* crosshair */ ATTRIB(HLAC, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(HLAC, model2, string, "weaponhlac");
15 /* refname   */ ATTRIB(HLAC, netname, string, "hlac");
16 /* wepname   */ ATTRIB(HLAC, m_name, string, _("Heavy Laser Assault Cannon"));
17
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, ammo, float, BOTH) \
21                 P(class, prefix, animtime, float, BOTH) \
22                 P(class, prefix, damage, float, BOTH) \
23                 P(class, prefix, edgedamage, float, BOTH) \
24                 P(class, prefix, force, float, BOTH) \
25                 P(class, prefix, lifetime, float, BOTH) \
26                 P(class, prefix, radius, float, BOTH) \
27                 P(class, prefix, refire, float, BOTH) \
28                 P(class, prefix, reload_ammo, float, NONE) \
29                 P(class, prefix, reload_time, float, NONE) \
30                 P(class, prefix, secondary, float, NONE) \
31                 P(class, prefix, shots, float, SEC) \
32                 P(class, prefix, speed, float, BOTH) \
33                 P(class, prefix, spread, float, SEC) \
34                 P(class, prefix, spread_add, float, PRI) \
35                 P(class, prefix, spread_crouchmod, float, BOTH) \
36                 P(class, prefix, spread_max, float, PRI) \
37                 P(class, prefix, spread_min, float, PRI) \
38                 P(class, prefix, switchdelay_drop, float, NONE) \
39                 P(class, prefix, switchdelay_raise, float, NONE) \
40                 P(class, prefix, weaponreplace, string,NONE) \
41                 P(class, prefix, weaponstartoverride, float, NONE) \
42                 P(class, prefix, weaponstart, float, NONE) \
43                 P(class, prefix, weaponthrowable, float, NONE) \
44         END()
45     W_PROPS(X, HLAC, hlac)
46 #undef X
47
48 ENDCLASS(HLAC)
49 REGISTER_WEAPON(HLAC, hlac, NEW(HLAC));
50
51
52 #endif
53 #ifdef IMPLEMENTATION
54 #ifdef SVQC
55 spawnfunc(weapon_hlac) { weapon_defaultspawnfunc(this, WEP_HLAC); }
56
57 void W_HLAC_Touch()
58 {SELFPARAM();
59         float isprimary;
60
61         PROJECTILE_TOUCH;
62
63         self.event_damage = func_null;
64
65         isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
66
67         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);
68
69         remove(self);
70 }
71
72 void W_HLAC_Attack(Weapon thiswep)
73 {SELFPARAM();
74         entity missile;
75     float spread;
76
77         W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(hlac, ammo));
78
79     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * self.misc_bulletcounter);
80     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
81     if(self.crouch)
82         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
83
84         W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
85         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
86         if(!autocvar_g_norecoil)
87         {
88                 self.punchangle_x = random() - 0.5;
89                 self.punchangle_y = random() - 0.5;
90         }
91
92         missile = new(hlacbolt);
93         missile.owner = missile.realowner = self;
94         missile.bot_dodge = true;
95
96     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
97
98         missile.movetype = MOVETYPE_FLY;
99         PROJECTILE_MAKETRIGGER(missile);
100
101         setorigin(missile, w_shotorg);
102         setsize(missile, '0 0 0', '0 0 0');
103
104         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
105         //missile.angles = vectoangles(missile.velocity); // csqc
106
107         missile.touch = W_HLAC_Touch;
108         missile.think = SUB_Remove_self;
109
110     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
111
112         missile.flags = FL_PROJECTILE;
113         missile.projectiledeathtype = WEP_HLAC.m_id;
114
115         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
116
117         MUTATOR_CALLHOOK(EditProjectile, self, missile);
118 }
119
120 void W_HLAC_Attack2()
121 {SELFPARAM();
122         entity missile;
123     float spread;
124
125     spread = WEP_CVAR_SEC(hlac, spread);
126
127
128     if(self.crouch)
129         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
130
131         W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
132         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
133
134         missile = new(hlacbolt);
135         missile.owner = missile.realowner = self;
136         missile.bot_dodge = true;
137
138     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
139
140         missile.movetype = MOVETYPE_FLY;
141         PROJECTILE_MAKETRIGGER(missile);
142
143         setorigin(missile, w_shotorg);
144         setsize(missile, '0 0 0', '0 0 0');
145
146         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
147         //missile.angles = vectoangles(missile.velocity); // csqc
148
149         missile.touch = W_HLAC_Touch;
150         missile.think = SUB_Remove_self;
151
152     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
153
154         missile.flags = FL_PROJECTILE;
155         missile.missile_flags = MIF_SPLASH;
156         missile.projectiledeathtype = WEP_HLAC.m_id | HITTYPE_SECONDARY;
157
158         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
159
160         MUTATOR_CALLHOOK(EditProjectile, self, missile);
161 }
162
163 // weapon frames
164 void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
165 {
166         if(PS(actor).m_weapon != PS(actor).m_switchweapon) // abort immediately if switching
167         {
168                 w_ready(thiswep, actor, weaponentity, fire);
169                 return;
170         }
171
172         if(actor.BUTTON_ATCK)
173         {
174                 if(!thiswep.wr_checkammo1(thiswep))
175                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
176                 {
177                         W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
178                         w_ready(thiswep, actor, weaponentity, fire);
179                         return;
180                 }
181
182                 int slot = weaponslot(weaponentity);
183                 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor();
184                 W_HLAC_Attack(WEP_HLAC);
185                 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
186         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
187         }
188         else
189         {
190                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
191         }
192 }
193
194 void W_HLAC_Attack2_Frame(Weapon thiswep)
195 {SELFPARAM();
196     float i;
197
198         W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hlac, ammo));
199
200     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
201         W_HLAC_Attack2();
202
203         if(!autocvar_g_norecoil)
204         {
205                 self.punchangle_x = random() - 0.5;
206                 self.punchangle_y = random() - 0.5;
207         }
208 }
209
210                 METHOD(HLAC, wr_aim, void(entity thiswep))
211                 {
212                         self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
213                 }
214                 METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
215                 {
216                         if(autocvar_g_balance_hlac_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) { // forced reload
217                                 thiswep.wr_reload(thiswep, actor, weaponentity);
218                         } else if(fire & 1)
219                         {
220                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hlac, refire)))
221                                 {
222                                         actor.misc_bulletcounter = 0;
223                                         W_HLAC_Attack(thiswep);
224                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
225                                 }
226                         }
227
228                         else if((fire & 2) && WEP_CVAR(hlac, secondary))
229                         {
230                                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hlac, refire)))
231                                 {
232                                         W_HLAC_Attack2_Frame(thiswep);
233                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
234                                 }
235                         }
236                 }
237                 METHOD(HLAC, wr_checkammo1, bool(entity thiswep))
238                 {
239                         float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_PRI(hlac, ammo);
240                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
241                         return ammo_amount;
242                 }
243                 METHOD(HLAC, wr_checkammo2, bool(entity thiswep))
244                 {
245                         float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_SEC(hlac, ammo);
246                         ammo_amount += self.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
247                         return ammo_amount;
248                 }
249                 METHOD(HLAC, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
250                 {
251                         W_Reload(self, min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), SND(RELOAD));
252                 }
253                 METHOD(HLAC, wr_suicidemessage, int(entity thiswep))
254                 {
255                         return WEAPON_HLAC_SUICIDE;
256                 }
257                 METHOD(HLAC, wr_killmessage, int(entity thiswep))
258                 {
259                         return WEAPON_HLAC_MURDER;
260                 }
261
262 #endif
263 #ifdef CSQC
264
265                 METHOD(HLAC, wr_impacteffect, void(entity thiswep))
266                 {
267                         vector org2;
268                         org2 = w_org + w_backoff * 6;
269                         pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
270                         if(!w_issilent)
271                                 sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
272                 }
273
274 #endif
275 #endif