]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_minstanex.qc
Rename WR_PRECACHE to WR_INIT, which is more appropriate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_minstanex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ MINSTANEX,
4 /* function  */ w_minstanex,
5 /* ammotype  */ IT_CELLS,
6 /* impulse   */ 7,
7 /* flags     */ WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_FLAG_SUPERWEAPON | WEP_TYPE_HITSCAN,
8 /* rating    */ BOT_PICKUP_RATING_HIGH,
9 /* model     */ "minstanex",
10 /* shortname */ "minstanex",
11 /* fullname  */ _("MinstaNex")
12 );
13
14 #ifdef SVQC
15 void spawnfunc_weapon_minstanex (void)
16 {
17         weapon_defaultspawnfunc(WEP_MINSTANEX);
18 }
19 #endif
20 #else
21 #ifdef SVQC
22 .float minstanex_lasthit;
23 .float jump_interval;
24
25 void W_MinstaNex_Attack (void)
26 {
27         float flying;
28         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
29
30         W_SetupShot (self, TRUE, 0, "weapons/minstanexfire.wav", CH_WEAPON_A, 10000);
31
32         yoda = 0;
33         damage_goodhits = 0;
34         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, 10000, 800, 0, 0, 0, 0, WEP_MINSTANEX);
35
36         if(yoda && flying)
37                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
38         if(damage_goodhits && self.minstanex_lasthit)
39         {
40                 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_ACHIEVEMENT_IMPRESSIVE);
41                 damage_goodhits = 0; // only every second time
42         }
43
44         self.minstanex_lasthit = damage_goodhits;
45
46         pointparticles(particleeffectnum("nex_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
47
48         // teamcolor / hit beam effect
49         vector v;
50         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
51         switch(self.team)
52         {
53                 case NUM_TEAM_1:   // 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 NUM_TEAM_2:   // 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 NUM_TEAM_3:   // 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 NUM_TEAM_4:   // 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                 default:
78                         if(damage_goodhits)
79                                 WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3_HIT"), w_shotorg, v);
80                         else
81                                 WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3"), w_shotorg, v);
82                         break;
83         }
84         
85         W_DecreaseAmmo(ammo_cells, ((g_minstagib) ? 1 : autocvar_g_balance_minstanex_ammo), autocvar_g_balance_minstanex_reload_ammo);
86 }
87
88 float w_minstanex(float req)
89 {
90         float ammo_amount;
91         float minstanex_ammo;
92
93         // now multiple WR_s use this
94         minstanex_ammo = ((g_minstagib) ? 1 : autocvar_g_balance_minstanex_ammo);
95
96         switch(req)
97         {
98                 case WR_AIM:
99                 {
100                         if(self.ammo_cells > 0)
101                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
102                         else
103                                 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE);
104                                 
105                         return TRUE;
106                 }
107                 case WR_THINK:
108                 {
109                         // if the laser uses load, we also consider its ammo for reloading
110                         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
111                                 WEP_ACTION(self.weapon, WR_RELOAD);
112                         else if(autocvar_g_balance_minstanex_reload_ammo && self.clip_load < minstanex_ammo) // forced reload
113                                 WEP_ACTION(self.weapon, WR_RELOAD);
114                         else if (self.BUTTON_ATCK)
115                         {
116                                 if (weapon_prepareattack(0, autocvar_g_balance_minstanex_refire))
117                                 {
118                                         W_MinstaNex_Attack();
119                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_minstanex_animtime, w_ready);
120                                 }
121                         }
122                         else if (self.BUTTON_ATCK2)
123                         {
124                                 if (self.jump_interval <= time)
125                                 if (weapon_prepareattack(1, -1))
126                                 {
127                                         // handle refire manually, so that primary and secondary can be fired without conflictions (important for minstagib)
128                                         self.jump_interval = time + autocvar_g_balance_minstanex_laser_refire * W_WeaponRateFactor();
129                                         
130                                         // decrease ammo for the laser?
131                                         if(autocvar_g_balance_minstanex_laser_ammo)
132                                                 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_minstanex_laser_ammo, autocvar_g_balance_minstanex_reload_ammo);
133
134                                         // ugly minstagib hack to reuse the fire mode of the laser
135                                         float w;
136                                         w = self.weapon;
137                                         self.weapon = WEP_LASER;
138                                         W_Laser_Shockwave();
139                                         self.weapon = w;
140                                         
141                                         // now do normal refire
142                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_minstanex_laser_animtime, w_ready);
143                                 }
144                         }
145                         
146                         return TRUE;
147                 }
148                 case WR_INIT:
149                 {
150                         precache_model ("models/nexflash.md3");
151                         precache_model ("models/weapons/g_minstanex.md3");
152                         precache_model ("models/weapons/v_minstanex.md3");
153                         precache_model ("models/weapons/h_minstanex.iqm");
154                         precache_sound ("weapons/minstanexfire.wav");
155                         precache_sound ("weapons/nexwhoosh1.wav");
156                         precache_sound ("weapons/nexwhoosh2.wav");
157                         precache_sound ("weapons/nexwhoosh3.wav");
158                         W_Laser(WR_INIT);
159                         return TRUE;
160                 }
161                 case WR_SETUP:
162                 {
163                         weapon_setup(WEP_MINSTANEX);
164                         self.current_ammo = ammo_cells;
165                         self.minstanex_lasthit = 0;
166                         return TRUE;
167                 }
168                 case WR_CHECKAMMO1:
169                 {
170                         ammo_amount = self.ammo_cells >= minstanex_ammo;
171                         ammo_amount += self.(weapon_load[WEP_MINSTANEX]) >= minstanex_ammo;
172                         return ammo_amount;
173                 }
174                 case WR_CHECKAMMO2:
175                 {
176                         if(!autocvar_g_balance_minstanex_laser_ammo)
177                                 return TRUE;
178                         ammo_amount = self.ammo_cells >= autocvar_g_balance_minstanex_laser_ammo;
179                         ammo_amount += self.(weapon_load[WEP_MINSTANEX]) >= autocvar_g_balance_minstanex_laser_ammo;
180                         return ammo_amount;
181                 }
182                 case WR_RESETPLAYER:
183                 {
184                         self.minstanex_lasthit = 0;
185                         return TRUE;
186                 }
187                 case WR_RELOAD:
188                 {
189                         float used_ammo;
190                         if(autocvar_g_balance_minstanex_laser_ammo)
191                                 used_ammo = min(minstanex_ammo, autocvar_g_balance_minstanex_laser_ammo);
192                         else
193                                 used_ammo = minstanex_ammo;
194
195                         W_Reload(used_ammo, autocvar_g_balance_minstanex_reload_ammo, autocvar_g_balance_minstanex_reload_time, "weapons/reload.wav");
196                         return TRUE;
197                 }
198                 case WR_SUICIDEMESSAGE:
199                 {
200                         return WEAPON_THINKING_WITH_PORTALS;
201                 }
202                 case WR_KILLMESSAGE:
203                 {
204                         return WEAPON_MINSTANEX_MURDER;
205                 }
206         }
207         return TRUE;
208 }
209 #endif
210 #ifdef CSQC
211 float w_minstanex(float req)
212 {
213         switch(req)
214         {
215                 case WR_IMPACTEFFECT:
216                 {
217                         vector org2;
218                         org2 = w_org + w_backoff * 6;
219                         pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
220                         if(!w_issilent)
221                                 sound(self, CH_SHOTS, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
222                                 
223                         return TRUE;
224                 }
225                 case WR_INIT:
226                 {
227                         precache_sound("weapons/neximpact.wav");
228                         return TRUE;
229                 }
230         }
231         return TRUE;
232 }
233 #endif
234 #endif