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_turnrate;
51 float autocvar_g_monster_mage_attack_spike_speed_max;
52 float autocvar_g_monster_mage_attack_spike_smart;
53 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
54 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
55 float autocvar_g_monster_mage_attack_spike_smart_mindist;
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_heal_self;
61 float autocvar_g_monster_mage_heal_allies;
62 float autocvar_g_monster_mage_heal_minhealth;
63 float autocvar_g_monster_mage_heal_range;
64 float autocvar_g_monster_mage_heal_delay;
65 float autocvar_g_monster_mage_shield_time;
66 float autocvar_g_monster_mage_shield_delay;
67 float autocvar_g_monster_mage_shield_blockpercent;
68 float autocvar_g_monster_mage_speed_stop;
69 float autocvar_g_monster_mage_speed_run;
70 float autocvar_g_monster_mage_speed_walk;
73 const float mage_anim_idle = 0;
74 const float mage_anim_walk = 1;
75 const float mage_anim_attack = 2;
76 const float mage_anim_pain = 3;
77 const float mage_anim_death = 4;
78 const float mage_anim_run = 5;
81 void M_Mage_Defend_Heal(entity this);
82 void M_Mage_Defend_Shield(entity this);
85 .float mage_shield_delay;
87 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
91 if(GetResource(targ, RES_HEALTH) <= 0)
93 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
95 if(STAT(FROZEN, targ))
98 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
99 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
104 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
107 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
108 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
109 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
110 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
111 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
114 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
115 case 3: return (GetResource(targ, RES_HEALTH) > 0);
121 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
123 this.event_damage = func_null;
125 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
127 this.realowner.mage_spike = NULL;
129 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
130 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),
131 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
136 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
138 PROJECTILE_TOUCH(this, toucher);
140 M_Mage_Attack_Spike_Explode(this, toucher);
145 // copied from W_Seeker_Think
146 void M_Mage_Attack_Spike_Think(entity this)
148 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || GetResource(this.owner, RES_HEALTH) <= 0) {
149 this.projectiledeathtype |= HITTYPE_SPLASH;
150 M_Mage_Attack_Spike_Explode(this, NULL);
153 float spd = vlen(this.velocity);
155 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
156 (autocvar_g_monster_mage_attack_spike_speed_max),
157 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
160 if (this.enemy != NULL)
161 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
164 if (this.enemy != NULL)
166 entity e = this.enemy;
167 vector eorg = 0.5 * (e.absmin + e.absmax);
168 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
169 vector desireddir = normalize(eorg - this.origin);
170 vector olddir = normalize(this.velocity); // get my current direction
172 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
173 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
175 // Is it a better idea (shorter distance) to trace to the target itself?
176 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
177 traceline(this.origin, this.origin + olddir * this.wait, false, this);
179 traceline(this.origin, eorg, false, this);
181 // Setup adaptive tracelength
182 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));
184 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
185 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
188 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
189 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
194 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
195 this.nextthink = time;// + 0.05; // csqc projectiles
196 UpdateCSQCProjectile(this);
199 void M_Mage_Attack_Spike(entity this, vector dir)
201 makevectors(this.angles);
203 entity missile = new(M_Mage_Attack_Spike);
204 missile.owner = missile.realowner = this;
205 setthink(missile, M_Mage_Attack_Spike_Think);
206 missile.ltime = time + 7;
207 missile.nextthink = time;
208 missile.solid = SOLID_BBOX;
209 set_movetype(missile, MOVETYPE_FLYMISSILE);
210 missile.flags = FL_PROJECTILE;
211 IL_PUSH(g_projectiles, missile);
212 IL_PUSH(g_bot_dodge, missile);
213 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
214 setsize(missile, '0 0 0', '0 0 0');
215 missile.velocity = dir * 400;
216 missile.avelocity = '300 300 300';
217 missile.enemy = this.enemy;
218 settouch(missile, M_Mage_Attack_Spike_Touch);
220 this.mage_spike = missile;
222 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
225 void M_Mage_Defend_Heal(entity this)
227 float washealed = false;
229 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
232 entity fx = EFFECT_Null;
239 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
245 if(GetResource(this, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
246 if(GetResource(this, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
247 if(GetResource(this, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
248 if(GetResource(this, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
249 if(GetResource(this, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
251 fx = EFFECT_AMMO_REGEN;
255 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
257 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
258 fx = EFFECT_ARMOR_REPAIR;
262 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
263 TakeResource(it, RES_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
268 Send_Effect(fx, it.origin, '0 0 0', 1);
272 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
273 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
274 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
275 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
281 setanim(this, this.anim_shoot, true, true, true);
282 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
283 this.anim_finished = time + 1.5;
287 void M_Mage_Attack_Push(entity this)
289 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
290 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
291 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
292 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
294 setanim(this, this.anim_shoot, true, true, true);
295 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
298 void M_Mage_Attack_Teleport(entity this, entity targ)
301 if(vdist(targ.origin - this.origin, >, 1500)) return;
303 makevectors(targ.angles);
304 tracebox(targ.origin + ((v_forward * -1) * 200), this.mins, this.maxs, this.origin, MOVE_NOMONSTERS, this);
306 if(trace_fraction < 1)
309 vector newpos = targ.origin + ((v_forward * -1) * 200);
311 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
312 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
314 setorigin(this, newpos);
316 vector a = vectoangles(targ.origin - this.origin);
320 this.fixangle = true;
321 this.velocity *= 0.5;
323 this.attack_finished_single[0] = time + 0.2;
326 void M_Mage_Defend_Shield(entity this)
328 StatusEffects_apply(STATUSEFFECT_Shield, this, time + autocvar_g_monster_mage_shield_time, 0);
329 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
330 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
331 setanim(this, this.anim_shoot, true, true, true);
332 this.attack_finished_single[0] = time + 1;
333 this.anim_finished = time + 1;
336 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
340 case MONSTER_ATTACK_MELEE:
344 Weapon wep = WEP_MAGE_SPIKE;
346 wep.wr_think(wep, actor, weaponentity, 2);
352 case MONSTER_ATTACK_RANGED:
354 if(!actor.mage_spike)
358 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
359 off.offhand_think(off, actor, true);
364 setanim(actor, actor.anim_shoot, true, true, true);
365 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
366 actor.anim_finished = time + 1;
367 Weapon wep = WEP_MAGE_SPIKE;
368 wep.wr_think(wep, actor, weaponentity, 1);
383 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
388 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
391 bool need_help = false;
393 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
395 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
396 if(M_Mage_Defend_Heal_Check(actor, it))
405 IL_EACH(g_monsters, it != actor,
407 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
408 if(M_Mage_Defend_Heal_Check(actor, it))
416 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
417 if(time >= actor.attack_finished_single[0])
419 M_Mage_Defend_Heal(actor);
421 if(actor.enemy && time >= actor.mage_shield_delay && random() < 0.5)
422 if(GetResource(actor, RES_HEALTH) < actor.max_health && !StatusEffects_active(STATUSEFFECT_Shield, actor))
423 M_Mage_Defend_Shield(actor);
428 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
434 METHOD(Mage, mr_death, bool(Mage this, entity actor))
437 setanim(actor, actor.anim_die1, false, true, true);
443 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
446 vector none = '0 0 0';
447 actor.anim_die1 = animfixfps(actor, '4 1 0.5', none); // 2 seconds
448 actor.anim_walk = animfixfps(actor, '1 1 1', none);
449 actor.anim_idle = animfixfps(actor, '0 1 1', none);
450 actor.anim_pain1 = animfixfps(actor, '3 1 2', none); // 0.5 seconds
451 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
452 actor.anim_run = animfixfps(actor, '5 1 1', none);
458 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
461 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
462 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
463 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
464 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
465 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
467 actor.monster_loot = ITEM_HealthBig;
468 actor.monster_attackfunc = M_Mage_Attack;