]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/monsters/monster/shalrath.qc
Fix more bad use of .think
[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
24 // animations
25 const float shalrath_anim_idle          = 0;
26 const float shalrath_anim_walk          = 1;
27 const float shalrath_anim_attack        = 2;
28 const float shalrath_anim_pain          = 3;
29 const float shalrath_anim_death         = 4;
30 const float shalrath_anim_run           = 5;
31
32 void() ShalMissile;
33 float() shal_missile;
34 void() shalrath_heal;
35
36 void shalrath_think ()
37 {
38         entity head;
39         float friend_needshelp = FALSE;
40         
41         FOR_EACH_PLAYER(head)
42         {
43                 if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
44                 if((!g_minstagib && head.health < autocvar_g_balance_health_regenstable) || (g_minstagib && head.ammo_cells < start_ammo_cells))
45                 {
46                         friend_needshelp = TRUE;
47                         break; // found 1 player near us who is low on health
48                 }
49         }
50         
51         self.think = shalrath_think;
52         self.nextthink = time + self.ticrate;
53         
54         if(self.delay != -1)
55                 self.nextthink = self.delay;
56                 
57         if(self.health < autocvar_g_monster_shalrath_heal_minhealth || friend_needshelp)
58         if(time >= self.attack_finished_single)
59         if(random() < 0.5)
60                 shalrath_heal();
61         
62         monster_move(autocvar_g_monster_shalrath_speed, autocvar_g_monster_shalrath_speed, 50, shalrath_anim_walk, shalrath_anim_run, shalrath_anim_idle);
63 }
64
65 void shalrath_attack ()
66 {
67         monsters_setframe(shalrath_anim_attack);
68         self.delay = time + 0.2;
69         self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_spike_delay;
70         self.monster_delayedattack = ShalMissile;
71 }
72
73 void shalrathattack_melee ()
74 {
75         monster_melee(self.enemy, autocvar_g_monster_shalrath_attack_melee_damage, 0.3, DEATH_MONSTER_MAGE, TRUE);
76 }
77
78 void shalrath_attack_melee ()
79 {
80         self.monster_delayedattack = shalrathattack_melee;
81         self.delay = time + 0.2;
82         monsters_setframe(shalrath_anim_attack);
83         self.attack_finished_single = time + autocvar_g_monster_shalrath_attack_melee_delay;
84 }
85
86 float shal_missile ()
87 {
88         shalrath_attack();
89         
90         return TRUE;
91 }
92
93 void ShalHome ()
94 {
95         local vector dir = '0 0 0', vtemp = self.enemy.origin + '0 0 10';
96         
97         if (self.enemy.health <= 0 || self.owner.health <= 0 || time >= self.ltime)
98         {
99                 remove(self);
100                 return;
101         }
102         dir = normalize(vtemp - self.origin);
103         UpdateCSQCProjectile(self);
104         if (monster_skill == 3)
105                 self.velocity = dir * 350;
106         else
107                 self.velocity = dir * 250;
108         self.nextthink = time + 0.2;
109         self.think = ShalHome;  
110 }
111
112 void shal_spike_explode ()
113 {
114         self.event_damage = func_null;
115
116         pointparticles(particleeffectnum("explosion_small"), self.origin, '0 0 0', 1);
117         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);
118
119         remove (self);
120 }
121
122 void shal_spike_touchexplode()
123 {
124         PROJECTILE_TOUCH;
125
126         shal_spike_explode();
127 }
128
129 void ShalMissile ()
130 {
131         local   entity  missile = world;
132         local   vector  dir = '0 0 0';
133         local   float   dist = 0;
134         
135         self.effects |= EF_MUZZLEFLASH;
136
137         missile = spawn ();
138         missile.owner = missile.realowner = self;
139         
140         self.v_angle = self.angles;
141         makevectors (self.angles);
142         
143         dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
144         dist = vlen (self.enemy.origin - self.origin);
145
146         missile.think = ShalHome;
147         missile.ltime = time + 7;
148         missile.nextthink = time;
149         missile.solid = SOLID_BBOX;
150         missile.movetype = MOVETYPE_FLYMISSILE;
151         missile.flags = FL_PROJECTILE;
152         setorigin (missile, self.origin + v_forward * 14 + '0 0 30' + v_right * -14);
153         setsize (missile, '0 0 0', '0 0 0');    
154         missile.velocity = dir * 400;
155         missile.avelocity = '300 300 300';
156         missile.enemy = self.enemy;
157         missile.touch = shal_spike_touchexplode;
158         
159         CSQCProjectile(missile, TRUE, PROJECTILE_VORE_SPIKE, TRUE);
160 }
161
162 float ShalrathCheckAttack ()
163 {
164         vector spot1 = '0 0 0', spot2 = '0 0 0';
165
166         if (self.health <= 0)
167                 return FALSE;
168                 
169         // reset delays when we have no enemy
170         if not(self.enemy)
171         {
172                 self.monster_delayedattack = func_null;
173                 self.delay = -1;
174         }
175         
176         if(self.monster_delayedattack && self.delay != -1)
177         {
178                 if(time < self.delay)
179                         return FALSE;
180                         
181                 self.monster_delayedattack();
182                 self.delay = -1;
183                 self.monster_delayedattack = func_null;
184         }
185         
186         if(time < self.attack_finished_single)
187                 return FALSE;
188         
189         if (vlen(self.enemy.origin - self.origin) <= 120)
190         {       // melee attack
191                 if (self.attack_melee)
192                 {
193                         monster_sound(self.msound_attack_melee, 0, FALSE); // no delay for attack sounds
194                         self.attack_melee();
195                         return TRUE;
196                 }
197         }
198
199 // see if any entities are in the way of the shot
200         spot1 = self.origin + self.view_ofs;
201         spot2 = self.enemy.origin + self.enemy.view_ofs;
202
203         traceline (spot1, spot2, FALSE, self);
204
205         if (trace_ent != self.enemy && trace_fraction < 1)
206                 return FALSE; // don't have a clear shot
207
208         //if (trace_inopen && trace_inwater)
209         //      return FALSE; // sight line crossed contents
210
211         if (self.attack_ranged())
212                 return TRUE;
213
214         return FALSE;
215 }
216
217 void shalrath_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_shalrath_heal_self, self.max_health);
223         WaypointSprite_UpdateHealth(self.sprite, self.health);
224         monsters_setframe(shalrath_anim_attack);
225         self.attack_finished_single = time + autocvar_g_monster_shalrath_heal_delay;
226         
227         for(head = world; (head = findfloat(head, monster_attack, TRUE)); )
228         {
229                 if(head.health > 0)
230                 if not(head.frozen || head.freezetag_frozen)
231                 if(vlen(head.origin - self.origin) < autocvar_g_monster_shalrath_heal_range * self.scale)
232                 if not(IsDifferentTeam(head, self))
233                 {
234                         if(IS_PLAYER(head))
235                         {
236                                 if(head.ammo_cells < start_ammo_cells || head.health < g_pickup_healthmedium_max)
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_shalrath_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_shalrath_heal_friends, head.max_health);
248                                 WaypointSprite_UpdateHealth(head.sprite, head.health);
249                         }
250                 }
251         }
252 }
253
254 void shalrath_die ()
255 {
256         Monster_CheckDropCvars ("shalrath");
257         
258         self.think = monster_dead_think;
259         self.nextthink = time + self.ticrate;
260         self.ltime = time + 5;
261         monsters_setframe(shalrath_anim_death);
262         
263         monster_hook_death(); // for post-death mods
264 }
265
266 void shalrath_spawn ()
267 {
268         if not(self.health)
269                 self.health = autocvar_g_monster_shalrath_health * self.scale;
270
271         self.damageforcescale   = 0.003;
272         self.classname                  = "monster_shalrath";
273         self.checkattack                = ShalrathCheckAttack;
274         self.attack_ranged              = shal_missile;
275         self.attack_melee               = shalrath_attack_melee;
276         self.nextthink                  = time + random() * 0.5 + 0.1;
277         self.think                              = shalrath_think;
278         
279         monsters_setframe(shalrath_anim_walk);
280         
281         monster_setupsounds("shalrath");
282         
283         monster_hook_spawn(); // for post-spawn mods
284 }
285
286 void spawnfunc_monster_shalrath ()
287 {       
288         if not(autocvar_g_monster_shalrath) { remove(self); return; }
289         
290         self.monster_spawnfunc = spawnfunc_monster_shalrath;
291         
292         if(Monster_CheckAppearFlags(self))
293                 return;
294         
295         if not (monster_initialize(
296                          "Mage", MONSTER_MAGE,
297                          SHALRATH_MIN, SHALRATH_MAX,
298                          FALSE,
299                          shalrath_die, shalrath_spawn))
300         {
301                 remove(self);
302                 return;
303         }
304 }
305
306 // compatibility with old spawns
307 void spawnfunc_monster_vore () { spawnfunc_monster_shalrath(); }
308
309 #endif // SVQC