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