]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/monster/spider.qc
Weapons: hide from menu
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / spider.qc
index 0179c66b9add72b73c2a165e64fbd0f4e9fd996d..78f8aff09e95867ddb5e9b37b56704ff12c2eca2 100644 (file)
@@ -1,29 +1,87 @@
+#ifndef SPIDER_H
+#define SPIDER_H
+
 #ifndef MENUQC
-bool M_Spider(int);
+MODEL(MON_SPIDER, "models/monsters/spider.dpm");
 #endif
-REGISTER_MONSTER_SIMPLE(
-/* MON_##id   */ SPIDER,
-/* spawnflags */ MON_FLAG_MELEE | MON_FLAG_RANGED | MON_FLAG_RIDE,
-/* mins,maxs  */ '-18 -18 -25', '18 18 30',
-/* model      */ "spider.dpm",
-/* netname    */ "spider",
-/* fullname   */ _("Spider")
-) {
+
+CLASS(Spider, Monster)
+    ATTRIB(Spider, spawnflags, int, MON_FLAG_MELEE | MON_FLAG_RANGED | MON_FLAG_RIDE);
+    ATTRIB(Spider, mins, vector, '-18 -18 -25');
+    ATTRIB(Spider, maxs, vector, '18 18 30');
+#ifndef MENUQC
+    ATTRIB(Spider, m_model, Model, MDL_MON_SPIDER);
+#endif
+    ATTRIB(Spider, netname, string, "spider");
+    ATTRIB(Spider, monster_name, string, _("Spider"));
+ENDCLASS(Spider)
+
+REGISTER_MONSTER(SPIDER, NEW(Spider)) {
 #ifndef MENUQC
-       this.monster_func = M_Spider;
-       this.monster_func(MR_PRECACHE);
+    MON_ACTION(this, MR_PRECACHE);
 #endif
 }
 
+#include "../../weapons/all.qh"
+
+CLASS(SpiderAttack, PortoLaunch)
+/* flags     */ ATTRIB(SpiderAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
+/* impulse   */ ATTRIB(SpiderAttack, impulse, int, 9);
+/* refname   */ ATTRIB(SpiderAttack, netname, string, "spider");
+/* wepname   */ ATTRIB(SpiderAttack, message, string, _("Spider attack"));
+ENDCLASS(SpiderAttack)
+REGISTER_WEAPON(SPIDER_ATTACK, NEW(SpiderAttack));
+
+#endif
+
+#ifdef IMPLEMENTATION
+
 #ifdef SVQC
-float autocvar_g_monster_spider_health;
-float autocvar_g_monster_spider_damageforcescale = 0.6;
-float autocvar_g_monster_spider_attack_bite_damage;
-float autocvar_g_monster_spider_attack_bite_delay;
+
+.float spider_web_delay;
+
 float autocvar_g_monster_spider_attack_web_damagetime;
 float autocvar_g_monster_spider_attack_web_speed;
 float autocvar_g_monster_spider_attack_web_speed_up;
 float autocvar_g_monster_spider_attack_web_delay;
+
+float autocvar_g_monster_spider_attack_bite_damage;
+float autocvar_g_monster_spider_attack_bite_delay;
+
+void M_Spider_Attack_Web();
+
+METHOD(SpiderAttack, wr_think, bool(SpiderAttack thiswep, bool fire1, bool fire2)) {
+    SELFPARAM();
+    bool isPlayer = IS_PLAYER(self);
+    if (fire1)
+    if ((!isPlayer && time >= self.spider_web_delay) || weapon_prepareattack(false, autocvar_g_monster_spider_attack_web_delay)) {
+               if (!isPlayer) {
+                       self.spider_web_delay = time + 3;
+                       setanim(self, self.anim_shoot, true, true, true);
+                       self.attack_finished_single = time + (autocvar_g_monster_spider_attack_web_delay);
+                       self.anim_finished = time + 1;
+               }
+        if (isPlayer) self.enemy = Monster_FindTarget(self);
+        W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
+       if (!isPlayer) w_shotdir = normalize((self.enemy.origin + '0 0 10') - self.origin);
+               M_Spider_Attack_Web();
+        weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
+        return true;
+    }
+    if (fire2)
+    if (!isPlayer || weapon_prepareattack(true, 0.5)) {
+       if (isPlayer) {
+               self.enemy = Monster_FindTarget(self);
+               self.attack_range = 60;
+       }
+       Monster_Attack_Melee(self.enemy, (autocvar_g_monster_spider_attack_bite_damage), ((random() > 0.5) ? self.anim_melee : self.anim_shoot), self.attack_range, (autocvar_g_monster_spider_attack_bite_delay), DEATH_MONSTER_SPIDER, true);
+        weapon_thinkf(WFRAME_FIRE2, 0, w_ready);
+    }
+    return true;
+}
+
+float autocvar_g_monster_spider_health;
+float autocvar_g_monster_spider_damageforcescale = 0.6;
 float autocvar_g_monster_spider_speed_stop;
 float autocvar_g_monster_spider_speed_run;
 float autocvar_g_monster_spider_speed_walk;
@@ -35,10 +93,8 @@ const float spider_anim_attack               = 2;
 const float spider_anim_attack2                = 3;
 */
 
-.float spider_web_delay;
-
 void M_Spider_Attack_Web_Explode()
-{
+{SELFPARAM();
        entity e;
        if(self)
        {
@@ -60,10 +116,10 @@ void M_Spider_Attack_Web_Touch()
 }
 
 void M_Spider_Attack_Web()
-{
+{SELFPARAM();
        monster_makevectors(self.enemy);
 
-       sound(self, CH_SHOTS, W_Sound("electro_fire2"), VOL_BASE, ATTEN_NORM);
+       sound(self, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
 
        entity proj = spawn ();
        proj.classname = "plasma";
@@ -97,27 +153,18 @@ void M_Spider_Attack_Web()
        CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
 }
 
-bool M_Spider_Attack(int attack_type)
-{
+bool M_Spider_Attack(int attack_type, entity targ)
+{SELFPARAM();
        switch(attack_type)
        {
+               Weapon wep = WEP_SPIDER_ATTACK;
                case MONSTER_ATTACK_MELEE:
                {
-                       return Monster_Attack_Melee(self.enemy, (autocvar_g_monster_spider_attack_bite_damage), ((random() > 0.5) ? self.anim_melee : self.anim_shoot), self.attack_range, (autocvar_g_monster_spider_attack_bite_delay), DEATH_MONSTER_SPIDER, true);
+                       return wep.wr_think(wep, false, true);
                }
                case MONSTER_ATTACK_RANGED:
                {
-                       if(time >= self.spider_web_delay)
-                       {
-                               setanim(self, self.anim_shoot, true, true, true);
-                               self.attack_finished_single = time + (autocvar_g_monster_spider_attack_web_delay);
-                               self.anim_finished = time + 1;
-                               M_Spider_Attack_Web();
-                               self.spider_web_delay = time + 3;
-                               return true;
-                       }
-
-                       return false;
+                       return wep.wr_think(wep, true, false);
                }
        }
 
@@ -127,29 +174,27 @@ bool M_Spider_Attack(int attack_type)
 void spawnfunc_monster_spider() { Monster_Spawn(MON_SPIDER.monsterid); }
 #endif // SVQC
 
-bool M_Spider(int req)
-{
-       switch(req)
-       {
                #ifdef SVQC
-               case MR_THINK:
+               METHOD(Spider, mr_think, bool(Spider thismon))
                {
                        return true;
                }
-               case MR_PAIN:
+               METHOD(Spider, mr_pain, bool(Spider thismon))
                {
                        return true;
                }
-               case MR_DEATH:
+               METHOD(Spider, mr_death, bool(Spider thismon))
                {
+                       SELFPARAM();
                        setanim(self, self.anim_melee, false, true, true);
                        self.angles_x = 180;
                        return true;
                }
                #endif
                #ifndef MENUQC
-               case MR_ANIM:
+               METHOD(Spider, mr_anim, bool(Spider thismon))
                {
+                       SELFPARAM();
                        vector none = '0 0 0';
                        self.anim_walk = animfixfps(self, '1 1 1', none);
                        self.anim_idle = animfixfps(self, '0 1 1', none);
@@ -161,8 +206,9 @@ bool M_Spider(int req)
                }
                #endif
                #ifdef SVQC
-               case MR_SETUP:
+               METHOD(Spider, mr_setup, bool(Spider thismon))
                {
+                       SELFPARAM();
                        if(!self.health) self.health = (autocvar_g_monster_spider_health);
                        if(!self.speed) { self.speed = (autocvar_g_monster_spider_speed_walk); }
                        if(!self.speed2) { self.speed2 = (autocvar_g_monster_spider_speed_run); }
@@ -174,14 +220,10 @@ bool M_Spider(int req)
 
                        return true;
                }
-               case MR_PRECACHE:
+               METHOD(Spider, mr_precache, bool(Spider thismon))
                {
-                       precache_model("models/monsters/spider.dpm");
-                       precache_sound (W_Sound("electro_fire2"));
                        return true;
                }
                #endif
-       }
 
-       return true;
-}
+#endif