]> 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 7f4554720dc41406e245b068325d02abb40fc363..7971d1d724bf933c2f1b55df8078157410e38806 100644 (file)
@@ -1,4 +1,3 @@
-#ifndef MENUQC
 // size
 const vector SHALRATH_MIN = '-36 -36 -24';
 const vector SHALRATH_MAX = '36 36 50';
@@ -6,8 +5,6 @@ const vector SHALRATH_MAX = '36 36 50';
 // model
 string SHALRATH_MODEL = "models/monsters/mage.dpm";
 
-#endif
-
 #ifdef SVQC
 // cvars
 float autocvar_g_monster_shalrath;
@@ -35,6 +32,8 @@ const float shalrath_anim_run         = 5;
 void() ShalMissile;
 float() shal_missile;
 void() shalrath_heal;
+void() shalrath_shield;
+void() shalrath_shield_die;
 
 void shalrath_think ()
 {
@@ -54,6 +53,10 @@ void shalrath_think ()
        self.think = shalrath_think;
        self.nextthink = time + self.ticrate;
        
+       if(self.weaponentity)
+       if(time >= self.weaponentity.ltime)
+               shalrath_shield_die();
+       
        if(self.delay != -1)
                self.nextthink = self.delay;
                
@@ -61,6 +64,13 @@ void shalrath_think ()
        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);
 }
@@ -166,8 +176,15 @@ float ShalrathCheckAttack ()
 {
        vector spot1 = '0 0 0', spot2 = '0 0 0';
 
-       if (self.health <= 0 || self.enemy == world || self.enemy.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)
        {
@@ -247,6 +264,45 @@ void shalrath_heal()
        }
 }
 
+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");
@@ -271,7 +327,6 @@ void shalrath_spawn ()
        self.attack_melee               = shalrath_attack_melee;
        self.nextthink                  = time + random() * 0.5 + 0.1;
        self.think                              = shalrath_think;
-       self.sprite_height              = 65;
        
        monsters_setframe(shalrath_anim_walk);