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