]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_monsters.qc
Use monster definitions directly instead of a set ID, reduces registry calls needed...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_monsters.qc
index 4c2b5ff269a601b1ff502f3977f97af5552aa532..b938b10ed60b9e5149e00803f771b1ce297be15b 100644 (file)
@@ -78,7 +78,7 @@ bool Monster_ValidTarget(entity this, entity targ)
 
        if((targ == this)
        || (autocvar_g_monsters_lineofsight && !checkpvs(this.origin + this.view_ofs, targ)) // enemy cannot be seen
-       || (IS_VEHICLE(targ) && !((REGISTRY_GET(Monsters, this.monsterid)).spawnflags & MON_FLAG_RANGED)) // melee vs vehicle is useless
+       || (IS_VEHICLE(targ) && !(this.monsterdef.spawnflags & MON_FLAG_RANGED)) // melee vs vehicle is useless
        || (time < game_starttime) // monsters do nothing before match has started
        || (targ.takedamage == DAMAGE_NO)
        || (game_stopped)
@@ -260,7 +260,7 @@ void Monster_Sound_Precache(string f)
 
 void Monster_Sounds_Precache(entity this)
 {
-       string m = (REGISTRY_GET(Monsters, this.monsterid)).m_model.model_str();
+       string m = this.monsterdef.m_model.model_str();
        float globhandle, n, i;
        string f;
 
@@ -465,7 +465,7 @@ void Monster_UpdateModel(entity this)
        this.anim_die2   = animfixfps(this, '9 1 0.01', '0 0 0');*/
 
        // then get the real values
-       Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+       Monster mon = this.monsterdef;
        mon.mr_anim(mon, this);
 }
 
@@ -512,7 +512,7 @@ bool Monster_Respawn_Check(entity this)
        return true;
 }
 
-void Monster_Respawn(entity this) { Monster_Spawn(this, true, this.monsterid); }
+void Monster_Respawn(entity this) { Monster_Spawn(this, true, this); }
 
 .vector        pos1, pos2;
 
@@ -878,16 +878,16 @@ void Monster_Dead_Think(entity this)
 void Monster_Appear(entity this, entity actor, entity trigger)
 {
        this.enemy = actor;
-       Monster_Spawn(this, false, this.monsterid);
+       Monster_Spawn(this, false, this.monsterdef);
 }
 
-bool Monster_Appear_Check(entity this, int monster_id)
+bool Monster_Appear_Check(entity this, Monster monster_id)
 {
        if(!(this.spawnflags & MONSTERFLAG_APPEAR))
                return false;
 
        setthink(this, func_null);
-       this.monsterid = monster_id; // set so this monster is properly registered (otherwise, normal initialization is used)
+       this.monsterdef = monster_id; // set so this monster is properly registered (otherwise, normal initialization is used)
        this.nextthink = 0;
        this.use = Monster_Appear;
        this.flags = FL_MONSTER; // set so this monster can get butchered
@@ -977,7 +977,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed)
 
        CSQCModel_UnlinkEntity(this);
 
-       Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+       Monster mon = this.monsterdef;
        mon.mr_death(mon, this);
 
        if(this.candrop && this.weapon)
@@ -1008,7 +1008,7 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage
        float take = v.x;
        //float save = v.y;
 
-       Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+       Monster mon = this.monsterdef;
        take = mon.mr_pain(mon, this, take, attacker, deathtype);
 
        if(take)
@@ -1236,7 +1236,7 @@ void Monster_Think(entity this)
                this.last_enemycheck = time + 1; // check for enemies every second
        }
 
-       Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+       Monster mon = this.monsterdef;
        if(mon.mr_think(mon, this))
        {
                Monster_Move(this, this.speed2, this.speed, this.stopspeed);
@@ -1252,7 +1252,7 @@ void Monster_Think(entity this)
 
 bool Monster_Spawn_Setup(entity this)
 {
-       Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+       Monster mon = this.monsterdef;
        mon.mr_setup(mon, this);
 
        // ensure some basic needs are met
@@ -1297,7 +1297,7 @@ bool Monster_Spawn_Setup(entity this)
        if(autocvar_g_monsters_healthbars)
        {
                entity wp = WaypointSprite_Spawn(WP_Monster, 0, 1024, this, '0 0 1' * (this.maxs.z + 15), NULL, this.team, this, sprite, true, RADARICON_DANGER);
-               wp.wp_extra = this.monsterid;
+               wp.wp_extra = this.monsterdef.monsterid;
                wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0 0');
                if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE))
                {
@@ -1315,12 +1315,11 @@ bool Monster_Spawn_Setup(entity this)
        return true;
 }
 
-bool Monster_Spawn(entity this, bool check_appear, int mon_id)
+bool Monster_Spawn(entity this, bool check_appear, Monster mon)
 {
        // setup the basic required properties for a monster
-       entity mon = REGISTRY_GET(Monsters, mon_id);
-       if(!mon.monsterid) { return false; } // invalid monster
 
+       if(!mon || mon == MON_Null) { return false; } // invalid monster
        if(!autocvar_g_monsters) { Monster_Remove(this); return false; }
 
        if(!(this.spawnflags & MONSTERFLAG_RESPAWNED) && !(this.flags & FL_MONSTER))
@@ -1332,7 +1331,7 @@ bool Monster_Spawn(entity this, bool check_appear, int mon_id)
                        precache_model(this.mdl_dead);
        }
 
-       if(check_appear && Monster_Appear_Check(this, mon_id)) { return true; } // return true so the monster isn't removed
+       if(check_appear && Monster_Appear_Check(this, mon)) { return true; } // return true so the monster isn't removed
 
        if(!this.monster_skill)
                this.monster_skill = cvar("g_monsters_skill");
@@ -1365,7 +1364,7 @@ bool Monster_Spawn(entity this, bool check_appear, int mon_id)
        if(!this.damagedbycontents)
                IL_PUSH(g_damagedbycontents, this);
        this.damagedbycontents  = true;
-       this.monsterid                  = mon_id;
+       this.monsterdef                 = mon;
        this.event_damage               = Monster_Damage;
        this.event_heal                 = Monster_Heal;
        settouch(this, Monster_Touch);