]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/monster/zombie.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / monster / zombie.qc
1 #include "zombie.qh"
2
3 #ifdef SVQC
4 float autocvar_g_monster_zombie_health;
5 float autocvar_g_monster_zombie_damageforcescale = 0.55;
6 float autocvar_g_monster_zombie_attack_melee_damage;
7 float autocvar_g_monster_zombie_attack_melee_delay;
8 float autocvar_g_monster_zombie_attack_leap_damage;
9 float autocvar_g_monster_zombie_attack_leap_force;
10 float autocvar_g_monster_zombie_attack_leap_speed;
11 float autocvar_g_monster_zombie_attack_leap_delay;
12 float autocvar_g_monster_zombie_speed_stop;
13 float autocvar_g_monster_zombie_speed_run;
14 float autocvar_g_monster_zombie_speed_walk;
15
16 .vector moveto;
17
18 void M_Zombie_Attack_Leap_Touch(entity this, entity toucher)
19 {
20         if (GetResource(this, RES_HEALTH) <= 0)
21                 return;
22
23         vector angles_face;
24
25         if(toucher.takedamage)
26         {
27                 angles_face = vectoangles(this.moveto - this.origin);
28                 angles_face = normalize(angles_face) * (autocvar_g_monster_zombie_attack_leap_force);
29                 Damage(toucher, this, this, (autocvar_g_monster_zombie_attack_leap_damage) * MONSTER_SKILLMOD(this), DEATH_MONSTER_ZOMBIE_JUMP.m_id, DMG_NOWEP, toucher.origin, angles_face);
30                 settouch(this, Monster_Touch); // instantly turn it off to stop damage spam
31                 this.state = 0;
32         }
33
34         if (trace_dphitcontents)
35         {
36                 this.state = 0;
37                 settouch(this, Monster_Touch);
38         }
39 }
40
41 void M_Zombie_Defend_Block_End(entity this)
42 {
43         if(GetResource(this, RES_HEALTH) <= 0)
44                 return;
45
46         setanim(this, this.anim_blockend, false, true, true);
47         SetResourceExplicit(this, RES_ARMOR, autocvar_g_monsters_armor_blockpercent);
48 }
49
50 bool M_Zombie_Defend_Block(entity this)
51 {
52         SetResourceExplicit(this, RES_ARMOR, 0.9);
53         this.state = MONSTER_ATTACK_MELEE; // freeze monster
54         this.attack_finished_single[0] = time + 2.1;
55         this.anim_finished = this.attack_finished_single[0];
56         setanim(this, this.anim_blockstart, false, true, true);
57
58         Monster_Delay(this, 1, 2, M_Zombie_Defend_Block_End);
59
60         return true;
61 }
62
63 bool M_Zombie_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
64 {
65         switch(attack_type)
66         {
67                 case MONSTER_ATTACK_MELEE:
68                 {
69                         if(random() < 0.3 && GetResource(actor, RES_HEALTH) < 75 && GetResource(actor.enemy, RES_HEALTH) > 10)
70                                 return M_Zombie_Defend_Block(actor);
71
72                         float anim_chance = random();
73                         vector chosen_anim;
74
75                         if(anim_chance < 0.33)
76                                 chosen_anim = actor.anim_melee1;
77                         else if(anim_chance < 0.66)
78                                 chosen_anim = actor.anim_melee2;
79                         else
80                                 chosen_anim = actor.anim_melee3;
81
82                         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);
83                 }
84                 case MONSTER_ATTACK_RANGED:
85                 {
86                         makevectors(actor.angles);
87                         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));
88                 }
89         }
90
91         return false;
92 }
93
94 spawnfunc(monster_zombie) { Monster_Spawn(this, true, MON_ZOMBIE); }
95 #endif // SVQC
96
97 #ifdef SVQC
98 METHOD(Zombie, mr_think, bool(Zombie this, entity actor))
99 {
100     TC(Zombie, this);
101     if(time >= actor.spawn_time)
102         actor.damageforcescale = autocvar_g_monster_zombie_damageforcescale;
103     return true;
104 }
105
106 METHOD(Zombie, mr_pain, float(Zombie this, entity actor, float damage_take, entity attacker, float deathtype))
107 {
108     TC(Zombie, this);
109     actor.pain_finished = time + 0.34;
110     if(time >= actor.spawn_time)
111         setanim(actor, ((random() > 0.5) ? actor.anim_pain1 : actor.anim_pain2), true, true, false);
112     return damage_take;
113 }
114
115 METHOD(Zombie, mr_death, bool(Zombie this, entity actor))
116 {
117     TC(Zombie, this);
118     SetResourceExplicit(actor, RES_ARMOR, autocvar_g_monsters_armor_blockpercent);
119
120     setanim(actor, ((random() > 0.5) ? actor.anim_die1 : actor.anim_die2), false, true, true);
121     return true;
122 }
123 #endif
124 #ifdef GAMEQC
125 METHOD(Zombie, mr_anim, bool(Zombie this, entity actor))
126 {
127     TC(Zombie, this);
128     vector none = '0 0 0';
129     actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
130     actor.anim_die2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
131     actor.anim_spawn = animfixfps(actor, '30 1 3', none);
132     actor.anim_walk = animfixfps(actor, '27 1 1', none);
133     actor.anim_idle = animfixfps(actor, '19 1 1', none);
134     actor.anim_pain1 = animfixfps(actor, '20 1 2', none); // 0.5 seconds
135     actor.anim_pain2 = animfixfps(actor, '22 1 2', none); // 0.5 seconds
136     actor.anim_melee1 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
137     actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
138     actor.anim_melee3 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
139     actor.anim_shoot = animfixfps(actor, '0 1 5', none); // analyze models and set framerate
140     actor.anim_run = animfixfps(actor, '27 1 1', none);
141     actor.anim_blockstart = animfixfps(actor, '8 1 1', none);
142     actor.anim_blockend = animfixfps(actor, '7 1 1', none);
143     return true;
144 }
145 #endif
146 #ifdef SVQC
147 METHOD(Zombie, mr_setup, bool(Zombie this, entity actor))
148 {
149     TC(Zombie, this);
150     if(!GetResource(actor, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_zombie_health);
151     if(!actor.speed) { actor.speed = (autocvar_g_monster_zombie_speed_walk); }
152     if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_zombie_speed_run); }
153     if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_zombie_speed_stop); }
154
155     if(actor.spawnflags & MONSTERFLAG_NORESPAWN)
156         actor.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn
157
158     actor.spawnflags &= ~MONSTERFLAG_APPEAR; // once it's appeared, it will respawn quickly, we don't want it to appear
159
160     actor.spawnflags |= MONSTER_RESPAWN_DEATHPOINT;
161
162     actor.monster_loot = ITEM_HealthMedium;
163     actor.monster_attackfunc = M_Zombie_Attack;
164     StatusEffects_apply(STATUSEFFECT_SpawnShield, actor, actor.spawn_time, 0);
165     actor.respawntime = 0.2;
166     actor.damageforcescale = 0.0001; // no push while spawning
167
168     setanim(actor, actor.anim_spawn, false, true, true);
169     actor.spawn_time = actor.animstate_endtime;
170
171     return true;
172 }
173 #endif