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