]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
Merge branch 'master' into Mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / spider.qc
1 #include "spider.qh"
2
3 #if defined(SVQC)
4         #include <common/mutators/base.qh>
5 #endif
6
7 #ifdef SVQC
8
9 .float spider_slowness; // effect time of slowness inflicted by spiders
10
11 .float spider_web_delay;
12
13 float autocvar_g_monster_spider_attack_web_damagetime;
14 float autocvar_g_monster_spider_attack_web_speed;
15 float autocvar_g_monster_spider_attack_web_speed_up;
16 float autocvar_g_monster_spider_attack_web_delay;
17 float autocvar_g_monster_spider_attack_web_range = 800;
18
19 float autocvar_g_monster_spider_attack_bite_damage;
20 float autocvar_g_monster_spider_attack_bite_delay;
21
22 void M_Spider_Attack_Web(entity this);
23
24 REGISTER_MUTATOR(spiderweb, true);
25
26 MUTATOR_HOOKFUNCTION(spiderweb, PlayerPhysics_UpdateStats)
27 {
28         entity player = M_ARGV(0, entity);
29
30         if(time < player.spider_slowness)
31                 STAT(MOVEVARS_HIGHSPEED, player) *= 0.5;
32 }
33
34 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
35 {
36     entity mon = M_ARGV(0, entity);
37
38         if(time < mon.spider_slowness)
39         {
40                 M_ARGV(1, float) *= 0.5; // run speed
41                 M_ARGV(2, float) *= 0.5; // walk speed
42         }
43 }
44
45 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
46 {
47         entity player = M_ARGV(0, entity);
48
49         player.spider_slowness = 0;
50         return false;
51 }
52
53 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
54 {
55     entity mon = M_ARGV(0, entity);
56
57         mon.spider_slowness = 0;
58 }
59
60 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
61 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire))
62 {
63     TC(SpiderAttack, thiswep);
64     bool isPlayer = IS_PLAYER(actor);
65     if (fire & 1)
66     if ((!isPlayer && time >= actor.spider_web_delay) || (isPlayer && weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_monster_spider_attack_web_delay))) {
67                 if (!isPlayer) {
68                         actor.spider_web_delay = time + autocvar_g_monster_spider_attack_web_delay;
69                         setanim(actor, actor.anim_shoot, true, true, true);
70                         if(actor.animstate_endtime > time)
71                                 actor.anim_finished = actor.animstate_endtime;
72                         else
73                                 actor.anim_finished = time + 1;
74                         actor.attack_finished_single[0] = actor.anim_finished + 0.2;
75                 }
76         if (isPlayer) actor.enemy = Monster_FindTarget(actor);
77         monster_makevectors(actor, actor.enemy);
78         W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_SpiderAttack_FIRE, CH_WEAPON_B, 0, DEATH_MONSTER_SPIDER.m_id);
79         if (!isPlayer) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
80                 M_Spider_Attack_Web(actor);
81         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
82         return;
83     }
84     if (fire & 2)
85     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
86         if (isPlayer) {
87                 actor.enemy = Monster_FindTarget(actor);
88                 actor.attack_range = 60;
89         }
90         Monster_Attack_Melee(actor, actor.enemy, (autocvar_g_monster_spider_attack_bite_damage), ((random() > 0.5) ? actor.anim_melee : actor.anim_shoot), actor.attack_range, (autocvar_g_monster_spider_attack_bite_delay), DEATH_MONSTER_SPIDER.m_id, true);
91         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
92     }
93 }
94
95 float autocvar_g_monster_spider_health;
96 float autocvar_g_monster_spider_damageforcescale = 0.6;
97 float autocvar_g_monster_spider_speed_stop;
98 float autocvar_g_monster_spider_speed_run;
99 float autocvar_g_monster_spider_speed_walk;
100
101 /*
102 const float spider_anim_idle            = 0;
103 const float spider_anim_walk            = 1;
104 const float spider_anim_attack          = 2;
105 const float spider_anim_attack2         = 3;
106 */
107
108 void M_Spider_Attack_Web_Explode(entity this)
109 {
110         if(this)
111         {
112                 Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
113                 RadiusDamage(this, this.realowner, 0, 0, 25, NULL, NULL, 25, this.projectiledeathtype, DMG_NOWEP, NULL);
114
115                 FOREACH_ENTITY_RADIUS(this.origin, 25, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && it.monsterdef != MON_SPIDER,
116                 {
117                         it.spider_slowness = time + (autocvar_g_monster_spider_attack_web_damagetime);
118                 });
119
120                 delete(this);
121         }
122 }
123
124 void M_Spider_Attack_Web_Explode_use(entity this, entity actor, entity trigger)
125 {
126         M_Spider_Attack_Web_Explode(this);
127 }
128
129 void M_Spider_Attack_Web_Touch(entity this, entity toucher)
130 {
131         PROJECTILE_TOUCH(this, toucher);
132
133         M_Spider_Attack_Web_Explode(this);
134 }
135
136 void M_Spider_Attack_Web(entity this)
137 {
138         sound(this, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
139
140         entity proj = new(plasma);
141         proj.owner = proj.realowner = this;
142         proj.use = M_Spider_Attack_Web_Explode_use;
143         setthink(proj, adaptor_think2use_hittype_splash);
144         proj.bot_dodge = true;
145         proj.bot_dodgerating = 0;
146         proj.nextthink = time + 5;
147         PROJECTILE_MAKETRIGGER(proj);
148         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
149         setorigin(proj, CENTER_OR_VIEWOFS(this));
150
151         //proj.glow_size = 50;
152         //proj.glow_color = 45;
153         set_movetype(proj, MOVETYPE_BOUNCE);
154         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);
155         settouch(proj, M_Spider_Attack_Web_Touch);
156         setsize(proj, '-4 -4 -4', '4 4 4');
157         proj.takedamage = DAMAGE_NO;
158         proj.damageforcescale = 0;
159         SetResourceExplicit(proj, RES_HEALTH, 500);
160         proj.event_damage = func_null;
161         proj.flags = FL_PROJECTILE;
162         IL_PUSH(g_projectiles, proj);
163         IL_PUSH(g_bot_dodge, proj);
164         proj.damagedbycontents = true;
165         IL_PUSH(g_damagedbycontents, proj);
166
167         proj.bouncefactor = 0.3;
168         proj.bouncestop = 0.05;
169         proj.missile_flags = MIF_SPLASH | MIF_ARC;
170
171         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
172 }
173
174 bool M_Spider_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
175 {
176         Weapon wep = WEP_SPIDER_ATTACK;
177         switch(attack_type)
178         {
179                 case MONSTER_ATTACK_MELEE:
180                 {
181                         wep.wr_think(wep, actor, weaponentity, 2);
182                         return true;
183                 }
184                 case MONSTER_ATTACK_RANGED:
185                 {
186                         if(vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_spider_attack_web_range))
187                         {
188                                 wep.wr_think(wep, actor, weaponentity, 1);
189                                 return true;
190                         }
191                 }
192         }
193
194         return false;
195 }
196
197 spawnfunc(monster_spider) { Monster_Spawn(this, true, MON_SPIDER); }
198 #endif // SVQC
199
200 #ifdef SVQC
201 METHOD(Spider, mr_think, bool(Spider this, entity actor))
202 {
203     TC(Spider, this);
204     return true;
205 }
206
207 METHOD(Spider, mr_pain, float(Spider this, entity actor, float damage_take, entity attacker, float deathtype))
208 {
209     TC(Spider, this);
210     setanim(actor, ((random() > 0.5) ? actor.anim_pain2 : actor.anim_pain1), true, true, false);
211     actor.pain_finished = actor.animstate_endtime;
212     return damage_take;
213 }
214
215 METHOD(Spider, mr_death, bool(Spider this, entity actor))
216 {
217     TC(Spider, this);
218     setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
219     return true;
220 }
221 #endif
222 #ifdef GAMEQC
223 METHOD(Spider, mr_anim, bool(Spider this, entity actor))
224 {
225     TC(Spider, this);
226     vector none = '0 0 0';
227     actor.anim_melee = animfixfps(actor, '0 1 5', none); // analyze models and set framerate
228     actor.anim_die1 = animfixfps(actor, '1 1 1', none);
229     actor.anim_die2 = animfixfps(actor, '2 1 1', none);
230     actor.anim_shoot = animfixfps(actor, '3 1 1', none);
231     //actor.anim_fire2 = animfixfps(actor, '4 1 1', none);
232     actor.anim_idle = animfixfps(actor, '5 1 1', none);
233     //actor.anim_sight = animfixfps(actor, '6 1 1', none);
234     actor.anim_pain1 = animfixfps(actor, '7 1 1', none);
235     actor.anim_pain2 = animfixfps(actor, '8 1 1', none);
236     //actor.anim_pain3 = animfixfps(actor, '9 1 1', none);
237     actor.anim_walk = animfixfps(actor, '10 1 1', none);
238     actor.anim_run = animfixfps(actor, '10 1 1', none); // temp?
239     //actor.anim_forwardright = animfixfps(actor, '11 1 1', none);
240     //actor.anim_walkright = animfixfps(actor, '12 1 1', none);
241     //actor.anim_walkbackright = animfixfps(actor, '13 1 1', none);
242     //actor.anim_walkback = animfixfps(actor, '14 1 1', none);
243     //actor.anim_walkbackleft = animfixfps(actor, '15 1 1', none);
244     //actor.anim_walkleft = animfixfps(actor, '16 1 1', none);
245     //actor.anim_forwardleft = animfixfps(actor, '17 1 1', none);
246     return true;
247 }
248 #endif
249 #ifdef SVQC
250 METHOD(Spider, mr_setup, bool(Spider this, entity actor))
251 {
252     TC(Spider, this);
253     if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_spider_health);
254     if(!actor.speed) { actor.speed = (autocvar_g_monster_spider_speed_walk); }
255     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_spider_speed_run); }
256     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_spider_speed_stop); }
257     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
258
259     actor.monster_loot = ITEM_HealthMedium;
260     actor.monster_attackfunc = M_Spider_Attack;
261
262     return true;
263 }
264 #endif