]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/porto.qc
Use the constants for player hitbox size when applicable (should fix observer hitbox)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / porto.qc
index be4387347ab1dbde10fd6fda7c2b1510405bfa0b..b998bc9ee8d41d42c7ee51b976cbe6cc4e63f7d3 100644 (file)
@@ -1,12 +1,13 @@
+#include "porto.qh"
 #ifndef IMPLEMENTATION
 CLASS(PortoLaunch, Weapon)
-/* ammotype  */ ATTRIB(PortoLaunch, ammo_field, .int, ammo_none)
-/* impulse   */ ATTRIB(PortoLaunch, impulse, int, 0)
+/* ammotype  */ ATTRIB(PortoLaunch, ammo_field, .int, ammo_none);
+/* impulse   */ ATTRIB(PortoLaunch, impulse, int, 0);
 /* flags     */ ATTRIB(PortoLaunch, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON);
 /* rating    */ ATTRIB(PortoLaunch, bot_pickupbasevalue, float, 0);
 /* color     */ ATTRIB(PortoLaunch, wpcolor, vector, '0.5 0.5 0.5');
 /* modelname */ ATTRIB(PortoLaunch, mdl, string, "porto");
-#ifndef MENUQC
+#ifdef GAMEQC
 /* model     */ ATTRIB(PortoLaunch, m_model, Model, MDL_PORTO_ITEM);
 #endif
 /* crosshair */ ATTRIB(PortoLaunch, w_crosshair, string, "gfx/crosshairporto");
@@ -50,88 +51,90 @@ spawnfunc(weapon_porto) { weapon_defaultspawnfunc(this, WEP_PORTO); }
 
 REGISTER_MUTATOR(porto_ticker, true);
 MUTATOR_HOOKFUNCTION(porto_ticker, SV_StartFrame) {
-       FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.porto_forbidden = max(0, it.porto_forbidden - 1)));
+       FOREACH_CLIENT(IS_PLAYER(it), it.porto_forbidden = max(0, it.porto_forbidden - 1));
 }
 
-void W_Porto_Success()
-{SELFPARAM();
-       if(self.realowner == world)
+void W_Porto_Success(entity this)
+{
+       if(this.realowner == NULL)
        {
-               objerror("Cannot succeed successfully: no owner\n");
+               objerror(this, "Cannot succeed successfully: no owner\n");
                return;
        }
 
-       self.realowner.porto_current = world;
-       remove(self);
+       this.realowner.porto_current = NULL;
+       delete(this);
 }
 
 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
-void W_Porto_Fail(float failhard)
-{SELFPARAM();
-       if(self.realowner == world)
+void W_Porto_Fail(entity this, float failhard)
+{
+       if(this.realowner == NULL)
        {
-               objerror("Cannot fail successfully: no owner\n");
+               objerror(this, "Cannot fail successfully: no owner\n");
                return;
        }
 
        // no portals here!
-       if(self.cnt < 0)
+       if(this.cnt < 0)
        {
-               Portal_ClearWithID(self.realowner, self.portal_id);
+               Portal_ClearWithID(this.realowner, this.portal_id);
        }
 
-       self.realowner.porto_current = world;
+       this.realowner.porto_current = NULL;
 
-       if(self.cnt < 0 && !failhard && self.realowner.playerid == self.playerid && !IS_DEAD(self.realowner) && !(self.realowner.weapons & WEPSET(PORTO)))
+       if(this.cnt < 0 && !failhard && this.realowner.playerid == this.playerid && !IS_DEAD(this.realowner) && !(this.realowner.weapons & WEPSET(PORTO)))
        {
-               setsize(self, '-16 -16 0', '16 16 32');
-               setorigin(self, self.origin + trace_plane_normal);
-               if(move_out_of_solid(self))
+               setsize(this, '-16 -16 0', '16 16 32');
+               setorigin(this, this.origin + trace_plane_normal);
+               if(move_out_of_solid(this))
                {
-                       self.flags = FL_ITEM;
-                       self.velocity = trigger_push_calculatevelocity(self.origin, self.realowner, 128);
-                       tracetoss(self, self);
-                       if(vdist(trace_endpos - self.realowner.origin, <, 128))
+                       this.flags = FL_ITEM;
+                       IL_PUSH(g_items, this);
+                       this.velocity = trigger_push_calculatevelocity(this.origin, this.realowner, 128);
+                       tracetoss(this, this);
+                       if(vdist(trace_endpos - this.realowner.origin, <, 128))
                        {
-                               W_ThrowNewWeapon(self.realowner, WEP_PORTO.m_id, 0, self.origin, self.velocity);
-                               Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
+                               W_ThrowNewWeapon(this.realowner, WEP_PORTO.m_id, 0, this.origin, this.velocity);
+                               Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_FAILED);
                        }
                }
        }
-       remove(self);
+       delete(this);
 }
 
 void W_Porto_Remove(entity p)
-{SELFPARAM();
+{
        if(p.porto_current.realowner == p && p.porto_current.classname == "porto")
        {
-               WITH(entity, self, p.porto_current, W_Porto_Fail(1));
+               W_Porto_Fail(p.porto_current, 1);
        }
 }
 
-void W_Porto_Think()
-{SELFPARAM();
+void W_Porto_Think(entity this)
+{
        trace_plane_normal = '0 0 0';
-       if(self.realowner.playerid != self.playerid)
-               remove(self);
+       if(this.realowner.playerid != this.playerid)
+               delete(this);
        else
-               W_Porto_Fail(0);
+               W_Porto_Fail(this, 0);
 }
 
-void W_Porto_Touch()
-{SELFPARAM();
+void W_Porto_Touch(entity this, entity toucher)
+{
        vector norm;
 
        // do not use PROJECTILE_TOUCH here
        // FIXME but DO handle warpzones!
 
-       if(other.classname == "portal")
+       if(toucher.classname == "portal")
                return; // handled by the portal
 
        norm = trace_plane_normal;
        if(trace_ent.iscreature)
        {
-               traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * STAT(PL_MIN, NULL).z, MOVE_WORLDONLY, self);
+               // TODO: why not use entity size?
+               traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_CONST.z, MOVE_WORLDONLY, this);
                if(trace_fraction >= 1)
                        return;
                if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
@@ -140,124 +143,124 @@ void W_Porto_Touch()
                        return;
        }
 
-       if(self.realowner.playerid != self.playerid)
+       if(this.realowner.playerid != this.playerid)
        {
-               sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
-               remove(self);
+               sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+               delete(this);
        }
        else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
        {
-               spamsound(self, CH_SHOTS, SND(PORTO_BOUNCE), VOL_BASE, ATTEN_NORM);
+               spamsound(this, CH_SHOTS, SND(PORTO_BOUNCE), VOL_BASE, ATTEN_NORM);
                // just reflect
-               self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
-               self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
+               this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * trace_plane_normal);
+               this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * trace_plane_normal));
        }
        else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
        {
-               sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
-               W_Porto_Fail(0);
-               if(self.cnt < 0)
-                       Portal_ClearAll_PortalsOnly(self.realowner);
+               sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+               W_Porto_Fail(this, 0);
+               if(this.cnt < 0)
+                       Portal_ClearAll_PortalsOnly(this.realowner);
        }
-       else if(self.cnt == 0)
+       else if(this.cnt == 0)
        {
                // in-portal only
-               if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
+               if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
                {
-                       sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
-                       W_Porto_Success();
+                       Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
+                       W_Porto_Success(this);
                }
                else
                {
-                       sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       W_Porto_Fail(0);
+                       W_Porto_Fail(this, 0);
                }
        }
-       else if(self.cnt == 1)
+       else if(this.cnt == 1)
        {
                // out-portal only
-               if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
+               if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
                {
-                       sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
-                       W_Porto_Success();
+                       Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
+                       W_Porto_Success(this);
                }
                else
                {
-                       sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       W_Porto_Fail(0);
+                       W_Porto_Fail(this, 0);
                }
        }
-       else if(self.effects & EF_RED)
+       else if(this.effects & EF_RED)
        {
-               self.effects += EF_BLUE - EF_RED;
-               if(Portal_SpawnInPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
+               this.effects += EF_BLUE - EF_RED;
+               if(Portal_SpawnInPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
                {
-                       sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
-                       self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
-                       self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
-                       CSQCProjectile(self, true, PROJECTILE_PORTO_BLUE, true); // change type
+                       Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_IN);
+                       this.right_vector = this.right_vector - 2 * trace_plane_normal * (this.right_vector * norm);
+                       this.angles = vectoangles(this.velocity - 2 * trace_plane_normal * (this.velocity * norm));
+                       CSQCProjectile(this, true, PROJECTILE_PORTO_BLUE, true); // change type
                }
                else
                {
-                       sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
                        trace_plane_normal = norm;
-                       Portal_ClearAll_PortalsOnly(self.realowner);
-                       W_Porto_Fail(0);
+                       Portal_ClearAll_PortalsOnly(this.realowner);
+                       W_Porto_Fail(this, 0);
                }
        }
        else
        {
-               if(self.realowner.portal_in.portal_id == self.portal_id)
+               if(this.realowner.portal_in.portal_id == this.portal_id)
                {
-                       if(Portal_SpawnOutPortalAtTrace(self.realowner, self.right_vector, self.portal_id))
+                       if(Portal_SpawnOutPortalAtTrace(this.realowner, this.right_vector, this.portal_id))
                        {
-                               sound(self, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
+                               sound(this, CH_SHOTS, SND_PORTO_CREATE, VOL_BASE, ATTEN_NORM);
                                trace_plane_normal = norm;
-                               Send_Notification(NOTIF_ONE, self.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
-                               W_Porto_Success();
+                               Send_Notification(NOTIF_ONE, this.realowner, MSG_CENTER, CENTER_PORTO_CREATED_OUT);
+                               W_Porto_Success(this);
                        }
                        else
                        {
-                               sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
-                               Portal_ClearAll_PortalsOnly(self.realowner);
-                               W_Porto_Fail(0);
+                               sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+                               Portal_ClearAll_PortalsOnly(this.realowner);
+                               W_Porto_Fail(this, 0);
                        }
                }
                else
                {
-                       sound(self, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
-                       Portal_ClearAll_PortalsOnly(self.realowner);
-                       W_Porto_Fail(0);
+                       sound(this, CH_SHOTS, SND_PORTO_UNSUPPORTED, VOL_BASE, ATTEN_NORM);
+                       Portal_ClearAll_PortalsOnly(this.realowner);
+                       W_Porto_Fail(this, 0);
                }
        }
 }
 
-void W_Porto_Attack(float type)
-{SELFPARAM();
+void W_Porto_Attack(entity actor, .entity weaponentity, float type)
+{
        entity gren;
 
-       W_SetupShot(self, false, 4, SND(PORTO_FIRE), CH_WEAPON_A, 0);
+       W_SetupShot(actor, weaponentity, false, 4, SND_PORTO_FIRE, CH_WEAPON_A, 0);
        // always shoot from the eye
        w_shotdir = v_forward;
-       w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
+       w_shotorg = actor.origin + actor.view_ofs + ((w_shotorg - actor.origin - actor.view_ofs) * v_forward) * v_forward;
 
        //Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
 
        gren = new(porto);
        gren.cnt = type;
-       gren.owner = gren.realowner = self;
-       gren.playerid = self.playerid;
+       gren.owner = gren.realowner = actor;
+       gren.playerid = actor.playerid;
        gren.bot_dodge = true;
        gren.bot_dodgerating = 200;
-       gren.movetype = MOVETYPE_BOUNCEMISSILE;
+       set_movetype(gren, MOVETYPE_BOUNCEMISSILE);
        PROJECTILE_MAKETRIGGER(gren);
        gren.effects = EF_RED;
        gren.scale = 4;
@@ -265,20 +268,22 @@ void W_Porto_Attack(float type)
        setsize(gren, '0 0 0', '0 0 0');
 
        gren.nextthink = time + WEP_CVAR_BOTH(porto, (type <= 0), lifetime);
-       gren.think = W_Porto_Think;
-       gren.touch = W_Porto_Touch;
+       setthink(gren, W_Porto_Think);
+       settouch(gren, W_Porto_Touch);
 
-       if(self.items & ITEM_Strength.m_itemid)
+       if(actor.items & ITEM_Strength.m_itemid)
                W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed) * autocvar_g_balance_powerup_strength_force, 0);
        else
                W_SetupProjVelocity_Basic(gren, WEP_CVAR_BOTH(porto, (type <= 0), speed), 0);
 
        gren.angles = vectoangles(gren.velocity);
        gren.flags = FL_PROJECTILE;
+       IL_PUSH(g_projectiles, gren);
+       IL_PUSH(g_bot_dodge, gren);
 
        gren.portal_id = time;
-       self.porto_current = gren;
-       gren.playerid = self.playerid;
+       actor.porto_current = gren;
+       gren.playerid = actor.playerid;
        fixedmakevectors(fixedvectoangles(gren.velocity));
        gren.right_vector = v_right;
 
@@ -289,17 +294,16 @@ void W_Porto_Attack(float type)
        else
                CSQCProjectile(gren, true, PROJECTILE_PORTO_RED, true);
 
-       MUTATOR_CALLHOOK(EditProjectile, self, gren);
+       MUTATOR_CALLHOOK(EditProjectile, actor, gren);
 }
 
-METHOD(PortoLaunch, wr_aim, void(entity thiswep))
+METHOD(PortoLaunch, wr_aim, void(entity thiswep, entity actor))
 {
-    SELFPARAM();
-    PHYS_INPUT_BUTTON_ATCK(self) = false;
-    PHYS_INPUT_BUTTON_ATCK2(self) = false;
+    PHYS_INPUT_BUTTON_ATCK(actor) = false;
+    PHYS_INPUT_BUTTON_ATCK2(actor) = false;
     if(!WEP_CVAR(porto, secondary))
-        if(bot_aim(WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
-            PHYS_INPUT_BUTTON_ATCK(self) = true;
+        if(bot_aim(actor, WEP_CVAR_PRI(porto, speed), 0, WEP_CVAR_PRI(porto, lifetime), false))
+            PHYS_INPUT_BUTTON_ATCK(actor) = true;
 }
 METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
 {
@@ -310,7 +314,7 @@ METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weapone
         if(!actor.porto_forbidden)
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
         {
-            W_Porto_Attack(0);
+            W_Porto_Attack(actor, weaponentity, 0);
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
         }
 
@@ -319,7 +323,7 @@ METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weapone
         if(!actor.porto_forbidden)
         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(porto, refire)))
         {
-            W_Porto_Attack(1);
+            W_Porto_Attack(actor, weaponentity, 1);
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(porto, animtime), w_ready);
         }
     }
@@ -352,35 +356,33 @@ METHOD(PortoLaunch, wr_think, void(entity thiswep, entity actor, .entity weapone
         if(!actor.porto_forbidden)
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(porto, refire)))
         {
-            W_Porto_Attack(-1);
+            W_Porto_Attack(actor, weaponentity, -1);
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(porto, animtime), w_ready);
         }
     }
 }
-METHOD(PortoLaunch, wr_checkammo1, bool(entity this))
+METHOD(PortoLaunch, wr_checkammo1, bool(entity thiswep, entity this))
 {
     // always allow infinite ammo
     return true;
 }
-METHOD(PortoLaunch, wr_checkammo2, bool(entity this))
+METHOD(PortoLaunch, wr_checkammo2, bool(entity thiswep, entity this))
 {
     // always allow infinite ammo
     return true;
 }
-METHOD(PortoLaunch, wr_setup, void(entity thiswep))
+METHOD(PortoLaunch, wr_setup, void(entity thiswep, entity actor))
 {
-    SELFPARAM();
-    self.ammo_field = ammo_none;
+    actor.ammo_field = ammo_none;
 }
-METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep))
+METHOD(PortoLaunch, wr_resetplayer, void(entity thiswep, entity actor))
 {
-    SELFPARAM();
-    self.porto_current = world;
+    actor.porto_current = NULL;
 }
 #endif
 #ifdef CSQC
-METHOD(PortoLaunch, wr_impacteffect, void(entity this)) {
-    LOG_WARNING("Since when does Porto send DamageInfo?\n");
+METHOD(PortoLaunch, wr_impacteffect, void(entity this, entity actor)) {
+    LOG_WARN("Since when does Porto send DamageInfo?");
 }
 #endif
 #endif