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