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