]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/monsters/monster/shalrath.qc
Add cvars for the force field
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / monsters / monster / shalrath.qc
1 // size
2 const vector SHALRATH_MIN = '-36 -36 -24';
3 const vector SHALRATH_MAX = '36 36 50';
4
5 // model
6 string SHALRATH_MODEL = "models/monsters/mage.dpm";
7
8 #ifdef SVQC
9 // cvars
10 float autocvar_g_monster_shalrath;
11 float autocvar_g_monster_shalrath_health;
12 float autocvar_g_monster_shalrath_speed;
13 float autocvar_g_monster_shalrath_attack_spike_damage;
14 float autocvar_g_monster_shalrath_attack_spike_radius;
15 float autocvar_g_monster_shalrath_attack_spike_delay;
16 float autocvar_g_monster_shalrath_attack_melee_damage;
17 float autocvar_g_monster_shalrath_attack_melee_delay;
18 float autocvar_g_monster_shalrath_heal_self;
19 float autocvar_g_monster_shalrath_heal_friends;
20 float autocvar_g_monster_shalrath_heal_minhealth;
21 float autocvar_g_monster_shalrath_heal_range;
22 float autocvar_g_monster_shalrath_heal_delay;
23 float autocvar_g_monster_shalrath_shield_time;
24 float autocvar_g_monster_shalrath_shield_delay;
25 float autocvar_g_monster_shalrath_shield_blockpercent;
26
27 // animations
28 const float shalrath_anim_idle          = 0;
29 const float shalrath_anim_walk          = 1;
30 const float shalrath_anim_attack        = 2;
31 const float shalrath_anim_pain          = 3;
32 const float shalrath_anim_death         = 4;
33 const float shalrath_anim_run           = 5;
34
35 void() ShalMissile;
36 float() shal_missile;
37 void() shalrath_heal;
38 void() shalrath_shield;
39 void() shalrath_shield_die;
40
41 void shalrath_think ()
42 {
43         entity head;
44         float friend_needshelp = FALSE;
45         
46         FOR_EACH_PLAYER(head)
47         {
48                 if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
49                 if((!g_minstagib && head.health < autocvar_g_balance_health_regenstable) || (g_minstagib && head.ammo_cells < start_ammo_cells))
50                 {
51                         friend_needshelp = TRUE;
52                         break; // found 1 player near us who is low on health
53                 }
54         }
55         
56         self.think = shalrath_think;
57         self.nextthink = time + self.ticrate;
58         
59         if(self.weaponentity)
60         if(time >= self.weaponentity.ltime)
61                 shalrath_shield_die();
62         
63         if(self.delay != -1)
64                 self.nextthink = self.delay;
65                 
66         if(self.health < autocvar_g_monster_shalrath_heal_minhealth || friend_needshelp)
67         if(time >= self.attack_finished_single)
68         if(random() < 0.5)
69                 shalrath_heal();
70                 
71         if(self.enemy)
72         if not(self.spawnflags & MONSTERFLAG_GIANT) // giants are too big to hold a shield
73         if(self.health < self.max_health)
74         if(time >= self.lastshielded)
75         if(random() < 0.5)
76                 shalrath_shield();
77         
78         monster_move(autocvar_g_monster_shalrath_speed, autocvar_g_monster_shalrath_speed, 50, shalrath_anim_walk, shalrath_anim_run, shalrath_anim_idle);
79 }
80
81 void shalrath_attack ()
82 {
83         monsters_setframe(shalrath_anim_attack);
84         self.delay = time + 0.2;
85         self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_spike_delay;
86         self.monster_delayedattack = ShalMissile;
87 }
88
89 void shalrathattack_melee ()
90 {
91         monster_melee(self.enemy, autocvar_g_monster_shalrath_attack_melee_damage, 0.3, DEATH_MONSTER_MAGE, TRUE);
92 }
93
94 void shalrath_attack_melee ()
95 {
96         self.monster_delayedattack = shalrathattack_melee;
97         self.delay = time + 0.2;
98         monsters_setframe(shalrath_anim_attack);
99         self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_melee_delay;
100 }
101
102 float shal_missile ()
103 {
104         shalrath_attack();
105         
106         return TRUE;
107 }
108
109 void ShalHome ()
110 {
111         local vector dir = '0 0 0', vtemp = self.enemy.origin + '0 0 10';
112         
113         if (self.enemy.health <= 0 || self.owner.health <= 0 || time >= self.ltime)
114         {
115                 remove(self);
116                 return;
117         }
118         dir = normalize(vtemp - self.origin);
119         UpdateCSQCProjectile(self);
120         if (monster_skill == 3)
121                 self.velocity = dir * 350;
122         else
123                 self.velocity = dir * 250;
124         self.nextthink = time + 0.2;
125         self.think = ShalHome;  
126 }
127
128 void shal_spike_explode ()
129 {
130         self.event_damage = func_null;
131
132         pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
133         RadiusDamage (self, self.realowner, autocvar_g_monster_shalrath_attack_spike_damage, autocvar_g_monster_shalrath_attack_spike_damage * 0.5, autocvar_g_monster_shalrath_attack_spike_radius, world, 0, DEATH_MONSTER_MAGE, other);
134
135         remove (self);
136 }
137
138 void shal_spike_touchexplode()
139 {
140         PROJECTILE_TOUCH;
141
142         shal_spike_explode();
143 }
144
145 void ShalMissile ()
146 {
147         local   entity  missile = world;
148         local   vector  dir = '0 0 0';
149         local   float   dist = 0;
150         
151         self.effects |= EF_MUZZLEFLASH;
152
153         missile = spawn ();
154         missile.owner = missile.realowner = self;
155         
156         self.v_angle = self.angles;
157         makevectors (self.angles);
158         
159         dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
160         dist = vlen (self.enemy.origin - self.origin);
161
162         missile.think = ShalHome;
163         missile.ltime = time + 7;
164         missile.nextthink = time;
165         missile.solid = SOLID_BBOX;
166         missile.movetype = MOVETYPE_FLYMISSILE;
167         missile.flags = FL_PROJECTILE;
168         setorigin (missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
169         setsize (missile, '0 0 0', '0 0 0');    
170         missile.velocity = dir * 400;
171         missile.avelocity = '300 300 300';
172         missile.enemy = self.enemy;
173         missile.touch = shal_spike_touchexplode;
174         
175         CSQCProjectile(missile, TRUE, PROJECTILE_VORE_SPIKE, TRUE);
176 }
177
178 float ShalrathCheckAttack ()
179 {
180         vector spot1 = '0 0 0', spot2 = '0 0 0';
181
182         if (self.health <= 0)
183                 return FALSE;
184                 
185         // reset delays when we have no enemy
186         if not(self.enemy)
187         {
188                 self.monster_delayedattack = func_null;
189                 self.delay = -1;
190         }
191         
192         if(self.monster_delayedattack && self.delay != -1)
193         {
194                 if(time < self.delay)
195                         return FALSE;
196                         
197                 self.monster_delayedattack();
198                 self.delay = -1;
199                 self.monster_delayedattack = func_null;
200         }
201         
202         if(time < self.attack_finished_single)
203                 return FALSE;
204         
205         if (vlen(self.enemy.origin - self.origin) <= 120)
206         {       // melee attack
207                 if (self.attack_melee)
208                 {
209                         monster_sound(self.msound_attack_melee, 0, FALSE); // no delay for attack sounds
210                         self.attack_melee();
211                         return TRUE;
212                 }
213         }
214
215 // see if any entities are in the way of the shot
216         spot1 = self.origin + self.view_ofs;
217         spot2 = self.enemy.origin + self.enemy.view_ofs;
218
219         traceline (spot1, spot2, FALSE, self);
220
221         if (trace_ent != self.enemy && trace_fraction < 1)
222                 return FALSE; // don't have a clear shot
223
224         //if (trace_inopen && trace_inwater)
225         //      return FALSE; // sight line crossed contents
226
227         if (self.attack_ranged())
228                 return TRUE;
229
230         return FALSE;
231 }
232
233 void shalrath_heal()
234 {
235         entity head;
236         if(self.health < self.max_health) // only show our effect if we are healing ourself too
237                 pointparticles(particleeffectnum("healing_fx"), self.origin, '0 0 0', 1);
238         self.health = bound(0, self.health + autocvar_g_monster_shalrath_heal_self, self.max_health);
239         WaypointSprite_UpdateHealth(self.sprite, self.health);
240         monsters_setframe(shalrath_anim_attack);
241         self.attack_finished_single = time + autocvar_g_monster_shalrath_heal_delay;
242         
243         for(head = world; (head = findfloat(head, monster_attack, TRUE)); )
244         {
245                 if(head.health > 0)
246                 if not(head.frozen || head.freezetag_frozen)
247                 if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
248                 if not(IsDifferentTeam(head, self))
249                 {
250                         if(IS_PLAYER(head))
251                         {
252                                 if(head.ammo_cells < start_ammo_cells || head.health < g_pickup_healthmedium_max)
253                                         pointparticles(particleeffectnum(((g_minstagib) ? "ammoregen_fx" : "healing_fx")), head.origin, '0 0 0', 1);
254                                 if(g_minstagib)
255                                         head.ammo_cells = bound(0, head.ammo_cells + 1, start_ammo_cells);
256                                 else
257                                         head.health = bound(0, head.health + autocvar_g_monster_shalrath_heal_friends, g_pickup_healthmedium_max);
258                         }
259                         else
260                         {
261                                 if(head.health < head.max_health)
262                                         pointparticles(particleeffectnum("healing_fx"), head.origin, '0 0 0', 1);
263                                 head.health = bound(0, head.health + autocvar_g_monster_shalrath_heal_friends, head.max_health);
264                                 WaypointSprite_UpdateHealth(head.sprite, head.health);
265                         }
266                 }
267         }
268 }
269
270 void shalrath_shield_die()
271 {
272         if not(self.weaponentity)
273                 return; // why would this be called without a shield?
274         
275         self.armorvalue = 1;
276         
277         remove(self.weaponentity);
278         
279         self.weaponentity = world;
280 }
281
282 void shalrath_shield()
283 {
284         if(self.weaponentity)
285                 return; // already have a shield
286
287         self.weaponentity = spawn();
288         self.weaponentity.owner = self.weaponentity.realowner = self;
289         setmodel(self.weaponentity, "models/onslaught/generator_shield.md3");
290         setattachment(self.weaponentity, self, "");
291         self.weaponentity.classname = "shield";
292         self.weaponentity.ltime = time + autocvar_g_monster_shalrath_shield_time;
293         self.weaponentity.health = 70;
294         self.weaponentity.alpha = 0.5;
295         self.weaponentity.scale = self.scale * 0.6;
296         self.weaponentity.effects = EF_ADDITIVE;
297         self.weaponentity.solid = SOLID_NOT;
298         self.weaponentity.movetype = MOVETYPE_NOCLIP;
299         self.weaponentity.avelocity = '7 0 11';
300         
301         self.lastshielded = time + autocvar_g_monster_shalrath_shield_delay;
302         
303         monsters_setframe(shalrath_anim_attack);
304         self.attack_finished_single = time + 1;
305         
306         self.armorvalue = autocvar_g_monster_shalrath_shield_blockpercent / 100;
307 }
308
309 void shalrath_die ()
310 {
311         Monster_CheckDropCvars ("shalrath");
312         
313         self.think = monster_dead_think;
314         self.nextthink = time + self.ticrate;
315         self.ltime = time + 5;
316         monsters_setframe(shalrath_anim_death);
317         
318         monster_hook_death(); // for post-death mods
319 }
320
321 void shalrath_spawn ()
322 {
323         if not(self.health)
324                 self.health = autocvar_g_monster_shalrath_health * self.scale;
325
326         self.damageforcescale   = 0.003;
327         self.classname                  = "monster_shalrath";
328         self.checkattack                = ShalrathCheckAttack;
329         self.attack_ranged              = shal_missile;
330         self.attack_melee               = shalrath_attack_melee;
331         self.nextthink                  = time + random() * 0.5 + 0.1;
332         self.think                              = shalrath_think;
333         
334         monsters_setframe(shalrath_anim_walk);
335         
336         monster_setupsounds("shalrath");
337         
338         monster_hook_spawn(); // for post-spawn mods
339 }
340
341 void spawnfunc_monster_shalrath ()
342 {       
343         if not(autocvar_g_monster_shalrath) { remove(self); return; }
344         
345         self.monster_spawnfunc = spawnfunc_monster_shalrath;
346         
347         if(Monster_CheckAppearFlags(self))
348                 return;
349         
350         if not (monster_initialize(
351                          "Mage", MONSTER_MAGE,
352                          SHALRATH_MIN, SHALRATH_MAX,
353                          FALSE,
354                          shalrath_die, shalrath_spawn))
355         {
356                 remove(self);
357                 return;
358         }
359 }
360
361 // compatibility with old spawns
362 void spawnfunc_monster_vore () { spawnfunc_monster_shalrath(); }
363
364 #endif // SVQC