dbfd72923ca7bffc6af1872191e263d6c326b227
[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_TYPE_HITSCAN, BOT_PICKUP_RATING_HIGH, "nex", "nex", "Nex");
3 #else
4 #ifdef SVQC
5 void SendCSQCNexBeamParticle(float charge) {
6         vector v;
7         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
8         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
9         WriteByte(MSG_BROADCAST, TE_CSQC_NEXGUNBEAMPARTICLE);
10         WriteCoord(MSG_BROADCAST, w_shotorg_x);
11         WriteCoord(MSG_BROADCAST, w_shotorg_y);
12         WriteCoord(MSG_BROADCAST, w_shotorg_z);
13         WriteCoord(MSG_BROADCAST, v_x);
14         WriteCoord(MSG_BROADCAST, v_y);
15         WriteCoord(MSG_BROADCAST, v_z);
16         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
17 }
18
19 void W_Nex_Attack (float issecondary)
20 {
21         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
22         if(issecondary)
23         {
24                 mydmg = cvar("g_balance_nex_secondary_damage");
25                 myforce = cvar("g_balance_nex_secondary_force");
26                 mymindist = cvar("g_balance_nex_secondary_damagefalloff_mindist");
27                 mymaxdist = cvar("g_balance_nex_secondary_damagefalloff_maxdist");
28                 myhalflife = cvar("g_balance_nex_secondary_damagefalloff_halflife");
29                 myforcehalflife = cvar("g_balance_nex_secondary_damagefalloff_forcehalflife");
30                 myammo = cvar("g_balance_nex_secondary_ammo");
31         }
32         else
33         {
34                 mydmg = cvar("g_balance_nex_primary_damage");
35                 myforce = cvar("g_balance_nex_primary_force");
36                 mymindist = cvar("g_balance_nex_primary_damagefalloff_mindist");
37                 mymaxdist = cvar("g_balance_nex_primary_damagefalloff_maxdist");
38                 myhalflife = cvar("g_balance_nex_primary_damagefalloff_halflife");
39                 myforcehalflife = cvar("g_balance_nex_primary_damagefalloff_forcehalflife");
40                 myammo = cvar("g_balance_nex_primary_ammo");
41         }
42
43         float flying;
44         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
45
46         if(cvar("g_balance_nex_charge"))
47         {
48                 charge = cvar("g_balance_nex_charge_mindmg") / mydmg + (1 - cvar("g_balance_nex_charge_mindmg") / mydmg) * self.nex_charge;
49                 self.nex_charge *= cvar("g_balance_nex_charge_shot_multiplier"); // do this AFTER setting mydmg/myforce
50                                                                                  // O RLY? -- divVerent
51         }
52         else
53                 charge = 1;
54         mydmg *= charge;
55         myforce *= charge;
56
57         W_SetupShot (self, TRUE, 5, "weapons/nexfire.wav", CHAN_WEAPON, mydmg);
58     if(charge > cvar("g_balance_nex_charge_limit") && cvar("g_balance_nex_charge_limit")) // if the Nex is overcharged, we play an extra sound
59     {
60         sound (self, CHAN_WEAPON2, "weapons/nexcharge.wav", VOL_BASE * (charge - 0.5 * cvar("g_balance_nex_charge_limit")) / (1 - 0.5 * cvar("g_balance_nex_charge_limit")), ATTN_NORM);
61     }
62
63         yoda = 0;
64         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_NEX);
65
66         if(yoda && flying)
67                 AnnounceTo(self, "yoda");
68
69         //beam and muzzle flash done on client
70         SendCSQCNexBeamParticle(charge);
71         
72         // flash and burn the wall
73         if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
74                 Damage_DamageInfo(trace_endpos, mydmg, 0, 0, myforce * w_shotdir, WEP_NEX, self);
75
76         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
77                 self.ammo_cells = self.ammo_cells - myammo;
78 }
79
80 void spawnfunc_weapon_nex (void); // defined in t_items.qc
81
82 .float nex_charge_pool_pauseregen_finished;
83 float w_nex(float req)
84 {
85         float dt;
86         if (req == WR_AIM)
87         {
88                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
89                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 1, FALSE);
90         }
91         else if (req == WR_THINK)
92         {
93                 if(cvar("g_balance_nex_charge") && self.nex_charge < cvar("g_balance_nex_charge_limit"))
94                         self.nex_charge = min(1, self.nex_charge + cvar("g_balance_nex_charge_rate") * frametime / W_TICSPERFRAME);
95
96                 if(cvar("g_balance_nex_secondary_charge_pool"))
97                 if(self.nex_charge_pool_ammo < 1)
98                 {
99                         if(self.nex_charge_pool_pauseregen_finished < time)
100                                 self.nex_charge_pool_ammo = min(1, self.nex_charge_pool_ammo + cvar("g_balance_nex_secondary_charge_pool_regen") * frametime / W_TICSPERFRAME);
101                         self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_nex_secondary_charge_pool_pause_health_regen"));
102                 }
103
104                 if (self.BUTTON_ATCK)
105                 {
106                         if (weapon_prepareattack(0, cvar("g_balance_nex_primary_refire")))
107                         {
108                                 W_Nex_Attack(0);
109                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nex_primary_animtime"), w_ready);
110                         }
111                 }
112                 if (self.BUTTON_ATCK2)
113                 {
114                         if(cvar("g_balance_nex_secondary_charge"))
115                         {
116                                 self.nex_charge_rottime = time + cvar("g_balance_nex_charge_rot_pause");
117                                 dt = frametime / W_TICSPERFRAME;
118
119                                 if(cvar("g_balance_nex_secondary_charge_pool"))
120                                 {
121                                         if(cvar("g_balance_nex_secondary_ammo"))
122                                         {
123                                                 // always deplete if secondary is held
124                                                 self.nex_charge_pool_ammo = max(0, self.nex_charge_pool_ammo - cvar("g_balance_nex_secondary_ammo") * dt);
125
126                                                 dt = min(dt, (1 - self.nex_charge) / cvar("g_balance_nex_secondary_charge_rate"));
127                                                 self.nex_charge_pool_pauseregen_finished = time + cvar("g_balance_nex_secondary_charge_pool_pause_regen");
128                                                 dt = min(dt, self.nex_charge_pool_ammo);
129                                                 dt = max(0, dt);
130
131                                                 self.nex_charge += dt * cvar("g_balance_nex_secondary_charge_rate");
132                                         }
133                                 }
134
135                                 else if(cvar("g_balance_nex_secondary_ammo"))
136                                 {
137                                         if(self.nex_charge < 1)
138                                         {
139                                                 dt = min(dt, (1 - self.nex_charge) / cvar("g_balance_nex_secondary_charge_rate"));
140                                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
141                                                 {
142                                                         dt = min(dt, (self.ammo_cells - cvar("g_balance_nex_primary_ammo")) / cvar("g_balance_nex_secondary_ammo"));
143                                                         dt = max(0, dt);
144                                                         if(dt > 0)
145                                                         {
146                                                                 self.ammo_cells = max(cvar("g_balance_nex_secondary_ammo"), self.ammo_cells - cvar("g_balance_nex_secondary_ammo") * dt);
147                                                         }
148                                                 }
149                                                 self.nex_charge += dt * cvar("g_balance_nex_secondary_charge_rate");
150                                         }
151                                 }
152                         }
153                         else if(cvar("g_balance_nex_secondary"))
154                         {
155                                 if (weapon_prepareattack(0, cvar("g_balance_nex_secondary_refire")))
156                                 {
157                                         W_Nex_Attack(1);
158                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nex_secondary_animtime"), w_ready);
159                                 }
160                         }
161                 }
162         }
163         else if (req == WR_PRECACHE)
164         {
165                 precache_model ("models/nexflash.md3");
166                 precache_model ("models/weapons/g_nex.md3");
167                 precache_model ("models/weapons/v_nex.md3");
168                 precache_model ("models/weapons/h_nex.iqm");
169                 precache_sound ("weapons/nexfire.wav");
170                 precache_sound ("weapons/nexwhoosh1.wav");
171                 precache_sound ("weapons/nexwhoosh2.wav");
172                 precache_sound ("weapons/nexwhoosh3.wav");
173         }
174         else if (req == WR_SETUP)
175                 weapon_setup(WEP_NEX);
176         else if (req == WR_CHECKAMMO1)
177                 return self.ammo_cells >= cvar("g_balance_nex_primary_ammo");
178         else if (req == WR_CHECKAMMO2)
179                 return self.ammo_cells >= cvar("g_balance_nex_primary_ammo"); // don't allow charging if we don't have enough ammo
180         return TRUE;
181 };
182 #endif
183 #ifdef CSQC
184 float w_nex(float req)
185 {
186         if(req == WR_IMPACTEFFECT)
187         {
188                 vector org2;
189                 org2 = w_org + w_backoff * 6;
190                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
191                 if(!w_issilent)
192                         sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
193         }
194         else if(req == WR_PRECACHE)
195         {
196                 precache_sound("weapons/neximpact.wav");
197         }
198         else if (req == WR_SUICIDEMESSAGE)
199                 w_deathtypestring = "%s did the impossible";
200         else if (req == WR_KILLMESSAGE)
201                 w_deathtypestring = "%s has been vaporized by %s";
202         return TRUE;
203 }
204 #endif
205 #endif