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