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