]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_porto.qc
82baf07bd1fa46b16d853fa019a13bc838257969
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_porto.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ PORTO,
4 /* function  */ W_Porto,
5 /* ammotype  */ ammo_none,
6 /* impulse   */ 0,
7 /* flags     */ WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON,
8 /* rating    */ 0,
9 /* color     */ '0.5 0.5 0.5',
10 /* modelname */ "porto",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairporto 0.6",
13 /* wepimg    */ "weaponporto",
14 /* refname   */ "porto",
15 /* wepname   */ _("Port-O-Launch")
16 );
17
18 #define PORTO_SETTINGS(w_cvar,w_prop) PORTO_SETTINGS_LIST(w_cvar, w_prop, PORTO, porto)
19 #define PORTO_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, BOTH, animtime) \
21         w_cvar(id, sn, BOTH, lifetime) \
22         w_cvar(id, sn, BOTH, refire) \
23         w_cvar(id, sn, BOTH, speed) \
24         w_cvar(id, sn, NONE, secondary) \
25         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
26         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
27         w_prop(id, sn, string, weaponreplace, weaponreplace) \
28         w_prop(id, sn, float,  weaponstart, weaponstart) \
29         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
30         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
31
32 #ifdef SVQC
33 PORTO_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
34 .entity porto_current;
35 .vector porto_v_angle; // holds "held" view angles
36 .float porto_v_angle_held;
37 .vector right_vector;
38 #endif
39 #else
40 #ifdef SVQC
41 #include "../triggers/trigger/jumppads.qh"
42
43 void spawnfunc_weapon_porto(void) { weapon_defaultspawnfunc(WEP_PORTO); }
44
45 void W_Porto_Success(void)
46 {
47         if(self.realowner == world)
48         {
49                 objerror("Cannot succeed successfully: no owner\n");
50                 return;
51         }
52
53         self.realowner.porto_current = world;
54         remove(self);
55 }
56
57 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
58 void W_Porto_Fail(float failhard)
59 {
60         if(self.realowner == world)
61         {
62                 objerror("Cannot fail successfully: no owner\n");
63                 return;
64         }
65
66         // no portals here!
67         if(self.cnt < 0)
68         {
69                 Portal_ClearWithID(self.realowner, self.portal_id);
70         }
71
72         self.realowner.porto_current = world;
73
74         if(self.cnt < 0 && !failhard && self.realowner.playerid == self.playerid && self.realowner.deadflag == DEAD_NO && !(self.realowner.weapons & WEPSET_PORTO))
75         {
76                 setsize(self, '-16 -16 0', '16 16 32');
77                 setorigin(self, self.origin + trace_plane_normal);
78                 if(move_out_of_solid(self))
79                 {
80                         self.flags = FL_ITEM;
81                         self.velocity = trigger_push_calculatevelocity(self.origin, self.realowner, 128);
82                         tracetoss(self, self);
83                         if(vlen(trace_endpos - self.realowner.origin) < 128)
84                         {
85                                 W_ThrowNewWeapon(self.realowner, WEP_PORTO, 0, self.origin, self.velocity);
86                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
87                         }
88                 }
89         }
90         remove(self);
91 }
92
93 void W_Porto_Remove(entity p)
94 {
95         if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
96         {
97                 entity oldself;
98                 oldself = self;
99                 self = p.porto_current;
100                 W_Porto_Fail(1);
101                 self = oldself;
102         }
103 }
104
105 void W_Porto_Think(void)
106 {
107         trace_plane_normal = '0 0 0';
108         if(self.realowner.playerid != self.playerid)
109                 remove(self);
110         else
111                 W_Porto_Fail(0);
112 }
113
114 void W_Porto_Touch(void)
115 {
116         vector norm;
117
118         // do not use PROJECTILE_TOUCH here
119         // FIXME but DO handle warpzones!
120
121         if(other.classname == "portal")
122                 return; // handled by the portal
123
124         norm = trace_plane_normal;
125         if(trace_ent.iscreature)
126         {
127                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN.z, MOVE_WORLDONLY, self);
128                 if(trace_fraction >= 1)
129                         return;
130                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
131                         return;
132                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
133                         return;
134         }
135
136         if(self.realowner.playerid != self.playerid)
137         {
138                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
139                 remove(self);
140         }
141         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
142         {
143                 spamsound(self, CH_SHOTS, "porto/bounce.wav", VOL_BASE, ATTEN_NORM);
144                 // just reflect
145                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
146                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
147         }
148         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
149         {
150                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
151                 W_Porto_Fail(0);
152                 if(self.cnt < 0)
153                         Portal_ClearAll_PortalsOnly(self.realowner);
154         }
155         else if(self.cnt == 0)
156         {
157                 // in-portal only
158                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
159                 {
160                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTEN_NORM);
161                         trace_plane_normal = norm;
162                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
163                         W_Porto_Success();
164                 }
165                 else
166                 {
167                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
168                         trace_plane_normal = norm;
169                         W_Porto_Fail(0);
170                 }
171         }
172         else if(self.cnt == 1)
173         {
174                 // out-portal only
175                 if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
176                 {
177                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTEN_NORM);
178                         trace_plane_normal = norm;
179                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
180                         W_Porto_Success();
181                 }
182                 else
183                 {
184                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
185                         trace_plane_normal = norm;
186                         W_Porto_Fail(0);
187                 }
188         }
189         else if(self.effects & EF_RED)
190         {
191                 self.effects += EF_BLUE - EF_RED;
192                 if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
193                 {
194                         sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTEN_NORM);
195                         trace_plane_normal = norm;
196                         Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
197                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
198                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
199                         CSQCProjectile(self, true, PROJECTILE_PORTO_BLUE, true); // change type
200                 }
201                 else
202                 {
203                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
204                         trace_plane_normal = norm;
205                         Portal_ClearAll_PortalsOnly(self.realowner);
206                         W_Porto_Fail(0);
207                 }
208         }
209         else
210         {
211                 if(self.realowner.portal_in.portal_id == self.portal_id)
212                 {
213                         if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
214                         {
215                                 sound(self, CH_SHOTS, "porto/create.wav", VOL_BASE, ATTEN_NORM);
216                                 trace_plane_normal = norm;
217                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
218                                 W_Porto_Success();
219                         }
220                         else
221                         {
222                                 sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
223                                 Portal_ClearAll_PortalsOnly(self.realowner);
224                                 W_Porto_Fail(0);
225                         }
226                 }
227                 else
228                 {
229                         sound(self, CH_SHOTS, "porto/unsupported.wav", VOL_BASE, ATTEN_NORM);
230                         Portal_ClearAll_PortalsOnly(self.realowner);
231                         W_Porto_Fail(0);
232                 }
233         }
234 }
235
236 void W_Porto_Attack(float type)
237 {
238         entity gren;
239
240         W_SetupShot(self, false, 4, "porto/fire.wav", CH_WEAPON_A, 0);
241         // always shoot from the eye
242         w_shotdir = v_forward;
243         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
244
245         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
246
247         gren = spawn();
248         gren.cnt = type;
249         gren.owner = gren.realowner = self;
250         gren.playerid = self.playerid;
251         gren.classname = "porto";
252         gren.bot_dodge = true;
253         gren.bot_dodgerating = 200;
254         gren.movetype = MOVETYPE_BOUNCEMISSILE;
255         PROJECTILE_MAKETRIGGER(gren);
256         gren.effects = EF_RED;
257         gren.scale = 4;
258         setorigin(gren, w_shotorg);
259         setsize(gren, '0 0 0', '0 0 0');
260
261         gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
262         gren.think = W_Porto_Think;
263         gren.touch = W_Porto_Touch;
264
265         if(self.items & IT_STRENGTH)
266                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
267         else
268                 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
269
270         gren.angles = vectoangles(gren.velocity);
271         gren.flags = FL_PROJECTILE;
272
273         gren.portal_id = time;
274         self.porto_current = gren;
275         gren.playerid = self.playerid;
276         fixedmakevectors(fixedvectoangles(gren.velocity));
277         gren.right_vector = v_right;
278
279         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
280
281         if(type > 0)
282                 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
283         else
284                 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
285
286         other = gren; MUTATOR_CALLHOOK(EditProjectile);
287 }
288
289 bool w_nexball_weapon(int req); // WEAPONTODO
290 bool W_Porto(int req)
291 {
292         //vector v_angle_save;
293
294         if(g_nexball) { return w_nexball_weapon(req); }
295
296         switch(req)
297         {
298                 case WR_AIM:
299                 {
300                         self.BUTTON_ATCK = false;
301                         self.BUTTON_ATCK2 = false;
302                         if(!WEP_CVAR(porto, secondary))
303                                 if(bot_aim(WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
304                                         self.BUTTON_ATCK = true;
305
306                         return true;
307                 }
308                 case WR_CONFIG:
309                 {
310                         PORTO_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
311                         return true;
312                 }
313                 case WR_THINK:
314                 {
315                         if(WEP_CVAR(porto, secondary))
316                         {
317                                 if(self.BUTTON_ATCK)
318                                 if(!self.porto_current)
319                                 if(!self.porto_forbidden)
320                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(porto, refire)))
321                                 {
322                                         W_Porto_Attack(0);
323                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
324                                 }
325
326                                 if(self.BUTTON_ATCK2)
327                                 if(!self.porto_current)
328                                 if(!self.porto_forbidden)
329                                 if(weapon_prepareattack(1, WEP_CVAR_SEC(porto, refire)))
330                                 {
331                                         W_Porto_Attack(1);
332                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
333                                 }
334                         }
335                         else
336                         {
337                                 if(self.porto_v_angle_held)
338                                 {
339                                         if(!self.BUTTON_ATCK2)
340                                         {
341                                                 self.porto_v_angle_held = 0;
342
343                                                 ClientData_Touch(self);
344                                         }
345                                 }
346                                 else
347                                 {
348                                         if(self.BUTTON_ATCK2)
349                                         {
350                                                 self.porto_v_angle = self.v_angle;
351                                                 self.porto_v_angle_held = 1;
352
353                                                 ClientData_Touch(self);
354                                         }
355                                 }
356                                 if(self.porto_v_angle_held)
357                                         makevectors(self.porto_v_angle); // override the previously set angles
358
359                                 if(self.BUTTON_ATCK)
360                                 if(!self.porto_current)
361                                 if(!self.porto_forbidden)
362                                 if(weapon_prepareattack(0, WEP_CVAR_PRI(porto, refire)))
363                                 {
364                                         W_Porto_Attack(-1);
365                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
366                                 }
367                         }
368
369                         return true;
370                 }
371                 case WR_INIT:
372                 {
373                         precache_model("models/weapons/g_porto.md3");
374                         precache_model("models/weapons/v_porto.md3");
375                         precache_model("models/weapons/h_porto.iqm");
376                         precache_model("models/portal.md3");
377                         precache_sound("porto/bounce.wav");
378                         precache_sound("porto/create.wav");
379                         precache_sound("porto/expire.wav");
380                         precache_sound("porto/explode.wav");
381                         precache_sound("porto/fire.wav");
382                         precache_sound("porto/unsupported.wav");
383                         PORTO_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
384                         return true;
385                 }
386                 case WR_SETUP:
387                 {
388                         self.ammo_field = ammo_none;
389                         return true;
390                 }
391                 case WR_RESETPLAYER:
392                 {
393                         self.porto_current = world;
394                         return true;
395                 }
396         }
397         return false;
398 }
399 #endif
400 #ifdef CSQC
401 bool W_Porto(int req)
402 {
403         switch(req)
404         {
405                 case WR_IMPACTEFFECT:
406                 {
407                         print("Since when does Porto send DamageInfo?\n");
408                         return true;
409                 }
410                 case WR_INIT:
411                 {
412                         // nothing to do
413                         return true;
414                 }
415                 case WR_ZOOMRETICLE:
416                 {
417                         // no weapon specific image for this weapon
418                         return false;
419                 }
420         }
421         return false;
422 }
423 #endif
424 #endif