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 MON_ACTION(this, MR_PRECACHE);
25 #include "../../weapons/all.qh"
27 CLASS(MageSpike, PortoLaunch)
28 /* flags */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN);
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, bool fire1, bool fire2)) {
46 if (!IS_PLAYER(self) || weapon_prepareattack(false, 0.2)) {
47 if (!self.target_range) self.target_range = autocvar_g_monsters_target_range;
48 self.enemy = Monster_FindTarget(self);
49 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
50 if (!IS_PLAYER(self)) w_shotdir = normalize((self.enemy.origin + '0 0 10') - self.origin);
51 M_Mage_Attack_Spike(w_shotdir);
52 weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
55 if (!IS_PLAYER(self) || weapon_prepareattack(true, 0.5)) {
57 weapon_thinkf(WFRAME_FIRE2, 0, w_ready);
61 void M_Mage_Attack_Teleport();
63 CLASS(OffhandMageTeleport, OffhandWeapon)
64 .bool OffhandMageTeleport_key_pressed;
65 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
67 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
68 WITH(entity, self, player, M_Mage_Attack_Teleport());
69 player.OffhandMageTeleport_key_pressed = key_pressed;
71 ENDCLASS(OffhandMageTeleport)
72 OffhandMageTeleport OFFHAND_MAGE_TELEPORT; STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
74 float autocvar_g_monster_mage_health;
75 float autocvar_g_monster_mage_damageforcescale = 0.5;
76 float autocvar_g_monster_mage_attack_spike_damage;
77 float autocvar_g_monster_mage_attack_spike_radius;
78 float autocvar_g_monster_mage_attack_spike_delay;
79 float autocvar_g_monster_mage_attack_spike_accel;
80 float autocvar_g_monster_mage_attack_spike_decel;
81 float autocvar_g_monster_mage_attack_spike_turnrate;
82 float autocvar_g_monster_mage_attack_spike_speed_max;
83 float autocvar_g_monster_mage_attack_spike_smart;
84 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
85 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
86 float autocvar_g_monster_mage_attack_spike_smart_mindist;
87 float autocvar_g_monster_mage_attack_push_damage;
88 float autocvar_g_monster_mage_attack_push_radius;
89 float autocvar_g_monster_mage_attack_push_delay;
90 float autocvar_g_monster_mage_attack_push_force;
91 float autocvar_g_monster_mage_heal_self;
92 float autocvar_g_monster_mage_heal_allies;
93 float autocvar_g_monster_mage_heal_minhealth;
94 float autocvar_g_monster_mage_heal_range;
95 float autocvar_g_monster_mage_heal_delay;
96 float autocvar_g_monster_mage_shield_time;
97 float autocvar_g_monster_mage_shield_delay;
98 float autocvar_g_monster_mage_shield_blockpercent;
99 float autocvar_g_monster_mage_speed_stop;
100 float autocvar_g_monster_mage_speed_run;
101 float autocvar_g_monster_mage_speed_walk;
104 const float mage_anim_idle = 0;
105 const float mage_anim_walk = 1;
106 const float mage_anim_attack = 2;
107 const float mage_anim_pain = 3;
108 const float mage_anim_death = 4;
109 const float mage_anim_run = 5;
112 void() M_Mage_Defend_Heal;
113 void() M_Mage_Defend_Shield;
116 .float mage_shield_delay;
117 .float mage_shield_time;
119 float M_Mage_Defend_Heal_Check(entity e)
125 if(DIFF_TEAM(e, self) && e != self.monster_follow)
130 return (IS_MONSTER(e) && e.health < e.max_health);
131 if(e.items & ITEM_Shield.m_itemid)
136 case 0: return (e.health < autocvar_g_balance_health_regenstable);
137 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));
138 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
139 case 3: return (e.health > 0);
145 void M_Mage_Attack_Spike_Explode()
147 self.event_damage = func_null;
149 sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
151 self.realowner.mage_spike = world;
153 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
154 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);
159 void M_Mage_Attack_Spike_Touch()
163 M_Mage_Attack_Spike_Explode();
166 // copied from W_Seeker_Think
167 void M_Mage_Attack_Spike_Think()
169 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
170 self.projectiledeathtype |= HITTYPE_SPLASH;
171 M_Mage_Attack_Spike_Explode();
174 float spd = vlen(self.velocity);
176 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
177 (autocvar_g_monster_mage_attack_spike_speed_max),
178 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
181 if (self.enemy != world)
182 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
185 if (self.enemy != world)
187 entity e = self.enemy;
188 vector eorg = 0.5 * (e.absmin + e.absmax);
189 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
190 vector desireddir = normalize(eorg - self.origin);
191 vector olddir = normalize(self.velocity); // get my current direction
192 float dist = vlen(eorg - self.origin);
194 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
195 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
197 // Is it a better idea (shorter distance) to trace to the target itself?
198 if ( vlen(self.origin + olddir * self.wait) < dist)
199 traceline(self.origin, self.origin + olddir * self.wait, false, self);
201 traceline(self.origin, eorg, false, self);
203 // Setup adaptive tracelength
204 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));
206 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
207 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
210 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
211 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
216 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
217 self.nextthink = time;// + 0.05; // csqc projectiles
218 UpdateCSQCProjectile(self);
221 void M_Mage_Attack_Spike(vector dir)
224 makevectors(self.angles);
226 entity missile = spawn();
227 missile.owner = missile.realowner = self;
228 missile.think = M_Mage_Attack_Spike_Think;
229 missile.ltime = time + 7;
230 missile.nextthink = time;
231 missile.solid = SOLID_BBOX;
232 missile.movetype = MOVETYPE_FLYMISSILE;
233 missile.flags = FL_PROJECTILE;
234 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
235 setsize(missile, '0 0 0', '0 0 0');
236 missile.velocity = dir * 400;
237 missile.avelocity = '300 300 300';
238 missile.enemy = self.enemy;
239 missile.touch = M_Mage_Attack_Spike_Touch;
241 self.mage_spike = missile;
243 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
246 void M_Mage_Defend_Heal()
249 float washealed = false;
251 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
260 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);
261 fx = EFFECT_HEALING.eent_eff_name;
264 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
265 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
266 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
267 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
268 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
272 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
274 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
275 fx = "armorrepair_fx";
279 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);
280 fx = EFFECT_RAGE.eent_eff_name;
284 Send_Effect_(fx, head.origin, '0 0 0', 1);
288 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
289 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
290 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
291 WaypointSprite_UpdateHealth(head.sprite, head.health);
297 setanim(self, self.anim_shoot, true, true, true);
298 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
299 self.anim_finished = time + 1.5;
303 void M_Mage_Attack_Push()
305 sound(self, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
306 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);
307 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
309 setanim(self, self.anim_shoot, true, true, true);
310 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
313 void M_Mage_Attack_Teleport()
315 entity targ = self.enemy;
317 if (vlen(targ.origin - self.origin) > 1500) return;
319 makevectors(targ.angles);
320 tracebox(targ.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
322 if(trace_fraction < 1)
325 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
326 setorigin(self, targ.origin + ((v_forward * -1) * 200));
328 vector a = vectoangles(targ.origin - self.origin);
332 self.fixangle = true;
333 self.velocity *= 0.5;
335 self.attack_finished_single = time + 0.2;
338 void M_Mage_Defend_Shield_Remove()
340 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
341 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
344 void M_Mage_Defend_Shield()
346 self.effects |= (EF_ADDITIVE | EF_BLUE);
347 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
348 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
349 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
350 setanim(self, self.anim_shoot, true, true, true);
351 self.attack_finished_single = time + 1;
352 self.anim_finished = time + 1;
355 float M_Mage_Attack(float attack_type, entity targ)
359 case MONSTER_ATTACK_MELEE:
363 Weapon wep = WEP_MAGE_SPIKE;
364 wep.wr_think(wep, false, true);
370 case MONSTER_ATTACK_RANGED:
376 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
377 off.offhand_think(off, self, true);
382 setanim(self, self.anim_shoot, true, true, true);
383 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
384 self.anim_finished = time + 1;
385 Weapon wep = WEP_MAGE_SPIKE;
386 wep.wr_think(wep, true, false);
401 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
406 METHOD(Mage, mr_think, bool(Monster thismon))
410 bool need_help = false;
412 for(head = world; (head = findfloat(head, iscreature, true)); )
414 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
415 if(M_Mage_Defend_Heal_Check(head))
421 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
422 if(time >= self.attack_finished_single)
424 M_Mage_Defend_Heal();
426 if(time >= self.mage_shield_time && self.armorvalue)
427 M_Mage_Defend_Shield_Remove();
430 if(self.health < self.max_health)
431 if(time >= self.mage_shield_delay)
433 M_Mage_Defend_Shield();
437 METHOD(Mage, mr_pain, bool(Monster thismon))
441 METHOD(Mage, mr_death, bool(Monster thismon))
444 setanim(self, self.anim_die1, false, true, true);
449 METHOD(Mage, mr_anim, bool(Monster thismon))
452 vector none = '0 0 0';
453 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
454 self.anim_walk = animfixfps(self, '1 1 1', none);
455 self.anim_idle = animfixfps(self, '0 1 1', none);
456 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
457 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
458 self.anim_run = animfixfps(self, '5 1 1', none);
464 METHOD(Mage, mr_setup, bool(Monster thismon))
467 if(!self.health) self.health = (autocvar_g_monster_mage_health);
468 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
469 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
470 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
471 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
473 self.monster_loot = spawnfunc_item_health_large;
474 self.monster_attackfunc = M_Mage_Attack;
478 METHOD(Mage, mr_precache, bool(Monster thismon))