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 // FIXME: item properties should be obtained from the registry
122 setsize(this, ITEM_D_MINS, ITEM_D_MAXS);
123 setorigin(this, this.origin + trace_plane_normal);
124 if(move_out_of_solid(this))
126 this.flags = FL_ITEM;
127 IL_PUSH(g_items, this);
128 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128, this);
129 tracetoss(this, this);
130 if(vdist(trace_endpos - this.realowner.origin, <, 128))
132 .entity weaponentity = this.weaponentity_fld;
133 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
134 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
141 void W_Porto_Remove(entity p)
143 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
145 W_Porto_Fail(p.porto_current, 1);
149 void W_Porto_Think(entity this)
151 trace_plane_normal = '0 0 0';
152 if(this.realowner.playerid != this.playerid)
155 W_Porto_Fail(this, 0);
158 void W_Porto_Touch(entity this, entity toucher)
162 // do not use PROJECTILE_TOUCH here
163 // FIXME but DO handle warpzones!
165 if(toucher.classname == "portal")
166 return; // handled by the portal
168 norm = trace_plane_normal;
169 if(trace_ent.iscreature)
171 // TODO: why not use entity size?
172 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
173 if(trace_fraction >= 1)
175 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
177 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
181 if(this.realowner.playerid != this.playerid)
183 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
186 else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
188 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
190 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
191 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
193 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
195 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
196 W_Porto_Fail(this, 0);
198 Portal_ClearAll_PortalsOnly(this.realowner);
200 else if(this.cnt == 0)
203 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
205 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
206 trace_plane_normal = norm;
207 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
208 W_Porto_Success(this);
212 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
213 trace_plane_normal = norm;
214 W_Porto_Fail(this, 0);
217 else if(this.cnt == 1)
220 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
222 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
223 trace_plane_normal = norm;
224 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
225 W_Porto_Success(this);
229 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
230 trace_plane_normal = norm;
231 W_Porto_Fail(this, 0);
234 else if(this.effects & EF_RED)
236 this.effects += EF_BLUE - EF_RED;
237 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
239 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
240 trace_plane_normal = norm;
241 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
242 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
243 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
244 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
248 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
249 trace_plane_normal = norm;
250 Portal_ClearAll_PortalsOnly(this.realowner);
251 W_Porto_Fail(this, 0);
256 if(this.realowner.portal_in.portal_id == this.portal_id)
258 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
260 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
261 trace_plane_normal = norm;
262 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
263 W_Porto_Success(this);
267 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
268 Portal_ClearAll_PortalsOnly(this.realowner);
269 W_Porto_Fail(this, 0);
274 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
275 Portal_ClearAll_PortalsOnly(this.realowner);
276 W_Porto_Fail(this, 0);
281 void W_Porto_Attack(Weapon thiswep, entity actor, .entity weaponentity, float type)
285 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
286 // always shoot from the eye
287 w_shotdir = v_forward;
288 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
290 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
293 gren.weaponentity_fld = weaponentity;
295 gren.owner = gren.realowner = actor;
296 gren.playerid = actor.playerid;
297 gren.bot_dodge = true;
298 gren.bot_dodgerating = 200;
299 set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
300 PROJECTILE_MAKETRIGGER(gren);
301 gren.clipgroup = CLIPGROUP_UNHITTABLEPROJ;
302 gren.effects = EF_RED;
304 setorigin(gren, w_shotorg);
305 setsize(gren, UNHITTABLEPROJ_MINS, UNHITTABLEPROJ_MAXS);
307 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
308 setthink(gren, W_Porto_Think);
309 settouch(gren, W_Porto_Touch);
311 // TODO: handle as mutator effect
312 if(StatusEffects_active(STATUSEFFECT_Strength, actor))
313 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
315 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
317 gren.angles = vectoangles(gren.velocity);
318 gren.flags = FL_PROJECTILE;
319 IL_PUSH(g_projectiles, gren);
320 IL_PUSH(g_bot_dodge, gren);
322 gren.portal_id = time;
323 actor.porto_current = gren;
324 gren.playerid = actor.playerid;
325 fixedmakevectors(fixedvectoangles(gren.velocity));
326 gren.right_vector = v_right;
328 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
331 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
333 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
335 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
338 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
340 PHYS_INPUT_BUTTON_ATCK(actor) = false;
341 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
342 if(!WEP_CVAR(porto, secondary))
343 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false, true))
344 PHYS_INPUT_BUTTON_ATCK(actor) = true;
346 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
348 if(WEP_CVAR(porto, secondary))
351 if(!actor.porto_current)
352 if(!actor.porto_forbidden)
353 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
355 W_Porto_Attack(thiswep, actor, weaponentity, 0);
356 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
360 if(!actor.porto_current)
361 if(!actor.porto_forbidden)
362 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
364 W_Porto_Attack(thiswep, actor, weaponentity, 1);
365 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
370 if(actor.(weaponentity).porto_v_angle_held)
373 actor.(weaponentity).porto_v_angle_held = 0;
379 actor.(weaponentity).porto_v_angle = actor.v_angle;
380 actor.(weaponentity).porto_v_angle_held = 1;
383 if(actor.(weaponentity).porto_v_angle_held)
384 makevectors(actor.(weaponentity).porto_v_angle); // override the previously set angles
387 if(!actor.porto_current)
388 if(!actor.porto_forbidden)
389 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
391 W_Porto_Attack(thiswep, actor, weaponentity, -1);
392 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
396 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this, .entity weaponentity))
398 // always allow infinite ammo
401 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
403 // always allow infinite ammo
406 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
408 actor.porto_current = NULL;
412 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
413 LOG_WARN("Since when does Porto send DamageInfo?");