Add a cvar to control monster attack range
authorMario <mario.mario@y7mail.com>
Fri, 30 Aug 2013 09:38:09 +0000 (19:38 +1000)
committerMario <mario.mario@y7mail.com>
Fri, 30 Aug 2013 09:38:09 +0000 (19:38 +1000)
13 files changed:
monsters.cfg
qcsrc/common/monsters/monster/animus.qc
qcsrc/common/monsters/monster/bruiser.qc
qcsrc/common/monsters/monster/brute.qc
qcsrc/common/monsters/monster/cerberus.qc
qcsrc/common/monsters/monster/knight.qc
qcsrc/common/monsters/monster/mage.qc
qcsrc/common/monsters/monster/shambler.qc
qcsrc/common/monsters/monster/spider.qc
qcsrc/common/monsters/monster/stingray.qc
qcsrc/common/monsters/monster/zombie.qc
qcsrc/common/monsters/sv_monsters.qc
qcsrc/server/autocvars.qh

index 5d75fdc..f44f71a 100644 (file)
@@ -173,6 +173,7 @@ set g_monsters_typefrag 1
 set g_monsters_healthbars 1
 set g_monsters_target_range 2000
 set g_monsters_target_infront 0
+set g_monsters_attack_range 120
 set g_monsters_respawn 1
 set g_monsters_respawn_delay 20
 set g_monsters_score_kill 1
index 40cf612..8c5d074 100644 (file)
@@ -56,7 +56,7 @@ float animus_attack(float attack_type)
                {
                        monsters_setframe(animus_anim_attack);
                        self.attack_finished_single = time + 1;
-                       monster_melee(self.enemy, MON_CVAR(animus, attack_melee_damage), 0.3, DEATH_MONSTER_ANIMUS, TRUE);
+                       monster_melee(self.enemy, MON_CVAR(animus, attack_melee_damage), self.attack_range, DEATH_MONSTER_ANIMUS, TRUE);
                        
                        return TRUE;
                }
index d0872f7..f6b8146 100644 (file)
@@ -43,7 +43,7 @@ float bruiser_attack(float attack_type)
                        monsters_setframe((len < 50) ? bruiser_anim_attack : bruiser_anim_runattack);
                        self.attack_finished_single = time + 1.25;
                        
-                       monster_melee(self.enemy, MON_CVAR(bruiser, attack_melee_damage), 0.3, DEATH_MONSTER_BRUISER, FALSE);
+                       monster_melee(self.enemy, MON_CVAR(bruiser, attack_melee_damage), self.attack_range, DEATH_MONSTER_BRUISER, FALSE);
                        
                        return TRUE;
                }
index 1d5f6d5..2f1d912 100644 (file)
@@ -45,7 +45,7 @@ void brute_blade()
        self.brute_cycles += 1;
        self.angles_y = self.angles_y + random()* 25;
        
-       monster_melee(self.enemy, MON_CVAR(brute, attack_chainsaw_damage), 0.3, DEATH_MONSTER_BRUTE_BLADE, TRUE);
+       monster_melee(self.enemy, MON_CVAR(brute, attack_chainsaw_damage), self.attack_range, DEATH_MONSTER_BRUTE_BLADE, TRUE);
        
        if(self.brute_cycles <= 4)
                defer(0.2, brute_blade);
index 689f042..0f3163f 100644 (file)
@@ -91,7 +91,7 @@ float cerberus_attack(float attack_type)
                {
                        monsters_setframe(cerberus_anim_attack);
                        self.attack_finished_single = time + 0.7;
-                       monster_melee(self.enemy, MON_CVAR(cerberus, attack_bite_damage), 0.2, DEATH_MONSTER_CERBERUS_BITE, TRUE);
+                       monster_melee(self.enemy, MON_CVAR(cerberus, attack_bite_damage), self.attack_range, DEATH_MONSTER_CERBERUS_BITE, TRUE);
                        
                        return TRUE;
                }
index c41c18b..433a9d3 100644 (file)
@@ -243,7 +243,7 @@ float knight_attack(float attack_type)
                        
                        monsters_setframe(anim);
                        self.attack_finished_single = time + 0.7;
-                       monster_melee(self.enemy, MON_CVAR(knight, attack_melee_damage), 0.3, DEATH_MONSTER_KNIGHT_MELEE, TRUE);
+                       monster_melee(self.enemy, MON_CVAR(knight, attack_melee_damage), self.attack_range, DEATH_MONSTER_KNIGHT_MELEE, TRUE);
                        
                        return TRUE;
                }
index e36cbf9..b729b38 100644 (file)
@@ -90,7 +90,7 @@ float friend_needshelp(entity e)
 
 void mageattack_melee()
 {
-       monster_melee(self.enemy, MON_CVAR(mage, attack_melee_damage), 0.3, DEATH_MONSTER_MAGE, TRUE);
+       monster_melee(self.enemy, MON_CVAR(mage, attack_melee_damage), self.attack_range, DEATH_MONSTER_MAGE, TRUE);
 }
 
 void mage_grenade_explode()
index ceddda3..729d728 100644 (file)
@@ -35,7 +35,7 @@ const float shambler_anim_death       = 8;
 
 void shambler_smash()
 {
-       monster_melee(self.enemy, MON_CVAR(shambler, attack_smash_damage), 0.3, DEATH_MONSTER_SHAMBLER_SMASH, TRUE);
+       monster_melee(self.enemy, MON_CVAR(shambler, attack_smash_damage), self.attack_range, DEATH_MONSTER_SHAMBLER_SMASH, TRUE);
 }
 
 void shambler_delayedsmash()
@@ -49,7 +49,7 @@ void shambler_swing()
 {
        float r = (random() < 0.5);
        monsters_setframe((r) ? shambler_anim_swingr : shambler_anim_swingl);
-       monster_melee(self.enemy, MON_CVAR(shambler, attack_claw_damage), 0.3, DEATH_MONSTER_SHAMBLER_CLAW, TRUE);
+       monster_melee(self.enemy, MON_CVAR(shambler, attack_claw_damage), self.attack_range, DEATH_MONSTER_SHAMBLER_CLAW, TRUE);
        self.attack_finished_single = time + 0.8;
        if(r)
                defer(0.5, shambler_swing);
@@ -135,6 +135,7 @@ float m_shambler(float req)
                case MR_SETUP:
                {
                        if not(self.health) self.health = MON_CVAR(shambler, health);
+                       if not(self.attack_range) self.attack_range = 150;
                        
                        self.monster_loot = spawnfunc_item_health_mega;
                        self.monster_attackfunc = shambler_attack;
index c88ca98..7e901af 100644 (file)
@@ -142,7 +142,7 @@ float spider_attack(float attack_type)
        {
                case MONSTER_ATTACK_MELEE:
                {
-                       monster_melee(self.enemy, MON_CVAR(spider, attack_bite_damage), 0.3, DEATH_MONSTER_SPIDER, TRUE);
+                       monster_melee(self.enemy, MON_CVAR(spider, attack_bite_damage), self.attack_range, DEATH_MONSTER_SPIDER, TRUE);
                        monsters_setframe((random() > 0.5) ? spider_anim_attack : spider_anim_attack2);
                        self.attack_finished_single = time + MON_CVAR(spider, attack_bite_delay);
                        
index dc11f84..41e866c 100644 (file)
@@ -35,7 +35,7 @@ float stingray_attack(float attack_type)
                {
                        monsters_setframe(stingray_anim_attack);
                        self.attack_finished_single = time + MON_CVAR(stingray, attack_bite_delay);
-                       monster_melee(self.enemy, MON_CVAR(stingray, attack_bite_damage), 0.1, DEATH_MONSTER_STINGRAY, FALSE);
+                       monster_melee(self.enemy, MON_CVAR(stingray, attack_bite_damage), self.attack_range, DEATH_MONSTER_STINGRAY, FALSE);
                        
                        return TRUE;
                }
index c3afdea..880f7c0 100644 (file)
@@ -96,7 +96,7 @@ float zombie_attack(float attack_type)
 
                        self.attack_finished_single = time + MON_CVAR(zombie, attack_melee_delay);
                        
-                       monster_melee(self.enemy, MON_CVAR(zombie, attack_melee_damage), 0.3, DEATH_MONSTER_ZOMBIE_MELEE, TRUE);
+                       monster_melee(self.enemy, MON_CVAR(zombie, attack_melee_damage), self.attack_range, DEATH_MONSTER_ZOMBIE_MELEE, TRUE);
                        
                        return TRUE;
                }
index ab715ef..17abfd4 100644 (file)
@@ -176,9 +176,9 @@ void monster_setupsounds(string mon)
        if(self.msound_sight == "") self.msound_sight = strzone(strcat("monsters/", mon, "_sight.wav"));
 }
 
-float monster_melee (entity targ, float damg, float er, float deathtype, float dostop)
+float monster_melee(entity targ, float damg, float er, float deathtype, float dostop)
 {
-       float dot, rdmg = damg * random();
+       float rdmg = damg * random();
 
        if (self.health <= 0)
                return FALSE;
@@ -194,9 +194,10 @@ float monster_melee (entity targ, float damg, float er, float deathtype, float d
        }
 
        makevectors (self.angles);
-       dot = normalize (targ.origin - self.origin) * v_forward;
        
-       if(dot > er)
+       traceline(self.origin + self.view_ofs, self.origin + v_forward * er, 0, self);
+       
+       if(trace_ent.takedamage)
                Damage(targ, self, self, rdmg * monster_skill, deathtype, targ.origin, normalize(targ.origin - self.origin));
                
        return TRUE;
@@ -319,6 +320,7 @@ void monster_checkattack(entity e, entity targ)
                return;
        }
        
+       if(vlen(targ.origin - e.origin) > e.attack_range)
        if(e.monster_attackfunc(MONSTER_ATTACK_RANGED))
        {
                monster_sound(e.msound_attack_ranged, 0, FALSE);
@@ -927,6 +929,9 @@ void monster_spawn()
        if not(self.monster_respawned)
        if not(self.skin)
                self.skin = rint(random() * 4);
+               
+       if not(self.attack_range)
+               self.attack_range = autocvar_g_monsters_attack_range;
        
        self.pos1 = self.origin;
        
@@ -1030,9 +1035,6 @@ float monster_initialize(float mon_id, float nodrop)
        if(mon.spawnflags & MONSTER_SIZE_BROKEN)
                self.scale = 1.3;
        
-       if not(self.attack_range)
-               self.attack_range = 120;
-       
        if not(self.ticrate)
                self.ticrate = autocvar_g_monsters_think_delay;
                
index 622ab1a..5875547 100644 (file)
@@ -1235,6 +1235,7 @@ float autocvar_g_monsters_max;
 float autocvar_g_monsters_max_perplayer;
 float autocvar_g_monsters_target_range;
 float autocvar_g_monsters_target_infront;
+float autocvar_g_monsters_attack_range;
 float autocvar_g_monsters_typefrag;
 float autocvar_g_monsters_owners;
 float autocvar_g_monsters_miniboss_chance;