]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Use monster definitions directly instead of a set ID, reduces registry calls needed...
authorMario <mario.mario@y7mail.com>
Mon, 27 Jul 2020 05:51:28 +0000 (15:51 +1000)
committerMario <mario.mario@y7mail.com>
Mon, 27 Jul 2020 05:51:28 +0000 (15:51 +1000)
16 files changed:
qcsrc/common/gamemodes/gamemode/invasion/sv_invasion.qc
qcsrc/common/monsters/all.qh
qcsrc/common/monsters/monster.qh
qcsrc/common/monsters/monster/mage.qc
qcsrc/common/monsters/monster/shambler.qc
qcsrc/common/monsters/monster/spider.qc
qcsrc/common/monsters/monster/wyvern.qc
qcsrc/common/monsters/monster/zombie.qc
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/monsters/sv_monsters.qh
qcsrc/common/monsters/sv_spawn.qc
qcsrc/common/monsters/sv_spawn.qh
qcsrc/common/monsters/sv_spawner.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/server/command/common.qc

index 31c5711424834925e91cb53e21d64da6ea2e9e39..a215040507d5bafe17968fb2c83b07db25174ce7 100644 (file)
@@ -207,7 +207,7 @@ void invasion_SpawnChosenMonster(Monster mon)
                setsize(e, mon.m_mins, mon.m_maxs);
 
                if(MoveToRandomMapLocation(e, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
-                       monster = spawnmonster(e, tospawn, mon.monsterid, NULL, NULL, e.origin, false, false, 2);
+                       monster = spawnmonster(e, tospawn, mon, NULL, NULL, e.origin, false, false, 2);
                else
                {
                        delete(e);
@@ -215,7 +215,7 @@ void invasion_SpawnChosenMonster(Monster mon)
                }
        }
        else // if spawnmob field falls through (unset), fallback to mon (relying on spawnmonster for that behaviour)
-               monster = spawnmonster(spawn(), ((spawn_point.spawnmob && spawn_point.spawnmob != "") ? spawn_point.spawnmob : tospawn), mon.monsterid, spawn_point, spawn_point, spawn_point.origin, false, false, 2);
+               monster = spawnmonster(spawn(), ((spawn_point.spawnmob && spawn_point.spawnmob != "") ? spawn_point.spawnmob : tospawn), mon, spawn_point, spawn_point, spawn_point.origin, false, false, 2);
 
        if(!monster)
                return;
@@ -290,7 +290,7 @@ bool Invasion_CheckWinner()
 
        IL_EACH(g_monsters, GetResource(it, RES_HEALTH) > 0,
        {
-               if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
+               if(it.monsterdef.spawnflags & MON_FLAG_SUPERMONSTER)
                        ++supermonster_count;
                ++total_alive_monsters;
 
@@ -467,7 +467,7 @@ MUTATOR_HOOKFUNCTION(inv, MonsterSpawn)
 
        mon.monster_skill = inv_monsterskill;
 
-       if((get_monsterinfo(mon.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
+       if(mon.monsterdef.spawnflags & MON_FLAG_SUPERMONSTER)
                Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, mon.monster_name);
 }
 
index 58840159ef60c60a386dbc5a817b3ad52ae93bc8..dfcacdc609b2da10aa47b4b1756be4d4dea6091e 100644 (file)
@@ -6,8 +6,6 @@ REGISTRY(Monsters, BITS(5))
 #define get_monsterinfo(i) REGISTRY_GET(Monsters, i)
 REGISTER_REGISTRY(Monsters)
 REGISTRY_CHECK(Monsters)
-const int MON_FIRST = 1;
-#define MON_LAST (REGISTRY_COUNT(Monsters) - 1)
 #define REGISTER_MONSTER(id, inst) REGISTER(Monsters, MON, id, monsterid, inst)
 
 #include "monster.qh"
index aba9c9aa9b66713607aa3f2c4d02412744b82e51..146f64d405533ca59aac5636f81720f16d922157 100644 (file)
@@ -17,6 +17,7 @@ const int MON_FLAG_HIDDEN = BIT(16);
 
 // entity properties of monsterinfo:
 .bool(int, entity actor, entity targ, .entity weaponentity) monster_attackfunc;
+.entity monsterdef;
 
 // animations
 .vector anim_blockend;
index 1cba349ed96e39fe5baa594b4f447b04d7af8651..8addac3531f58b4f02625b27d4082c078cf41371 100644 (file)
@@ -388,7 +388,7 @@ bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponent
        return false;
 }
 
-spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE.monsterid); }
+spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
 
 #endif // SVQC
 
index 2e3f02a0623a86f5591c5b922e0f8ce13ee27b7d..c67d90664267231a8e60df654a811425431d6795 100644 (file)
@@ -197,7 +197,7 @@ bool M_Shambler_Attack(int attack_type, entity actor, entity targ, .entity weapo
        return false;
 }
 
-spawnfunc(monster_shambler) { Monster_Spawn(this, true, MON_SHAMBLER.monsterid); }
+spawnfunc(monster_shambler) { Monster_Spawn(this, true, MON_SHAMBLER); }
 #endif // SVQC
 
 #ifdef SVQC
index d9a51c05e9a4649718deac200f0e5f4beeff9b6a..08d28218786524d462b6cf2d321b91aa38e899b0 100644 (file)
@@ -104,7 +104,7 @@ void M_Spider_Attack_Web_Explode(entity this)
                Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
                RadiusDamage(this, this.realowner, 0, 0, 25, NULL, NULL, 25, this.projectiledeathtype, DMG_NOWEP, NULL);
 
-               FOREACH_ENTITY_RADIUS(this.origin, 25, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && it.monsterid != MON_SPIDER.monsterid,
+               FOREACH_ENTITY_RADIUS(this.origin, 25, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && it.monsterdef != MON_SPIDER,
                {
                        it.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
                });
@@ -185,7 +185,7 @@ bool M_Spider_Attack(int attack_type, entity actor, entity targ, .entity weapone
        return false;
 }
 
-spawnfunc(monster_spider) { Monster_Spawn(this, true, MON_SPIDER.monsterid); }
+spawnfunc(monster_spider) { Monster_Spawn(this, true, MON_SPIDER); }
 #endif // SVQC
 
 #ifdef SVQC
index 4de122e8494419205178cc87dc74f77957699c7f..0a811cb70b5ee9da3e259c03048e1516fa771703 100644 (file)
@@ -106,7 +106,7 @@ bool M_Wyvern_Attack(int attack_type, entity actor, entity targ, .entity weapone
        return false;
 }
 
-spawnfunc(monster_wyvern) { Monster_Spawn(this, true, MON_WYVERN.monsterid); }
+spawnfunc(monster_wyvern) { Monster_Spawn(this, true, MON_WYVERN); }
 #endif // SVQC
 
 #ifdef SVQC
index 3b2c0451b89a8657afd9d681c3cd39a97a48d744..70981fa00293ec65e4e4fec6b9d6d83a04a6e302 100644 (file)
@@ -125,7 +125,7 @@ bool M_Zombie_Attack(int attack_type, entity actor, entity targ, .entity weapone
        return false;
 }
 
-spawnfunc(monster_zombie) { Monster_Spawn(this, true, MON_ZOMBIE.monsterid); }
+spawnfunc(monster_zombie) { Monster_Spawn(this, true, MON_ZOMBIE); }
 #endif // SVQC
 
 #ifdef SVQC
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);
index 9d890d7358eb71335c9f0f0e47fa40612f4853eb..755abaaf2c67f69950d4be432bd6f8c3c7cddad6 100644 (file)
@@ -70,7 +70,7 @@ void Monster_Remove(entity this);
 
 void monsters_setstatus(entity this);
 
-bool Monster_Spawn(entity this, bool check_appear, int mon_id);
+bool Monster_Spawn(entity this, bool check_appear, Monster mon);
 
 void monster_setupcolors(entity this);
 
index d456282d429ee6fbc6c5113f90b7f57484b8fcff..f4ae76df8ce919049741f1763cb6a795c5857da2 100644 (file)
@@ -8,7 +8,7 @@
     #include <server/autocvars.qh>
     #include <server/defs.qh>
 #endif
-entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
+entity spawnmonster (entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
 {
        e.spawnflags = MONSTERFLAG_SPAWNED;
 
@@ -26,7 +26,7 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                        RandomSelection_AddEnt(it, 1, 1);
                });
 
-               monster_id = RandomSelection_chosen_ent.monsterid;
+               monster_id = RandomSelection_chosen_ent;
        }
        else if(monster != "")
        {
@@ -36,12 +36,12 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                        if(it.netname == monster)
                        {
                                found = true;
-                               monster_id = it.monsterid; // we have the monster, old monster id is no longer required
+                               monster_id = it; // we have the monster, old monster id is no longer required
                                break;
                        }
                });
 
-               if(!found && !monster_id)
+               if(!found && monster_id == MON_Null)
                {
                        if(removeifinvalid)
                        {
@@ -49,7 +49,10 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                                return NULL; // no good
                        }
                        else
-                               monster_id = MON_FIRST;
+                       {
+                               // select a random valid monster type if no valid monster was provided
+                               return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
+                       }
                }
        }
 
index 983676db87d3c4a225dd141db6017ebe173624d4..2c1127b7ddadc7c62ca2956811da1c4421f4b5d9 100644 (file)
@@ -1,3 +1,5 @@
 #pragma once
 
-entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag);
+#include <common/monsters/monster.qh>
+
+entity spawnmonster (entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag);
index 13c98e93fa1f64e75271e79cba146614c1b6dd94..d12ee2bc6c184196a462a4d85ae218f80a9970b8 100644 (file)
@@ -17,7 +17,7 @@ void spawner_use(entity this, entity actor, entity trigger)
        e.angles = this.angles;
        e.monster_skill = this.monster_skill;
        e.skin = this.skin;
-       e = spawnmonster(e, this.spawnmob, 0, this, this, this.origin, false, true, this.monster_moveflags);
+       e = spawnmonster(e, this.spawnmob, MON_Null, this, this, this.origin, false, true, this.monster_moveflags);
 }
 
 spawnfunc(monster_spawner)
index f4ff4d34a532f22557c838b613bf6f3bd69f1286..a23fc36970a6822f5ca48af79b29487c338a5df5 100644 (file)
@@ -179,7 +179,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
        entity mon = M_ARGV(0, entity);
 
        // always refill ammo
-       if(mon.monsterid == MON_MAGE.monsterid)
+       if(mon.monsterdef == MON_MAGE)
                mon.skin = 1;
 }
 
index 7dffc0f4d0fc9a8d4b6122f00709feb82d2ad127..bd539aa8e68bf84451c76eab1ec82276e98c4e37 100644 (file)
@@ -673,7 +673,7 @@ void nade_monster_boom(entity this)
 {
        entity e = spawn();
        e.noalign = true; // don't drop to floor
-       e = spawnmonster(e, this.pokenade_type, 0, this.realowner, this.realowner, this.origin, false, false, 1);
+       e = spawnmonster(e, this.pokenade_type, MON_Null, this.realowner, this.realowner, this.origin, false, false, 1);
 
        if(autocvar_g_nades_pokenade_monster_lifetime > 0)
                e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
index f791446eb5872a8b0a6fb37807d430bc9aa594d0..32ccd883e97d28d0ebbce901bdd67cf8e2b4399d 100644 (file)
@@ -395,7 +395,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
 
                                        totalspawned += 1;
                                        WarpZone_TraceBox(CENTER_OR_VIEWOFS(caller), caller.mins, caller.maxs, CENTER_OR_VIEWOFS(caller) + v_forward * 150, true, caller);
-                                       mon = spawnmonster(spawn(), arg_lower, 0, caller, caller, trace_endpos, false, false, moveflag);
+                                       mon = spawnmonster(spawn(), arg_lower, MON_Null, caller, caller, trace_endpos, false, false, moveflag);
                                        print_to(caller, strcat("Spawned ", mon.monster_name));
                                        return;
                                }
@@ -416,7 +416,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        if (!autocvar_g_monsters_edit) { print_to(caller, "Monster editing is disabled"); return; }
                                        if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; }
                                        if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; }
-                                       if (mon.monsterid == MON_MAGE.monsterid) { print_to(caller, "Mage skins can't be changed"); return; }  // TODO
+                                       if (mon.monsterdef == MON_MAGE) { print_to(caller, "Mage skins can't be changed"); return; }  // TODO
 
                                        mon.skin = stof(argument);
                                        print_to(caller, strcat("Monster skin successfully changed to ", ftos(mon.skin)));