]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/monster/zombie.qc
Add a check just incase the mutator deletes the item entity
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / zombie.qc
index 24ecd296c6bb9054e4e83328ddf6282370697c3c..805fb7bf779b9ffee09e7fd6b353a7aef9133bfc 100644 (file)
@@ -2,27 +2,30 @@
 REGISTER_MONSTER(
 /* MON_##id   */ ZOMBIE,
 /* function   */ m_zombie,
-/* spawnflags */ 0,
+/* spawnflags */ MON_FLAG_MELEE,
 /* mins,maxs  */ '-18 -18 -25', '18 18 47',
 /* model      */ "zombie.dpm",
 /* netname    */ "zombie",
 /* fullname   */ _("Zombie")
 );
 
+#define ZOMBIE_SETTINGS(monster) \
+       MON_ADD_CVAR(monster, health) \
+       MON_ADD_CVAR(monster, attack_melee_damage) \
+       MON_ADD_CVAR(monster, attack_melee_delay) \
+       MON_ADD_CVAR(monster, attack_leap_damage) \
+       MON_ADD_CVAR(monster, attack_leap_force) \
+       MON_ADD_CVAR(monster, attack_leap_speed) \
+       MON_ADD_CVAR(monster, attack_leap_delay) \
+       MON_ADD_CVAR(monster, speed_stop) \
+       MON_ADD_CVAR(monster, speed_run) \
+       MON_ADD_CVAR(monster, speed_walk) 
+
+#ifdef SVQC
+ZOMBIE_SETTINGS(zombie)
+#endif // SVQC
 #else
 #ifdef SVQC
-float autocvar_g_monster_zombie;
-float autocvar_g_monster_zombie_stopspeed;
-float autocvar_g_monster_zombie_attack_leap_damage;
-float autocvar_g_monster_zombie_attack_leap_delay;
-float autocvar_g_monster_zombie_attack_leap_force;
-float autocvar_g_monster_zombie_attack_leap_speed;
-float autocvar_g_monster_zombie_attack_stand_damage;
-float autocvar_g_monster_zombie_attack_stand_delay;
-float autocvar_g_monster_zombie_health;
-float autocvar_g_monster_zombie_speed_walk;
-float autocvar_g_monster_zombie_speed_run;
-
 const float zombie_anim_attackleap                     = 0;
 const float zombie_anim_attackrun1                     = 1;
 const float zombie_anim_attackrun2                     = 2;
@@ -65,8 +68,8 @@ void zombie_attack_leap_touch()
        if(other.takedamage)
        {
                angles_face = vectoangles(self.moveto - self.origin);
-               angles_face = normalize(angles_face) * autocvar_g_monster_zombie_attack_leap_force;
-               Damage(other, self, self, autocvar_g_monster_zombie_attack_leap_damage * monster_skill, DEATH_MONSTER_ZOMBIE_JUMP, other.origin, angles_face);
+               angles_face = normalize(angles_face) * MON_CVAR(zombie, attack_leap_force);
+               Damage(other, self, self, MON_CVAR(zombie, attack_leap_damage) * monster_skill, DEATH_MONSTER_ZOMBIE_JUMP, other.origin, angles_face);
                self.touch = MonsterTouch; // instantly turn it off to stop damage spam
        }
 
@@ -74,6 +77,29 @@ void zombie_attack_leap_touch()
                self.touch = MonsterTouch;
 }
 
+void zombie_blockend()
+{
+       if(self.health <= 0)
+               return;
+
+       monsters_setframe(zombie_anim_blockend);
+       self.armorvalue = 0;
+       self.m_armor_blockpercent = autocvar_g_monsters_armor_blockpercent;
+}
+
+float zombie_block()
+{
+       monsters_setframe(zombie_anim_blockstart);
+       self.armorvalue = 100;
+       self.m_armor_blockpercent = 0.9;
+       self.state = MONSTER_STATE_ATTACK_MELEE; // freeze monster
+       self.attack_finished_single = time + 2.1;
+       
+       defer(2, zombie_blockend);
+       
+       return TRUE;
+}
+
 float zombie_attack(float attack_type)
 {
        switch(attack_type)
@@ -88,20 +114,16 @@ float zombie_attack(float attack_type)
                                chosen_anim = zombie_anim_attackstanding2;
                        else
                                chosen_anim = zombie_anim_attackstanding3;
-                               
-                       monsters_setframe(chosen_anim);
-
-                       self.attack_finished_single = time + autocvar_g_monster_zombie_attack_stand_delay;
                        
-                       monster_melee(self.enemy, autocvar_g_monster_zombie_attack_stand_damage, 0.3, DEATH_MONSTER_ZOMBIE_MELEE, TRUE);
+                       if(random() < 0.3 && self.health < 75 && self.enemy.health > 10)
+                               return zombie_block();
                        
-                       return TRUE;
+                       return monster_melee(self.enemy, MON_CVAR(zombie, attack_melee_damage), chosen_anim, self.attack_range, MON_CVAR(zombie, attack_melee_delay), DEATH_MONSTER_ZOMBIE_MELEE, TRUE);
                }
                case MONSTER_ATTACK_RANGED:
                {
                        makevectors(self.angles);
-                       if(monster_leap(zombie_anim_attackleap, zombie_attack_leap_touch, v_forward * autocvar_g_monster_zombie_attack_leap_speed + '0 0 200', autocvar_g_monster_zombie_attack_leap_delay))
-                               return TRUE;
+                       return monster_leap(zombie_anim_attackleap, zombie_attack_leap_touch, v_forward * MON_CVAR(zombie, attack_leap_speed) + '0 0 200', MON_CVAR(zombie, attack_leap_delay));
                }
        }
        
@@ -110,8 +132,6 @@ float zombie_attack(float attack_type)
 
 void spawnfunc_monster_zombie() 
 {
-       if not(autocvar_g_monster_zombie) { remove(self); return; }
-       
        self.classname = "monster_zombie";
        
        self.monster_spawnfunc = spawnfunc_monster_zombie;
@@ -130,23 +150,29 @@ float m_zombie(float req)
        {
                case MR_THINK:
                {
-                       monster_move(autocvar_g_monster_zombie_speed_run, autocvar_g_monster_zombie_speed_walk, autocvar_g_monster_zombie_stopspeed, zombie_anim_runforward, zombie_anim_runforward, zombie_anim_idle);
+                       monster_move(MON_CVAR(zombie, speed_run), MON_CVAR(zombie, speed_walk), MON_CVAR(zombie, speed_stop), zombie_anim_runforward, zombie_anim_runforward, zombie_anim_idle);
                        return TRUE;
                }
                case MR_DEATH:
                {
+                       self.armorvalue = 0;
+                       self.m_armor_blockpercent = autocvar_g_monsters_armor_blockpercent;
                        monsters_setframe((random() > 0.5) ? zombie_anim_deathback1 : zombie_anim_deathfront1);
                        return TRUE;
                }
                case MR_SETUP:
                {
-                       if not(self.health) self.health = autocvar_g_monster_zombie_health;
-                               
+                       if not(self.health) self.health = MON_CVAR(zombie, health);
+                       
+                       if(self.spawnflags & MONSTERFLAG_NORESPAWN)
+                               self.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn
+                       
+                       self.monster_loot = spawnfunc_item_health_medium;
                        self.monster_attackfunc = zombie_attack;
                        monsters_setframe(zombie_anim_spawn);
                        self.spawn_time = time + 2.1;
                        self.spawnshieldtime = self.spawn_time;
-                       self.respawntime = 0.1;
+                       self.respawntime = 0.2;
                        
                        return TRUE;
                }
@@ -155,6 +181,11 @@ float m_zombie(float req)
                        // nothing
                        return TRUE;
                }
+               case MR_CONFIG:
+               {
+                       MON_CONFIG_SETTINGS(ZOMBIE_SETTINGS(zombie))
+                       return TRUE;
+               }
        }
        
        return TRUE;