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