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