4 #include <common/triggers/trigger/jumppads.qh>
6 REGISTER_MUTATOR(porto_ticker, true);
7 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
8 FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
11 void W_Porto_Success(entity this)
13 if(this.realowner == NULL)
15 objerror(this, "Cannot succeed successfully: no owner\n");
19 this.realowner.porto_current = NULL;
23 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity);
24 void W_Porto_Fail(entity this, float failhard)
26 if(this.realowner == NULL)
28 objerror(this, "Cannot fail successfully: no owner\n");
35 Portal_ClearWithID(this.realowner, this.portal_id);
38 this.realowner.porto_current = NULL;
40 if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(this.realowner.weapons & WEPSET(PORTO)))
42 setsize(this, '-16 -16 0', '16 16 32');
43 setorigin(this, this.origin + trace_plane_normal);
44 if(move_out_of_solid(this))
47 IL_PUSH(g_items, this);
48 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128, this);
49 tracetoss(this, this);
50 if(vdist(trace_endpos - this.realowner.origin, <, 128))
52 .entity weaponentity = this.weaponentity_fld;
53 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity, weaponentity);
54 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
61 void W_Porto_Remove(entity p)
63 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
65 W_Porto_Fail(p.porto_current, 1);
69 void W_Porto_Think(entity this)
71 trace_plane_normal = '0 0 0';
72 if(this.realowner.playerid != this.playerid)
75 W_Porto_Fail(this, 0);
78 void W_Porto_Touch(entity this, entity toucher)
82 // do not use PROJECTILE_TOUCH here
83 // FIXME but DO handle warpzones!
85 if(toucher.classname == "portal")
86 return; // handled by the portal
88 norm = trace_plane_normal;
89 if(trace_ent.iscreature)
91 // TODO: why not use entity size?
92 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
93 if(trace_fraction >= 1)
95 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
97 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
101 if(this.realowner.playerid != this.playerid)
103 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
106 else if((trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) || (trace_dphitcontents & DPCONTENTS_PLAYERCLIP))
108 spamsound(this, CH_SHOTS, SND_PORTO_BOUNCE, VOL_BASE, ATTEN_NORM);
110 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
111 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
113 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
115 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
116 W_Porto_Fail(this, 0);
118 Portal_ClearAll_PortalsOnly(this.realowner);
120 else if(this.cnt == 0)
123 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
125 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
126 trace_plane_normal = norm;
127 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
128 W_Porto_Success(this);
132 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
133 trace_plane_normal = norm;
134 W_Porto_Fail(this, 0);
137 else if(this.cnt == 1)
140 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
142 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
143 trace_plane_normal = norm;
144 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
145 W_Porto_Success(this);
149 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
150 trace_plane_normal = norm;
151 W_Porto_Fail(this, 0);
154 else if(this.effects & EF_RED)
156 this.effects += EF_BLUE - EF_RED;
157 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
159 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
160 trace_plane_normal = norm;
161 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
162 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
163 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
164 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
168 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
169 trace_plane_normal = norm;
170 Portal_ClearAll_PortalsOnly(this.realowner);
171 W_Porto_Fail(this, 0);
176 if(this.realowner.portal_in.portal_id == this.portal_id)
178 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
180 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
181 trace_plane_normal = norm;
182 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
183 W_Porto_Success(this);
187 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
188 Portal_ClearAll_PortalsOnly(this.realowner);
189 W_Porto_Fail(this, 0);
194 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
195 Portal_ClearAll_PortalsOnly(this.realowner);
196 W_Porto_Fail(this, 0);
201 void W_Porto_Attack(entity actor, .entity weaponentity, float type)
205 W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0, WEP_PORTO.m_id); // TODO: does the deathtype even need to be set here? porto can't hurt people
206 // always shoot from the eye
207 w_shotdir = v_forward;
208 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
210 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
213 gren.weaponentity_fld = weaponentity;
215 gren.owner = gren.realowner = actor;
216 gren.playerid = actor.playerid;
217 gren.bot_dodge = true;
218 gren.bot_dodgerating = 200;
219 set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
220 PROJECTILE_MAKETRIGGER(gren);
221 gren.effects = EF_RED;
223 setorigin(gren, w_shotorg);
224 setsize(gren, '0 0 0', '0 0 0');
226 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
227 setthink(gren, W_Porto_Think);
228 settouch(gren, W_Porto_Touch);
230 if(actor.items & ITEM_Strength.m_itemid)
231 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
233 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
235 gren.angles = vectoangles(gren.velocity);
236 gren.flags = FL_PROJECTILE;
237 IL_PUSH(g_projectiles, gren);
238 IL_PUSH(g_bot_dodge, gren);
240 gren.portal_id = time;
241 actor.porto_current = gren;
242 gren.playerid = actor.playerid;
243 fixedmakevectors(fixedvectoangles(gren.velocity));
244 gren.right_vector = v_right;
246 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
249 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
251 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
253 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
256 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
258 PHYS_INPUT_BUTTON_ATCK(actor) = false;
259 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
260 if(!WEP_CVAR(porto, secondary))
261 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
262 PHYS_INPUT_BUTTON_ATCK(actor) = true;
264 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
266 if(WEP_CVAR(porto, secondary))
269 if(!actor.porto_current)
270 if(!actor.porto_forbidden)
271 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
273 W_Porto_Attack(actor, weaponentity, 0);
274 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
278 if(!actor.porto_current)
279 if(!actor.porto_forbidden)
280 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
282 W_Porto_Attack(actor, weaponentity, 1);
283 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
288 if(actor.(weaponentity).porto_v_angle_held)
291 actor.(weaponentity).porto_v_angle_held = 0;
297 actor.(weaponentity).porto_v_angle = actor.v_angle;
298 actor.(weaponentity).porto_v_angle_held = 1;
301 if(actor.(weaponentity).porto_v_angle_held)
302 makevectors(actor.(weaponentity).porto_v_angle); // override the previously set angles
305 if(!actor.porto_current)
306 if(!actor.porto_forbidden)
307 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
309 W_Porto_Attack(actor, weaponentity, -1);
310 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
314 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this, .entity weaponentity))
316 // always allow infinite ammo
319 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this, .entity weaponentity))
321 // always allow infinite ammo
324 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
326 actor.porto_current = NULL;
330 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
331 LOG_WARN("Since when does Porto send DamageInfo?");