]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/spider.qc
Nullify the think function on map entities, works around some crashes in certain...
[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
18 float autocvar_g_monster_spider_attack_bite_damage;
19 float autocvar_g_monster_spider_attack_bite_delay;
20
21 void M_Spider_Attack_Web(entity this);
22
23 REGISTER_MUTATOR(spiderweb, true);
24
25 MUTATOR_HOOKFUNCTION(spiderweb, PlayerPhysics_UpdateStats)
26 {
27         entity player = M_ARGV(0, entity);
28
29         if(time < player.spider_slowness)
30                 STAT(MOVEVARS_HIGHSPEED, player) *= 0.5;
31 }
32
33 MUTATOR_HOOKFUNCTION(spiderweb, MonsterMove)
34 {
35     entity mon = M_ARGV(0, entity);
36
37         if(time < mon.spider_slowness)
38         {
39                 M_ARGV(1, float) *= 0.5; // run speed
40                 M_ARGV(2, float) *= 0.5; // walk speed
41         }
42 }
43
44 MUTATOR_HOOKFUNCTION(spiderweb, PlayerSpawn)
45 {
46         entity player = M_ARGV(0, entity);
47
48         player.spider_slowness = 0;
49         return false;
50 }
51
52 MUTATOR_HOOKFUNCTION(spiderweb, MonsterSpawn)
53 {
54     entity mon = M_ARGV(0, entity);
55
56         mon.spider_slowness = 0;
57 }
58
59 SOUND(SpiderAttack_FIRE, W_Sound("electro_fire"));
60 METHOD(SpiderAttack, wr_think, void(SpiderAttack thiswep, entity actor, .entity weaponentity, int fire))
61 {
62     TC(SpiderAttack, thiswep);
63     bool isPlayer = IS_PLAYER(actor);
64     if (fire & 1)
65     if ((!isPlayer && time >= actor.spider_web_delay) || weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_monster_spider_attack_web_delay)) {
66                 if (!isPlayer) {
67                         actor.spider_web_delay = time + 3;
68                         setanim(actor, actor.anim_shoot, true, true, true);
69                         actor.attack_finished_single[0] = time + (autocvar_g_monster_spider_attack_web_delay);
70                         actor.anim_finished = time + 1;
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.monsterdef != MON_SPIDER,
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 M_Spider_Attack_Web(entity this)
133 {
134         sound(this, CH_SHOTS, SND_ELECTRO_FIRE2, VOL_BASE, ATTEN_NORM);
135
136         entity proj = new(plasma);
137         proj.owner = proj.realowner = this;
138         proj.use = M_Spider_Attack_Web_Explode_use;
139         setthink(proj, adaptor_think2use_hittype_splash);
140         proj.bot_dodge = true;
141         proj.bot_dodgerating = 0;
142         proj.nextthink = time + 5;
143         PROJECTILE_MAKETRIGGER(proj);
144         proj.projectiledeathtype = DEATH_MONSTER_SPIDER.m_id;
145         setorigin(proj, CENTER_OR_VIEWOFS(this));
146
147         //proj.glow_size = 50;
148         //proj.glow_color = 45;
149         set_movetype(proj, MOVETYPE_BOUNCE);
150         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);
151         settouch(proj, M_Spider_Attack_Web_Touch);
152         setsize(proj, '-4 -4 -4', '4 4 4');
153         proj.takedamage = DAMAGE_NO;
154         proj.damageforcescale = 0;
155         SetResourceExplicit(proj, RES_HEALTH, 500);
156         proj.event_damage = func_null;
157         proj.flags = FL_PROJECTILE;
158         IL_PUSH(g_projectiles, proj);
159         IL_PUSH(g_bot_dodge, proj);
160         proj.damagedbycontents = true;
161         IL_PUSH(g_damagedbycontents, proj);
162
163         proj.bouncefactor = 0.3;
164         proj.bouncestop = 0.05;
165         proj.missile_flags = MIF_SPLASH | MIF_ARC;
166
167         CSQCProjectile(proj, true, PROJECTILE_ELECTRO, true);
168 }
169
170 bool M_Spider_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
171 {
172         Weapon wep = WEP_SPIDER_ATTACK;
173         switch(attack_type)
174         {
175                 case MONSTER_ATTACK_MELEE:
176                 {
177                         wep.wr_think(wep, actor, weaponentity, 2);
178                         return true;
179                 }
180                 case MONSTER_ATTACK_RANGED:
181                 {
182                         wep.wr_think(wep, actor, weaponentity, 1);
183                         return true;
184                 }
185         }
186
187         return false;
188 }
189
190 spawnfunc(monster_spider) { Monster_Spawn(this, true, MON_SPIDER); }
191 #endif // SVQC
192
193 #ifdef SVQC
194 METHOD(Spider, mr_think, bool(Spider this, entity actor))
195 {
196     TC(Spider, this);
197     return true;
198 }
199
200 METHOD(Spider, mr_pain, float(Spider this, entity actor, float damage_take, entity attacker, float deathtype))
201 {
202     TC(Spider, this);
203     return damage_take;
204 }
205
206 METHOD(Spider, mr_death, bool(Spider this, entity actor))
207 {
208     TC(Spider, this);
209     setanim(actor, actor.anim_melee, false, true, true);
210     actor.angles_x = 180;
211     return true;
212 }
213 #endif
214 #ifdef GAMEQC
215 METHOD(Spider, mr_anim, bool(Spider this, entity actor))
216 {
217     TC(Spider, this);
218     vector none = '0 0 0';
219     actor.anim_walk = animfixfps(actor, '1 1 1', none);
220     actor.anim_idle = animfixfps(actor, '0 1 1', none);
221     actor.anim_melee = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
222     actor.anim_shoot = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
223     actor.anim_run = animfixfps(actor, '1 1 1', none);
224     return true;
225 }
226 #endif
227 #ifdef SVQC
228 METHOD(Spider, mr_setup, bool(Spider this, entity actor))
229 {
230     TC(Spider, this);
231     if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_spider_health);
232     if(!actor.speed) { actor.speed = (autocvar_g_monster_spider_speed_walk); }
233     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_spider_speed_run); }
234     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_spider_speed_stop); }
235     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_spider_damageforcescale); }
236
237     actor.monster_loot = ITEM_HealthMedium;
238     actor.monster_attackfunc = M_Spider_Attack;
239
240     return true;
241 }
242 #endif