4 #include <common/triggers/trigger/jumppads.qh>
6 spawnfunc(weapon_porto) { weapon_defaultspawnfunc(this, WEP_PORTO); }
8 REGISTER_MUTATOR(porto_ticker, true);
9 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
10 FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
13 void W_Porto_Success(entity this)
15 if(this.realowner == NULL)
17 objerror(this, "Cannot succeed successfully: no owner\n");
21 this.realowner.porto_current = NULL;
25 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity);
26 void W_Porto_Fail(entity this, float failhard)
28 if(this.realowner == NULL)
30 objerror(this, "Cannot fail successfully: no owner\n");
37 Portal_ClearWithID(this.realowner, this.portal_id);
40 this.realowner.porto_current = NULL;
42 if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(this.realowner.weapons & WEPSET(PORTO)))
44 setsize(this, '-16 -16 0', '16 16 32');
45 setorigin(this, this.origin + trace_plane_normal);
46 if(move_out_of_solid(this))
49 IL_PUSH(g_items, this);
50 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128);
51 tracetoss(this, this);
52 if(vdist(trace_endpos - this.realowner.origin, <, 128))
54 .entity weaponentity = this.weaponentity_fld;
55 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
56 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
63 void W_Porto_Remove(entity p)
65 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
67 W_Porto_Fail(p.porto_current, 1);
71 void W_Porto_Think(entity this)
73 trace_plane_normal = '0 0 0';
74 if(this.realowner.playerid != this.playerid)
77 W_Porto_Fail(this, 0);
80 void W_Porto_Touch(entity this, entity toucher)
84 // do not use PROJECTILE_TOUCH here
85 // FIXME but DO handle warpzones!
87 if(toucher.classname == "portal")
88 return; // handled by the portal
90 norm = trace_plane_normal;
91 if(trace_ent.iscreature)
93 // TODO: why not use entity size?
94 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
95 if(trace_fraction >= 1)
97 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
99 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
103 if(this.realowner.playerid != this.playerid)
105 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
108 else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
110 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
112 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
113 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
115 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
117 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
118 W_Porto_Fail(this, 0);
120 Portal_ClearAll_PortalsOnly(this.realowner);
122 else if(this.cnt == 0)
125 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
127 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
128 trace_plane_normal = norm;
129 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
130 W_Porto_Success(this);
134 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
135 trace_plane_normal = norm;
136 W_Porto_Fail(this, 0);
139 else if(this.cnt == 1)
142 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
144 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
145 trace_plane_normal = norm;
146 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
147 W_Porto_Success(this);
151 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
152 trace_plane_normal = norm;
153 W_Porto_Fail(this, 0);
156 else if(this.effects & EF_RED)
158 this.effects += EF_BLUE - EF_RED;
159 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
161 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
162 trace_plane_normal = norm;
163 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
164 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
165 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
166 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
170 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
171 trace_plane_normal = norm;
172 Portal_ClearAll_PortalsOnly(this.realowner);
173 W_Porto_Fail(this, 0);
178 if(this.realowner.portal_in.portal_id == this.portal_id)
180 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
182 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
183 trace_plane_normal = norm;
184 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
185 W_Porto_Success(this);
189 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
190 Portal_ClearAll_PortalsOnly(this.realowner);
191 W_Porto_Fail(this, 0);
196 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
197 Portal_ClearAll_PortalsOnly(this.realowner);
198 W_Porto_Fail(this, 0);
203 void W_Porto_Attack(entity actor, .entity weaponentity, float type)
207 W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0);
208 // always shoot from the eye
209 w_shotdir = v_forward;
210 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
212 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
215 gren.weaponentity_fld = weaponentity;
217 gren.owner = gren.realowner = actor;
218 gren.playerid = actor.playerid;
219 gren.bot_dodge = true;
220 gren.bot_dodgerating = 200;
221 set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
222 PROJECTILE_MAKETRIGGER(gren);
223 gren.effects = EF_RED;
225 setorigin(gren, w_shotorg);
226 setsize(gren, '0 0 0', '0 0 0');
228 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
229 setthink(gren, W_Porto_Think);
230 settouch(gren, W_Porto_Touch);
232 if(actor.items & ITEM_Strength.m_itemid)
233 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
235 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
237 gren.angles = vectoangles(gren.velocity);
238 gren.flags = FL_PROJECTILE;
239 IL_PUSH(g_projectiles, gren);
240 IL_PUSH(g_bot_dodge, gren);
242 gren.portal_id = time;
243 actor.porto_current = gren;
244 gren.playerid = actor.playerid;
245 fixedmakevectors(fixedvectoangles(gren.velocity));
246 gren.right_vector = v_right;
248 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
251 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
253 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
255 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
258 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
260 PHYS_INPUT_BUTTON_ATCK(actor) = false;
261 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
262 if(!WEP_CVAR(porto, secondary))
263 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
264 PHYS_INPUT_BUTTON_ATCK(actor) = true;
266 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
268 if(WEP_CVAR(porto, secondary))
271 if(!actor.porto_current)
272 if(!actor.porto_forbidden)
273 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
275 W_Porto_Attack(actor, weaponentity, 0);
276 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
280 if(!actor.porto_current)
281 if(!actor.porto_forbidden)
282 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
284 W_Porto_Attack(actor, weaponentity, 1);
285 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
290 if(actor.(weaponentity).porto_v_angle_held)
293 actor.(weaponentity).porto_v_angle_held = 0;
299 actor.(weaponentity).porto_v_angle = actor.v_angle;
300 actor.(weaponentity).porto_v_angle_held = 1;
303 if(actor.(weaponentity).porto_v_angle_held)
304 makevectors(actor.(weaponentity).porto_v_angle); // override the previously set angles
307 if(!actor.porto_current)
308 if(!actor.porto_forbidden)
309 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
311 W_Porto_Attack(actor, weaponentity, -1);
312 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
316 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this, .entity weaponentity))
318 // always allow infinite ammo
321 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
323 // always allow infinite ammo
326 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
328 actor.porto_current = NULL;
332 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
333 LOG_WARN("Since when does Porto send DamageInfo?");