5de8fccd870ab8b58d9ee5d95bf49f7db9c7458f
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / spider.qc
1 #ifndef SPIDER_H
2 #define SPIDER_H
3
4 #ifndef MENUQC
5 MODEL(MON_SPIDER, "models/monsters/spider.dpm");
6 #endif
7
8 CLASS(Spider, Monster)
9     ATTRIB(Spider, spawnflags, int, MON_FLAG_MELEE | MON_FLAG_RANGED | MON_FLAG_RIDE);
10     ATTRIB(Spider, mins, vector, '-18 -18 -25');
11     ATTRIB(Spider, maxs, vector, '18 18 30');
12 #ifndef MENUQC
13     ATTRIB(Spider, m_model, Model, MDL_MON_SPIDER);
14 #endif
15     ATTRIB(Spider, netname, string, "spider");
16     ATTRIB(Spider, monster_name, string, _("Spider"));
17 ENDCLASS(Spider)
18
19 REGISTER_MONSTER(SPIDER, NEW(Spider)) {
20 #ifndef MENUQC
21     MON_ACTION(this, MR_PRECACHE);
22 #endif
23 }
24
25 #endif
26
27 #ifdef IMPLEMENTATION
28
29 #ifdef SVQC
30 float autocvar_g_monster_spider_health;
31 float autocvar_g_monster_spider_damageforcescale = 0.6;
32 float autocvar_g_monster_spider_attack_bite_damage;
33 float autocvar_g_monster_spider_attack_bite_delay;
34 float autocvar_g_monster_spider_attack_web_damagetime;
35 float autocvar_g_monster_spider_attack_web_speed;
36 float autocvar_g_monster_spider_attack_web_speed_up;
37 float autocvar_g_monster_spider_attack_web_delay;
38 float autocvar_g_monster_spider_speed_stop;
39 float autocvar_g_monster_spider_speed_run;
40 float autocvar_g_monster_spider_speed_walk;
41
42 /*
43 const float spider_anim_idle            = 0;
44 const float spider_anim_walk            = 1;
45 const float spider_anim_attack          = 2;
46 const float spider_anim_attack2         = 3;
47 */
48
49 .float spider_web_delay;
50
51 void M_Spider_Attack_Web_Explode()
52 {SELFPARAM();
53         entity e;
54         if(self)
55         {
56                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
57                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
58
59                 for(e = findradius(self.origin, 25); e; e = e.chain) if(e != self) if(e.takedamage && e.deadflag == DEAD_NO) if(e.health > 0) if(e.monsterid != MON_SPIDER.monsterid)
60                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
61
62                 remove(self);
63         }
64 }
65
66 void M_Spider_Attack_Web_Touch()
67 {
68         PROJECTILE_TOUCH;
69
70         M_Spider_Attack_Web_Explode();
71 }
72
73 void M_Spider_Attack_Web()
74 {SELFPARAM();
75         monster_makevectors(self.enemy);
76
77         sound(self, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
78
79         entity proj = spawn ();
80         proj.classname = "plasma";
81         proj.owner = proj.realowner = self;
82         proj.use = M_Spider_Attack_Web_Explode;
83         proj.think = adaptor_think2use_hittype_splash;
84         proj.bot_dodge = true;
85         proj.bot_dodgerating = 0;
86         proj.nextthink = time + 5;
87         PROJECTILE_MAKETRIGGER(proj);
88         proj.projectiledeathtype = DEATH_MONSTER_SPIDER;
89         setorigin(proj, CENTER_OR_VIEWOFS(self));
90
91         //proj.glow_size = 50;
92         //proj.glow_color = 45;
93         proj.movetype = MOVETYPE_BOUNCE;
94         W_SetupProjVelocity_Explicit(proj, v_forward, v_up, (autocvar_g_monster_spider_attack_web_speed), (autocvar_g_monster_spider_attack_web_speed_up), 0, 0, false);
95         proj.touch = M_Spider_Attack_Web_Touch;
96         setsize(proj, '-4 -4 -4', '4 4 4');
97         proj.takedamage = DAMAGE_NO;
98         proj.damageforcescale = 0;
99         proj.health = 500;
100         proj.event_damage = func_null;
101         proj.flags = FL_PROJECTILE;
102         proj.damagedbycontents = true;
103
104         proj.bouncefactor = 0.3;
105         proj.bouncestop = 0.05;
106         proj.missile_flags = MIF_SPLASH | MIF_ARC;
107
108         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
109 }
110
111 bool M_Spider_Attack(int attack_type, entity targ)
112 {SELFPARAM();
113         switch(attack_type)
114         {
115                 case MONSTER_ATTACK_MELEE:
116                 {
117                         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);
118                 }
119                 case MONSTER_ATTACK_RANGED:
120                 {
121                         if(time >= self.spider_web_delay)
122                         {
123                                 setanim(self, self.anim_shoot, true, true, true);
124                                 self.attack_finished_single = time + (autocvar_g_monster_spider_attack_web_delay);
125                                 self.anim_finished = time + 1;
126                                 M_Spider_Attack_Web();
127                                 self.spider_web_delay = time + 3;
128                                 return true;
129                         }
130
131                         return false;
132                 }
133         }
134
135         return false;
136 }
137
138 void spawnfunc_monster_spider() { Monster_Spawn(MON_SPIDER.monsterid); }
139 #endif // SVQC
140
141                 #ifdef SVQC
142                 METHOD(Spider, mr_think, bool(Spider thismon))
143                 {
144                         return true;
145                 }
146                 METHOD(Spider, mr_pain, bool(Spider thismon))
147                 {
148                         return true;
149                 }
150                 METHOD(Spider, mr_death, bool(Spider thismon))
151                 {
152                         SELFPARAM();
153                         setanim(self, self.anim_melee, false, true, true);
154                         self.angles_x = 180;
155                         return true;
156                 }
157                 #endif
158                 #ifndef MENUQC
159                 METHOD(Spider, mr_anim, bool(Spider thismon))
160                 {
161                         SELFPARAM();
162                         vector none = '0 0 0';
163                         self.anim_walk = animfixfps(self, '1 1 1', none);
164                         self.anim_idle = animfixfps(self, '0 1 1', none);
165                         self.anim_melee = animfixfps(self, '2 1 5', none); // analyze models and set framerate
166                         self.anim_shoot = animfixfps(self, '3 1 5', none); // analyze models and set framerate
167                         self.anim_run = animfixfps(self, '1 1 1', none);
168
169                         return true;
170                 }
171                 #endif
172                 #ifdef SVQC
173                 METHOD(Spider, mr_setup, bool(Spider thismon))
174                 {
175                         SELFPARAM();
176                         if(!self.health) self.health = (autocvar_g_monster_spider_health);
177                         if(!self.speed) { self.speed = (autocvar_g_monster_spider_speed_walk); }
178                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_spider_speed_run); }
179                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_spider_speed_stop); }
180                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
181
182                         self.monster_loot = spawnfunc_item_health_medium;
183                         self.monster_attackfunc = M_Spider_Attack;
184
185                         return true;
186                 }
187                 METHOD(Spider, mr_precache, bool(Spider thismon))
188                 {
189                         return true;
190                 }
191                 #endif
192
193 #endif