]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
Fix up more mutator hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / nexball / nexball.qc
index cc24cfde6449d86b2dbfe13fd7dae679740f4fe4..a7528d5a1945588d8a1d2eb7873a44f40aecf92c 100644 (file)
@@ -1,6 +1,18 @@
 #include "nexball.qh"
 
 #ifdef IMPLEMENTATION
+#ifdef CSQC
+int autocvar_cl_eventchase_nexball = 1;
+
+REGISTER_MUTATOR(cl_nb, true);
+
+MUTATOR_HOOKFUNCTION(cl_nb, WantEventchase)
+{
+       if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WEPSET(NEXBALL)))
+               return true;
+       return false;
+}
+#endif
 #ifdef SVQC
 .float metertime = _STAT(NB_METERSTART);
 
@@ -40,9 +52,9 @@ float autocvar_g_balance_nexball_secondary_lifetime;
 float autocvar_g_balance_nexball_secondary_refire;
 float autocvar_g_balance_nexball_secondary_speed;
 
-void basketball_touch();
-void football_touch();
-void ResetBall();
+void basketball_touch(entity this);
+void football_touch(entity this);
+void ResetBall(entity this);
 const int NBM_NONE = 0;
 const int NBM_FOOTBALL = 2;
 const int NBM_BASKETBALL = 4;
@@ -84,11 +96,11 @@ void ball_restart(entity this)
 {
        if(this.owner)
                DropBall(this, this.owner.origin, '0 0 0');
-       ResetBall();
+       ResetBall(this);
 }
 
-void nexball_setstatus()
-{SELFPARAM();
+void nexball_setstatus(entity this)
+{
        this.items &= ~IT_KEY1;
        if(this.ballcarried)
        {
@@ -96,7 +108,8 @@ void nexball_setstatus()
                {
                        bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
                        DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
-                       WITHSELF(this.ballcarried, ResetBall());
+                       entity e = this.ballcarried;
+                       WITHSELF(e, ResetBall(e));
                }
                else
                        this.items |= IT_KEY1;
@@ -120,8 +133,8 @@ void relocate_nexball(entity this)
        }
 }
 
-void DropOwner()
-{SELFPARAM();
+void DropOwner(entity this)
+{
        entity ownr;
        ownr = this.owner;
        DropBall(this, ownr.origin, ownr.velocity);
@@ -175,7 +188,7 @@ void GiveBall(entity plyr, entity ball)
 
        if(autocvar_g_nexball_basketball_delay_hold)
        {
-               ball.think = DropOwner;
+               setthink(ball, DropOwner);
                ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
        }
 
@@ -183,7 +196,7 @@ void GiveBall(entity plyr, entity ball)
        plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
        plyr.weapons = WEPSET(NEXBALL);
        Weapon w = WEP_NEXBALL;
-       WITHSELF(plyr, w.wr_resetplayer(w));
+       WITHSELF(plyr, w.wr_resetplayer(w, plyr));
        PS(plyr).m_switchweapon = WEP_NEXBALL;
        WITHSELF(plyr, W_SwitchWeapon(plyr, WEP_NEXBALL));
 }
@@ -202,7 +215,7 @@ void DropBall(entity ball, vector org, vector vel)
        ball.velocity = vel;
        ball.nb_droptime = time;
        settouch(ball, basketball_touch);
-       ball.think = ResetBall;
+       setthink(ball, ResetBall);
        ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
 
        if(ball.owner.metertime)
@@ -220,8 +233,8 @@ void DropBall(entity ball, vector org, vector vel)
        ball.owner = world;
 }
 
-void InitBall()
-{SELFPARAM();
+void InitBall(entity this)
+{
        if(gameover) return;
        UNSET_ONGROUND(this);
        this.movetype = MOVETYPE_BOUNCE;
@@ -230,7 +243,7 @@ void InitBall()
        else if(this.classname == "nexball_football")
                settouch(this, football_touch);
        this.cnt = 0;
-       this.think = ResetBall;
+       setthink(this, ResetBall);
        this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
        this.teamtime = 0;
        this.pusher = world;
@@ -240,8 +253,8 @@ void InitBall()
        LogNB("init", world);
 }
 
-void ResetBall()
-{SELFPARAM();
+void ResetBall(entity this)
+{
        if(this.cnt < 2)        // step 1
        {
                if(time == this.teamtime)
@@ -271,13 +284,13 @@ void ResetBall()
                this.velocity = '0 0 0';
                setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
                this.movetype = MOVETYPE_NONE;
-               this.think = InitBall;
+               setthink(this, InitBall);
                this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
        }
 }
 
-void football_touch()
-{SELFPARAM();
+void football_touch(entity this)
+{
        if(other.solid == SOLID_BSP)
        {
                if(time > self.lastground + 0.1)
@@ -322,11 +335,11 @@ void football_touch()
        self.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
 }
 
-void basketball_touch()
-{SELFPARAM();
+void basketball_touch(entity this)
+{
        if(other.ballcarried)
        {
-               football_touch();
+               football_touch(this);
                return;
        }
        if(!self.cnt && IS_PLAYER(other) && !STAT(FROZEN, other) && !IS_DEAD(other) && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
@@ -344,8 +357,8 @@ void basketball_touch()
        }
 }
 
-void GoalTouch()
-{SELFPARAM();
+void GoalTouch(entity this)
+{
        entity ball;
        float isclient, pscore, otherteam;
        string pname;
@@ -427,7 +440,7 @@ void GoalTouch()
        WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
 
        ball.cnt = 1;
-       ball.think = ResetBall;
+       setthink(ball, ResetBall);
        if(ball.classname == "nexball_basketball")
                settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
        ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
@@ -556,7 +569,7 @@ void SpawnBall(entity this)
        WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
 
        this.reset = ball_restart;
-       this.think = InitBall;
+       setthink(this, InitBall);
        this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
 }
 
@@ -596,8 +609,8 @@ spawnfunc(nexball_football)
        SpawnBall(this);
 }
 
-float nb_Goal_Customize()
-{SELFPARAM();
+float nb_Goal_Customize(entity this)
+{
        entity e, wp_owner;
        e = WaypointSprite_getviewentity(other);
        wp_owner = self.owner;
@@ -616,7 +629,7 @@ void SpawnGoal(entity this)
        {
                entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
                wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
-               this.sprite.customizeentityforclient = nb_Goal_Customize;
+               setcefc(this.sprite, nb_Goal_Customize);
        }
 
        this.classname = "nexball_goal";
@@ -702,8 +715,8 @@ spawnfunc(ball_bound)
 //=======================//
 
 
-void W_Nexball_Think()
-{SELFPARAM();
+void W_Nexball_Think(entity this)
+{
        //dprint("W_Nexball_Think\n");
        //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
        vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
@@ -717,18 +730,18 @@ void W_Nexball_Think()
        this.nextthink = time;
 }
 
-void W_Nexball_Touch()
-{SELFPARAM();
+void W_Nexball_Touch(entity this)
+{
        entity ball, attacker;
-       attacker = self.owner;
-       //self.think = func_null;
-       //self.enemy = world;
+       attacker = this.owner;
+       //this.think = func_null;
+       //this.enemy = world;
 
-       PROJECTILE_TOUCH;
+       PROJECTILE_TOUCH(this);
        if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
                if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
                {
-                       other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
+                       other.velocity = other.velocity + normalize(this.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
                        UNSET_ONGROUND(other);
                        if(!attacker.ballcarried)
                        {
@@ -745,22 +758,22 @@ void W_Nexball_Touch()
                                GiveBall(attacker, other.ballcarried);
                        }
                }
-       remove(self);
+       remove(this);
 }
 
-void W_Nexball_Attack(float t)
-{SELFPARAM();
+void W_Nexball_Attack(entity actor, float t)
+{
        entity ball;
        float mul, mi, ma;
-       if(!(ball = self.ballcarried))
+       if(!(ball = actor.ballcarried))
                return;
 
-       W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
+       W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
        tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
        if(trace_startsolid)
        {
-               if(self.metertime)
-                       self.metertime = 0; // Shot failed, hide the power meter
+               if(actor.metertime)
+                       actor.metertime = 0; // Shot failed, hide the power meter
                return;
        }
 
@@ -778,7 +791,7 @@ void W_Nexball_Attack(float t)
                mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
        }
 
-       DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
+       DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
 
 
        //TODO: use the speed_up cvar too ??
@@ -786,14 +799,14 @@ void W_Nexball_Attack(float t)
 
 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
 
-void W_Nexball_Attack2()
-{SELFPARAM();
-       if(self.ballcarried.enemy)
+void W_Nexball_Attack2(entity actor)
+{
+       if(actor.ballcarried.enemy)
        {
-               entity _ball = self.ballcarried;
-               W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
+               entity _ball = actor.ballcarried;
+               W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
                DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
-               _ball.think = W_Nexball_Think;
+               setthink(_ball, W_Nexball_Think);
                _ball.nextthink = time;
                return;
        }
@@ -801,10 +814,10 @@ void W_Nexball_Attack2()
        if(!autocvar_g_nexball_tackling)
                return;
 
-       W_SetupShot(self, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
+       W_SetupShot(actor, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
        entity missile = new(ballstealer);
 
-       missile.owner = self;
+       missile.owner = actor;
 
        missile.movetype = MOVETYPE_FLY;
        PROJECTILE_MAKETRIGGER(missile);
@@ -816,7 +829,7 @@ void W_Nexball_Attack2()
        W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
        missile.angles = vectoangles(missile.velocity);
        settouch(missile, W_Nexball_Touch);
-       missile.think = SUB_Remove_self;
+       setthink(missile, SUB_Remove);
        missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
 
        missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
@@ -825,13 +838,13 @@ void W_Nexball_Attack2()
        CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
 }
 
-float ball_customize()
-{SELFPARAM();
+float ball_customize(entity this)
+{
        if(!self.owner)
        {
                self.effects &= ~EF_FLAME;
                self.scale = 1;
-               self.customizeentityforclient = func_null;
+               setcefc(self, func_null);
                return true;
        }
 
@@ -854,38 +867,37 @@ float ball_customize()
 
 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
 {
-    SELFPARAM();
     TC(BallStealer, thiswep);
     if(fire & 1)
         if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
             if(autocvar_g_nexball_basketball_meter)
             {
-                if(self.ballcarried && !self.metertime)
-                    self.metertime = time;
+                if(actor.ballcarried && !actor.metertime)
+                    actor.metertime = time;
                 else
                     weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
             }
             else
             {
-                W_Nexball_Attack(-1);
+                W_Nexball_Attack(actor, -1);
                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
             }
     if(fire & 2)
         if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
         {
-            W_Nexball_Attack2();
+            W_Nexball_Attack2(actor);
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
         }
 
-    if(!(fire & 1) && self.metertime && self.ballcarried)
+    if(!(fire & 1) && actor.metertime && actor.ballcarried)
     {
-        W_Nexball_Attack(time - self.metertime);
+        W_Nexball_Attack(actor, time - actor.metertime);
         // DropBall or stealing will set metertime back to 0
         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
     }
 }
 
-METHOD(BallStealer, wr_setup, void(BallStealer this))
+METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
 {
     TC(BallStealer, this);
     //weapon_setup(WEP_PORTO.m_id);
@@ -910,20 +922,24 @@ void nb_DropBall(entity player)
 }
 
 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
-{SELFPARAM();
-       nb_DropBall(self);
-       return false;
+{
+       entity player = M_ARGV(0, entity);
+
+       nb_DropBall(player);
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
 {
+       entity frag_target = M_ARGV(2, entity);
+
        nb_DropBall(frag_target);
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
-{SELFPARAM();
-       nb_DropBall(self);
+{
+       entity player = M_ARGV(0, entity);
+
+       nb_DropBall(player);
        return false;
 }
 
@@ -936,7 +952,7 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                {
                        // 'view ball'
                        self.ballcarried.velocity = self.velocity;
-                       self.ballcarried.customizeentityforclient = ball_customize;
+                       setcefc(self.ballcarried, ball_customize);
 
                        vector org = self.origin + self.view_ofs +
                                          v_forward * autocvar_g_nexball_viewmodel_offset.x +
@@ -979,7 +995,7 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                        {
                                self.weapons = self.(weaponentity).weapons;
                                Weapon w = WEP_NEXBALL;
-                               w.wr_resetplayer(w);
+                               w.wr_resetplayer(w, self);
                                PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
                                W_SwitchWeapon(self, PS(self).m_switchweapon);
 
@@ -989,28 +1005,31 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
 
        }
 
-       nexball_setstatus();
+       nexball_setstatus(self);
 
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
 {
-       SELFPARAM();
-       this.metertime = other.metertime;
+       entity spectatee = M_ARGV(0, entity);
+       entity client = M_ARGV(1, entity);
+
+       client.metertime = spectatee.metertime;
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
 {
-       SELFPARAM();
-       this.metertime = 0;
+       entity player = M_ARGV(0, entity);
+
+       player.metertime = 0;
        .entity weaponentity = weaponentities[0];
-       this.(weaponentity).weapons = '0 0 0';
+       player.(weaponentity).weapons = '0 0 0';
 
        if (nexball_mode & NBM_BASKETBALL)
-               this.weapons |= WEPSET(NEXBALL);
+               player.weapons |= WEPSET(NEXBALL);
        else
-               this.weapons = '0 0 0';
+               player.weapons = '0 0 0';
 
        return false;
 }
@@ -1029,19 +1048,25 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
 }
 
 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
-{SELFPARAM();
-       return PS(self).m_weapon == WEP_NEXBALL;
+{
+       entity player = M_ARGV(0, entity);
+
+       return PS(player).m_weapon == WEP_NEXBALL;
 }
 
 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
-{SELFPARAM();
-       return PS(self).m_weapon == WEP_MORTAR; // TODO: what is this for?
+{
+       entity player = M_ARGV(0, entity);
+
+       return PS(player).m_weapon == WEP_MORTAR; // TODO: what is this for?
 }
 
 MUTATOR_HOOKFUNCTION(nb, FilterItem)
-{SELFPARAM();
-       if(self.classname == "droppedweapon")
-       if(self.weapon == WEP_NEXBALL.m_id)
+{
+       entity item = M_ARGV(0, entity);
+
+       if(item.classname == "droppedweapon")
+       if(item.weapon == WEP_NEXBALL.m_id)
                return true;
 
        return false;
@@ -1049,18 +1074,20 @@ MUTATOR_HOOKFUNCTION(nb, FilterItem)
 
 MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
 {
-       ret_string = "nexball_team";
+       M_ARGV(1, string) = "nexball_team";
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
 {
-       ret_float = 0; // weapon is set a few lines later, apparently
+       M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
 {
+       entity frag_target = M_ARGV(0, entity);
+
        if(frag_target.ballcarried)
                DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);