From: TimePath Date: Mon, 28 Sep 2015 03:45:24 +0000 (+1000) Subject: Monsters: prepare for classification X-Git-Tag: xonotic-v0.8.2~1874^2~82 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=035a588f9494a734e8eb948d4da5dfba9d5c664c;p=xonotic%2Fxonotic-data.pk3dir.git Monsters: prepare for classification --- diff --git a/qcsrc/common/animdecide.qc b/qcsrc/common/animdecide.qc index 5c2caa6a7..7e670ee73 100644 --- a/qcsrc/common/animdecide.qc +++ b/qcsrc/common/animdecide.qc @@ -12,7 +12,7 @@ bool monsters_animoverride(entity e) { - int monster_id = 0; + Monster monster_id = NULL; for(int i = MON_FIRST; i <= MON_LAST; ++i) { entity mon = get_monsterinfo(i); @@ -20,7 +20,7 @@ bool monsters_animoverride(entity e) //if(substring(e.model, 0, strlen(mon.model) - 4) == substring(mon.model, 0, strlen(mon.model) - 4)) if(e.model == mon.model) { - monster_id = i; + monster_id = mon; break; } } diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index 20a210378..ea1eb5158 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -26,14 +26,6 @@ REGISTER_REGISTRY(RegisterMonsters) #include "../util.qh" -// monster requests -const int MR_SETUP = 1; // (SERVER) setup monster data -const int MR_THINK = 2; // (SERVER) logic to run every frame -const int MR_DEATH = 3; // (SERVER) called when monster dies -const int MR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this monster -const int MR_PAIN = 5; // (SERVER) called when monster is damaged -const int MR_ANIM = 6; // (BOTH?) sets animations for monster - // special spawn flags const int MONSTER_RESPAWN_DEATHPOINT = 16; // re-spawn where we died const int MONSTER_TYPE_FLY = 32; @@ -65,7 +57,4 @@ const int MON_FLAG_RIDE = 4096; // monster can be ridden in special modes .vector anim_walk; .vector anim_spawn; -// other useful macros -#define MON_ACTION(monstertype,mrequest) (get_monsterinfo(monstertype)).monster_func(mrequest) - #endif diff --git a/qcsrc/common/monsters/monster.qh b/qcsrc/common/monsters/monster.qh index 79077acc3..ee1ff994a 100644 --- a/qcsrc/common/monsters/monster.qh +++ b/qcsrc/common/monsters/monster.qh @@ -1,7 +1,8 @@ #ifndef MONSTER_H #define MONSTER_H -bool m_null(int) { return false; } +bool m_null(entity thismon, int) { return false; } +bool m_new(entity thismon, int); /** If you register a new monster, make sure to add it to all.inc */ CLASS(Monster, Object) @@ -9,7 +10,35 @@ CLASS(Monster, Object) ATTRIB(Monster, classname, string, "monster_info") /** human readable name */ ATTRIB(Monster, monster_name, string, string_null) - ATTRIB(Monster, monster_func, bool(int), m_null) + ATTRIB(Monster, monster_func, bool(Monster, int), m_new) ENDCLASS(Monster) +// monster requests +const int MR_SETUP = 1; // (SERVER) setup monster data +.bool(Monster this) mr_setup; +const int MR_THINK = 2; // (SERVER) logic to run every frame +.bool(Monster this) mr_think; +const int MR_DEATH = 3; // (SERVER) called when monster dies +.bool(Monster this) mr_death; +const int MR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this monster +.bool(Monster this) mr_precache; +const int MR_PAIN = 5; // (SERVER) called when monster is damaged +.bool(Monster this) mr_pain; +const int MR_ANIM = 6; // (BOTH?) sets animations for monster +.bool(Monster this) mr_anim; + +// other useful macros +#define MON_ACTION(mon,mrequest) mon.monster_func(mon, mrequest) +#define _MON_ACTION(mon,mrequest) MON_ACTION(get_monsterinfo(mon), mrequest) + +bool m_new(entity this, int req) { + if (req == MR_SETUP) return this.mr_setup ? this.mr_setup(this) : false; + if (req == MR_THINK) return this.mr_think ? this.mr_think(this) : false; + if (req == MR_DEATH) return this.mr_death ? this.mr_death(this) : false; + if (req == MR_PRECACHE) return this.mr_precache ? this.mr_precache(this) : false; + if (req == MR_PAIN) return this.mr_pain ? this.mr_pain(this) : false; + if (req == MR_ANIM) return this.mr_anim ? this.mr_anim(this) : false; + return false; +} + #endif diff --git a/qcsrc/common/monsters/monster/mage.qc b/qcsrc/common/monsters/monster/mage.qc index 291ebe364..d0c6f2e29 100644 --- a/qcsrc/common/monsters/monster/mage.qc +++ b/qcsrc/common/monsters/monster/mage.qc @@ -1,5 +1,5 @@ #ifndef MENUQC -bool M_Mage(int); +bool M_Mage(Monster thismon, int); #endif REGISTER_MONSTER_SIMPLE( /* MON_##id */ MAGE, @@ -11,7 +11,7 @@ REGISTER_MONSTER_SIMPLE( ) { #ifndef MENUQC this.monster_func = M_Mage; - this.monster_func(MR_PRECACHE); + MON_ACTION(this, MR_PRECACHE); #endif } @@ -368,7 +368,7 @@ void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); } #endif // SVQC -bool M_Mage(int req) +bool M_Mage(Monster thismon, int req) {SELFPARAM(); switch(req) { diff --git a/qcsrc/common/monsters/monster/shambler.qc b/qcsrc/common/monsters/monster/shambler.qc index 55e0f46e9..dff3b7e70 100644 --- a/qcsrc/common/monsters/monster/shambler.qc +++ b/qcsrc/common/monsters/monster/shambler.qc @@ -1,5 +1,5 @@ #ifndef MENUQC -bool M_Shambler(int); +bool M_Shambler(Monster thismon, int); #endif REGISTER_MONSTER_SIMPLE( /* MON_##id */ SHAMBLER, @@ -11,7 +11,7 @@ REGISTER_MONSTER_SIMPLE( ) { #ifndef MENUQC this.monster_func = M_Shambler; - this.monster_func(MR_PRECACHE); + MON_ACTION(this, MR_PRECACHE); #endif } @@ -214,7 +214,7 @@ float M_Shambler_Attack(float attack_type) void spawnfunc_monster_shambler() { Monster_Spawn(MON_SHAMBLER.monsterid); } #endif // SVQC -bool M_Shambler(int req) +bool M_Shambler(Monster thismon, int req) {SELFPARAM(); switch(req) { diff --git a/qcsrc/common/monsters/monster/spider.qc b/qcsrc/common/monsters/monster/spider.qc index f6c3089ce..9b4d3ff25 100644 --- a/qcsrc/common/monsters/monster/spider.qc +++ b/qcsrc/common/monsters/monster/spider.qc @@ -1,5 +1,5 @@ #ifndef MENUQC -bool M_Spider(int); +bool M_Spider(Monster thismon, int); #endif REGISTER_MONSTER_SIMPLE( /* MON_##id */ SPIDER, @@ -11,7 +11,7 @@ REGISTER_MONSTER_SIMPLE( ) { #ifndef MENUQC this.monster_func = M_Spider; - this.monster_func(MR_PRECACHE); + MON_ACTION(this, MR_PRECACHE); #endif } @@ -127,7 +127,7 @@ bool M_Spider_Attack(int attack_type) void spawnfunc_monster_spider() { Monster_Spawn(MON_SPIDER.monsterid); } #endif // SVQC -bool M_Spider(int req) +bool M_Spider(Monster thismon, int req) {SELFPARAM(); switch(req) { diff --git a/qcsrc/common/monsters/monster/wyvern.qc b/qcsrc/common/monsters/monster/wyvern.qc index af174603d..2a3ce0b8f 100644 --- a/qcsrc/common/monsters/monster/wyvern.qc +++ b/qcsrc/common/monsters/monster/wyvern.qc @@ -1,5 +1,5 @@ #ifndef MENUQC -bool M_Wyvern(int); +bool M_Wyvern(Monster thismon, int); #endif REGISTER_MONSTER_SIMPLE( /* MON_##id */ WYVERN, @@ -11,7 +11,7 @@ REGISTER_MONSTER_SIMPLE( ) { #ifndef MENUQC this.monster_func = M_Wyvern; - this.monster_func(MR_PRECACHE); + MON_ACTION(this, MR_PRECACHE); #endif } @@ -104,8 +104,9 @@ float M_Wyvern_Attack(float attack_type) void spawnfunc_monster_wyvern() { Monster_Spawn(MON_WYVERN.monsterid); } #endif // SVQC -bool M_Wyvern(int req) -{SELFPARAM(); +bool M_Wyvern(Monster thismon, int req) +{ + SELFPARAM(); switch(req) { #ifdef SVQC diff --git a/qcsrc/common/monsters/monster/zombie.qc b/qcsrc/common/monsters/monster/zombie.qc index ed169c99d..8511d2e19 100644 --- a/qcsrc/common/monsters/monster/zombie.qc +++ b/qcsrc/common/monsters/monster/zombie.qc @@ -1,5 +1,5 @@ #ifndef MENUQC -bool M_Zombie(int); +bool M_Zombie(Monster thismon, int); #endif REGISTER_MONSTER_SIMPLE( /* MON_##id */ ZOMBIE, @@ -11,7 +11,7 @@ REGISTER_MONSTER_SIMPLE( ) { #ifndef MENUQC this.monster_func = M_Zombie; - this.monster_func(MR_PRECACHE); + MON_ACTION(this, MR_PRECACHE); #endif } @@ -141,7 +141,7 @@ float M_Zombie_Attack(float attack_type) void spawnfunc_monster_zombie() { Monster_Spawn(MON_ZOMBIE.monsterid); } #endif // SVQC -bool M_Zombie(int req) +bool M_Zombie(Monster thismon, int req) {SELFPARAM(); switch(req) { diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 73e6d9060..5a747532b 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -471,7 +471,7 @@ void Monster_UpdateModel() self.anim_die2 = animfixfps(self, '9 1 0.01', '0 0 0');*/ // then get the real values - MON_ACTION(self.monsterid, MR_ANIM); + _MON_ACTION(self.monsterid, MR_ANIM); } void Monster_Touch() @@ -1037,7 +1037,7 @@ void Monster_Dead(entity attacker, float gibbed) CSQCModel_UnlinkEntity(); - MON_ACTION(self.monsterid, MR_DEATH); + _MON_ACTION(self.monsterid, MR_DEATH); if(self.candrop && self.weapon) W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325'); @@ -1070,7 +1070,7 @@ void Monster_Damage(entity inflictor, entity attacker, float damage, int deathty damage_take = take; frag_attacker = attacker; frag_deathtype = deathtype; - MON_ACTION(self.monsterid, MR_PAIN); + _MON_ACTION(self.monsterid, MR_PAIN); take = damage_take; if(take) @@ -1231,7 +1231,7 @@ void Monster_Think() return; } - if(MON_ACTION(self.monsterid, MR_THINK)) + if(_MON_ACTION(self.monsterid, MR_THINK)) Monster_Move(self.speed2, self.speed, self.stopspeed); Monster_Anim(); @@ -1241,7 +1241,7 @@ void Monster_Think() float Monster_Spawn_Setup() {SELFPARAM(); - MON_ACTION(self.monsterid, MR_SETUP); + _MON_ACTION(self.monsterid, MR_SETUP); // ensure some basic needs are met if(!self.health) { self.health = 100; } diff --git a/qcsrc/server/mutators/gamemode_invasion.qc b/qcsrc/server/mutators/gamemode_invasion.qc index 412e7bd54..bb36e2654 100644 --- a/qcsrc/server/mutators/gamemode_invasion.qc +++ b/qcsrc/server/mutators/gamemode_invasion.qc @@ -14,7 +14,7 @@ void spawnfunc_invasion_spawnpoint() if(autocvar_g_invasion_zombies_only) // precache only if it hasn't been already if(self.monsterid) - MON_ACTION(self.monsterid, MR_PRECACHE); + _MON_ACTION(self.monsterid, MR_PRECACHE); } float invasion_PickMonster(float supermonster_count) @@ -431,7 +431,7 @@ void invasion_DelayedInit() // Do this check with a delay so we can wait for tea void invasion_Initialize() { if(autocvar_g_invasion_zombies_only) - MON_ACTION(MON_ZOMBIE.monsterid, MR_PRECACHE); + MON_ACTION(MON_ZOMBIE, MR_PRECACHE); else { float i; @@ -442,7 +442,7 @@ void invasion_Initialize() if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM)) continue; // flying/swimming monsters not yet supported - MON_ACTION(i, MR_PRECACHE); + MON_ACTION(mon, MR_PRECACHE); } }