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