1 // =========================
2 // SVQC Monster Properties
3 // =========================
8 if(self && IS_PLAYER(other) && other.deadflag == DEAD_NO)
11 self.think = SUB_Remove;
12 self.nextthink = time + 0.1;
16 void monster_item_spawn()
22 self.velocity = randomvec() * 175 + '0 0 325';
23 self.touch = M_Item_Touch;
25 SUB_SetFade(self, time + autocvar_g_monsters_drop_time, 1);
28 void monster_dropitem()
30 if(!self.candrop || !self.monster_loot)
33 vector org = self.origin + ((self.mins + self.maxs) * 0.5);
38 e.monster_loot = self.monster_loot;
41 MUTATOR_CALLHOOK(MonsterDropItem);
44 e.think = monster_item_spawn;
45 e.nextthink = time + 0.3;
48 void monsters_setframe(float _frame)
50 if(self.frame == _frame)
53 self.anim_start_time = time;
55 self.SendFlags |= MSF_ANIM;
58 float monster_isvalidtarget (entity targ, entity ent)
61 return FALSE; // someone doesn't exist
64 return FALSE; // don't attack ourselves
66 traceline(ent.origin, targ.origin, MOVE_NORMAL, ent);
74 if(targ.vehicle_flags & VHF_ISVEHICLE)
75 if not((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED)
76 return FALSE; // melee attacks are useless against vehicles
78 if(time < game_starttime)
79 return FALSE; // monsters do nothing before the match has started
81 if(vlen(targ.origin - ent.origin) >= ent.target_range)
82 return FALSE; // enemy is too far away
84 if(targ.takedamage == DAMAGE_NO)
85 return FALSE; // enemy can't be damaged
87 if(targ.items & IT_INVISIBILITY)
88 return FALSE; // enemy is invisible
90 if(substring(targ.classname, 0, 10) == "onslaught_")
91 return FALSE; // don't attack onslaught targets
93 if(IS_SPEC(targ) || IS_OBSERVER(targ))
94 return FALSE; // enemy is a spectator
96 if not(targ.vehicle_flags & VHF_ISVEHICLE)
97 if(targ.deadflag != DEAD_NO || ent.deadflag != DEAD_NO || targ.health <= 0 || ent.health <= 0)
98 return FALSE; // enemy/self is dead
100 if(ent.monster_owner == targ)
101 return FALSE; // don't attack our master
103 if(targ.monster_owner == ent)
104 return FALSE; // don't attack our pet
106 if not(targ.vehicle_flags & VHF_ISVEHICLE)
107 if(targ.flags & FL_NOTARGET)
108 return FALSE; // enemy can't be targeted
110 if not(autocvar_g_monsters_typefrag)
112 return FALSE; // no typefragging!
114 if not(IsDifferentTeam(targ, ent))
115 return FALSE; // enemy is on our team
117 if(autocvar_g_monsters_target_infront || ent.spawnflags & MONSTERFLAG_INFRONT)
118 if(ent.enemy != targ)
122 makevectors (ent.angles);
123 dot = normalize (targ.origin - ent.origin) * v_forward;
132 entity FindTarget (entity ent)
134 if(MUTATOR_CALLHOOK(MonsterFindTarget)) { return ent.enemy; } // Handled by a mutator
136 entity head, closest_target = world;
137 head = findradius(ent.origin, ent.target_range);
139 while(head) // find the closest acceptable target to pass to
141 if(monster_isvalidtarget(head, ent))
143 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
144 vector head_center = CENTER_OR_VIEWOFS(head);
145 vector ent_center = CENTER_OR_VIEWOFS(ent);
147 //if(ctf_CheckPassDirection(head_center, ent_center, ent.v_angle, head.WarpZone_findradius_nearest))
150 vector closest_target_center = CENTER_OR_VIEWOFS(closest_target);
151 if(vlen(ent_center - head_center) < vlen(ent_center - closest_target_center))
152 { closest_target = head; }
154 else { closest_target = head; }
160 return closest_target;
168 if(self.enemy != other)
169 if not(other.flags & FL_MONSTER)
170 if(monster_isvalidtarget(other, self))
174 string get_monster_model_datafilename(string m, float sk, string fil)
179 m = "models/monsters/*_";
181 m = strcat(m, ftos(sk));
184 return strcat(m, ".", fil);
187 void PrecacheMonsterSounds(string f)
191 fh = fopen(f, FILE_READ);
194 while((s = fgets(fh)))
196 if(tokenize_console(s) != 3)
198 dprint("Invalid sound info line: ", s, "\n");
201 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
206 void precache_monstersounds()
208 string m = (get_monsterinfo(self.monsterid)).model;
209 float globhandle, n, i;
212 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
215 n = search_getsize(globhandle);
216 for (i = 0; i < n; ++i)
218 //print(search_getfilename(globhandle, i), "\n");
219 f = search_getfilename(globhandle, i);
220 PrecacheMonsterSounds(f);
222 search_end(globhandle);
225 void ClearMonsterSounds()
227 #define _MSOUND(m) if(self.monstersound_##m) { strunzone(self.monstersound_##m); self.monstersound_##m = string_null; }
232 .string GetMonsterSoundSampleField(string type)
234 GetMonsterSoundSampleField_notFound = 0;
237 #define _MSOUND(m) case #m: return monstersound_##m;
241 GetMonsterSoundSampleField_notFound = 1;
245 float LoadMonsterSounds(string f, float first)
250 fh = fopen(f, FILE_READ);
253 dprint("Monster sound file not found: ", f, "\n");
256 while((s = fgets(fh)))
258 if(tokenize_console(s) != 3)
260 field = GetMonsterSoundSampleField(argv(0));
261 if(GetMonsterSoundSampleField_notFound)
264 strunzone(self.field);
265 self.field = strzone(strcat(argv(1), " ", argv(2)));
271 .float skin_for_monstersound;
272 void UpdateMonsterSounds()
274 entity mon = get_monsterinfo(self.monsterid);
276 if(self.skin == self.skin_for_monstersound)
278 self.skin_for_monstersound = self.skin;
279 ClearMonsterSounds();
280 //LoadMonsterSounds("sound/monsters/default.sounds", 1);
281 if(!autocvar_g_debug_defaultsounds)
282 if(!LoadMonsterSounds(get_monster_model_datafilename(mon.model, self.skin, "sounds"), 0))
283 LoadMonsterSounds(get_monster_model_datafilename(mon.model, 0, "sounds"), 0);
286 void MonsterSound(.string samplefield, float sound_delay, float delaytoo, float chan)
288 if(delaytoo && time < self.msound_delay)
290 GlobalSound(self.samplefield, chan, VOICETYPE_PLAYERSOUND);
292 self.msound_delay = time + sound_delay;
295 void monster_makevectors(entity e)
299 v = CENTER_OR_VIEWOFS(e);
300 self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
301 self.v_angle_x = -self.v_angle_x;
303 makevectors(self.v_angle);
306 float monster_melee(entity targ, float damg, float anim, float er, float anim_finished, float deathtype, float dostop)
308 float rdmg = damg * random();
310 if (self.health <= 0)
311 return FALSE; // attacking while dead?!
317 self.state = MONSTER_STATE_ATTACK_MELEE;
318 self.SendFlags |= MSF_MOVE;
321 monsters_setframe(anim);
323 if(anim_finished != 0)
324 self.attack_finished_single = time + anim_finished;
326 monster_makevectors(targ);
328 traceline(self.origin + self.view_ofs, self.origin + v_forward * er, 0, self);
330 if(trace_ent.takedamage)
331 Damage(trace_ent, self, self, rdmg * monster_skill, deathtype, trace_ent.origin, normalize(trace_ent.origin - self.origin));
336 void Monster_CheckMinibossFlag ()
338 if(MUTATOR_CALLHOOK(MonsterCheckBossFlag))
341 float chance = random() * 100;
343 // g_monsters_miniboss_chance cvar or spawnflags 64 causes a monster to be a miniboss
344 if ((self.spawnflags & MONSTERFLAG_MINIBOSS) || (chance < autocvar_g_monsters_miniboss_chance))
346 self.health += autocvar_g_monsters_miniboss_healthboost;
348 self.weapon = WEP_NEX;
352 float Monster_CanRespawn(entity ent)
355 if(MUTATOR_CALLHOOK(MonsterRespawn))
356 return TRUE; // enabled by a mutator
358 if(ent.spawnflags & MONSTERFLAG_NORESPAWN)
361 if not(autocvar_g_monsters_respawn)
369 if(Monster_CanRespawn(self))
371 self.monster_respawned = TRUE;
372 self.think = self.monster_spawnfunc;
373 self.nextthink = time + self.respawntime;
374 self.deadflag = DEAD_RESPAWNING;
375 if(self.spawnflags & MONSTER_RESPAWN_DEATHPOINT)
377 self.pos1 = self.origin;
378 self.pos2 = self.angles;
380 self.event_damage = func_null;
381 self.takedamage = DAMAGE_NO;
382 setorigin(self, self.pos1);
383 self.angles = self.pos2;
384 self.health = self.max_health;
386 self.SendFlags |= MSF_MOVE;
387 self.SendFlags |= MSF_STATUS;
390 SUB_SetFade(self, time + 3, 1);
393 float Monster_CanJump (vector vel)
396 return FALSE; // already attacking
397 if not(self.flags & FL_ONGROUND)
398 return FALSE; // not on the ground
400 return FALSE; // called when dead?
401 if(time < self.attack_finished_single)
402 return FALSE; // still attacking
404 vector old = self.velocity;
407 tracetoss(self, self);
409 if (trace_ent != self.enemy)
415 float monster_leap (float anm, void() touchfunc, vector vel, float anim_finished)
417 if(!Monster_CanJump(vel))
420 monsters_setframe(anm);
421 self.state = MONSTER_STATE_ATTACK_LEAP;
422 self.touch = touchfunc;
425 self.flags &= ~FL_ONGROUND;
427 self.attack_finished_single = time + anim_finished;
432 void monster_checkattack(entity e, entity targ)
439 if not(e.monster_attackfunc)
442 if(time < e.attack_finished_single)
445 if(vlen(targ.origin - e.origin) <= e.attack_range)
446 if(e.monster_attackfunc(MONSTER_ATTACK_MELEE))
448 //monster_sound(e.msound_attack_melee, 0, FALSE);
449 MonsterSound(monstersound_melee, 0, FALSE, CH_VOICE);
453 if(vlen(targ.origin - e.origin) > e.attack_range)
454 if(e.monster_attackfunc(MONSTER_ATTACK_RANGED))
456 //monster_sound(e.msound_attack_ranged, 0, FALSE);
457 MonsterSound(monstersound_ranged, 0, FALSE, CH_VOICE);
466 if(monster_isvalidtarget(activator, self))
467 self.enemy = activator;
471 .float last_enemycheck; // for checking enemy
472 vector monster_pickmovetarget(entity targ)
474 // enemy is always preferred target
477 makevectors(self.angles);
478 self.monster_movestate = MONSTER_MOVE_ENEMY;
479 self.last_trace = time + 1.2;
480 return self.enemy.origin;
483 switch(self.monster_moveflags)
485 case MONSTER_MOVE_OWNER:
487 self.monster_movestate = MONSTER_MOVE_OWNER;
488 self.last_trace = time + 0.3;
489 return (self.monster_owner) ? self.monster_owner.origin : self.origin;
491 case MONSTER_MOVE_SPAWNLOC:
493 self.monster_movestate = MONSTER_MOVE_SPAWNLOC;
494 self.last_trace = time + 2;
497 case MONSTER_MOVE_NOMOVE:
499 self.monster_movestate = MONSTER_MOVE_NOMOVE;
500 self.last_trace = time + 2;
504 case MONSTER_MOVE_WANDER:
507 self.monster_movestate = MONSTER_MOVE_WANDER;
508 self.last_trace = time + 2;
510 self.angles_y = rint(random() * 500);
511 makevectors(self.angles);
512 pos = self.origin + v_forward * 600;
514 if(self.flags & FL_FLY || self.flags & FL_SWIM)
515 if(self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
517 pos_z = random() * 200;
524 self.last_trace = time + 0.5;
533 void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_run, float manim_walk, float manim_idle)
535 fixedmakevectors(self.angles);
538 self.goalentity = find(world, targetname, self.target2);
544 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
545 self.health = max(1, self.max_health * self.revive_progress);
547 self.SendFlags |= MSF_STATUS;
549 movelib_beak_simple(stopspeed);
551 self.velocity = '0 0 0';
553 self.nextthink = time + 0.1;
555 if(self.revive_progress >= 1)
556 Unfreeze(self); // wait for next think before attacking
558 // don't bother updating angles here?
559 if(self.origin != self.oldorigin)
561 self.oldorigin = self.origin;
562 self.SendFlags |= MSF_MOVE;
565 return; // no moving while frozen
568 if(self.flags & FL_SWIM)
570 if(self.waterlevel < WATERLEVEL_WETFEET)
572 if(time >= self.last_trace)
574 self.fish_wasdrowning = TRUE;
575 self.last_trace = time + 0.4;
577 Damage (self, world, world, 2, DEATH_DROWN, self.origin, '0 0 0');
578 self.angles = '90 90 0';
581 self.velocity_y += random() * 50;
582 self.velocity_x -= random() * 50;
586 self.velocity_y -= random() * 50;
587 self.velocity_x += random() * 50;
589 self.velocity_z += random() * 150;
593 self.movetype = MOVETYPE_BOUNCE;
594 //self.velocity_z = -200;
596 self.SendFlags |= MSF_MOVE | MSF_ANG;
600 else if(self.fish_wasdrowning)
602 self.fish_wasdrowning = FALSE;
604 self.movetype = MOVETYPE_WALK;
608 targ = self.goalentity;
610 monster_target = targ;
611 monster_speed_run = runspeed;
612 monster_speed_walk = walkspeed;
614 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)
616 runspeed = walkspeed = 0;
617 if(time >= self.spawn_time)
618 monsters_setframe(manim_idle);
619 movelib_beak_simple(stopspeed);
620 if(self.oldorigin != self.origin)
622 self.oldorigin = self.origin;
623 self.SendFlags |= MSF_MOVE;
628 targ = monster_target;
629 runspeed = monster_speed_run;
630 walkspeed = monster_speed_walk;
633 if(autocvar_g_monsters_teams)
634 if(IsDifferentTeam(self.monster_owner, self))
635 self.monster_owner = world;
637 if(self.enemy && self.enemy.health < 1)
638 self.enemy = world; // enough!
640 if(time >= self.last_enemycheck)
642 if not(monster_isvalidtarget(self.enemy, self))
647 self.enemy = FindTarget(self);
649 MonsterSound(monstersound_sight, 0, FALSE, CH_VOICE);
650 //monster_sound(self.msound_sight, 0, FALSE);
653 self.last_enemycheck = time + 0.5;
656 if(self.state == MONSTER_STATE_ATTACK_MELEE && time >= self.attack_finished_single)
659 if(self.state != MONSTER_STATE_ATTACK_MELEE) // don't move if set
660 if(time >= self.last_trace || self.enemy) // update enemy instantly
661 self.moveto = monster_pickmovetarget(targ);
664 MonsterSound(monstersound_idle, 5, TRUE, CH_VOICE);
665 //monster_sound(self.msound_idle, 5, TRUE);
667 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
668 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
670 if(self.state == MONSTER_STATE_ATTACK_LEAP && (self.flags & FL_ONGROUND))
673 self.touch = MonsterTouch;
676 //self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
679 vector real_angle = vectoangles(self.steerto) - self.angles;
681 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
684 if(self.flags & FL_SWIM)
685 turny = vlen(self.angles - self.moveto);
689 turny = bound(turny * -1, shortangle_f(real_angle_y, self.angles_y), turny);
690 self.angles_y += turny;
693 if(self.state == MONSTER_STATE_ATTACK_MELEE)
694 self.moveto = self.origin;
696 if(self.enemy && self.enemy.vehicle)
699 if(((self.flags & FL_FLY) || (self.flags & FL_SWIM)) && self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
700 v_forward = normalize(self.moveto - self.origin);
702 self.moveto_z = self.origin_z;
704 if(vlen(self.origin - self.moveto) > 64)
706 if(self.flags & FL_FLY || self.flags & FL_SWIM)
707 movelib_move_simple(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
709 movelib_move_simple_gravity(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
711 if(time > self.pain_finished)
712 if(time > self.attack_finished_single)
713 if(vlen(self.velocity) > 10)
714 monsters_setframe((self.enemy) ? manim_run : manim_walk);
716 monsters_setframe(manim_idle);
720 entity e = find(world, targetname, self.target2);
722 self.target2 = e.target2;
724 self.target2 = e.target;
726 movelib_beak_simple(stopspeed);
727 if(time > self.attack_finished_single)
728 if(time > self.pain_finished)
729 if (vlen(self.velocity) <= 30)
730 monsters_setframe(manim_idle);
733 monster_checkattack(self, self.enemy);
735 if(self.angles != self.oldangles)
737 self.oldangles = self.angles;
738 self.SendFlags |= MSF_ANG;
741 if(self.origin != self.oldorigin)
743 self.oldorigin = self.origin;
744 self.SendFlags |= MSF_MOVE;
748 void monster_dead_think()
750 self.think = monster_dead_think;
751 self.nextthink = time + self.ticrate;
753 self.deadflag = DEAD_DEAD;
756 if(time >= self.ltime)
762 if(self.oldorigin != self.origin)
764 self.oldorigin = self.origin;
765 self.SendFlags |= MSF_MOVE;
769 void monsters_setstatus()
771 self.stat_monsters_total = monsters_total;
772 self.stat_monsters_killed = monsters_killed;
775 void Monster_Appear()
777 self.enemy = activator;
778 self.spawnflags &= ~MONSTERFLAG_APPEAR;
779 self.monster_spawnfunc();
782 float Monster_CheckAppearFlags(entity ent)
784 if not(ent.spawnflags & MONSTERFLAG_APPEAR)
787 ent.think = func_null;
789 ent.use = Monster_Appear;
790 ent.flags = FL_MONSTER; // set so this monster can get butchered
795 void monsters_reset()
797 setorigin(self, self.pos1);
798 self.angles = self.pos2;
800 self.health = self.max_health;
801 self.velocity = '0 0 0';
803 self.goalentity = world;
804 self.attack_finished_single = 0;
805 self.moveto = self.origin;
807 self.SendFlags |= MSF_STATUS;
810 float monster_send(entity to, float sf)
812 WriteByte(MSG_ENTITY, ENT_CLIENT_MONSTER);
813 WriteByte(MSG_ENTITY, sf);
816 WriteByte(MSG_ENTITY, self.monsterid);
818 WriteCoord(MSG_ENTITY, self.origin_x);
819 WriteCoord(MSG_ENTITY, self.origin_y);
820 WriteCoord(MSG_ENTITY, self.origin_z);
822 WriteAngle(MSG_ENTITY, self.angles_x);
823 WriteAngle(MSG_ENTITY, self.angles_y);
825 WriteByte(MSG_ENTITY, self.skin);
826 WriteByte(MSG_ENTITY, self.team);
831 WriteShort(MSG_ENTITY, rint(self.angles_x));
832 WriteShort(MSG_ENTITY, rint(self.angles_y));
837 WriteShort(MSG_ENTITY, rint(self.origin_x));
838 WriteShort(MSG_ENTITY, rint(self.origin_y));
839 WriteShort(MSG_ENTITY, rint(self.origin_z));
841 WriteShort(MSG_ENTITY, rint(self.velocity_x));
842 WriteShort(MSG_ENTITY, rint(self.velocity_y));
843 WriteShort(MSG_ENTITY, rint(self.velocity_z));
845 WriteShort(MSG_ENTITY, rint(self.angles_y));
850 WriteCoord(MSG_ENTITY, self.anim_start_time);
851 WriteByte(MSG_ENTITY, self.frame);
856 WriteByte(MSG_ENTITY, self.skin);
858 WriteByte(MSG_ENTITY, self.team);
860 WriteByte(MSG_ENTITY, self.deadflag);
863 WriteByte(MSG_ENTITY, 0);
865 WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
871 void monster_link(void() spawnproc)
873 Net_LinkEntity(self, TRUE, 0, monster_send);
874 self.think = spawnproc;
875 self.nextthink = time;
878 void monsters_corpse_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
880 self.health -= damage;
882 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
884 if(self.health <= -100) // 100 health until gone?
886 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
888 self.think = SUB_Remove;
889 self.nextthink = time + 0.1;
895 self.think = monster_dead_think;
896 self.nextthink = self.ticrate;
897 self.ltime = time + 5;
901 MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
902 //monster_sound(self.msound_death, 0, FALSE);
904 if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
905 monsters_killed += 1;
907 if(self.candrop && self.weapon)
908 W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325');
910 if(IS_CLIENT(self.realowner))
911 self.realowner.monstercount -= 1;
913 self.event_damage = monsters_corpse_damage;
914 self.solid = SOLID_CORPSE;
915 self.takedamage = DAMAGE_AIM;
917 self.movetype = MOVETYPE_TOSS;
918 self.moveto = self.origin;
919 self.touch = MonsterTouch; // reset incase monster was pouncing
921 if not(self.flags & FL_FLY)
922 self.velocity = '0 0 0';
924 self.SendFlags |= MSF_MOVE;
926 // number of monsters spawned with mobspawn command
929 MON_ACTION(self.monsterid, MR_DEATH);
932 void monsters_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
934 if(self.frozen && deathtype != DEATH_KILL)
937 if(time < self.pain_finished && deathtype != DEATH_KILL)
940 if(time < self.spawnshieldtime)
946 v = healtharmor_applydamage(self.armorvalue, self.m_armor_blockpercent, damage);
952 self.dmg_time = time;
954 if(sound_allowed(MSG_BROADCAST, attacker) && deathtype != DEATH_DROWN)
955 spamsound (self, CH_PAIN, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
957 self.velocity += force * self.damageforcescale;
959 if(deathtype != DEATH_DROWN)
961 Violence_GibSplash_At(hitloc, force, 2, bound(0, take, 200) / 16, self, attacker);
963 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
965 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
970 if(deathtype == DEATH_KILL)
971 self.candrop = FALSE; // killed by mobkill command
974 activator = attacker;
977 self.target2 = self.oldtarget2; // reset to original target on death, incase we respawn
981 frag_attacker = attacker;
983 MUTATOR_CALLHOOK(MonsterDies);
985 if(self.health <= -100) // check if we're already gibbed
987 Violence_GibSplash(self, 1, 0.5, attacker);
989 self.think = SUB_Remove;
990 self.nextthink = time + 0.1;
994 self.SendFlags |= MSF_STATUS;
999 self.think = monster_think;
1000 self.nextthink = self.ticrate;
1002 MON_ACTION(self.monsterid, MR_THINK);
1005 void monster_spawn()
1007 MON_ACTION(self.monsterid, MR_SETUP);
1009 if not(self.monster_respawned)
1010 Monster_CheckMinibossFlag();
1012 self.max_health = self.health;
1013 self.pain_finished = self.nextthink;
1014 self.anim_start_time = time;
1016 if not(self.noalign)
1018 setorigin(self, self.origin + '0 0 20');
1019 tracebox(self.origin + '0 0 100', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1020 setorigin(self, trace_endpos);
1023 if not(self.monster_respawned)
1025 self.skin = rint(random() * 4);
1027 if not(self.attack_range)
1028 self.attack_range = autocvar_g_monsters_attack_range;
1030 self.pos1 = self.origin;
1032 //monster_setupsounds(self.netname);
1033 precache_monstersounds();
1034 UpdateMonsterSounds();
1035 //monster_precachesounds(self);
1038 self.monster_attack = TRUE; // we can have monster enemies in team games
1040 //monster_sound(self.msound_spawn, 0, FALSE);
1041 MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
1043 self.think = monster_think;
1044 self.nextthink = time + self.ticrate;
1046 self.SendFlags |= MSF_SETUP;
1048 MUTATOR_CALLHOOK(MonsterSpawn);
1051 float monster_initialize(float mon_id, float nodrop)
1053 if not(autocvar_g_monsters)
1056 entity mon = get_monsterinfo(mon_id);
1058 // support for quake style removing monsters based on skill
1059 switch(monster_skill)
1062 case 1: if(self.spawnflags & MONSTERSKILL_NOTEASY) return FALSE; break;
1063 case 2: if(self.spawnflags & MONSTERSKILL_NOTMEDIUM) return FALSE; break;
1065 case 3: if(self.spawnflags & MONSTERSKILL_NOTHARD) return FALSE; break;
1068 if(self.team && !teamplay)
1071 if not(self.spawnflags & MONSTERFLAG_SPAWNED) // naturally spawned monster
1072 if not(self.monster_respawned)
1073 monsters_total += 1;
1075 setsize(self, mon.mins, mon.maxs);
1076 self.flags = FL_MONSTER;
1077 self.takedamage = DAMAGE_AIM;
1078 self.bot_attack = TRUE;
1079 self.iscreature = TRUE;
1080 self.teleportable = TRUE;
1081 self.damagedbycontents = TRUE;
1082 self.monsterid = mon_id;
1083 self.damageforcescale = 0;
1084 self.event_damage = monsters_damage;
1085 self.touch = MonsterTouch;
1086 self.use = monster_use;
1087 self.solid = SOLID_BBOX;
1088 self.movetype = MOVETYPE_WALK;
1089 self.spawnshieldtime = time + autocvar_g_monsters_spawnshieldtime;
1091 self.velocity = '0 0 0';
1092 self.moveto = self.origin;
1093 self.pos2 = self.angles;
1094 self.reset = monsters_reset;
1095 self.netname = mon.netname;
1096 self.monster_name = M_NAME(mon_id);
1097 self.candrop = TRUE;
1098 self.view_ofs = '0 0 1' * (self.maxs_z * 0.5);
1099 self.oldtarget2 = self.target2;
1100 self.deadflag = DEAD_NO;
1102 self.noalign = nodrop;
1103 self.spawn_time = time;
1105 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
1107 if(mon.spawnflags & MONSTER_TYPE_SWIM)
1108 self.flags |= FL_SWIM;
1110 if(mon.spawnflags & MONSTER_TYPE_FLY)
1112 self.flags |= FL_FLY;
1113 self.movetype = MOVETYPE_FLY;
1116 if(mon.spawnflags & MONSTER_SIZE_BROKEN)
1119 if not(self.ticrate)
1120 self.ticrate = autocvar_g_monsters_think_delay;
1122 self.ticrate = bound(sys_frametime, self.ticrate, 60);
1124 if not(self.m_armor_blockpercent)
1125 self.m_armor_blockpercent = 0.5;
1127 if not(self.target_range)
1128 self.target_range = autocvar_g_monsters_target_range;
1130 if not(self.respawntime)
1131 self.respawntime = autocvar_g_monsters_respawn_delay;
1133 if not(self.monster_moveflags)
1134 self.monster_moveflags = MONSTER_MOVE_WANDER;
1136 monster_link(monster_spawn);