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