]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_porto.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_porto.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(PORTO, w_porto, 0, 0, WEP_TYPE_OTHER, 0, "porto" , "porto", _("Port-O-Launch"))
3 #else
4 #ifdef SVQC
5 .entity porto_current;
6 .vector porto_v_angle; // holds "held" view angles
7 .float porto_v_angle_held;
8 .vector right_vector;
9
10 void W_Porto_SetAmmoCounter()
11 {
12         // this weapon doesn't have a reload system, so always set the clip to 0 when switching to it
13         self.clip_load = self.clip_size = 0; // also keeps crosshair ammo from displaying
14 }
15
16 void W_Porto_Success (void)
17 {
18         if(self.owner == world)
19         {
20                 objerror("Cannot succeed successfully: no owner\n");
21                 return;
22         }
23
24         self.owner.porto_current = world;
25         remove(self);
26 }
27
28 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
29 void W_Porto_Fail (float failhard)
30 {
31         if(self.owner == world)
32         {
33                 objerror("Cannot fail successfully: no owner\n");
34                 return;
35         }
36
37         // no portals here!
38         Portal_ClearWithID(self.owner, self.portal_id);
39         self.owner.porto_current = world;
40
41         if(!failhard && self.owner.playerid == self.playerid && self.owner.deadflag == DEAD_NO && !(self.owner.weapons & WEPBIT_PORTO))
42         {
43                 setsize (self, '-16 -16 0', '16 16 32');
44                 setorigin(self, self.origin + trace_plane_normal);
45                 if(move_out_of_solid(self))
46                 {
47                         self.flags = FL_ITEM;
48                         self.velocity = trigger_push_calculatevelocity(self.origin, self.owner, 128);
49                         tracetoss(self, self);
50                         if(vlen(trace_endpos - self.owner.origin) < 128)
51                         {
52                                 W_ThrowNewWeapon(self.owner, WEP_PORTO, 0, self.origin, self.velocity);
53                                 centerprint(self.owner, "^1Portal deployment failed.\n\n^2Catch it to try again!");
54                         }
55                 }
56         }
57         remove(self);
58 }
59
60 void W_Porto_Remove (entity p)
61 {
62         if(p.porto_current)
63         {
64                 entity oldself;
65                 oldself = self;
66                 self = p.porto_current;
67                 W_Porto_Fail(1);
68                 self = oldself;
69         }
70 }
71
72 void W_Porto_Think (void)
73 {
74         trace_plane_normal = '0 0 0';
75         if(self.owner.playerid != self.playerid)
76                 remove(self);
77         else
78                 W_Porto_Fail(0);
79 }
80
81 void W_Porto_Touch (void)
82 {
83         vector norm;
84
85         // do not use PROJECTILE_TOUCH here
86
87         if(other.classname == "portal")
88                 return; // handled by the portal
89
90         norm = trace_plane_normal;
91         if(trace_ent.iscreature)
92         {
93                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_z, MOVE_WORLDONLY, self);
94                 if(trace_fraction >= 1)
95                         return;
96                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
97                         return;
98                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
99                         return;
100         }
101
102         if(self.owner.playerid != self.playerid)
103         {
104                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
105                 remove(self);
106         }
107         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
108         {
109                 spamsound(self, CHAN_PROJECTILE, "porto/bounce.wav", VOL_BASE, ATTN_NORM);
110                 // just reflect
111                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
112                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
113         }
114         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
115         {
116                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
117                 W_Porto_Fail(0);
118         }
119         else if(self.effects & EF_RED)
120         {
121                 self.effects += EF_BLUE - EF_RED;
122                 if(Portal_SpawnInPortalAtTrace(self.owner, self.right_vector, self.portal_id))
123                 {
124                         sound(self, CHAN_PROJECTILE, "porto/create.wav", VOL_BASE, ATTN_NORM);
125                         trace_plane_normal = norm;
126                         centerprint(self.owner, "^1In^7-portal created.");
127                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
128                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
129                         CSQCProjectile(self, TRUE, PROJECTILE_PORTO_BLUE, TRUE); // change type
130                 }
131                 else
132                 {
133                         sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
134                         trace_plane_normal = norm;
135                         W_Porto_Fail(0);
136                 }
137         }
138         else
139         {
140                 if(self.owner.portal_in.portal_id == self.portal_id)
141                 {
142                         if(Portal_SpawnOutPortalAtTrace(self.owner, self.right_vector, self.portal_id))
143                         {
144                                 sound(self, CHAN_PROJECTILE, "porto/create.wav", VOL_BASE, ATTN_NORM);
145                                 trace_plane_normal = norm;
146                                 centerprint(self.owner, "^4Out^7-portal created.");
147                                 W_Porto_Success();
148                         }
149                         else
150                         {
151                                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
152                                 W_Porto_Fail(0);
153                         }
154                 }
155                 else
156                 {
157                         sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
158                         W_Porto_Fail(0);
159                 }
160         }
161 }
162
163 void W_Porto_Attack (void)
164 {
165         local entity gren;
166
167         if not(self.items & IT_UNLIMITED_SUPERWEAPONS)
168                 self.weapons = self.weapons - (self.weapons & WEPBIT_PORTO);
169         W_SetupShot (self, FALSE, 4, "porto/fire.wav", CHAN_WEAPON, 0);
170         // always shoot from the eye
171         w_shotdir = v_forward;
172         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
173
174         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
175
176         gren = spawn ();
177         gren.owner = self;
178         gren.playerid = self.playerid;
179         gren.classname = "porto";
180         gren.bot_dodge = TRUE;
181         gren.bot_dodgerating = 200;
182         gren.movetype = MOVETYPE_BOUNCEMISSILE;
183         PROJECTILE_MAKETRIGGER(gren);
184         gren.effects = EF_RED;
185         gren.scale = 4;
186         setorigin(gren, w_shotorg);
187         setsize(gren, '0 0 0', '0 0 0');
188
189         gren.nextthink = time + autocvar_g_balance_porto_primary_lifetime;
190         gren.think = W_Porto_Think;
191         gren.touch = W_Porto_Touch;
192         if(self.items & IT_STRENGTH)
193                 W_SetupProjectileVelocity(gren, autocvar_g_balance_porto_primary_speed * autocvar_g_balance_powerup_strength_force, 0);
194         else
195                 W_SetupProjectileVelocity(gren, autocvar_g_balance_porto_primary_speed, 0);
196
197         gren.angles = vectoangles (gren.velocity);
198         gren.flags = FL_PROJECTILE;
199
200         gren.portal_id = time;
201         self.porto_current = gren;
202         gren.playerid = self.playerid;
203         fixedmakevectors(fixedvectoangles(gren.velocity));
204         gren.right_vector = v_right;
205
206         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
207
208         CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_RED, TRUE);
209
210         other = gren; MUTATOR_CALLHOOK(EditProjectile);
211 }
212
213 void spawnfunc_weapon_porto (void)
214 {
215         weapon_defaultspawnfunc(WEP_PORTO);
216 }
217
218 float w_nexball_weapon(float req);
219 float w_porto(float req)
220 {
221         vector v_angle_save;
222
223         if (g_nexball) { return w_nexball_weapon(req); }
224         if (req == WR_AIM)
225         {
226                 self.BUTTON_ATCK = FALSE;
227                 self.BUTTON_ATCK2 = FALSE;
228                 if(bot_aim(autocvar_g_balance_porto_primary_speed, 0, autocvar_g_balance_grenadelauncher_primary_lifetime, FALSE))
229                         self.BUTTON_ATCK = TRUE;
230         }
231         else if (req == WR_THINK)
232         {
233                 if(self.porto_v_angle_held)
234                 {
235                         if(!self.BUTTON_ATCK2)
236                         {
237                                 self.porto_v_angle_held = 0;
238
239                                 ClientData_Touch(self);
240                         }
241                 }
242                 else
243                 {
244                         if(self.BUTTON_ATCK2)
245                         {
246                                 self.porto_v_angle = self.v_angle;
247                                 self.porto_v_angle_held = 1;
248
249                                 ClientData_Touch(self);
250                         }
251                 }
252                 v_angle_save = self.v_angle;
253                 if(self.porto_v_angle_held)
254                         makevectors(self.porto_v_angle); // override the previously set angles
255
256                 if (self.BUTTON_ATCK)
257                 if (!self.porto_current)
258                 if (!self.porto_forbidden)
259                 if (weapon_prepareattack(0, autocvar_g_balance_porto_primary_refire))
260                 {
261                         W_Porto_Attack();
262                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_porto_primary_animtime, w_ready);
263                 }
264         }
265         else if (req == WR_PRECACHE)
266         {
267                 precache_model ("models/weapons/g_porto.md3");
268                 precache_model ("models/weapons/v_porto.md3");
269                 precache_model ("models/weapons/h_porto.iqm");
270                 precache_model ("models/portal.md3");
271                 precache_sound ("porto/bounce.wav");
272                 precache_sound ("porto/create.wav");
273                 precache_sound ("porto/expire.wav");
274                 precache_sound ("porto/explode.wav");
275                 precache_sound ("porto/fire.wav");
276                 precache_sound ("porto/unsupported.wav");
277         }
278         else if (req == WR_SETUP)
279         {
280                 weapon_setup(WEP_PORTO);
281                 W_Porto_SetAmmoCounter();
282         }
283         else if (req == WR_RESETPLAYER)
284         {
285                 self.porto_current = world;
286         }
287         return TRUE;
288 };
289 #endif
290 #ifdef CSQC
291 float w_porto(float req)
292 {
293         if(req == WR_IMPACTEFFECT)
294         {
295                 print("Since when does Porto send DamageInfo?\n");
296         }
297         else if(req == WR_PRECACHE)
298         {
299                 // nothing to do
300         }
301         else if (req == WR_SUICIDEMESSAGE)
302                 w_deathtypestring = _("%s did the impossible");
303         else if (req == WR_KILLMESSAGE)
304                 w_deathtypestring = _("%s felt %s doing the impossible to him");
305         return TRUE;
306 }
307 #endif
308 #endif