5 SOUND(MageSpike_FIRE, W_Sound("electro_fire"));
6 void M_Mage_Attack_Spike(entity this, vector dir);
7 void M_Mage_Attack_Push(entity this);
8 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, .entity weaponentity, int fire))
10 TC(MageSpike, thiswep);
12 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
13 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
14 actor.enemy = Monster_FindTarget(actor);
15 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MageSpike_FIRE, CH_WEAPON_B, 0, DEATH_MONSTER_MAGE.m_id);
16 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
17 M_Mage_Attack_Spike(actor, w_shotdir);
18 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
21 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
22 M_Mage_Attack_Push(actor);
23 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
27 void M_Mage_Attack_Teleport(entity this, entity targ);
29 CLASS(OffhandMageTeleport, OffhandWeapon)
30 .bool OffhandMageTeleport_key_pressed;
31 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
33 TC(OffhandMageTeleport, this);
34 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
35 M_Mage_Attack_Teleport(player, player.enemy);
36 player.OffhandMageTeleport_key_pressed = key_pressed;
38 ENDCLASS(OffhandMageTeleport)
39 OffhandMageTeleport OFFHAND_MAGE_TELEPORT; STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
41 float autocvar_g_monster_mage_health;
42 float autocvar_g_monster_mage_damageforcescale = 0.5;
43 float autocvar_g_monster_mage_attack_spike_damage;
44 float autocvar_g_monster_mage_attack_spike_radius;
45 float autocvar_g_monster_mage_attack_spike_delay;
46 float autocvar_g_monster_mage_attack_spike_accel;
47 float autocvar_g_monster_mage_attack_spike_decel;
48 float autocvar_g_monster_mage_attack_spike_chance = 0.45;
49 float autocvar_g_monster_mage_attack_spike_turnrate;
50 float autocvar_g_monster_mage_attack_spike_speed_max;
51 float autocvar_g_monster_mage_attack_spike_smart;
52 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
53 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
54 float autocvar_g_monster_mage_attack_spike_smart_mindist;
55 float autocvar_g_monster_mage_attack_push_chance = 0.7;
56 float autocvar_g_monster_mage_attack_push_damage;
57 float autocvar_g_monster_mage_attack_push_radius;
58 float autocvar_g_monster_mage_attack_push_delay;
59 float autocvar_g_monster_mage_attack_push_force;
60 float autocvar_g_monster_mage_attack_teleport_chance = 0.2;
61 float autocvar_g_monster_mage_attack_teleport_delay = 2;
62 float autocvar_g_monster_mage_attack_teleport_random = 0.4;
63 float autocvar_g_monster_mage_attack_teleport_random_range = 1200;
64 float autocvar_g_monster_mage_heal_self;
65 float autocvar_g_monster_mage_heal_allies;
66 float autocvar_g_monster_mage_heal_minhealth;
67 float autocvar_g_monster_mage_heal_range;
68 float autocvar_g_monster_mage_heal_delay;
69 float autocvar_g_monster_mage_shield_time;
70 float autocvar_g_monster_mage_shield_delay;
71 float autocvar_g_monster_mage_shield_blockpercent;
72 float autocvar_g_monster_mage_speed_stop;
73 float autocvar_g_monster_mage_speed_run;
74 float autocvar_g_monster_mage_speed_walk;
77 const float mage_anim_idle = 0;
78 const float mage_anim_walk = 1;
79 const float mage_anim_attack = 2;
80 const float mage_anim_pain = 3;
81 const float mage_anim_death = 4;
82 const float mage_anim_run = 5;
85 void M_Mage_Defend_Heal(entity this);
86 void M_Mage_Defend_Shield(entity this);
89 .float mage_shield_delay;
90 .float mage_shield_time;
92 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
96 if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0)
98 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
100 if(STAT(FROZEN, targ))
103 return (IS_MONSTER(targ) && GetResourceAmount(targ, RESOURCE_HEALTH) < targ.max_health);
104 if(targ.items & ITEM_Shield.m_itemid)
109 case 0: return (GetResourceAmount(targ, RESOURCE_HEALTH) < autocvar_g_balance_health_regenstable);
112 return ((GetResourceAmount(targ, RESOURCE_CELLS) && GetResourceAmount(targ, RESOURCE_CELLS) < g_pickup_cells_max)
113 || (GetResourceAmount(targ, RESOURCE_PLASMA) && GetResourceAmount(targ, RESOURCE_PLASMA) < g_pickup_plasma_max)
114 || (GetResourceAmount(targ, RESOURCE_ROCKETS) && GetResourceAmount(targ, RESOURCE_ROCKETS) < g_pickup_rockets_max)
115 || (GetResourceAmount(targ, RESOURCE_BULLETS) && GetResourceAmount(targ, RESOURCE_BULLETS) < g_pickup_nails_max)
116 || (GetResourceAmount(targ, RESOURCE_SHELLS) && GetResourceAmount(targ, RESOURCE_SHELLS) < g_pickup_shells_max)
119 case 2: return (GetResourceAmount(targ, RESOURCE_ARMOR) < autocvar_g_balance_armor_regenstable);
120 case 3: return (GetResourceAmount(targ, RESOURCE_HEALTH) > 0);
126 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
128 this.event_damage = func_null;
130 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
132 this.realowner.mage_spike = NULL;
134 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
135 RadiusDamage (this, this.realowner, (autocvar_g_monster_mage_attack_spike_damage), (autocvar_g_monster_mage_attack_spike_damage) * 0.5, (autocvar_g_monster_mage_attack_spike_radius),
136 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
141 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
143 PROJECTILE_TOUCH(this, toucher);
145 M_Mage_Attack_Spike_Explode(this, toucher);
150 // copied from W_Seeker_Think
151 void M_Mage_Attack_Spike_Think(entity this)
153 if (time > this.ltime || (this.enemy && GetResourceAmount(this.enemy, RESOURCE_HEALTH) <= 0) || GetResourceAmount(this.owner, RESOURCE_HEALTH) <= 0) {
154 this.projectiledeathtype |= HITTYPE_SPLASH;
155 M_Mage_Attack_Spike_Explode(this, NULL);
158 float spd = vlen(this.velocity);
160 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
161 (autocvar_g_monster_mage_attack_spike_speed_max),
162 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
165 if (this.enemy != NULL)
166 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
169 if (this.enemy != NULL)
171 entity e = this.enemy;
172 vector eorg = 0.5 * (e.absmin + e.absmax);
173 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
174 vector desireddir = normalize(eorg - this.origin);
175 vector olddir = normalize(this.velocity); // get my current direction
177 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
178 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
180 // Is it a better idea (shorter distance) to trace to the target itself?
181 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
182 traceline(this.origin, this.origin + olddir * this.wait, false, this);
184 traceline(this.origin, eorg, false, this);
186 // Setup adaptive tracelength
187 this.wait = bound((autocvar_g_monster_mage_attack_spike_smart_trace_min), vlen(this.origin - trace_endpos), this.wait = (autocvar_g_monster_mage_attack_spike_smart_trace_max));
189 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
190 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
193 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
194 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
199 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
200 this.nextthink = time;// + 0.05; // csqc projectiles
201 UpdateCSQCProjectile(this);
204 void M_Mage_Attack_Spike(entity this, vector dir)
206 makevectors(this.angles);
208 entity missile = spawn();
209 missile.owner = missile.realowner = this;
210 setthink(missile, M_Mage_Attack_Spike_Think);
211 missile.ltime = time + 7;
212 missile.nextthink = time;
213 missile.solid = SOLID_BBOX;
214 set_movetype(missile, MOVETYPE_FLYMISSILE);
215 missile.flags = FL_PROJECTILE;
216 IL_PUSH(g_projectiles, missile);
217 IL_PUSH(g_bot_dodge, missile);
218 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
219 setsize(missile, '0 0 0', '0 0 0');
220 missile.velocity = dir * 400;
221 missile.avelocity = '300 300 300';
222 missile.enemy = this.enemy;
223 settouch(missile, M_Mage_Attack_Spike_Touch);
225 this.mage_spike = missile;
227 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
230 void M_Mage_Defend_Heal(entity this)
232 bool washealed = false;
234 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
237 entity fx = EFFECT_Null;
244 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
250 if(GetResourceAmount(it, RESOURCE_CELLS)) GiveResourceWithLimit(it, RESOURCE_CELLS, 1, g_pickup_cells_max);
251 if(GetResourceAmount(it, RESOURCE_PLASMA)) GiveResourceWithLimit(it, RESOURCE_PLASMA, 1, g_pickup_plasma_max);
252 if(GetResourceAmount(it, RESOURCE_ROCKETS)) GiveResourceWithLimit(it, RESOURCE_ROCKETS, 1, g_pickup_rockets_max);
253 if(GetResourceAmount(it, RESOURCE_SHELLS)) GiveResourceWithLimit(it, RESOURCE_SHELLS, 2, g_pickup_shells_max);
254 if(GetResourceAmount(it, RESOURCE_BULLETS)) GiveResourceWithLimit(it, RESOURCE_BULLETS, 5, g_pickup_nails_max);
256 fx = EFFECT_AMMO_REGEN;
260 if(GetResourceAmount(it, RESOURCE_ARMOR) < autocvar_g_balance_armor_regenstable)
262 GiveResourceWithLimit(it, RESOURCE_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
263 fx = EFFECT_ARMOR_REPAIR;
267 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
268 TakeResource(it, RESOURCE_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
273 Send_Effect(fx, it.origin, '0 0 0', 1);
277 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
278 Heal(it, this, autocvar_g_monster_mage_heal_allies, RESOURCE_LIMIT_NONE);
279 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
280 WaypointSprite_UpdateHealth(it.sprite, GetResourceAmount(it, RESOURCE_HEALTH));
286 setanim(this, this.anim_melee, true, true, true);
287 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
288 this.state = MONSTER_ATTACK_MELEE;
289 this.anim_finished = time + 1.5;
293 void M_Mage_Attack_Push(entity this)
295 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
296 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
297 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
298 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
300 setanim(this, this.anim_duckjump, true, true, true);
301 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
302 this.anim_finished = time + 1;
303 this.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
306 void M_Mage_Attack_Teleport(entity this, entity targ)
309 if(vdist(targ.origin - this.origin, >, 1500)) return;
311 if(autocvar_g_monster_mage_attack_teleport_random && random() <= autocvar_g_monster_mage_attack_teleport_random)
313 vector oldpos = this.origin;
314 vector extrasize = '1 1 1' * autocvar_g_monster_mage_attack_teleport_random_range;
315 if(MoveToRandomLocationWithinBounds(this, this.absmin - extrasize, this.absmax + extrasize,
316 DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER,
317 Q3SURFACEFLAG_SKY, 10, 64, 256, true))
319 vector a = vectoangles(targ.origin - this.origin);
320 this.angles = '0 1 0' * a.y;
321 this.fixangle = true;
322 Send_Effect(EFFECT_SPAWN_NEUTRAL, oldpos, '0 0 0', 1);
323 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
324 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
329 if(!IS_ONGROUND(targ)) return;
331 makevectors(targ.angles);
332 tracebox(CENTER_OR_VIEWOFS(targ), this.mins, this.maxs, CENTER_OR_VIEWOFS(targ) + ((v_forward * -1) * 200), MOVE_NOMONSTERS, this);
334 if(trace_fraction < 1)
337 vector newpos = trace_endpos;
339 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
340 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
342 setorigin(this, newpos);
344 vector a = vectoangles(targ.origin - this.origin);
348 this.fixangle = true;
349 this.velocity *= 0.5;
351 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
354 void M_Mage_Defend_Shield_Remove(entity this)
356 this.effects &= ~(EF_ADDITIVE | EF_BLUE);
357 SetResourceAmountExplicit(this, RESOURCE_ARMOR, autocvar_g_monsters_armor_blockpercent);
360 void M_Mage_Defend_Shield(entity this)
362 this.effects |= (EF_ADDITIVE | EF_BLUE);
363 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
364 SetResourceAmountExplicit(this, RESOURCE_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
365 this.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
366 setanim(this, this.anim_shoot, true, true, true);
367 this.attack_finished_single[0] = time + 1; // give just a short cooldown on attacking
368 this.anim_finished = time + 1;
371 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
375 case MONSTER_ATTACK_MELEE:
377 if(random() <= autocvar_g_monster_mage_attack_push_chance)
379 Weapon wep = WEP_MAGE_SPIKE;
381 wep.wr_think(wep, actor, weaponentity, 2);
387 case MONSTER_ATTACK_RANGED:
389 if(random() <= autocvar_g_monster_mage_attack_teleport_chance)
391 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
392 actor.OffhandMageTeleport_key_pressed = 0;
393 off.offhand_think(off, actor, 1);
396 else if(!actor.mage_spike && random() <= autocvar_g_monster_mage_attack_spike_chance)
398 setanim(actor, actor.anim_shoot, true, true, true);
399 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
400 actor.anim_finished = time + 1;
401 actor.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
402 Weapon wep = WEP_MAGE_SPIKE;
403 wep.wr_think(wep, actor, weaponentity, 1);
414 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE.monsterid); }
419 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
422 bool need_help = false;
424 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
426 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
427 if(M_Mage_Defend_Heal_Check(actor, it))
436 IL_EACH(g_monsters, it != actor,
438 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
439 if(M_Mage_Defend_Heal_Check(actor, it))
447 if(GetResourceAmount(actor, RESOURCE_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
448 if(time >= actor.attack_finished_single[0])
450 M_Mage_Defend_Heal(actor);
452 if(time >= actor.mage_shield_time && GetResourceAmount(actor, RESOURCE_ARMOR))
453 M_Mage_Defend_Shield_Remove(actor);
456 if(GetResourceAmount(actor, RESOURCE_HEALTH) < actor.max_health)
457 if(time >= actor.mage_shield_delay)
459 M_Mage_Defend_Shield(actor);
464 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
470 METHOD(Mage, mr_death, bool(Mage this, entity actor))
473 setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
479 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
482 vector none = '0 0 0';
483 actor.anim_idle = animfixfps(actor, '0 1 1', none);
484 actor.anim_walk = animfixfps(actor, '1 1 1', none);
485 actor.anim_run = animfixfps(actor, '1 1 1', none);
486 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
487 actor.anim_duckjump = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
488 actor.anim_melee = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
489 //actor.anim_fire1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
490 //actor.anim_fire2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
491 //actor.anim_fire3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
492 actor.anim_pain1 = animfixfps(actor, '6 1 2', none); // 0.5 seconds
493 actor.anim_pain2 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
494 //actor.anim_pain3 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
495 actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
496 actor.anim_die2 = animfixfps(actor, '10 1 0.5', none); // 2 seconds
497 //actor.anim_dead1 = animfixfps(actor, '11 1 0.5', none); // 2 seconds
498 //actor.anim_dead2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
504 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
507 if(!GetResourceAmount(this, RESOURCE_HEALTH)) SetResourceAmountExplicit(actor, RESOURCE_HEALTH, autocvar_g_monster_mage_health);
508 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
509 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
510 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
511 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
513 actor.monster_loot = ITEM_HealthBig;
514 actor.monster_attackfunc = M_Mage_Attack;