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);
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_turnrate;
49 float autocvar_g_monster_mage_attack_spike_speed_max;
50 float autocvar_g_monster_mage_attack_spike_smart;
51 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
52 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
53 float autocvar_g_monster_mage_attack_spike_smart_mindist;
54 float autocvar_g_monster_mage_attack_push_damage;
55 float autocvar_g_monster_mage_attack_push_radius;
56 float autocvar_g_monster_mage_attack_push_delay;
57 float autocvar_g_monster_mage_attack_push_force;
58 float autocvar_g_monster_mage_heal_self;
59 float autocvar_g_monster_mage_heal_allies;
60 float autocvar_g_monster_mage_heal_minhealth;
61 float autocvar_g_monster_mage_heal_range;
62 float autocvar_g_monster_mage_heal_delay;
63 float autocvar_g_monster_mage_shield_time;
64 float autocvar_g_monster_mage_shield_delay;
65 float autocvar_g_monster_mage_shield_blockpercent;
66 float autocvar_g_monster_mage_speed_stop;
67 float autocvar_g_monster_mage_speed_run;
68 float autocvar_g_monster_mage_speed_walk;
71 const float mage_anim_idle = 0;
72 const float mage_anim_walk = 1;
73 const float mage_anim_attack = 2;
74 const float mage_anim_pain = 3;
75 const float mage_anim_death = 4;
76 const float mage_anim_run = 5;
79 void M_Mage_Defend_Heal(entity this);
80 void M_Mage_Defend_Shield(entity this);
83 .float mage_shield_delay;
84 .float mage_shield_time;
86 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
92 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
94 if(STAT(FROZEN, targ))
97 return (IS_MONSTER(targ) && targ.health < targ.max_health);
98 if(targ.items & ITEM_Shield.m_itemid)
103 case 0: return (targ.health < autocvar_g_balance_health_regenstable);
104 case 1: return ((targ.ammo_cells && targ.ammo_cells < g_pickup_cells_max) || (targ.ammo_plasma && targ.ammo_plasma < g_pickup_plasma_max) || (targ.ammo_rockets && targ.ammo_rockets < g_pickup_rockets_max) || (targ.ammo_nails && targ.ammo_nails < g_pickup_nails_max) || (targ.ammo_shells && targ.ammo_shells < g_pickup_shells_max));
105 case 2: return (targ.armorvalue < autocvar_g_balance_armor_regenstable);
106 case 3: return (targ.health > 0);
112 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
114 this.event_damage = func_null;
116 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
118 this.realowner.mage_spike = NULL;
120 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
121 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),
122 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
127 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
129 PROJECTILE_TOUCH(this, toucher);
131 M_Mage_Attack_Spike_Explode(this, toucher);
136 // copied from W_Seeker_Think
137 void M_Mage_Attack_Spike_Think(entity this)
139 if (time > this.ltime || (this.enemy && this.enemy.health <= 0) || this.owner.health <= 0) {
140 this.projectiledeathtype |= HITTYPE_SPLASH;
141 M_Mage_Attack_Spike_Explode(this, NULL);
144 float spd = vlen(this.velocity);
146 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
147 (autocvar_g_monster_mage_attack_spike_speed_max),
148 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
151 if (this.enemy != NULL)
152 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
155 if (this.enemy != NULL)
157 entity e = this.enemy;
158 vector eorg = 0.5 * (e.absmin + e.absmax);
159 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
160 vector desireddir = normalize(eorg - this.origin);
161 vector olddir = normalize(this.velocity); // get my current direction
163 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
164 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
166 // Is it a better idea (shorter distance) to trace to the target itself?
167 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
168 traceline(this.origin, this.origin + olddir * this.wait, false, this);
170 traceline(this.origin, eorg, false, this);
172 // Setup adaptive tracelength
173 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));
175 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
176 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
179 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
180 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
185 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
186 this.nextthink = time;// + 0.05; // csqc projectiles
187 UpdateCSQCProjectile(this);
190 void M_Mage_Attack_Spike(entity this, vector dir)
192 makevectors(this.angles);
194 entity missile = spawn();
195 missile.owner = missile.realowner = this;
196 setthink(missile, M_Mage_Attack_Spike_Think);
197 missile.ltime = time + 7;
198 missile.nextthink = time;
199 missile.solid = SOLID_BBOX;
200 set_movetype(missile, MOVETYPE_FLYMISSILE);
201 missile.flags = FL_PROJECTILE;
202 IL_PUSH(g_projectiles, missile);
203 IL_PUSH(g_bot_dodge, missile);
204 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
205 setsize(missile, '0 0 0', '0 0 0');
206 missile.velocity = dir * 400;
207 missile.avelocity = '300 300 300';
208 missile.enemy = this.enemy;
209 settouch(missile, M_Mage_Attack_Spike_Touch);
211 this.mage_spike = missile;
213 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
216 void M_Mage_Defend_Heal(entity this)
218 float washealed = false;
220 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
223 entity fx = EFFECT_Null;
229 if(it.health < autocvar_g_balance_health_regenstable) it.health = bound(0, it.health + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_health_regenstable);
233 if(it.ammo_cells) it.ammo_cells = bound(it.ammo_cells, it.ammo_cells + 1, g_pickup_cells_max);
234 if(it.ammo_plasma) it.ammo_plasma = bound(it.ammo_plasma, it.ammo_plasma + 1, g_pickup_plasma_max);
235 if(it.ammo_rockets) it.ammo_rockets = bound(it.ammo_rockets, it.ammo_rockets + 1, g_pickup_rockets_max);
236 if(it.ammo_shells) it.ammo_shells = bound(it.ammo_shells, it.ammo_shells + 2, g_pickup_shells_max);
237 if(it.ammo_nails) it.ammo_nails = bound(it.ammo_nails, it.ammo_nails + 5, g_pickup_nails_max);
238 fx = EFFECT_AMMO_REGEN;
241 if(it.armorvalue < autocvar_g_balance_armor_regenstable)
243 it.armorvalue = bound(0, it.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
244 fx = EFFECT_ARMOR_REPAIR;
248 it.health = bound(0, it.health - ((it == this) ? (autocvar_g_monster_mage_heal_self) : (autocvar_g_monster_mage_heal_allies)), autocvar_g_balance_health_regenstable);
253 Send_Effect(fx, it.origin, '0 0 0', 1);
257 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
258 it.health = bound(0, it.health + (autocvar_g_monster_mage_heal_allies), it.max_health);
259 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
260 WaypointSprite_UpdateHealth(it.sprite, it.health);
266 setanim(this, this.anim_shoot, true, true, true);
267 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
268 this.anim_finished = time + 1.5;
272 void M_Mage_Attack_Push(entity this)
274 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
275 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
276 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
277 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
279 setanim(this, this.anim_shoot, true, true, true);
280 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
283 void M_Mage_Attack_Teleport(entity this, entity targ)
286 if(vdist(targ.origin - this.origin, >, 1500)) return;
288 makevectors(targ.angles);
289 tracebox(targ.origin + ((v_forward * -1) * 200), this.mins, this.maxs, this.origin, MOVE_NOMONSTERS, this);
291 if(trace_fraction < 1)
294 vector newpos = targ.origin + ((v_forward * -1) * 200);
296 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
297 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
299 setorigin(this, newpos);
301 vector a = vectoangles(targ.origin - this.origin);
305 this.fixangle = true;
306 this.velocity *= 0.5;
308 this.attack_finished_single[0] = time + 0.2;
311 void M_Mage_Defend_Shield_Remove(entity this)
313 this.effects &= ~(EF_ADDITIVE | EF_BLUE);
314 this.armorvalue = autocvar_g_monsters_armor_blockpercent;
317 void M_Mage_Defend_Shield(entity this)
319 this.effects |= (EF_ADDITIVE | EF_BLUE);
320 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
321 this.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
322 this.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
323 setanim(this, this.anim_shoot, true, true, true);
324 this.attack_finished_single[0] = time + 1;
325 this.anim_finished = time + 1;
328 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
332 case MONSTER_ATTACK_MELEE:
336 Weapon wep = WEP_MAGE_SPIKE;
338 wep.wr_think(wep, actor, weaponentity, 2);
344 case MONSTER_ATTACK_RANGED:
346 if(!actor.mage_spike)
350 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
351 off.offhand_think(off, actor, true);
356 setanim(actor, actor.anim_shoot, true, true, true);
357 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
358 actor.anim_finished = time + 1;
359 Weapon wep = WEP_MAGE_SPIKE;
360 wep.wr_think(wep, actor, weaponentity, 1);
375 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE.monsterid); }
380 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
383 bool need_help = false;
385 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
387 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
388 if(M_Mage_Defend_Heal_Check(actor, it))
397 IL_EACH(g_monsters, it != actor,
399 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
400 if(M_Mage_Defend_Heal_Check(actor, it))
408 if(actor.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
409 if(time >= actor.attack_finished_single[0])
411 M_Mage_Defend_Heal(actor);
413 if(time >= actor.mage_shield_time && actor.armorvalue)
414 M_Mage_Defend_Shield_Remove(actor);
417 if(actor.health < actor.max_health)
418 if(time >= actor.mage_shield_delay)
420 M_Mage_Defend_Shield(actor);
425 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
431 METHOD(Mage, mr_death, bool(Mage this, entity actor))
434 setanim(actor, actor.anim_die1, false, true, true);
440 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
443 vector none = '0 0 0';
444 actor.anim_die1 = animfixfps(actor, '4 1 0.5', none); // 2 seconds
445 actor.anim_walk = animfixfps(actor, '1 1 1', none);
446 actor.anim_idle = animfixfps(actor, '0 1 1', none);
447 actor.anim_pain1 = animfixfps(actor, '3 1 2', none); // 0.5 seconds
448 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
449 actor.anim_run = animfixfps(actor, '5 1 1', none);
455 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
458 if(!actor.health) actor.health = (autocvar_g_monster_mage_health);
459 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
460 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
461 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
462 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
464 actor.monster_loot = ITEM_HealthBig;
465 actor.monster_attackfunc = M_Mage_Attack;