]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/zombie.qc
Merge branch 'terencehill/hide_motd' into 'master'
[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 .vector moveto;
77
78 void M_Zombie_Attack_Leap_Touch()
79 {SELFPARAM();
80         if (self.health <= 0)
81                 return;
82
83         vector angles_face;
84
85         if(other.takedamage)
86         {
87                 angles_face = vectoangles(self.moveto - self.origin);
88                 angles_face = normalize(angles_face) * (autocvar_g_monster_zombie_attack_leap_force);
89                 Damage(other, self, self, (autocvar_g_monster_zombie_attack_leap_damage) * MONSTER_SKILLMOD(self), DEATH_MONSTER_ZOMBIE_JUMP.m_id, other.origin, angles_face);
90                 self.touch = Monster_Touch; // instantly turn it off to stop damage spam
91                 self.state = 0;
92         }
93
94         if (trace_dphitcontents)
95         {
96                 self.state = 0;
97                 self.touch = Monster_Touch;
98         }
99 }
100
101 void M_Zombie_Defend_Block_End()
102 {SELFPARAM();
103         if(self.health <= 0)
104                 return;
105
106         setanim(self, self.anim_blockend, false, true, true);
107         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
108 }
109
110 float M_Zombie_Defend_Block()
111 {SELFPARAM();
112         self.armorvalue = 0.9;
113         self.state = MONSTER_ATTACK_MELEE; // freeze monster
114         self.attack_finished_single[0] = time + 2.1;
115         self.anim_finished = self.attack_finished_single[0];
116         setanim(self, self.anim_blockstart, false, true, true);
117
118         Monster_Delay(1, 0, 2, M_Zombie_Defend_Block_End);
119
120         return true;
121 }
122
123 float M_Zombie_Attack(float attack_type, entity targ)
124 {SELFPARAM();
125         switch(attack_type)
126         {
127                 case MONSTER_ATTACK_MELEE:
128                 {
129                         if(random() < 0.3 && self.health < 75 && self.enemy.health > 10)
130                                 return M_Zombie_Defend_Block();
131
132                         float rand = random();
133                         vector chosen_anim;
134
135                         if(rand < 0.33)
136                                 chosen_anim = self.anim_melee1;
137                         else if(rand < 0.66)
138                                 chosen_anim = self.anim_melee2;
139                         else
140                                 chosen_anim = self.anim_melee3;
141
142                         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.m_id, true);
143                 }
144                 case MONSTER_ATTACK_RANGED:
145                 {
146                         makevectors(self.angles);
147                         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));
148                 }
149         }
150
151         return false;
152 }
153
154 spawnfunc(monster_zombie) { Monster_Spawn(MON_ZOMBIE.monsterid); }
155 #endif // SVQC
156
157                 #ifdef SVQC
158                 METHOD(Zombie, mr_think, bool(Zombie thismon))
159                 {
160                         SELFPARAM();
161                         if(time >= self.spawn_time)
162                                 self.damageforcescale = autocvar_g_monster_zombie_damageforcescale;
163                         return true;
164                 }
165                 METHOD(Zombie, mr_pain, bool(Zombie thismon))
166                 {
167                         SELFPARAM();
168                         self.pain_finished = time + 0.34;
169                         setanim(self, ((random() > 0.5) ? self.anim_pain1 : self.anim_pain2), true, true, false);
170                         return true;
171                 }
172                 METHOD(Zombie, mr_death, bool(Zombie thismon))
173                 {
174                         SELFPARAM();
175                         self.armorvalue = autocvar_g_monsters_armor_blockpercent;
176
177                         setanim(self, ((random() > 0.5) ? self.anim_die1 : self.anim_die2), false, true, true);
178                         return true;
179                 }
180                 #endif
181                 #ifndef MENUQC
182                 METHOD(Zombie, mr_anim, bool(Zombie thismon))
183                 {
184                         SELFPARAM();
185                         vector none = '0 0 0';
186                         self.anim_die1 = animfixfps(self, '9 1 0.5', none); // 2 seconds
187                         self.anim_die2 = animfixfps(self, '12 1 0.5', none); // 2 seconds
188                         self.anim_spawn = animfixfps(self, '30 1 3', none);
189                         self.anim_walk = animfixfps(self, '27 1 1', none);
190                         self.anim_idle = animfixfps(self, '19 1 1', none);
191                         self.anim_pain1 = animfixfps(self, '20 1 2', none); // 0.5 seconds
192                         self.anim_pain2 = animfixfps(self, '22 1 2', none); // 0.5 seconds
193                         self.anim_melee1 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
194                         self.anim_melee2 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
195                         self.anim_melee3 = animfixfps(self, '4 1 5', none); // analyze models and set framerate
196                         self.anim_shoot = animfixfps(self, '0 1 5', none); // analyze models and set framerate
197                         self.anim_run = animfixfps(self, '27 1 1', none);
198                         self.anim_blockstart = animfixfps(self, '8 1 1', none);
199                         self.anim_blockend = animfixfps(self, '7 1 1', none);
200
201                         return true;
202                 }
203                 #endif
204                 #ifdef SVQC
205                 METHOD(Zombie, mr_setup, bool(Zombie thismon))
206                 {
207                         if(!self.health) self.health = (autocvar_g_monster_zombie_health);
208                         if(!self.speed) { self.speed = (autocvar_g_monster_zombie_speed_walk); }
209                         if(!self.speed2) { self.speed2 = (autocvar_g_monster_zombie_speed_run); }
210                         if(!self.stopspeed) { self.stopspeed = (autocvar_g_monster_zombie_speed_stop); }
211
212                         if(self.spawnflags & MONSTERFLAG_NORESPAWN)
213                                 self.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn
214
215                         self.spawnflags |= MONSTER_RESPAWN_DEATHPOINT;
216
217                         self.monster_loot = spawnfunc_item_health_medium;
218                         self.monster_attackfunc = M_Zombie_Attack;
219                         self.spawnshieldtime = self.spawn_time;
220                         self.respawntime = 0.2;
221                         self.damageforcescale = 0.0001; // no push while spawning
222
223                         setanim(self, self.anim_spawn, false, true, true);
224                         self.spawn_time = self.animstate_endtime;
225
226                         return true;
227                 }
228                 METHOD(Zombie, mr_precache, bool(Zombie thismon))
229                 {
230                         return true;
231                 }
232                 #endif
233
234 #endif