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