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