]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_monsters.qc
Purge self from the damage/death mutator hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_monsters.qc
index def29e969df9a8b373d50121deb37f77065877dc..f641d7944fce06f77fee7f12bd296853274397c5 100644 (file)
@@ -31,7 +31,7 @@ void monsters_setstatus(entity this)
        this.stat_monsters_killed = monsters_killed;
 }
 
-void monster_dropitem(entity this)
+void monster_dropitem(entity this, entity attacker)
 {
        if(!this.candrop || !this.monster_loot)
                return;
@@ -42,8 +42,8 @@ void monster_dropitem(entity this)
 
        e.monster_loot = this.monster_loot;
 
-       MUTATOR_CALLHOOK(MonsterDropItem, e);
-       e = other;
+       MUTATOR_CALLHOOK(MonsterDropItem, this, e, attacker);
+       e = M_ARGV(1, entity);
 
        if(e && e.monster_loot)
        {
@@ -191,7 +191,6 @@ void monster_changeteam(entity ent, float newteam)
 }
 
 .void(entity) monster_delayedfunc;
-void Monster_Delay_Action_self();
 void Monster_Delay_Action(entity this)
 {
        if(Monster_ValidTarget(this.owner, this.owner.enemy)) { this.monster_delayedfunc(this.owner); }
@@ -199,28 +198,22 @@ void Monster_Delay_Action(entity this)
        if(this.cnt > 1)
        {
                this.cnt -= 1;
-               this.think = Monster_Delay_Action_self;
+               setthink(this, Monster_Delay_Action);
                this.nextthink = time + this.count;
        }
        else
        {
-               this.think = SUB_Remove_self;
+               setthink(this, SUB_Remove);
                this.nextthink = time;
        }
 }
 
-void Monster_Delay_Action_self()
-{
-    SELFPARAM();
-       Monster_Delay_Action(self);
-}
-
 void Monster_Delay(entity this, int repeat_count, float defer_amnt, void(entity) func)
 {
        // deferred attacking, checks if monster is still alive and target is still valid before attacking
        entity e = spawn();
 
-       e.think = Monster_Delay_Action_self;
+       setthink(e, Monster_Delay_Action);
        e.nextthink = time + defer_amnt;
        e.count = defer_amnt;
        e.owner = this;
@@ -401,7 +394,7 @@ bool Monster_Attack_Leap_Check(entity this, vector vel)
        return true;
 }
 
-bool Monster_Attack_Leap(entity this, vector anm, void() touchfunc, vector vel, float animtime)
+bool Monster_Attack_Leap(entity this, vector anm, void(entity this) touchfunc, vector vel, float animtime)
 {
        if(!Monster_Attack_Leap_Check(this, vel))
                return false;
@@ -415,7 +408,7 @@ bool Monster_Attack_Leap(entity this, vector anm, void() touchfunc, vector vel,
 
        if(this.flags & FL_MONSTER)
                this.state = MONSTER_ATTACK_RANGED;
-       this.touch = touchfunc;
+       settouch(this, touchfunc);
        this.origin_z += 1;
        this.velocity = vel;
        UNSET_ONGROUND(this);
@@ -473,8 +466,8 @@ void Monster_UpdateModel(entity this)
        mon.mr_anim(mon, this);
 }
 
-void Monster_Touch()
-{SELFPARAM();
+void Monster_Touch(entity this)
+{
        if(other == world) { return; }
 
        if(other.monster_attack)
@@ -516,14 +509,14 @@ bool Monster_Respawn_Check(entity this)
        return true;
 }
 
-void Monster_Respawn() { SELFPARAM(); Monster_Spawn(this, this.monsterid); }
+void Monster_Respawn(entity this) { Monster_Spawn(this, this.monsterid); }
 
 void Monster_Dead_Fade(entity this)
 {
        if(Monster_Respawn_Check(this))
        {
                this.spawnflags |= MONSTERFLAG_RESPAWNED;
-               this.think = Monster_Respawn;
+               setthink(this, Monster_Respawn);
                this.nextthink = time + this.respawntime;
                this.monster_lifetime = 0;
                this.deadflag = DEAD_RESPAWNING;
@@ -835,7 +828,7 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
        if(this.state == MONSTER_ATTACK_RANGED && IS_ONGROUND(this))
        {
                this.state = 0;
-               this.touch = Monster_Touch;
+               settouch(this, Monster_Touch);
        }
 
        if(this.state && time >= this.attack_finished_single[0])
@@ -919,8 +912,8 @@ void Monster_Remove(entity this)
        remove(this);
 }
 
-void Monster_Dead_Think()
-{SELFPARAM();
+void Monster_Dead_Think(entity this)
+{
        this.nextthink = time + this.ticrate;
 
        if(this.monster_lifetime != 0)
@@ -943,7 +936,7 @@ bool Monster_Appear_Check(entity this, int monster_id)
        if(!(this.spawnflags & MONSTERFLAG_APPEAR))
                return false;
 
-       this.think = func_null;
+       setthink(this, func_null);
        this.monsterid = monster_id; // set so this monster is properly registered (otherwise, normal initialization is used)
        this.nextthink = 0;
        this.use = Monster_Appear;
@@ -980,7 +973,7 @@ void Monster_Dead_Damage(entity this, entity inflictor, entity attacker, float d
                // number of monsters spawned with mobspawn command
                totalspawned -= 1;
 
-               this.think = SUB_Remove_self;
+               setthink(this, SUB_Remove);
                this.nextthink = time + 0.1;
                this.event_damage = func_null;
        }
@@ -988,7 +981,7 @@ void Monster_Dead_Damage(entity this, entity inflictor, entity attacker, float d
 
 void Monster_Dead(entity this, entity attacker, float gibbed)
 {
-       this.think = Monster_Dead_Think;
+       setthink(this, Monster_Dead_Think);
        this.nextthink = time;
        this.monster_lifetime = time + 5;
 
@@ -998,7 +991,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed)
                this.health = 0; // reset by Unfreeze
        }
 
-       monster_dropitem(this);
+       monster_dropitem(this, attacker);
 
        Monster_Sound(this, monstersound_death, 0, false, CH_VOICE);
 
@@ -1022,7 +1015,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed)
        this.enemy                      = world;
        this.movetype           = MOVETYPE_TOSS;
        this.moveto                     = this.origin;
-       this.touch                      = Monster_Touch; // reset incase monster was pouncing
+       settouch(this, Monster_Touch); // reset incase monster was pouncing
        this.reset                      = func_null;
        this.state                      = 0;
        this.attack_finished_single[0] = 0;
@@ -1064,12 +1057,8 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage
        take = v_x;
        save = v_y;
 
-       damage_take = take;
-       frag_attacker = attacker;
-       frag_deathtype = deathtype;
        Monster mon = get_monsterinfo(this.monsterid);
-       mon.mr_pain(mon, this);
-       take = damage_take;
+       take = mon.mr_pain(mon, this, take, attacker, deathtype);
 
        if(take)
        {
@@ -1109,13 +1098,13 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage
 
                WaypointSprite_Kill(this.sprite);
 
-               MUTATOR_CALLHOOK(MonsterDies, this, attacker);
+               MUTATOR_CALLHOOK(MonsterDies, this, attacker, deathtype);
 
                if(this.health <= -100 || deathtype == DEATH_KILL.m_id) // check if we're already gibbed
                {
                        Violence_GibSplash(this, 1, 0.5, attacker);
 
-                       this.think = SUB_Remove_self;
+                       setthink(this, SUB_Remove);
                        this.nextthink = time + 0.1;
                }
        }
@@ -1214,9 +1203,9 @@ void Monster_Anim(entity this)
        */
 }
 
-void Monster_Think()
-{SELFPARAM();
-       this.think = Monster_Think;
+void Monster_Think(entity this)
+{
+       setthink(this, Monster_Think);
        this.nextthink = this.ticrate;
 
        if(this.monster_lifetime)
@@ -1287,7 +1276,7 @@ bool Monster_Spawn_Setup(entity this)
                }
        }
 
-       this.think = Monster_Think;
+       setthink(this, Monster_Think);
        this.nextthink = time + this.ticrate;
 
        if(MUTATOR_CALLHOOK(MonsterSpawn, this))
@@ -1331,7 +1320,7 @@ bool Monster_Spawn(entity this, int mon_id)
        this.damagedbycontents  = true;
        this.monsterid                  = mon_id;
        this.event_damage               = Monster_Damage;
-       this.touch                              = Monster_Touch;
+       settouch(this, Monster_Touch);
        this.use                                = Monster_Use;
        this.solid                              = SOLID_BBOX;
        this.movetype                   = MOVETYPE_WALK;