]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
Purge self from the damage/death mutator hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / onslaught.qc
index d2e85cf68734ccd6aa5746566de67b7f20a74f44..1f9c88780ee326dc6ee92436d9544de19b8ac2de 100644 (file)
@@ -162,8 +162,8 @@ void FixSize(entity e);
 // CaptureShield Functions
 // =======================
 
-bool ons_CaptureShield_Customize()
-{SELFPARAM();
+bool ons_CaptureShield_Customize(entity this)
+{
        entity e = WaypointSprite_getviewentity(other);
 
        if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
@@ -172,8 +172,8 @@ bool ons_CaptureShield_Customize()
        return true;
 }
 
-void ons_CaptureShield_Touch()
-{SELFPARAM();
+void ons_CaptureShield_Touch(entity this)
+{
        if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
        if(!IS_PLAYER(other)) { return; }
        if(SAME_TEAM(other, self)) { return; }
@@ -208,8 +208,8 @@ void ons_CaptureShield_Spawn(entity generator, bool is_generator)
        shield.team = generator.team;
        shield.colormap = generator.colormap;
        shield.reset = ons_CaptureShield_Reset;
-       shield.touch = ons_CaptureShield_Touch;
-       shield.customizeentityforclient = ons_CaptureShield_Customize;
+       settouch(shield, ons_CaptureShield_Touch);
+       setcefc(shield, ons_CaptureShield_Customize);
        shield.effects = EF_ADDITIVE;
        shield.movetype = MOVETYPE_NOCLIP;
        shield.solid = SOLID_TRIGGER;
@@ -395,8 +395,8 @@ bool ons_Link_Send(entity this, entity to, int sendflags)
        return true;
 }
 
-void ons_Link_CheckUpdate()
-{SELFPARAM();
+void ons_Link_CheckUpdate(entity this)
+{
        // TODO check if the two sides have moved (currently they won't move anyway)
        float cc = 0, cc1 = 0, cc2 = 0;
 
@@ -423,7 +423,7 @@ void ons_DelayedLinkSetup(entity this)
 
        LOG_DEBUG(strcat(etos(this.goalentity), " linked with ", etos(this.enemy), "\n"));
        this.SendFlags |= 3;
-       this.think = ons_Link_CheckUpdate;
+       setthink(this, ons_Link_CheckUpdate);
        this.nextthink = time;
 }
 
@@ -559,8 +559,8 @@ void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker
        this.SendFlags |= CPSF_STATUS;
 }
 
-void ons_ControlPoint_Icon_Think()
-{SELFPARAM();
+void ons_ControlPoint_Icon_Think(entity this)
+{
        this.nextthink = time + ONS_CP_THINKRATE;
 
        if(autocvar_g_onslaught_cp_proxydecap)
@@ -627,8 +627,8 @@ void ons_ControlPoint_Icon_Think()
        }
 }
 
-void ons_ControlPoint_Icon_BuildThink()
-{SELFPARAM();
+void ons_ControlPoint_Icon_BuildThink(entity this)
+{
        int a;
 
        this.nextthink = time + ONS_CP_THINKRATE;
@@ -646,7 +646,7 @@ void ons_ControlPoint_Icon_BuildThink()
        {
                this.health = this.max_health;
                this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
-               this.think = ons_ControlPoint_Icon_Think;
+               setthink(this, ons_ControlPoint_Icon_Think);
                sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
                this.owner.iscaptured = true;
                this.solid = SOLID_BBOX;
@@ -681,7 +681,7 @@ void ons_ControlPoint_Icon_BuildThink()
                Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
 }
 
-void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
+void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
 
 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
 {
@@ -776,8 +776,8 @@ void ons_ControlPoint_UpdateSprite(entity e)
        }
 }
 
-void ons_ControlPoint_Touch()
-{SELFPARAM();
+void ons_ControlPoint_Touch(entity this)
+{
        entity toucher = other;
        int attackable;
 
@@ -813,8 +813,8 @@ void ons_ControlPoint_Touch()
        onslaught_updatelinks();
 }
 
-void ons_ControlPoint_Think()
-{SELFPARAM();
+void ons_ControlPoint_Think(entity this)
+{
        self.nextthink = time + ONS_CP_THINKRATE;
        CSQCMODEL_AUTOUPDATE(self);
 }
@@ -830,7 +830,7 @@ void ons_ControlPoint_Reset(entity this)
        this.iscaptured = false;
        this.islinked = false;
        this.isshielded = true;
-       this.think = ons_ControlPoint_Think;
+       setthink(this, ons_ControlPoint_Think);
        this.ons_toucher = world;
        this.nextthink = time + ONS_CP_THINKRATE;
        setmodel_fixsize(this, MDL_ONS_CP_PAD1);
@@ -865,8 +865,8 @@ void ons_ControlPoint_Setup(entity cp)
        cp.team = 0;
        cp.solid = SOLID_BBOX;
        cp.movetype = MOVETYPE_NONE;
-       cp.touch = ons_ControlPoint_Touch;
-       cp.think = ons_ControlPoint_Think;
+       settouch(cp, ons_ControlPoint_Touch);
+       setthink(cp, ons_ControlPoint_Think);
        cp.nextthink = time + ONS_CP_THINKRATE;
        cp.reset = ons_ControlPoint_Reset;
        cp.colormap = 1024;
@@ -889,7 +889,7 @@ void ons_ControlPoint_Setup(entity cp)
        {
                setorigin(cp, cp.origin + '0 0 20');
                cp.noalign = false;
-               WITHSELF(cp, droptofloor());
+               droptofloor(cp);
                cp.movetype = MOVETYPE_TOSS;
        }
 
@@ -990,7 +990,7 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d
                this.takedamage = DAMAGE_NO; // can't be hurt anymore
                this.event_damage = func_null; // won't do anything if hurt
                this.count = 0; // reset counter
-               this.think = func_null;
+               setthink(this, func_null);
                this.nextthink = 0;
                //this.think(); // do the first explosion now
 
@@ -1021,8 +1021,8 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d
        this.SendFlags |= GSF_STATUS;
 }
 
-void ons_GeneratorThink()
-{SELFPARAM();
+void ons_GeneratorThink(entity this)
+{
        this.nextthink = time + GEN_THINKRATE;
        if (!gameover)
        {
@@ -1052,7 +1052,7 @@ void ons_GeneratorReset(entity this)
        this.islinked = true;
        this.isshielded = true;
        this.event_damage = ons_GeneratorDamage;
-       this.think = ons_GeneratorThink;
+       setthink(this, ons_GeneratorThink);
        this.nextthink = time + GEN_THINKRATE;
 
        Net_LinkEntity(this, false, 0, generator_send);
@@ -1083,8 +1083,8 @@ void ons_DelayedGeneratorSetup(entity this)
 }
 
 
-void onslaught_generator_touch()
-{SELFPARAM();
+void onslaught_generator_touch(entity this)
+{
        if ( IS_PLAYER(other) )
        if ( SAME_TEAM(self,other) )
        if ( self.iscaptured )
@@ -1112,12 +1112,12 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o
        gen.bot_attack = true;
        gen.event_damage = ons_GeneratorDamage;
        gen.reset = ons_GeneratorReset;
-       gen.think = ons_GeneratorThink;
+       setthink(gen, ons_GeneratorThink);
        gen.nextthink = time + GEN_THINKRATE;
        gen.iscaptured = true;
        gen.islinked = true;
        gen.isshielded = true;
-       gen.touch = onslaught_generator_touch;
+       settouch(gen, onslaught_generator_touch);
 
        // appearence
        // model handled by CSQC
@@ -1126,7 +1126,7 @@ void ons_GeneratorSetup(entity gen) // called when spawning a generator entity o
        gen.colormap = 1024 + (teamnumber - 1) * 17;
 
        // generator placement
-       WITHSELF(gen, droptofloor());
+       droptofloor(gen);
 
        // waypointsprites
        WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
@@ -1596,13 +1596,13 @@ void havocbot_ons_reset_role(entity this)
  * Find control point or generator owned by the same team self which is nearest to pos
  * if max_dist is positive, only control points within this range will be considered
  */
-entity ons_Nearest_ControlPoint(vector pos, float max_dist)
-{SELFPARAM();
+entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
+{
        entity tmp_entity, closest_target = world;
        tmp_entity = findchain(classname, "onslaught_controlpoint");
        while(tmp_entity)
        {
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                if(tmp_entity.iscaptured)
                if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
                if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
@@ -1612,7 +1612,7 @@ entity ons_Nearest_ControlPoint(vector pos, float max_dist)
        tmp_entity = findchain(classname, "onslaught_generator");
        while(tmp_entity)
        {
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
                if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
                        closest_target = tmp_entity;
@@ -1627,8 +1627,8 @@ entity ons_Nearest_ControlPoint(vector pos, float max_dist)
  * if max_dist is positive, only control points within this range will be considered
  * This function only check distances on the XY plane, disregarding Z
  */
-entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
-{SELFPARAM();
+entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
+{
        entity tmp_entity, closest_target = world;
        vector delta;
        float smallest_distance = 0, distance;
@@ -1640,7 +1640,7 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
                delta_z = 0;
                distance = vlen(delta);
 
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                if(tmp_entity.iscaptured)
                if(max_dist <= 0 || distance <= max_dist)
                if(closest_target == world || distance <= smallest_distance )
@@ -1658,7 +1658,7 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
                delta_z = 0;
                distance = vlen(delta);
 
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                if(max_dist <= 0 || distance <= max_dist)
                if(closest_target == world || distance <= smallest_distance )
                {
@@ -1755,7 +1755,7 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe
 // ==============
 
 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
-{SELFPARAM();
+{
        FOREACH_CLIENT(IS_PLAYER(it), {
                it.ons_roundlost = false;
                it.ons_deathloc = '0 0 0';
@@ -1777,10 +1777,12 @@ MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
 }
 
 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
-{SELFPARAM();
+{
+       entity player = M_ARGV(0, entity);
+
        if(!round_handler_IsRoundStarted())
        {
-               self.player_blocked = true;
+               player.player_blocked = true;
                return false;
        }
 
@@ -1794,13 +1796,13 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                l.sprite.SendFlags |= 16;
        }
 
-       if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
+       if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
 
        if ( autocvar_g_onslaught_spawn_choose )
-       if ( self.ons_spawn_by )
-       if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
+       if ( player.ons_spawn_by )
+       if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
        {
-               self.ons_spawn_by = world;
+               player.ons_spawn_by = world;
                return false;
        }
 
@@ -1809,7 +1811,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
        {
                float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
                entity tmp_entity, closest_target = world;
-               vector spawn_loc = self.ons_deathloc;
+               vector spawn_loc = player.ons_deathloc;
 
                // new joining player or round reset, don't bother checking
                if(spawn_loc == '0 0 0') { return false; }
@@ -1818,7 +1820,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
 
                for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
                {
-                       if(SAME_TEAM(tmp_entity, self))
+                       if(SAME_TEAM(tmp_entity, player))
                        if(random_target)
                                RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
                        else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
@@ -1837,14 +1839,14 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                                iteration_scale -= i / 10;
                                loc = closest_target.origin + '0 0 96' * iteration_scale;
                                loc += ('0 1 0' * random()) * 128 * iteration_scale;
-                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
+                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
                                if(trace_fraction == 1.0 && !trace_startsolid)
                                {
                                        traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
                                        if(trace_fraction == 1.0 && !trace_startsolid)
                                        {
-                                               setorigin(self, loc);
-                                               self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
+                                               setorigin(player, loc);
+                                               player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
                                                return false;
                                        }
                                }
@@ -1857,7 +1859,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
        {
                float random_target = autocvar_g_onslaught_spawn_at_generator_random;
                entity tmp_entity, closest_target = world;
-               vector spawn_loc = self.ons_deathloc;
+               vector spawn_loc = player.ons_deathloc;
 
                // new joining player or round reset, don't bother checking
                if(spawn_loc == '0 0 0') { return false; }
@@ -1870,7 +1872,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                                RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
                        else
                        {
-                               if(SAME_TEAM(tmp_entity, self))
+                               if(SAME_TEAM(tmp_entity, player))
                                if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
                                        closest_target = tmp_entity;
                        }
@@ -1888,14 +1890,14 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                                iteration_scale -= i / 10;
                                loc = closest_target.origin + '0 0 128' * iteration_scale;
                                loc += ('0 1 0' * random()) * 256 * iteration_scale;
-                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
+                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
                                if(trace_fraction == 1.0 && !trace_startsolid)
                                {
                                        traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
                                        if(trace_fraction == 1.0 && !trace_startsolid)
                                        {
-                                               setorigin(self, loc);
-                                               self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
+                                               setorigin(player, loc);
+                                               player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
                                                return false;
                                        }
                                }
@@ -1908,6 +1910,8 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
 
 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
 {
+       entity frag_target = M_ARGV(2, entity);
+
        frag_target.ons_deathloc = frag_target.origin;
        entity l;
        for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
@@ -2024,13 +2028,17 @@ MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
 }
 
 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
-{SELFPARAM();
+{
        if(MUTATOR_RETURNVALUE) // command was already handled?
                return false;
 
+       entity player = M_ARGV(0, entity);
+       string cmd_name = M_ARGV(1, string);
+       int cmd_argc = M_ARGV(2, int);
+
        if ( cmd_name == "ons_spawn" )
        {
-               vector pos = self.origin;
+               vector pos = player.origin;
                if(cmd_argc > 1)
                        pos_x = stof(argv(1));
                if(cmd_argc > 2)
@@ -2038,53 +2046,53 @@ MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
                if(cmd_argc > 3)
                        pos_z = stof(argv(3));
 
-               if ( IS_PLAYER(self) )
+               if ( IS_PLAYER(player) )
                {
-                       if ( !STAT(FROZEN, self) )
+                       if ( !STAT(FROZEN, player) )
                        {
-                               entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
+                               entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
 
-                               if ( !source_point && self.health > 0 )
+                               if ( !source_point && player.health > 0 )
                                {
-                                       sprint(self, "\nYou need to be next to a control point\n");
-                                       return 1;
+                                       sprint(player, "\nYou need to be next to a control point\n");
+                                       return true;
                                }
 
 
-                               entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
+                               entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
 
                                if ( closest_target == world )
                                {
-                                       sprint(self, "\nNo control point found\n");
-                                       return 1;
+                                       sprint(player, "\nNo control point found\n");
+                                       return true;
                                }
 
-                               if ( self.health <= 0 )
+                               if ( player.health <= 0 )
                                {
-                                       self.ons_spawn_by = closest_target;
-                                       self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
+                                       player.ons_spawn_by = closest_target;
+                                       player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
                                }
                                else
                                {
                                        if ( source_point == closest_target )
                                        {
-                                               sprint(self, "\nTeleporting to the same point\n");
-                                               return 1;
+                                               sprint(player, "\nTeleporting to the same point\n");
+                                               return true;
                                        }
 
-                                       if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
-                                               sprint(self, "\nUnable to teleport there\n");
+                                       if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
+                                               sprint(player, "\nUnable to teleport there\n");
                                }
 
-                               return 1;
+                               return true;
                        }
 
-                       sprint(self, "\nNo teleportation for you\n");
+                       sprint(player, "\nNo teleportation for you\n");
                }
 
-               return 1;
+               return true;
        }
-       return 0;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
@@ -2093,7 +2101,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
 
        if((time > self.teleport_antispam) && (!IS_DEAD(self)) && !self.vehicle)
        {
-               entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
+               entity source_point = ons_Nearest_ControlPoint(self, self.origin, autocvar_g_onslaught_teleport_radius);
                if ( source_point )
                {
                        stuffcmd(self, "qc_cmd_cl hud clickradar\n");
@@ -2156,7 +2164,7 @@ MUTATOR_HOOKFUNCTION(ons, TurretThink)
        }
 
        if(self.team != self.tur_head.team)
-               turret_respawn();
+               turret_respawn(self);
 
        return false;
 }