]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/mage.qc
a3114812b61f8ccc1ca41ecf5fcb71fc4843bd5e
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / mage.qc
1 #ifndef MENUQC
2 bool M_Mage(int);
3 #endif
4 REGISTER_MONSTER_SIMPLE(
5 /* MON_##id   */ MAGE,
6 /* spawnflags */ MON_FLAG_MELEE | MON_FLAG_RANGED,
7 /* mins,maxs  */ '-36 -36 -24', '36 36 50',
8 /* model      */ "mage.dpm",
9 /* netname    */ "mage",
10 /* fullname   */ _("Mage")
11 ) {
12 #ifndef MENUQC
13     this.monster_func = M_Mage;
14     this.monster_func(MR_PRECACHE);
15 #endif
16 }
17
18 #include "../../weapons/all.qh"
19
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"));
25 ENDCLASS(MageSpike)
26 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike)) {
27         localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", this.netname, 230 + this.m_id - 1));
28 }
29
30 #ifdef SVQC
31
32 void M_Mage_Attack_Spike(vector dir);
33 METHOD(MageSpike, wr_think, bool(entity thiswep)) {
34         SELFPARAM();
35         if (self.BUTTON_ATCK)
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);
42         }
43         return true;
44 }
45
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;
74
75 /*
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;
82 */
83
84 void() M_Mage_Defend_Heal;
85 void() M_Mage_Defend_Shield;
86
87 .entity mage_spike;
88 .float mage_shield_delay;
89 .float mage_shield_time;
90
91 float M_Mage_Defend_Heal_Check(entity e)
92 {SELFPARAM();
93         if(e == world)
94                 return false;
95         if(e.health <= 0)
96                 return false;
97         if(DIFF_TEAM(e, self) && e != self.monster_follow)
98                 return false;
99         if(e.frozen)
100                 return false;
101         if(!IS_PLAYER(e))
102                 return (IS_MONSTER(e) && e.health < e.max_health);
103         if(e.items & ITEM_Shield.m_itemid)
104                 return false;
105
106         switch(self.skin)
107         {
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);
112         }
113
114         return false;
115 }
116
117 void M_Mage_Attack_Spike_Explode()
118 {SELFPARAM();
119         self.event_damage = func_null;
120
121         sound(self, CH_SHOTS, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
122
123         self.realowner.mage_spike = world;
124
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);
127
128         remove (self);
129 }
130
131 void M_Mage_Attack_Spike_Touch()
132 {
133         PROJECTILE_TOUCH;
134
135         M_Mage_Attack_Spike_Explode();
136 }
137
138 // copied from W_Seeker_Think
139 void M_Mage_Attack_Spike_Think()
140 {SELFPARAM();
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();
144         }
145
146         float spd = vlen(self.velocity);
147         spd = bound(
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
151         );
152
153         if (self.enemy != world)
154                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
155                         self.enemy = world;
156
157         if (self.enemy != world)
158         {
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);
165
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)))
168                 {
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);
172                         else
173                                 traceline(self.origin, eorg, false, self);
174
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));
177
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);
180                 }
181
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
184         }
185
186         ///////////////
187
188         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
189         self.nextthink = time;// + 0.05; // csqc projectiles
190         UpdateCSQCProjectile(self);
191 }
192
193 void M_Mage_Attack_Spike(vector dir);
194 void M_Mage_Attack_Spike_Aim()
195 {
196         SELFPARAM();
197         return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
198 }
199
200 void M_Mage_Attack_Spike(vector dir)
201 {
202         SELFPARAM();
203         makevectors(self.angles);
204
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;
219
220         self.mage_spike = missile;
221
222         CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
223 }
224
225 void M_Mage_Defend_Heal()
226 {SELFPARAM();
227         entity head;
228         float washealed = false;
229
230         for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
231         {
232                 washealed = true;
233                 string fx = "";
234                 if(IS_PLAYER(head))
235                 {
236                         switch(self.skin)
237                         {
238                                 case 0:
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;
241                                         break;
242                                 case 1:
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);
248                                         fx = "ammoregen_fx";
249                                         break;
250                                 case 2:
251                                         if(head.armorvalue < autocvar_g_balance_armor_regenstable)
252                                         {
253                                                 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
254                                                 fx = "armorrepair_fx";
255                                         }
256                                         break;
257                                 case 3:
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;
260                                         break;
261                         }
262
263                         Send_Effect_(fx, head.origin, '0 0 0', 1);
264                 }
265                 else
266                 {
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);
271                 }
272         }
273
274         if(washealed)
275         {
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;
279         }
280 }
281
282 void M_Mage_Attack_Push()
283 {SELFPARAM();
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);
287
288         setanim(self, self.anim_shoot, true, true, true);
289         self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
290 }
291
292 void M_Mage_Attack_Teleport()
293 {SELFPARAM();
294         if(vlen(self.enemy.origin - self.origin) >= 500)
295                 return;
296
297         makevectors(self.enemy.angles);
298         tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
299
300         if(trace_fraction < 1)
301                 return;
302
303         Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
304         setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
305
306         self.attack_finished_single = time + 0.2;
307 }
308
309 void M_Mage_Defend_Shield_Remove()
310 {SELFPARAM();
311         self.effects &= ~(EF_ADDITIVE | EF_BLUE);
312         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
313 }
314
315 void M_Mage_Defend_Shield()
316 {SELFPARAM();
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;
324 }
325
326 float M_Mage_Attack(float attack_type)
327 {SELFPARAM();
328         switch(attack_type)
329         {
330                 case MONSTER_ATTACK_MELEE:
331                 {
332                         if(random() <= 0.7)
333                         {
334                                 M_Mage_Attack_Push();
335                                 return true;
336                         }
337
338                         return false;
339                 }
340                 case MONSTER_ATTACK_RANGED:
341                 {
342                         if(!self.mage_spike)
343                         {
344                                 if(random() <= 0.4)
345                                 {
346                                         M_Mage_Attack_Teleport();
347                                         return true;
348                                 }
349                                 else
350                                 {
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);
355                                         return true;
356                                 }
357                         }
358
359                         if(self.mage_spike)
360                                 return true;
361                         else
362                                 return false;
363                 }
364         }
365
366         return false;
367 }
368
369 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
370
371 #endif // SVQC
372
373 bool M_Mage(int req)
374 {SELFPARAM();
375         switch(req)
376         {
377                 #ifdef SVQC
378                 case MR_THINK:
379                 {
380                         entity head;
381                         bool need_help = false;
382
383                         for(head = world; (head = findfloat(head, iscreature, true)); )
384                         if(head != self)
385                         if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
386                         if(M_Mage_Defend_Heal_Check(head))
387                         {
388                                 need_help = true;
389                                 break;
390                         }
391
392                         if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
393                         if(time >= self.attack_finished_single)
394                         if(random() < 0.5)
395                                 M_Mage_Defend_Heal();
396
397                         if(time >= self.mage_shield_time && self.armorvalue)
398                                 M_Mage_Defend_Shield_Remove();
399
400                         if(self.enemy)
401                         if(self.health < self.max_health)
402                         if(time >= self.mage_shield_delay)
403                         if(random() < 0.5)
404                                 M_Mage_Defend_Shield();
405
406                         return true;
407                 }
408                 case MR_PAIN:
409                 {
410                         return true;
411                 }
412                 case MR_DEATH:
413                 {
414                         setanim(self, self.anim_die1, false, true, true);
415                         return true;
416                 }
417                 #endif
418                 #ifndef MENUQC
419                 case MR_ANIM:
420                 {
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);
428
429                         return true;
430                 }
431                 #endif
432                 #ifdef SVQC
433                 case MR_SETUP:
434                 {
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); }
440
441                         self.monster_loot = spawnfunc_item_health_large;
442                         self.monster_attackfunc = M_Mage_Attack;
443
444                         return true;
445                 }
446                 case MR_PRECACHE:
447                 {
448                         precache_sound (W_Sound("grenade_impact"));
449                         precache_sound (W_Sound("tagexp1"));
450                         return true;
451                 }
452                 #endif
453         }
454
455         return true;
456 }