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;
86 .float mage_shield_time;
88 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
92 if(GetResource(targ, RES_HEALTH) <= 0)
94 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
96 if(STAT(FROZEN, targ))
99 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
100 if(targ.items & ITEM_Shield.m_itemid)
105 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
108 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
109 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
110 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
111 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
112 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
115 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
116 case 3: return (GetResource(targ, RES_HEALTH) > 0);
122 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
124 this.event_damage = func_null;
126 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
128 this.realowner.mage_spike = NULL;
130 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
131 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),
132 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
137 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
139 PROJECTILE_TOUCH(this, toucher);
141 M_Mage_Attack_Spike_Explode(this, toucher);
146 // copied from W_Seeker_Think
147 void M_Mage_Attack_Spike_Think(entity this)
149 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || GetResource(this.owner, RES_HEALTH) <= 0) {
150 this.projectiledeathtype |= HITTYPE_SPLASH;
151 M_Mage_Attack_Spike_Explode(this, NULL);
154 float spd = vlen(this.velocity);
156 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
157 (autocvar_g_monster_mage_attack_spike_speed_max),
158 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
161 if (this.enemy != NULL)
162 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
165 if (this.enemy != NULL)
167 entity e = this.enemy;
168 vector eorg = 0.5 * (e.absmin + e.absmax);
169 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
170 vector desireddir = normalize(eorg - this.origin);
171 vector olddir = normalize(this.velocity); // get my current direction
173 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
174 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
176 // Is it a better idea (shorter distance) to trace to the target itself?
177 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
178 traceline(this.origin, this.origin + olddir * this.wait, false, this);
180 traceline(this.origin, eorg, false, this);
182 // Setup adaptive tracelength
183 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));
185 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
186 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
189 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
190 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
195 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
196 this.nextthink = time;// + 0.05; // csqc projectiles
197 UpdateCSQCProjectile(this);
200 void M_Mage_Attack_Spike(entity this, vector dir)
202 makevectors(this.angles);
204 entity missile = new(M_Mage_Attack_Spike);
205 missile.owner = missile.realowner = this;
206 setthink(missile, M_Mage_Attack_Spike_Think);
207 missile.ltime = time + 7;
208 missile.nextthink = time;
209 missile.solid = SOLID_BBOX;
210 set_movetype(missile, MOVETYPE_FLYMISSILE);
211 missile.flags = FL_PROJECTILE;
212 IL_PUSH(g_projectiles, missile);
213 IL_PUSH(g_bot_dodge, missile);
214 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
215 setsize(missile, '0 0 0', '0 0 0');
216 missile.velocity = dir * 400;
217 missile.avelocity = '300 300 300';
218 missile.enemy = this.enemy;
219 settouch(missile, M_Mage_Attack_Spike_Touch);
221 this.mage_spike = missile;
223 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
226 void M_Mage_Defend_Heal(entity this)
228 float washealed = false;
230 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
233 entity fx = EFFECT_Null;
240 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
246 if(GetResource(this, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
247 if(GetResource(this, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
248 if(GetResource(this, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
249 if(GetResource(this, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
250 if(GetResource(this, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
252 fx = EFFECT_AMMO_REGEN;
256 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
258 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
259 fx = EFFECT_ARMOR_REPAIR;
263 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
264 TakeResource(it, RES_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
269 Send_Effect(fx, it.origin, '0 0 0', 1);
273 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
274 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
275 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
276 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
282 setanim(this, this.anim_shoot, true, true, true);
283 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
284 this.anim_finished = time + 1.5;
288 void M_Mage_Attack_Push(entity this)
290 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
291 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
292 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
293 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
295 setanim(this, this.anim_shoot, true, true, true);
296 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
299 void M_Mage_Attack_Teleport(entity this, entity targ)
302 if(vdist(targ.origin - this.origin, >, 1500)) return;
304 makevectors(targ.angles);
305 tracebox(targ.origin + ((v_forward * -1) * 200), this.mins, this.maxs, this.origin, MOVE_NOMONSTERS, this);
307 if(trace_fraction < 1)
310 vector newpos = targ.origin + ((v_forward * -1) * 200);
312 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
313 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
315 setorigin(this, newpos);
317 vector a = vectoangles(targ.origin - this.origin);
321 this.fixangle = true;
322 this.velocity *= 0.5;
324 this.attack_finished_single[0] = time + 0.2;
327 void M_Mage_Defend_Shield_Remove(entity this)
329 this.effects &= ~(EF_ADDITIVE | EF_BLUE);
330 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monsters_armor_blockpercent);
333 void M_Mage_Defend_Shield(entity this)
335 this.effects |= (EF_ADDITIVE | EF_BLUE);
336 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
337 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
338 this.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
339 setanim(this, this.anim_shoot, true, true, true);
340 this.attack_finished_single[0] = time + 1;
341 this.anim_finished = time + 1;
344 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
348 case MONSTER_ATTACK_MELEE:
352 Weapon wep = WEP_MAGE_SPIKE;
354 wep.wr_think(wep, actor, weaponentity, 2);
360 case MONSTER_ATTACK_RANGED:
362 if(!actor.mage_spike)
366 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
367 off.offhand_think(off, actor, true);
372 setanim(actor, actor.anim_shoot, true, true, true);
373 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
374 actor.anim_finished = time + 1;
375 Weapon wep = WEP_MAGE_SPIKE;
376 wep.wr_think(wep, actor, weaponentity, 1);
391 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
396 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
399 bool need_help = false;
401 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
403 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
404 if(M_Mage_Defend_Heal_Check(actor, it))
413 IL_EACH(g_monsters, it != actor,
415 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
416 if(M_Mage_Defend_Heal_Check(actor, it))
424 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
425 if(time >= actor.attack_finished_single[0])
427 M_Mage_Defend_Heal(actor);
429 if(time >= actor.mage_shield_time && GetResource(actor, RES_ARMOR))
430 M_Mage_Defend_Shield_Remove(actor);
433 if(GetResource(actor, RES_HEALTH) < actor.max_health)
434 if(time >= actor.mage_shield_delay)
436 M_Mage_Defend_Shield(actor);
441 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
447 METHOD(Mage, mr_death, bool(Mage this, entity actor))
450 setanim(actor, actor.anim_die1, false, true, true);
456 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
459 vector none = '0 0 0';
460 actor.anim_die1 = animfixfps(actor, '4 1 0.5', none); // 2 seconds
461 actor.anim_walk = animfixfps(actor, '1 1 1', none);
462 actor.anim_idle = animfixfps(actor, '0 1 1', none);
463 actor.anim_pain1 = animfixfps(actor, '3 1 2', none); // 0.5 seconds
464 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
465 actor.anim_run = animfixfps(actor, '5 1 1', none);
471 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
474 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
475 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
476 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
477 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
478 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
480 actor.monster_loot = ITEM_HealthBig;
481 actor.monster_attackfunc = M_Mage_Attack;