]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_vaporizer.qc
Some hook & nade stuff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_vaporizer.qc
1 #ifndef IMPLEMENTATION
2 REGISTER_WEAPON(
3 /* WEP_##id  */ VAPORIZER,
4 /* function  */ W_Vaporizer,
5 /* ammotype  */ ammo_cells,
6 /* impulse   */ 7,
7 /* flags     */ WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_FLAG_SUPERWEAPON | WEP_TYPE_HITSCAN,
8 /* rating    */ BOT_PICKUP_RATING_HIGH,
9 /* color     */ '0.5 1 1',
10 /* modelname */ "minstanex",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairminstanex 0.6",
13 /* wepimg    */ "weaponminstanex",
14 /* refname   */ "vaporizer",
15 /* wepname   */ _("Vaporizer")
16 );
17
18 #define VAPORIZER_SETTINGS(w_cvar,w_prop) VAPORIZER_SETTINGS_LIST(w_cvar, w_prop, VAPORIZER, vaporizer)
19 #define VAPORIZER_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, PRI, ammo) \
21         w_cvar(id, sn, PRI, animtime) \
22         w_cvar(id, sn, PRI, refire) \
23         w_cvar(id, sn, SEC, ammo) \
24         w_cvar(id, sn, SEC, animtime) \
25         w_cvar(id, sn, SEC, damage) \
26         w_cvar(id, sn, SEC, delay) \
27         w_cvar(id, sn, SEC, edgedamage) \
28         w_cvar(id, sn, SEC, force) \
29         w_cvar(id, sn, SEC, lifetime) \
30         w_cvar(id, sn, SEC, radius) \
31         w_cvar(id, sn, SEC, refire) \
32         w_cvar(id, sn, SEC, shotangle) \
33         w_cvar(id, sn, SEC, speed) \
34         w_cvar(id, sn, SEC, spread) \
35         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
36         w_prop(id, sn, float,  reloading_time, reload_time) \
37         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
38         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
39         w_prop(id, sn, string, weaponreplace, weaponreplace) \
40         w_prop(id, sn, float,  weaponstart, weaponstart) \
41         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
42         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
43
44 #ifdef SVQC
45 VAPORIZER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
46 .float vaporizer_lasthit;
47 .float jump_interval;
48 #endif
49 #endif
50 #ifdef IMPLEMENTATION
51 #ifdef SVQC
52 void spawnfunc_weapon_vaporizer(void) { weapon_defaultspawnfunc(WEP_VAPORIZER.m_id); }
53 void spawnfunc_weapon_minstanex(void) { spawnfunc_weapon_vaporizer(); }
54
55 void W_Vaporizer_Attack(void)
56 {
57         float flying;
58         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
59
60         W_SetupShot(self, true, 0, "", CH_WEAPON_A, 10000);
61         // handle sound separately so we can change the volume
62         // added bonus: no longer plays the strength sound (strength gives no bonus to instakill anyway)
63         sound (self, CH_WEAPON_A, W_Sound("minstanexfire"), VOL_BASE * 0.8, ATTEN_NORM);
64
65         yoda = 0;
66         damage_goodhits = 0;
67         FireRailgunBullet(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, 10000, 800, 0, 0, 0, 0, WEP_VAPORIZER.m_id);
68
69         if(yoda && flying)
70                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
71         if(damage_goodhits && self.vaporizer_lasthit)
72         {
73                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
74                 damage_goodhits = 0; // only every second time
75         }
76
77         self.vaporizer_lasthit = damage_goodhits;
78
79         Send_Effect(EFFECT_VORTEX_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
80
81         // teamcolor / hit beam effect
82         vector v;
83         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
84         switch(self.team)
85         {
86                 case NUM_TEAM_1:   // Red
87                         if(damage_goodhits)
88                                 Send_Effect(EFFECT_VAPORIZER_RED_HIT, w_shotorg, v, 1);
89                         else
90                                 Send_Effect(EFFECT_VAPORIZER_RED, w_shotorg, v, 1);
91                         break;
92                 case NUM_TEAM_2:   // Blue
93                         if(damage_goodhits)
94                                 Send_Effect(EFFECT_VAPORIZER_BLUE_HIT, w_shotorg, v, 1);
95                         else
96                                 Send_Effect(EFFECT_VAPORIZER_BLUE, w_shotorg, v, 1);
97                         break;
98                 case NUM_TEAM_3:   // Yellow
99                         if(damage_goodhits)
100                                 Send_Effect(EFFECT_VAPORIZER_YELLOW_HIT, w_shotorg, v, 1);
101                         else
102                                 Send_Effect(EFFECT_VAPORIZER_YELLOW, w_shotorg, v, 1);
103                         break;
104                 case NUM_TEAM_4:   // Pink
105                         if(damage_goodhits)
106                                 Send_Effect(EFFECT_VAPORIZER_PINK_HIT, w_shotorg, v, 1);
107                         else
108                                 Send_Effect(EFFECT_VAPORIZER_PINK, w_shotorg, v, 1);
109                         break;
110                 default:
111                         if(damage_goodhits)
112                                 Send_Effect_("TE_TEI_G3_HIT", w_shotorg, v, 1);
113                         else
114                                 Send_Effect_("TE_TEI_G3", w_shotorg, v, 1);
115                         break;
116         }
117
118         W_DecreaseAmmo(((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo)));
119 }
120
121 float W_Vaporizer(float req)
122 {
123         float ammo_amount;
124         float vaporizer_ammo;
125
126         // now multiple WR_s use this
127         vaporizer_ammo = ((g_instagib) ? 1 : WEP_CVAR_PRI(vaporizer, ammo));
128
129         switch(req)
130         {
131                 case WR_AIM:
132                 {
133                         if(self.WEP_AMMO(VAPORIZER) > 0)
134                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, false);
135                         else
136                                 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(vaporizer, speed), 0, WEP_CVAR_SEC(vaporizer, lifetime), false); // WEAPONTODO: replace with proper vaporizer cvars
137
138                         return true;
139                 }
140                 case WR_THINK:
141                 {
142                         // if the laser uses load, we also consider its ammo for reloading
143                         if(WEP_CVAR(vaporizer, reload_ammo) && WEP_CVAR_SEC(vaporizer, ammo) && self.clip_load < min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo))) // forced reload
144                                 WEP_ACTION(self.weapon, WR_RELOAD);
145                         else if(WEP_CVAR(vaporizer, reload_ammo) && self.clip_load < vaporizer_ammo) // forced reload
146                                 WEP_ACTION(self.weapon, WR_RELOAD);
147                         else if(self.BUTTON_ATCK)
148                         {
149                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(vaporizer, refire)))
150                                 {
151                                         W_Vaporizer_Attack();
152                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
153                                 }
154                         }
155                         else if(self.BUTTON_ATCK2)
156                         {
157                                 if(self.jump_interval <= time)
158                                 if(weapon_prepareattack(1, -1))
159                                 {
160                                         // handle refire manually, so that primary and secondary can be fired without conflictions (important for instagib)
161                                         self.jump_interval = time + WEP_CVAR_SEC(vaporizer, refire) * W_WeaponRateFactor();
162
163                                         // decrease ammo for the laser?
164                                         if(WEP_CVAR_SEC(vaporizer, ammo))
165                                                 W_DecreaseAmmo(WEP_CVAR_SEC(vaporizer, ammo));
166
167                                         // ugly instagib hack to reuse the fire mode of the laser
168                                         int oldwep = self.weapon; // we can't avoid this hack
169                                         self.weapon = WEP_BLASTER.m_id;
170                                         W_Blaster_Attack(
171                                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
172                                                 WEP_CVAR_SEC(vaporizer, shotangle),
173                                                 WEP_CVAR_SEC(vaporizer, damage),
174                                                 WEP_CVAR_SEC(vaporizer, edgedamage),
175                                                 WEP_CVAR_SEC(vaporizer, radius),
176                                                 WEP_CVAR_SEC(vaporizer, force),
177                                                 WEP_CVAR_SEC(vaporizer, speed),
178                                                 WEP_CVAR_SEC(vaporizer, spread),
179                                                 WEP_CVAR_SEC(vaporizer, delay),
180                                                 WEP_CVAR_SEC(vaporizer, lifetime)
181                                         );
182                                         self.weapon = oldwep;
183
184                                         // now do normal refire
185                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(vaporizer, animtime), w_ready);
186                                 }
187                         }
188
189                         return true;
190                 }
191                 case WR_INIT:
192                 {
193                         precache_model("models/nexflash.md3");
194                         precache_model(W_Model("g_minstanex.md3"));
195                         precache_model(W_Model("v_minstanex.md3"));
196                         precache_model(W_Model("h_minstanex.iqm"));
197                         precache_sound(W_Sound("minstanexfire"));
198                         precache_sound(W_Sound("nexwhoosh1"));
199                         precache_sound(W_Sound("nexwhoosh2"));
200                         precache_sound(W_Sound("nexwhoosh3"));
201                         //W_Blaster(WR_INIT); // Samual: Is this really the proper thing to do? Didn't we already run this previously?
202                         VAPORIZER_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
203                         return true;
204                 }
205                 case WR_SETUP:
206                 {
207                         self.ammo_field = WEP_AMMO(VAPORIZER);
208                         self.vaporizer_lasthit = 0;
209                         return true;
210                 }
211                 case WR_CHECKAMMO1:
212                 {
213                         ammo_amount = self.WEP_AMMO(VAPORIZER) >= vaporizer_ammo;
214                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= vaporizer_ammo;
215                         return ammo_amount;
216                 }
217                 case WR_CHECKAMMO2:
218                 {
219                         if(!WEP_CVAR_SEC(vaporizer, ammo))
220                                 return true;
221                         ammo_amount = self.WEP_AMMO(VAPORIZER) >= WEP_CVAR_SEC(vaporizer, ammo);
222                         ammo_amount += self.(weapon_load[WEP_VAPORIZER.m_id]) >= WEP_CVAR_SEC(vaporizer, ammo);
223                         return ammo_amount;
224                 }
225                 case WR_CONFIG:
226                 {
227                         VAPORIZER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
228                         return true;
229                 }
230                 case WR_RESETPLAYER:
231                 {
232                         self.vaporizer_lasthit = 0;
233                         return true;
234                 }
235                 case WR_RELOAD:
236                 {
237                         float used_ammo;
238                         if(WEP_CVAR_SEC(vaporizer, ammo))
239                                 used_ammo = min(vaporizer_ammo, WEP_CVAR_SEC(vaporizer, ammo));
240                         else
241                                 used_ammo = vaporizer_ammo;
242
243                         W_Reload(used_ammo, W_Sound("reload"));
244                         return true;
245                 }
246                 case WR_SUICIDEMESSAGE:
247                 {
248                         return WEAPON_THINKING_WITH_PORTALS;
249                 }
250                 case WR_KILLMESSAGE:
251                 {
252                         return WEAPON_VAPORIZER_MURDER;
253                 }
254         }
255         return false;
256 }
257 #endif
258 #ifdef CSQC
259 float W_Vaporizer(float req)
260 {
261         switch(req)
262         {
263                 case WR_IMPACTEFFECT:
264                 {
265                         vector org2;
266                         org2 = w_org + w_backoff * 6;
267                         if(w_deathtype & HITTYPE_SECONDARY)
268                         {
269                                 pointparticles(particleeffectnum(EFFECT_BLASTER_IMPACT), org2, w_backoff * 1000, 1);
270                                 if(!w_issilent) { sound(self, CH_SHOTS, W_Sound("laserimpact"), VOL_BASE, ATTN_NORM); }
271                         }
272                         else
273                         {
274                                 pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
275                                 if(!w_issilent) { sound(self, CH_SHOTS, W_Sound("neximpact"), VOL_BASE, ATTN_NORM); }
276                         }
277                         return true;
278                 }
279                 case WR_INIT:
280                 {
281                         precache_sound(W_Sound("laserimpact"));
282                         precache_sound(W_Sound("neximpact"));
283                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
284                         {
285                                 precache_pic("gfx/reticle_nex");
286                         }
287                         return true;
288                 }
289                 case WR_ZOOMRETICLE:
290                 {
291                         if(button_zoom || zoomscript_caught)
292                         {
293                                 reticle_image = "gfx/reticle_nex";
294                                 return true;
295                         }
296                         else
297                         {
298                                 // no weapon specific image for this weapon
299                                 return false;
300                         }
301                 }
302         }
303         return false;
304 }
305 #endif
306 #endif