]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/knight.qc
Replace monsters config with a modified dumped config
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / knight.qc
1 #ifdef REGISTER_MONSTER
2 REGISTER_MONSTER(
3 /* MON_##id   */ KNIGHT,
4 /* function   */ m_knight,
5 /* spawnflags */ MONSTER_SIZE_BROKEN,
6 /* mins,maxs  */ '-20 -20 -32', '20 20 41',
7 /* model      */ "hknight.mdl",
8 /* netname    */ "knight",
9 /* fullname   */ _("Knight")
10 );
11
12 #define KNIGHT_SETTINGS(monster) \
13         MON_ADD_CVAR(monster, health) \
14         MON_ADD_CVAR(monster, attack_melee_damage) \
15         MON_ADD_CVAR(monster, attack_inferno_damage) \
16         MON_ADD_CVAR(monster, attack_inferno_damagetime) \
17         MON_ADD_CVAR(monster, attack_inferno_chance) \
18         MON_ADD_CVAR(monster, attack_fireball_damage) \
19         MON_ADD_CVAR(monster, attack_fireball_edgedamage) \
20         MON_ADD_CVAR(monster, attack_fireball_damagetime) \
21         MON_ADD_CVAR(monster, attack_fireball_force) \
22         MON_ADD_CVAR(monster, attack_fireball_radius) \
23         MON_ADD_CVAR(monster, attack_fireball_chance) \
24         MON_ADD_CVAR(monster, attack_spike_damage) \
25         MON_ADD_CVAR(monster, attack_spike_edgedamage) \
26         MON_ADD_CVAR(monster, attack_spike_force) \
27         MON_ADD_CVAR(monster, attack_spike_radius) \
28         MON_ADD_CVAR(monster, attack_spike_chance) \
29         MON_ADD_CVAR(monster, attack_jump_damage) \
30         MON_ADD_CVAR(monster, attack_jump_distance) \
31         MON_ADD_CVAR(monster, attack_jump_chance) \
32         MON_ADD_CVAR(monster, speed_stop) \
33         MON_ADD_CVAR(monster, speed_run) \
34         MON_ADD_CVAR(monster, speed_walk) 
35
36 #ifdef SVQC
37 KNIGHT_SETTINGS(knight)
38 #endif // SVQC
39 #else
40 #ifdef SVQC
41 const float knight_anim_stand   = 0;
42 const float knight_anim_walk    = 1;
43 const float knight_anim_run     = 2;
44 const float knight_anim_pain    = 3;
45 const float knight_anim_death1  = 4;
46 const float knight_anim_death2  = 5;
47 const float knight_anim_charge1 = 6;
48 const float knight_anim_magic1  = 7;
49 const float knight_anim_magic2  = 8;
50 const float knight_anim_charge2 = 9;
51 const float knight_anim_slice   = 10;
52 const float knight_anim_smash   = 11;
53 const float knight_anim_wattack = 12;
54 const float knight_anim_magic3  = 13;
55
56 .float knight_cycles;
57
58 void knight_inferno()
59 {
60         if not(self.enemy)
61                 return;
62                 
63         traceline((self.absmin + self.absmax) * 0.5, (self.enemy.absmin + self.enemy.absmax) * 0.5, TRUE, world);
64         if (trace_fraction != 1)
65                 return; // not visible
66         
67         self.enemy.effects |= EF_MUZZLEFLASH;
68         sound(self.enemy, CHAN_AUTO, "player/lava.wav", 1, ATTN_NORM);
69         
70         if(vlen(self.enemy.origin - self.origin) <= 2000)
71                 Fire_AddDamage(self.enemy, self, MON_CVAR(knight, attack_inferno_damage) * monster_skill, MON_CVAR(knight, attack_inferno_damagetime), DEATH_MONSTER_KNIGHT_INFERNO);
72 }
73
74 void knight_fireball_explode()
75 {
76         entity e;
77         if(self)
78         {
79                 pointparticles(particleeffectnum("fireball_explode"), self.origin, '0 0 0', 1);
80                 
81                 RadiusDamage(self, self.realowner, MON_CVAR(knight, attack_fireball_damage), MON_CVAR(knight, attack_fireball_edgedamage), MON_CVAR(knight, attack_fireball_force), world, MON_CVAR(knight, attack_fireball_radius), self.projectiledeathtype, world);
82                 
83                 for(e = world; (e = findfloat(e, takedamage, DAMAGE_AIM)); ) if(vlen(e.origin - self.origin) <= MON_CVAR(knight, attack_inferno_damage))
84                         Fire_AddDamage(e, self, 5 * monster_skill, MON_CVAR(knight, attack_fireball_damagetime), self.projectiledeathtype);
85                 
86                 remove(self);
87         }
88 }
89
90 void knight_fireball_touch()
91 {
92         PROJECTILE_TOUCH;
93         
94         knight_fireball_explode();
95 }
96
97 void knight_fireball()
98 {
99         entity missile = spawn();
100         vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
101         
102         monster_makevectors(self.enemy);
103         
104         self.effects |= EF_MUZZLEFLASH;
105         sound(self, CHAN_WEAPON, "weapons/fireball2.wav", 1, ATTN_NORM);
106
107         missile.owner = missile.realowner = self;
108         missile.solid = SOLID_TRIGGER;
109         missile.movetype = MOVETYPE_FLYMISSILE;
110         missile.projectiledeathtype = DEATH_MONSTER_KNIGHT_FBALL;
111         setsize(missile, '-6 -6 -6', '6 6 6');          
112         setorigin(missile, self.origin + self.view_ofs + v_forward * 14);
113         missile.flags = FL_PROJECTILE;
114         missile.velocity = dir * 400;
115         missile.avelocity = '300 300 300';
116         missile.nextthink = time + 5;
117         missile.think = knight_fireball_explode;
118         missile.enemy = self.enemy;
119         missile.touch = knight_fireball_touch;
120         CSQCProjectile(missile, TRUE, PROJECTILE_FIREMINE, TRUE);
121 }
122
123 void knight_spike_explode()
124 {
125         if(self)
126         {
127                 pointparticles(particleeffectnum("TE_WIZSPIKE"), self.origin, '0 0 0', 1);
128                 
129                 RadiusDamage (self, self.realowner, MON_CVAR(knight, attack_spike_damage), MON_CVAR(knight, attack_spike_edgedamage), MON_CVAR(knight, attack_spike_force), world, MON_CVAR(knight, attack_spike_radius), DEATH_MONSTER_KNIGHT_SPIKE, other);
130                 remove(self);
131         }
132 }
133
134 void knight_spike_touch()
135 {
136         PROJECTILE_TOUCH;
137         
138         knight_spike_explode();
139 }
140
141 void knight_spike()
142 {
143         entity missile;
144         vector dir = normalize((self.enemy.origin + '0 0 10') - self.origin);
145
146         self.effects |= EF_MUZZLEFLASH;
147
148         missile = spawn ();
149         missile.owner = missile.realowner = self;
150         missile.solid = SOLID_TRIGGER;
151         missile.movetype = MOVETYPE_FLYMISSILE;
152         setsize (missile, '0 0 0', '0 0 0');            
153         setorigin(missile, self.origin + '0 0 10' + v_forward * 14);
154         missile.scale = self.scale;
155         missile.flags = FL_PROJECTILE;
156         missile.velocity = dir * 400;
157         missile.avelocity = '300 300 300';
158         missile.nextthink = time + 5;
159         missile.think = knight_spike_explode;
160         missile.enemy = self.enemy;
161         missile.touch = knight_spike_touch;
162         CSQCProjectile(missile, TRUE, PROJECTILE_CRYLINK, TRUE);
163 }
164
165 void knight_spikes()
166 {
167         self.knight_cycles += 1;
168         knight_spike();
169         
170         if(self.knight_cycles <= 7)
171                 defer(0.1, knight_spikes);
172 }
173
174 float knight_attack_ranged()
175 {
176         if not(self.flags & FL_ONGROUND)
177                 return FALSE;
178                 
179         self.knight_cycles = 0;
180         
181         RandomSelection_Init();
182         RandomSelection_Add(world, 1, "", MON_CVAR(knight, attack_fireball_chance), 1);
183         RandomSelection_Add(world, 2, "", MON_CVAR(knight, attack_inferno_chance), 1);
184         RandomSelection_Add(world, 3, "", MON_CVAR(knight, attack_spike_chance), 1);
185         if(self.health >= 100) RandomSelection_Add(world, 4, "", ((vlen(self.enemy.origin - self.origin) > MON_CVAR(knight, attack_jump_distance)) ? 1 : MON_CVAR(knight, attack_jump_chance)), 1);
186         
187         switch(RandomSelection_chosen_float)
188         {
189                 case 1:
190                 {
191                         monsters_setframe(knight_anim_magic2);
192                         self.attack_finished_single = time + 2;
193                         defer(0.4, knight_fireball);
194                         
195                         return TRUE;
196                 }
197                 case 2:
198                 {
199                         self.attack_finished_single = time + 3;
200                         defer(0.5, knight_inferno);
201                         return TRUE;
202                 }
203                 case 3:
204                 {
205                         monsters_setframe(knight_anim_magic3);
206                         self.attack_finished_single = time + 3;
207                         defer(0.4, knight_spikes);
208                         
209                         return TRUE;
210                 }
211                 case 4:
212                 {
213                         float er = vlen(self.enemy.origin - self.origin);
214                         
215                         if(er >= 400 && er < 1200)
216                         if(findtrajectorywithleading(self.origin, self.mins, self.maxs, self.enemy, 1000, 0, 10, 0, self))
217                         {
218                                 self.velocity = findtrajectory_velocity;
219                                 Damage(self.enemy, self, self, MON_CVAR(knight, attack_jump_damage) * monster_skill, DEATH_MONSTER_KNIGHT_CRUSH, self.enemy.origin, normalize(self.enemy.origin - self.origin));
220                                 self.attack_finished_single = time + 2;
221                                 return TRUE;
222                         }
223                         return FALSE;
224                 }
225         }
226         
227         return FALSE;
228 }
229
230 float knight_attack(float attack_type)
231 {
232         switch(attack_type)
233         {
234                 case MONSTER_ATTACK_MELEE:
235                 {
236                         float anim;
237                         if(random() < 0.3)
238                                 anim = knight_anim_slice;
239                         else if(random() < 0.6)
240                                 anim = knight_anim_smash;
241                         else
242                                 anim = knight_anim_wattack;
243                         
244                         monsters_setframe(anim);
245                         self.attack_finished_single = time + 0.7;
246                         monster_melee(self.enemy, MON_CVAR(knight, attack_melee_damage), 0.3, DEATH_MONSTER_KNIGHT_MELEE, TRUE);
247                         
248                         return TRUE;
249                 }
250                 case MONSTER_ATTACK_RANGED:
251                 {
252                         if(knight_attack_ranged())
253                                 return TRUE;
254                 }
255         }
256         
257         return FALSE;
258 }
259
260 void spawnfunc_monster_knight()
261 {
262         self.classname = "monster_knight";
263         
264         self.monster_spawnfunc = spawnfunc_monster_knight;
265         
266         if(Monster_CheckAppearFlags(self))
267                 return;
268         
269         if not(monster_initialize(MON_KNIGHT, FALSE)) { remove(self); return; }
270 }
271
272 // compatibility with old spawns
273 void spawnfunc_monster_hell_knight() { spawnfunc_monster_knight(); }
274
275 float m_knight(float req)
276 {
277         switch(req)
278         {
279                 case MR_THINK:
280                 {
281                         monster_move(MON_CVAR(knight, speed_run), MON_CVAR(knight, speed_walk), MON_CVAR(knight, speed_stop), knight_anim_run, knight_anim_walk, knight_anim_stand);
282                         return TRUE;
283                 }
284                 case MR_DEATH:
285                 {
286                         float chance = random();
287                         monsters_setframe((random() > 0.5) ? knight_anim_death1 : knight_anim_death2);
288                         if(chance < 0.10 || self.flags & MONSTERFLAG_MINIBOSS)
289                         if(self.candrop)
290                         {
291                                 self.superweapons_finished = time + autocvar_g_balance_superweapons_time + 5; // give the player a few seconds to find the weapon
292                                 self.weapon = WEP_FIREBALL;
293                         }
294                         return TRUE;
295                 }
296                 case MR_SETUP:
297                 {
298                         if not(self.health) self.health = MON_CVAR(knight, health);
299                                 
300                         self.monster_attackfunc = knight_attack;
301                         monsters_setframe(knight_anim_stand);
302                         
303                         return TRUE;
304                 }
305                 case MR_INIT:
306                 {
307                         precache_sound ("player/lava.wav");
308                         return TRUE;
309                 }
310                 case MR_CONFIG:
311                 {
312                         MON_CONFIG_SETTINGS(KNIGHT_SETTINGS(knight))
313                         return TRUE;
314                 }
315         }
316         
317         return TRUE;
318 }
319
320 #endif // SVQC
321 #ifdef CSQC
322 float m_knight(float req)
323 {
324         switch(req)
325         {
326                 case MR_DEATH:
327                 {
328                         // nothing
329                         return TRUE;
330                 }
331                 case MR_INIT:
332                 {
333                         precache_model ("models/monsters/hknight.mdl");
334                         return TRUE;
335                 }
336         }
337         
338         return TRUE;
339 }
340
341 #endif // CSQC
342 #endif // REGISTER_MONSTER