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);
}
}
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;
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;
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);
}
#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"
// entity properties of monsterinfo:
.bool(int, entity actor, entity targ, .entity weaponentity) monster_attackfunc;
+.entity monsterdef;
// animations
.vector anim_blockend;
return false;
}
-spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE.monsterid); }
+spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
#endif // SVQC
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
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);
});
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
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
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
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)
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;
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);
}
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;
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
CSQCModel_UnlinkEntity(this);
- Monster mon = REGISTRY_GET(Monsters, this.monsterid);
+ Monster mon = this.monsterdef;
mon.mr_death(mon, this);
if(this.candrop && this.weapon)
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)
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);
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
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))
{
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))
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");
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);
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);
#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;
RandomSelection_AddEnt(it, 1, 1);
});
- monster_id = RandomSelection_chosen_ent.monsterid;
+ monster_id = RandomSelection_chosen_ent;
}
else if(monster != "")
{
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)
{
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);
+ }
}
}
#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);
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)
entity mon = M_ARGV(0, entity);
// always refill ammo
- if(mon.monsterid == MON_MAGE.monsterid)
+ if(mon.monsterdef == MON_MAGE)
mon.skin = 1;
}
{
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;
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;
}
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)));