]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/monsters/monster/shalrath.qc
Rename hell-knight to knight
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / monsters / monster / shalrath.qc
index 4a523ae48b05e48a1e44ebdad9bfd43f7bbf6280..1ec6cec90042c5fc2c438b3156c0d608134c090f 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,61 +15,144 @@ 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;
+float autocvar_g_monster_shalrath_shield_time;
+float autocvar_g_monster_shalrath_shield_delay;
+float autocvar_g_monster_shalrath_shield_blockpercent;
+float autocvar_g_monster_shalrath_attack_grenade_damage;
+float autocvar_g_monster_shalrath_attack_grenade_edgedamage;
+float autocvar_g_monster_shalrath_attack_grenade_radius;
+float autocvar_g_monster_shalrath_attack_grenade_lifetime;
+float autocvar_g_monster_shalrath_attack_grenade_force;
+float autocvar_g_monster_shalrath_attack_grenade_chance;
 
 // 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;
+void() shalrath_heal;
+void() shalrath_shield;
+void() shalrath_shield_die;
 
-void shalrath_think ()
+void shalrath_think()
 {
+       entity head;
+       float friend_needshelp = FALSE, need_hpammo = FALSE;
+       
+       FOR_EACH_PLAYER(head)
+       {
+               need_hpammo = ((g_minstagib) ? head.ammo_cells < start_ammo_cells : head.health < autocvar_g_balance_health_regenstable);
+               if not(IsDifferentTeam(head, self))
+               if(head.health > 0)
+               if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range)
+               if(need_hpammo)
+               {
+                       friend_needshelp = TRUE;
+                       break; // found 1 player near us who is low on health
+               }
+       }
+       FOR_EACH_MONSTER(head) if(head != self)
+       {
+               if not(IsDifferentTeam(head, self))
+               if(head.health > 0)
+               if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range)
+               if(head.health < head.max_health)
+               {
+                       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.delay != -1)
-               self.nextthink = self.delay;
+       if(self.weaponentity)
+       if(time >= self.weaponentity.ltime)
+               shalrath_shield_die();
+               
+       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(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 ()
+void shalrathattack_melee()
 {
-       self.frame = shalrath_anim_attack;
-       self.delay = time + 0.2;
-       self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_spike_delay;
-       self.monster_delayedattack = ShalMissile;
+       monster_melee(self.enemy, autocvar_g_monster_shalrath_attack_melee_damage, 0.3, DEATH_MONSTER_MAGE, TRUE);
+       
+       self.delay = -1;
+       self.monster_delayedattack = func_null;
 }
 
-void shalrathattack_melee ()
+void shalrath_grenade_explode()
 {
-       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_MAGE);
+       pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
+       
+       sound(self, CH_SHOTS, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
+       RadiusDamage (self, self.realowner, autocvar_g_monster_shalrath_attack_grenade_damage, autocvar_g_monster_shalrath_attack_grenade_edgedamage, autocvar_g_monster_shalrath_attack_grenade_radius, world, autocvar_g_monster_shalrath_attack_grenade_force, DEATH_MONSTER_MAGE, other);
+       remove(self);
 }
 
-void shalrath_attack_melee ()
+void shalrath_grenade_touch()
 {
-       self.monster_delayedattack = shalrathattack_melee;
-       self.delay = time + 0.2;
-       self.frame = shalrath_anim_attack;
-       self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_melee_delay;
+       if(IS_PLAYER(other))
+       {
+               PROJECTILE_TOUCH;
+               shalrath_grenade_explode();
+               return;
+       }
 }
 
-float shal_missile ()
+void shalrath_throw_itemgrenade()
 {
-       shalrath_attack();
+       makevectors(self.angles);
+
+       W_SetupShot_ProjectileSize (self, '-64 -64 -64', '64 64 64', FALSE, 4, "", CH_WEAPON_A, autocvar_g_monster_shalrath_attack_grenade_damage);
+       w_shotdir = v_forward; // no TrueAim for grenades please
+
+       entity gren = spawn ();
+       gren.owner = gren.realowner = self;
+       gren.classname = "grenade";
+       gren.bot_dodge = FALSE;
+       gren.movetype = MOVETYPE_BOUNCE;
+       gren.solid = SOLID_TRIGGER;
+       gren.projectiledeathtype = DEATH_MONSTER_MAGE;
+       setorigin(gren, w_shotorg);
+       setsize(gren, '-64 -64 -64', '64 64 64');
+
+       gren.nextthink = time + autocvar_g_monster_shalrath_attack_grenade_lifetime;
+       gren.think = shalrath_grenade_explode;
+       gren.use = shalrath_grenade_explode;
+       gren.touch = shalrath_grenade_touch;
+
+       gren.missile_flags = MIF_SPLASH | MIF_ARC;
+       W_SETUPPROJECTILEVELOCITY_UP(gren, g_monster_shalrath_attack_grenade);
+       
+       gren.flags = FL_PROJECTILE;
        
-       return TRUE;
+       setmodel(gren, "models/items/g_h50.md3");
+       
+       self.attack_finished_single = time + 1.5;
 }
 
-void ShalHome ()
+void ShalHome()
 {
        local vector dir = '0 0 0', vtemp = self.enemy.origin + '0 0 10';
        
@@ -84,7 +171,7 @@ void ShalHome ()
        self.think = ShalHome;  
 }
 
-void shal_spike_explode ()
+void shal_spike_explode()
 {
        self.event_damage = func_null;
 
@@ -101,7 +188,7 @@ void shal_spike_touchexplode()
        shal_spike_explode();
 }
 
-void ShalMissile ()
+void ShalMissile()
 {
        local   entity  missile = world;
        local   vector  dir = '0 0 0';
@@ -112,8 +199,7 @@ void ShalMissile ()
        missile = spawn ();
        missile.owner = missile.realowner = self;
        
-       self.v_angle = self.angles;
-       makevectors (self.angles);
+       monster_makevectors(self.enemy);
        
        dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
        dist = vlen (self.enemy.origin - self.origin);
@@ -134,110 +220,161 @@ void ShalMissile ()
        CSQCProjectile(missile, TRUE, PROJECTILE_VORE_SPIKE, TRUE);
 }
 
-float ShalrathCheckAttack ()
+void shalrath_heal()
 {
-       local vector spot1 = '0 0 0', spot2 = '0 0 0';
-       local entity targ = self.enemy;
-
-       if (self.health <= 0 || targ == world || targ.health < 1)
-               return FALSE;
+       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;
        
-       if(self.monster_delayedattack && self.delay != -1)
+       for(head = world; (head = findfloat(head, monster_attack, TRUE)); )
        {
-               if(time < self.delay)
-                       return FALSE;
-                       
-               self.monster_delayedattack();
-               self.delay = -1;
-               self.monster_delayedattack = func_null;
+               if(head.health > 0)
+               if not(head.frozen)
+               if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range)
+               if not(IsDifferentTeam(head, self))
+               {
+                       if(IS_PLAYER(head))
+                       {
+                               if((g_minstagib && head.ammo_cells < start_ammo_cells) || head.health < start_health)
+                                       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);
        
-       if(time < self.attack_finished_single)
-               return FALSE;
+       self.weaponentity = world;
+}
+
+void shalrath_shield()
+{
+       if(self.weaponentity)
+               return; // already have a shield
+               
+       entity shield = spawn();
+
+       shield.owner = self;
+       shield.team = self.team;
+       shield.ltime = time + autocvar_g_monster_shalrath_shield_time;
+       shield.health = 70;
+       shield.classname = "shield";
+       shield.effects = EF_ADDITIVE;
+       shield.movetype = MOVETYPE_NOCLIP;
+       shield.solid = SOLID_TRIGGER;
+       shield.avelocity = '7 0 11';
+       shield.scale = self.scale * 0.6;
+       
+       setattachment(shield, self, "");
+       setmodel(shield, "models/ctf/shield.md3");
+       setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
+       
+       self.weaponentity = shield;
+       
+       self.lastshielded = time + autocvar_g_monster_shalrath_shield_delay;
+       
+       monsters_setframe(shalrath_anim_attack);
+       self.attack_finished_single = time + 1;
        
-       if (vlen(self.enemy.origin - self.origin) <= 120)
-       {       // melee attack
-               if (self.attack_melee)
+       self.armorvalue = autocvar_g_monster_shalrath_shield_blockpercent / 100;
+}
+
+float mage_attack(float attack_type)
+{
+       switch(attack_type)
+       {
+               case MONSTER_ATTACK_MELEE:
+               {
+                       self.monster_delayedattack = shalrathattack_melee;
+                       self.delay = time + 0.2;
+                       monsters_setframe(shalrath_anim_attack);
+                       self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_melee_delay;
+                       
+                       return TRUE;
+               }
+               case MONSTER_ATTACK_RANGED:
                {
-                       monster_sound(self.msound_attack_melee, 0, FALSE); // no delay for attack sounds
-                       self.attack_melee();
+                       if(random() < autocvar_g_monster_shalrath_attack_grenade_chance / 100)
+                       {
+                               shalrath_throw_itemgrenade();
+                               return TRUE;
+                       }
+       
+                       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;
+                       
                        return TRUE;
                }
        }
-
-// see if any entities are in the way of the shot
-       spot1 = self.origin + self.view_ofs;
-       spot2 = targ.origin + targ.view_ofs;
-
-       traceline (spot1, spot2, FALSE, self);
-
-       if (trace_ent != targ && 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_die ()
+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.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
 }
 
-void shalrath_spawn ()
+void shalrath_spawn()
 {
        if not(self.health)
-               self.health = autocvar_g_monster_shalrath_health * self.scale;
+               self.health = autocvar_g_monster_shalrath_health;
 
        self.damageforcescale   = 0.003;
        self.classname                  = "monster_shalrath";
-       self.checkattack                = ShalrathCheckAttack;
-       self.attack_ranged              = shal_missile;
-       self.attack_melee               = shalrath_attack_melee;
+       self.monster_attackfunc = mage_attack;
        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
 }
 
-void spawnfunc_monster_shalrath ()
+void spawnfunc_monster_mage()
 {      
        if not(autocvar_g_monster_shalrath) { remove(self); return; }
        
-       self.monster_spawnfunc = spawnfunc_monster_shalrath;
+       self.monster_spawnfunc = spawnfunc_monster_mage;
        
-       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))
@@ -248,4 +385,6 @@ void spawnfunc_monster_shalrath ()
 }
 
 // compatibility with old spawns
-void spawnfunc_monster_vore () { spawnfunc_monster_shalrath(); }
+void spawnfunc_monster_shalrath() { spawnfunc_monster_mage(); }
+
+#endif // SVQC