Merge branch 'terencehill/lms_itemtimes_fix' into 'master'
[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()
82 {SELFPARAM();
83         entity head;
84
85         sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
86         Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
87
88         self.event_damage = func_null;
89         self.takedamage = DAMAGE_NO;
90         self.movetype = MOVETYPE_NONE;
91         self.velocity = '0 0 0';
92
93         if(self.movetype == MOVETYPE_NONE)
94                 self.velocity = self.oldvelocity;
95
96         RadiusDamage (self, self.realowner, (autocvar_g_monster_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_radius), world, world, (autocvar_g_monster_shambler_attack_lightning_force), self.projectiledeathtype, other);
97
98         for(head = findradius(self.origin, (autocvar_g_monster_shambler_attack_lightning_radius_zap)); head; head = head.chain) if(head != self.realowner) if(head.takedamage)
99         {
100                 te_csqc_lightningarc(self.origin, head.origin);
101                 Damage(head, self, self.realowner, (autocvar_g_monster_shambler_attack_lightning_damage_zap) * MONSTER_SKILLMOD(self), DEATH_MONSTER_SHAMBLER_ZAP.m_id, head.origin, '0 0 0');
102         }
103
104         self.think = SUB_Remove_self;
105         self.nextthink = time + 0.2;
106 }
107
108 void M_Shambler_Attack_Lightning_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
109 {
110         if (this.health <= 0)
111                 return;
112
113         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
114                 return; // g_projectiles_damage says to halt
115
116         this.health = this.health - damage;
117
118         if (this.health <= 0)
119                 WITH(entity, self, this, W_PrepareExplosionByDamage(attacker, this.use));
120 }
121
122 void M_Shambler_Attack_Lightning_Touch()
123 {SELFPARAM();
124         PROJECTILE_TOUCH;
125
126         self.use ();
127 }
128
129 void M_Shambler_Attack_Lightning_Think()
130 {SELFPARAM();
131         self.nextthink = time;
132         if (time > self.cnt)
133         {
134                 other = world;
135                 M_Shambler_Attack_Lightning_Explode();
136                 return;
137         }
138 }
139
140 void M_Shambler_Attack_Lightning(entity this)
141 {
142         entity gren;
143
144         monster_makevectors(this, this.enemy);
145
146         gren = new(grenade);
147         gren.owner = gren.realowner = this;
148         gren.bot_dodge = true;
149         gren.bot_dodgerating = (autocvar_g_monster_shambler_attack_lightning_damage);
150         gren.movetype = MOVETYPE_BOUNCE;
151         PROJECTILE_MAKETRIGGER(gren);
152         gren.projectiledeathtype = DEATH_MONSTER_SHAMBLER_ZAP.m_id;
153         setorigin(gren, CENTER_OR_VIEWOFS(this));
154         setsize(gren, '-8 -8 -8', '8 8 8');
155         gren.scale = 2.5;
156
157         gren.cnt = time + 5;
158         gren.nextthink = time;
159         gren.think = M_Shambler_Attack_Lightning_Think;
160         gren.use = M_Shambler_Attack_Lightning_Explode;
161         gren.touch = M_Shambler_Attack_Lightning_Touch;
162
163         gren.takedamage = DAMAGE_YES;
164         gren.health = 50;
165         gren.damageforcescale = 0;
166         gren.event_damage = M_Shambler_Attack_Lightning_Damage;
167         gren.damagedbycontents = true;
168         gren.missile_flags = MIF_SPLASH | MIF_ARC;
169         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);
170
171         gren.angles = vectoangles (gren.velocity);
172         gren.flags = FL_PROJECTILE;
173
174         CSQCProjectile(gren, true, PROJECTILE_SHAMBLER_LIGHTNING, true);
175 }
176
177 .int state;
178
179 bool M_Shambler_Attack(int attack_type, entity actor, entity targ)
180 {
181         switch(attack_type)
182         {
183                 case MONSTER_ATTACK_MELEE:
184                 {
185                         int swing_cnt = bound(1, floor(random() * 4), 3);
186                         Monster_Delay(actor, swing_cnt, 0.5, M_Shambler_Attack_Swing);
187                         actor.anim_finished = actor.attack_finished_single[0] = time + (0.5 * swing_cnt); // set this for the delay
188                         return true;
189                 }
190                 case MONSTER_ATTACK_RANGED:
191                 {
192                         float randomness = random();
193
194                         if(time >= actor.shambler_lastattack) // shambler doesn't attack much
195                         if(IS_ONGROUND(actor))
196                         if(randomness <= 0.5 && vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_shambler_attack_smash_range))
197                         {
198                                 setanim(actor, actor.anim_melee2, true, true, false);
199                                 Monster_Delay(actor, 1, 0.7, M_Shambler_Attack_Smash);
200                                 actor.attack_finished_single[0] = time + 1.1;
201                                 actor.anim_finished = time + 1.1;
202                                 actor.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
203                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
204                                 return true;
205                         }
206                         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
207                         {
208                                 setanim(actor, actor.anim_shoot, true, true, false);
209                                 actor.state = MONSTER_ATTACK_MELEE; // maybe we should rename this to something more general
210                                 actor.attack_finished_single[0] = time + 1.1;
211                                 actor.anim_finished = 1.1;
212                                 actor.shambler_lastattack = time + 3 + random() * 1.5;
213                                 Monster_Delay(actor, 1, 0.6, M_Shambler_Attack_Lightning);
214                                 return true;
215                         }
216
217                         return false;
218                 }
219         }
220
221         return false;
222 }
223
224 spawnfunc(monster_shambler) { Monster_Spawn(this, MON_SHAMBLER.monsterid); }
225 #endif // SVQC
226
227                 #ifdef SVQC
228                 METHOD(Shambler, mr_think, bool(Shambler thismon, entity actor))
229                 {
230                         return true;
231                 }
232                 METHOD(Shambler, mr_pain, bool(Shambler thismon, entity actor))
233                 {
234                         actor.pain_finished = time + 0.5;
235                         setanim(actor, actor.anim_pain1, true, true, false);
236                         return true;
237                 }
238                 METHOD(Shambler, mr_death, bool(Shambler thismon, entity actor))
239                 {
240                         setanim(actor, actor.anim_die1, false, true, true);
241                         return true;
242                 }
243                 #endif
244                 #ifndef MENUQC
245                 METHOD(Shambler, mr_anim, bool(Shambler thismon, entity actor))
246                 {
247                         vector none = '0 0 0';
248                         actor.anim_die1 = animfixfps(actor, '8 1 0.5', none); // 2 seconds
249                         actor.anim_walk = animfixfps(actor, '1 1 1', none);
250                         actor.anim_idle = animfixfps(actor, '0 1 1', none);
251                         actor.anim_pain1 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
252                         actor.anim_melee1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
253                         actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
254                         actor.anim_melee3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
255                         actor.anim_shoot = animfixfps(actor, '6 1 5', none); // analyze models and set framerate
256                         actor.anim_run = animfixfps(actor, '2 1 1', none);
257                         return true;
258                 }
259                 #endif
260                 #ifdef SVQC
261                 spawnfunc(item_health_mega);
262                 .float animstate_endtime;
263                 METHOD(Shambler, mr_setup, bool(Shambler thismon, entity actor))
264                 {
265                         if(!actor.health) actor.health = (autocvar_g_monster_shambler_health);
266                         if(!actor.attack_range) actor.attack_range = 150;
267                         if(!actor.speed) { actor.speed = (autocvar_g_monster_shambler_speed_walk); }
268                         if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_shambler_speed_run); }
269                         if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_shambler_speed_stop); }
270                         if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_shambler_damageforcescale); }
271
272                         actor.monster_loot = spawnfunc_item_health_mega;
273                         actor.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
274
275                         setanim(actor, actor.anim_shoot, false, true, true);
276                         actor.spawn_time = actor.animstate_endtime;
277                         actor.spawnshieldtime = actor.spawn_time;
278                         actor.monster_attackfunc = M_Shambler_Attack;
279
280                         return true;
281                 }
282                 METHOD(Shambler, mr_precache, bool(Shambler thismon))
283                 {
284                         return true;
285                 }
286                 #endif
287
288 #endif