]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/zombie.qc
Move mod directory below qcsrc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / zombie.qc
1 #ifndef MENUQC
2 bool M_Zombie(int);
3 #endif
4 REGISTER_MONSTER_SIMPLE(
5 /* MON_##id   */ ZOMBIE,
6 /* spawnflags */ MON_FLAG_MELEE | MON_FLAG_RIDE,
7 /* mins,maxs  */ '-18 -18 -25', '18 18 47',
8 /* model      */ "zombie.dpm",
9 /* netname    */ "zombie",
10 /* fullname   */ _("Zombie")
11 ) {
12 #ifndef MENUQC
13         this.monster_func = M_Zombie;
14         this.monster_func(MR_PRECACHE);
15 #endif
16 }
17
18 #ifdef SVQC
19 float autocvar_g_monster_zombie_health;
20 float autocvar_g_monster_zombie_damageforcescale = 0.55;
21 float autocvar_g_monster_zombie_attack_melee_damage;
22 float autocvar_g_monster_zombie_attack_melee_delay;
23 float autocvar_g_monster_zombie_attack_leap_damage;
24 float autocvar_g_monster_zombie_attack_leap_force;
25 float autocvar_g_monster_zombie_attack_leap_speed;
26 float autocvar_g_monster_zombie_attack_leap_delay;
27 float autocvar_g_monster_zombie_speed_stop;
28 float autocvar_g_monster_zombie_speed_run;
29 float autocvar_g_monster_zombie_speed_walk;
30
31 /*
32 const float zombie_anim_attackleap                      = 0;
33 const float zombie_anim_attackrun1                      = 1;
34 const float zombie_anim_attackrun2                      = 2;
35 const float zombie_anim_attackrun3                      = 3;
36 const float zombie_anim_attackstanding1         = 4;
37 const float zombie_anim_attackstanding2         = 5;
38 const float zombie_anim_attackstanding3         = 6;
39 const float zombie_anim_blockend                        = 7;
40 const float zombie_anim_blockstart                      = 8;
41 const float zombie_anim_deathback1                      = 9;
42 const float zombie_anim_deathback2                      = 10;
43 const float zombie_anim_deathback3                      = 11;
44 const float zombie_anim_deathfront1                     = 12;
45 const float zombie_anim_deathfront2                     = 13;
46 const float zombie_anim_deathfront3                     = 14;
47 const float zombie_anim_deathleft1                      = 15;
48 const float zombie_anim_deathleft2                      = 16;
49 const float zombie_anim_deathright1                     = 17;
50 const float zombie_anim_deathright2                     = 18;
51 const float zombie_anim_idle                            = 19;
52 const float zombie_anim_painback1                       = 20;
53 const float zombie_anim_painback2                       = 21;
54 const float zombie_anim_painfront1                      = 22;
55 const float zombie_anim_painfront2                      = 23;
56 const float zombie_anim_runbackwards            = 24;
57 const float zombie_anim_runbackwardsleft        = 25;
58 const float zombie_anim_runbackwardsright       = 26;
59 const float zombie_anim_runforward                      = 27;
60 const float zombie_anim_runforwardleft          = 28;
61 const float zombie_anim_runforwardright         = 29;
62 const float zombie_anim_spawn                           = 30;
63 */
64
65 void M_Zombie_Attack_Leap_Touch()
66 {
67         if (self.health <= 0)
68                 return;
69
70         vector angles_face;
71
72         if(other.takedamage)
73         {
74                 angles_face = vectoangles(self.moveto - self.origin);
75                 angles_face = normalize(angles_face) * (autocvar_g_monster_zombie_attack_leap_force);
76                 Damage(other, self, self, (autocvar_g_monster_zombie_attack_leap_damage) * MONSTER_SKILLMOD(self), DEATH_MONSTER_ZOMBIE_JUMP, other.origin, angles_face);
77                 self.touch = Monster_Touch; // instantly turn it off to stop damage spam
78                 self.state = 0;
79         }
80
81         if (trace_dphitcontents)
82         {
83                 self.state = 0;
84                 self.touch = Monster_Touch;
85         }
86 }
87
88 void M_Zombie_Defend_Block_End()
89 {
90         if(self.health <= 0)
91                 return;
92
93         setanim(self, self.anim_blockend, false, true, true);
94         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
95 }
96
97 float M_Zombie_Defend_Block()
98 {
99         self.armorvalue = 0.9;
100         self.state = MONSTER_ATTACK_MELEE; // freeze monster
101         self.attack_finished_single = time + 2.1;
102         self.anim_finished = self.attack_finished_single;
103         setanim(self, self.anim_blockstart, false, true, true);
104
105         Monster_Delay(1, 0, 2, M_Zombie_Defend_Block_End);
106
107         return true;
108 }
109
110 float M_Zombie_Attack(float attack_type)
111 {
112         switch(attack_type)
113         {
114                 case MONSTER_ATTACK_MELEE:
115                 {
116                         if(random() < 0.3 && self.health < 75 && self.enemy.health > 10)
117                                 return M_Zombie_Defend_Block();
118
119                         float rand = random();
120                         vector chosen_anim;
121
122                         if(rand < 0.33)
123                                 chosen_anim = self.anim_melee1;
124                         else if(rand < 0.66)
125                                 chosen_anim = self.anim_melee2;
126                         else
127                                 chosen_anim = self.anim_melee3;
128
129                         return Monster_Attack_Melee(self.enemy, (autocvar_g_monster_zombie_attack_melee_damage), chosen_anim, self.attack_range, (autocvar_g_monster_zombie_attack_melee_delay), DEATH_MONSTER_ZOMBIE_MELEE, true);
130                 }
131                 case MONSTER_ATTACK_RANGED:
132                 {
133                         makevectors(self.angles);
134                         return Monster_Attack_Leap(self.anim_shoot, M_Zombie_Attack_Leap_Touch, v_forward * (autocvar_g_monster_zombie_attack_leap_speed) + '0 0 200', (autocvar_g_monster_zombie_attack_leap_delay));
135                 }
136         }
137
138         return false;
139 }
140
141 void spawnfunc_monster_zombie() { Monster_Spawn(MON_ZOMBIE.monsterid); }
142 #endif // SVQC
143
144 bool M_Zombie(int req)
145 {
146         switch(req)
147         {
148                 #ifdef SVQC
149                 case MR_THINK:
150                 {
151                         if(time >= self.spawn_time)
152                                 self.damageforcescale = autocvar_g_monster_zombie_damageforcescale;
153                         return true;
154                 }
155                 case MR_PAIN:
156                 {
157                         self.pain_finished = time + 0.34;
158                         setanim(self, ((random() > 0.5) ? self.anim_pain1 : self.anim_pain2), true, true, false);
159                         return true;
160                 }
161                 case MR_DEATH:
162                 {
163                         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
164
165                         setanim(self, ((random() > 0.5) ? self.anim_die1 : self.anim_die2), false, true, true);
166                         return true;
167                 }
168                 #endif
169                 #ifndef MENUQC
170                 case MR_ANIM:
171                 {
172                         vector none = '0 0 0';
173                         self.anim_die1 = animfixfps(self, '9 1 0.5', none); // 2 seconds
174                         self.anim_die2 = animfixfps(self, '12 1 0.5', none); // 2 seconds
175                         self.anim_spawn = animfixfps(self, '30 1 3', none);
176                         self.anim_walk = animfixfps(self, '27 1 1', none);
177                         self.anim_idle = animfixfps(self, '19 1 1', none);
178                         self.anim_pain1 = animfixfps(self, '20 1 2', none); // 0.5 seconds
179                         self.anim_pain2 = animfixfps(self, '22 1 2', none); // 0.5 seconds
180                         self.anim_melee1 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
181                         self.anim_melee2 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
182                         self.anim_melee3 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
183                         self.anim_shoot = animfixfps(self, '0 1 5', none); // analyze models and set framerate
184                         self.anim_run = animfixfps(self, '27 1 1', none);
185                         self.anim_blockstart = animfixfps(self, '8 1 1', none);
186                         self.anim_blockend = animfixfps(self, '7 1 1', none);
187
188                         return true;
189                 }
190                 #endif
191                 #ifdef SVQC
192                 case MR_SETUP:
193                 {
194                         if(!self.health) self.health = (autocvar_g_monster_zombie_health);
195                         if(!self.speed) { self.speed = (autocvar_g_monster_zombie_speed_walk); }
196                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_zombie_speed_run); }
197                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_zombie_speed_stop); }
198
199                         if(self.spawnflags & MONSTERFLAG_NORESPAWN)
200                                 self.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn
201
202                         self.spawnflags |= MONSTER_RESPAWN_DEATHPOINT;
203
204                         self.monster_loot = spawnfunc_item_health_medium;
205                         self.monster_attackfunc = M_Zombie_Attack;
206                         self.spawnshieldtime = self.spawn_time;
207                         self.respawntime = 0.2;
208                         self.damageforcescale = 0.0001; // no push while spawning
209
210                         setanim(self, self.anim_spawn, false, true, true);
211                         self.spawn_time = self.animstate_endtime;
212
213                         return true;
214                 }
215                 case MR_PRECACHE:
216                 {
217                         precache_model("models/monsters/zombie.dpm");
218                         return true;
219                 }
220                 #endif
221         }
222
223         return true;
224 }