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);
//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;
}
}
#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;
.vector anim_walk;
.vector anim_spawn;
-// other useful macros
-#define MON_ACTION(monstertype,mrequest) (get_monsterinfo(monstertype)).monster_func(mrequest)
-
#endif
#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)
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
#ifndef MENUQC
-bool M_Mage(int);
+bool M_Mage(Monster thismon, int);
#endif
REGISTER_MONSTER_SIMPLE(
/* MON_##id */ MAGE,
) {
#ifndef MENUQC
this.monster_func = M_Mage;
- this.monster_func(MR_PRECACHE);
+ MON_ACTION(this, MR_PRECACHE);
#endif
}
#endif // SVQC
-bool M_Mage(int req)
+bool M_Mage(Monster thismon, int req)
{SELFPARAM();
switch(req)
{
#ifndef MENUQC
-bool M_Shambler(int);
+bool M_Shambler(Monster thismon, int);
#endif
REGISTER_MONSTER_SIMPLE(
/* MON_##id */ SHAMBLER,
) {
#ifndef MENUQC
this.monster_func = M_Shambler;
- this.monster_func(MR_PRECACHE);
+ MON_ACTION(this, MR_PRECACHE);
#endif
}
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)
{
#ifndef MENUQC
-bool M_Spider(int);
+bool M_Spider(Monster thismon, int);
#endif
REGISTER_MONSTER_SIMPLE(
/* MON_##id */ SPIDER,
) {
#ifndef MENUQC
this.monster_func = M_Spider;
- this.monster_func(MR_PRECACHE);
+ MON_ACTION(this, MR_PRECACHE);
#endif
}
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)
{
#ifndef MENUQC
-bool M_Wyvern(int);
+bool M_Wyvern(Monster thismon, int);
#endif
REGISTER_MONSTER_SIMPLE(
/* MON_##id */ WYVERN,
) {
#ifndef MENUQC
this.monster_func = M_Wyvern;
- this.monster_func(MR_PRECACHE);
+ MON_ACTION(this, MR_PRECACHE);
#endif
}
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
#ifndef MENUQC
-bool M_Zombie(int);
+bool M_Zombie(Monster thismon, int);
#endif
REGISTER_MONSTER_SIMPLE(
/* MON_##id */ ZOMBIE,
) {
#ifndef MENUQC
this.monster_func = M_Zombie;
- this.monster_func(MR_PRECACHE);
+ MON_ACTION(this, MR_PRECACHE);
#endif
}
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)
{
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()
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');
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)
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();
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; }
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)
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;
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);
}
}