a25a89e7dde125194dedfe8124412ed8bc2edc20
[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, M_Model("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     this.mr_precache(this);
22 #endif
23 }
24
25 #include "../../weapons/all.qh"
26
27 CLASS(SpiderAttack, PortoLaunch)
28 /* flags     */ ATTRIB(SpiderAttack, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
29 /* impulse   */ ATTRIB(SpiderAttack, impulse, int, 9);
30 /* refname   */ ATTRIB(SpiderAttack, netname, string, "spider");
31 /* wepname   */ ATTRIB(SpiderAttack, m_name, string, _("Spider attack"));
32 ENDCLASS(SpiderAttack)
33 REGISTER_WEAPON(SPIDER_ATTACK, NEW(SpiderAttack));
34
35 #endif
36
37 #ifdef IMPLEMENTATION
38
39 #ifdef SVQC
40
41 .float spider_slowness; // effect time of slowness inflicted by spiders
42
43 .float spider_web_delay;
44
45 float autocvar_g_monster_spider_attack_web_damagetime;
46 float autocvar_g_monster_spider_attack_web_speed;
47 float autocvar_g_monster_spider_attack_web_speed_up;
48 float autocvar_g_monster_spider_attack_web_delay;
49
50 float autocvar_g_monster_spider_attack_bite_damage;
51 float autocvar_g_monster_spider_attack_bite_delay;
52
53 void M_Spider_Attack_Web();
54
55 REGISTER_MUTATOR(spiderweb, true);
56
57 MUTATOR_HOOKFUNCTION(spiderweb, PlayerPhysics)
58 {
59         if (time >= self.spider_slowness)
60                 return false;
61         PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
62         PHYS_MAXAIRSPEED(self) *= 0.5;
63         PHYS_AIRSPEEDLIMIT_NONQW(self) *= 0.5;
64         PHYS_AIRSTRAFEACCELERATE(self) *= 0.5;
65         return false;
66 }
67
68 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
69 {
70         if(time < self.spider_slowness)
71         {
72                 monster_speed_run *= 0.5;
73                 monster_speed_walk *= 0.5;
74         }
75         return false;
76 }
77
78 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
79 {
80         self.spider_slowness = 0;
81         return false;
82 }
83
84 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
85 {
86         self.spider_slowness = 0;
87         return false;
88 }
89
90 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
91 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire)) {
92     bool isPlayer = IS_PLAYER(actor);
93     if (fire & 1)
94     if ((!isPlayer && time >= actor.spider_web_delay) || weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_monster_spider_attack_web_delay)) {
95                 if (!isPlayer) {
96                         actor.spider_web_delay = time + 3;
97                         setanim(actor, actor.anim_shoot, true, true, true);
98                         actor.attack_finished_single[0] = time + (autocvar_g_monster_spider_attack_web_delay);
99                         actor.anim_finished = time + 1;
100                 }
101         if (isPlayer) actor.enemy = Monster_FindTarget(actor);
102         W_SetupShot_Dir(actor, v_forward, false, 0, SND(SpiderAttack_FIRE), CH_WEAPON_B, 0);
103         if (!isPlayer) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
104                 M_Spider_Attack_Web();
105         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
106         return;
107     }
108     if (fire & 2)
109     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
110         if (isPlayer) {
111                 actor.enemy = Monster_FindTarget(actor);
112                 actor.attack_range = 60;
113         }
114         Monster_Attack_Melee(actor.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.m_id, true);
115         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
116     }
117 }
118
119 float autocvar_g_monster_spider_health;
120 float autocvar_g_monster_spider_damageforcescale = 0.6;
121 float autocvar_g_monster_spider_speed_stop;
122 float autocvar_g_monster_spider_speed_run;
123 float autocvar_g_monster_spider_speed_walk;
124
125 /*
126 const float spider_anim_idle            = 0;
127 const float spider_anim_walk            = 1;
128 const float spider_anim_attack          = 2;
129 const float spider_anim_attack2         = 3;
130 */
131
132 void M_Spider_Attack_Web_Explode()
133 {SELFPARAM();
134         entity e;
135         if(self)
136         {
137                 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
138                 RadiusDamage(self, self.realowner, 0, 0, 25, world, world, 25, self.projectiledeathtype, world);
139
140                 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)
141                         e.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
142
143                 remove(self);
144         }
145 }
146
147 void M_Spider_Attack_Web_Touch()
148 {
149         PROJECTILE_TOUCH;
150
151         M_Spider_Attack_Web_Explode();
152 }
153
154 void adaptor_think2use_hittype_splash();
155
156 void M_Spider_Attack_Web()
157 {SELFPARAM();
158         monster_makevectors(self.enemy);
159
160         sound(self, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
161
162         entity proj = new(plasma);
163         proj.owner = proj.realowner = self;
164         proj.use = M_Spider_Attack_Web_Explode;
165         proj.think = adaptor_think2use_hittype_splash;
166         proj.bot_dodge = true;
167         proj.bot_dodgerating = 0;
168         proj.nextthink = time + 5;
169         PROJECTILE_MAKETRIGGER(proj);
170         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
171         setorigin(proj, CENTER_OR_VIEWOFS(self));
172
173         //proj.glow_size = 50;
174         //proj.glow_color = 45;
175         proj.movetype = MOVETYPE_BOUNCE;
176         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);
177         proj.touch = M_Spider_Attack_Web_Touch;
178         setsize(proj, '-4 -4 -4', '4 4 4');
179         proj.takedamage = DAMAGE_NO;
180         proj.damageforcescale = 0;
181         proj.health = 500;
182         proj.event_damage = func_null;
183         proj.flags = FL_PROJECTILE;
184         proj.damagedbycontents = true;
185
186         proj.bouncefactor = 0.3;
187         proj.bouncestop = 0.05;
188         proj.missile_flags = MIF_SPLASH | MIF_ARC;
189
190         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
191 }
192
193 bool M_Spider_Attack(int attack_type, entity targ)
194 {SELFPARAM();
195     .entity weaponentity = weaponentities[0];
196         switch(attack_type)
197         {
198                 Weapon wep = WEP_SPIDER_ATTACK;
199                 case MONSTER_ATTACK_MELEE:
200                 {
201                         wep.wr_think(wep, self, weaponentity, 2);
202                         return true;
203                 }
204                 case MONSTER_ATTACK_RANGED:
205                 {
206                         wep.wr_think(wep, self, weaponentity, 1);
207                         return true;
208                 }
209         }
210
211         return false;
212 }
213
214 spawnfunc(monster_spider) { Monster_Spawn(MON_SPIDER.monsterid); }
215 #endif // SVQC
216
217                 #ifdef SVQC
218                 METHOD(Spider, mr_think, bool(Spider thismon))
219                 {
220                         return true;
221                 }
222                 METHOD(Spider, mr_pain, bool(Spider thismon))
223                 {
224                         return true;
225                 }
226                 METHOD(Spider, mr_death, bool(Spider thismon))
227                 {
228                         SELFPARAM();
229                         setanim(self, self.anim_melee, false, true, true);
230                         self.angles_x = 180;
231                         return true;
232                 }
233                 #endif
234                 #ifndef MENUQC
235                 METHOD(Spider, mr_anim, bool(Spider thismon))
236                 {
237                         SELFPARAM();
238                         vector none = '0 0 0';
239                         self.anim_walk = animfixfps(self, '1 1 1', none);
240                         self.anim_idle = animfixfps(self, '0 1 1', none);
241                         self.anim_melee = animfixfps(self, '2 1 5', none); // analyze models and set framerate
242                         self.anim_shoot = animfixfps(self, '3 1 5', none); // analyze models and set framerate
243                         self.anim_run = animfixfps(self, '1 1 1', none);
244
245                         return true;
246                 }
247                 #endif
248                 #ifdef SVQC
249                 spawnfunc(item_health_medium);
250                 METHOD(Spider, mr_setup, bool(Spider thismon))
251                 {
252                         SELFPARAM();
253                         if(!self.health) self.health = (autocvar_g_monster_spider_health);
254                         if(!self.speed) { self.speed = (autocvar_g_monster_spider_speed_walk); }
255                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_spider_speed_run); }
256                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_spider_speed_stop); }
257                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
258
259                         self.monster_loot = spawnfunc_item_health_medium;
260                         self.monster_attackfunc = M_Spider_Attack;
261
262                         return true;
263                 }
264                 METHOD(Spider, mr_precache, bool(Spider thismon))
265                 {
266                         return true;
267                 }
268                 #endif
269
270 #endif