5 MODEL(MON_MAGE, "models/monsters/mage.dpm");
9 ATTRIB(Mage, spawnflags, int, MON_FLAG_MELEE | MON_FLAG_RANGED);
10 ATTRIB(Mage, mins, vector, '-36 -36 -24');
11 ATTRIB(Mage, maxs, vector, '36 36 50');
13 ATTRIB(Mage, m_model, Model, MDL_MON_MAGE);
15 ATTRIB(Mage, netname, string, "mage");
16 ATTRIB(Mage, monster_name, string, _("Mage"));
19 REGISTER_MONSTER(MAGE, NEW(Mage)) {
21 this.mr_precache(this);
25 #include "../../weapons/all.qh"
27 CLASS(MageSpike, PortoLaunch)
28 /* flags */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
29 /* impulse */ ATTRIB(MageSpike, impulse, int, 9);
30 /* refname */ ATTRIB(MageSpike, netname, string, "magespike");
31 /* wepname */ ATTRIB(MageSpike, message, string, _("Mage spike"));
33 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike));
41 void M_Mage_Attack_Spike(vector dir);
42 void M_Mage_Attack_Push();
43 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, bool fire1, bool fire2)) {
45 if (!IS_PLAYER(actor) || weapon_prepareattack(actor, false, 0.2)) {
46 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
47 actor.enemy = Monster_FindTarget(actor);
48 W_SetupShot_Dir(actor, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
49 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
50 M_Mage_Attack_Spike(w_shotdir);
51 weapon_thinkf(actor, WFRAME_FIRE1, 0, w_ready);
54 if (!IS_PLAYER(actor) || weapon_prepareattack(actor, true, 0.5)) {
56 weapon_thinkf(actor, WFRAME_FIRE2, 0, w_ready);
60 void M_Mage_Attack_Teleport();
62 CLASS(OffhandMageTeleport, OffhandWeapon)
63 .bool OffhandMageTeleport_key_pressed;
64 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
66 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
67 WITH(entity, self, player, M_Mage_Attack_Teleport());
68 player.OffhandMageTeleport_key_pressed = key_pressed;
70 ENDCLASS(OffhandMageTeleport)
71 OffhandMageTeleport OFFHAND_MAGE_TELEPORT; STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
73 float autocvar_g_monster_mage_health;
74 float autocvar_g_monster_mage_damageforcescale = 0.5;
75 float autocvar_g_monster_mage_attack_spike_damage;
76 float autocvar_g_monster_mage_attack_spike_radius;
77 float autocvar_g_monster_mage_attack_spike_delay;
78 float autocvar_g_monster_mage_attack_spike_accel;
79 float autocvar_g_monster_mage_attack_spike_decel;
80 float autocvar_g_monster_mage_attack_spike_turnrate;
81 float autocvar_g_monster_mage_attack_spike_speed_max;
82 float autocvar_g_monster_mage_attack_spike_smart;
83 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
84 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
85 float autocvar_g_monster_mage_attack_spike_smart_mindist;
86 float autocvar_g_monster_mage_attack_push_damage;
87 float autocvar_g_monster_mage_attack_push_radius;
88 float autocvar_g_monster_mage_attack_push_delay;
89 float autocvar_g_monster_mage_attack_push_force;
90 float autocvar_g_monster_mage_heal_self;
91 float autocvar_g_monster_mage_heal_allies;
92 float autocvar_g_monster_mage_heal_minhealth;
93 float autocvar_g_monster_mage_heal_range;
94 float autocvar_g_monster_mage_heal_delay;
95 float autocvar_g_monster_mage_shield_time;
96 float autocvar_g_monster_mage_shield_delay;
97 float autocvar_g_monster_mage_shield_blockpercent;
98 float autocvar_g_monster_mage_speed_stop;
99 float autocvar_g_monster_mage_speed_run;
100 float autocvar_g_monster_mage_speed_walk;
103 const float mage_anim_idle = 0;
104 const float mage_anim_walk = 1;
105 const float mage_anim_attack = 2;
106 const float mage_anim_pain = 3;
107 const float mage_anim_death = 4;
108 const float mage_anim_run = 5;
111 void() M_Mage_Defend_Heal;
112 void() M_Mage_Defend_Shield;
115 .float mage_shield_delay;
116 .float mage_shield_time;
118 float M_Mage_Defend_Heal_Check(entity e)
124 if(DIFF_TEAM(e, self) && e != self.monster_follow)
129 return (IS_MONSTER(e) && e.health < e.max_health);
130 if(e.items & ITEM_Shield.m_itemid)
135 case 0: return (e.health < autocvar_g_balance_health_regenstable);
136 case 1: return ((e.ammo_cells && e.ammo_cells < g_pickup_cells_max) || (e.ammo_plasma && e.ammo_plasma < g_pickup_plasma_max) || (e.ammo_rockets && e.ammo_rockets < g_pickup_rockets_max) || (e.ammo_nails && e.ammo_nails < g_pickup_nails_max) || (e.ammo_shells && e.ammo_shells < g_pickup_shells_max));
137 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
138 case 3: return (e.health > 0);
144 void M_Mage_Attack_Spike_Explode()
146 self.event_damage = func_null;
148 sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
150 self.realowner.mage_spike = world;
152 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
153 RadiusDamage (self, self.realowner, (autocvar_g_monster_mage_attack_spike_damage), (autocvar_g_monster_mage_attack_spike_damage) * 0.5, (autocvar_g_monster_mage_attack_spike_radius), world, world, 0, DEATH_MONSTER_MAGE, other);
158 void M_Mage_Attack_Spike_Touch()
162 M_Mage_Attack_Spike_Explode();
165 // copied from W_Seeker_Think
166 void M_Mage_Attack_Spike_Think()
168 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
169 self.projectiledeathtype |= HITTYPE_SPLASH;
170 M_Mage_Attack_Spike_Explode();
173 float spd = vlen(self.velocity);
175 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
176 (autocvar_g_monster_mage_attack_spike_speed_max),
177 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
180 if (self.enemy != world)
181 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
184 if (self.enemy != world)
186 entity e = self.enemy;
187 vector eorg = 0.5 * (e.absmin + e.absmax);
188 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
189 vector desireddir = normalize(eorg - self.origin);
190 vector olddir = normalize(self.velocity); // get my current direction
191 float dist = vlen(eorg - self.origin);
193 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
194 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
196 // Is it a better idea (shorter distance) to trace to the target itself?
197 if ( vlen(self.origin + olddir * self.wait) < dist)
198 traceline(self.origin, self.origin + olddir * self.wait, false, self);
200 traceline(self.origin, eorg, false, self);
202 // Setup adaptive tracelength
203 self.wait = bound((autocvar_g_monster_mage_attack_spike_smart_trace_min), vlen(self.origin - trace_endpos), self.wait = (autocvar_g_monster_mage_attack_spike_smart_trace_max));
205 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
206 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
209 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
210 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
215 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
216 self.nextthink = time;// + 0.05; // csqc projectiles
217 UpdateCSQCProjectile(self);
220 void M_Mage_Attack_Spike(vector dir)
223 makevectors(self.angles);
225 entity missile = spawn();
226 missile.owner = missile.realowner = self;
227 missile.think = M_Mage_Attack_Spike_Think;
228 missile.ltime = time + 7;
229 missile.nextthink = time;
230 missile.solid = SOLID_BBOX;
231 missile.movetype = MOVETYPE_FLYMISSILE;
232 missile.flags = FL_PROJECTILE;
233 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
234 setsize(missile, '0 0 0', '0 0 0');
235 missile.velocity = dir * 400;
236 missile.avelocity = '300 300 300';
237 missile.enemy = self.enemy;
238 missile.touch = M_Mage_Attack_Spike_Touch;
240 self.mage_spike = missile;
242 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
245 void M_Mage_Defend_Heal()
248 float washealed = false;
250 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
259 if(head.health < autocvar_g_balance_health_regenstable) head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_health_regenstable);
260 fx = EFFECT_HEALING.eent_eff_name;
263 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
264 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
265 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
266 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
267 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
271 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
273 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
274 fx = "armorrepair_fx";
278 head.health = bound(0, head.health - ((head == self) ? (autocvar_g_monster_mage_heal_self) : (autocvar_g_monster_mage_heal_allies)), autocvar_g_balance_health_regenstable);
279 fx = EFFECT_RAGE.eent_eff_name;
283 Send_Effect_(fx, head.origin, '0 0 0', 1);
287 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
288 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
289 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
290 WaypointSprite_UpdateHealth(head.sprite, head.health);
296 setanim(self, self.anim_shoot, true, true, true);
297 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
298 self.anim_finished = time + 1.5;
302 void M_Mage_Attack_Push()
304 sound(self, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
305 RadiusDamage (self, self, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius), world, world, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE, self.enemy);
306 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
308 setanim(self, self.anim_shoot, true, true, true);
309 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
312 void M_Mage_Attack_Teleport()
314 entity targ = self.enemy;
316 if (vlen(targ.origin - self.origin) > 1500) return;
318 makevectors(targ.angles);
319 tracebox(targ.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
321 if(trace_fraction < 1)
324 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
325 setorigin(self, targ.origin + ((v_forward * -1) * 200));
327 vector a = vectoangles(targ.origin - self.origin);
331 self.fixangle = true;
332 self.velocity *= 0.5;
334 self.attack_finished_single = time + 0.2;
337 void M_Mage_Defend_Shield_Remove()
339 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
340 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
343 void M_Mage_Defend_Shield()
345 self.effects |= (EF_ADDITIVE | EF_BLUE);
346 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
347 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
348 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
349 setanim(self, self.anim_shoot, true, true, true);
350 self.attack_finished_single = time + 1;
351 self.anim_finished = time + 1;
354 float M_Mage_Attack(float attack_type, entity targ)
358 case MONSTER_ATTACK_MELEE:
362 Weapon wep = WEP_MAGE_SPIKE;
363 wep.wr_think(wep, self, false, true);
369 case MONSTER_ATTACK_RANGED:
375 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
376 off.offhand_think(off, self, true);
381 setanim(self, self.anim_shoot, true, true, true);
382 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
383 self.anim_finished = time + 1;
384 Weapon wep = WEP_MAGE_SPIKE;
385 wep.wr_think(wep, self, true, false);
400 spawnfunc(monster_mage) { Monster_Spawn(MON_MAGE.monsterid); }
405 METHOD(Mage, mr_think, bool(Monster thismon))
409 bool need_help = false;
411 for(head = world; (head = findfloat(head, iscreature, true)); )
413 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
414 if(M_Mage_Defend_Heal_Check(head))
420 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
421 if(time >= self.attack_finished_single)
423 M_Mage_Defend_Heal();
425 if(time >= self.mage_shield_time && self.armorvalue)
426 M_Mage_Defend_Shield_Remove();
429 if(self.health < self.max_health)
430 if(time >= self.mage_shield_delay)
432 M_Mage_Defend_Shield();
436 METHOD(Mage, mr_pain, bool(Monster thismon))
440 METHOD(Mage, mr_death, bool(Monster thismon))
443 setanim(self, self.anim_die1, false, true, true);
448 METHOD(Mage, mr_anim, bool(Monster thismon))
451 vector none = '0 0 0';
452 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
453 self.anim_walk = animfixfps(self, '1 1 1', none);
454 self.anim_idle = animfixfps(self, '0 1 1', none);
455 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
456 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
457 self.anim_run = animfixfps(self, '5 1 1', none);
463 METHOD(Mage, mr_setup, bool(Monster thismon))
466 if(!self.health) self.health = (autocvar_g_monster_mage_health);
467 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
468 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
469 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
470 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
472 self.monster_loot = spawnfunc_item_health_large;
473 self.monster_attackfunc = M_Mage_Attack;
477 METHOD(Mage, mr_precache, bool(Monster thismon))