]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/monsters/monster/mage.qc
Rename shalrath to mage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / monsters / monster / mage.qc
1 // size
2 const vector MAGE_MIN = '-36 -36 -24';
3 const vector MAGE_MAX = '36 36 50';
4
5 // model
6 string MAGE_MODEL = "models/monsters/mage.dpm";
7
8 #ifdef SVQC
9 // cvars
10 float autocvar_g_monster_mage;
11 float autocvar_g_monster_mage_health;
12 float autocvar_g_monster_mage_speed;
13 float autocvar_g_monster_mage_attack_spike_damage;
14 float autocvar_g_monster_mage_attack_spike_radius;
15 float autocvar_g_monster_mage_attack_spike_delay;
16 float autocvar_g_monster_mage_attack_melee_damage;
17 float autocvar_g_monster_mage_attack_melee_delay;
18 float autocvar_g_monster_mage_heal_self;
19 float autocvar_g_monster_mage_heal_friends;
20 float autocvar_g_monster_mage_heal_minhealth;
21 float autocvar_g_monster_mage_heal_range;
22 float autocvar_g_monster_mage_heal_delay;
23 float autocvar_g_monster_mage_shield_time;
24 float autocvar_g_monster_mage_shield_delay;
25 float autocvar_g_monster_mage_shield_blockpercent;
26 float autocvar_g_monster_mage_attack_grenade_damage;
27 float autocvar_g_monster_mage_attack_grenade_edgedamage;
28 float autocvar_g_monster_mage_attack_grenade_radius;
29 float autocvar_g_monster_mage_attack_grenade_lifetime;
30 float autocvar_g_monster_mage_attack_grenade_force;
31 float autocvar_g_monster_mage_attack_grenade_chance;
32
33 // animations
34 const float mage_anim_idle              = 0;
35 const float mage_anim_walk              = 1;
36 const float mage_anim_attack    = 2;
37 const float mage_anim_pain              = 3;
38 const float mage_anim_death     = 4;
39 const float mage_anim_run               = 5;
40
41 void() mage_heal;
42 void() mage_shield;
43 void() mage_shield_die;
44
45 void mage_think()
46 {
47         entity head;
48         float friend_needshelp = FALSE, need_hpammo = FALSE;
49         
50         FOR_EACH_PLAYER(head)
51         {
52                 need_hpammo = ((g_minstagib) ? head.ammo_cells < start_ammo_cells : head.health < autocvar_g_balance_health_regenstable);
53                 if not(IsDifferentTeam(head, self))
54                 if(head.health > 0)
55                 if(vlen(head.origin - self.origin) < autocvar_g_monster_mage_heal_range)
56                 if(need_hpammo)
57                 {
58                         friend_needshelp = TRUE;
59                         break; // found 1 player near us who is low on health
60                 }
61         }
62         FOR_EACH_MONSTER(head) if(head != self)
63         {
64                 if not(IsDifferentTeam(head, self))
65                 if(head.health > 0)
66                 if(vlen(head.origin - self.origin) < autocvar_g_monster_mage_heal_range)
67                 if(head.health < head.max_health)
68                 {
69                         friend_needshelp = TRUE;
70                         break; // found 1 player near us who is low on health
71                 }
72         }
73         
74         self.think = mage_think;
75         self.nextthink = time + self.ticrate;
76         
77         if(self.weaponentity)
78         if(time >= self.weaponentity.ltime)
79                 mage_shield_die();
80                 
81         if(self.health < autocvar_g_monster_mage_heal_minhealth || friend_needshelp)
82         if(time >= self.attack_finished_single)
83         if(random() < 0.5)
84                 mage_heal();
85                 
86         if(self.enemy)
87         if(self.health < self.max_health)
88         if(time >= self.lastshielded)
89         if(random() < 0.5)
90                 mage_shield();
91         
92         monster_move(autocvar_g_monster_mage_speed, autocvar_g_monster_mage_speed, 50, mage_anim_walk, mage_anim_run, mage_anim_idle);
93 }
94
95 void mageattack_melee()
96 {
97         monster_melee(self.enemy, autocvar_g_monster_mage_attack_melee_damage, 0.3, DEATH_MONSTER_MAGE, TRUE);
98         
99         self.delay = -1;
100         self.monster_delayedattack = func_null;
101 }
102
103 void mage_grenade_explode()
104 {
105         pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
106         
107         sound(self, CH_SHOTS, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
108         RadiusDamage (self, self.realowner, autocvar_g_monster_mage_attack_grenade_damage, autocvar_g_monster_mage_attack_grenade_edgedamage, autocvar_g_monster_mage_attack_grenade_radius, world, autocvar_g_monster_mage_attack_grenade_force, DEATH_MONSTER_MAGE, other);
109         remove(self);
110 }
111
112 void mage_grenade_touch()
113 {
114         if(IS_PLAYER(other))
115         {
116                 PROJECTILE_TOUCH;
117                 mage_grenade_explode();
118                 return;
119         }
120 }
121
122 void mage_throw_itemgrenade()
123 {
124         makevectors(self.angles);
125
126         W_SetupShot_ProjectileSize (self, '-64 -64 -64', '64 64 64', FALSE, 4, "", CH_WEAPON_A, autocvar_g_monster_mage_attack_grenade_damage);
127         w_shotdir = v_forward; // no TrueAim for grenades please
128
129         entity gren = spawn ();
130         gren.owner = gren.realowner = self;
131         gren.classname = "grenade";
132         gren.bot_dodge = FALSE;
133         gren.movetype = MOVETYPE_BOUNCE;
134         gren.solid = SOLID_TRIGGER;
135         gren.projectiledeathtype = DEATH_MONSTER_MAGE;
136         setorigin(gren, w_shotorg);
137         setsize(gren, '-64 -64 -64', '64 64 64');
138
139         gren.nextthink = time + autocvar_g_monster_mage_attack_grenade_lifetime;
140         gren.think = mage_grenade_explode;
141         gren.use = mage_grenade_explode;
142         gren.touch = mage_grenade_touch;
143
144         gren.missile_flags = MIF_SPLASH | MIF_ARC;
145         W_SETUPPROJECTILEVELOCITY_UP(gren, g_monster_mage_attack_grenade);
146         
147         gren.flags = FL_PROJECTILE;
148         
149         setmodel(gren, "models/items/g_h50.md3");
150         
151         self.attack_finished_single = time + 1.5;
152 }
153
154 void mage_spike_explode()
155 {
156         self.event_damage = func_null;
157
158         pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
159         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, 0, DEATH_MONSTER_MAGE, other);
160
161         remove (self);
162 }
163
164 void mage_spike_touch()
165 {
166         PROJECTILE_TOUCH;
167
168         mage_spike_explode();
169 }
170
171 void mage_spike_think()
172 {
173         if(self.enemy.health <= 0 || self.owner.health <= 0 || time >= self.ltime)
174         {
175                 mage_spike_explode();
176                 return;
177         }
178         
179         vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
180         
181         UpdateCSQCProjectile(self);
182         
183         if (monster_skill == 3)
184                 self.velocity = dir * 350;
185         else
186                 self.velocity = dir * 250;
187                 
188         self.nextthink = time + 0.2;
189         self.think = mage_spike_think;  
190 }
191
192 void mage_spike()
193 {
194         entity missile;
195         vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
196
197         makevectors(self.angles);
198
199         missile = spawn ();
200         missile.owner = missile.realowner = self;
201         missile.think = mage_spike_think;
202         missile.ltime = time + 7;
203         missile.nextthink = time;
204         missile.solid = SOLID_BBOX;
205         missile.movetype = MOVETYPE_FLYMISSILE;
206         missile.flags = FL_PROJECTILE;
207         setorigin(missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
208         setsize (missile, '0 0 0', '0 0 0');    
209         missile.velocity = dir * 400;
210         missile.avelocity = '300 300 300';
211         missile.enemy = self.enemy;
212         missile.touch = mage_spike_touch;
213         
214         CSQCProjectile(missile, TRUE, PROJECTILE_MAGE_SPIKE, TRUE);
215 }
216
217 void mage_heal()
218 {
219         entity head;
220         if(self.health < self.max_health) // only show our effect if we are healing ourself too
221                 pointparticles(particleeffectnum("healing_fx"), self.origin, '0 0 0', 1);
222         self.health = bound(0, self.health + autocvar_g_monster_mage_heal_self, self.max_health);
223         WaypointSprite_UpdateHealth(self.sprite, self.health);
224         monsters_setframe(mage_anim_attack);
225         self.attack_finished_single = time + autocvar_g_monster_mage_heal_delay;
226         
227         for(head = world; (head = findfloat(head, monster_attack, TRUE)); )
228         {
229                 if(head.health > 0)
230                 if not(head.frozen)
231                 if(vlen(head.origin - self.origin) < autocvar_g_monster_mage_heal_range)
232                 if not(IsDifferentTeam(head, self))
233                 {
234                         if(IS_PLAYER(head))
235                         {
236                                 if((g_minstagib && head.ammo_cells < start_ammo_cells) || head.health < start_health)
237                                         pointparticles(particleeffectnum(((g_minstagib) ? "ammoregen_fx" : "healing_fx")), head.origin, '0 0 0', 1);
238                                 if(g_minstagib)
239                                         head.ammo_cells = bound(0, head.ammo_cells + 1, start_ammo_cells);
240                                 else
241                                         head.health = bound(0, head.health + autocvar_g_monster_mage_heal_friends, g_pickup_healthmedium_max);
242                         }
243                         else
244                         {
245                                 if(head.health < head.max_health)
246                                         pointparticles(particleeffectnum("healing_fx"), head.origin, '0 0 0', 1);
247                                 head.health = bound(0, head.health + autocvar_g_monster_mage_heal_friends, head.max_health);
248                                 WaypointSprite_UpdateHealth(head.sprite, head.health);
249                         }
250                 }
251         }
252 }
253
254 void mage_shield_die()
255 {
256         if not(self.weaponentity)
257                 return; // why would this be called without a shield?
258         
259         self.armorvalue = 1;
260         
261         remove(self.weaponentity);
262         
263         self.weaponentity = world;
264 }
265
266 void mage_shield()
267 {
268         if(self.weaponentity)
269                 return; // already have a shield
270                 
271         entity shield = spawn();
272
273         shield.owner = self;
274         shield.team = self.team;
275         shield.ltime = time + autocvar_g_monster_mage_shield_time;
276         shield.health = 70;
277         shield.classname = "shield";
278         shield.effects = EF_ADDITIVE;
279         shield.movetype = MOVETYPE_NOCLIP;
280         shield.solid = SOLID_TRIGGER;
281         shield.avelocity = '7 0 11';
282         shield.scale = self.scale * 0.6;
283         
284         setattachment(shield, self, "");
285         setmodel(shield, "models/ctf/shield.md3");
286         setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
287         
288         self.weaponentity = shield;
289         
290         self.lastshielded = time + autocvar_g_monster_mage_shield_delay;
291         
292         monsters_setframe(mage_anim_attack);
293         self.attack_finished_single = time + 1;
294         
295         self.armorvalue = autocvar_g_monster_mage_shield_blockpercent / 100;
296 }
297
298 float mage_attack(float attack_type)
299 {
300         switch(attack_type)
301         {
302                 case MONSTER_ATTACK_MELEE:
303                 {
304                         self.monster_delayedattack = mageattack_melee;
305                         self.delay = time + 0.2;
306                         monsters_setframe(mage_anim_attack);
307                         self.attack_finished_single = time + autocvar_g_monster_mage_attack_melee_delay;
308                         
309                         return TRUE;
310                 }
311                 case MONSTER_ATTACK_RANGED:
312                 {
313                         if(random() < autocvar_g_monster_mage_attack_grenade_chance / 100)
314                         {
315                                 mage_throw_itemgrenade();
316                                 return TRUE;
317                         }
318         
319                         monsters_setframe(mage_anim_attack);
320                         self.delay = time + 0.2;
321                         self.attack_finished_single = time + autocvar_g_monster_mage_attack_spike_delay;
322                         self.monster_delayedattack = mage_spike;
323                         
324                         return TRUE;
325                 }
326         }
327         
328         return FALSE;
329 }
330
331 void mage_die()
332 {
333         Monster_CheckDropCvars ("mage");
334         
335         self.think = monster_dead_think;
336         self.nextthink = time + self.ticrate;
337         self.ltime = time + 5;
338         monsters_setframe(mage_anim_death);
339         
340         monster_hook_death(); // for post-death mods
341 }
342
343 void mage_spawn()
344 {
345         if not(self.health)
346                 self.health = autocvar_g_monster_mage_health;
347
348         self.damageforcescale   = 0.003;
349         self.classname                  = "monster_mage";
350         self.monster_attackfunc = mage_attack;
351         self.nextthink                  = time + random() * 0.5 + 0.1;
352         self.think                              = mage_think;
353         
354         monsters_setframe(mage_anim_walk);
355         
356         monster_setupsounds("mage");
357         
358         monster_hook_spawn(); // for post-spawn mods
359 }
360
361 void spawnfunc_monster_mage()
362 {       
363         if not(autocvar_g_monster_mage) { remove(self); return; }
364         
365         self.monster_spawnfunc = spawnfunc_monster_mage;
366         
367         if(Monster_CheckAppearFlags(self))
368                 return;
369         
370         if not (monster_initialize(
371                          "Mage", MONSTER_MAGE,
372                          MAGE_MIN, MAGE_MAX,
373                          FALSE,
374                          mage_die, mage_spawn))
375         {
376                 remove(self);
377                 return;
378         }
379 }
380
381 // compatibility with old spawns
382 void spawnfunc_monster_shalrath() { spawnfunc_monster_mage(); }
383
384 #endif // SVQC