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