]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/vortex.qc
Weapons: add a second .weaponentity
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / vortex.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Vortex, Weapon)
3 /* ammotype  */ ATTRIB(Vortex, ammo_field, .int, ammo_cells)
4 /* impulse   */ ATTRIB(Vortex, impulse, int, 7)
5 /* flags     */ ATTRIB(Vortex, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
6 /* rating    */ ATTRIB(Vortex, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color     */ ATTRIB(Vortex, wpcolor, vector, '0.5 1 1');
8 /* modelname */ ATTRIB(Vortex, mdl, string, "nex");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(Vortex, m_model, Model, MDL_VORTEX_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(Vortex, w_crosshair, string, "gfx/crosshairnex");
13 /* crosshair */ ATTRIB(Vortex, w_crosshair_size, float, 0.65);
14 /* wepimg    */ ATTRIB(Vortex, model2, string, "weaponnex");
15 /* refname   */ ATTRIB(Vortex, netname, string, "vortex");
16 /* wepname   */ ATTRIB(Vortex, message, string, _("Vortex"));
17 ENDCLASS(Vortex)
18 REGISTER_WEAPON(VORTEX, NEW(Vortex));
19
20 #define VORTEX_SETTINGS(w_cvar,w_prop) VORTEX_SETTINGS_LIST(w_cvar, w_prop, VORTEX, vortex)
21 #define VORTEX_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, BOTH, ammo) \
23         w_cvar(id, sn, BOTH, animtime) \
24         w_cvar(id, sn, BOTH, damage) \
25         w_cvar(id, sn, BOTH, force) \
26         w_cvar(id, sn, BOTH, damagefalloff_mindist) \
27         w_cvar(id, sn, BOTH, damagefalloff_maxdist) \
28         w_cvar(id, sn, BOTH, damagefalloff_halflife) \
29         w_cvar(id, sn, BOTH, damagefalloff_forcehalflife) \
30         w_cvar(id, sn, BOTH, refire) \
31         w_cvar(id, sn, NONE, charge) \
32         w_cvar(id, sn, NONE, charge_mindmg) \
33         w_cvar(id, sn, NONE, charge_shot_multiplier) \
34         w_cvar(id, sn, NONE, charge_animlimit) \
35         w_cvar(id, sn, NONE, charge_limit) \
36         w_cvar(id, sn, NONE, charge_rate) \
37         w_cvar(id, sn, NONE, charge_rot_rate) \
38         w_cvar(id, sn, NONE, charge_rot_pause) \
39         w_cvar(id, sn, NONE, charge_start) \
40         w_cvar(id, sn, NONE, charge_minspeed) \
41         w_cvar(id, sn, NONE, charge_maxspeed) \
42         w_cvar(id, sn, NONE, charge_velocity_rate) \
43         w_cvar(id, sn, NONE, secondary) \
44         w_cvar(id, sn, SEC,  chargepool) \
45         w_cvar(id, sn, SEC,  chargepool_regen) \
46         w_cvar(id, sn, SEC,  chargepool_pause_regen) \
47         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
48         w_prop(id, sn, float,  reloading_time, reload_time) \
49         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
50         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
51         w_prop(id, sn, string, weaponreplace, weaponreplace) \
52         w_prop(id, sn, float,  weaponstart, weaponstart) \
53         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
54         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
55
56 #ifdef SVQC
57 VORTEX_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
58
59 .float vortex_lasthit;
60 #endif
61 #endif
62 #ifdef IMPLEMENTATION
63 #ifdef SVQC
64 spawnfunc(weapon_vortex) { weapon_defaultspawnfunc(WEP_VORTEX.m_id); }
65 spawnfunc(weapon_nex) { spawnfunc_weapon_vortex(this); }
66
67 void SendCSQCVortexBeamParticle(float charge) {
68         vector v;
69         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
70         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
71         WriteByte(MSG_BROADCAST, TE_CSQC_VORTEXBEAMPARTICLE);
72         WriteCoord(MSG_BROADCAST, w_shotorg.x);
73         WriteCoord(MSG_BROADCAST, w_shotorg.y);
74         WriteCoord(MSG_BROADCAST, w_shotorg.z);
75         WriteCoord(MSG_BROADCAST, v.x);
76         WriteCoord(MSG_BROADCAST, v.y);
77         WriteCoord(MSG_BROADCAST, v.z);
78         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
79 }
80
81 void W_Vortex_Attack(Weapon thiswep, float issecondary)
82 {SELFPARAM();
83         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
84
85         mydmg = WEP_CVAR_BOTH(vortex, !issecondary, damage);
86         myforce = WEP_CVAR_BOTH(vortex, !issecondary, force);
87         mymindist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_mindist);
88         mymaxdist = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_maxdist);
89         myhalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_halflife);
90         myforcehalflife = WEP_CVAR_BOTH(vortex, !issecondary, damagefalloff_forcehalflife);
91         myammo = WEP_CVAR_BOTH(vortex, !issecondary, ammo);
92
93         float flying;
94         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
95
96         if(WEP_CVAR(vortex, charge))
97         {
98                 charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * self.vortex_charge;
99                 self.vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce
100                 // O RLY? -- divVerent
101                 // YA RLY -- FruitieX
102         }
103         else
104                 charge = 1;
105         mydmg *= charge;
106         myforce *= charge;
107
108         W_SetupShot(self, true, 5, SND(NEXFIRE), CH_WEAPON_A, mydmg);
109         if(charge > WEP_CVAR(vortex, charge_animlimit) && WEP_CVAR(vortex, charge_animlimit)) // if the Vortex is overcharged, we play an extra sound
110         {
111                 sound(self, CH_WEAPON_B, SND_NEXCHARGE, VOL_BASE * (charge - 0.5 * WEP_CVAR(vortex, charge_animlimit)) / (1 - 0.5 * WEP_CVAR(vortex, charge_animlimit)), ATTN_NORM);
112         }
113
114         yoda = 0;
115         damage_goodhits = 0;
116         FireRailgunBullet(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_VORTEX.m_id);
117
118         if(yoda && flying)
119                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
120         if(damage_goodhits && self.vortex_lasthit)
121         {
122                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
123                 damage_goodhits = 0; // only every second time
124         }
125
126         self.vortex_lasthit = damage_goodhits;
127
128         //beam and muzzle flash done on client
129         SendCSQCVortexBeamParticle(charge);
130
131         W_DecreaseAmmo(thiswep, self, myammo);
132 }
133
134 .float vortex_chargepool_pauseregen_finished;
135
136                 METHOD(Vortex, wr_aim, void(entity thiswep))
137                 {
138                         if(bot_aim(1000000, 0, 1, false))
139                                 self.BUTTON_ATCK = true;
140                         else
141                         {
142                                 if(WEP_CVAR(vortex, charge))
143                                         self.BUTTON_ATCK2 = true;
144                         }
145                 }
146                 METHOD(Vortex, wr_think, void(entity thiswep, entity actor, int slot, int fire))
147                 {
148                         if(WEP_CVAR(vortex, charge) && actor.vortex_charge < WEP_CVAR(vortex, charge_limit))
149                                 actor.vortex_charge = min(1, actor.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME);
150
151                         if(WEP_CVAR_SEC(vortex, chargepool))
152                                 if(actor.vortex_chargepool_ammo < 1)
153                                 {
154                                         if(actor.vortex_chargepool_pauseregen_finished < time)
155                                                 actor.vortex_chargepool_ammo = min(1, actor.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME);
156                                         actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen));
157                                 }
158
159                         if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload
160                                 Weapon w = get_weaponinfo(actor.weapon);
161                                 w.wr_reload(w);
162                         } else
163                         {
164                                 if(fire & 1)
165                                 {
166                                         if(weapon_prepareattack(thiswep, actor, slot, false, WEP_CVAR_PRI(vortex, refire)))
167                                         {
168                                                 W_Vortex_Attack(thiswep, 0);
169                                                 weapon_thinkf(actor, slot, WFRAME_FIRE1, WEP_CVAR_PRI(vortex, animtime), w_ready);
170                                         }
171                                 }
172                                 if((WEP_CVAR(vortex, charge) && !WEP_CVAR(vortex, secondary)) ? (actor.BUTTON_ZOOM | actor.BUTTON_ZOOMSCRIPT) : (fire & 2))
173                                 {
174                                         if(WEP_CVAR(vortex, charge))
175                                         {
176                                                 actor.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause);
177                                                 float dt = frametime / W_TICSPERFRAME;
178
179                                                 if(actor.vortex_charge < 1)
180                                                 {
181                                                         if(WEP_CVAR_SEC(vortex, chargepool))
182                                                         {
183                                                                 if(WEP_CVAR_SEC(vortex, ammo))
184                                                                 {
185                                                                         // always deplete if secondary is held
186                                                                         actor.vortex_chargepool_ammo = max(0, actor.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt);
187
188                                                                         dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
189                                                                         actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen);
190                                                                         dt = min(dt, actor.vortex_chargepool_ammo);
191                                                                         dt = max(0, dt);
192
193                                                                         actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
194                                                                 }
195                                                         }
196
197                                                         else if(WEP_CVAR_SEC(vortex, ammo))
198                                                         {
199                                                                 if(fire & 2) // only eat ammo when the button is pressed
200                                                                 {
201                                                                         dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
202                                                                         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
203                                                                         {
204                                                                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
205                                                                                 if(autocvar_g_balance_vortex_reload_ammo)
206                                                                                 {
207                                                                                         dt = min(dt, (actor.clip_load - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
208                                                                                         dt = max(0, dt);
209                                                                                         if(dt > 0)
210                                                                                         {
211                                                                                                 actor.clip_load = max(WEP_CVAR_SEC(vortex, ammo), actor.clip_load - WEP_CVAR_SEC(vortex, ammo) * dt);
212                                                                                         }
213                                                                                         actor.(weapon_load[WEP_VORTEX.m_id]) = actor.clip_load;
214                                                                                 }
215                                                                                 else
216                                                                                 {
217                                                                                         dt = min(dt, (actor.WEP_AMMO(VORTEX) - WEP_CVAR_PRI(vortex, ammo)) / WEP_CVAR_SEC(vortex, ammo));
218                                                                                         dt = max(0, dt);
219                                                                                         if(dt > 0)
220                                                                                         {
221                                                                                                 actor.WEP_AMMO(VORTEX) = max(WEP_CVAR_SEC(vortex, ammo), actor.WEP_AMMO(VORTEX) - WEP_CVAR_SEC(vortex, ammo) * dt);
222                                                                                         }
223                                                                                 }
224                                                                         }
225                                                                         actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
226                                                                 }
227                                                         }
228
229                                                         else
230                                                         {
231                                                                 dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate));
232                                                                 actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate);
233                                                         }
234                                                 }
235                                         }
236                                         else if(WEP_CVAR(vortex, secondary))
237                                         {
238                                                 if(weapon_prepareattack(thiswep, actor, slot, false, WEP_CVAR_SEC(vortex, refire)))
239                                                 {
240                                                         W_Vortex_Attack(thiswep, 1);
241                                                         weapon_thinkf(actor, slot, WFRAME_FIRE1, WEP_CVAR_SEC(vortex, animtime), w_ready);
242                                                 }
243                                         }
244                                 }
245                         }
246                 }
247                 METHOD(Vortex, wr_init, void(entity thiswep))
248                 {
249                         VORTEX_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
250                 }
251                 METHOD(Vortex, wr_setup, void(entity thiswep))
252                 {
253                         self.vortex_lasthit = 0;
254                 }
255                 METHOD(Vortex, wr_checkammo1, bool(entity thiswep))
256                 {
257                         float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_PRI(vortex, ammo);
258                         ammo_amount += (autocvar_g_balance_vortex_reload_ammo && self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_PRI(vortex, ammo));
259                         return ammo_amount;
260                 }
261                 METHOD(Vortex, wr_checkammo2, bool(entity thiswep))
262                 {
263                         if(WEP_CVAR(vortex, secondary))
264                         {
265                                 // don't allow charging if we don't have enough ammo
266                                 float ammo_amount = self.WEP_AMMO(VORTEX) >= WEP_CVAR_SEC(vortex, ammo);
267                                 ammo_amount += self.(weapon_load[WEP_VORTEX.m_id]) >= WEP_CVAR_SEC(vortex, ammo);
268                                 return ammo_amount;
269                         }
270                         else
271                         {
272                                 return false; // zoom is not a fire mode
273                         }
274                 }
275                 METHOD(Vortex, wr_config, void(entity thiswep))
276                 {
277                         VORTEX_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
278                 }
279                 METHOD(Vortex, wr_resetplayer, void(entity thiswep))
280                 {
281                         if (WEP_CVAR(vortex, charge)) {
282                                 if (WEP_CVAR_SEC(vortex, chargepool)) {
283                                         self.vortex_chargepool_ammo = 1;
284                                 }
285                                 self.vortex_charge = WEP_CVAR(vortex, charge_start);
286                         }
287                         self.vortex_lasthit = 0;
288                 }
289                 METHOD(Vortex, wr_reload, void(entity thiswep))
290                 {
291                         W_Reload(self, min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo)), SND(RELOAD));
292                 }
293                 METHOD(Vortex, wr_suicidemessage, int(entity thiswep))
294                 {
295                         return WEAPON_THINKING_WITH_PORTALS;
296                 }
297                 METHOD(Vortex, wr_killmessage, int(entity thiswep))
298                 {
299                         return WEAPON_VORTEX_MURDER;
300                 }
301
302 #endif
303 #ifdef CSQC
304 float autocvar_g_balance_vortex_secondary = 0; // WEAPONTODO
305
306                 METHOD(Vortex, wr_impacteffect, void(entity thiswep))
307                 {
308                         vector org2 = w_org + w_backoff * 6;
309                         pointparticles(particleeffectnum(EFFECT_VORTEX_IMPACT), org2, '0 0 0', 1);
310                         if(!w_issilent)
311                                 sound(self, CH_SHOTS, SND_NEXIMPACT, VOL_BASE, ATTN_NORM);
312                 }
313                 METHOD(Vortex, wr_init, void(entity thiswep))
314                 {
315                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
316                         {
317                                 precache_pic("gfx/reticle_nex");
318                         }
319                 }
320                 METHOD(Vortex, wr_zoomreticle, bool(entity thiswep))
321                 {
322                         if(button_zoom || zoomscript_caught || (!WEP_CVAR(vortex, secondary) && button_attack2))
323                         {
324                                 reticle_image = "gfx/reticle_nex";
325                                 return true;
326                         }
327                         else
328                         {
329                                 // no weapon specific image for this weapon
330                                 return false;
331                         }
332                 }
333
334 #endif
335 #endif