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;
18 float autocvar_g_monster_mage_health;
19 float autocvar_g_monster_mage_attack_spike_damage;
20 float autocvar_g_monster_mage_attack_spike_radius;
21 float autocvar_g_monster_mage_attack_spike_delay;
22 float autocvar_g_monster_mage_attack_spike_accel;
23 float autocvar_g_monster_mage_attack_spike_decel;
24 float autocvar_g_monster_mage_attack_spike_turnrate;
25 float autocvar_g_monster_mage_attack_spike_speed_max;
26 float autocvar_g_monster_mage_attack_spike_smart;
27 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
28 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
29 float autocvar_g_monster_mage_attack_spike_smart_mindist;
30 float autocvar_g_monster_mage_attack_push_damage;
31 float autocvar_g_monster_mage_attack_push_radius;
32 float autocvar_g_monster_mage_attack_push_delay;
33 float autocvar_g_monster_mage_attack_push_force;
34 float autocvar_g_monster_mage_heal_self;
35 float autocvar_g_monster_mage_heal_allies;
36 float autocvar_g_monster_mage_heal_minhealth;
37 float autocvar_g_monster_mage_heal_range;
38 float autocvar_g_monster_mage_heal_delay;
39 float autocvar_g_monster_mage_shield_time;
40 float autocvar_g_monster_mage_shield_delay;
41 float autocvar_g_monster_mage_shield_blockpercent;
42 float autocvar_g_monster_mage_speed_stop;
43 float autocvar_g_monster_mage_speed_run;
44 float autocvar_g_monster_mage_speed_walk;
46 const float mage_anim_idle = 0;
47 const float mage_anim_walk = 1;
48 const float mage_anim_attack = 2;
49 const float mage_anim_pain = 3;
50 const float mage_anim_death = 4;
51 const float mage_anim_run = 5;
59 float friend_needshelp(entity e)
65 if(DIFF_TEAM(e, self) && e != self.monster_owner)
70 return ((e.flags & FL_MONSTER) && e.health < e.max_health);
71 if(e.items & IT_INVINCIBLE)
76 case 0: return (e.health < autocvar_g_balance_health_regenstable);
77 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));
78 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
79 case 3: return (e.health > 0);
85 void mage_spike_explode()
87 self.event_damage = func_null;
89 sound(self, CH_SHOTS, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
91 self.realowner.mage_spike = world;
93 pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
94 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);
99 void mage_spike_touch()
103 mage_spike_explode();
106 // copied from W_Seeker_Think
107 void mage_spike_think()
110 vector desireddir, olddir, newdir, eorg;
115 if (time > self.ltime || self.enemy.health <= 0 || self.owner.health <= 0)
117 self.projectiledeathtype |= HITTYPE_SPLASH;
118 mage_spike_explode();
121 spd = vlen(self.velocity);
123 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
124 (autocvar_g_monster_mage_attack_spike_speed_max),
125 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
128 if (self.enemy != world)
129 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
132 if (self.enemy != world)
135 eorg = 0.5 * (e.absmin + e.absmax);
136 turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
137 desireddir = normalize(eorg - self.origin);
138 olddir = normalize(self.velocity); // get my current direction
139 dist = vlen(eorg - self.origin);
141 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
142 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
144 // Is it a better idea (shorter distance) to trace to the target itself?
145 if ( vlen(self.origin + olddir * self.wait) < dist)
146 traceline(self.origin, self.origin + olddir * self.wait, false, self);
148 traceline(self.origin, eorg, false, self);
150 // Setup adaptive tracelength
151 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));
153 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
154 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
157 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
158 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
165 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
166 self.nextthink = time;// + 0.05; // csqc projectiles
167 UpdateCSQCProjectile(self);
170 void mage_attack_spike()
173 vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
175 makevectors(self.angles);
178 missile.owner = missile.realowner = self;
179 missile.think = mage_spike_think;
180 missile.ltime = time + 7;
181 missile.nextthink = time;
182 missile.solid = SOLID_BBOX;
183 missile.movetype = MOVETYPE_FLYMISSILE;
184 missile.flags = FL_PROJECTILE;
185 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
186 setsize (missile, '0 0 0', '0 0 0');
187 missile.velocity = dir * 400;
188 missile.avelocity = '300 300 300';
189 missile.enemy = self.enemy;
190 missile.touch = mage_spike_touch;
192 self.mage_spike = missile;
194 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
200 float washealed = false;
202 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(friend_needshelp(head))
211 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);
215 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
216 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
217 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
218 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
219 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
223 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
225 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
226 fx = "armorrepair_fx";
230 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);
235 pointparticles(particleeffectnum(fx), head.origin, '0 0 0', 1);
239 pointparticles(particleeffectnum("healing_fx"), head.origin, '0 0 0', 1);
240 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
241 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE))
242 WaypointSprite_UpdateHealth(head.sprite, head.health);
248 self.frame = mage_anim_attack;
249 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
255 sound(self, CH_SHOTS, "weapons/tagexp1.wav", 1, ATTEN_NORM);
256 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);
257 pointparticles(particleeffectnum("TE_EXPLOSION"), self.origin, '0 0 0', 1);
259 self.frame = mage_anim_attack;
260 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
265 if(vlen(self.enemy.origin - self.origin) >= 500)
268 makevectors(self.enemy.angles);
269 tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
271 if(trace_fraction < 1)
274 pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1);
275 setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
277 self.attack_finished_single = time + 0.2;
280 void mage_shield_remove()
282 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
284 self.m_armor_blockpercent = autocvar_g_monsters_armor_blockpercent;
289 self.effects |= (EF_ADDITIVE | EF_BLUE);
290 self.lastshielded = time + (autocvar_g_monster_mage_shield_delay);
291 self.m_armor_blockpercent = (autocvar_g_monster_mage_shield_blockpercent);
292 self.armorvalue = self.health;
293 self.shield_ltime = time + (autocvar_g_monster_mage_shield_time);
294 self.frame = mage_anim_attack;
295 self.attack_finished_single = time + 1;
298 float mage_attack(float attack_type)
302 case MONSTER_ATTACK_MELEE:
312 case MONSTER_ATTACK_RANGED:
323 self.frame = mage_anim_attack;
324 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
325 defer(0.2, mage_attack_spike);
340 void spawnfunc_monster_mage()
342 self.classname = "monster_mage";
344 if(!monster_initialize(MON_MAGE.monsterid)) { remove(self); return; }
347 // compatibility with old spawns
348 void spawnfunc_monster_shalrath() { spawnfunc_monster_mage(); }
350 float m_mage(float req)
357 float need_help = false;
359 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain)
361 if(friend_needshelp(head))
367 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
368 if(time >= self.attack_finished_single)
372 if(time >= self.shield_ltime && self.armorvalue)
373 mage_shield_remove();
376 if(self.health < self.max_health)
377 if(time >= self.lastshielded)
381 monster_move((autocvar_g_monster_mage_speed_run), (autocvar_g_monster_mage_speed_walk), (autocvar_g_monster_mage_speed_stop), mage_anim_walk, mage_anim_run, mage_anim_idle);
386 self.frame = mage_anim_death;
391 if(!self.health) self.health = (autocvar_g_monster_mage_health);
393 self.monster_loot = spawnfunc_item_health_large;
394 self.monster_attackfunc = mage_attack;
395 self.frame = mage_anim_walk;
401 precache_model("models/monsters/mage.dpm");
402 precache_sound ("weapons/grenade_impact.wav");
403 precache_sound ("weapons/tagexp1.wav");
413 float m_mage(float req)