Xonotic
shambler.qc
Go to the documentation of this file.
1 #include "shambler.qh"
2 
3 #ifdef SVQC
4 float autocvar_g_monster_shambler_health;
5 float autocvar_g_monster_shambler_damageforcescale = 0.1;
6 float autocvar_g_monster_shambler_attack_smash_damage;
7 float autocvar_g_monster_shambler_attack_smash_range;
8 float autocvar_g_monster_shambler_attack_claw_damage;
9 float autocvar_g_monster_shambler_attack_lightning_damage;
10 float autocvar_g_monster_shambler_attack_lightning_damage_zap = 15;
11 float autocvar_g_monster_shambler_attack_lightning_force;
12 float autocvar_g_monster_shambler_attack_lightning_radius;
13 float autocvar_g_monster_shambler_attack_lightning_radius_zap;
14 float autocvar_g_monster_shambler_attack_lightning_speed;
15 float autocvar_g_monster_shambler_attack_lightning_speed_up;
16 float autocvar_g_monster_shambler_speed_stop;
17 float autocvar_g_monster_shambler_speed_run;
18 float autocvar_g_monster_shambler_speed_walk;
19 
20 /*
21 const float shambler_anim_stand = 0;
22 const float shambler_anim_walk = 1;
23 const float shambler_anim_run = 2;
24 const float shambler_anim_smash = 3;
25 const float shambler_anim_swingr = 4;
26 const float shambler_anim_swingl = 5;
27 const float shambler_anim_magic = 6;
28 const float shambler_anim_pain = 7;
29 const float shambler_anim_death = 8;
30 */
31 
32 .float shambler_lastattack; // delay attacks separately
33 
34 void M_Shambler_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_shambler_attack_smash_range, MOVE_NORMAL, this);
43 
44  if(trace_ent.takedamage)
45  Damage(trace_ent, this, this, (autocvar_g_monster_shambler_attack_smash_damage) * MONSTER_SKILLMOD(this), DEATH_MONSTER_SHAMBLER_SMASH.m_id, DMG_NOWEP, trace_ent.origin, normalize(trace_ent.origin - this.origin));
46 }
47 
48 void M_Shambler_Attack_Swing(entity this)
49 {
50  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);
51 }
52 
54 
55 void M_Shambler_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;
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_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_damage), (autocvar_g_monster_shambler_attack_lightning_radius),
69  NULL, NULL, (autocvar_g_monster_shambler_attack_lightning_force), this.projectiledeathtype, DMG_NOWEP, directhitentity);
70 
71  FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_shambler_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_shambler_attack_lightning_damage_zap) * MONSTER_SKILLMOD(this), DEATH_MONSTER_SHAMBLER_ZAP.m_id, DMG_NOWEP, it.origin, '0 0 0');
75  });
76 
77  setthink(this, SUB_Remove);
78  this.nextthink = time + 0.2;
79 }
80 
81 void M_Shambler_Attack_Lightning_Explode_use(entity this, entity actor, entity trigger)
82 {
83  M_Shambler_Attack_Lightning_Explode(this, trigger);
84 }
85 
86 void M_Shambler_Attack_Lightning_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
87 {
88  if (GetResource(this, RES_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  TakeResource(this, RES_HEALTH, damage);
95 
96  if (GetResource(this, RES_HEALTH) <= 0)
97  W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
98 }
99 
100 void M_Shambler_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_Shambler_Attack_Lightning_Think(entity this)
108 {
109  this.nextthink = time;
110  if (time > this.cnt)
111  {
112  M_Shambler_Attack_Lightning_Explode(this, NULL);
113  return;
114  }
115 }
116 
117 void M_Shambler_Attack_Lightning(entity this)
118 {
119  entity gren = new(grenade);
120  gren.owner = gren.realowner = this;
121  gren.bot_dodge = true;
122  gren.bot_dodgerating = (autocvar_g_monster_shambler_attack_lightning_damage);
125  gren.projectiledeathtype = DEATH_MONSTER_SHAMBLER_ZAP.m_id;
126  setorigin(gren, CENTER_OR_VIEWOFS(this));
127  setsize(gren, '-8 -8 -8', '8 8 8');
128  gren.scale = 2.5;
129 
130  gren.cnt = time + 5;
131  gren.nextthink = time;
132  setthink(gren, M_Shambler_Attack_Lightning_Think);
133  gren.use = M_Shambler_Attack_Lightning_Explode_use;
134  settouch(gren, M_Shambler_Attack_Lightning_Touch);
135 
136  gren.takedamage = DAMAGE_YES;
137  SetResourceExplicit(gren, RES_HEALTH, 50);
138  gren.damageforcescale = 0;
139  gren.event_damage = M_Shambler_Attack_Lightning_Damage;
140  gren.damagedbycontents = true;
142  gren.missile_flags = MIF_SPLASH | MIF_ARC;
143  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);
144 
145  gren.angles = vectoangles (gren.velocity);
146  gren.flags = FL_PROJECTILE;
147  IL_PUSH(g_projectiles, gren);
148  IL_PUSH(g_bot_dodge, gren);
149 
151 }
152 
153 .int state;
154 
155 bool M_Shambler_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
156 {
157  switch(attack_type)
158  {
160  {
161  int swing_cnt = bound(1, floor(random() * 4), 3);
162  Monster_Delay(actor, swing_cnt, 0.5, M_Shambler_Attack_Swing);
163  actor.anim_finished = actor.attack_finished_single[0] = time + (0.5 * swing_cnt); // set this for the delay
164  return true;
165  }
167  {
168  float randomness = random();
169 
170  if(time >= actor.shambler_lastattack) // shambler doesn't attack much
171  if(IS_ONGROUND(actor))
172  if(randomness <= 0.5 && vdist(actor.enemy.origin - actor.origin, <=, autocvar_g_monster_shambler_attack_smash_range))
173  {
174  setanim(actor, actor.anim_melee2, true, true, false);
175  Monster_Delay(actor, 1, 0.7, M_Shambler_Attack_Smash);
176  actor.attack_finished_single[0] = time + 1.1;
177  actor.anim_finished = time + 1.1;
178  actor.state = MONSTER_ATTACK_MELEE; // kinda a melee attack
179  actor.shambler_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_shambler_attack_smash_range * 1.5)) // small chance, don't want this spammed
183  {
184  setanim(actor, actor.anim_shoot, 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.shambler_lastattack = time + 3 + random() * 1.5;
189  Monster_Delay(actor, 1, 0.6, M_Shambler_Attack_Lightning);
190  return true;
191  }
192 
193  return false;
194  }
195  }
196 
197  return false;
198 }
199 
200 spawnfunc(monster_shambler) { Monster_Spawn(this, true, MON_SHAMBLER); }
201 #endif // SVQC
202 
203 #ifdef SVQC
204 METHOD(Shambler, mr_think, bool(Shambler this, entity actor))
205 {
206  TC(Shambler, this);
207  return true;
208 }
209 
210 METHOD(Shambler, mr_pain, float(Shambler this, entity actor, float damage_take, entity attacker, float deathtype))
211 {
212  TC(Shambler, this);
213  actor.pain_finished = time + 0.5;
214  setanim(actor, actor.anim_pain1, true, true, false);
215  return damage_take;
216 }
217 
218 METHOD(Shambler, mr_death, bool(Shambler this, entity actor))
219 {
220  TC(Shambler, this);
221  setanim(actor, actor.anim_die1, false, true, true);
222  return true;
223 }
224 #endif
225 #ifdef GAMEQC
226 METHOD(Shambler, mr_anim, bool(Shambler this, entity actor))
227 {
228  TC(Shambler, this);
229  vector none = '0 0 0';
230  actor.anim_die1 = animfixfps(actor, '8 1 0.5', none); // 2 seconds
231  actor.anim_walk = animfixfps(actor, '1 1 1', none);
232  actor.anim_idle = animfixfps(actor, '0 1 1', none);
233  actor.anim_pain1 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
234  actor.anim_melee1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
235  actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
236  actor.anim_melee3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
237  actor.anim_shoot = animfixfps(actor, '6 1 5', none); // analyze models and set framerate
238  actor.anim_run = animfixfps(actor, '2 1 1', none);
239  return true;
240 }
241 #endif
242 #ifdef SVQC
243 .float animstate_endtime;
244 METHOD(Shambler, mr_setup, bool(Shambler this, entity actor))
245 {
246  TC(Shambler, this);
247  if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_shambler_health);
248  if(!actor.attack_range) actor.attack_range = 150;
249  if(!actor.speed) { actor.speed = (autocvar_g_monster_shambler_speed_walk); }
250  if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_shambler_speed_run); }
251  if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_shambler_speed_stop); }
252  if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_shambler_damageforcescale); }
253 
254  actor.monster_loot = ITEM_HealthMega;
255  actor.weapon = WEP_ELECTRO.m_id; // matches attacks better than WEP_VORTEX
256 
257  setanim(actor, actor.anim_shoot, false, true, true);
258  actor.spawn_time = actor.animstate_endtime;
259  StatusEffects_apply(STATUSEFFECT_SpawnShield, actor, actor.spawn_time, 0);
260  actor.monster_attackfunc = M_Shambler_Attack;
261 
262  return true;
263 }
264 #endif
float state
Definition: subs.qh:32
float MOVETYPE_NONE
Definition: progsdefs.qc:246
float animstate_endtime
Definition: anim.qh:38
#define PROJECTILE_MAKETRIGGER(e)
Definition: common.qh:29
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
const int MIF_ARC
Definition: common.qh:35
#define setanim(...)
Definition: anim.qh:45
const int MIF_SPLASH
Definition: common.qh:34
bool Monster_Attack_Melee(entity this, entity targ, float damg, vector anim, float er, float animtime, int deathtype, bool dostop)
Definition: sv_monsters.qc:362
float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
Definition: common.qc:49
IntrusiveList g_damagedbycontents
Definition: damage.qh:155
entity() spawn
const float MOVE_NORMAL
Definition: csprogsdefs.qc:252
void Monster_Delay(entity this, int repeat_count, float defer_amnt, void(entity) func)
Definition: sv_monsters.qc:218
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
vector maxs
Definition: csprogsdefs.qc:113
vector anim_melee3
Definition: monster.qh:27
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
origin
Definition: ent_cs.qc:114
vector oldvelocity
Definition: main.qh:38
float MOVETYPE_BOUNCE
Definition: progsdefs.qc:256
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
#define DMG_NOWEP
Definition: damage.qh:126
float move_movetype
Definition: movetypes.qh:76
IntrusiveList g_bot_dodge
Definition: api.qh:150
entity trace_ent
Definition: csprogsdefs.qc:40
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
Definition: cl_resources.qc:31
#define PROJECTILE_TOUCH(e, t)
Definition: common.qh:27
RES_HEALTH
Definition: ent_cs.qc:126
void W_SetupProjVelocity_Explicit(entity proj, vector dir, vector upDir, float pSpeed, float pUpSpeed, float pZSpeed, float spread, float forceAbsolute)
Definition: tracing.qc:185
entity enemy
Definition: sv_ctf.qh:143
vector mins
Definition: csprogsdefs.qc:113
float cnt
Definition: powerups.qc:24
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
const int PROJECTILE_SHAMBLER_LIGHTNING
Definition: projectiles.qh:35
#define MONSTER_SKILLMOD(mon)
Definition: sv_monsters.qh:59
vector v_up
Definition: csprogsdefs.qc:31
void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
Definition: common.qc:91
const int MONSTER_ATTACK_MELEE
Definition: sv_monsters.qh:70
#define NULL
Definition: post.qh:17
const float VOL_BASE
Definition: sound.qh:36
#define TC(T, sym)
Definition: _all.inc:82
const int MONSTER_ATTACK_RANGED
Definition: sv_monsters.qh:71
float takedamage
Definition: progsdefs.qc:147
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition: damage.qc:583
const float ATTEN_NORM
Definition: sound.qh:30
float nextthink
Definition: csprogsdefs.qc:121
const int CH_SHOTS
Definition: sound.qh:14
#define CENTER_OR_VIEWOFS(ent)
Definition: utils.qh:28
vector(float skel, float bonenum) _skel_get_boneabs_hidden
IntrusiveList g_projectiles
Definition: common.qh:46
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
bool Monster_Spawn(entity this, bool check_appear, Monster mon)
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype,.entity weaponentity, entity directhitentity)
Definition: damage.qc:1057
entity realowner
Definition: common.qh:25
setorigin(ent, v)
#define setthink(e, f)
vector angles
Definition: csprogsdefs.qc:104
#define use
Definition: csprogsdefs.qh:50
#define sound(e, c, s, v, a)
Definition: sound.qh:52
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
#define makevectors
Definition: post.qh:21
float attack_range
Definition: sv_monsters.qh:43
float DAMAGE_NO
Definition: progsdefs.qc:282
void set_movetype(entity this, int mt)
var void func_null()
vector anim_melee2
Definition: monster.qh:26
vector v_forward
Definition: csprogsdefs.qc:31
float DAMAGE_YES
Definition: progsdefs.qc:283
int projectiledeathtype
Definition: common.qh:20