Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_nex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(NEX, w_nex, IT_CELLS, 7, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_HIGH, "nex", "nex", _("Nex"))
3 #else
4 #ifdef SVQC
5
6 void SendCSQCNexBeamParticle(float charge) {
7         vector v;
8         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
9         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
10         WriteByte(MSG_BROADCAST, TE_CSQC_NEXGUNBEAMPARTICLE);
11         WriteCoord(MSG_BROADCAST, w_shotorg_x);
12         WriteCoord(MSG_BROADCAST, w_shotorg_y);
13         WriteCoord(MSG_BROADCAST, w_shotorg_z);
14         WriteCoord(MSG_BROADCAST, v_x);
15         WriteCoord(MSG_BROADCAST, v_y);
16         WriteCoord(MSG_BROADCAST, v_z);
17         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
18 }
19
20 void W_Nex_Attack (float issecondary)
21 {
22         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
23         if(issecondary)
24         {
25                 mydmg = autocvar_g_balance_nex_secondary_damage;
26                 myforce = autocvar_g_balance_nex_secondary_force;
27                 mymindist = autocvar_g_balance_nex_secondary_damagefalloff_mindist;
28                 mymaxdist = autocvar_g_balance_nex_secondary_damagefalloff_maxdist;
29                 myhalflife = autocvar_g_balance_nex_secondary_damagefalloff_halflife;
30                 myforcehalflife = autocvar_g_balance_nex_secondary_damagefalloff_forcehalflife;
31                 myammo = autocvar_g_balance_nex_secondary_ammo;
32         }
33         else
34         {
35                 mydmg = autocvar_g_balance_nex_primary_damage;
36                 myforce = autocvar_g_balance_nex_primary_force;
37                 mymindist = autocvar_g_balance_nex_primary_damagefalloff_mindist;
38                 mymaxdist = autocvar_g_balance_nex_primary_damagefalloff_maxdist;
39                 myhalflife = autocvar_g_balance_nex_primary_damagefalloff_halflife;
40                 myforcehalflife = autocvar_g_balance_nex_primary_damagefalloff_forcehalflife;
41                 myammo = autocvar_g_balance_nex_primary_ammo;
42         }
43
44         float flying;
45         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
46
47         if(autocvar_g_balance_nex_charge)
48         {
49                 charge = autocvar_g_balance_nex_charge_mindmg / mydmg + (1 - autocvar_g_balance_nex_charge_mindmg / mydmg) * self.nex_charge;
50                 self.nex_charge *= autocvar_g_balance_nex_charge_shot_multiplier; // do this AFTER setting mydmg/myforce
51                 // O RLY? -- divVerent
52                 // YA RLY -- FruitieX
53         }
54         else
55                 charge = 1;
56         mydmg *= charge;
57         myforce *= charge;
58
59         W_SetupShot (self, TRUE, 5, "weapons/nexfire.wav", CH_WEAPON_A, mydmg);
60         if(charge > autocvar_g_balance_nex_charge_animlimit && autocvar_g_balance_nex_charge_animlimit) // if the Nex is overcharged, we play an extra sound
61         {
62                 sound (self, CH_WEAPON_B, "weapons/nexcharge.wav", VOL_BASE * (charge - 0.5 * autocvar_g_balance_nex_charge_animlimit) / (1 - 0.5 * autocvar_g_balance_nex_charge_animlimit), ATTN_NORM);
63         }
64
65         yoda = 0;
66         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_NEX);
67
68         if(yoda && flying)
69                 AnnounceTo(self, "yoda");
70
71         //beam and muzzle flash done on client
72         SendCSQCNexBeamParticle(charge);
73
74         // flash and burn the wall
75         if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
76                 Damage_DamageInfo(trace_endpos, mydmg, 0, 0, myforce * w_shotdir, WEP_NEX, self);
77
78         W_DecreaseAmmo(ammo_cells, myammo, autocvar_g_balance_nex_reload_ammo);
79 }
80
81 void spawnfunc_weapon_nex (void); // defined in t_items.qc
82
83 .float nex_chargepool_pauseregen_finished;
84 float w_nex(float req)
85 {
86         float dt;
87         float ammo_amount;
88         if (req == WR_AIM)
89         {
90                 if(bot_aim(1000000, 0, 1, FALSE))
91                         self.BUTTON_ATCK = TRUE;
92                 else
93                 {
94                         if(autocvar_g_balance_nex_charge)
95                                 self.BUTTON_ATCK2 = TRUE;
96                 }
97         }
98         else if (req == WR_THINK)
99         {
100                 if(autocvar_g_balance_nex_charge && self.nex_charge < autocvar_g_balance_nex_charge_limit)
101                         self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_rate * frametime / W_TICSPERFRAME);
102
103                 if(autocvar_g_balance_nex_secondary_chargepool)
104                         if(self.nex_chargepool_ammo < 1)
105                         {
106                                 if(self.nex_chargepool_pauseregen_finished < time)
107                                         self.nex_chargepool_ammo = min(1, self.nex_chargepool_ammo + autocvar_g_balance_nex_secondary_chargepool_regen * frametime / W_TICSPERFRAME);
108                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_nex_secondary_chargepool_pause_health_regen);
109                         }
110
111                 if(autocvar_g_balance_nex_reload_ammo && self.clip_load < min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo)) // forced reload
112                         weapon_action(self.weapon, WR_RELOAD);
113                 else
114                 {
115                         if (self.BUTTON_ATCK)
116                         {
117                                 if (weapon_prepareattack(0, autocvar_g_balance_nex_primary_refire))
118                                 {
119                                         W_Nex_Attack(0);
120                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nex_primary_animtime, w_ready);
121                                 }
122                         }
123                         if ((autocvar_g_balance_nex_secondary_charge && !autocvar_g_balance_nex_secondary) ? (self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) : self.BUTTON_ATCK2)
124                         {
125                                 if(autocvar_g_balance_nex_secondary_charge)
126                                 {
127                                         self.nex_charge_rottime = time + autocvar_g_balance_nex_charge_rot_pause;
128                                         dt = frametime / W_TICSPERFRAME;
129
130                                         if(self.nex_charge < 1)
131                                         {
132                                                 if(autocvar_g_balance_nex_secondary_chargepool)
133                                                 {
134                                                         if(autocvar_g_balance_nex_secondary_ammo)
135                                                         {
136                                                                 // always deplete if secondary is held
137                                                                 self.nex_chargepool_ammo = max(0, self.nex_chargepool_ammo - autocvar_g_balance_nex_secondary_ammo * dt);
138
139                                                                 dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
140                                                                 self.nex_chargepool_pauseregen_finished = time + autocvar_g_balance_nex_secondary_chargepool_pause_regen;
141                                                                 dt = min(dt, self.nex_chargepool_ammo);
142                                                                 dt = max(0, dt);
143
144                                                                 self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
145                                                         }
146                                                 }
147
148                                                 else if(autocvar_g_balance_nex_secondary_ammo)
149                                                 {
150                                                         if(self.BUTTON_ATCK2) // only eat ammo when the button is pressed
151                                                         {
152                                                                 dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
153                                                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
154                                                                 {
155                                                                         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
156                                                                         if(autocvar_g_balance_nex_reload_ammo)
157                                                                         {
158                                                                                 dt = min(dt, (self.clip_load - autocvar_g_balance_nex_primary_ammo) / autocvar_g_balance_nex_secondary_ammo);
159                                                                                 dt = max(0, dt);
160                                                                                 if(dt > 0)
161                                                                                 {
162                                                                                         self.clip_load = max(autocvar_g_balance_nex_secondary_ammo, self.clip_load - autocvar_g_balance_nex_secondary_ammo * dt);
163                                                                                 }
164                                                                                 self.(weapon_load[WEP_NEX]) = self.clip_load;
165                                                                         }
166                                                                         else
167                                                                         {
168                                                                                 dt = min(dt, (self.ammo_cells - autocvar_g_balance_nex_primary_ammo) / autocvar_g_balance_nex_secondary_ammo);
169                                                                                 dt = max(0, dt);
170                                                                                 if(dt > 0)
171                                                                                 {
172                                                                                         self.ammo_cells = max(autocvar_g_balance_nex_secondary_ammo, self.ammo_cells - autocvar_g_balance_nex_secondary_ammo * dt);
173                                                                                 }
174                                                                         }
175                                                                 }
176                                                                 self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
177                                                         }
178                                                 }
179
180                                                 else
181                                                 {
182                                                         dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
183                                                         self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
184                                                 }
185                                         }
186                                 }
187                                 else if(autocvar_g_balance_nex_secondary)
188                                 {
189                                         if (weapon_prepareattack(0, autocvar_g_balance_nex_secondary_refire))
190                                         {
191                                                 W_Nex_Attack(1);
192                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nex_secondary_animtime, w_ready);
193                                         }
194                                 }
195                         }
196                 }
197         }
198         else if (req == WR_PRECACHE)
199         {
200                 precache_model ("models/nexflash.md3");
201                 precache_model ("models/weapons/g_nex.md3");
202                 precache_model ("models/weapons/v_nex.md3");
203                 precache_model ("models/weapons/h_nex.iqm");
204                 precache_sound ("weapons/nexfire.wav");
205                 precache_sound ("weapons/nexcharge.wav");
206                 precache_sound ("weapons/nexwhoosh1.wav");
207                 precache_sound ("weapons/nexwhoosh2.wav");
208                 precache_sound ("weapons/nexwhoosh3.wav");
209                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
210         }
211         else if (req == WR_SETUP)
212         {
213                 weapon_setup(WEP_NEX);
214                 self.current_ammo = ammo_cells;
215         }
216         else if (req == WR_CHECKAMMO1)
217         {
218                 ammo_amount = self.ammo_cells >= autocvar_g_balance_nex_primary_ammo;
219                 ammo_amount += (autocvar_g_balance_nex_reload_ammo && self.(weapon_load[WEP_NEX]) >= autocvar_g_balance_nex_primary_ammo);
220                 return ammo_amount;
221         }
222         else if (req == WR_CHECKAMMO2)
223         {
224                 if(autocvar_g_balance_nex_secondary)
225                 {
226                         // don't allow charging if we don't have enough ammo
227                         ammo_amount = self.ammo_cells >= autocvar_g_balance_nex_secondary_ammo;
228                         ammo_amount += self.(weapon_load[WEP_NEX]) >= autocvar_g_balance_nex_secondary_ammo;    
229                         return ammo_amount;
230                 }
231                 else
232                 {
233                         return FALSE; // zoom is not a fire mode
234                 }
235         }
236         else if (req == WR_RELOAD)
237         {
238                 W_Reload(min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo), autocvar_g_balance_nex_reload_ammo, autocvar_g_balance_nex_reload_time, "weapons/reload.wav");
239         }
240
241         return TRUE;
242 }
243 #endif
244 #ifdef CSQC
245 float w_nex(float req)
246 {
247         if(req == WR_IMPACTEFFECT)
248         {
249                 vector org2;
250                 org2 = w_org + w_backoff * 6;
251                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
252                 if(!w_issilent)
253                         sound(self, CH_SHOTS, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
254         }
255         else if(req == WR_PRECACHE)
256         {
257                 precache_sound("weapons/neximpact.wav");
258         }
259         else if (req == WR_SUICIDEMESSAGE)
260                 w_deathtypestring = _("%s is now thinking with portals");
261         else if (req == WR_KILLMESSAGE)
262                 w_deathtypestring = _("%s has been vaporized by %s's nex");
263         return TRUE;
264 }
265 #endif
266 #endif