]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/mage.qc
d0c6f2e29e377bd2a6f79344f3970b5f6febbd1c
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / mage.qc
1 #ifndef MENUQC
2 bool M_Mage(Monster thismon, 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     MON_ACTION(this, 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
28 #ifdef SVQC
29
30 void M_Mage_Attack_Spike(vector dir);
31 METHOD(MageSpike, wr_think, bool(entity thiswep)) {
32         SELFPARAM();
33         if (self.BUTTON_ATCK)
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);
40         }
41         return true;
42 }
43
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;
72
73 /*
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;
80 */
81
82 void() M_Mage_Defend_Heal;
83 void() M_Mage_Defend_Shield;
84
85 .entity mage_spike;
86 .float mage_shield_delay;
87 .float mage_shield_time;
88
89 float M_Mage_Defend_Heal_Check(entity e)
90 {SELFPARAM();
91         if(e == world)
92                 return false;
93         if(e.health <= 0)
94                 return false;
95         if(DIFF_TEAM(e, self) && e != self.monster_follow)
96                 return false;
97         if(e.frozen)
98                 return false;
99         if(!IS_PLAYER(e))
100                 return (IS_MONSTER(e) && e.health < e.max_health);
101         if(e.items & ITEM_Shield.m_itemid)
102                 return false;
103
104         switch(self.skin)
105         {
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);
110         }
111
112         return false;
113 }
114
115 void M_Mage_Attack_Spike_Explode()
116 {SELFPARAM();
117         self.event_damage = func_null;
118
119         sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
120
121         self.realowner.mage_spike = world;
122
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);
125
126         remove (self);
127 }
128
129 void M_Mage_Attack_Spike_Touch()
130 {
131         PROJECTILE_TOUCH;
132
133         M_Mage_Attack_Spike_Explode();
134 }
135
136 // copied from W_Seeker_Think
137 void M_Mage_Attack_Spike_Think()
138 {SELFPARAM();
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();
142         }
143
144         float spd = vlen(self.velocity);
145         spd = bound(
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
149         );
150
151         if (self.enemy != world)
152                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
153                         self.enemy = world;
154
155         if (self.enemy != world)
156         {
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);
163
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)))
166                 {
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);
170                         else
171                                 traceline(self.origin, eorg, false, self);
172
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));
175
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);
178                 }
179
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
182         }
183
184         ///////////////
185
186         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
187         self.nextthink = time;// + 0.05; // csqc projectiles
188         UpdateCSQCProjectile(self);
189 }
190
191 void M_Mage_Attack_Spike(vector dir);
192 void M_Mage_Attack_Spike_Aim()
193 {
194         SELFPARAM();
195         return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
196 }
197
198 void M_Mage_Attack_Spike(vector dir)
199 {
200         SELFPARAM();
201         makevectors(self.angles);
202
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;
217
218         self.mage_spike = missile;
219
220         CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
221 }
222
223 void M_Mage_Defend_Heal()
224 {SELFPARAM();
225         entity head;
226         float washealed = false;
227
228         for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
229         {
230                 washealed = true;
231                 string fx = "";
232                 if(IS_PLAYER(head))
233                 {
234                         switch(self.skin)
235                         {
236                                 case 0:
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;
239                                         break;
240                                 case 1:
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);
246                                         fx = "ammoregen_fx";
247                                         break;
248                                 case 2:
249                                         if(head.armorvalue < autocvar_g_balance_armor_regenstable)
250                                         {
251                                                 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
252                                                 fx = "armorrepair_fx";
253                                         }
254                                         break;
255                                 case 3:
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;
258                                         break;
259                         }
260
261                         Send_Effect_(fx, head.origin, '0 0 0', 1);
262                 }
263                 else
264                 {
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);
269                 }
270         }
271
272         if(washealed)
273         {
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;
277         }
278 }
279
280 void M_Mage_Attack_Push()
281 {SELFPARAM();
282         sound(self, CH_SHOTS, SND_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);
285
286         setanim(self, self.anim_shoot, true, true, true);
287         self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
288 }
289
290 void M_Mage_Attack_Teleport()
291 {SELFPARAM();
292         if(vlen(self.enemy.origin - self.origin) >= 500)
293                 return;
294
295         makevectors(self.enemy.angles);
296         tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
297
298         if(trace_fraction < 1)
299                 return;
300
301         Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
302         setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
303
304         self.attack_finished_single = time + 0.2;
305 }
306
307 void M_Mage_Defend_Shield_Remove()
308 {SELFPARAM();
309         self.effects &= ~(EF_ADDITIVE | EF_BLUE);
310         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
311 }
312
313 void M_Mage_Defend_Shield()
314 {SELFPARAM();
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;
322 }
323
324 float M_Mage_Attack(float attack_type)
325 {SELFPARAM();
326         switch(attack_type)
327         {
328                 case MONSTER_ATTACK_MELEE:
329                 {
330                         if(random() <= 0.7)
331                         {
332                                 M_Mage_Attack_Push();
333                                 return true;
334                         }
335
336                         return false;
337                 }
338                 case MONSTER_ATTACK_RANGED:
339                 {
340                         if(!self.mage_spike)
341                         {
342                                 if(random() <= 0.4)
343                                 {
344                                         M_Mage_Attack_Teleport();
345                                         return true;
346                                 }
347                                 else
348                                 {
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);
353                                         return true;
354                                 }
355                         }
356
357                         if(self.mage_spike)
358                                 return true;
359                         else
360                                 return false;
361                 }
362         }
363
364         return false;
365 }
366
367 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
368
369 #endif // SVQC
370
371 bool M_Mage(Monster thismon, int req)
372 {SELFPARAM();
373         switch(req)
374         {
375                 #ifdef SVQC
376                 case MR_THINK:
377                 {
378                         entity head;
379                         bool need_help = false;
380
381                         for(head = world; (head = findfloat(head, iscreature, true)); )
382                         if(head != self)
383                         if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
384                         if(M_Mage_Defend_Heal_Check(head))
385                         {
386                                 need_help = true;
387                                 break;
388                         }
389
390                         if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
391                         if(time >= self.attack_finished_single)
392                         if(random() < 0.5)
393                                 M_Mage_Defend_Heal();
394
395                         if(time >= self.mage_shield_time && self.armorvalue)
396                                 M_Mage_Defend_Shield_Remove();
397
398                         if(self.enemy)
399                         if(self.health < self.max_health)
400                         if(time >= self.mage_shield_delay)
401                         if(random() < 0.5)
402                                 M_Mage_Defend_Shield();
403
404                         return true;
405                 }
406                 case MR_PAIN:
407                 {
408                         return true;
409                 }
410                 case MR_DEATH:
411                 {
412                         setanim(self, self.anim_die1, false, true, true);
413                         return true;
414                 }
415                 #endif
416                 #ifndef MENUQC
417                 case MR_ANIM:
418                 {
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);
426
427                         return true;
428                 }
429                 #endif
430                 #ifdef SVQC
431                 case MR_SETUP:
432                 {
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); }
438
439                         self.monster_loot = spawnfunc_item_health_large;
440                         self.monster_attackfunc = M_Mage_Attack;
441
442                         return true;
443                 }
444                 case MR_PRECACHE:
445                 {
446                         return true;
447                 }
448                 #endif
449         }
450
451         return true;
452 }