3 CLASS(PortoLaunch, Weapon)
4 /* ammotype */ ATTRIB(PortoLaunch, ammo_field, .int, ammo_none);
5 /* impulse */ ATTRIB(PortoLaunch, impulse, int, 0);
6 /* flags */ ATTRIB(PortoLaunch, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON);
7 /* rating */ ATTRIB(PortoLaunch, bot_pickupbasevalue, float, 0);
8 /* color */ ATTRIB(PortoLaunch, wpcolor, vector, '0.5 0.5 0.5');
9 /* modelname */ ATTRIB(PortoLaunch, mdl, string, "porto");
11 /* model */ ATTRIB(PortoLaunch, m_model, Model, MDL_PORTO_ITEM);
13 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair, string, "gfx/crosshairporto");
14 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair_size, float, 0.6);
15 /* wepimg */ ATTRIB(PortoLaunch, model2, string, "weaponporto");
16 /* refname */ ATTRIB(PortoLaunch, netname, string, "porto");
17 /* wepname */ ATTRIB(PortoLaunch, m_name, string, _("Port-O-Launch"));
19 #define X(BEGIN, P, END, class, prefix) \
21 P(class, prefix, animtime, float, BOTH) \
22 P(class, prefix, lifetime, float, BOTH) \
23 P(class, prefix, refire, float, BOTH) \
24 P(class, prefix, secondary, float, NONE) \
25 P(class, prefix, speed, float, BOTH) \
26 P(class, prefix, switchdelay_drop, float, NONE) \
27 P(class, prefix, switchdelay_raise, float, NONE) \
28 P(class, prefix, weaponreplace, string,NONE) \
29 P(class, prefix, weaponstartoverride, float, NONE) \
30 P(class, prefix, weaponstart, float, NONE) \
31 P(class, prefix, weaponthrowable, float, NONE) \
33 W_PROPS(X, PortoLaunch, porto)
36 REGISTER_WEAPON(PORTO, porto, NEW(PortoLaunch));
39 .entity porto_current;
40 .vector porto_v_angle; // holds "held" view angles
41 .float porto_v_angle_held;
43 .float porto_forbidden;
48 #include <common/triggers/trigger/jumppads.qh>
50 spawnfunc(weapon_porto) { weapon_defaultspawnfunc(this, WEP_PORTO); }
52 REGISTER_MUTATOR(porto_ticker, true);
53 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
54 FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
57 void W_Porto_Success(entity this)
59 if(this.realowner == NULL)
61 objerror(this, "Cannot succeed successfully: no owner\n");
65 this.realowner.porto_current = NULL;
69 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
70 void W_Porto_Fail(entity this, float failhard)
72 if(this.realowner == NULL)
74 objerror(this, "Cannot fail successfully: no owner\n");
81 Portal_ClearWithID(this.realowner, this.portal_id);
84 this.realowner.porto_current = NULL;
86 if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(this.realowner.weapons & WEPSET(PORTO)))
88 setsize(this, '-16 -16 0', '16 16 32');
89 setorigin(this, this.origin + trace_plane_normal);
90 if(move_out_of_solid(this))
93 IL_PUSH(g_items, this);
94 this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128);
95 tracetoss(this, this);
96 if(vdist(trace_endpos - this.realowner.origin, <, 128))
98 W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity);
99 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
106 void W_Porto_Remove(entity p)
108 if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
110 W_Porto_Fail(p.porto_current, 1);
114 void W_Porto_Think(entity this)
116 trace_plane_normal = '0 0 0';
117 if(this.realowner.playerid != this.playerid)
120 W_Porto_Fail(this, 0);
123 void W_Porto_Touch(entity this, entity toucher)
127 // do not use PROJECTILE_TOUCH here
128 // FIXME but DO handle warpzones!
130 if(toucher.classname == "portal")
131 return; // handled by the portal
133 norm = trace_plane_normal;
134 if(trace_ent.iscreature)
136 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * STAT(PL_MIN, NULL).z, MOVE_WORLDONLY, this);
137 if(trace_fraction >= 1)
139 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
141 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
145 if(this.realowner.playerid != this.playerid)
147 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
150 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
152 spamsound(this, CH_SHOTS, SND(PORTO_BOUNCE), VOL_BASE, ATTEN_NORM);
154 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
155 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
157 else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
159 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
160 W_Porto_Fail(this, 0);
162 Portal_ClearAll_PortalsOnly(this.realowner);
164 else if(this.cnt == 0)
167 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
169 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
170 trace_plane_normal = norm;
171 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
172 W_Porto_Success(this);
176 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
177 trace_plane_normal = norm;
178 W_Porto_Fail(this, 0);
181 else if(this.cnt == 1)
184 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
186 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
187 trace_plane_normal = norm;
188 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
189 W_Porto_Success(this);
193 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
194 trace_plane_normal = norm;
195 W_Porto_Fail(this, 0);
198 else if(this.effects & EF_RED)
200 this.effects += EF_BLUE - EF_RED;
201 if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
203 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
204 trace_plane_normal = norm;
205 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
206 this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
207 this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
208 CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
212 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
213 trace_plane_normal = norm;
214 Portal_ClearAll_PortalsOnly(this.realowner);
215 W_Porto_Fail(this, 0);
220 if(this.realowner.portal_in.portal_id == this.portal_id)
222 if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
224 sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
225 trace_plane_normal = norm;
226 Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
227 W_Porto_Success(this);
231 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
232 Portal_ClearAll_PortalsOnly(this.realowner);
233 W_Porto_Fail(this, 0);
238 sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
239 Portal_ClearAll_PortalsOnly(this.realowner);
240 W_Porto_Fail(this, 0);
245 void W_Porto_Attack(entity actor, .entity weaponentity, float type)
249 W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0);
250 // always shoot from the eye
251 w_shotdir = v_forward;
252 w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
254 //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
258 gren.owner = gren.realowner = actor;
259 gren.playerid = actor.playerid;
260 gren.bot_dodge = true;
261 gren.bot_dodgerating = 200;
262 set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
263 PROJECTILE_MAKETRIGGER(gren);
264 gren.effects = EF_RED;
266 setorigin(gren, w_shotorg);
267 setsize(gren, '0 0 0', '0 0 0');
269 gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
270 setthink(gren, W_Porto_Think);
271 settouch(gren, W_Porto_Touch);
273 if(actor.items & ITEM_Strength.m_itemid)
274 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
276 W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
278 gren.angles = vectoangles(gren.velocity);
279 gren.flags = FL_PROJECTILE;
280 IL_PUSH(g_projectiles, gren);
282 gren.portal_id = time;
283 actor.porto_current = gren;
284 gren.playerid = actor.playerid;
285 fixedmakevectors(fixedvectoangles(gren.velocity));
286 gren.right_vector = v_right;
288 gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
291 CSQCProjectile(gren, true, PROJECTILE_PORTO_BLUE, true);
293 CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
295 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
298 METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor))
300 PHYS_INPUT_BUTTON_ATCK(actor) = false;
301 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
302 if(!WEP_CVAR(porto, secondary))
303 if(bot_aim(actor, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
304 PHYS_INPUT_BUTTON_ATCK(actor) = true;
306 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
308 if(WEP_CVAR(porto, secondary))
311 if(!actor.porto_current)
312 if(!actor.porto_forbidden)
313 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
315 W_Porto_Attack(actor, weaponentity, 0);
316 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
320 if(!actor.porto_current)
321 if(!actor.porto_forbidden)
322 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
324 W_Porto_Attack(actor, weaponentity, 1);
325 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
330 if(actor.porto_v_angle_held)
334 actor.porto_v_angle_held = 0;
336 ClientData_Touch(actor);
343 actor.porto_v_angle = actor.v_angle;
344 actor.porto_v_angle_held = 1;
346 ClientData_Touch(actor);
349 if(actor.porto_v_angle_held)
350 makevectors(actor.porto_v_angle); // override the previously set angles
353 if(!actor.porto_current)
354 if(!actor.porto_forbidden)
355 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
357 W_Porto_Attack(actor, weaponentity, -1);
358 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
362 METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this))
364 // always allow infinite ammo
367 METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this))
369 // always allow infinite ammo
372 METHOD(PortoLaunch, wr_setup, void(entity thiswep, entity actor))
374 actor.ammo_field = ammo_none;
376 METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
378 actor.porto_current = NULL;
382 METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
383 LOG_WARN("Since when does Porto send DamageInfo?");