6 entity e = new_pure(porto);
8 IL_PUSH(g_drawables, e);
9 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
12 const int polyline_length = 16;
13 .vector polyline[polyline_length];
14 void Porto_Draw(entity this)
16 if (spectatee_status || intermission == 1 || intermission == 2 || STAT(HEALTH) <= 0 || WEP_CVAR(porto, secondary)) return;
18 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
20 entity wepent = viewmodels[slot];
22 if (wepent.activeweapon != WEP_PORTO) continue;
24 vector pos = view_origin;
25 vector dir = view_forward;
26 makevectors(((autocvar_chase_active) ? warpzone_save_view_angles : view_angles));
27 pos += v_right * -wepent.movedir.y
28 + v_up * wepent.movedir.z;
30 if (wepent.angles_held_status)
32 makevectors(wepent.angles_held);
36 wepent.polyline[0] = pos;
38 int portal_number = 0, portal1_idx = 1, portal_max = 2;
39 int n = 1 + 2; // 2 lines == 3 points
40 for (int idx = 0; idx < n && idx < polyline_length - 1; )
42 traceline(pos, pos + 65536 * dir, true, this);
43 dir = reflect(dir, trace_plane_normal);
45 wepent.polyline[++idx] = pos;
46 if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
51 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
58 vector ang = vectoangles2(trace_plane_normal, dir);
61 if (!CheckWireframeBox(this, pos - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
68 if (portal_number >= portal_max) break;
69 if (portal_number == 1) portal1_idx = idx;
71 for (int idx = 0; idx < n - 1; ++idx)
73 vector p = wepent.polyline[idx], q = wepent.polyline[idx + 1];
74 if (idx == 0) p -= view_up * 16; // line from player
75 vector rgb = (idx < portal1_idx) ? '1 0 0' : '0 0 1';
76 Draw_CylindricLine(p, q, 4, "", 1, 0, rgb, 0.5, DRAWFLAG_NORMAL, view_origin);
83 #include <common/mapobjects/trigger/jumppads.qh>
84 #include <server/weapons/throwing.qh>
86 REGISTER_MUTATOR(porto_ticker, true);
87 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
88 FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
91 void W_Porto_Success(entity this)
93 if(this.realowner == NULL)
95 objerror(this, "Cannot succeed successfully: no owner\n");
99 this.realowner.porto_current = NULL;
103 void W_Porto_Fail(entity this, float failhard)
105 if(this.realowner == NULL)
107 objerror(this, "Cannot fail successfully: no owner\n");
114 Portal_ClearWithID(this.realowner, this.portal_id);
117 this.realowner.porto_current = NULL;
119 if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(STAT(WEAPONS, this.realowner) & WEPSET(PORTO)))
121 setsize(this, '-16 -16 0', '16 16 48');
122 setorigin(this, this.origin + trace_plane_normal);
123 if(move_out_of_solid(this))
125 this.flags = FL_ITEM;
126 IL_PUSH(g_items, this);
127 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128, this);
128 tracetoss(this, this);
129 if(vdist(trace_endpos - this.realowner.origin, <, 128))
131 .entity weaponentity = this.weaponentity_fld;
132 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
133 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
140 void W_Porto_Remove(entity p)
142 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
144 W_Porto_Fail(p.porto_current, 1);
148 void W_Porto_Think(entity this)
150 trace_plane_normal = '0 0 0';
151 if(this.realowner.playerid != this.playerid)
154 W_Porto_Fail(this, 0);
157 void W_Porto_Touch(entity this, entity toucher)
161 // do not use PROJECTILE_TOUCH here
162 // FIXME but DO handle warpzones!
164 if(toucher.classname == "portal")
165 return; // handled by the portal
167 norm = trace_plane_normal;
168 if(trace_ent.iscreature)
170 // TODO: why not use entity size?
171 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
172 if(trace_fraction >= 1)
174 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
176 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
180 if(this.realowner.playerid != this.playerid)
182 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
185 else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
187 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
189 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
190 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
192 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
194 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
195 W_Porto_Fail(this, 0);
197 Portal_ClearAll_PortalsOnly(this.realowner);
199 else if(this.cnt == 0)
202 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
204 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
205 trace_plane_normal = norm;
206 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
207 W_Porto_Success(this);
211 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
212 trace_plane_normal = norm;
213 W_Porto_Fail(this, 0);
216 else if(this.cnt == 1)
219 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
221 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
222 trace_plane_normal = norm;
223 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
224 W_Porto_Success(this);
228 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
229 trace_plane_normal = norm;
230 W_Porto_Fail(this, 0);
233 else if(this.effects & EF_RED)
235 this.effects += EF_BLUE - EF_RED;
236 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
238 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
239 trace_plane_normal = norm;
240 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
241 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
242 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
243 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
247 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
248 trace_plane_normal = norm;
249 Portal_ClearAll_PortalsOnly(this.realowner);
250 W_Porto_Fail(this, 0);
255 if(this.realowner.portal_in.portal_id == this.portal_id)
257 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
259 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
260 trace_plane_normal = norm;
261 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
262 W_Porto_Success(this);
266 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
267 Portal_ClearAll_PortalsOnly(this.realowner);
268 W_Porto_Fail(this, 0);
273 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
274 Portal_ClearAll_PortalsOnly(this.realowner);
275 W_Porto_Fail(this, 0);
280 void W_Porto_Attack(Weapon thiswep, entity actor, .entity weaponentity, float type)
284 W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0, thiswep.m_id); // TODO: does the deathtype even need to be set here? porto can't hurt people
285 // always shoot from the eye
286 w_shotdir = v_forward;
287 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
289 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
292 gren.weaponentity_fld = weaponentity;
294 gren.owner = gren.realowner = actor;
295 gren.playerid = actor.playerid;
296 gren.bot_dodge = true;
297 gren.bot_dodgerating = 200;
298 set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
299 PROJECTILE_MAKETRIGGER(gren);
300 gren.effects = EF_RED;
302 setorigin(gren, w_shotorg);
303 setsize(gren, '0 0 0', '0 0 0');
305 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
306 setthink(gren, W_Porto_Think);
307 settouch(gren, W_Porto_Touch);
309 if(actor.items & ITEM_Strength.m_itemid)
310 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
312 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
314 gren.angles = vectoangles(gren.velocity);
315 gren.flags = FL_PROJECTILE;
316 IL_PUSH(g_projectiles, gren);
317 IL_PUSH(g_bot_dodge, gren);
319 gren.portal_id = time;
320 actor.porto_current = gren;
321 gren.playerid = actor.playerid;
322 fixedmakevectors(fixedvectoangles(gren.velocity));
323 gren.right_vector = v_right;
325 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
328 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
330 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
332 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
335 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
337 PHYS_INPUT_BUTTON_ATCK(actor) = false;
338 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
339 if(!WEP_CVAR(porto, secondary))
340 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
341 PHYS_INPUT_BUTTON_ATCK(actor) = true;
343 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
345 if(WEP_CVAR(porto, secondary))
348 if(!actor.porto_current)
349 if(!actor.porto_forbidden)
350 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
352 W_Porto_Attack(thiswep, actor, weaponentity, 0);
353 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
357 if(!actor.porto_current)
358 if(!actor.porto_forbidden)
359 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
361 W_Porto_Attack(thiswep, actor, weaponentity, 1);
362 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
367 if(actor.(weaponentity).porto_v_angle_held)
370 actor.(weaponentity).porto_v_angle_held = 0;
376 actor.(weaponentity).porto_v_angle = actor.v_angle;
377 actor.(weaponentity).porto_v_angle_held = 1;
380 if(actor.(weaponentity).porto_v_angle_held)
381 makevectors(actor.(weaponentity).porto_v_angle); // override the previously set angles
384 if(!actor.porto_current)
385 if(!actor.porto_forbidden)
386 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
388 W_Porto_Attack(thiswep, actor, weaponentity, -1);
389 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
393 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this, .entity weaponentity))
395 // always allow infinite ammo
398 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
400 // always allow infinite ammo
403 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
405 actor.porto_current = NULL;
409 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
410 LOG_WARN("Since when does Porto send DamageInfo?");