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 monster_makevectors(actor, actor.enemy);
16 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MageSpike_FIRE, CH_WEAPON_B, 0, DEATH_MONSTER_MAGE.m_id);
17 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
18 M_Mage_Attack_Spike(actor, w_shotdir);
19 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
22 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
23 M_Mage_Attack_Push(actor);
24 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
28 void M_Mage_Attack_Teleport(entity this, entity targ);
30 CLASS(OffhandMageTeleport, OffhandWeapon)
31 .bool OffhandMageTeleport_key_pressed;
32 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
34 TC(OffhandMageTeleport, this);
35 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
36 M_Mage_Attack_Teleport(player, player.enemy);
37 player.OffhandMageTeleport_key_pressed = key_pressed;
39 ENDCLASS(OffhandMageTeleport)
40 OffhandMageTeleport OFFHAND_MAGE_TELEPORT;
41 STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
43 float autocvar_g_monster_mage_health;
44 float autocvar_g_monster_mage_damageforcescale = 0.5;
45 float autocvar_g_monster_mage_attack_spike_damage;
46 float autocvar_g_monster_mage_attack_spike_radius;
47 float autocvar_g_monster_mage_attack_spike_delay;
48 float autocvar_g_monster_mage_attack_spike_accel;
49 float autocvar_g_monster_mage_attack_spike_decel;
50 float autocvar_g_monster_mage_attack_spike_chance = 0.45;
51 float autocvar_g_monster_mage_attack_spike_turnrate;
52 float autocvar_g_monster_mage_attack_spike_speed_max;
53 float autocvar_g_monster_mage_attack_spike_smart;
54 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
55 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
56 float autocvar_g_monster_mage_attack_spike_smart_mindist;
57 float autocvar_g_monster_mage_attack_push_chance = 0.7;
58 float autocvar_g_monster_mage_attack_push_damage;
59 float autocvar_g_monster_mage_attack_push_radius;
60 float autocvar_g_monster_mage_attack_push_delay;
61 float autocvar_g_monster_mage_attack_push_force;
62 float autocvar_g_monster_mage_attack_teleport_chance = 0.2;
63 float autocvar_g_monster_mage_attack_teleport_delay = 2;
64 float autocvar_g_monster_mage_attack_teleport_random = 0.4;
65 float autocvar_g_monster_mage_attack_teleport_random_range = 1200;
66 float autocvar_g_monster_mage_heal_self;
67 float autocvar_g_monster_mage_heal_allies;
68 float autocvar_g_monster_mage_heal_minhealth;
69 float autocvar_g_monster_mage_heal_range;
70 float autocvar_g_monster_mage_heal_delay;
71 float autocvar_g_monster_mage_shield_time;
72 float autocvar_g_monster_mage_shield_delay;
73 float autocvar_g_monster_mage_shield_blockpercent;
74 float autocvar_g_monster_mage_speed_stop;
75 float autocvar_g_monster_mage_speed_run;
76 float autocvar_g_monster_mage_speed_walk;
79 const float mage_anim_idle = 0;
80 const float mage_anim_walk = 1;
81 const float mage_anim_attack = 2;
82 const float mage_anim_pain = 3;
83 const float mage_anim_death = 4;
84 const float mage_anim_run = 5;
87 void M_Mage_Defend_Heal(entity this);
88 void M_Mage_Defend_Shield(entity this);
91 .float mage_shield_delay;
92 .float mage_shield_time;
94 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
98 if(GetResource(targ, RES_HEALTH) <= 0)
100 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
102 if(STAT(FROZEN, targ))
105 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
106 if(targ.items & ITEM_Shield.m_itemid)
111 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
114 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
115 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
116 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
117 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
118 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
121 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
122 case 3: return (GetResource(targ, RES_HEALTH) > 0);
128 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
130 this.event_damage = func_null;
132 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
134 this.realowner.mage_spike = NULL;
136 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
137 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),
138 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
143 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
145 PROJECTILE_TOUCH(this, toucher);
147 M_Mage_Attack_Spike_Explode(this, toucher);
152 // copied from W_Seeker_Think
153 void M_Mage_Attack_Spike_Think(entity this)
155 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || GetResource(this.owner, RES_HEALTH) <= 0) {
156 this.projectiledeathtype |= HITTYPE_SPLASH;
157 M_Mage_Attack_Spike_Explode(this, NULL);
160 float spd = vlen(this.velocity);
162 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
163 (autocvar_g_monster_mage_attack_spike_speed_max),
164 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
167 if (this.enemy != NULL)
168 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
171 if (this.enemy != NULL)
173 entity e = this.enemy;
174 vector eorg = 0.5 * (e.absmin + e.absmax);
175 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
176 vector desireddir = normalize(eorg - this.origin);
177 vector olddir = normalize(this.velocity); // get my current direction
179 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
180 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
182 // Is it a better idea (shorter distance) to trace to the target itself?
183 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
184 traceline(this.origin, this.origin + olddir * this.wait, false, this);
186 traceline(this.origin, eorg, false, this);
188 // Setup adaptive tracelength
189 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));
191 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
192 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
195 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
196 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
201 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
202 this.nextthink = time;// + 0.05; // csqc projectiles
203 UpdateCSQCProjectile(this);
206 void M_Mage_Attack_Spike(entity this, vector dir)
208 makevectors(this.angles);
210 entity missile = new(M_Mage_Attack_Spike);
211 missile.owner = missile.realowner = this;
212 setthink(missile, M_Mage_Attack_Spike_Think);
213 missile.ltime = time + 7;
214 missile.nextthink = time;
215 missile.solid = SOLID_BBOX;
216 set_movetype(missile, MOVETYPE_FLYMISSILE);
217 missile.flags = FL_PROJECTILE;
218 IL_PUSH(g_projectiles, missile);
219 IL_PUSH(g_bot_dodge, missile);
220 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
221 setsize(missile, '0 0 0', '0 0 0');
222 missile.velocity = dir * 400;
223 missile.avelocity = '300 300 300';
224 missile.enemy = this.enemy;
225 settouch(missile, M_Mage_Attack_Spike_Touch);
227 this.mage_spike = missile;
229 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
232 void M_Mage_Defend_Heal(entity this)
234 bool washealed = false;
236 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
239 entity fx = EFFECT_Null;
246 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
252 if(GetResource(it, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
253 if(GetResource(it, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
254 if(GetResource(it, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
255 if(GetResource(it, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
256 if(GetResource(it, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
258 fx = EFFECT_AMMO_REGEN;
262 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
264 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
265 fx = EFFECT_ARMOR_REPAIR;
269 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
270 TakeResource(it, RES_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
275 Send_Effect(fx, it.origin, '0 0 0', 1);
279 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
280 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
281 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
282 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
288 setanim(this, this.anim_melee, true, true, true);
289 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
290 this.state = MONSTER_ATTACK_MELEE;
291 this.anim_finished = time + 1.5;
295 void M_Mage_Attack_Push(entity this)
297 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
298 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
299 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
300 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
302 setanim(this, this.anim_duckjump, true, true, true);
303 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
304 this.anim_finished = time + 1;
305 this.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
308 void M_Mage_Attack_Teleport(entity this, entity targ)
311 if(vdist(targ.origin - this.origin, >, 1500)) return;
313 if(autocvar_g_monster_mage_attack_teleport_random && random() <= autocvar_g_monster_mage_attack_teleport_random)
315 vector oldpos = this.origin;
316 vector extrasize = '1 1 1' * autocvar_g_monster_mage_attack_teleport_random_range;
317 if(MoveToRandomLocationWithinBounds(this, this.absmin - extrasize, this.absmax + extrasize,
318 DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER,
319 Q3SURFACEFLAG_SKY, 10, 64, 256, true))
321 vector a = vectoangles(targ.origin - this.origin);
322 this.angles = '0 1 0' * a.y;
323 this.fixangle = true;
324 Send_Effect(EFFECT_SPAWN_NEUTRAL, oldpos, '0 0 0', 1);
325 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
326 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
331 if(!IS_ONGROUND(targ)) return;
333 makevectors(targ.angles);
334 tracebox(CENTER_OR_VIEWOFS(targ), this.mins, this.maxs, CENTER_OR_VIEWOFS(targ) + ((v_forward * -1) * 200), MOVE_NOMONSTERS, this);
336 if(trace_fraction < 1)
339 vector newpos = trace_endpos;
341 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
342 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
344 setorigin(this, newpos);
346 vector a = vectoangles(targ.origin - this.origin);
350 this.fixangle = true;
351 this.velocity *= 0.5;
353 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
356 void M_Mage_Defend_Shield_Remove(entity this)
358 this.effects &= ~(EF_ADDITIVE | EF_BLUE);
359 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monsters_armor_blockpercent);
362 void M_Mage_Defend_Shield(entity this)
364 this.effects |= (EF_ADDITIVE | EF_BLUE);
365 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
366 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
367 this.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
368 setanim(this, this.anim_shoot, true, true, true);
369 this.attack_finished_single[0] = time + 1; // give just a short cooldown on attacking
370 this.anim_finished = time + 1;
373 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
377 case MONSTER_ATTACK_MELEE:
379 if(random() <= autocvar_g_monster_mage_attack_push_chance)
381 Weapon wep = WEP_MAGE_SPIKE;
383 wep.wr_think(wep, actor, weaponentity, 2);
389 case MONSTER_ATTACK_RANGED:
391 if(random() <= autocvar_g_monster_mage_attack_teleport_chance)
393 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
394 actor.OffhandMageTeleport_key_pressed = 0;
395 off.offhand_think(off, actor, 1);
398 else if(!actor.mage_spike && random() <= autocvar_g_monster_mage_attack_spike_chance)
400 setanim(actor, actor.anim_shoot, true, true, true);
401 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
402 actor.anim_finished = time + 1;
403 actor.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
404 Weapon wep = WEP_MAGE_SPIKE;
405 wep.wr_think(wep, actor, weaponentity, 1);
416 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
421 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
424 bool need_help = false;
426 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
428 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
429 if(M_Mage_Defend_Heal_Check(actor, it))
438 IL_EACH(g_monsters, it != actor,
440 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
441 if(M_Mage_Defend_Heal_Check(actor, it))
449 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
450 if(time >= actor.attack_finished_single[0])
452 M_Mage_Defend_Heal(actor);
454 if(time >= actor.mage_shield_time && GetResource(actor, RES_ARMOR))
455 M_Mage_Defend_Shield_Remove(actor);
458 if(GetResource(actor, RES_HEALTH) < actor.max_health)
459 if(time >= actor.mage_shield_delay)
461 M_Mage_Defend_Shield(actor);
466 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
472 METHOD(Mage, mr_death, bool(Mage this, entity actor))
475 setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
481 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
484 vector none = '0 0 0';
485 actor.anim_idle = animfixfps(actor, '0 1 1', none);
486 actor.anim_walk = animfixfps(actor, '1 1 1', none);
487 actor.anim_run = animfixfps(actor, '1 1 1', none);
488 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
489 actor.anim_duckjump = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
490 actor.anim_melee = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
491 //actor.anim_fire1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
492 //actor.anim_fire2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
493 //actor.anim_fire3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
494 actor.anim_pain1 = animfixfps(actor, '6 1 2', none); // 0.5 seconds
495 actor.anim_pain2 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
496 //actor.anim_pain3 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
497 actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
498 actor.anim_die2 = animfixfps(actor, '10 1 0.5', none); // 2 seconds
499 //actor.anim_dead1 = animfixfps(actor, '11 1 0.5', none); // 2 seconds
500 //actor.anim_dead2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
506 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
509 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
510 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
511 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
512 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
513 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
515 actor.monster_loot = ITEM_HealthBig;
516 actor.monster_attackfunc = M_Mage_Attack;