Merge branch 'master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / shambler.qc
1 #ifdef REGISTER_MONSTER
2 REGISTER_MONSTER(
3 /* MON_##id   */ SHAMBLER,
4 /* function   */ m_shambler,
5 /* spawnflags */ MONSTER_SIZE_BROKEN | MON_FLAG_SUPERMONSTER | MON_FLAG_MELEE | MON_FLAG_RANGED,
6 /* mins,maxs  */ '-41 -41 -31', '41 41 65',
7 /* model      */ "shambler.mdl",
8 /* netname    */ "shambler",
9 /* fullname   */ _("Shambler")
10 );
11
12 #else
13 #ifdef SVQC
14 float autocvar_g_monster_shambler_health;
15 float autocvar_g_monster_shambler_attack_smash_damage;
16 float autocvar_g_monster_shambler_attack_claw_damage;
17 float autocvar_g_monster_shambler_attack_lightning_damage;
18 float autocvar_g_monster_shambler_attack_lightning_force;
19 float autocvar_g_monster_shambler_attack_lightning_radius;
20 float autocvar_g_monster_shambler_attack_lightning_radius_zap;
21 float autocvar_g_monster_shambler_attack_lightning_speed;
22 float autocvar_g_monster_shambler_attack_lightning_speed_up;
23 float autocvar_g_monster_shambler_speed_stop;
24 float autocvar_g_monster_shambler_speed_run;
25 float autocvar_g_monster_shambler_speed_walk;
26
27 const float shambler_anim_stand         = 0;
28 const float shambler_anim_walk          = 1;
29 const float shambler_anim_run           = 2;
30 const float shambler_anim_smash         = 3;
31 const float shambler_anim_swingr        = 4;
32 const float shambler_anim_swingl        = 5;
33 const float shambler_anim_magic         = 6;
34 const float shambler_anim_pain          = 7;
35 const float shambler_anim_death         = 8;
36
37 .float shambler_lastattack; // delay attacks separately
38
39 void shambler_smash()
40 {
41         makevectors(self.angles);
42         pointparticles(particleeffectnum("explosion_medium"), (self.origin + (v_forward * 150)) - ('0 0 1' * self.maxs_z), '0 0 0', 1);
43         sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
44
45         tracebox(self.origin + v_forward * 50, self.mins * 0.5, self.maxs * 0.5, self.origin + v_forward * 500, MOVE_NORMAL, self);
46
47         if(trace_ent.takedamage)
48                 Damage(trace_ent, self, self, (autocvar_g_monster_shambler_attack_smash_damage) * Monster_SkillModifier(), DEATH_MONSTER_SHAMBLER_SMASH, trace_ent.origin, normalize(trace_ent.origin - self.origin));
49 }
50
51 void shambler_swing()
52 {
53         float r = (random() < 0.5);
54         monster_melee(self.enemy, (autocvar_g_monster_shambler_attack_claw_damage), ((r) ? shambler_anim_swingr : shambler_anim_swingl), self.attack_range, 0.8, DEATH_MONSTER_SHAMBLER_CLAW, TRUE);
55         if(r)
56         {
57                 defer(0.5, shambler_swing);
58                 self.attack_finished_single += 0.5;
59         }
60 }
61
62 void shambler_lightning_explode()
63 {
64         entity head;
65
66         sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_NORM);
67         pointparticles(particleeffectnum("electro_impact"), '0 0 0', '0 0 0', 1);
68
69         self.event_damage = func_null;
70         self.takedamage = DAMAGE_NO;
71         self.movetype = MOVETYPE_NONE;
72         self.velocity = '0 0 0';
73
74         if(self.movetype == MOVETYPE_NONE)
75                 self.velocity = self.oldvelocity;
76
77         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);
78
79         for(head = findradius(self.origin, (autocvar_g_monster_shambler_attack_lightning_radius_zap)); head; head = head.chain) if(head != self.realowner) if(head.takedamage)
80         {
81                 te_csqc_lightningarc(self.origin, head.origin);
82                 Damage(head, self, self.realowner, (autocvar_g_monster_shambler_attack_lightning_damage) * Monster_SkillModifier(), DEATH_MONSTER_SHAMBLER_ZAP, head.origin, '0 0 0');
83         }
84
85         self.think = SUB_Remove;
86         self.nextthink = time + 0.2;
87 }
88
89 void shambler_lightning_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
90 {
91         if (self.health <= 0)
92                 return;
93
94         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
95                 return; // g_projectiles_damage says to halt
96
97         self.health = self.health - damage;
98
99         if (self.health <= 0)
100                 W_PrepareExplosionByDamage(attacker, self.use);
101 }
102
103 void shambler_lightning_touch()
104 {
105         PROJECTILE_TOUCH;
106
107         self.use ();
108 }
109
110 void shambler_lightning_think()
111 {
112         self.nextthink = time;
113         if (time > self.cnt)
114         {
115                 other = world;
116                 shambler_lightning_explode();
117                 return;
118         }
119 }
120
121 void shambler_lightning()
122 {
123         entity gren;
124
125         monster_makevectors(self.enemy);
126
127         gren = spawn ();
128         gren.owner = gren.realowner = self;
129         gren.classname = "grenade";
130         gren.bot_dodge = TRUE;
131         gren.bot_dodgerating = (autocvar_g_monster_shambler_attack_lightning_damage);
132         gren.movetype = MOVETYPE_BOUNCE;
133         PROJECTILE_MAKETRIGGER(gren);
134         gren.projectiledeathtype = DEATH_MONSTER_SHAMBLER_ZAP;
135         setorigin(gren, CENTER_OR_VIEWOFS(self));
136         setsize(gren, '-8 -8 -8', '8 8 8');
137         gren.scale = 2.5;
138
139         gren.cnt = time + 5;
140         gren.nextthink = time;
141         gren.think = shambler_lightning_think;
142         gren.use = shambler_lightning_explode;
143         gren.touch = shambler_lightning_touch;
144
145         gren.takedamage = DAMAGE_YES;
146         gren.health = 50;
147         gren.damageforcescale = 0;
148         gren.event_damage = shambler_lightning_damage;
149         gren.damagedbycontents = TRUE;
150         gren.missile_flags = MIF_SPLASH | MIF_ARC;
151         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);
152
153         gren.angles = vectoangles (gren.velocity);
154         gren.flags = FL_PROJECTILE;
155
156         CSQCProjectile(gren, TRUE, PROJECTILE_SHAMBLER_LIGHTNING, TRUE);
157 }
158
159 float shambler_attack(float attack_type)
160 {
161         switch(attack_type)
162         {
163                 case MONSTER_ATTACK_MELEE:
164                 {
165                         shambler_swing();
166                         return TRUE;
167                 }
168                 case MONSTER_ATTACK_RANGED:
169                 {
170                         if(time >= self.shambler_lastattack) // shambler doesn't attack much
171                         if(self.flags & FL_ONGROUND)
172                         if(random() <= 0.5 && vlen(self.enemy.origin - self.origin) <= 500)
173                         {
174                                 self.frame = shambler_anim_smash;
175                                 defer(0.7, shambler_smash);
176                                 self.attack_finished_single = time + 1.1;
177                                 self.shambler_lastattack = time + 3;
178                                 return TRUE;
179                         }
180                         else if(random() <= 0.1) // small chance, don't want this spammed
181                         {
182                                 self.frame = shambler_anim_magic;
183                                 self.attack_finished_single = time + 1.1;
184                                 self.shambler_lastattack = time + 3;
185                                 defer(0.6, shambler_lightning);
186                                 return TRUE;
187                         }
188
189                         return FALSE;
190                 }
191         }
192
193         return FALSE;
194 }
195
196 void spawnfunc_monster_shambler()
197 {
198         self.classname = "monster_shambler";
199
200         if(!monster_initialize(MON_SHAMBLER)) { remove(self); return; }
201 }
202
203 float m_shambler(float req)
204 {
205         switch(req)
206         {
207                 case MR_THINK:
208                 {
209                         monster_move((autocvar_g_monster_shambler_speed_run), (autocvar_g_monster_shambler_speed_walk), (autocvar_g_monster_shambler_speed_stop), shambler_anim_run, shambler_anim_walk, shambler_anim_stand);
210                         return TRUE;
211                 }
212                 case MR_DEATH:
213                 {
214                         self.frame = shambler_anim_death;
215                         return TRUE;
216                 }
217                 case MR_SETUP:
218                 {
219                         if(!self.health) self.health = (autocvar_g_monster_shambler_health);
220                         if(!self.attack_range) self.attack_range = 150;
221
222                         self.monster_loot = spawnfunc_item_health_mega;
223                         self.monster_attackfunc = shambler_attack;
224                         self.frame = shambler_anim_stand;
225                         self.weapon = WEP_VORTEX;
226
227                         return TRUE;
228                 }
229                 case MR_PRECACHE:
230                 {
231                         precache_model("models/monsters/shambler.mdl");
232                         return TRUE;
233                 }
234         }
235
236         return TRUE;
237 }
238
239 #endif // SVQC
240 #ifdef CSQC
241 float m_shambler(float req)
242 {
243         switch(req)
244         {
245                 case MR_PRECACHE:
246                 {
247                         return TRUE;
248                 }
249         }
250
251         return TRUE;
252 }
253
254 #endif // CSQC
255 #endif // REGISTER_MONSTER