]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/golem.qc
Merge branch 'master' into Mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / golem.qc
1 #include "golem.qh"
2
3 #ifdef SVQC
4 float autocvar_g_monster_golem_health;
5 float autocvar_g_monster_golem_damageforcescale = 0.1;
6 float autocvar_g_monster_golem_attack_smash_damage;
7 float autocvar_g_monster_golem_attack_smash_range;
8 float autocvar_g_monster_golem_attack_claw_damage;
9 float autocvar_g_monster_golem_attack_lightning_damage;
10 float autocvar_g_monster_golem_attack_lightning_damage_zap = 15;
11 float autocvar_g_monster_golem_attack_lightning_force;
12 float autocvar_g_monster_golem_attack_lightning_radius;
13 float autocvar_g_monster_golem_attack_lightning_radius_zap;
14 float autocvar_g_monster_golem_attack_lightning_speed;
15 float autocvar_g_monster_golem_attack_lightning_speed_up;
16 float autocvar_g_monster_golem_speed_stop;
17 float autocvar_g_monster_golem_speed_run;
18 float autocvar_g_monster_golem_speed_walk;
19
20 /*
21 const float golem_anim_stand            = 0;
22 const float golem_anim_walk             = 1;
23 const float golem_anim_run              = 2;
24 const float golem_anim_smash            = 3;
25 const float golem_anim_swingr   = 4;
26 const float golem_anim_swingl   = 5;
27 const float golem_anim_magic            = 6;
28 const float golem_anim_pain             = 7;
29 const float golem_anim_death            = 8;
30 */
31
32 .float golem_lastattack; // delay attacks separately
33
34 void M_Golem_Attack_Smash(entity this)
35 {
36         makevectors(this.angles);
37         Send_Effect(EFFECT_EXPLOSION_MEDIUM, (this.origin + (v_forward * 150)) - ('0 0 1' * this.maxs.z), '0 0 0', 1);
38         sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
39
40         // RadiusDamage does NOT support custom starting location, which means we must use this hack...
41
42         tracebox(this.origin + v_forward * 50, this.mins * 0.5, this.maxs * 0.5, this.origin + v_forward * autocvar_g_monster_golem_attack_smash_range, MOVE_NORMAL, this);
43
44         if(trace_ent.takedamage)
45                 Damage(trace_ent, this, this, (autocvar_g_monster_golem_attack_smash_damage) * MONSTER_SKILLMOD(this), DEATH_MONSTER_GOLEM_SMASH.m_id, trace_ent.origin, normalize(trace_ent.origin - this.origin));
46 }
47
48 void M_Golem_Attack_Swing(entity this)
49 {
50         Monster_Attack_Melee(this, this.enemy, (autocvar_g_monster_golem_attack_claw_damage), ((random() >= 0.5) ? this.anim_melee2 : this.anim_melee3), this.attack_range, 0.8, DEATH_MONSTER_GOLEM_CLAW.m_id, true);
51 }
52
53 #include <common/effects/qc/_mod.qh>
54
55 void M_Golem_Attack_Lightning_Explode(entity this, entity directhitentity)
56 {
57         sound(this, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
58         Send_Effect(EFFECT_ELECTRO_IMPACT, this.origin, '0 0 0', 1);
59
60         this.event_damage = func_null;
61         this.takedamage = DAMAGE_NO;
62         set_movetype(this, MOVETYPE_NONE);
63         this.velocity = '0 0 0';
64
65         if(this.move_movetype == MOVETYPE_NONE)
66                 this.velocity = this.oldvelocity;
67
68         RadiusDamage (this, this.realowner, (autocvar_g_monster_golem_attack_lightning_damage), (autocvar_g_monster_golem_attack_lightning_damage), (autocvar_g_monster_golem_attack_lightning_radius),
69                                         NULL, NULL, (autocvar_g_monster_golem_attack_lightning_force), this.projectiledeathtype, directhitentity);
70
71         FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_golem_attack_lightning_radius_zap, it != this.realowner && it.takedamage,
72         {
73                 te_csqc_lightningarc(this.origin, it.origin);
74                 Damage(it, this, this.realowner, (autocvar_g_monster_golem_attack_lightning_damage_zap) * MONSTER_SKILLMOD(this), DEATH_MONSTER_GOLEM_ZAP.m_id, it.origin, '0 0 0');
75         });
76
77         setthink(this, SUB_Remove);
78         this.nextthink = time + 0.2;
79 }
80
81 void M_Golem_Attack_Lightning_Explode_use(entity this, entity actor, entity trigger)
82 {
83         M_Golem_Attack_Lightning_Explode(this, trigger);
84 }
85
86 void M_Golem_Attack_Lightning_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
87 {
88         if (this.health <= 0)
89                 return;
90
91         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
92                 return; // g_projectiles_damage says to halt
93
94         this.health = this.health - damage;
95
96         if (this.health <= 0)
97                 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
98 }
99
100 void M_Golem_Attack_Lightning_Touch(entity this, entity toucher)
101 {
102         PROJECTILE_TOUCH(this, toucher);
103
104         this.use(this, NULL, toucher);
105 }
106
107 void M_Golem_Attack_Lightning_Think(entity this)
108 {
109         this.nextthink = time;
110         if (time > this.cnt)
111         {
112                 M_Golem_Attack_Lightning_Explode(this, NULL);
113                 return;
114         }
115 }
116
117 void M_Golem_Attack_Lightning(entity this)
118 {
119         entity gren;
120
121         monster_makevectors(this, this.enemy);
122
123         gren = new(grenade);
124         gren.owner = gren.realowner = this;
125         gren.bot_dodge = true;
126         gren.bot_dodgerating = (autocvar_g_monster_golem_attack_lightning_damage);
127         set_movetype(gren, MOVETYPE_BOUNCE);
128         PROJECTILE_MAKETRIGGER(gren);
129         gren.projectiledeathtype = DEATH_MONSTER_GOLEM_ZAP.m_id;
130         setorigin(gren, CENTER_OR_VIEWOFS(this));
131         setsize(gren, '-8 -8 -8', '8 8 8');
132         gren.scale = 2.5;
133
134         gren.cnt = time + 5;
135         gren.nextthink = time;
136         setthink(gren, M_Golem_Attack_Lightning_Think);
137         gren.use = M_Golem_Attack_Lightning_Explode_use;
138         settouch(gren, M_Golem_Attack_Lightning_Touch);
139
140         gren.takedamage = DAMAGE_YES;
141         gren.health = 50;
142         gren.damageforcescale = 0;
143         gren.event_damage = M_Golem_Attack_Lightning_Damage;
144         gren.damagedbycontents = true;
145         IL_PUSH(g_damagedbycontents, gren);
146         gren.missile_flags = MIF_SPLASH | MIF_ARC;
147         W_SetupProjVelocity_Explicit(gren, v_forward, v_up, (autocvar_g_monster_golem_attack_lightning_speed), (autocvar_g_monster_golem_attack_lightning_speed_up), 0, 0, false);
148
149         gren.angles = vectoangles (gren.velocity);
150         gren.flags = FL_PROJECTILE;
151         IL_PUSH(g_projectiles, gren);
152         IL_PUSH(g_bot_dodge, gren);
153
154         CSQCProjectile(gren, true, PROJECTILE_GOLEM_LIGHTNING, true);
155 }
156
157 .int state;
158
159 bool M_Golem_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
160 {
161         switch(attack_type)
162         {
163                 case MONSTER_ATTACK_MELEE:
164                 {
165                         int swing_cnt = bound(1, floor(random() * 4), 3);
166                         Monster_Delay(actor, swing_cnt, 0.5, M_Golem_Attack_Swing);
167                         actor.anim_finished = actor.attack_finished_single[0] = time + (0.5 * swing_cnt); // set this for the delay
168                         return true;
169                 }
170                 case MONSTER_ATTACK_RANGED:
171                 {
172                         float randomness = random();
173
174                         if(time >= actor.golem_lastattack) // golem doesn't attack much
175                         if(IS_ONGROUND(actor))
176                         if(randomness <= 0.5 && vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_golem_attack_smash_range))
177                         {
178                                 setanim(actor, actor.anim_melee2, true, true, false);
179                                 Monster_Delay(actor, 1, 0.7, M_Golem_Attack_Smash);
180                                 actor.attack_finished_single[0] = time + 1.1;
181                                 actor.anim_finished = time + 1.1;
182                                 actor.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
183                                 actor.golem_lastattack = time + 3 + random() * 1.5;
184                                 return true;
185                         }
186                         else if(randomness <= 0.1 && vdist(actor.enemy.origin - actor.origin, >=, autocvar_g_monster_golem_attack_smash_range * 1.5)) // small chance, don't want this spammed
187                         {
188                                 setanim(actor, actor.anim_shoot, true, true, false);
189                                 actor.state = MONSTER_ATTACK_MELEE; // maybe we should rename this to something more general
190                                 actor.attack_finished_single[0] = time + 1.1;
191                                 actor.anim_finished = 1.1;
192                                 actor.golem_lastattack = time + 3 + random() * 1.5;
193                                 Monster_Delay(actor, 1, 0.6, M_Golem_Attack_Lightning);
194                                 return true;
195                         }
196
197                         return false;
198                 }
199         }
200
201         return false;
202 }
203
204 spawnfunc(monster_golem) { Monster_Spawn(this, true, MON_GOLEM.monsterid); }
205 // compatibility
206 spawnfunc(monster_shambler) { spawnfunc_monster_golem(this); }
207 #endif // SVQC
208
209 #ifdef SVQC
210 METHOD(Golem, mr_think, bool(Golem this, entity actor))
211 {
212     TC(Golem, this);
213     return true;
214 }
215
216 METHOD(Golem, mr_pain, float(Golem this, entity actor, float damage_take, entity attacker, float deathtype))
217 {
218     TC(Golem, this);
219     actor.pain_finished = time + 0.5;
220     setanim(actor, actor.anim_pain1, true, true, false);
221     return damage_take;
222 }
223
224 METHOD(Golem, mr_death, bool(Golem this, entity actor))
225 {
226     TC(Golem, this);
227     setanim(actor, actor.anim_die1, false, true, true);
228     return true;
229 }
230 #endif
231 #ifdef GAMEQC
232 METHOD(Golem, mr_anim, bool(Golem this, entity actor))
233 {
234     TC(Golem, this);
235     vector none = '0 0 0';
236     actor.anim_idle = animfixfps(actor, '0 1 1', none);
237     actor.anim_walk = animfixfps(actor, '1 1 1', none);
238     actor.anim_run = animfixfps(actor, '2 1 1', none);
239     actor.anim_melee1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
240     actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
241     actor.anim_melee3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
242     //actor.anim_melee4 = animfixfps(actor, '6 1 5', none); // analyze models and set framerate
243     actor.anim_pain1 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
244     actor.anim_pain2 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
245     //actor.anim_pain3 = animfixfps(actor, '9 1 2', none); // 0.5 seconds
246     //actor.anim_pain4 = animfixfps(actor, '10 1 2', none); // 0.5 seconds
247     //actor.anim_pain5 = animfixfps(actor, '11 1 2', none); // 0.5 seconds
248     //actor.anim_sight = animfixfps(actor, '12 1 5', none); // analyze models and set framerate
249     actor.anim_die1 = animfixfps(actor, '13 1 0.5', none); // 2 seconds
250     actor.anim_die2 = animfixfps(actor, '14 1 0.5', none); // 2 seconds
251     //actor.anim_dead = animfixfps(actor, '15 1 0.5', none); // 2 seconds
252     //actor.anim_dieback = animfixfps(actor, '16 1 0.5', none); // 2 seconds
253     //actor.anim_deadback = animfixfps(actor, '17 1 0.5', none); // 2 seconds
254     //actor.anim_dead2 = animfixfps(actor, '18 1 0.5', none); // 2 seconds
255     //actor.anim_dead3 = animfixfps(actor, '19 1 0.5', none); // 2 seconds
256     //actor.anim_dead4 = animfixfps(actor, '20 1 0.5', none); // 2 seconds
257     //actor.anim_dead5 = animfixfps(actor, '21 1 0.5', none); // 2 seconds
258     //actor.anim_dead6 = animfixfps(actor, '22 1 0.5', none); // 2 seconds
259     return true;
260 }
261 #endif
262 #ifdef SVQC
263 .float animstate_endtime;
264 METHOD(Golem, mr_setup, bool(Golem this, entity actor))
265 {
266     TC(Golem, this);
267     if(!actor.health) actor.health = (autocvar_g_monster_golem_health);
268     if(!actor.attack_range) actor.attack_range = 150;
269     if(!actor.speed) { actor.speed = (autocvar_g_monster_golem_speed_walk); }
270     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_golem_speed_run); }
271     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_golem_speed_stop); }
272     if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_golem_damageforcescale); }
273
274     actor.monster_loot = ITEM_HealthMega;
275     actor.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
276
277     setanim(actor, actor.anim_shoot, false, true, true);
278     actor.spawn_time = actor.animstate_endtime;
279     actor.spawnshieldtime = actor.spawn_time;
280     actor.monster_attackfunc = M_Golem_Attack;
281
282     return true;
283 }
284 #endif