]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/mage.qc
0030a4fa81b0f0b1330bd8ee14bcbf90a4638d12
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / mage.qc
1 #ifndef MAGE_H
2 #define MAGE_H
3
4 #ifndef MENUQC
5 MODEL(MON_MAGE, "models/monsters/mage.dpm");
6 #endif
7
8 CLASS(Mage, Monster)
9     ATTRIB(Mage, spawnflags, int, MON_FLAG_MELEE | MON_FLAG_RANGED);
10     ATTRIB(Mage, mins, vector, '-36 -36 -24');
11     ATTRIB(Mage, maxs, vector, '36 36 50');
12 #ifndef MENUQC
13     ATTRIB(Mage, m_model, Model, MDL_MON_MAGE);
14 #endif
15     ATTRIB(Mage, netname, string, "mage");
16     ATTRIB(Mage, monster_name, string, _("Mage"));
17 ENDCLASS(Mage)
18
19 REGISTER_MONSTER(MAGE, NEW(Mage)) {
20 #ifndef MENUQC
21     MON_ACTION(this, MR_PRECACHE);
22 #endif
23 }
24
25 #include "../../weapons/all.qh"
26
27 CLASS(MageSpike, PortoLaunch)
28 /* flags     */ ATTRIB(MageSpike, spawnflags, int, WEP_TYPE_OTHER);
29 /* impulse   */ ATTRIB(MageSpike, impulse, int, 9);
30 /* refname   */ ATTRIB(MageSpike, netname, string, "magespike");
31 /* wepname   */ ATTRIB(MageSpike, message, string, _("Mage spike"));
32 ENDCLASS(MageSpike)
33 REGISTER_WEAPON(MAGE_SPIKE, NEW(MageSpike));
34
35 #endif
36
37 #ifdef IMPLEMENTATION
38
39 #ifdef SVQC
40
41 void M_Mage_Attack_Spike(vector dir);
42 METHOD(MageSpike, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
43         SELFPARAM();
44         if (fire1)
45         if (weapon_prepareattack(0, WEP_CVAR_PRI(electro, refire))) {
46                 if (!self.target_range) self.target_range = autocvar_g_monsters_target_range;
47                 self.enemy = Monster_FindTarget(self);
48                 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
49                 M_Mage_Attack_Spike(w_shotdir);
50                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
51         }
52         return true;
53 }
54
55 float autocvar_g_monster_mage_health;
56 float autocvar_g_monster_mage_damageforcescale = 0.5;
57 float autocvar_g_monster_mage_attack_spike_damage;
58 float autocvar_g_monster_mage_attack_spike_radius;
59 float autocvar_g_monster_mage_attack_spike_delay;
60 float autocvar_g_monster_mage_attack_spike_accel;
61 float autocvar_g_monster_mage_attack_spike_decel;
62 float autocvar_g_monster_mage_attack_spike_turnrate;
63 float autocvar_g_monster_mage_attack_spike_speed_max;
64 float autocvar_g_monster_mage_attack_spike_smart;
65 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
66 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
67 float autocvar_g_monster_mage_attack_spike_smart_mindist;
68 float autocvar_g_monster_mage_attack_push_damage;
69 float autocvar_g_monster_mage_attack_push_radius;
70 float autocvar_g_monster_mage_attack_push_delay;
71 float autocvar_g_monster_mage_attack_push_force;
72 float autocvar_g_monster_mage_heal_self;
73 float autocvar_g_monster_mage_heal_allies;
74 float autocvar_g_monster_mage_heal_minhealth;
75 float autocvar_g_monster_mage_heal_range;
76 float autocvar_g_monster_mage_heal_delay;
77 float autocvar_g_monster_mage_shield_time;
78 float autocvar_g_monster_mage_shield_delay;
79 float autocvar_g_monster_mage_shield_blockpercent;
80 float autocvar_g_monster_mage_speed_stop;
81 float autocvar_g_monster_mage_speed_run;
82 float autocvar_g_monster_mage_speed_walk;
83
84 /*
85 const float mage_anim_idle              = 0;
86 const float mage_anim_walk              = 1;
87 const float mage_anim_attack    = 2;
88 const float mage_anim_pain              = 3;
89 const float mage_anim_death             = 4;
90 const float mage_anim_run               = 5;
91 */
92
93 void() M_Mage_Defend_Heal;
94 void() M_Mage_Defend_Shield;
95
96 .entity mage_spike;
97 .float mage_shield_delay;
98 .float mage_shield_time;
99
100 float M_Mage_Defend_Heal_Check(entity e)
101 {SELFPARAM();
102         if(e == world)
103                 return false;
104         if(e.health <= 0)
105                 return false;
106         if(DIFF_TEAM(e, self) && e != self.monster_follow)
107                 return false;
108         if(e.frozen)
109                 return false;
110         if(!IS_PLAYER(e))
111                 return (IS_MONSTER(e) && e.health < e.max_health);
112         if(e.items & ITEM_Shield.m_itemid)
113                 return false;
114
115         switch(self.skin)
116         {
117                 case 0: return (e.health < autocvar_g_balance_health_regenstable);
118                 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));
119                 case 2: return (e.armorvalue < autocvar_g_balance_armor_regenstable);
120                 case 3: return (e.health > 0);
121         }
122
123         return false;
124 }
125
126 void M_Mage_Attack_Spike_Explode()
127 {SELFPARAM();
128         self.event_damage = func_null;
129
130         sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
131
132         self.realowner.mage_spike = world;
133
134         Send_Effect(EFFECT_EXPLOSION_SMALL, self.origin, '0 0 0', 1);
135         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);
136
137         remove (self);
138 }
139
140 void M_Mage_Attack_Spike_Touch()
141 {
142         PROJECTILE_TOUCH;
143
144         M_Mage_Attack_Spike_Explode();
145 }
146
147 // copied from W_Seeker_Think
148 void M_Mage_Attack_Spike_Think()
149 {SELFPARAM();
150         if (time > self.ltime || (self.enemy && self.enemy.health <= 0) || self.owner.health <= 0) {
151                 self.projectiledeathtype |= HITTYPE_SPLASH;
152                 M_Mage_Attack_Spike_Explode();
153         }
154
155         float spd = vlen(self.velocity);
156         spd = bound(
157                 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
158                 (autocvar_g_monster_mage_attack_spike_speed_max),
159                 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
160         );
161
162         if (self.enemy != world)
163                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
164                         self.enemy = world;
165
166         if (self.enemy != world)
167         {
168                 entity e = self.enemy;
169                 vector eorg = 0.5 * (e.absmin + e.absmax);
170                 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
171                 vector desireddir = normalize(eorg - self.origin);
172                 vector olddir = normalize(self.velocity); // get my current direction
173                 float dist = vlen(eorg - self.origin);
174
175                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
176                 if ((autocvar_g_monster_mage_attack_spike_smart) && (dist > (autocvar_g_monster_mage_attack_spike_smart_mindist)))
177                 {
178                         // Is it a better idea (shorter distance) to trace to the target itself?
179                         if ( vlen(self.origin + olddir * self.wait) < dist)
180                                 traceline(self.origin, self.origin + olddir * self.wait, false, self);
181                         else
182                                 traceline(self.origin, eorg, false, self);
183
184                         // Setup adaptive tracelength
185                         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));
186
187                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
188                         desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
189                 }
190
191                 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
192                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
193         }
194
195         ///////////////
196
197         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
198         self.nextthink = time;// + 0.05; // csqc projectiles
199         UpdateCSQCProjectile(self);
200 }
201
202 void M_Mage_Attack_Spike(vector dir);
203 void M_Mage_Attack_Spike_Aim()
204 {
205         SELFPARAM();
206         return M_Mage_Attack_Spike(normalize((self.enemy.origin + '0 0 10') - self.origin));
207 }
208
209 void M_Mage_Attack_Spike(vector dir)
210 {
211         SELFPARAM();
212         makevectors(self.angles);
213
214         entity missile = spawn();
215         missile.owner = missile.realowner = self;
216         missile.think = M_Mage_Attack_Spike_Think;
217         missile.ltime = time + 7;
218         missile.nextthink = time;
219         missile.solid = SOLID_BBOX;
220         missile.movetype = MOVETYPE_FLYMISSILE;
221         missile.flags = FL_PROJECTILE;
222         setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
223         setsize(missile, '0 0 0', '0 0 0');
224         missile.velocity = dir * 400;
225         missile.avelocity = '300 300 300';
226         missile.enemy = self.enemy;
227         missile.touch = M_Mage_Attack_Spike_Touch;
228
229         self.mage_spike = missile;
230
231         CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
232 }
233
234 void M_Mage_Defend_Heal()
235 {SELFPARAM();
236         entity head;
237         float washealed = false;
238
239         for(head = findradius(self.origin, (autocvar_g_monster_mage_heal_range)); head; head = head.chain) if(M_Mage_Defend_Heal_Check(head))
240         {
241                 washealed = true;
242                 string fx = "";
243                 if(IS_PLAYER(head))
244                 {
245                         switch(self.skin)
246                         {
247                                 case 0:
248                                         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);
249                                         fx = EFFECT_HEALING.eent_eff_name;
250                                         break;
251                                 case 1:
252                                         if(head.ammo_cells) head.ammo_cells = bound(head.ammo_cells, head.ammo_cells + 1, g_pickup_cells_max);
253                                         if(head.ammo_plasma) head.ammo_plasma = bound(head.ammo_plasma, head.ammo_plasma + 1, g_pickup_plasma_max);
254                                         if(head.ammo_rockets) head.ammo_rockets = bound(head.ammo_rockets, head.ammo_rockets + 1, g_pickup_rockets_max);
255                                         if(head.ammo_shells) head.ammo_shells = bound(head.ammo_shells, head.ammo_shells + 2, g_pickup_shells_max);
256                                         if(head.ammo_nails) head.ammo_nails = bound(head.ammo_nails, head.ammo_nails + 5, g_pickup_nails_max);
257                                         fx = "ammoregen_fx";
258                                         break;
259                                 case 2:
260                                         if(head.armorvalue < autocvar_g_balance_armor_regenstable)
261                                         {
262                                                 head.armorvalue = bound(0, head.armorvalue + (autocvar_g_monster_mage_heal_allies), autocvar_g_balance_armor_regenstable);
263                                                 fx = "armorrepair_fx";
264                                         }
265                                         break;
266                                 case 3:
267                                         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);
268                                         fx = EFFECT_RAGE.eent_eff_name;
269                                         break;
270                         }
271
272                         Send_Effect_(fx, head.origin, '0 0 0', 1);
273                 }
274                 else
275                 {
276                         Send_Effect(EFFECT_HEALING, head.origin, '0 0 0', 1);
277                         head.health = bound(0, head.health + (autocvar_g_monster_mage_heal_allies), head.max_health);
278                         if(!(head.spawnflags & MONSTERFLAG_INVINCIBLE) && head.sprite)
279                                 WaypointSprite_UpdateHealth(head.sprite, head.health);
280                 }
281         }
282
283         if(washealed)
284         {
285                 setanim(self, self.anim_shoot, true, true, true);
286                 self.attack_finished_single = time + (autocvar_g_monster_mage_heal_delay);
287                 self.anim_finished = time + 1.5;
288         }
289 }
290
291 void M_Mage_Attack_Push()
292 {SELFPARAM();
293         sound(self, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
294         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);
295         Send_Effect(EFFECT_TE_EXPLOSION, self.origin, '0 0 0', 1);
296
297         setanim(self, self.anim_shoot, true, true, true);
298         self.attack_finished_single = time + (autocvar_g_monster_mage_attack_push_delay);
299 }
300
301 void M_Mage_Attack_Teleport()
302 {SELFPARAM();
303         if(vlen(self.enemy.origin - self.origin) >= 500)
304                 return;
305
306         makevectors(self.enemy.angles);
307         tracebox(self.enemy.origin + ((v_forward * -1) * 200), self.mins, self.maxs, self.origin, MOVE_NOMONSTERS, self);
308
309         if(trace_fraction < 1)
310                 return;
311
312         Send_Effect(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1);
313         setorigin(self, self.enemy.origin + ((v_forward * -1) * 200));
314
315         self.attack_finished_single = time + 0.2;
316 }
317
318 void M_Mage_Defend_Shield_Remove()
319 {SELFPARAM();
320         self.effects &= ~(EF_ADDITIVE | EF_BLUE);
321         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
322 }
323
324 void M_Mage_Defend_Shield()
325 {SELFPARAM();
326         self.effects |= (EF_ADDITIVE | EF_BLUE);
327         self.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
328         self.armorvalue = (autocvar_g_monster_mage_shield_blockpercent);
329         self.mage_shield_time = time + (autocvar_g_monster_mage_shield_time);
330         setanim(self, self.anim_shoot, true, true, true);
331         self.attack_finished_single = time + 1;
332         self.anim_finished = time + 1;
333 }
334
335 float M_Mage_Attack(float attack_type)
336 {SELFPARAM();
337         switch(attack_type)
338         {
339                 case MONSTER_ATTACK_MELEE:
340                 {
341                         if(random() <= 0.7)
342                         {
343                                 M_Mage_Attack_Push();
344                                 return true;
345                         }
346
347                         return false;
348                 }
349                 case MONSTER_ATTACK_RANGED:
350                 {
351                         if(!self.mage_spike)
352                         {
353                                 if(random() <= 0.4)
354                                 {
355                                         M_Mage_Attack_Teleport();
356                                         return true;
357                                 }
358                                 else
359                                 {
360                                         setanim(self, self.anim_shoot, true, true, true);
361                                         self.attack_finished_single = time + (autocvar_g_monster_mage_attack_spike_delay);
362                                         self.anim_finished = time + 1;
363                                         Monster_Delay(1, 0, 0.2, M_Mage_Attack_Spike_Aim);
364                                         return true;
365                                 }
366                         }
367
368                         if(self.mage_spike)
369                                 return true;
370                         else
371                                 return false;
372                 }
373         }
374
375         return false;
376 }
377
378 void spawnfunc_monster_mage() { Monster_Spawn(MON_MAGE.monsterid); }
379
380 #endif // SVQC
381
382                 #ifdef SVQC
383                 METHOD(Mage, mr_think, bool(Monster thismon))
384                 {
385                         SELFPARAM();
386                         entity head;
387                         bool need_help = false;
388
389                         for(head = world; (head = findfloat(head, iscreature, true)); )
390                         if(head != self)
391                         if(vlen(head.origin - self.origin) <= (autocvar_g_monster_mage_heal_range))
392                         if(M_Mage_Defend_Heal_Check(head))
393                         {
394                                 need_help = true;
395                                 break;
396                         }
397
398                         if(self.health < (autocvar_g_monster_mage_heal_minhealth) || need_help)
399                         if(time >= self.attack_finished_single)
400                         if(random() < 0.5)
401                                 M_Mage_Defend_Heal();
402
403                         if(time >= self.mage_shield_time && self.armorvalue)
404                                 M_Mage_Defend_Shield_Remove();
405
406                         if(self.enemy)
407                         if(self.health < self.max_health)
408                         if(time >= self.mage_shield_delay)
409                         if(random() < 0.5)
410                                 M_Mage_Defend_Shield();
411
412                         return true;
413                 }
414                 METHOD(Mage, mr_pain, bool(Monster thismon))
415                 {
416                         return true;
417                 }
418                 METHOD(Mage, mr_death, bool(Monster thismon))
419                 {
420                         SELFPARAM();
421                         setanim(self, self.anim_die1, false, true, true);
422                         return true;
423                 }
424                 #endif
425                 #ifndef MENUQC
426                 METHOD(Mage, mr_anim, bool(Monster thismon))
427                 {
428                         SELFPARAM();
429                         vector none = '0 0 0';
430                         self.anim_die1 = animfixfps(self, '4 1 0.5', none); // 2 seconds
431                         self.anim_walk = animfixfps(self, '1 1 1', none);
432                         self.anim_idle = animfixfps(self, '0 1 1', none);
433                         self.anim_pain1 = animfixfps(self, '3 1 2', none); // 0.5 seconds
434                         self.anim_shoot = animfixfps(self, '2 1 5', none); // analyze models and set framerate
435                         self.anim_run = animfixfps(self, '5 1 1', none);
436
437                         return true;
438                 }
439                 #endif
440                 #ifdef SVQC
441                 METHOD(Mage, mr_setup, bool(Monster thismon))
442                 {
443                         SELFPARAM();
444                         if(!self.health) self.health = (autocvar_g_monster_mage_health);
445                         if(!self.speed) { self.speed = (autocvar_g_monster_mage_speed_walk); }
446                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_mage_speed_run); }
447                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_mage_speed_stop); }
448                         if(!self.damageforcescale) { self.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
449
450                         self.monster_loot = spawnfunc_item_health_large;
451                         self.monster_attackfunc = M_Mage_Attack;
452
453                         return true;
454                 }
455                 METHOD(Mage, mr_precache, bool(Monster thismon))
456                 {
457                         return true;
458                 }
459                 #endif
460
461 #endif