Merge branch 'terencehill/hide_motd' 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, "models/monsters/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 "../../../server/csqceffects.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;
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 = spawn ();
153         gren.owner = gren.realowner = self;
154         gren.classname = "grenade";
155         gren.bot_dodge = true;
156         gren.bot_dodgerating = (autocvar_g_monster_shambler_attack_lightning_damage);
157         gren.movetype = MOVETYPE_BOUNCE;
158         PROJECTILE_MAKETRIGGER(gren);
159         gren.projectiledeathtype = DEATH_MONSTER_SHAMBLER_ZAP.m_id;
160         setorigin(gren, CENTER_OR_VIEWOFS(self));
161         setsize(gren, '-8 -8 -8', '8 8 8');
162         gren.scale = 2.5;
163
164         gren.cnt = time + 5;
165         gren.nextthink = time;
166         gren.think = M_Shambler_Attack_Lightning_Think;
167         gren.use = M_Shambler_Attack_Lightning_Explode;
168         gren.touch = M_Shambler_Attack_Lightning_Touch;
169
170         gren.takedamage = DAMAGE_YES;
171         gren.health = 50;
172         gren.damageforcescale = 0;
173         gren.event_damage = M_Shambler_Attack_Lightning_Damage;
174         gren.damagedbycontents = true;
175         gren.missile_flags = MIF_SPLASH | MIF_ARC;
176         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);
177
178         gren.angles = vectoangles (gren.velocity);
179         gren.flags = FL_PROJECTILE;
180
181         CSQCProjectile(gren, true, PROJECTILE_SHAMBLER_LIGHTNING, true);
182 }
183
184 .int state;
185
186 float M_Shambler_Attack(float attack_type, entity targ)
187 {SELFPARAM();
188         switch(attack_type)
189         {
190                 case MONSTER_ATTACK_MELEE:
191                 {
192                         M_Shambler_Attack_Swing();
193                         return true;
194                 }
195                 case MONSTER_ATTACK_RANGED:
196                 {
197                         float randomness = random(), enemy_len = vlen(self.enemy.origin - self.origin);
198
199                         if(time >= self.shambler_lastattack) // shambler doesn't attack much
200                         if(self.flags & FL_ONGROUND)
201                         if(randomness <= 0.5 && enemy_len <= autocvar_g_monster_shambler_attack_smash_range)
202                         {
203                                 setanim(self, self.anim_melee2, true, true, false);
204                                 Monster_Delay(1, 0, 0.7, M_Shambler_Attack_Smash);
205                                 self.attack_finished_single[0] = time + 1.1;
206                                 self.anim_finished = time + 1.1;
207                                 self.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
208                                 self.shambler_lastattack = time + 3 + random() * 1.5;
209                                 return true;
210                         }
211                         else if(randomness <= 0.1 && enemy_len >= autocvar_g_monster_shambler_attack_smash_range * 1.5) // small chance, don't want this spammed
212                         {
213                                 setanim(self, self.anim_shoot, true, true, false);
214                                 self.state = MONSTER_ATTACK_MELEE; // maybe we should rename this to something more general
215                                 self.attack_finished_single[0] = time + 1.1;
216                                 self.anim_finished = 1.1;
217                                 self.shambler_lastattack = time + 3 + random() * 1.5;
218                                 Monster_Delay(1, 0, 0.6, M_Shambler_Attack_Lightning);
219                                 return true;
220                         }
221
222                         return false;
223                 }
224         }
225
226         return false;
227 }
228
229 spawnfunc(monster_shambler) { Monster_Spawn(MON_SHAMBLER.monsterid); }
230 #endif // SVQC
231
232                 #ifdef SVQC
233                 METHOD(Shambler, mr_think, bool(Shambler thismon))
234                 {
235                         return true;
236                 }
237                 METHOD(Shambler, mr_pain, bool(Shambler thismon))
238                 {
239                         SELFPARAM();
240                         self.pain_finished = time + 0.5;
241                         setanim(self, self.anim_pain1, true, true, false);
242                         return true;
243                 }
244                 METHOD(Shambler, mr_death, bool(Shambler thismon))
245                 {
246                         SELFPARAM();
247                         setanim(self, self.anim_die1, false, true, true);
248                         return true;
249                 }
250                 #endif
251                 #ifndef MENUQC
252                 METHOD(Shambler, mr_anim, bool(Shambler thismon))
253                 {
254                         SELFPARAM();
255                         vector none = '0 0 0';
256                         self.anim_die1 = animfixfps(self, '8 1 0.5', none); // 2 seconds
257                         self.anim_walk = animfixfps(self, '1 1 1', none);
258                         self.anim_idle = animfixfps(self, '0 1 1', none);
259                         self.anim_pain1 = animfixfps(self, '7 1 2', none); // 0.5 seconds
260                         self.anim_melee1 = animfixfps(self, '3 1 5', none); // analyze models and set framerate
261                         self.anim_melee2 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
262                         self.anim_melee3 = animfixfps(self, '5 1 5', none); // analyze models and set framerate
263                         self.anim_shoot = animfixfps(self, '6 1 5', none); // analyze models and set framerate
264                         self.anim_run = animfixfps(self, '2 1 1', none);
265
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 thismon))
273                 {
274                         SELFPARAM();
275                         if(!self.health) self.health = (autocvar_g_monster_shambler_health);
276                         if(!self.attack_range) self.attack_range = 150;
277                         if(!self.speed) { self.speed = (autocvar_g_monster_shambler_speed_walk); }
278                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_shambler_speed_run); }
279                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_shambler_speed_stop); }
280                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_shambler_damageforcescale); }
281
282                         self.monster_loot = spawnfunc_item_health_mega;
283                         self.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
284
285                         setanim(self, self.anim_shoot, false, true, true);
286                         self.spawn_time = self.animstate_endtime;
287                         self.spawnshieldtime = self.spawn_time;
288                         self.monster_attackfunc = M_Shambler_Attack;
289
290                         return true;
291                 }
292                 METHOD(Shambler, mr_precache, bool(Shambler thismon))
293                 {
294                         return true;
295                 }
296                 #endif
297
298 #endif