]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_minstanex.qc
Merge remote-tracking branch 'origin/terencehill/spectate_prev'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_minstanex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(MINSTANEX, w_minstanex, IT_CELLS, 7, WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_FLAG_SUPERWEAPON | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_HIGH, "minstanex", "minstanex", _("MinstaNex"))
3 #else
4 #ifdef SVQC
5 .float minstanex_lasthit;
6 .float jump_interval;
7
8 void W_MinstaNex_Attack (void)
9 {
10         float flying;
11         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
12
13         W_SetupShot (self, TRUE, 0, "weapons/minstanexfire.wav", CH_WEAPON_A, 10000);
14
15         yoda = 0;
16         damage_goodhits = 0;
17         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, 10000, 800, 0, 0, 0, 0, WEP_MINSTANEX);
18
19         if(g_minstagib)
20         {
21                 if(yoda)
22                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
23         }
24         else
25         {
26                 if(yoda && flying)
27                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
28                 if(damage_goodhits && self.minstanex_lasthit)
29                 {
30                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
31                         damage_goodhits = 0; // only every second time
32                 }
33         }
34
35         self.minstanex_lasthit = damage_goodhits;
36
37         pointparticles(particleeffectnum("nex_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
38
39         // teamcolor / hit beam effect
40         vector v;
41         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
42         if(teamplay)
43         {
44             switch(self.team)
45             {
46             case NUM_TEAM_1:   // Red
47                 if(damage_goodhits)
48                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3RED_HIT"), w_shotorg, v);
49                 else
50                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3RED"), w_shotorg, v);
51                 break;
52             case NUM_TEAM_2:   // Blue
53                 if(damage_goodhits)
54                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3BLUE_HIT"), w_shotorg, v);
55                 else
56                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3BLUE"), w_shotorg, v);
57                 break;
58             case NUM_TEAM_3:   // Yellow
59                 if(damage_goodhits)
60                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3YELLOW_HIT"), w_shotorg, v);
61                 else
62                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3YELLOW"), w_shotorg, v);
63                 break;
64             case NUM_TEAM_4:   // Pink
65                 if(damage_goodhits)
66                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3PINK_HIT"), w_shotorg, v);
67                 else
68                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3PINK"), w_shotorg, v);
69                 break;
70             }
71         }
72         else
73         WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3"), w_shotorg, v);
74
75         if (g_minstagib)
76                 W_DecreaseAmmo(ammo_cells, 1, autocvar_g_balance_minstanex_reload_ammo);
77         else
78                 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_minstanex_ammo, autocvar_g_balance_minstanex_reload_ammo);
79 }
80
81
82 .float minstagib_nextthink;
83 .float minstagib_needammo;
84 void minstagib_stop_countdown(entity e)
85 {
86         if (!e.minstagib_needammo)
87                 return;
88         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_MINSTA_FINDAMMO);
89         e.minstagib_needammo = FALSE;
90 }
91 void minstagib_ammocheck(void)
92 {
93         if (time < self.minstagib_nextthink)
94                 return;
95
96         if (self.deadflag || gameover || (self.flags & FL_GODMODE))
97                 minstagib_stop_countdown(self);
98         else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO))
99         {
100                 if (self.minstagib_needammo)
101                         self.health = 100;
102                 minstagib_stop_countdown(self);
103         }
104         else
105         {
106                 self.minstagib_needammo = TRUE;
107                 if (self.health == 5)
108                 {
109                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
110                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_MINSTAGIB_TERMINATED);
111                 }
112                 else if (self.health == 10)
113                 {
114                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
115                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_1);
116                 }
117                 else if (self.health == 20)
118                 {
119                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
120                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_2);
121                 }
122                 else if (self.health == 30)
123                 {
124                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
125                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_3);
126                 }
127                 else if (self.health == 40)
128                 {
129                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
130                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_4);
131                 }
132                 else if (self.health == 50)
133                 {
134                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
135                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_5);
136                 }
137                 else if (self.health == 60)
138                 {
139                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
140                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_6);
141                 }
142                 else if (self.health == 70)
143                 {
144                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
145                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_7);
146                 }
147                 else if (self.health == 80)
148                 {
149                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
150                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_8);
151                 }
152                 else if (self.health == 90)
153                 {
154                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MINSTA_FINDAMMO);
155                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
156                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_9);
157                 }
158                 else if (self.health == 100)
159                 {
160                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_MULTI, MULTI_MINSTA_FINDAMMO);
161                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
162                 }
163         }
164         self.minstagib_nextthink = time + 1;
165 }
166
167 void spawnfunc_weapon_minstanex (void); // defined in t_items.qc
168
169 float w_minstanex(float req)
170 {
171         float ammo_amount;
172         float minstanex_ammo;
173
174         // now multiple WR_s use this
175         if(g_minstagib)
176                 minstanex_ammo = 1;
177         else
178                 minstanex_ammo = autocvar_g_balance_minstanex_ammo;
179
180         if (req == WR_AIM)
181         {
182                 if(self.ammo_cells > 0)
183                         self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
184                 else
185                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE);
186         }
187         else if (req == WR_THINK)
188         {
189                 // if the laser uses load, we also consider its ammo for reloading
190                 if(autocvar_g_balance_minstanex_reload_ammo && autocvar_g_balance_minstanex_laser_ammo && self.clip_load < min(minstanex_ammo, autocvar_g_balance_minstanex_laser_ammo)) // forced reload
191                         weapon_action(self.weapon, WR_RELOAD);
192                 else if(autocvar_g_balance_minstanex_reload_ammo && self.clip_load < minstanex_ammo) // forced reload
193                         weapon_action(self.weapon, WR_RELOAD);
194                 else if (self.BUTTON_ATCK)
195                 {
196                         if (weapon_prepareattack(0, autocvar_g_balance_minstanex_refire))
197                         {
198                                 W_MinstaNex_Attack();
199                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_minstanex_animtime, w_ready);
200                         }
201                 }
202                 else if (self.BUTTON_ATCK2)
203                 {
204                         if (self.jump_interval <= time)
205                         if (weapon_prepareattack(1, -1))
206                         {
207                                 // handle refire manually, so that primary and secondary can be fired without conflictions (important for minstagib)
208                                 self.jump_interval = time + autocvar_g_balance_minstanex_laser_refire * W_WeaponRateFactor();
209                                 
210                                 // decrease ammo for the laser?
211                                 if(autocvar_g_balance_minstanex_laser_ammo)
212                                         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_minstanex_laser_ammo, autocvar_g_balance_minstanex_reload_ammo);
213
214                                 // ugly minstagib hack to reuse the fire mode of the laser
215                                 float w;
216                                 w = self.weapon;
217                                 self.weapon = WEP_LASER;
218                                 W_Laser_Attack(2);
219                                 self.weapon = w;
220                                 
221                                 // now do normal refire
222                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_minstanex_laser_animtime, w_ready);
223                         }
224                 }
225         }
226         else if (req == WR_PRECACHE)
227         {
228                 precache_model ("models/nexflash.md3");
229                 precache_model ("models/weapons/g_minstanex.md3");
230                 precache_model ("models/weapons/v_minstanex.md3");
231                 precache_model ("models/weapons/h_minstanex.iqm");
232                 precache_sound ("weapons/minstanexfire.wav");
233                 precache_sound ("weapons/nexwhoosh1.wav");
234                 precache_sound ("weapons/nexwhoosh2.wav");
235                 precache_sound ("weapons/nexwhoosh3.wav");
236                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
237                 w_laser(WR_PRECACHE);
238         }
239         else if (req == WR_SETUP)
240         {
241                 weapon_setup(WEP_MINSTANEX);
242                 self.current_ammo = ammo_cells;
243                 self.minstanex_lasthit = 0;
244         }
245         else if (req == WR_CHECKAMMO1)
246         {
247                 ammo_amount = self.ammo_cells >= minstanex_ammo;
248                 ammo_amount += self.(weapon_load[WEP_MINSTANEX]) >= minstanex_ammo;
249                 return ammo_amount;
250         }
251         else if (req == WR_CHECKAMMO2)
252         {
253                 if(!autocvar_g_balance_minstanex_laser_ammo)
254                         return TRUE;
255                 ammo_amount = self.ammo_cells >= autocvar_g_balance_minstanex_laser_ammo;
256                 ammo_amount += self.(weapon_load[WEP_MINSTANEX]) >= autocvar_g_balance_minstanex_laser_ammo;
257                 return ammo_amount;
258         }
259         else if (req == WR_RESETPLAYER)
260         {
261                 self.minstanex_lasthit = 0;
262         }
263         else if (req == WR_RELOAD)
264         {
265                 float used_ammo;
266                 if(autocvar_g_balance_minstanex_laser_ammo)
267                         used_ammo = min(minstanex_ammo, autocvar_g_balance_minstanex_laser_ammo);
268                 else
269                         used_ammo = minstanex_ammo;
270
271                 W_Reload(used_ammo, autocvar_g_balance_minstanex_reload_ammo, autocvar_g_balance_minstanex_reload_time, "weapons/reload.wav");
272         }
273         else if (req == WR_SUICIDEMESSAGE)
274         {
275                 return WEAPON_THINKING_WITH_PORTALS;
276         }
277         else if (req == WR_KILLMESSAGE)
278         {
279                 return WEAPON_MINSTANEX_MURDER;
280         }
281         return TRUE;
282 }
283 #endif
284 #ifdef CSQC
285 float w_minstanex(float req)
286 {
287         if(req == WR_IMPACTEFFECT)
288         {
289                 vector org2;
290                 org2 = w_org + w_backoff * 6;
291                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
292                 if(!w_issilent)
293                         sound(self, CH_SHOTS, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
294         }
295         else if(req == WR_PRECACHE)
296         {
297                 precache_sound("weapons/neximpact.wav");
298         }
299         return TRUE;
300 }
301 #endif
302 #endif