2 CLASS(PortoLaunch, Weapon)
3 /* ammotype */ ATTRIB(PortoLaunch, ammo_field, .int, ammo_none)
4 /* impulse */ ATTRIB(PortoLaunch, impulse, int, 0)
5 /* flags */ ATTRIB(PortoLaunch, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON);
6 /* rating */ ATTRIB(PortoLaunch, bot_pickupbasevalue, float, 0);
7 /* color */ ATTRIB(PortoLaunch, wpcolor, vector, '0.5 0.5 0.5');
8 /* modelname */ ATTRIB(PortoLaunch, mdl, string, "porto");
10 /* model */ ATTRIB(PortoLaunch, m_model, Model, MDL_PORTO_ITEM);
12 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair, string, "gfx/crosshairporto");
13 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair_size, float, 0.6);
14 /* wepimg */ ATTRIB(PortoLaunch, model2, string, "weaponporto");
15 /* refname */ ATTRIB(PortoLaunch, netname, string, "porto");
16 /* wepname */ ATTRIB(PortoLaunch, m_name, string, _("Port-O-Launch"));
18 #define X(BEGIN, P, END, class, prefix) \
20 P(class, prefix, animtime, float, BOTH) \
21 P(class, prefix, lifetime, float, BOTH) \
22 P(class, prefix, refire, float, BOTH) \
23 P(class, prefix, secondary, float, NONE) \
24 P(class, prefix, speed, float, BOTH) \
25 P(class, prefix, switchdelay_drop, float, NONE) \
26 P(class, prefix, switchdelay_raise, float, NONE) \
27 P(class, prefix, weaponreplace, string,NONE) \
28 P(class, prefix, weaponstartoverride, float, NONE) \
29 P(class, prefix, weaponstart, float, NONE) \
30 P(class, prefix, weaponthrowable, float, NONE) \
32 W_PROPS(X, PortoLaunch, porto)
35 REGISTER_WEAPON(PORTO, porto, NEW(PortoLaunch));
38 .entity porto_current;
39 .vector porto_v_angle; // holds "held" view angles
40 .float porto_v_angle_held;
42 .float porto_forbidden;
47 #include <common/triggers/trigger/jumppads.qh>
49 spawnfunc(weapon_porto) { weapon_defaultspawnfunc(this, WEP_PORTO); }
51 REGISTER_MUTATOR(porto_ticker, true);
52 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
53 FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
56 void W_Porto_Success(entity this)
58 if(this.realowner == NULL)
60 objerror(this, "Cannot succeed successfully: no owner\n");
64 this.realowner.porto_current = NULL;
68 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
69 void W_Porto_Fail(entity this, float failhard)
71 if(this.realowner == NULL)
73 objerror(this, "Cannot fail successfully: no owner\n");
80 Portal_ClearWithID(this.realowner, this.portal_id);
83 this.realowner.porto_current = NULL;
85 if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(this.realowner.weapons & WEPSET(PORTO)))
87 setsize(this, '-16 -16 0', '16 16 32');
88 setorigin(this, this.origin + trace_plane_normal);
89 if(move_out_of_solid(this))
92 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128);
93 tracetoss(this, this);
94 if(vdist(trace_endpos - this.realowner.origin, <, 128))
96 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity);
97 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
104 void W_Porto_Remove(entity p)
106 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
108 W_Porto_Fail(p.porto_current, 1);
112 void W_Porto_Think(entity this)
114 trace_plane_normal = '0 0 0';
115 if(this.realowner.playerid != this.playerid)
118 W_Porto_Fail(this, 0);
121 void W_Porto_Touch(entity this)
125 // do not use PROJECTILE_TOUCH here
126 // FIXME but DO handle warpzones!
128 if(other.classname == "portal")
129 return; // handled by the portal
131 norm = trace_plane_normal;
132 if(trace_ent.iscreature)
134 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * STAT(PL_MIN, NULL).z, MOVE_WORLDONLY, this);
135 if(trace_fraction >= 1)
137 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
139 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
143 if(this.realowner.playerid != this.playerid)
145 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
148 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
150 spamsound(this, CH_SHOTS, SND(PORTO_BOUNCE), VOL_BASE, ATTEN_NORM);
152 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
153 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
155 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
157 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
158 W_Porto_Fail(this, 0);
160 Portal_ClearAll_PortalsOnly(this.realowner);
162 else if(this.cnt == 0)
165 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
167 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
168 trace_plane_normal = norm;
169 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
170 W_Porto_Success(this);
174 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
175 trace_plane_normal = norm;
176 W_Porto_Fail(this, 0);
179 else if(this.cnt == 1)
182 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
184 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
185 trace_plane_normal = norm;
186 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
187 W_Porto_Success(this);
191 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
192 trace_plane_normal = norm;
193 W_Porto_Fail(this, 0);
196 else if(this.effects & EF_RED)
198 this.effects += EF_BLUE - EF_RED;
199 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
201 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
202 trace_plane_normal = norm;
203 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
204 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
205 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
206 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
210 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
211 trace_plane_normal = norm;
212 Portal_ClearAll_PortalsOnly(this.realowner);
213 W_Porto_Fail(this, 0);
218 if(this.realowner.portal_in.portal_id == this.portal_id)
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 Portal_ClearAll_PortalsOnly(this.realowner);
231 W_Porto_Fail(this, 0);
236 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
237 Portal_ClearAll_PortalsOnly(this.realowner);
238 W_Porto_Fail(this, 0);
243 void W_Porto_Attack(entity actor, float type)
247 W_SetupShot(actor, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0);
248 // always shoot from the eye
249 w_shotdir = v_forward;
250 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
252 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
256 gren.owner = gren.realowner = actor;
257 gren.playerid = actor.playerid;
258 gren.bot_dodge = true;
259 gren.bot_dodgerating = 200;
260 gren.movetype = MOVETYPE_BOUNCEMISSILE;
261 PROJECTILE_MAKETRIGGER(gren);
262 gren.effects = EF_RED;
264 setorigin(gren, w_shotorg);
265 setsize(gren, '0 0 0', '0 0 0');
267 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
268 setthink(gren, W_Porto_Think);
269 settouch(gren, W_Porto_Touch);
271 if(actor.items & ITEM_Strength.m_itemid)
272 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
274 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
276 gren.angles = vectoangles(gren.velocity);
277 gren.flags = FL_PROJECTILE;
279 gren.portal_id = time;
280 actor.porto_current = gren;
281 gren.playerid = actor.playerid;
282 fixedmakevectors(fixedvectoangles(gren.velocity));
283 gren.right_vector = v_right;
285 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
288 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
290 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
292 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
295 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor))
297 PHYS_INPUT_BUTTON_ATCK(actor) = false;
298 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
299 if(!WEP_CVAR(porto, secondary))
300 if(bot_aim(actor, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
301 PHYS_INPUT_BUTTON_ATCK(actor) = true;
303 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
305 if(WEP_CVAR(porto, secondary))
308 if(!actor.porto_current)
309 if(!actor.porto_forbidden)
310 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
312 W_Porto_Attack(actor, 0);
313 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
317 if(!actor.porto_current)
318 if(!actor.porto_forbidden)
319 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
321 W_Porto_Attack(actor, 1);
322 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
327 if(actor.porto_v_angle_held)
331 actor.porto_v_angle_held = 0;
333 ClientData_Touch(actor);
340 actor.porto_v_angle = actor.v_angle;
341 actor.porto_v_angle_held = 1;
343 ClientData_Touch(actor);
346 if(actor.porto_v_angle_held)
347 makevectors(actor.porto_v_angle); // override the previously set angles
350 if(!actor.porto_current)
351 if(!actor.porto_forbidden)
352 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
354 W_Porto_Attack(actor, -1);
355 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
359 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this))
361 // always allow infinite ammo
364 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this))
366 // always allow infinite ammo
369 METHOD(PortoLaunch, wr_setup, void(entity thiswep, entity actor))
371 actor.ammo_field = ammo_none;
373 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
375 actor.porto_current = NULL;
379 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
380 LOG_WARNING("Since when does Porto send DamageInfo?\n");