5 MODEL(MON_MAGE, M_Model("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"
26 #include "../../items/all.qc"
28 CLASS(MageSpike, PortoLaunch)
29 /* flags */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
30 /* impulse */ ATTRIB(MageSpike, impulse, int, 9);
31 /* refname */ ATTRIB(MageSpike, netname, string, "magespike");
32 /* wepname */ ATTRIB(MageSpike, m_name, string, _("Mage spike"));
34 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike));
42 void M_Mage_Attack_Spike(vector dir);
43 void M_Mage_Attack_Push();
44 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, .entity weaponentity, int fire)) {
46 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
47 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
48 actor.enemy = Monster_FindTarget(actor);
49 W_SetupShot_Dir(actor, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
50 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
51 M_Mage_Attack_Spike(w_shotdir);
52 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
55 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
57 weapon_thinkf(actor, weaponentity, 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.m_id, other);
159 void M_Mage_Attack_Spike_Touch()
163 M_Mage_Attack_Spike_Explode();
168 // copied from W_Seeker_Think
169 void M_Mage_Attack_Spike_Think()
171 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
172 self.projectiledeathtype |= HITTYPE_SPLASH;
173 M_Mage_Attack_Spike_Explode();
176 float spd = vlen(self.velocity);
178 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
179 (autocvar_g_monster_mage_attack_spike_speed_max),
180 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
183 if (self.enemy != world)
184 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
187 if (self.enemy != world)
189 entity e = self.enemy;
190 vector eorg = 0.5 * (e.absmin + e.absmax);
191 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
192 vector desireddir = normalize(eorg - self.origin);
193 vector olddir = normalize(self.velocity); // get my current direction
194 float dist = vlen(eorg - self.origin);
196 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
197 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
199 // Is it a better idea (shorter distance) to trace to the target itself?
200 if ( vlen(self.origin + olddir * self.wait) < dist)
201 traceline(self.origin, self.origin + olddir * self.wait, false, self);
203 traceline(self.origin, eorg, false, self);
205 // Setup adaptive tracelength
206 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));
208 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
209 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
212 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
213 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
218 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
219 self.nextthink = time;// + 0.05; // csqc projectiles
220 UpdateCSQCProjectile(self);
223 void M_Mage_Attack_Spike(vector dir)
226 makevectors(self.angles);
228 entity missile = spawn();
229 missile.owner = missile.realowner = self;
230 missile.think = M_Mage_Attack_Spike_Think;
231 missile.ltime = time + 7;
232 missile.nextthink = time;
233 missile.solid = SOLID_BBOX;
234 missile.movetype = MOVETYPE_FLYMISSILE;
235 missile.flags = FL_PROJECTILE;
236 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
237 setsize(missile, '0 0 0', '0 0 0');
238 missile.velocity = dir * 400;
239 missile.avelocity = '300 300 300';
240 missile.enemy = self.enemy;
241 missile.touch = M_Mage_Attack_Spike_Touch;
243 self.mage_spike = missile;
245 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
248 void M_Mage_Defend_Heal()
251 float washealed = false;
253 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
262 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);
263 fx = EFFECT_HEALING.eent_eff_name;
266 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
267 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
268 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
269 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
270 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
274 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
276 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
277 fx = "armorrepair_fx";
281 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);
282 fx = EFFECT_RAGE.eent_eff_name;
286 Send_Effect_(fx, head.origin, '0 0 0', 1);
290 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
291 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
292 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
293 WaypointSprite_UpdateHealth(head.sprite, head.health);
299 setanim(self, self.anim_shoot, true, true, true);
300 self.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
301 self.anim_finished = time + 1.5;
305 void M_Mage_Attack_Push()
307 sound(self, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
308 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.m_id, self.enemy);
309 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
311 setanim(self, self.anim_shoot, true, true, true);
312 self.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
315 void M_Mage_Attack_Teleport()
317 entity targ = self.enemy;
319 if (vlen(targ.origin - self.origin) > 1500) return;
321 makevectors(targ.angles);
322 tracebox(targ.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
324 if(trace_fraction < 1)
327 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
328 setorigin(self, targ.origin + ((v_forward * -1) * 200));
330 vector a = vectoangles(targ.origin - self.origin);
334 self.fixangle = true;
335 self.velocity *= 0.5;
337 self.attack_finished_single[0] = time + 0.2;
340 void M_Mage_Defend_Shield_Remove()
342 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
343 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
346 void M_Mage_Defend_Shield()
348 self.effects |= (EF_ADDITIVE | EF_BLUE);
349 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
350 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
351 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
352 setanim(self, self.anim_shoot, true, true, true);
353 self.attack_finished_single[0] = time + 1;
354 self.anim_finished = time + 1;
357 float M_Mage_Attack(float attack_type, entity targ)
359 .entity weaponentity = weaponentities[0];
362 case MONSTER_ATTACK_MELEE:
366 Weapon wep = WEP_MAGE_SPIKE;
368 wep.wr_think(wep, self, weaponentity, 2);
374 case MONSTER_ATTACK_RANGED:
380 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
381 off.offhand_think(off, self, true);
386 setanim(self, self.anim_shoot, true, true, true);
387 self.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
388 self.anim_finished = time + 1;
389 Weapon wep = WEP_MAGE_SPIKE;
390 wep.wr_think(wep, self, weaponentity, 1);
405 spawnfunc(monster_mage) { Monster_Spawn(MON_MAGE.monsterid); }
410 METHOD(Mage, mr_think, bool(Monster thismon))
414 bool need_help = false;
416 for(head = world; (head = findfloat(head, iscreature, true)); )
418 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
419 if(M_Mage_Defend_Heal_Check(head))
425 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
426 if(time >= self.attack_finished_single[0])
428 M_Mage_Defend_Heal();
430 if(time >= self.mage_shield_time && self.armorvalue)
431 M_Mage_Defend_Shield_Remove();
434 if(self.health < self.max_health)
435 if(time >= self.mage_shield_delay)
437 M_Mage_Defend_Shield();
441 METHOD(Mage, mr_pain, bool(Monster thismon))
445 METHOD(Mage, mr_death, bool(Monster thismon))
448 setanim(self, self.anim_die1, false, true, true);
453 METHOD(Mage, mr_anim, bool(Monster thismon))
456 vector none = '0 0 0';
457 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
458 self.anim_walk = animfixfps(self, '1 1 1', none);
459 self.anim_idle = animfixfps(self, '0 1 1', none);
460 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
461 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
462 self.anim_run = animfixfps(self, '5 1 1', none);
469 spawnfunc(item_health_large);
470 METHOD(Mage, mr_setup, bool(Monster thismon))
473 if(!self.health) self.health = (autocvar_g_monster_mage_health);
474 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
475 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
476 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
477 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
479 self.monster_loot = spawnfunc_item_health_large;
480 self.monster_attackfunc = M_Mage_Attack;
484 METHOD(Mage, mr_precache, bool(Monster thismon))