]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_monsters.qc
Merge branch 'master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_monsters.qc
index fe2f0a40f99dd4ddbf3fe7662fa032d8b6f13947..013eea7436b122149ed78db98f0fff22d6bbc93a 100644 (file)
@@ -1,5 +1,5 @@
 // =========================
-//  SVQC Monster Properties
+//     SVQC Monster Properties
 // =========================
 
 
@@ -9,8 +9,11 @@ void monster_item_spawn()
                self.monster_loot();
 
        self.gravity = 1;
+       self.reset = SUB_Remove;
+       self.noalign = TRUE;
        self.velocity = randomvec() * 175 + '0 0 325';
        self.classname = "droppedweapon"; // hax
+       self.item_spawnshieldtime = time + 0.7;
 
        SUB_SetFade(self, time + autocvar_g_monsters_drop_time, 1);
 }
@@ -38,14 +41,11 @@ void monster_dropitem()
        }
 }
 
-void monsters_setframe(float _frame)
+float Monster_SkillModifier()
 {
-       if(self.frame == _frame)
-               return;
+       float t = 0.5+self.monster_skill*((1.2-0.3)/10);
 
-       self.anim_start_time = time;
-       self.frame = _frame;
-       self.SendFlags |= MSF_ANIM;
+       return t;
 }
 
 float monster_isvalidtarget (entity targ, entity ent)
@@ -62,7 +62,7 @@ float monster_isvalidtarget (entity targ, entity ent)
                return FALSE;
 
        if(targ.vehicle_flags & VHF_ISVEHICLE)
-       if not((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED)
+       if(!((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED))
                return FALSE; // melee attacks are useless against vehicles
 
        if(time < game_starttime)
@@ -83,7 +83,7 @@ float monster_isvalidtarget (entity targ, entity ent)
        if(IS_SPEC(targ) || IS_OBSERVER(targ))
                return FALSE; // enemy is a spectator
 
-       if not(targ.vehicle_flags & VHF_ISVEHICLE)
+       if(!(targ.vehicle_flags & VHF_ISVEHICLE))
        if(targ.deadflag != DEAD_NO || ent.deadflag != DEAD_NO || targ.health <= 0 || ent.health <= 0)
                return FALSE; // enemy/self is dead
 
@@ -93,18 +93,18 @@ float monster_isvalidtarget (entity targ, entity ent)
        if(targ.monster_owner == ent)
                return FALSE; // don't attack our pet
 
-       if not(targ.vehicle_flags & VHF_ISVEHICLE)
+       if(!(targ.vehicle_flags & VHF_ISVEHICLE))
        if(targ.flags & FL_NOTARGET)
                return FALSE; // enemy can't be targeted
 
-       if not(autocvar_g_monsters_typefrag)
+       if(!autocvar_g_monsters_typefrag)
        if(targ.BUTTON_CHAT)
                return FALSE; // no typefragging!
 
        if(SAME_TEAM(targ, ent))
                return FALSE; // enemy is on our team
-               
-       if (targ.frozen == 1 || (targ.frozen == 2 && ent.monsterid != MON_SPIDER))
+
+       if (targ.freezetag_frozen)
                return FALSE; // ignore frozen
 
        if(autocvar_g_monsters_target_infront || ent.spawnflags & MONSTERFLAG_INFRONT)
@@ -160,7 +160,7 @@ void MonsterTouch ()
                return;
 
        if(self.enemy != other)
-       if not(other.flags & FL_MONSTER)
+       if(!(other.flags & FL_MONSTER))
        if(monster_isvalidtarget(other, self))
                self.enemy = other;
 }
@@ -299,8 +299,6 @@ void monster_makevectors(entity e)
 
 float monster_melee(entity targ, float damg, float anim, float er, float anim_finished, float deathtype, float dostop)
 {
-       float rdmg = damg * random();
-
        if (self.health <= 0)
                return FALSE; // attacking while dead?!
 
@@ -309,10 +307,9 @@ float monster_melee(entity targ, float damg, float anim, float er, float anim_fi
                self.velocity_x = 0;
                self.velocity_y = 0;
                self.state = MONSTER_STATE_ATTACK_MELEE;
-               self.SendFlags |= MSF_MOVE;
        }
 
-       monsters_setframe(anim);
+       self.frame = anim;
 
        if(anim_finished != 0)
                self.attack_finished_single = time + anim_finished;
@@ -322,7 +319,7 @@ float monster_melee(entity targ, float damg, float anim, float er, float anim_fi
        traceline(self.origin + self.view_ofs, self.origin + v_forward * er, 0, self);
 
        if(trace_ent.takedamage)
-               Damage(trace_ent, self, self, rdmg * monster_skill, deathtype, trace_ent.origin, normalize(trace_ent.origin - self.origin));
+               Damage(trace_ent, self, self, damg * Monster_SkillModifier(), deathtype, trace_ent.origin, normalize(trace_ent.origin - self.origin));
 
        return TRUE;
 }
@@ -338,21 +335,23 @@ void Monster_CheckMinibossFlag ()
        if ((self.spawnflags & MONSTERFLAG_MINIBOSS) || (chance < autocvar_g_monsters_miniboss_chance))
        {
                self.health += autocvar_g_monsters_miniboss_healthboost;
-               if not(self.weapon)
-                       self.weapon = WEP_NEX;
+               self.effects |= EF_RED;
+               if(!self.weapon)
+                       self.weapon = WEP_VORTEX;
        }
 }
 
 float Monster_CanRespawn(entity ent)
 {
        other = ent;
+       if(ent.deadflag == DEAD_DEAD) // don't call when monster isn't dead
        if(MUTATOR_CALLHOOK(MonsterRespawn))
                return TRUE; // enabled by a mutator
 
        if(ent.spawnflags & MONSTERFLAG_NORESPAWN)
                return FALSE;
 
-       if not(autocvar_g_monsters_respawn)
+       if(!autocvar_g_monsters_respawn)
                return FALSE;
 
        return TRUE;
@@ -362,9 +361,10 @@ void Monster_Fade ()
 {
        if(Monster_CanRespawn(self))
        {
-               self.monster_respawned = TRUE;
+               self.spawnflags |= MONSTERFLAG_RESPAWNED;
                self.think = self.monster_spawnfunc;
                self.nextthink = time + self.respawntime;
+               self.ltime = 0;
                self.deadflag = DEAD_RESPAWNING;
                if(self.spawnflags & MONSTER_RESPAWN_DEATHPOINT)
                {
@@ -376,19 +376,25 @@ void Monster_Fade ()
                setorigin(self, self.pos1);
                self.angles = self.pos2;
                self.health = self.max_health;
-
-               self.SendFlags |= MSF_MOVE;
-               self.SendFlags |= MSF_STATUS;
+               setmodel(self, "null");
        }
        else
+       {
+               // number of monsters spawned with mobspawn command
+               totalspawned -= 1;
+
+               if(IS_CLIENT(self.realowner))
+                       self.realowner.monstercount -= 1;
+
                SUB_SetFade(self, time + 3, 1);
+       }
 }
 
 float Monster_CanJump (vector vel)
 {
        if(self.state)
                return FALSE; // already attacking
-       if not(self.flags & FL_ONGROUND)
+       if(!(self.flags & FL_ONGROUND))
                return FALSE; // not on the ground
        if(self.health <= 0)
                return FALSE; // called when dead?
@@ -411,7 +417,7 @@ float monster_leap (float anm, void() touchfunc, vector vel, float anim_finished
        if(!Monster_CanJump(vel))
                return FALSE;
 
-       monsters_setframe(anm);
+       self.frame = anm;
        self.state = MONSTER_STATE_ATTACK_LEAP;
        self.touch = touchfunc;
        self.origin_z += 1;
@@ -430,7 +436,7 @@ void monster_checkattack(entity e, entity targ)
        if(targ == world)
                return;
 
-       if not(e.monster_attackfunc)
+       if(!e.monster_attackfunc)
                return;
 
        if(time < e.attack_finished_single)
@@ -453,7 +459,7 @@ void monster_checkattack(entity e, entity targ)
 
 void monster_use ()
 {
-       if not(self.enemy)
+       if(!self.enemy)
        if(self.health > 0)
        if(monster_isvalidtarget(activator, self))
                self.enemy = activator;
@@ -531,38 +537,6 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
 
        entity targ;
 
-       if(self.frozen)
-       {
-               self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
-               self.health = max(1, self.max_health * self.revive_progress);
-
-               self.SendFlags |= MSF_STATUS;
-
-               movelib_beak_simple(stopspeed);
-               
-               monsters_setframe(manim_idle);
-
-               if(vlen(self.velocity) > 0)
-               {
-                       self.velocity = '0 0 0';
-                       self.SendFlags |= MSF_MOVE;
-               }
-               self.enemy = world;
-               self.nextthink = time + self.ticrate;
-
-               if(self.revive_progress >= 1)
-                       Unfreeze(self); // wait for next think before attacking
-
-               // don't bother updating angles here?
-               if(self.origin != self.oldorigin)
-               {
-                       self.oldorigin = self.origin;
-                       self.SendFlags |= MSF_MOVE;
-               }
-
-               return; // no moving while frozen
-       }
-
        if(self.flags & FL_SWIM)
        {
                if(self.waterlevel < WATERLEVEL_WETFEET)
@@ -591,8 +565,6 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
                        self.movetype = MOVETYPE_BOUNCE;
                        //self.velocity_z = -200;
 
-                       self.SendFlags |= MSF_MOVE | MSF_ANG;
-
                        return;
                }
                else if(self.fish_wasdrowning)
@@ -613,19 +585,20 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
        {
                runspeed = walkspeed = 0;
                if(time >= self.spawn_time)
-                       monsters_setframe(manim_idle);
+                       self.frame = manim_idle;
                movelib_beak_simple(stopspeed);
-               if(self.oldorigin != self.origin)
-               {
-                       self.oldorigin = self.origin;
-                       self.SendFlags |= MSF_MOVE;
-               }
                return;
        }
 
        targ = monster_target;
-       runspeed = monster_speed_run;
-       walkspeed = monster_speed_walk;
+       runspeed = bound(0, monster_speed_run * Monster_SkillModifier(), runspeed * 2); // limit maxspeed to prevent craziness
+       walkspeed = bound(0, monster_speed_walk * Monster_SkillModifier(), walkspeed * 2); // limit maxspeed to prevent craziness
+
+       if(time < self.spider_slowness)
+       {
+               runspeed *= 0.5;
+               walkspeed *= 0.5;
+       }
 
        if(teamplay)
        if(autocvar_g_monsters_teams)
@@ -637,10 +610,10 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
 
        if(time >= self.last_enemycheck)
        {
-               if not(monster_isvalidtarget(self.enemy, self))
+               if(!monster_isvalidtarget(self.enemy, self))
                        self.enemy = world;
 
-               if not(self.enemy)
+               if(!self.enemy)
                {
                        self.enemy = FindTarget(self);
                        if(self.enemy)
@@ -657,8 +630,8 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
        if(time >= self.last_trace || self.enemy) // update enemy instantly
                self.moveto = monster_pickmovetarget(targ);
 
-       if not(self.enemy)
-               MonsterSound(monstersound_idle, 5, TRUE, CH_VOICE);
+       if(!self.enemy)
+               MonsterSound(monstersound_idle, 7, TRUE, CH_VOICE);
 
        if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
                self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
@@ -707,9 +680,9 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
                if(time > self.pain_finished)
                if(time > self.attack_finished_single)
                if(vlen(self.velocity) > 10)
-                       monsters_setframe((self.enemy) ? manim_run : manim_walk);
+                       self.frame = ((self.enemy) ? manim_run : manim_walk);
                else
-                       monsters_setframe(manim_idle);
+                       self.frame = manim_idle;
        }
        else
        {
@@ -723,30 +696,32 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
                if(time > self.attack_finished_single)
                if(time > self.pain_finished)
                if (vlen(self.velocity) <= 30)
-                       monsters_setframe(manim_idle);
+                       self.frame = manim_idle;
        }
 
        monster_checkattack(self, self.enemy);
+}
 
-       if(self.angles != self.oldangles)
-       {
-               self.oldangles = self.angles;
-               self.SendFlags |= MSF_ANG;
-       }
+void monster_remove(entity mon)
+{
+       if(!mon)
+               return; // nothing to remove
 
-       if(self.origin != self.oldorigin)
-       {
-               self.oldorigin = self.origin;
-               self.SendFlags |= MSF_MOVE;
-       }
+       pointparticles(particleeffectnum("item_pickup"), mon.origin, '0 0 0', 1);
+
+       if(mon.weaponentity)
+               remove(mon.weaponentity);
+
+       WaypointSprite_Kill(mon.sprite);
+
+       remove(mon);
 }
 
 void monster_dead_think()
 {
-       self.think = monster_dead_think;
        self.nextthink = time + self.ticrate;
 
-       self.deadflag = DEAD_DEAD;
+       CSQCMODEL_AUTOUPDATE();
 
        if(self.ltime != 0)
        if(time >= self.ltime)
@@ -754,12 +729,6 @@ void monster_dead_think()
                Monster_Fade();
                return;
        }
-
-       if(self.oldorigin != self.origin)
-       {
-               self.oldorigin = self.origin;
-               self.SendFlags |= MSF_MOVE;
-       }
 }
 
 void monsters_setstatus()
@@ -777,7 +746,7 @@ void Monster_Appear()
 
 float Monster_CheckAppearFlags(entity ent)
 {
-       if not(ent.spawnflags & MONSTERFLAG_APPEAR)
+       if(!(ent.spawnflags & MONSTERFLAG_APPEAR))
                return FALSE;
 
        ent.think = func_null;
@@ -792,8 +761,6 @@ void monsters_reset()
 {
        setorigin(self, self.pos1);
        self.angles = self.pos2;
-       
-       Unfreeze(self); // remove any icy remains
 
        self.health = self.max_health;
        self.velocity = '0 0 0';
@@ -801,76 +768,6 @@ void monsters_reset()
        self.goalentity = world;
        self.attack_finished_single = 0;
        self.moveto = self.origin;
-
-       self.SendFlags |= MSF_STATUS;
-}
-
-float monster_send(entity to, float sf)
-{
-       WriteByte(MSG_ENTITY, ENT_CLIENT_MONSTER);
-       WriteByte(MSG_ENTITY, sf);
-       if(sf & MSF_SETUP)
-       {
-               WriteByte(MSG_ENTITY, self.monsterid);
-
-               WriteCoord(MSG_ENTITY, self.origin_x);
-               WriteCoord(MSG_ENTITY, self.origin_y);
-               WriteCoord(MSG_ENTITY, self.origin_z);
-
-               WriteAngle(MSG_ENTITY, self.angles_x);
-               WriteAngle(MSG_ENTITY, self.angles_y);
-
-               WriteByte(MSG_ENTITY, self.skin);
-               WriteByte(MSG_ENTITY, self.team);
-       }
-
-       if(sf & MSF_ANG)
-       {
-               WriteShort(MSG_ENTITY, rint(self.angles_x));
-               WriteShort(MSG_ENTITY, rint(self.angles_y));
-       }
-
-       if(sf & MSF_MOVE)
-       {
-               WriteShort(MSG_ENTITY, rint(self.origin_x));
-               WriteShort(MSG_ENTITY, rint(self.origin_y));
-               WriteShort(MSG_ENTITY, rint(self.origin_z));
-
-               WriteShort(MSG_ENTITY, rint(self.velocity_x));
-               WriteShort(MSG_ENTITY, rint(self.velocity_y));
-               WriteShort(MSG_ENTITY, rint(self.velocity_z));
-
-               WriteShort(MSG_ENTITY, rint(self.angles_y));
-       }
-
-       if(sf & MSF_ANIM)
-       {
-               WriteCoord(MSG_ENTITY, self.anim_start_time);
-               WriteByte(MSG_ENTITY, self.frame);
-       }
-
-       if(sf & MSF_STATUS)
-       {
-               WriteByte(MSG_ENTITY, self.skin);
-
-               WriteByte(MSG_ENTITY, self.team);
-
-               WriteByte(MSG_ENTITY, self.deadflag);
-
-               if(self.health <= 0)
-                       WriteByte(MSG_ENTITY, 0);
-               else
-                       WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
-       }
-
-       return TRUE;
-}
-
-void monster_link(void() spawnproc)
-{
-       Net_LinkEntity(self, TRUE, 0, monster_send);
-       self.think        = spawnproc;
-       self.nextthink  = time;
 }
 
 void monsters_corpse_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
@@ -883,37 +780,50 @@ void monsters_corpse_damage (entity inflictor, entity attacker, float damage, fl
        {
                Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
 
+               // number of monsters spawned with mobspawn command
+               totalspawned -= 1;
+
+               if(IS_CLIENT(self.realowner))
+                       self.realowner.monstercount -= 1;
+
                self.think = SUB_Remove;
                self.nextthink = time + 0.1;
        }
 }
 
-void monster_die()
+void monster_die(entity attacker, float gibbed)
 {
        self.think = monster_dead_think;
-       self.nextthink = self.ticrate;
+       self.nextthink = time;
        self.ltime = time + 5;
-       
-       Unfreeze(self); // remove any icy remains
-       self.health = 0; // reset by Unfreeze
 
        monster_dropitem();
 
        MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
 
-       if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !(self.spawnflags & MONSTERFLAG_RESPAWNED))
                monsters_killed += 1;
 
+       if(IS_PLAYER(attacker))
+       if(autocvar_g_monsters_score_spawned || !((self.spawnflags & MONSTERFLAG_SPAWNED) || (self.spawnflags & MONSTERFLAG_RESPAWNED)))
+               PlayerScore_Add(attacker, SP_SCORE, +autocvar_g_monsters_score_kill);
+
+       if(gibbed)
+       {
+               // number of monsters spawned with mobspawn command
+               totalspawned -= 1;
+
+               if(IS_CLIENT(self.realowner))
+                       self.realowner.monstercount -= 1;
+       }
+
        if(self.candrop && self.weapon)
                W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325');
 
-       if(IS_CLIENT(self.realowner))
-       if not(self.monster_respawned)
-               self.realowner.monstercount -= 1;
-
        self.event_damage       = monsters_corpse_damage;
        self.solid                      = SOLID_CORPSE;
        self.takedamage         = DAMAGE_AIM;
+       self.deadflag           = DEAD_DEAD;
        self.enemy                      = world;
        self.movetype           = MOVETYPE_TOSS;
        self.moveto                     = self.origin;
@@ -922,37 +832,31 @@ void monster_die()
        self.state                      = 0;
        self.attack_finished_single = 0;
 
-       if not(self.flags & FL_FLY)
+       if(!(self.flags & FL_FLY))
                self.velocity = '0 0 0';
 
-       self.SendFlags |= MSF_MOVE;
-
-       // number of monsters spawned with mobspawn command
-       totalspawned -= 1;
-
        MON_ACTION(self.monsterid, MR_DEATH);
 }
 
 void monsters_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
-       if(self.frozen && deathtype != DEATH_KILL)
-               return;
-
        if(time < self.pain_finished && deathtype != DEATH_KILL)
                return;
 
-       if(time < self.spawnshieldtime)
+       if(time < self.spawnshieldtime && deathtype != DEATH_KILL)
                return;
 
        vector v;
        float take, save;
 
-       v = healtharmor_applydamage(self.armorvalue, self.m_armor_blockpercent, damage);
+       v = healtharmor_applydamage(self.armorvalue, self.m_armor_blockpercent, deathtype, damage);
        take = v_x;
        save = v_y;
 
        self.health -= take;
 
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+
        self.dmg_time = time;
 
        if(sound_allowed(MSG_BROADCAST, attacker) && deathtype != DEATH_DROWN)
@@ -980,13 +884,15 @@ void monsters_damage (entity inflictor, entity attacker, float damage, float dea
                SUB_UseTargets();
                self.target2 = self.oldtarget2; // reset to original target on death, incase we respawn
 
-               monster_die();
+               monster_die(attacker, (self.health <= -100 || deathtype == DEATH_KILL));
+
+               WaypointSprite_Kill(self.sprite);
 
                frag_attacker = attacker;
                frag_target = self;
                MUTATOR_CALLHOOK(MonsterDies);
 
-               if(self.health <= -100) // check if we're already gibbed
+               if(self.health <= -100 || deathtype == DEATH_KILL) // check if we're already gibbed
                {
                        Violence_GibSplash(self, 1, 0.5, attacker);
 
@@ -994,15 +900,36 @@ void monsters_damage (entity inflictor, entity attacker, float damage, float dea
                        self.nextthink = time + 0.1;
                }
        }
+}
 
-       self.SendFlags |= MSF_STATUS;
+void monster_setupcolors()
+{
+       if(IS_PLAYER(self.monster_owner))
+               self.colormap = self.monster_owner.colormap;
+       else if(teamplay && self.team)
+               self.colormap = 1024 + (self.team - 1) * 17;
+       else
+       {
+               if(self.monster_skill <= MONSTER_SKILL_EASY)
+                       self.colormap = 1029;
+               else if(self.monster_skill <= MONSTER_SKILL_MEDIUM)
+                       self.colormap = 1027;
+               else if(self.monster_skill <= MONSTER_SKILL_HARD)
+                       self.colormap = 1038;
+               else if(self.monster_skill <= MONSTER_SKILL_INSANE)
+                       self.colormap = 1028;
+               else if(self.monster_skill <= MONSTER_SKILL_NIGHTMARE)
+                       self.colormap = 1032;
+               else
+                       self.colormap = 1024;
+       }
 }
 
 void monster_think()
 {
        self.think = monster_think;
        self.nextthink = self.ticrate;
-       
+
        if(self.ltime)
        if(time >= self.ltime)
        {
@@ -1011,77 +938,77 @@ void monster_think()
        }
 
        MON_ACTION(self.monsterid, MR_THINK);
+
+       CSQCMODEL_AUTOUPDATE();
 }
 
-void monster_spawn()
+float monster_spawn()
 {
        MON_ACTION(self.monsterid, MR_SETUP);
 
-       if not(self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+       {
                Monster_CheckMinibossFlag();
+               self.health *= Monster_SkillModifier();
+       }
 
        self.max_health = self.health;
        self.pain_finished = self.nextthink;
-       self.anim_start_time = time;
 
-       if not(self.noalign)
-       {
-               setorigin(self, self.origin + '0 0 20');
-               tracebox(self.origin + '0 0 100', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
-               setorigin(self, trace_endpos);
-       }
+       if(IS_PLAYER(self.monster_owner))
+               self.effects |= EF_DIMLIGHT;
 
-       if not(self.monster_respawned)
-       if not(self.skin)
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+       if(!self.skin)
                self.skin = rint(random() * 4);
 
-       if not(self.attack_range)
+       if(!self.attack_range)
                self.attack_range = autocvar_g_monsters_attack_range;
 
-       self.pos1 = self.origin;
-
-       //monster_setupsounds(self.netname);
        precache_monstersounds();
        UpdateMonsterSounds();
-       //monster_precachesounds(self);
 
        if(teamplay)
                self.monster_attack = TRUE; // we can have monster enemies in team games
-               
+
        MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
 
+       WaypointSprite_Spawn(M_NAME(self.monsterid), 0, 1024, self, '0 0 1' * (self.maxs_z + 15), world, self.team, self, sprite, TRUE, RADARICON_DANGER, ((self.team) ? Team_ColorRGB(self.team) : '1 0 0'));
+       WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+
        self.think = monster_think;
        self.nextthink = time + self.ticrate;
 
-       self.SendFlags |= MSF_SETUP;
+       if(MUTATOR_CALLHOOK(MonsterSpawn))
+               return FALSE;
 
-       MUTATOR_CALLHOOK(MonsterSpawn);
+       return TRUE;
 }
 
 float monster_initialize(float mon_id, float nodrop)
 {
-       if not(autocvar_g_monsters)
+       if(!autocvar_g_monsters)
                return FALSE;
 
        entity mon = get_monsterinfo(mon_id);
 
+       if(!self.monster_skill)
+               self.monster_skill = cvar("g_monsters_skill");
+
        // support for quake style removing monsters based on skill
-       switch(monster_skill)
-       {
-               case 0:
-               case 1: if(self.spawnflags & MONSTERSKILL_NOTEASY)              return FALSE; break;
-               case 2: if(self.spawnflags & MONSTERSKILL_NOTMEDIUM)    return FALSE; break;
-               default:
-               case 3: if(self.spawnflags & MONSTERSKILL_NOTHARD)              return FALSE; break;
-       }
+       if(self.monster_skill == MONSTER_SKILL_EASY) if(self.spawnflags & MONSTERSKILL_NOTEASY) { return FALSE; }
+       if(self.monster_skill == MONSTER_SKILL_MEDIUM) if(self.spawnflags & MONSTERSKILL_NOTMEDIUM) { return FALSE; }
+       if(self.monster_skill == MONSTER_SKILL_HARD) if(self.spawnflags & MONSTERSKILL_NOTHARD) { return FALSE; }
 
        if(self.team && !teamplay)
                self.team = 0;
 
-       if not(self.spawnflags & MONSTERFLAG_SPAWNED) // naturally spawned monster
-       if not(self.monster_respawned)
+       if(!(self.spawnflags & MONSTERFLAG_SPAWNED)) // naturally spawned monster
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
                monsters_total += 1;
 
+       setmodel(self, mon.model);
        setsize(self, mon.mins, mon.maxs);
        self.flags                              = FL_MONSTER;
        self.takedamage                 = DAMAGE_AIM;
@@ -1100,6 +1027,7 @@ float monster_initialize(float mon_id, float nodrop)
        self.enemy                              = world;
        self.velocity                   = '0 0 0';
        self.moveto                             = self.origin;
+       self.pos1                               = self.origin;
        self.pos2                               = self.angles;
        self.reset                              = monsters_reset;
        self.netname                    = mon.netname;
@@ -1111,9 +1039,16 @@ float monster_initialize(float mon_id, float nodrop)
        self.scale                              = 1;
        self.noalign                    = nodrop;
        self.spawn_time                 = time;
+       self.spider_slowness    = 0;
        self.gravity                    = 1;
        self.dphitcontentsmask  = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
 
+       if(autocvar_g_fullbrightplayers)
+               self.effects |= EF_FULLBRIGHT;
+
+       if(autocvar_g_nodepthtestplayers)
+               self.effects |= EF_NODEPTHTEST;
+
        if(mon.spawnflags & MONSTER_TYPE_SWIM)
                self.flags |= FL_SWIM;
 
@@ -1126,24 +1061,37 @@ float monster_initialize(float mon_id, float nodrop)
        if(mon.spawnflags & MONSTER_SIZE_BROKEN)
                self.scale = 1.3;
 
-       if not(self.ticrate)
+       if(!self.ticrate)
                self.ticrate = autocvar_g_monsters_think_delay;
 
        self.ticrate = bound(sys_frametime, self.ticrate, 60);
 
-       if not(self.m_armor_blockpercent)
+       if(!self.m_armor_blockpercent)
                self.m_armor_blockpercent = 0.5;
 
-       if not(self.target_range)
+       if(!self.target_range)
                self.target_range = autocvar_g_monsters_target_range;
 
-       if not(self.respawntime)
+       if(!self.respawntime)
                self.respawntime = autocvar_g_monsters_respawn_delay;
 
-       if not(self.monster_moveflags)
+       if(!self.monster_moveflags)
                self.monster_moveflags = MONSTER_MOVE_WANDER;
 
-       monster_link(monster_spawn);
+       if(!self.noalign)
+       {
+               setorigin(self, self.origin + '0 0 20');
+               tracebox(self.origin + '0 0 64', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
+               setorigin(self, trace_endpos);
+       }
+
+       if(!monster_spawn())
+               return FALSE;
+
+       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+               monster_setupcolors();
+
+       CSQCMODEL_AUTOINIT();
 
        return TRUE;
 }