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);
19 float autocvar_g_monster_mage_health;
20 float autocvar_g_monster_mage_damageforcescale = 0.5;
21 float autocvar_g_monster_mage_attack_spike_damage;
22 float autocvar_g_monster_mage_attack_spike_radius;
23 float autocvar_g_monster_mage_attack_spike_delay;
24 float autocvar_g_monster_mage_attack_spike_accel;
25 float autocvar_g_monster_mage_attack_spike_decel;
26 float autocvar_g_monster_mage_attack_spike_turnrate;
27 float autocvar_g_monster_mage_attack_spike_speed_max;
28 float autocvar_g_monster_mage_attack_spike_smart;
29 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
30 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
31 float autocvar_g_monster_mage_attack_spike_smart_mindist;
32 float autocvar_g_monster_mage_attack_push_damage;
33 float autocvar_g_monster_mage_attack_push_radius;
34 float autocvar_g_monster_mage_attack_push_delay;
35 float autocvar_g_monster_mage_attack_push_force;
36 float autocvar_g_monster_mage_heal_self;
37 float autocvar_g_monster_mage_heal_allies;
38 float autocvar_g_monster_mage_heal_minhealth;
39 float autocvar_g_monster_mage_heal_range;
40 float autocvar_g_monster_mage_heal_delay;
41 float autocvar_g_monster_mage_shield_time;
42 float autocvar_g_monster_mage_shield_delay;
43 float autocvar_g_monster_mage_shield_blockpercent;
44 float autocvar_g_monster_mage_speed_stop;
45 float autocvar_g_monster_mage_speed_run;
46 float autocvar_g_monster_mage_speed_walk;
49 const float mage_anim_idle = 0;
50 const float mage_anim_walk = 1;
51 const float mage_anim_attack = 2;
52 const float mage_anim_pain = 3;
53 const float mage_anim_death = 4;
54 const float mage_anim_run = 5;
57 void() M_Mage_Defend_Heal;
58 void() M_Mage_Defend_Shield;
61 .float mage_shield_delay;
62 .float mage_shield_time;
64 float M_Mage_Defend_Heal_Check(entity e)
70 if(DIFF_TEAM(e, self) && e != self.monster_follow)
75 return (IS_MONSTER(e) && e.health < e.max_health);
76 if(e.items & ITEM_Shield.m_itemid)
81 case 0: return (e.health < autocvar_g_balance_health_regenstable);
82 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));
83 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
84 case 3: return (e.health > 0);
90 void M_Mage_Attack_Spike_Explode()
92 self.event_damage = func_null;
94 sound(self, CH_SHOTS, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
96 self.realowner.mage_spike = world;
98 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
99 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);
104 void M_Mage_Attack_Spike_Touch()
108 M_Mage_Attack_Spike_Explode();
111 // copied from W_Seeker_Think
112 void M_Mage_Attack_Spike_Think()
115 vector desireddir, olddir, newdir, eorg;
120 if (time > self.ltime || self.enemy.health <= 0 || self.owner.health <= 0)
122 self.projectiledeathtype |= HITTYPE_SPLASH;
123 M_Mage_Attack_Spike_Explode();
126 spd = vlen(self.velocity);
128 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
129 (autocvar_g_monster_mage_attack_spike_speed_max),
130 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
133 if (self.enemy != world)
134 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
137 if (self.enemy != world)
140 eorg = 0.5 * (e.absmin + e.absmax);
141 turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
142 desireddir = normalize(eorg - self.origin);
143 olddir = normalize(self.velocity); // get my current direction
144 dist = vlen(eorg - self.origin);
146 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
147 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
149 // Is it a better idea (shorter distance) to trace to the target itself?
150 if ( vlen(self.origin + olddir * self.wait) < dist)
151 traceline(self.origin, self.origin + olddir * self.wait, false, self);
153 traceline(self.origin, eorg, false, self);
155 // Setup adaptive tracelength
156 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));
158 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
159 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
162 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
163 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
170 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
171 self.nextthink = time;// + 0.05; // csqc projectiles
172 UpdateCSQCProjectile(self);
175 void M_Mage_Attack_Spike()
178 vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
180 makevectors(self.angles);
183 missile.owner = missile.realowner = self;
184 missile.think = M_Mage_Attack_Spike_Think;
185 missile.ltime = time + 7;
186 missile.nextthink = time;
187 missile.solid = SOLID_BBOX;
188 missile.movetype = MOVETYPE_FLYMISSILE;
189 missile.flags = FL_PROJECTILE;
190 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
191 setsize (missile, '0 0 0', '0 0 0');
192 missile.velocity = dir * 400;
193 missile.avelocity = '300 300 300';
194 missile.enemy = self.enemy;
195 missile.touch = M_Mage_Attack_Spike_Touch;
197 self.mage_spike = missile;
199 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
202 void M_Mage_Defend_Heal()
205 float washealed = false;
207 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
216 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);
217 fx = EFFECT_HEALING.eent_eff_name;
220 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
221 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
222 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
223 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
224 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
228 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
230 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
231 fx = "armorrepair_fx";
235 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);
236 fx = EFFECT_RAGE.eent_eff_name;
240 Send_Effect_(fx, head.origin, '0 0 0', 1);
244 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
245 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
246 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
247 WaypointSprite_UpdateHealth(head.sprite, head.health);
253 setanim(self, self.anim_shoot, true, true, true);
254 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
255 self.anim_finished = time + 1.5;
259 void M_Mage_Attack_Push()
261 sound(self, CH_SHOTS, W_Sound("tagexp1"), 1, ATTEN_NORM);
262 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);
263 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
265 setanim(self, self.anim_shoot, true, true, true);
266 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
269 void M_Mage_Attack_Teleport()
271 if(vlen(self.enemy.origin - self.origin) >= 500)
274 makevectors(self.enemy.angles);
275 tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
277 if(trace_fraction < 1)
280 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
281 setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
283 self.attack_finished_single = time + 0.2;
286 void M_Mage_Defend_Shield_Remove()
288 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
289 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
292 void M_Mage_Defend_Shield()
294 self.effects |= (EF_ADDITIVE | EF_BLUE);
295 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
296 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
297 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
298 setanim(self, self.anim_shoot, true, true, true);
299 self.attack_finished_single = time + 1;
300 self.anim_finished = time + 1;
303 float M_Mage_Attack(float attack_type)
307 case MONSTER_ATTACK_MELEE:
311 M_Mage_Attack_Push();
317 case MONSTER_ATTACK_RANGED:
323 M_Mage_Attack_Teleport();
328 setanim(self, self.anim_shoot, true, true, true);
329 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
330 self.anim_finished = time + 1;
331 Monster_Delay(1, 0, 0.2, M_Mage_Attack_Spike);
346 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
358 bool need_help = false;
360 for(head = world; (head = findfloat(head, iscreature, true)); )
362 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
363 if(M_Mage_Defend_Heal_Check(head))
369 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
370 if(time >= self.attack_finished_single)
372 M_Mage_Defend_Heal();
374 if(time >= self.mage_shield_time && self.armorvalue)
375 M_Mage_Defend_Shield_Remove();
378 if(self.health < self.max_health)
379 if(time >= self.mage_shield_delay)
381 M_Mage_Defend_Shield();
391 setanim(self, self.anim_die1, false, true, true);
398 vector none = '0 0 0';
399 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
400 self.anim_walk = animfixfps(self, '1 1 1', none);
401 self.anim_idle = animfixfps(self, '0 1 1', none);
402 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
403 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
404 self.anim_run = animfixfps(self, '5 1 1', none);
412 if(!self.health) self.health = (autocvar_g_monster_mage_health);
413 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
414 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
415 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
416 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
418 self.monster_loot = spawnfunc_item_health_large;
419 self.monster_attackfunc = M_Mage_Attack;
425 precache_model("models/monsters/mage.dpm");
426 precache_sound (W_Sound("grenade_impact"));
427 precache_sound (W_Sound("tagexp1"));