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