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