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