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 <common/weapons/all.qh>
26 #include <common/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 SOUND(MageSpike_FIRE, W_Sound("electro_fire"));
43 void M_Mage_Attack_Spike(entity this, vector dir);
44 void M_Mage_Attack_Push(entity this);
45 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, .entity weaponentity, int fire))
47 TC(MageSpike, thiswep);
49 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
50 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
51 actor.enemy = Monster_FindTarget(actor);
52 W_SetupShot_Dir(actor, v_forward, false, 0, SND_MageSpike_FIRE, CH_WEAPON_B, 0);
53 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
54 M_Mage_Attack_Spike(actor, w_shotdir);
55 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
58 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
59 M_Mage_Attack_Push(actor);
60 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
64 void M_Mage_Attack_Teleport(entity this, entity targ);
66 CLASS(OffhandMageTeleport, OffhandWeapon)
67 .bool OffhandMageTeleport_key_pressed;
68 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
70 TC(OffhandMageTeleport, this);
71 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
72 M_Mage_Attack_Teleport(player, player.enemy);
73 player.OffhandMageTeleport_key_pressed = key_pressed;
75 ENDCLASS(OffhandMageTeleport)
76 OffhandMageTeleport OFFHAND_MAGE_TELEPORT; STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
78 float autocvar_g_monster_mage_health;
79 float autocvar_g_monster_mage_damageforcescale = 0.5;
80 float autocvar_g_monster_mage_attack_spike_damage;
81 float autocvar_g_monster_mage_attack_spike_radius;
82 float autocvar_g_monster_mage_attack_spike_delay;
83 float autocvar_g_monster_mage_attack_spike_accel;
84 float autocvar_g_monster_mage_attack_spike_decel;
85 float autocvar_g_monster_mage_attack_spike_turnrate;
86 float autocvar_g_monster_mage_attack_spike_speed_max;
87 float autocvar_g_monster_mage_attack_spike_smart;
88 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
89 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
90 float autocvar_g_monster_mage_attack_spike_smart_mindist;
91 float autocvar_g_monster_mage_attack_push_damage;
92 float autocvar_g_monster_mage_attack_push_radius;
93 float autocvar_g_monster_mage_attack_push_delay;
94 float autocvar_g_monster_mage_attack_push_force;
95 float autocvar_g_monster_mage_heal_self;
96 float autocvar_g_monster_mage_heal_allies;
97 float autocvar_g_monster_mage_heal_minhealth;
98 float autocvar_g_monster_mage_heal_range;
99 float autocvar_g_monster_mage_heal_delay;
100 float autocvar_g_monster_mage_shield_time;
101 float autocvar_g_monster_mage_shield_delay;
102 float autocvar_g_monster_mage_shield_blockpercent;
103 float autocvar_g_monster_mage_speed_stop;
104 float autocvar_g_monster_mage_speed_run;
105 float autocvar_g_monster_mage_speed_walk;
108 const float mage_anim_idle = 0;
109 const float mage_anim_walk = 1;
110 const float mage_anim_attack = 2;
111 const float mage_anim_pain = 3;
112 const float mage_anim_death = 4;
113 const float mage_anim_run = 5;
116 void M_Mage_Defend_Heal(entity this);
117 void M_Mage_Defend_Shield(entity this);
120 .float mage_shield_delay;
121 .float mage_shield_time;
123 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
129 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
131 if(STAT(FROZEN, targ))
134 return (IS_MONSTER(targ) && targ.health < targ.max_health);
135 if(targ.items & ITEM_Shield.m_itemid)
140 case 0: return (targ.health < autocvar_g_balance_health_regenstable);
141 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));
142 case 2: return (targ.armorvalue < autocvar_g_balance_armor_regenstable);
143 case 3: return (targ.health > 0);
149 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
151 this.event_damage = func_null;
153 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
155 this.realowner.mage_spike = NULL;
157 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
158 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), NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, directhitentity);
163 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
165 PROJECTILE_TOUCH(this, toucher);
167 M_Mage_Attack_Spike_Explode(this, toucher);
172 // copied from W_Seeker_Think
173 void M_Mage_Attack_Spike_Think(entity this)
175 if (time > this.ltime || (this.enemy && this.enemy.health <= 0) || this.owner.health <= 0) {
176 this.projectiledeathtype |= HITTYPE_SPLASH;
177 M_Mage_Attack_Spike_Explode(this, NULL);
180 float spd = vlen(this.velocity);
182 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
183 (autocvar_g_monster_mage_attack_spike_speed_max),
184 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
187 if (this.enemy != NULL)
188 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
191 if (this.enemy != NULL)
193 entity e = this.enemy;
194 vector eorg = 0.5 * (e.absmin + e.absmax);
195 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
196 vector desireddir = normalize(eorg - this.origin);
197 vector olddir = normalize(this.velocity); // get my current direction
199 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
200 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
202 // Is it a better idea (shorter distance) to trace to the target itthis?
203 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
204 traceline(this.origin, this.origin + olddir * this.wait, false, this);
206 traceline(this.origin, eorg, false, this);
208 // Setup adaptive tracelength
209 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));
211 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
212 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
215 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
216 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
221 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
222 this.nextthink = time;// + 0.05; // csqc projectiles
223 UpdateCSQCProjectile(this);
226 void M_Mage_Attack_Spike(entity this, vector dir)
228 makevectors(this.angles);
230 entity missile = spawn();
231 missile.owner = missile.realowner = this;
232 setthink(missile, M_Mage_Attack_Spike_Think);
233 missile.ltime = time + 7;
234 missile.nextthink = time;
235 missile.solid = SOLID_BBOX;
236 set_movetype(missile, MOVETYPE_FLYMISSILE);
237 missile.flags = FL_PROJECTILE;
238 IL_PUSH(g_projectiles, missile);
239 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
240 setsize(missile, '0 0 0', '0 0 0');
241 missile.velocity = dir * 400;
242 missile.avelocity = '300 300 300';
243 missile.enemy = this.enemy;
244 settouch(missile, M_Mage_Attack_Spike_Touch);
246 this.mage_spike = missile;
248 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
251 void M_Mage_Defend_Heal(entity this)
253 float washealed = false;
255 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
264 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);
265 fx = EFFECT_HEALING.eent_eff_name;
268 if(it.ammo_cells) it.ammo_cells = bound(it.ammo_cells, it.ammo_cells + 1, g_pickup_cells_max);
269 if(it.ammo_plasma) it.ammo_plasma = bound(it.ammo_plasma, it.ammo_plasma + 1, g_pickup_plasma_max);
270 if(it.ammo_rockets) it.ammo_rockets = bound(it.ammo_rockets, it.ammo_rockets + 1, g_pickup_rockets_max);
271 if(it.ammo_shells) it.ammo_shells = bound(it.ammo_shells, it.ammo_shells + 2, g_pickup_shells_max);
272 if(it.ammo_nails) it.ammo_nails = bound(it.ammo_nails, it.ammo_nails + 5, g_pickup_nails_max);
276 if(it.armorvalue < autocvar_g_balance_armor_regenstable)
278 it.armorvalue = bound(0, it.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
279 fx = "armorrepair_fx";
283 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);
284 fx = EFFECT_RAGE.eent_eff_name;
288 Send_Effect_(fx, it.origin, '0 0 0', 1);
292 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
293 it.health = bound(0, it.health + (autocvar_g_monster_mage_heal_allies), it.max_health);
294 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
295 WaypointSprite_UpdateHealth(it.sprite, it.health);
301 setanim(this, this.anim_shoot, true, true, true);
302 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
303 this.anim_finished = time + 1.5;
307 void M_Mage_Attack_Push(entity this)
309 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
310 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius), NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, this.enemy);
311 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
313 setanim(this, this.anim_shoot, true, true, true);
314 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
317 void M_Mage_Attack_Teleport(entity this, entity targ)
320 if(vdist(targ.origin - this.origin, >, 1500)) return;
322 makevectors(targ.angles);
323 tracebox(targ.origin + ((v_forward * -1) * 200), this.mins, this.maxs, this.origin, MOVE_NOMONSTERS, this);
325 if(trace_fraction < 1)
328 vector newpos = targ.origin + ((v_forward * -1) * 200);
330 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
331 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
333 setorigin(this, newpos);
335 vector a = vectoangles(targ.origin - this.origin);
339 this.fixangle = true;
340 this.velocity *= 0.5;
342 this.attack_finished_single[0] = time + 0.2;
345 void M_Mage_Defend_Shield_Remove(entity this)
347 this.effects &= ~(EF_ADDITIVE | EF_BLUE);
348 this.armorvalue = autocvar_g_monsters_armor_blockpercent;
351 void M_Mage_Defend_Shield(entity this)
353 this.effects |= (EF_ADDITIVE | EF_BLUE);
354 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
355 this.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
356 this.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
357 setanim(this, this.anim_shoot, true, true, true);
358 this.attack_finished_single[0] = time + 1;
359 this.anim_finished = time + 1;
362 bool M_Mage_Attack(int attack_type, entity actor, entity targ)
364 .entity weaponentity = weaponentities[0];
367 case MONSTER_ATTACK_MELEE:
371 Weapon wep = WEP_MAGE_SPIKE;
373 wep.wr_think(wep, actor, weaponentity, 2);
379 case MONSTER_ATTACK_RANGED:
381 if(!actor.mage_spike)
385 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
386 off.offhand_think(off, actor, true);
391 setanim(actor, actor.anim_shoot, true, true, true);
392 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
393 actor.anim_finished = time + 1;
394 Weapon wep = WEP_MAGE_SPIKE;
395 wep.wr_think(wep, actor, weaponentity, 1);
410 spawnfunc(monster_mage) { Monster_Spawn(this, MON_MAGE.monsterid); }
415 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
418 bool need_help = false;
420 FOREACH_ENTITY_FLOAT(iscreature, true,
423 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
424 if(M_Mage_Defend_Heal_Check(actor, it))
431 if(actor.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
432 if(time >= actor.attack_finished_single[0])
434 M_Mage_Defend_Heal(actor);
436 if(time >= actor.mage_shield_time && actor.armorvalue)
437 M_Mage_Defend_Shield_Remove(actor);
440 if(actor.health < actor.max_health)
441 if(time >= actor.mage_shield_delay)
443 M_Mage_Defend_Shield(actor);
448 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
454 METHOD(Mage, mr_death, bool(Mage this, entity actor))
457 setanim(actor, actor.anim_die1, false, true, true);
463 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
466 vector none = '0 0 0';
467 actor.anim_die1 = animfixfps(actor, '4 1 0.5', none); // 2 seconds
468 actor.anim_walk = animfixfps(actor, '1 1 1', none);
469 actor.anim_idle = animfixfps(actor, '0 1 1', none);
470 actor.anim_pain1 = animfixfps(actor, '3 1 2', none); // 0.5 seconds
471 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
472 actor.anim_run = animfixfps(actor, '5 1 1', none);
478 spawnfunc(item_health_large);
479 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
482 if(!actor.health) actor.health = (autocvar_g_monster_mage_health);
483 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
484 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
485 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
486 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
488 actor.monster_loot = spawnfunc_item_health_large;
489 actor.monster_attackfunc = M_Mage_Attack;
494 METHOD(Mage, mr_precache, bool(Mage this))