4 REGISTER_MONSTER_SIMPLE(
6 /* spawnflags */ MON_FLAG_MELEE | MON_FLAG_RANGED,
7 /* mins,maxs */ '-36 -36 -24', '36 36 50',
8 /* model */ "mage.dpm",
10 /* fullname */ _("Mage")
13 this.monster_func = M_Mage;
14 this.monster_func(MR_PRECACHE);
18 CLASS(MageSpike, PortoLaunch)
19 /* flags */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER);
20 /* impulse */ ATTRIB(MageSpike, impulse, int, 5);
21 /* refname */ ATTRIB(MageSpike, netname, string, "magespike");
22 /* wepname */ ATTRIB(MageSpike, message, string, _("Mage spike"));
24 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike)) {
25 localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", this.netname, 230 + this.m_id - 1));
30 void M_Mage_Attack_Spike(vector dir);
31 METHOD(MageSpike, wr_think, bool(entity thiswep)) {
34 if (weapon_prepareattack(0, WEP_CVAR_PRI(electro, refire))) {
35 if (!self.target_range) self.target_range = autocvar_g_monsters_target_range;
36 self.enemy = Monster_FindTarget(self);
37 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
38 M_Mage_Attack_Spike(w_shotdir);
39 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
44 float autocvar_g_monster_mage_health;
45 float autocvar_g_monster_mage_damageforcescale = 0.5;
46 float autocvar_g_monster_mage_attack_spike_damage;
47 float autocvar_g_monster_mage_attack_spike_radius;
48 float autocvar_g_monster_mage_attack_spike_delay;
49 float autocvar_g_monster_mage_attack_spike_accel;
50 float autocvar_g_monster_mage_attack_spike_decel;
51 float autocvar_g_monster_mage_attack_spike_turnrate;
52 float autocvar_g_monster_mage_attack_spike_speed_max;
53 float autocvar_g_monster_mage_attack_spike_smart;
54 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
55 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
56 float autocvar_g_monster_mage_attack_spike_smart_mindist;
57 float autocvar_g_monster_mage_attack_push_damage;
58 float autocvar_g_monster_mage_attack_push_radius;
59 float autocvar_g_monster_mage_attack_push_delay;
60 float autocvar_g_monster_mage_attack_push_force;
61 float autocvar_g_monster_mage_heal_self;
62 float autocvar_g_monster_mage_heal_allies;
63 float autocvar_g_monster_mage_heal_minhealth;
64 float autocvar_g_monster_mage_heal_range;
65 float autocvar_g_monster_mage_heal_delay;
66 float autocvar_g_monster_mage_shield_time;
67 float autocvar_g_monster_mage_shield_delay;
68 float autocvar_g_monster_mage_shield_blockpercent;
69 float autocvar_g_monster_mage_speed_stop;
70 float autocvar_g_monster_mage_speed_run;
71 float autocvar_g_monster_mage_speed_walk;
74 const float mage_anim_idle = 0;
75 const float mage_anim_walk = 1;
76 const float mage_anim_attack = 2;
77 const float mage_anim_pain = 3;
78 const float mage_anim_death = 4;
79 const float mage_anim_run = 5;
82 void() M_Mage_Defend_Heal;
83 void() M_Mage_Defend_Shield;
86 .float mage_shield_delay;
87 .float mage_shield_time;
89 float M_Mage_Defend_Heal_Check(entity e)
95 if(DIFF_TEAM(e, self) && e != self.monster_follow)
100 return (IS_MONSTER(e) && e.health < e.max_health);
101 if(e.items & ITEM_Shield.m_itemid)
106 case 0: return (e.health < autocvar_g_balance_health_regenstable);
107 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));
108 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
109 case 3: return (e.health > 0);
115 void M_Mage_Attack_Spike_Explode()
117 self.event_damage = func_null;
119 sound(self, CH_SHOTS, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
121 self.realowner.mage_spike = world;
123 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
124 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);
129 void M_Mage_Attack_Spike_Touch()
133 M_Mage_Attack_Spike_Explode();
136 // copied from W_Seeker_Think
137 void M_Mage_Attack_Spike_Think()
139 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
140 self.projectiledeathtype |= HITTYPE_SPLASH;
141 M_Mage_Attack_Spike_Explode();
144 float spd = vlen(self.velocity);
146 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
147 (autocvar_g_monster_mage_attack_spike_speed_max),
148 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
151 if (self.enemy != world)
152 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
155 if (self.enemy != world)
157 entity e = self.enemy;
158 vector eorg = 0.5 * (e.absmin + e.absmax);
159 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
160 vector desireddir = normalize(eorg - self.origin);
161 vector olddir = normalize(self.velocity); // get my current direction
162 float dist = vlen(eorg - self.origin);
164 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
165 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
167 // Is it a better idea (shorter distance) to trace to the target itself?
168 if ( vlen(self.origin + olddir * self.wait) < dist)
169 traceline(self.origin, self.origin + olddir * self.wait, false, self);
171 traceline(self.origin, eorg, false, self);
173 // Setup adaptive tracelength
174 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));
176 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
177 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
180 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
181 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
186 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
187 self.nextthink = time;// + 0.05; // csqc projectiles
188 UpdateCSQCProjectile(self);
191 void M_Mage_Attack_Spike(vector dir);
192 void M_Mage_Attack_Spike_Aim()
195 return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
198 void M_Mage_Attack_Spike(vector dir)
201 makevectors(self.angles);
203 entity missile = spawn();
204 missile.owner = missile.realowner = self;
205 missile.think = M_Mage_Attack_Spike_Think;
206 missile.ltime = time + 7;
207 missile.nextthink = time;
208 missile.solid = SOLID_BBOX;
209 missile.movetype = MOVETYPE_FLYMISSILE;
210 missile.flags = FL_PROJECTILE;
211 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
212 setsize(missile, '0 0 0', '0 0 0');
213 missile.velocity = dir * 400;
214 missile.avelocity = '300 300 300';
215 missile.enemy = self.enemy;
216 missile.touch = M_Mage_Attack_Spike_Touch;
218 self.mage_spike = missile;
220 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
223 void M_Mage_Defend_Heal()
226 float washealed = false;
228 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
237 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);
238 fx = EFFECT_HEALING.eent_eff_name;
241 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
242 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
243 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
244 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
245 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
249 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
251 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
252 fx = "armorrepair_fx";
256 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);
257 fx = EFFECT_RAGE.eent_eff_name;
261 Send_Effect_(fx, head.origin, '0 0 0', 1);
265 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
266 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
267 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
268 WaypointSprite_UpdateHealth(head.sprite, head.health);
274 setanim(self, self.anim_shoot, true, true, true);
275 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
276 self.anim_finished = time + 1.5;
280 void M_Mage_Attack_Push()
282 sound(self, CH_SHOTS, W_Sound("tagexp1"), 1, ATTEN_NORM);
283 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);
284 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
286 setanim(self, self.anim_shoot, true, true, true);
287 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
290 void M_Mage_Attack_Teleport()
292 if(vlen(self.enemy.origin - self.origin) >= 500)
295 makevectors(self.enemy.angles);
296 tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
298 if(trace_fraction < 1)
301 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
302 setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
304 self.attack_finished_single = time + 0.2;
307 void M_Mage_Defend_Shield_Remove()
309 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
310 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
313 void M_Mage_Defend_Shield()
315 self.effects |= (EF_ADDITIVE | EF_BLUE);
316 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
317 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
318 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
319 setanim(self, self.anim_shoot, true, true, true);
320 self.attack_finished_single = time + 1;
321 self.anim_finished = time + 1;
324 float M_Mage_Attack(float attack_type)
328 case MONSTER_ATTACK_MELEE:
332 M_Mage_Attack_Push();
338 case MONSTER_ATTACK_RANGED:
344 M_Mage_Attack_Teleport();
349 setanim(self, self.anim_shoot, true, true, true);
350 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
351 self.anim_finished = time + 1;
352 Monster_Delay(1, 0, 0.2, M_Mage_Attack_Spike_Aim);
367 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
379 bool need_help = false;
381 for(head = world; (head = findfloat(head, iscreature, true)); )
383 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
384 if(M_Mage_Defend_Heal_Check(head))
390 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
391 if(time >= self.attack_finished_single)
393 M_Mage_Defend_Heal();
395 if(time >= self.mage_shield_time && self.armorvalue)
396 M_Mage_Defend_Shield_Remove();
399 if(self.health < self.max_health)
400 if(time >= self.mage_shield_delay)
402 M_Mage_Defend_Shield();
412 setanim(self, self.anim_die1, false, true, true);
419 vector none = '0 0 0';
420 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
421 self.anim_walk = animfixfps(self, '1 1 1', none);
422 self.anim_idle = animfixfps(self, '0 1 1', none);
423 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
424 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
425 self.anim_run = animfixfps(self, '5 1 1', none);
433 if(!self.health) self.health = (autocvar_g_monster_mage_health);
434 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
435 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
436 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
437 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
439 self.monster_loot = spawnfunc_item_health_large;
440 self.monster_attackfunc = M_Mage_Attack;
446 precache_sound (W_Sound("grenade_impact"));
447 precache_sound (W_Sound("tagexp1"));