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 #include "../../weapons/all.qh"
20 CLASS(MageSpike, PortoLaunch)
21 /* flags */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER);
22 /* impulse */ ATTRIB(MageSpike, impulse, int, 9);
23 /* refname */ ATTRIB(MageSpike, netname, string, "magespike");
24 /* wepname */ ATTRIB(MageSpike, message, string, _("Mage spike"));
26 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike)) {
27 localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", this.netname, 230 + this.m_id - 1));
32 void M_Mage_Attack_Spike(vector dir);
33 METHOD(MageSpike, wr_think, bool(entity thiswep)) {
36 if (weapon_prepareattack(0, WEP_CVAR_PRI(electro, refire))) {
37 if (!self.target_range) self.target_range = autocvar_g_monsters_target_range;
38 self.enemy = Monster_FindTarget(self);
39 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
40 M_Mage_Attack_Spike(w_shotdir);
41 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
46 float autocvar_g_monster_mage_health;
47 float autocvar_g_monster_mage_damageforcescale = 0.5;
48 float autocvar_g_monster_mage_attack_spike_damage;
49 float autocvar_g_monster_mage_attack_spike_radius;
50 float autocvar_g_monster_mage_attack_spike_delay;
51 float autocvar_g_monster_mage_attack_spike_accel;
52 float autocvar_g_monster_mage_attack_spike_decel;
53 float autocvar_g_monster_mage_attack_spike_turnrate;
54 float autocvar_g_monster_mage_attack_spike_speed_max;
55 float autocvar_g_monster_mage_attack_spike_smart;
56 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
57 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
58 float autocvar_g_monster_mage_attack_spike_smart_mindist;
59 float autocvar_g_monster_mage_attack_push_damage;
60 float autocvar_g_monster_mage_attack_push_radius;
61 float autocvar_g_monster_mage_attack_push_delay;
62 float autocvar_g_monster_mage_attack_push_force;
63 float autocvar_g_monster_mage_heal_self;
64 float autocvar_g_monster_mage_heal_allies;
65 float autocvar_g_monster_mage_heal_minhealth;
66 float autocvar_g_monster_mage_heal_range;
67 float autocvar_g_monster_mage_heal_delay;
68 float autocvar_g_monster_mage_shield_time;
69 float autocvar_g_monster_mage_shield_delay;
70 float autocvar_g_monster_mage_shield_blockpercent;
71 float autocvar_g_monster_mage_speed_stop;
72 float autocvar_g_monster_mage_speed_run;
73 float autocvar_g_monster_mage_speed_walk;
76 const float mage_anim_idle = 0;
77 const float mage_anim_walk = 1;
78 const float mage_anim_attack = 2;
79 const float mage_anim_pain = 3;
80 const float mage_anim_death = 4;
81 const float mage_anim_run = 5;
84 void() M_Mage_Defend_Heal;
85 void() M_Mage_Defend_Shield;
88 .float mage_shield_delay;
89 .float mage_shield_time;
91 float M_Mage_Defend_Heal_Check(entity e)
97 if(DIFF_TEAM(e, self) && e != self.monster_follow)
102 return (IS_MONSTER(e) && e.health < e.max_health);
103 if(e.items & ITEM_Shield.m_itemid)
108 case 0: return (e.health < autocvar_g_balance_health_regenstable);
109 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));
110 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
111 case 3: return (e.health > 0);
117 void M_Mage_Attack_Spike_Explode()
119 self.event_damage = func_null;
121 sound(self, CH_SHOTS, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
123 self.realowner.mage_spike = world;
125 Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
126 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);
131 void M_Mage_Attack_Spike_Touch()
135 M_Mage_Attack_Spike_Explode();
138 // copied from W_Seeker_Think
139 void M_Mage_Attack_Spike_Think()
141 if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
142 self.projectiledeathtype |= HITTYPE_SPLASH;
143 M_Mage_Attack_Spike_Explode();
146 float spd = vlen(self.velocity);
148 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
149 (autocvar_g_monster_mage_attack_spike_speed_max),
150 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
153 if (self.enemy != world)
154 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
157 if (self.enemy != world)
159 entity e = self.enemy;
160 vector eorg = 0.5 * (e.absmin + e.absmax);
161 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
162 vector desireddir = normalize(eorg - self.origin);
163 vector olddir = normalize(self.velocity); // get my current direction
164 float dist = vlen(eorg - self.origin);
166 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
167 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
169 // Is it a better idea (shorter distance) to trace to the target itself?
170 if ( vlen(self.origin + olddir * self.wait) < dist)
171 traceline(self.origin, self.origin + olddir * self.wait, false, self);
173 traceline(self.origin, eorg, false, self);
175 // Setup adaptive tracelength
176 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));
178 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
179 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
182 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
183 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
188 //self.angles = vectoangles(self.velocity); // turn model in the new flight direction
189 self.nextthink = time;// + 0.05; // csqc projectiles
190 UpdateCSQCProjectile(self);
193 void M_Mage_Attack_Spike(vector dir);
194 void M_Mage_Attack_Spike_Aim()
197 return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
200 void M_Mage_Attack_Spike(vector dir)
203 makevectors(self.angles);
205 entity missile = spawn();
206 missile.owner = missile.realowner = self;
207 missile.think = M_Mage_Attack_Spike_Think;
208 missile.ltime = time + 7;
209 missile.nextthink = time;
210 missile.solid = SOLID_BBOX;
211 missile.movetype = MOVETYPE_FLYMISSILE;
212 missile.flags = FL_PROJECTILE;
213 setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
214 setsize(missile, '0 0 0', '0 0 0');
215 missile.velocity = dir * 400;
216 missile.avelocity = '300 300 300';
217 missile.enemy = self.enemy;
218 missile.touch = M_Mage_Attack_Spike_Touch;
220 self.mage_spike = missile;
222 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
225 void M_Mage_Defend_Heal()
228 float washealed = false;
230 for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
239 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);
240 fx = EFFECT_HEALING.eent_eff_name;
243 if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
244 if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
245 if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
246 if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
247 if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
251 if(head.armorvalue < autocvar_g_balance_armor_regenstable)
253 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
254 fx = "armorrepair_fx";
258 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);
259 fx = EFFECT_RAGE.eent_eff_name;
263 Send_Effect_(fx, head.origin, '0 0 0', 1);
267 Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
268 head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
269 if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
270 WaypointSprite_UpdateHealth(head.sprite, head.health);
276 setanim(self, self.anim_shoot, true, true, true);
277 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
278 self.anim_finished = time + 1.5;
282 void M_Mage_Attack_Push()
284 sound(self, CH_SHOTS, W_Sound("tagexp1"), 1, ATTEN_NORM);
285 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);
286 Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
288 setanim(self, self.anim_shoot, true, true, true);
289 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
292 void M_Mage_Attack_Teleport()
294 if(vlen(self.enemy.origin - self.origin) >= 500)
297 makevectors(self.enemy.angles);
298 tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
300 if(trace_fraction < 1)
303 Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
304 setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
306 self.attack_finished_single = time + 0.2;
309 void M_Mage_Defend_Shield_Remove()
311 self.effects &= ~(EF_ADDITIVE | EF_BLUE);
312 self.armorvalue = autocvar_g_monsters_armor_blockpercent;
315 void M_Mage_Defend_Shield()
317 self.effects |= (EF_ADDITIVE | EF_BLUE);
318 self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
319 self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
320 self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
321 setanim(self, self.anim_shoot, true, true, true);
322 self.attack_finished_single = time + 1;
323 self.anim_finished = time + 1;
326 float M_Mage_Attack(float attack_type)
330 case MONSTER_ATTACK_MELEE:
334 M_Mage_Attack_Push();
340 case MONSTER_ATTACK_RANGED:
346 M_Mage_Attack_Teleport();
351 setanim(self, self.anim_shoot, true, true, true);
352 self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
353 self.anim_finished = time + 1;
354 Monster_Delay(1, 0, 0.2, M_Mage_Attack_Spike_Aim);
369 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
381 bool need_help = false;
383 for(head = world; (head = findfloat(head, iscreature, true)); )
385 if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
386 if(M_Mage_Defend_Heal_Check(head))
392 if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
393 if(time >= self.attack_finished_single)
395 M_Mage_Defend_Heal();
397 if(time >= self.mage_shield_time && self.armorvalue)
398 M_Mage_Defend_Shield_Remove();
401 if(self.health < self.max_health)
402 if(time >= self.mage_shield_delay)
404 M_Mage_Defend_Shield();
414 setanim(self, self.anim_die1, false, true, true);
421 vector none = '0 0 0';
422 self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
423 self.anim_walk = animfixfps(self, '1 1 1', none);
424 self.anim_idle = animfixfps(self, '0 1 1', none);
425 self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
426 self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
427 self.anim_run = animfixfps(self, '5 1 1', none);
435 if(!self.health) self.health = (autocvar_g_monster_mage_health);
436 if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
437 if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
438 if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
439 if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
441 self.monster_loot = spawnfunc_item_health_large;
442 self.monster_attackfunc = M_Mage_Attack;
448 precache_sound (W_Sound("grenade_impact"));
449 precache_sound (W_Sound("tagexp1"));