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);
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 METHOD(MageSpike, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
45 if (weapon_prepareattack(0, WEP_CVAR_PRI(electro, refire))) {
46 if (!self.target_range) self.target_range = autocvar_g_monsters_target_range;
47 self.enemy = Monster_FindTarget(self);
48 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
49 M_Mage_Attack_Spike(w_shotdir);
50 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
55 float autocvar_g_monster_mage_health;
56 float autocvar_g_monster_mage_damageforcescale = 0.5;
57 float autocvar_g_monster_mage_attack_spike_damage;
58 float autocvar_g_monster_mage_attack_spike_radius;
59 float autocvar_g_monster_mage_attack_spike_delay;
60 float autocvar_g_monster_mage_attack_spike_accel;
61 float autocvar_g_monster_mage_attack_spike_decel;
62 float autocvar_g_monster_mage_attack_spike_turnrate;
63 float autocvar_g_monster_mage_attack_spike_speed_max;
64 float autocvar_g_monster_mage_attack_spike_smart;
65 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
66 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
67 float autocvar_g_monster_mage_attack_spike_smart_mindist;
68 float autocvar_g_monster_mage_attack_push_damage;
69 float autocvar_g_monster_mage_attack_push_radius;
70 float autocvar_g_monster_mage_attack_push_delay;
71 float autocvar_g_monster_mage_attack_push_force;
72 float autocvar_g_monster_mage_heal_self;
73 float autocvar_g_monster_mage_heal_allies;
74 float autocvar_g_monster_mage_heal_minhealth;
75 float autocvar_g_monster_mage_heal_range;
76 float autocvar_g_monster_mage_heal_delay;
77 float autocvar_g_monster_mage_shield_time;
78 float autocvar_g_monster_mage_shield_delay;
79 float autocvar_g_monster_mage_shield_blockpercent;
80 float autocvar_g_monster_mage_speed_stop;
81 float autocvar_g_monster_mage_speed_run;
82 float autocvar_g_monster_mage_speed_walk;
85 const float mage_anim_idle = 0;
86 const float mage_anim_walk = 1;
87 const float mage_anim_attack = 2;
88 const float mage_anim_pain = 3;
89 const float mage_anim_death = 4;
90 const float mage_anim_run = 5;
93 void() M_Mage_Defend_Heal;
94 void() M_Mage_Defend_Shield;
97 .float mage_shield_delay;
98 .float mage_shield_time;
100 float M_Mage_Defend_Heal_Check(entity e)
106 if(DIFF_TEAM(e, self) && e != self.monster_follow)
111 return (IS_MONSTER(e) && e.health < e.max_health);
112 if(e.items & ITEM_Shield.m_itemid)
117 case 0: return (e.health < autocvar_g_balance_health_regenstable);
118 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));
119 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
120 case 3: return (e.health > 0);
126 void M_Mage_Attack_Spike_Explode()
128 self.event_damage = func_null;
130 sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
132 self.realowner.mage_spike = world;
134 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
135 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);
140 void M_Mage_Attack_Spike_Touch()
144 M_Mage_Attack_Spike_Explode();
147 // copied from W_Seeker_Think
148 void M_Mage_Attack_Spike_Think()
150 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
151 self.projectiledeathtype |= HITTYPE_SPLASH;
152 M_Mage_Attack_Spike_Explode();
155 float spd = vlen(self.velocity);
157 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
158 (autocvar_g_monster_mage_attack_spike_speed_max),
159 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
162 if (self.enemy != world)
163 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
166 if (self.enemy != world)
168 entity e = self.enemy;
169 vector eorg = 0.5 * (e.absmin + e.absmax);
170 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
171 vector desireddir = normalize(eorg - self.origin);
172 vector olddir = normalize(self.velocity); // get my current direction
173 float dist = vlen(eorg - self.origin);
175 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
176 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
178 // Is it a better idea (shorter distance) to trace to the target itself?
179 if ( vlen(self.origin + olddir * self.wait) < dist)
180 traceline(self.origin, self.origin + olddir * self.wait, false, self);
182 traceline(self.origin, eorg, false, self);
184 // Setup adaptive tracelength
185 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));
187 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
188 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
191 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
192 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
197 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
198 self.nextthink = time;// + 0.05; // csqc projectiles
199 UpdateCSQCProjectile(self);
202 void M_Mage_Attack_Spike(vector dir);
203 void M_Mage_Attack_Spike_Aim()
206 return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
209 void M_Mage_Attack_Spike(vector dir)
212 makevectors(self.angles);
214 entity missile = spawn();
215 missile.owner = missile.realowner = self;
216 missile.think = M_Mage_Attack_Spike_Think;
217 missile.ltime = time + 7;
218 missile.nextthink = time;
219 missile.solid = SOLID_BBOX;
220 missile.movetype = MOVETYPE_FLYMISSILE;
221 missile.flags = FL_PROJECTILE;
222 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
223 setsize(missile, '0 0 0', '0 0 0');
224 missile.velocity = dir * 400;
225 missile.avelocity = '300 300 300';
226 missile.enemy = self.enemy;
227 missile.touch = M_Mage_Attack_Spike_Touch;
229 self.mage_spike = missile;
231 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
234 void M_Mage_Defend_Heal()
237 float washealed = false;
239 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
248 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);
249 fx = EFFECT_HEALING.eent_eff_name;
252 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
253 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
254 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
255 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
256 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
260 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
262 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
263 fx = "armorrepair_fx";
267 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);
268 fx = EFFECT_RAGE.eent_eff_name;
272 Send_Effect_(fx, head.origin, '0 0 0', 1);
276 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
277 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
278 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
279 WaypointSprite_UpdateHealth(head.sprite, head.health);
285 setanim(self, self.anim_shoot, true, true, true);
286 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
287 self.anim_finished = time + 1.5;
291 void M_Mage_Attack_Push()
293 sound(self, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
294 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);
295 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
297 setanim(self, self.anim_shoot, true, true, true);
298 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
301 void M_Mage_Attack_Teleport()
303 if(vlen(self.enemy.origin - self.origin) >= 500)
306 makevectors(self.enemy.angles);
307 tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
309 if(trace_fraction < 1)
312 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
313 setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
315 self.attack_finished_single = time + 0.2;
318 void M_Mage_Defend_Shield_Remove()
320 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
321 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
324 void M_Mage_Defend_Shield()
326 self.effects |= (EF_ADDITIVE | EF_BLUE);
327 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
328 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
329 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
330 setanim(self, self.anim_shoot, true, true, true);
331 self.attack_finished_single = time + 1;
332 self.anim_finished = time + 1;
335 float M_Mage_Attack(float attack_type)
339 case MONSTER_ATTACK_MELEE:
343 M_Mage_Attack_Push();
349 case MONSTER_ATTACK_RANGED:
355 M_Mage_Attack_Teleport();
360 setanim(self, self.anim_shoot, true, true, true);
361 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
362 self.anim_finished = time + 1;
363 Monster_Delay(1, 0, 0.2, M_Mage_Attack_Spike_Aim);
378 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
383 METHOD(Mage, mr_think, bool(Monster thismon))
387 bool need_help = false;
389 for(head = world; (head = findfloat(head, iscreature, true)); )
391 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
392 if(M_Mage_Defend_Heal_Check(head))
398 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
399 if(time >= self.attack_finished_single)
401 M_Mage_Defend_Heal();
403 if(time >= self.mage_shield_time && self.armorvalue)
404 M_Mage_Defend_Shield_Remove();
407 if(self.health < self.max_health)
408 if(time >= self.mage_shield_delay)
410 M_Mage_Defend_Shield();
414 METHOD(Mage, mr_pain, bool(Monster thismon))
418 METHOD(Mage, mr_death, bool(Monster thismon))
421 setanim(self, self.anim_die1, false, true, true);
426 METHOD(Mage, mr_anim, bool(Monster thismon))
429 vector none = '0 0 0';
430 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
431 self.anim_walk = animfixfps(self, '1 1 1', none);
432 self.anim_idle = animfixfps(self, '0 1 1', none);
433 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
434 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
435 self.anim_run = animfixfps(self, '5 1 1', none);
441 METHOD(Mage, mr_setup, bool(Monster thismon))
444 if(!self.health) self.health = (autocvar_g_monster_mage_health);
445 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
446 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
447 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
448 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
450 self.monster_loot = spawnfunc_item_health_large;
451 self.monster_attackfunc = M_Mage_Attack;
455 METHOD(Mage, mr_precache, bool(Monster thismon))