]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/monsters/monster/shalrath.qc
Some fixes for mage shield
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / monsters / monster / shalrath.qc
index 76c56d2fefc3e6f792aa9e75d8a692d5430359c8..7971d1d724bf933c2f1b55df8078157410e38806 100644 (file)
@@ -1,7 +1,11 @@
 // size
-const vector SHALRATH_MIN = '-32 -32 -24';
-const vector SHALRATH_MAX = '32 32 32';
+const vector SHALRATH_MIN = '-36 -36 -24';
+const vector SHALRATH_MAX = '36 36 50';
 
+// model
+string SHALRATH_MODEL = "models/monsters/mage.dpm";
+
+#ifdef SVQC
 // cvars
 float autocvar_g_monster_shalrath;
 float autocvar_g_monster_shalrath_health;
@@ -11,32 +15,69 @@ float autocvar_g_monster_shalrath_attack_spike_radius;
 float autocvar_g_monster_shalrath_attack_spike_delay;
 float autocvar_g_monster_shalrath_attack_melee_damage;
 float autocvar_g_monster_shalrath_attack_melee_delay;
+float autocvar_g_monster_shalrath_heal_self;
+float autocvar_g_monster_shalrath_heal_friends;
+float autocvar_g_monster_shalrath_heal_minhealth;
+float autocvar_g_monster_shalrath_heal_range;
+float autocvar_g_monster_shalrath_heal_delay;
 
 // animations
-#define shalrath_anim_idle             0
-#define shalrath_anim_walk             1
-#define shalrath_anim_attack   2
-#define shalrath_anim_pain             3
-#define shalrath_anim_death    4
-#define shalrath_anim_run              5
-
+const float shalrath_anim_idle         = 0;
+const float shalrath_anim_walk                 = 1;
+const float shalrath_anim_attack       = 2;
+const float shalrath_anim_pain                 = 3;
+const float shalrath_anim_death        = 4;
+const float shalrath_anim_run          = 5;
 
 void() ShalMissile;
+float() shal_missile;
+void() shalrath_heal;
+void() shalrath_shield;
+void() shalrath_shield_die;
 
 void shalrath_think ()
 {
+       entity head;
+       float friend_needshelp = FALSE;
+       
+       FOR_EACH_PLAYER(head)
+       {
+               if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
+               if((!g_minstagib && head.health < autocvar_g_balance_health_regenstable) || (g_minstagib && head.ammo_cells < start_ammo_cells))
+               {
+                       friend_needshelp = TRUE;
+                       break; // found 1 player near us who is low on health
+               }
+       }
+       
        self.think = shalrath_think;
-       self.nextthink = time + 0.1;
+       self.nextthink = time + self.ticrate;
+       
+       if(self.weaponentity)
+       if(time >= self.weaponentity.ltime)
+               shalrath_shield_die();
        
        if(self.delay != -1)
                self.nextthink = self.delay;
+               
+       if(self.health < autocvar_g_monster_shalrath_heal_minhealth || friend_needshelp)
+       if(time >= self.attack_finished_single)
+       if(random() < 0.5)
+               shalrath_heal();
+               
+       if(self.enemy)
+       if not(self.spawnflags & MONSTERFLAG_GIANT) // giants are too big to hold a shield
+       if(self.health < self.max_health)
+       if(time >= self.lastshielded)
+       if(random() < 0.5)
+               shalrath_shield();
        
        monster_move(autocvar_g_monster_shalrath_speed, autocvar_g_monster_shalrath_speed, 50, shalrath_anim_walk, shalrath_anim_run, shalrath_anim_idle);
 }
 
 void shalrath_attack ()
 {
-       self.frame = shalrath_anim_attack;
+       monsters_setframe(shalrath_anim_attack);
        self.delay = time + 0.2;
        self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_spike_delay;
        self.monster_delayedattack = ShalMissile;
@@ -44,40 +85,29 @@ void shalrath_attack ()
 
 void shalrathattack_melee ()
 {
-       float bigdmg = 0, rdmg = autocvar_g_monster_shalrath_attack_melee_damage * random();
-
-       bigdmg = rdmg * self.scale;
-
-       monster_melee(self.enemy, bigdmg * monster_skill, 120, DEATH_MONSTER_SHALRATH_MELEE);
+       monster_melee(self.enemy, autocvar_g_monster_shalrath_attack_melee_damage, 0.3, DEATH_MONSTER_MAGE, TRUE);
 }
 
 void shalrath_attack_melee ()
 {
        self.monster_delayedattack = shalrathattack_melee;
        self.delay = time + 0.2;
-       self.frame = shalrath_anim_attack;
+       monsters_setframe(shalrath_anim_attack);
        self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_melee_delay;
 }
 
 float shal_missile ()
 {
-       // don't throw if it is blocked
-       traceline(self.origin + '0 0 10', self.enemy.origin + '0 0 10', FALSE, self);
-       if (enemy_range() > 1000)
-               return FALSE;
-       if (trace_ent != self.enemy)
-               return FALSE;
        shalrath_attack();
+       
        return TRUE;
 }
 
-.float shal_cycles;
 void ShalHome ()
 {
        local vector dir = '0 0 0', vtemp = self.enemy.origin + '0 0 10';
        
-       self.shal_cycles += 1;
-       if (self.enemy.health <= 0 || self.owner.health <= 0 || self.shal_cycles >= 20)
+       if (self.enemy.health <= 0 || self.owner.health <= 0 || time >= self.ltime)
        {
                remove(self);
                return;
@@ -97,7 +127,7 @@ void shal_spike_explode ()
        self.event_damage = func_null;
 
        pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
-       RadiusDamage (self, self.realowner, autocvar_g_monster_shalrath_attack_spike_damage, autocvar_g_monster_shalrath_attack_spike_damage * 0.5, autocvar_g_monster_shalrath_attack_spike_radius, world, 0, DEATH_MONSTER_SHALRATH_MELEE, other);
+       RadiusDamage (self, self.realowner, autocvar_g_monster_shalrath_attack_spike_damage, autocvar_g_monster_shalrath_attack_spike_damage * 0.5, autocvar_g_monster_shalrath_attack_spike_radius, world, 0, DEATH_MONSTER_MAGE, other);
 
        remove (self);
 }
@@ -127,6 +157,7 @@ void ShalMissile ()
        dist = vlen (self.enemy.origin - self.origin);
 
        missile.think = ShalHome;
+       missile.ltime = time + 7;
        missile.nextthink = time;
        missile.solid = SOLID_BBOX;
        missile.movetype = MOVETYPE_FLYMISSILE;
@@ -143,11 +174,17 @@ void ShalMissile ()
 
 float ShalrathCheckAttack ()
 {
-       local vector spot1 = '0 0 0', spot2 = '0 0 0';
-       local entity targ = self.enemy;
+       vector spot1 = '0 0 0', spot2 = '0 0 0';
 
-       if (self.health <= 0 || targ == world || targ.health < 1)
+       if (self.health <= 0)
                return FALSE;
+               
+       // reset delays when we have no enemy
+       if not(self.enemy)
+       {
+               self.monster_delayedattack = func_null;
+               self.delay = -1;
+       }
        
        if(self.monster_delayedattack && self.delay != -1)
        {
@@ -166,46 +203,114 @@ float ShalrathCheckAttack ()
        {       // melee attack
                if (self.attack_melee)
                {
+                       monster_sound(self.msound_attack_melee, 0, FALSE); // no delay for attack sounds
                        self.attack_melee();
                        return TRUE;
                }
        }
 
-       if (vlen(targ.origin - self.origin) >= 2000) // long traces are slow
-               return FALSE;
-
 // see if any entities are in the way of the shot
-       spot1 = self.origin + '0 0 10';
-       spot2 = targ.origin + '0 0 10';
+       spot1 = self.origin + self.view_ofs;
+       spot2 = self.enemy.origin + self.enemy.view_ofs;
 
        traceline (spot1, spot2, FALSE, self);
 
-       if (trace_ent != targ && trace_fraction < 1)
+       if (trace_ent != self.enemy && trace_fraction < 1)
                return FALSE; // don't have a clear shot
 
        //if (trace_inopen && trace_inwater)
        //      return FALSE; // sight line crossed contents
 
-       if (random() < 0.2)
        if (self.attack_ranged())
                return TRUE;
 
        return FALSE;
 }
 
+void shalrath_heal()
+{
+       entity head;
+       if(self.health < self.max_health) // only show our effect if we are healing ourself too
+               pointparticles(particleeffectnum("healing_fx"), self.origin, '0 0 0', 1);
+       self.health = bound(0, self.health + autocvar_g_monster_shalrath_heal_self, self.max_health);
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       monsters_setframe(shalrath_anim_attack);
+       self.attack_finished_single = time + autocvar_g_monster_shalrath_heal_delay;
+       
+       for(head = world; (head = findfloat(head, monster_attack, TRUE)); )
+       {
+               if(head.health > 0)
+               if not(head.frozen || head.freezetag_frozen)
+               if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
+               if not(IsDifferentTeam(head, self))
+               {
+                       if(IS_PLAYER(head))
+                       {
+                               if(head.ammo_cells < start_ammo_cells || head.health < g_pickup_healthmedium_max)
+                                       pointparticles(particleeffectnum(((g_minstagib) ? "ammoregen_fx" : "healing_fx")), head.origin, '0 0 0', 1);
+                               if(g_minstagib)
+                                       head.ammo_cells = bound(0, head.ammo_cells + 1, start_ammo_cells);
+                               else
+                                       head.health = bound(0, head.health + autocvar_g_monster_shalrath_heal_friends, g_pickup_healthmedium_max);
+                       }
+                       else
+                       {
+                               if(head.health < head.max_health)
+                                       pointparticles(particleeffectnum("healing_fx"), head.origin, '0 0 0', 1);
+                               head.health = bound(0, head.health + autocvar_g_monster_shalrath_heal_friends, head.max_health);
+                               WaypointSprite_UpdateHealth(head.sprite, head.health);
+                       }
+               }
+       }
+}
+
+void shalrath_shield_die()
+{
+       if not(self.weaponentity)
+               return; // why would this be called without a shield?
+       
+       self.armorvalue = 1;
+       
+       remove(self.weaponentity);
+       
+       self.weaponentity = world;
+}
+
+void shalrath_shield()
+{
+       if(self.weaponentity)
+               return; // already have a shield
+
+       self.weaponentity = spawn();
+       self.weaponentity.owner = self.weaponentity.realowner = self;
+       setmodel(self.weaponentity, "models/onslaught/generator_shield.md3");
+       setattachment(self.weaponentity, self, "");
+       self.weaponentity.classname = "shield";
+       self.weaponentity.ltime = time + 3;
+       self.weaponentity.health = 70;
+       self.weaponentity.alpha = 0.5;
+       self.weaponentity.scale = self.scale * 0.6;
+       self.weaponentity.effects = EF_ADDITIVE;
+       self.weaponentity.solid = SOLID_NOT;
+       self.weaponentity.movetype = MOVETYPE_NOCLIP;
+       self.weaponentity.avelocity = '7 0 11';
+       
+       self.lastshielded = time + 7; // 1 shield every 7 seconds?
+       
+       monsters_setframe(shalrath_anim_attack);
+       self.attack_finished_single = time + 1;
+       
+       self.armorvalue = 0.2;
+}
+
 void shalrath_die ()
 {
        Monster_CheckDropCvars ("shalrath");
        
-       self.think                      = Monster_Fade;
-       self.frame                      = shalrath_anim_death;
-       self.solid                      = SOLID_NOT;
-       self.takedamage         = DAMAGE_NO;
-       self.event_damage   = func_null;
-       self.enemy                      = world;
-       self.nextthink          = time + 2.1;
-       self.pain_finished  = self.nextthink;   
-       self.movetype           = MOVETYPE_TOSS;
+       self.think = monster_dead_think;
+       self.nextthink = time + self.ticrate;
+       self.ltime = time + 5;
+       monsters_setframe(shalrath_anim_death);
        
        monster_hook_death(); // for post-death mods
 }
@@ -222,8 +327,10 @@ void shalrath_spawn ()
        self.attack_melee               = shalrath_attack_melee;
        self.nextthink                  = time + random() * 0.5 + 0.1;
        self.think                              = shalrath_think;
-       self.frame                              = shalrath_anim_walk;
-       self.sprite_height              = 40 * self.scale;
+       
+       monsters_setframe(shalrath_anim_walk);
+       
+       monster_setupsounds("shalrath");
        
        monster_hook_spawn(); // for post-spawn mods
 }
@@ -234,20 +341,11 @@ void spawnfunc_monster_shalrath ()
        
        self.monster_spawnfunc = spawnfunc_monster_shalrath;
        
-       if(self.spawnflags & MONSTERFLAG_APPEAR)
-       {
-               self.think = func_null;
-               self.nextthink = -1;
-               self.use = Monster_Appear;
-               
+       if(Monster_CheckAppearFlags(self))
                return;
-       }
-       
-       self.scale = 1.3;
        
        if not (monster_initialize(
-                        "Mage",
-                        "models/monsters/mage.dpm",
+                        "Mage", MONSTER_MAGE,
                         SHALRATH_MIN, SHALRATH_MAX,
                         FALSE,
                         shalrath_die, shalrath_spawn))
@@ -259,3 +357,5 @@ void spawnfunc_monster_shalrath ()
 
 // compatibility with old spawns
 void spawnfunc_monster_vore () { spawnfunc_monster_shalrath(); }
+
+#endif // SVQC