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