]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/shambler.qc
1abe2e9c8700af6156ce8bbcfb78e87a726b4863
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / shambler.qc
1 #include "shambler.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6 float autocvar_g_monster_shambler_health;
7 float autocvar_g_monster_shambler_damageforcescale = 0.1;
8 float autocvar_g_monster_shambler_attack_smash_damage;
9 float autocvar_g_monster_shambler_attack_smash_range;
10 float autocvar_g_monster_shambler_attack_claw_damage;
11 float autocvar_g_monster_shambler_attack_lightning_damage;
12 float autocvar_g_monster_shambler_attack_lightning_damage_zap = 15;
13 float autocvar_g_monster_shambler_attack_lightning_force;
14 float autocvar_g_monster_shambler_attack_lightning_radius;
15 float autocvar_g_monster_shambler_attack_lightning_radius_zap;
16 float autocvar_g_monster_shambler_attack_lightning_speed;
17 float autocvar_g_monster_shambler_attack_lightning_speed_up;
18 float autocvar_g_monster_shambler_speed_stop;
19 float autocvar_g_monster_shambler_speed_run;
20 float autocvar_g_monster_shambler_speed_walk;
21
22 /*
23 const float shambler_anim_stand         = 0;
24 const float shambler_anim_walk          = 1;
25 const float shambler_anim_run           = 2;
26 const float shambler_anim_smash         = 3;
27 const float shambler_anim_swingr        = 4;
28 const float shambler_anim_swingl        = 5;
29 const float shambler_anim_magic         = 6;
30 const float shambler_anim_pain          = 7;
31 const float shambler_anim_death         = 8;
32 */
33
34 .float shambler_lastattack; // delay attacks separately
35
36 void M_Shambler_Attack_Smash(entity this)
37 {
38         makevectors(this.angles);
39         Send_Effect(EFFECT_EXPLOSION_MEDIUM, (this.origin + (v_forward * 150)) - ('0 0 1' * this.maxs.z), '0 0 0', 1);
40         sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
41
42         // RadiusDamage does NOT support custom starting location, which means we must use this hack...
43
44         tracebox(this.origin + v_forward * 50, this.mins * 0.5, this.maxs * 0.5, this.origin + v_forward * autocvar_g_monster_shambler_attack_smash_range, MOVE_NORMAL, this);
45
46         if(trace_ent.takedamage)
47                 Damage(trace_ent, this, this, (autocvar_g_monster_shambler_attack_smash_damage) * MONSTER_SKILLMOD(this), DEATH_MONSTER_SHAMBLER_SMASH.m_id, trace_ent.origin, normalize(trace_ent.origin - this.origin));
48 }
49
50 void M_Shambler_Attack_Swing(entity this)
51 {
52         Monster_Attack_Melee(this, this.enemy, (autocvar_g_monster_shambler_attack_claw_damage), ((random() >= 0.5) ? this.anim_melee2 : this.anim_melee3), this.attack_range, 0.8, DEATH_MONSTER_SHAMBLER_CLAW.m_id, true);
53 }
54
55 #include <common/effects/qc/all.qh>
56
57 void M_Shambler_Attack_Lightning_Explode(entity this, entity directhitentity)
58 {
59         sound(this, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
60         Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
61
62         this.event_damage = func_null;
63         this.takedamage = DAMAGE_NO;
64         set_movetype(this, MOVETYPE_NONE);
65         this.velocity = '0 0 0';
66
67         if(this.move_movetype == MOVETYPE_NONE)
68                 this.velocity = this.oldvelocity;
69
70         RadiusDamage (this, this.realowner, (autocvar_g_monster_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_radius),
71                                         NULL, NULL, (autocvar_g_monster_shambler_attack_lightning_force), this.projectiledeathtype, directhitentity);
72
73         FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_shambler_attack_lightning_radius_zap, it != this.realowner && it.takedamage,
74         {
75                 te_csqc_lightningarc(this.origin, it.origin);
76                 Damage(it, this, this.realowner, (autocvar_g_monster_shambler_attack_lightning_damage_zap) * MONSTER_SKILLMOD(this), DEATH_MONSTER_SHAMBLER_ZAP.m_id, it.origin, '0 0 0');
77         });
78
79         setthink(this, SUB_Remove);
80         this.nextthink = time + 0.2;
81 }
82
83 void M_Shambler_Attack_Lightning_Explode_use(entity this, entity actor, entity trigger)
84 {
85         M_Shambler_Attack_Lightning_Explode(this, trigger);
86 }
87
88 void M_Shambler_Attack_Lightning_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
89 {
90         if (this.health <= 0)
91                 return;
92
93         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
94                 return; // g_projectiles_damage says to halt
95
96         this.health = this.health - damage;
97
98         if (this.health <= 0)
99                 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
100 }
101
102 void M_Shambler_Attack_Lightning_Touch(entity this, entity toucher)
103 {
104         PROJECTILE_TOUCH(this, toucher);
105
106         this.use(this, NULL, toucher);
107 }
108
109 void M_Shambler_Attack_Lightning_Think(entity this)
110 {
111         this.nextthink = time;
112         if (time > this.cnt)
113         {
114                 M_Shambler_Attack_Lightning_Explode(this, NULL);
115                 return;
116         }
117 }
118
119 void M_Shambler_Attack_Lightning(entity this)
120 {
121         entity gren;
122
123         monster_makevectors(this, this.enemy);
124
125         gren = new(grenade);
126         gren.owner = gren.realowner = this;
127         gren.bot_dodge = true;
128         gren.bot_dodgerating = (autocvar_g_monster_shambler_attack_lightning_damage);
129         set_movetype(gren, MOVETYPE_BOUNCE);
130         PROJECTILE_MAKETRIGGER(gren);
131         gren.projectiledeathtype = DEATH_MONSTER_SHAMBLER_ZAP.m_id;
132         setorigin(gren, CENTER_OR_VIEWOFS(this));
133         setsize(gren, '-8 -8 -8', '8 8 8');
134         gren.scale = 2.5;
135
136         gren.cnt = time + 5;
137         gren.nextthink = time;
138         setthink(gren, M_Shambler_Attack_Lightning_Think);
139         gren.use = M_Shambler_Attack_Lightning_Explode_use;
140         settouch(gren, M_Shambler_Attack_Lightning_Touch);
141
142         gren.takedamage = DAMAGE_YES;
143         gren.health = 50;
144         gren.damageforcescale = 0;
145         gren.event_damage = M_Shambler_Attack_Lightning_Damage;
146         gren.damagedbycontents = true;
147         gren.missile_flags = MIF_SPLASH | MIF_ARC;
148         W_SetupProjVelocity_Explicit(gren, v_forward, v_up, (autocvar_g_monster_shambler_attack_lightning_speed), (autocvar_g_monster_shambler_attack_lightning_speed_up), 0, 0, false);
149
150         gren.angles = vectoangles (gren.velocity);
151         gren.flags = FL_PROJECTILE;
152         IL_PUSH(g_projectiles, gren);
153         IL_PUSH(g_bot_dodge, gren);
154
155         CSQCProjectile(gren, true, PROJECTILE_SHAMBLER_LIGHTNING, true);
156 }
157
158 .int state;
159
160 bool M_Shambler_Attack(int attack_type, entity actor, entity targ)
161 {
162         switch(attack_type)
163         {
164                 case MONSTER_ATTACK_MELEE:
165                 {
166                         int swing_cnt = bound(1, floor(random() * 4), 3);
167                         Monster_Delay(actor, swing_cnt, 0.5, M_Shambler_Attack_Swing);
168                         actor.anim_finished = actor.attack_finished_single[0] = time + (0.5 * swing_cnt); // set this for the delay
169                         return true;
170                 }
171                 case MONSTER_ATTACK_RANGED:
172                 {
173                         float randomness = random();
174
175                         if(time >= actor.shambler_lastattack) // shambler doesn't attack much
176                         if(IS_ONGROUND(actor))
177                         if(randomness <= 0.5 && vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_shambler_attack_smash_range))
178                         {
179                                 setanim(actor, actor.anim_melee2, true, true, false);
180                                 Monster_Delay(actor, 1, 0.7, M_Shambler_Attack_Smash);
181                                 actor.attack_finished_single[0] = time + 1.1;
182                                 actor.anim_finished = time + 1.1;
183                                 actor.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
184                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
185                                 return true;
186                         }
187                         else if(randomness <= 0.1 && vdist(actor.enemy.origin - actor.origin, >=, autocvar_g_monster_shambler_attack_smash_range * 1.5)) // small chance, don't want this spammed
188                         {
189                                 setanim(actor, actor.anim_shoot, true, true, false);
190                                 actor.state = MONSTER_ATTACK_MELEE; // maybe we should rename this to something more general
191                                 actor.attack_finished_single[0] = time + 1.1;
192                                 actor.anim_finished = 1.1;
193                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
194                                 Monster_Delay(actor, 1, 0.6, M_Shambler_Attack_Lightning);
195                                 return true;
196                         }
197
198                         return false;
199                 }
200         }
201
202         return false;
203 }
204
205 spawnfunc(monster_shambler) { Monster_Spawn(this, MON_SHAMBLER.monsterid); }
206 #endif // SVQC
207
208 #ifdef SVQC
209 METHOD(Shambler, mr_think, bool(Shambler this, entity actor))
210 {
211     TC(Shambler, this);
212     return true;
213 }
214
215 METHOD(Shambler, mr_pain, float(Shambler this, entity actor, float damage_take, entity attacker, float deathtype))
216 {
217     TC(Shambler, this);
218     actor.pain_finished = time + 0.5;
219     setanim(actor, actor.anim_pain1, true, true, false);
220     return damage_take;
221 }
222
223 METHOD(Shambler, mr_death, bool(Shambler this, entity actor))
224 {
225     TC(Shambler, this);
226     setanim(actor, actor.anim_die1, false, true, true);
227     return true;
228 }
229 #endif
230 #ifdef GAMEQC
231 METHOD(Shambler, mr_anim, bool(Shambler this, entity actor))
232 {
233     TC(Shambler, this);
234     vector none = '0 0 0';
235     actor.anim_die1 = animfixfps(actor, '8 1 0.5', none); // 2 seconds
236     actor.anim_walk = animfixfps(actor, '1 1 1', none);
237     actor.anim_idle = animfixfps(actor, '0 1 1', none);
238     actor.anim_pain1 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
239     actor.anim_melee1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
240     actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
241     actor.anim_melee3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
242     actor.anim_shoot = animfixfps(actor, '6 1 5', none); // analyze models and set framerate
243     actor.anim_run = animfixfps(actor, '2 1 1', none);
244     return true;
245 }
246 #endif
247 #ifdef SVQC
248 spawnfunc(item_health_mega);
249 .float animstate_endtime;
250 METHOD(Shambler, mr_setup, bool(Shambler this, entity actor))
251 {
252     TC(Shambler, this);
253     if(!actor.health) actor.health = (autocvar_g_monster_shambler_health);
254     if(!actor.attack_range) actor.attack_range = 150;
255     if(!actor.speed) { actor.speed = (autocvar_g_monster_shambler_speed_walk); }
256     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_shambler_speed_run); }
257     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_shambler_speed_stop); }
258     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_shambler_damageforcescale); }
259
260     actor.monster_loot = spawnfunc_item_health_mega;
261     actor.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
262
263     setanim(actor, actor.anim_shoot, false, true, true);
264     actor.spawn_time = actor.animstate_endtime;
265     actor.spawnshieldtime = actor.spawn_time;
266     actor.monster_attackfunc = M_Shambler_Attack;
267
268     return true;
269 }
270
271 METHOD(Shambler, mr_precache, bool(Shambler this))
272 {
273     TC(Shambler, this);
274     return true;
275 }
276 #endif
277
278 #endif