]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/shambler.qc
Merge branch 'master' into Mario/entcs
[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
154         CSQCProjectile(gren, true, PROJECTILE_SHAMBLER_LIGHTNING, true);
155 }
156
157 .int state;
158
159 bool M_Shambler_Attack(int attack_type, entity actor, entity targ)
160 {
161         switch(attack_type)
162         {
163                 case MONSTER_ATTACK_MELEE:
164                 {
165                         int swing_cnt = bound(1, floor(random() * 4), 3);
166                         Monster_Delay(actor, swing_cnt, 0.5, M_Shambler_Attack_Swing);
167                         actor.anim_finished = actor.attack_finished_single[0] = time + (0.5 * swing_cnt); // set this for the delay
168                         return true;
169                 }
170                 case MONSTER_ATTACK_RANGED:
171                 {
172                         float randomness = random();
173
174                         if(time >= actor.shambler_lastattack) // shambler doesn't attack much
175                         if(IS_ONGROUND(actor))
176                         if(randomness <= 0.5 && vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_shambler_attack_smash_range))
177                         {
178                                 setanim(actor, actor.anim_melee2, true, true, false);
179                                 Monster_Delay(actor, 1, 0.7, M_Shambler_Attack_Smash);
180                                 actor.attack_finished_single[0] = time + 1.1;
181                                 actor.anim_finished = time + 1.1;
182                                 actor.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
183                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
184                                 return true;
185                         }
186                         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
187                         {
188                                 setanim(actor, actor.anim_shoot, true, true, false);
189                                 actor.state = MONSTER_ATTACK_MELEE; // maybe we should rename this to something more general
190                                 actor.attack_finished_single[0] = time + 1.1;
191                                 actor.anim_finished = 1.1;
192                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
193                                 Monster_Delay(actor, 1, 0.6, M_Shambler_Attack_Lightning);
194                                 return true;
195                         }
196
197                         return false;
198                 }
199         }
200
201         return false;
202 }
203
204 spawnfunc(monster_shambler) { Monster_Spawn(this, MON_SHAMBLER.monsterid); }
205 #endif // SVQC
206
207 #ifdef SVQC
208 METHOD(Shambler, mr_think, bool(Shambler this, entity actor))
209 {
210     TC(Shambler, this);
211     return true;
212 }
213
214 METHOD(Shambler, mr_pain, float(Shambler this, entity actor, float damage_take, entity attacker, float deathtype))
215 {
216     TC(Shambler, this);
217     actor.pain_finished = time + 0.5;
218     setanim(actor, actor.anim_pain1, true, true, false);
219     return damage_take;
220 }
221
222 METHOD(Shambler, mr_death, bool(Shambler this, entity actor))
223 {
224     TC(Shambler, this);
225     setanim(actor, actor.anim_die1, false, true, true);
226     return true;
227 }
228 #endif
229 #ifdef GAMEQC
230 METHOD(Shambler, mr_anim, bool(Shambler this, entity actor))
231 {
232     TC(Shambler, this);
233     vector none = '0 0 0';
234     actor.anim_die1 = animfixfps(actor, '8 1 0.5', none); // 2 seconds
235     actor.anim_walk = animfixfps(actor, '1 1 1', none);
236     actor.anim_idle = animfixfps(actor, '0 1 1', none);
237     actor.anim_pain1 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
238     actor.anim_melee1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
239     actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
240     actor.anim_melee3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
241     actor.anim_shoot = animfixfps(actor, '6 1 5', none); // analyze models and set framerate
242     actor.anim_run = animfixfps(actor, '2 1 1', none);
243     return true;
244 }
245 #endif
246 #ifdef SVQC
247 spawnfunc(item_health_mega);
248 .float animstate_endtime;
249 METHOD(Shambler, mr_setup, bool(Shambler this, entity actor))
250 {
251     TC(Shambler, this);
252     if(!actor.health) actor.health = (autocvar_g_monster_shambler_health);
253     if(!actor.attack_range) actor.attack_range = 150;
254     if(!actor.speed) { actor.speed = (autocvar_g_monster_shambler_speed_walk); }
255     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_shambler_speed_run); }
256     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_shambler_speed_stop); }
257     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_shambler_damageforcescale); }
258
259     actor.monster_loot = spawnfunc_item_health_mega;
260     actor.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
261
262     setanim(actor, actor.anim_shoot, false, true, true);
263     actor.spawn_time = actor.animstate_endtime;
264     actor.spawnshieldtime = actor.spawn_time;
265     actor.monster_attackfunc = M_Shambler_Attack;
266
267     return true;
268 }
269
270 METHOD(Shambler, mr_precache, bool(Shambler this))
271 {
272     TC(Shambler, this);
273     return true;
274 }
275 #endif
276
277 #endif