1 // =========================
2 // SVQC Monster Properties
3 // =========================
6 void monster_item_spawn()
12 self.velocity = randomvec() * 175 + '0 0 325';
13 self.classname = "droppedweapon"; // hax
15 SUB_SetFade(self, time + autocvar_g_monsters_drop_time, 1);
18 void monster_dropitem()
20 if(!self.candrop || !self.monster_loot)
23 vector org = self.origin + ((self.mins + self.maxs) * 0.5);
28 e.monster_loot = self.monster_loot;
31 MUTATOR_CALLHOOK(MonsterDropItem);
36 e.think = monster_item_spawn;
37 e.nextthink = time + 0.3;
41 void monsters_setframe(float _frame)
43 if(self.frame == _frame)
46 self.anim_start_time = time;
48 self.SendFlags |= MSF_ANIM;
51 float monster_isvalidtarget (entity targ, entity ent)
54 return FALSE; // someone doesn't exist
57 return FALSE; // don't attack ourselves
59 traceline(ent.origin, targ.origin, MOVE_NORMAL, ent);
64 if(targ.vehicle_flags & VHF_ISVEHICLE)
65 if not((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED)
66 return FALSE; // melee attacks are useless against vehicles
68 if(time < game_starttime)
69 return FALSE; // monsters do nothing before the match has started
71 if(vlen(targ.origin - ent.origin) >= ent.target_range)
72 return FALSE; // enemy is too far away
74 if(targ.takedamage == DAMAGE_NO)
75 return FALSE; // enemy can't be damaged
77 if(targ.items & IT_INVISIBILITY)
78 return FALSE; // enemy is invisible
80 if(substring(targ.classname, 0, 10) == "onslaught_")
81 return FALSE; // don't attack onslaught targets
83 if(IS_SPEC(targ) || IS_OBSERVER(targ))
84 return FALSE; // enemy is a spectator
86 if not(targ.vehicle_flags & VHF_ISVEHICLE)
87 if(targ.deadflag != DEAD_NO || ent.deadflag != DEAD_NO || targ.health <= 0 || ent.health <= 0)
88 return FALSE; // enemy/self is dead
90 if(ent.monster_owner == targ)
91 return FALSE; // don't attack our master
93 if(targ.monster_owner == ent)
94 return FALSE; // don't attack our pet
96 if not(targ.vehicle_flags & VHF_ISVEHICLE)
97 if(targ.flags & FL_NOTARGET)
98 return FALSE; // enemy can't be targeted
100 if not(autocvar_g_monsters_typefrag)
102 return FALSE; // no typefragging!
104 if(SAME_TEAM(targ, ent))
105 return FALSE; // enemy is on our team
107 if(autocvar_g_monsters_target_infront || ent.spawnflags & MONSTERFLAG_INFRONT)
108 if(ent.enemy != targ)
112 makevectors (ent.angles);
113 dot = normalize (targ.origin - ent.origin) * v_forward;
122 entity FindTarget (entity ent)
124 if(MUTATOR_CALLHOOK(MonsterFindTarget)) { return ent.enemy; } // Handled by a mutator
126 entity head, closest_target = world;
127 head = findradius(ent.origin, ent.target_range);
129 while(head) // find the closest acceptable target to pass to
131 if(head.monster_attack)
132 if(monster_isvalidtarget(head, ent))
134 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
135 vector head_center = CENTER_OR_VIEWOFS(head);
136 vector ent_center = CENTER_OR_VIEWOFS(ent);
138 //if(ctf_CheckPassDirection(head_center, ent_center, ent.v_angle, head.WarpZone_findradius_nearest))
141 vector closest_target_center = CENTER_OR_VIEWOFS(closest_target);
142 if(vlen(ent_center - head_center) < vlen(ent_center - closest_target_center))
143 { closest_target = head; }
145 else { closest_target = head; }
151 return closest_target;
159 if(self.enemy != other)
160 if not(other.flags & FL_MONSTER)
161 if(monster_isvalidtarget(other, self))
165 string get_monster_model_datafilename(string m, float sk, string fil)
170 m = "models/monsters/*_";
172 m = strcat(m, ftos(sk));
175 return strcat(m, ".", fil);
178 void PrecacheMonsterSounds(string f)
182 fh = fopen(f, FILE_READ);
185 while((s = fgets(fh)))
187 if(tokenize_console(s) != 3)
189 dprint("Invalid sound info line: ", s, "\n");
192 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
197 void precache_monstersounds()
199 string m = (get_monsterinfo(self.monsterid)).model;
200 float globhandle, n, i;
203 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
206 n = search_getsize(globhandle);
207 for (i = 0; i < n; ++i)
209 //print(search_getfilename(globhandle, i), "\n");
210 f = search_getfilename(globhandle, i);
211 PrecacheMonsterSounds(f);
213 search_end(globhandle);
216 void ClearMonsterSounds()
218 #define _MSOUND(m) if(self.monstersound_##m) { strunzone(self.monstersound_##m); self.monstersound_##m = string_null; }
223 .string GetMonsterSoundSampleField(string type)
225 GetMonsterSoundSampleField_notFound = 0;
228 #define _MSOUND(m) case #m: return monstersound_##m;
232 GetMonsterSoundSampleField_notFound = 1;
236 float LoadMonsterSounds(string f, float first)
241 fh = fopen(f, FILE_READ);
244 dprint("Monster sound file not found: ", f, "\n");
247 while((s = fgets(fh)))
249 if(tokenize_console(s) != 3)
251 field = GetMonsterSoundSampleField(argv(0));
252 if(GetMonsterSoundSampleField_notFound)
255 strunzone(self.field);
256 self.field = strzone(strcat(argv(1), " ", argv(2)));
262 .float skin_for_monstersound;
263 void UpdateMonsterSounds()
265 entity mon = get_monsterinfo(self.monsterid);
267 if(self.skin == self.skin_for_monstersound)
269 self.skin_for_monstersound = self.skin;
270 ClearMonsterSounds();
271 //LoadMonsterSounds("sound/monsters/default.sounds", 1);
272 if(!autocvar_g_debug_defaultsounds)
273 if(!LoadMonsterSounds(get_monster_model_datafilename(mon.model, self.skin, "sounds"), 0))
274 LoadMonsterSounds(get_monster_model_datafilename(mon.model, 0, "sounds"), 0);
277 void MonsterSound(.string samplefield, float sound_delay, float delaytoo, float chan)
279 if(delaytoo && time < self.msound_delay)
281 GlobalSound(self.samplefield, chan, VOICETYPE_PLAYERSOUND);
283 self.msound_delay = time + sound_delay;
286 void monster_makevectors(entity e)
290 v = CENTER_OR_VIEWOFS(e);
291 self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
292 self.v_angle_x = -self.v_angle_x;
294 makevectors(self.v_angle);
297 float monster_melee(entity targ, float damg, float anim, float er, float anim_finished, float deathtype, float dostop)
299 float rdmg = damg * random();
301 if (self.health <= 0)
302 return FALSE; // attacking while dead?!
308 self.state = MONSTER_STATE_ATTACK_MELEE;
309 self.SendFlags |= MSF_MOVE;
312 monsters_setframe(anim);
314 if(anim_finished != 0)
315 self.attack_finished_single = time + anim_finished;
317 monster_makevectors(targ);
319 traceline(self.origin + self.view_ofs, self.origin + v_forward * er, 0, self);
321 if(trace_ent.takedamage)
322 Damage(trace_ent, self, self, rdmg * monster_skill, deathtype, trace_ent.origin, normalize(trace_ent.origin - self.origin));
327 void Monster_CheckMinibossFlag ()
329 if(MUTATOR_CALLHOOK(MonsterCheckBossFlag))
332 float chance = random() * 100;
334 // g_monsters_miniboss_chance cvar or spawnflags 64 causes a monster to be a miniboss
335 if ((self.spawnflags & MONSTERFLAG_MINIBOSS) || (chance < autocvar_g_monsters_miniboss_chance))
337 self.health += autocvar_g_monsters_miniboss_healthboost;
339 self.weapon = WEP_NEX;
343 float Monster_CanRespawn(entity ent)
346 if(MUTATOR_CALLHOOK(MonsterRespawn))
347 return TRUE; // enabled by a mutator
349 if(ent.spawnflags & MONSTERFLAG_NORESPAWN)
352 if not(autocvar_g_monsters_respawn)
360 if(Monster_CanRespawn(self))
362 self.monster_respawned = TRUE;
363 self.think = self.monster_spawnfunc;
364 self.nextthink = time + self.respawntime;
365 self.deadflag = DEAD_RESPAWNING;
366 if(self.spawnflags & MONSTER_RESPAWN_DEATHPOINT)
368 self.pos1 = self.origin;
369 self.pos2 = self.angles;
371 self.event_damage = func_null;
372 self.takedamage = DAMAGE_NO;
373 setorigin(self, self.pos1);
374 self.angles = self.pos2;
375 self.health = self.max_health;
377 self.SendFlags |= MSF_MOVE;
378 self.SendFlags |= MSF_STATUS;
381 SUB_SetFade(self, time + 3, 1);
384 float Monster_CanJump (vector vel)
387 return FALSE; // already attacking
388 if not(self.flags & FL_ONGROUND)
389 return FALSE; // not on the ground
391 return FALSE; // called when dead?
392 if(time < self.attack_finished_single)
393 return FALSE; // still attacking
395 vector old = self.velocity;
398 tracetoss(self, self);
400 if (trace_ent != self.enemy)
406 float monster_leap (float anm, void() touchfunc, vector vel, float anim_finished)
408 if(!Monster_CanJump(vel))
411 monsters_setframe(anm);
412 self.state = MONSTER_STATE_ATTACK_LEAP;
413 self.touch = touchfunc;
416 self.flags &= ~FL_ONGROUND;
418 self.attack_finished_single = time + anim_finished;
423 void monster_checkattack(entity e, entity targ)
430 if not(e.monster_attackfunc)
433 if(time < e.attack_finished_single)
436 if(vlen(targ.origin - e.origin) <= e.attack_range)
437 if(e.monster_attackfunc(MONSTER_ATTACK_MELEE))
439 MonsterSound(monstersound_melee, 0, FALSE, CH_VOICE);
443 if(vlen(targ.origin - e.origin) > e.attack_range)
444 if(e.monster_attackfunc(MONSTER_ATTACK_RANGED))
446 MonsterSound(monstersound_ranged, 0, FALSE, CH_VOICE);
455 if(monster_isvalidtarget(activator, self))
456 self.enemy = activator;
460 .float last_enemycheck; // for checking enemy
461 vector monster_pickmovetarget(entity targ)
463 // enemy is always preferred target
466 makevectors(self.angles);
467 self.monster_movestate = MONSTER_MOVE_ENEMY;
468 self.last_trace = time + 1.2;
469 return self.enemy.origin;
472 switch(self.monster_moveflags)
474 case MONSTER_MOVE_OWNER:
476 self.monster_movestate = MONSTER_MOVE_OWNER;
477 self.last_trace = time + 0.3;
478 return (self.monster_owner) ? self.monster_owner.origin : self.origin;
480 case MONSTER_MOVE_SPAWNLOC:
482 self.monster_movestate = MONSTER_MOVE_SPAWNLOC;
483 self.last_trace = time + 2;
486 case MONSTER_MOVE_NOMOVE:
488 self.monster_movestate = MONSTER_MOVE_NOMOVE;
489 self.last_trace = time + 2;
493 case MONSTER_MOVE_WANDER:
496 self.monster_movestate = MONSTER_MOVE_WANDER;
497 self.last_trace = time + 2;
499 self.angles_y = rint(random() * 500);
500 makevectors(self.angles);
501 pos = self.origin + v_forward * 600;
503 if(self.flags & FL_FLY || self.flags & FL_SWIM)
504 if(self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
506 pos_z = random() * 200;
513 self.last_trace = time + 0.5;
522 void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_run, float manim_walk, float manim_idle)
524 fixedmakevectors(self.angles);
527 self.goalentity = find(world, targetname, self.target2);
533 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
534 self.health = max(1, self.max_health * self.revive_progress);
536 self.SendFlags |= MSF_STATUS;
538 movelib_beak_simple(stopspeed);
540 self.velocity = '0 0 0';
542 self.nextthink = time + 0.1;
544 if(self.revive_progress >= 1)
545 Unfreeze(self); // wait for next think before attacking
547 // don't bother updating angles here?
548 if(self.origin != self.oldorigin)
550 self.oldorigin = self.origin;
551 self.SendFlags |= MSF_MOVE;
554 return; // no moving while frozen
557 if(self.flags & FL_SWIM)
559 if(self.waterlevel < WATERLEVEL_WETFEET)
561 if(time >= self.last_trace)
563 self.fish_wasdrowning = TRUE;
564 self.last_trace = time + 0.4;
566 Damage (self, world, world, 2, DEATH_DROWN, self.origin, '0 0 0');
567 self.angles = '90 90 0';
570 self.velocity_y += random() * 50;
571 self.velocity_x -= random() * 50;
575 self.velocity_y -= random() * 50;
576 self.velocity_x += random() * 50;
578 self.velocity_z += random() * 150;
582 self.movetype = MOVETYPE_BOUNCE;
583 //self.velocity_z = -200;
585 self.SendFlags |= MSF_MOVE | MSF_ANG;
589 else if(self.fish_wasdrowning)
591 self.fish_wasdrowning = FALSE;
593 self.movetype = MOVETYPE_WALK;
597 targ = self.goalentity;
599 monster_target = targ;
600 monster_speed_run = runspeed;
601 monster_speed_walk = walkspeed;
603 if(MUTATOR_CALLHOOK(MonsterMove) || gameover || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || time < game_starttime || (autocvar_g_campaign && !campaign_bots_may_start) || time < self.spawn_time)
605 runspeed = walkspeed = 0;
606 if(time >= self.spawn_time)
607 monsters_setframe(manim_idle);
608 movelib_beak_simple(stopspeed);
609 if(self.oldorigin != self.origin)
611 self.oldorigin = self.origin;
612 self.SendFlags |= MSF_MOVE;
617 targ = monster_target;
618 runspeed = monster_speed_run;
619 walkspeed = monster_speed_walk;
622 if(autocvar_g_monsters_teams)
623 if(DIFF_TEAM(self.monster_owner, self))
624 self.monster_owner = world;
626 if(self.enemy && self.enemy.health < 1)
627 self.enemy = world; // enough!
629 if(time >= self.last_enemycheck)
631 if not(monster_isvalidtarget(self.enemy, self))
636 self.enemy = FindTarget(self);
638 MonsterSound(monstersound_sight, 0, FALSE, CH_VOICE);
641 self.last_enemycheck = time + 0.5;
644 if(self.state == MONSTER_STATE_ATTACK_MELEE && time >= self.attack_finished_single)
647 if(self.state != MONSTER_STATE_ATTACK_MELEE) // don't move if set
648 if(time >= self.last_trace || self.enemy) // update enemy instantly
649 self.moveto = monster_pickmovetarget(targ);
652 MonsterSound(monstersound_idle, 5, TRUE, CH_VOICE);
654 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
655 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
657 if(self.state == MONSTER_STATE_ATTACK_LEAP && (self.flags & FL_ONGROUND))
660 self.touch = MonsterTouch;
663 //self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
666 vector real_angle = vectoangles(self.steerto) - self.angles;
668 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
671 if(self.flags & FL_SWIM)
672 turny = vlen(self.angles - self.moveto);
676 turny = bound(turny * -1, shortangle_f(real_angle_y, self.angles_y), turny);
677 self.angles_y += turny;
680 if(self.state == MONSTER_STATE_ATTACK_MELEE)
681 self.moveto = self.origin;
683 if(self.enemy && self.enemy.vehicle)
686 if(((self.flags & FL_FLY) || (self.flags & FL_SWIM)) && self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
687 v_forward = normalize(self.moveto - self.origin);
689 self.moveto_z = self.origin_z;
691 if(vlen(self.origin - self.moveto) > 64)
693 if(self.flags & FL_FLY || self.flags & FL_SWIM)
694 movelib_move_simple(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
696 movelib_move_simple_gravity(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
698 if(time > self.pain_finished)
699 if(time > self.attack_finished_single)
700 if(vlen(self.velocity) > 10)
701 monsters_setframe((self.enemy) ? manim_run : manim_walk);
703 monsters_setframe(manim_idle);
707 entity e = find(world, targetname, self.target2);
709 self.target2 = e.target2;
711 self.target2 = e.target;
713 movelib_beak_simple(stopspeed);
714 if(time > self.attack_finished_single)
715 if(time > self.pain_finished)
716 if (vlen(self.velocity) <= 30)
717 monsters_setframe(manim_idle);
720 monster_checkattack(self, self.enemy);
722 if(self.angles != self.oldangles)
724 self.oldangles = self.angles;
725 self.SendFlags |= MSF_ANG;
728 if(self.origin != self.oldorigin)
730 self.oldorigin = self.origin;
731 self.SendFlags |= MSF_MOVE;
735 void monster_dead_think()
737 self.think = monster_dead_think;
738 self.nextthink = time + self.ticrate;
740 self.deadflag = DEAD_DEAD;
743 if(time >= self.ltime)
749 if(self.oldorigin != self.origin)
751 self.oldorigin = self.origin;
752 self.SendFlags |= MSF_MOVE;
756 void monsters_setstatus()
758 self.stat_monsters_total = monsters_total;
759 self.stat_monsters_killed = monsters_killed;
762 void Monster_Appear()
764 self.enemy = activator;
765 self.spawnflags &= ~MONSTERFLAG_APPEAR;
766 self.monster_spawnfunc();
769 float Monster_CheckAppearFlags(entity ent)
771 if not(ent.spawnflags & MONSTERFLAG_APPEAR)
774 ent.think = func_null;
776 ent.use = Monster_Appear;
777 ent.flags = FL_MONSTER; // set so this monster can get butchered
782 void monsters_reset()
784 setorigin(self, self.pos1);
785 self.angles = self.pos2;
787 self.health = self.max_health;
788 self.velocity = '0 0 0';
790 self.goalentity = world;
791 self.attack_finished_single = 0;
792 self.moveto = self.origin;
794 self.SendFlags |= MSF_STATUS;
797 float monster_send(entity to, float sf)
799 WriteByte(MSG_ENTITY, ENT_CLIENT_MONSTER);
800 WriteByte(MSG_ENTITY, sf);
803 WriteByte(MSG_ENTITY, self.monsterid);
805 WriteCoord(MSG_ENTITY, self.origin_x);
806 WriteCoord(MSG_ENTITY, self.origin_y);
807 WriteCoord(MSG_ENTITY, self.origin_z);
809 WriteAngle(MSG_ENTITY, self.angles_x);
810 WriteAngle(MSG_ENTITY, self.angles_y);
812 WriteByte(MSG_ENTITY, self.skin);
813 WriteByte(MSG_ENTITY, self.team);
818 WriteShort(MSG_ENTITY, rint(self.angles_x));
819 WriteShort(MSG_ENTITY, rint(self.angles_y));
824 WriteShort(MSG_ENTITY, rint(self.origin_x));
825 WriteShort(MSG_ENTITY, rint(self.origin_y));
826 WriteShort(MSG_ENTITY, rint(self.origin_z));
828 WriteShort(MSG_ENTITY, rint(self.velocity_x));
829 WriteShort(MSG_ENTITY, rint(self.velocity_y));
830 WriteShort(MSG_ENTITY, rint(self.velocity_z));
832 WriteShort(MSG_ENTITY, rint(self.angles_y));
837 WriteCoord(MSG_ENTITY, self.anim_start_time);
838 WriteByte(MSG_ENTITY, self.frame);
843 WriteByte(MSG_ENTITY, self.skin);
845 WriteByte(MSG_ENTITY, self.team);
847 WriteByte(MSG_ENTITY, self.deadflag);
850 WriteByte(MSG_ENTITY, 0);
852 WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
858 void monster_link(void() spawnproc)
860 Net_LinkEntity(self, TRUE, 0, monster_send);
861 self.think = spawnproc;
862 self.nextthink = time;
865 void monsters_corpse_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
867 self.health -= damage;
869 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
871 if(self.health <= -100) // 100 health until gone?
873 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
875 self.think = SUB_Remove;
876 self.nextthink = time + 0.1;
882 self.think = monster_dead_think;
883 self.nextthink = self.ticrate;
884 self.ltime = time + 5;
888 MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
890 if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
891 monsters_killed += 1;
893 if(self.candrop && self.weapon)
894 W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325');
896 if(IS_CLIENT(self.realowner))
897 if not(self.monster_respawned)
898 self.realowner.monstercount -= 1;
900 self.event_damage = monsters_corpse_damage;
901 self.solid = SOLID_CORPSE;
902 self.takedamage = DAMAGE_AIM;
904 self.movetype = MOVETYPE_TOSS;
905 self.moveto = self.origin;
906 self.touch = MonsterTouch; // reset incase monster was pouncing
907 self.reset = func_null;
909 self.attack_finished_single = 0;
911 if not(self.flags & FL_FLY)
912 self.velocity = '0 0 0';
914 self.SendFlags |= MSF_MOVE;
916 // number of monsters spawned with mobspawn command
919 MON_ACTION(self.monsterid, MR_DEATH);
922 void monsters_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
924 if(self.frozen && deathtype != DEATH_KILL)
927 if(time < self.pain_finished && deathtype != DEATH_KILL)
930 if(time < self.spawnshieldtime)
936 v = healtharmor_applydamage(self.armorvalue, self.m_armor_blockpercent, damage);
942 self.dmg_time = time;
944 if(sound_allowed(MSG_BROADCAST, attacker) && deathtype != DEATH_DROWN)
945 spamsound (self, CH_PAIN, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
947 self.velocity += force * self.damageforcescale;
949 if(deathtype != DEATH_DROWN)
951 Violence_GibSplash_At(hitloc, force, 2, bound(0, take, 200) / 16, self, attacker);
953 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
955 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
960 if(deathtype == DEATH_KILL)
961 self.candrop = FALSE; // killed by mobkill command
964 activator = attacker;
967 self.target2 = self.oldtarget2; // reset to original target on death, incase we respawn
971 frag_attacker = attacker;
973 MUTATOR_CALLHOOK(MonsterDies);
975 if(self.health <= -100) // check if we're already gibbed
977 Violence_GibSplash(self, 1, 0.5, attacker);
979 self.think = SUB_Remove;
980 self.nextthink = time + 0.1;
984 self.SendFlags |= MSF_STATUS;
989 self.think = monster_think;
990 self.nextthink = self.ticrate;
992 MON_ACTION(self.monsterid, MR_THINK);
997 MON_ACTION(self.monsterid, MR_SETUP);
999 if not(self.monster_respawned)
1000 Monster_CheckMinibossFlag();
1002 self.max_health = self.health;
1003 self.pain_finished = self.nextthink;
1004 self.anim_start_time = time;
1006 if not(self.noalign)
1008 setorigin(self, self.origin + '0 0 20');
1009 tracebox(self.origin + '0 0 100', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1010 setorigin(self, trace_endpos);
1013 if not(self.monster_respawned)
1015 self.skin = rint(random() * 4);
1017 if not(self.attack_range)
1018 self.attack_range = autocvar_g_monsters_attack_range;
1020 self.pos1 = self.origin;
1022 //monster_setupsounds(self.netname);
1023 precache_monstersounds();
1024 UpdateMonsterSounds();
1025 //monster_precachesounds(self);
1028 self.monster_attack = TRUE; // we can have monster enemies in team games
1030 MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
1032 self.think = monster_think;
1033 self.nextthink = time + self.ticrate;
1035 self.SendFlags |= MSF_SETUP;
1037 MUTATOR_CALLHOOK(MonsterSpawn);
1040 float monster_initialize(float mon_id, float nodrop)
1042 if not(autocvar_g_monsters)
1045 entity mon = get_monsterinfo(mon_id);
1047 // support for quake style removing monsters based on skill
1048 switch(monster_skill)
1051 case 1: if(self.spawnflags & MONSTERSKILL_NOTEASY) return FALSE; break;
1052 case 2: if(self.spawnflags & MONSTERSKILL_NOTMEDIUM) return FALSE; break;
1054 case 3: if(self.spawnflags & MONSTERSKILL_NOTHARD) return FALSE; break;
1057 if(self.team && !teamplay)
1060 if not(self.spawnflags & MONSTERFLAG_SPAWNED) // naturally spawned monster
1061 if not(self.monster_respawned)
1062 monsters_total += 1;
1064 setsize(self, mon.mins, mon.maxs);
1065 self.flags = FL_MONSTER;
1066 self.takedamage = DAMAGE_AIM;
1067 self.bot_attack = TRUE;
1068 self.iscreature = TRUE;
1069 self.teleportable = TRUE;
1070 self.damagedbycontents = TRUE;
1071 self.monsterid = mon_id;
1072 self.damageforcescale = 0;
1073 self.event_damage = monsters_damage;
1074 self.touch = MonsterTouch;
1075 self.use = monster_use;
1076 self.solid = SOLID_BBOX;
1077 self.movetype = MOVETYPE_WALK;
1078 self.spawnshieldtime = time + autocvar_g_monsters_spawnshieldtime;
1080 self.velocity = '0 0 0';
1081 self.moveto = self.origin;
1082 self.pos2 = self.angles;
1083 self.reset = monsters_reset;
1084 self.netname = mon.netname;
1085 self.monster_name = M_NAME(mon_id);
1086 self.candrop = TRUE;
1087 self.view_ofs = '0 0 1' * (self.maxs_z * 0.5);
1088 self.oldtarget2 = self.target2;
1089 self.deadflag = DEAD_NO;
1091 self.noalign = nodrop;
1092 self.spawn_time = time;
1094 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
1096 if(mon.spawnflags & MONSTER_TYPE_SWIM)
1097 self.flags |= FL_SWIM;
1099 if(mon.spawnflags & MONSTER_TYPE_FLY)
1101 self.flags |= FL_FLY;
1102 self.movetype = MOVETYPE_FLY;
1105 if(mon.spawnflags & MONSTER_SIZE_BROKEN)
1108 if not(self.ticrate)
1109 self.ticrate = autocvar_g_monsters_think_delay;
1111 self.ticrate = bound(sys_frametime, self.ticrate, 60);
1113 if not(self.m_armor_blockpercent)
1114 self.m_armor_blockpercent = 0.5;
1116 if not(self.target_range)
1117 self.target_range = autocvar_g_monsters_target_range;
1119 if not(self.respawntime)
1120 self.respawntime = autocvar_g_monsters_respawn_delay;
1122 if not(self.monster_moveflags)
1123 self.monster_moveflags = MONSTER_MOVE_WANDER;
1125 monster_link(monster_spawn);