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);
71 if(targ.vehicle_flags & VHF_ISVEHICLE)
72 if not((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED)
73 return FALSE; // melee attacks are useless against vehicles
75 if(time < game_starttime)
76 return FALSE; // monsters do nothing before the match has started
78 if(vlen(targ.origin - ent.origin) >= ent.target_range)
79 return FALSE; // enemy is too far away
81 if(targ.takedamage == DAMAGE_NO)
82 return FALSE; // enemy can't be damaged
84 if(targ.items & IT_INVISIBILITY)
85 return FALSE; // enemy is invisible
87 if(substring(targ.classname, 0, 10) == "onslaught_")
88 return FALSE; // don't attack onslaught targets
90 if(IS_SPEC(targ) || IS_OBSERVER(targ))
91 return FALSE; // enemy is a spectator
93 if not(targ.vehicle_flags & VHF_ISVEHICLE)
94 if(targ.deadflag != DEAD_NO || ent.deadflag != DEAD_NO || targ.health <= 0 || ent.health <= 0)
95 return FALSE; // enemy/self is dead
97 if(ent.monster_owner == targ)
98 return FALSE; // don't attack our master
100 if(targ.monster_owner == ent)
101 return FALSE; // don't attack our pet
103 if not(targ.vehicle_flags & VHF_ISVEHICLE)
104 if(targ.flags & FL_NOTARGET)
105 return FALSE; // enemy can't be targeted
107 if not(autocvar_g_monsters_typefrag)
109 return FALSE; // no typefragging!
111 if not(IsDifferentTeam(targ, ent))
112 return FALSE; // enemy is on our team
114 if(autocvar_g_monsters_target_infront || ent.spawnflags & MONSTERFLAG_INFRONT)
115 if(ent.enemy != targ)
119 makevectors (ent.angles);
120 dot = normalize (targ.origin - ent.origin) * v_forward;
129 entity FindTarget (entity ent)
131 if(MUTATOR_CALLHOOK(MonsterFindTarget)) { return ent.enemy; } // Handled by a mutator
133 entity head, closest_target = world;
134 head = findradius(ent.origin, ent.target_range);
136 while(head) // find the closest acceptable target to pass to
138 if(head.monster_attack)
139 if(monster_isvalidtarget(head, ent))
141 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
142 vector head_center = CENTER_OR_VIEWOFS(head);
143 vector ent_center = CENTER_OR_VIEWOFS(ent);
145 //if(ctf_CheckPassDirection(head_center, ent_center, ent.v_angle, head.WarpZone_findradius_nearest))
148 vector closest_target_center = CENTER_OR_VIEWOFS(closest_target);
149 if(vlen(ent_center - head_center) < vlen(ent_center - closest_target_center))
150 { closest_target = head; }
152 else { closest_target = head; }
158 return closest_target;
166 if(self.enemy != other)
167 if not(other.flags & FL_MONSTER)
168 if(monster_isvalidtarget(other, self))
172 string get_monster_model_datafilename(string m, float sk, string fil)
177 m = "models/monsters/*_";
179 m = strcat(m, ftos(sk));
182 return strcat(m, ".", fil);
185 void PrecacheMonsterSounds(string f)
189 fh = fopen(f, FILE_READ);
192 while((s = fgets(fh)))
194 if(tokenize_console(s) != 3)
196 dprint("Invalid sound info line: ", s, "\n");
199 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
204 void precache_monstersounds()
206 string m = (get_monsterinfo(self.monsterid)).model;
207 float globhandle, n, i;
210 globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
213 n = search_getsize(globhandle);
214 for (i = 0; i < n; ++i)
216 //print(search_getfilename(globhandle, i), "\n");
217 f = search_getfilename(globhandle, i);
218 PrecacheMonsterSounds(f);
220 search_end(globhandle);
223 void ClearMonsterSounds()
225 #define _MSOUND(m) if(self.monstersound_##m) { strunzone(self.monstersound_##m); self.monstersound_##m = string_null; }
230 .string GetMonsterSoundSampleField(string type)
232 GetMonsterSoundSampleField_notFound = 0;
235 #define _MSOUND(m) case #m: return monstersound_##m;
239 GetMonsterSoundSampleField_notFound = 1;
243 float LoadMonsterSounds(string f, float first)
248 fh = fopen(f, FILE_READ);
251 dprint("Monster sound file not found: ", f, "\n");
254 while((s = fgets(fh)))
256 if(tokenize_console(s) != 3)
258 field = GetMonsterSoundSampleField(argv(0));
259 if(GetMonsterSoundSampleField_notFound)
262 strunzone(self.field);
263 self.field = strzone(strcat(argv(1), " ", argv(2)));
269 .float skin_for_monstersound;
270 void UpdateMonsterSounds()
272 entity mon = get_monsterinfo(self.monsterid);
274 if(self.skin == self.skin_for_monstersound)
276 self.skin_for_monstersound = self.skin;
277 ClearMonsterSounds();
278 //LoadMonsterSounds("sound/monsters/default.sounds", 1);
279 if(!autocvar_g_debug_defaultsounds)
280 if(!LoadMonsterSounds(get_monster_model_datafilename(mon.model, self.skin, "sounds"), 0))
281 LoadMonsterSounds(get_monster_model_datafilename(mon.model, 0, "sounds"), 0);
284 void MonsterSound(.string samplefield, float sound_delay, float delaytoo, float chan)
286 if(delaytoo && time < self.msound_delay)
288 GlobalSound(self.samplefield, chan, VOICETYPE_PLAYERSOUND);
290 self.msound_delay = time + sound_delay;
293 void monster_makevectors(entity e)
297 v = CENTER_OR_VIEWOFS(e);
298 self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
299 self.v_angle_x = -self.v_angle_x;
301 makevectors(self.v_angle);
304 float monster_melee(entity targ, float damg, float anim, float er, float anim_finished, float deathtype, float dostop)
306 float rdmg = damg * random();
308 if (self.health <= 0)
309 return FALSE; // attacking while dead?!
315 self.state = MONSTER_STATE_ATTACK_MELEE;
316 self.SendFlags |= MSF_MOVE;
319 monsters_setframe(anim);
321 if(anim_finished != 0)
322 self.attack_finished_single = time + anim_finished;
324 monster_makevectors(targ);
326 traceline(self.origin + self.view_ofs, self.origin + v_forward * er, 0, self);
328 if(trace_ent.takedamage)
329 Damage(trace_ent, self, self, rdmg * monster_skill, deathtype, trace_ent.origin, normalize(trace_ent.origin - self.origin));
334 void Monster_CheckMinibossFlag ()
336 if(MUTATOR_CALLHOOK(MonsterCheckBossFlag))
339 float chance = random() * 100;
341 // g_monsters_miniboss_chance cvar or spawnflags 64 causes a monster to be a miniboss
342 if ((self.spawnflags & MONSTERFLAG_MINIBOSS) || (chance < autocvar_g_monsters_miniboss_chance))
344 self.health += autocvar_g_monsters_miniboss_healthboost;
346 self.weapon = WEP_NEX;
350 float Monster_CanRespawn(entity ent)
353 if(MUTATOR_CALLHOOK(MonsterRespawn))
354 return TRUE; // enabled by a mutator
356 if(ent.spawnflags & MONSTERFLAG_NORESPAWN)
359 if not(autocvar_g_monsters_respawn)
367 if(Monster_CanRespawn(self))
369 self.monster_respawned = TRUE;
370 self.think = self.monster_spawnfunc;
371 self.nextthink = time + self.respawntime;
372 self.deadflag = DEAD_RESPAWNING;
373 if(self.spawnflags & MONSTER_RESPAWN_DEATHPOINT)
375 self.pos1 = self.origin;
376 self.pos2 = self.angles;
378 self.event_damage = func_null;
379 self.takedamage = DAMAGE_NO;
380 setorigin(self, self.pos1);
381 self.angles = self.pos2;
382 self.health = self.max_health;
384 self.SendFlags |= MSF_MOVE;
385 self.SendFlags |= MSF_STATUS;
388 SUB_SetFade(self, time + 3, 1);
391 float Monster_CanJump (vector vel)
394 return FALSE; // already attacking
395 if not(self.flags & FL_ONGROUND)
396 return FALSE; // not on the ground
398 return FALSE; // called when dead?
399 if(time < self.attack_finished_single)
400 return FALSE; // still attacking
402 vector old = self.velocity;
405 tracetoss(self, self);
407 if (trace_ent != self.enemy)
413 float monster_leap (float anm, void() touchfunc, vector vel, float anim_finished)
415 if(!Monster_CanJump(vel))
418 monsters_setframe(anm);
419 self.state = MONSTER_STATE_ATTACK_LEAP;
420 self.touch = touchfunc;
423 self.flags &= ~FL_ONGROUND;
425 self.attack_finished_single = time + anim_finished;
430 void monster_checkattack(entity e, entity targ)
437 if not(e.monster_attackfunc)
440 if(time < e.attack_finished_single)
443 if(vlen(targ.origin - e.origin) <= e.attack_range)
444 if(e.monster_attackfunc(MONSTER_ATTACK_MELEE))
446 //monster_sound(e.msound_attack_melee, 0, FALSE);
447 MonsterSound(monstersound_melee, 0, FALSE, CH_VOICE);
451 if(vlen(targ.origin - e.origin) > e.attack_range)
452 if(e.monster_attackfunc(MONSTER_ATTACK_RANGED))
454 //monster_sound(e.msound_attack_ranged, 0, FALSE);
455 MonsterSound(monstersound_ranged, 0, FALSE, CH_VOICE);
464 if(monster_isvalidtarget(activator, self))
465 self.enemy = activator;
469 .float last_enemycheck; // for checking enemy
470 vector monster_pickmovetarget(entity targ)
472 // enemy is always preferred target
475 makevectors(self.angles);
476 self.monster_movestate = MONSTER_MOVE_ENEMY;
477 self.last_trace = time + 1.2;
478 return self.enemy.origin;
481 switch(self.monster_moveflags)
483 case MONSTER_MOVE_OWNER:
485 self.monster_movestate = MONSTER_MOVE_OWNER;
486 self.last_trace = time + 0.3;
487 return (self.monster_owner) ? self.monster_owner.origin : self.origin;
489 case MONSTER_MOVE_SPAWNLOC:
491 self.monster_movestate = MONSTER_MOVE_SPAWNLOC;
492 self.last_trace = time + 2;
495 case MONSTER_MOVE_NOMOVE:
497 self.monster_movestate = MONSTER_MOVE_NOMOVE;
498 self.last_trace = time + 2;
502 case MONSTER_MOVE_WANDER:
505 self.monster_movestate = MONSTER_MOVE_WANDER;
506 self.last_trace = time + 2;
508 self.angles_y = rint(random() * 500);
509 makevectors(self.angles);
510 pos = self.origin + v_forward * 600;
512 if(self.flags & FL_FLY || self.flags & FL_SWIM)
513 if(self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
515 pos_z = random() * 200;
522 self.last_trace = time + 0.5;
531 void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_run, float manim_walk, float manim_idle)
533 fixedmakevectors(self.angles);
536 self.goalentity = find(world, targetname, self.target2);
542 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
543 self.health = max(1, self.max_health * self.revive_progress);
545 self.SendFlags |= MSF_STATUS;
547 movelib_beak_simple(stopspeed);
549 self.velocity = '0 0 0';
551 self.nextthink = time + 0.1;
553 if(self.revive_progress >= 1)
554 Unfreeze(self); // wait for next think before attacking
556 // don't bother updating angles here?
557 if(self.origin != self.oldorigin)
559 self.oldorigin = self.origin;
560 self.SendFlags |= MSF_MOVE;
563 return; // no moving while frozen
566 if(self.flags & FL_SWIM)
568 if(self.waterlevel < WATERLEVEL_WETFEET)
570 if(time >= self.last_trace)
572 self.fish_wasdrowning = TRUE;
573 self.last_trace = time + 0.4;
575 Damage (self, world, world, 2, DEATH_DROWN, self.origin, '0 0 0');
576 self.angles = '90 90 0';
579 self.velocity_y += random() * 50;
580 self.velocity_x -= random() * 50;
584 self.velocity_y -= random() * 50;
585 self.velocity_x += random() * 50;
587 self.velocity_z += random() * 150;
591 self.movetype = MOVETYPE_BOUNCE;
592 //self.velocity_z = -200;
594 self.SendFlags |= MSF_MOVE | MSF_ANG;
598 else if(self.fish_wasdrowning)
600 self.fish_wasdrowning = FALSE;
602 self.movetype = MOVETYPE_WALK;
606 targ = self.goalentity;
608 monster_target = targ;
609 monster_speed_run = runspeed;
610 monster_speed_walk = walkspeed;
612 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)
614 runspeed = walkspeed = 0;
615 if(time >= self.spawn_time)
616 monsters_setframe(manim_idle);
617 movelib_beak_simple(stopspeed);
618 if(self.oldorigin != self.origin)
620 self.oldorigin = self.origin;
621 self.SendFlags |= MSF_MOVE;
626 targ = monster_target;
627 runspeed = monster_speed_run;
628 walkspeed = monster_speed_walk;
631 if(autocvar_g_monsters_teams)
632 if(IsDifferentTeam(self.monster_owner, self))
633 self.monster_owner = world;
635 if(self.enemy && self.enemy.health < 1)
636 self.enemy = world; // enough!
638 if(time >= self.last_enemycheck)
640 if not(monster_isvalidtarget(self.enemy, self))
645 self.enemy = FindTarget(self);
647 MonsterSound(monstersound_sight, 0, FALSE, CH_VOICE);
648 //monster_sound(self.msound_sight, 0, FALSE);
651 self.last_enemycheck = time + 0.5;
654 if(self.state == MONSTER_STATE_ATTACK_MELEE && time >= self.attack_finished_single)
657 if(self.state != MONSTER_STATE_ATTACK_MELEE) // don't move if set
658 if(time >= self.last_trace || self.enemy) // update enemy instantly
659 self.moveto = monster_pickmovetarget(targ);
662 MonsterSound(monstersound_idle, 5, TRUE, CH_VOICE);
663 //monster_sound(self.msound_idle, 5, TRUE);
665 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
666 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
668 if(self.state == MONSTER_STATE_ATTACK_LEAP && (self.flags & FL_ONGROUND))
671 self.touch = MonsterTouch;
674 //self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
677 vector real_angle = vectoangles(self.steerto) - self.angles;
679 if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
682 if(self.flags & FL_SWIM)
683 turny = vlen(self.angles - self.moveto);
687 turny = bound(turny * -1, shortangle_f(real_angle_y, self.angles_y), turny);
688 self.angles_y += turny;
691 if(self.state == MONSTER_STATE_ATTACK_MELEE)
692 self.moveto = self.origin;
694 if(self.enemy && self.enemy.vehicle)
697 if(((self.flags & FL_FLY) || (self.flags & FL_SWIM)) && self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
698 v_forward = normalize(self.moveto - self.origin);
700 self.moveto_z = self.origin_z;
702 if(vlen(self.origin - self.moveto) > 64)
704 if(self.flags & FL_FLY || self.flags & FL_SWIM)
705 movelib_move_simple(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
707 movelib_move_simple_gravity(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
709 if(time > self.pain_finished)
710 if(time > self.attack_finished_single)
711 if(vlen(self.velocity) > 10)
712 monsters_setframe((self.enemy) ? manim_run : manim_walk);
714 monsters_setframe(manim_idle);
718 entity e = find(world, targetname, self.target2);
720 self.target2 = e.target2;
722 self.target2 = e.target;
724 movelib_beak_simple(stopspeed);
725 if(time > self.attack_finished_single)
726 if(time > self.pain_finished)
727 if (vlen(self.velocity) <= 30)
728 monsters_setframe(manim_idle);
731 monster_checkattack(self, self.enemy);
733 if(self.angles != self.oldangles)
735 self.oldangles = self.angles;
736 self.SendFlags |= MSF_ANG;
739 if(self.origin != self.oldorigin)
741 self.oldorigin = self.origin;
742 self.SendFlags |= MSF_MOVE;
746 void monster_dead_think()
748 self.think = monster_dead_think;
749 self.nextthink = time + self.ticrate;
751 self.deadflag = DEAD_DEAD;
754 if(time >= self.ltime)
760 if(self.oldorigin != self.origin)
762 self.oldorigin = self.origin;
763 self.SendFlags |= MSF_MOVE;
767 void monsters_setstatus()
769 self.stat_monsters_total = monsters_total;
770 self.stat_monsters_killed = monsters_killed;
773 void Monster_Appear()
775 self.enemy = activator;
776 self.spawnflags &= ~MONSTERFLAG_APPEAR;
777 self.monster_spawnfunc();
780 float Monster_CheckAppearFlags(entity ent)
782 if not(ent.spawnflags & MONSTERFLAG_APPEAR)
785 ent.think = func_null;
787 ent.use = Monster_Appear;
788 ent.flags = FL_MONSTER; // set so this monster can get butchered
793 void monsters_reset()
795 setorigin(self, self.pos1);
796 self.angles = self.pos2;
798 self.health = self.max_health;
799 self.velocity = '0 0 0';
801 self.goalentity = world;
802 self.attack_finished_single = 0;
803 self.moveto = self.origin;
805 self.SendFlags |= MSF_STATUS;
808 float monster_send(entity to, float sf)
810 WriteByte(MSG_ENTITY, ENT_CLIENT_MONSTER);
811 WriteByte(MSG_ENTITY, sf);
814 WriteByte(MSG_ENTITY, self.monsterid);
816 WriteCoord(MSG_ENTITY, self.origin_x);
817 WriteCoord(MSG_ENTITY, self.origin_y);
818 WriteCoord(MSG_ENTITY, self.origin_z);
820 WriteAngle(MSG_ENTITY, self.angles_x);
821 WriteAngle(MSG_ENTITY, self.angles_y);
823 WriteByte(MSG_ENTITY, self.skin);
824 WriteByte(MSG_ENTITY, self.team);
829 WriteShort(MSG_ENTITY, rint(self.angles_x));
830 WriteShort(MSG_ENTITY, rint(self.angles_y));
835 WriteShort(MSG_ENTITY, rint(self.origin_x));
836 WriteShort(MSG_ENTITY, rint(self.origin_y));
837 WriteShort(MSG_ENTITY, rint(self.origin_z));
839 WriteShort(MSG_ENTITY, rint(self.velocity_x));
840 WriteShort(MSG_ENTITY, rint(self.velocity_y));
841 WriteShort(MSG_ENTITY, rint(self.velocity_z));
843 WriteShort(MSG_ENTITY, rint(self.angles_y));
848 WriteCoord(MSG_ENTITY, self.anim_start_time);
849 WriteByte(MSG_ENTITY, self.frame);
854 WriteByte(MSG_ENTITY, self.skin);
856 WriteByte(MSG_ENTITY, self.team);
858 WriteByte(MSG_ENTITY, self.deadflag);
861 WriteByte(MSG_ENTITY, 0);
863 WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
869 void monster_link(void() spawnproc)
871 Net_LinkEntity(self, TRUE, 0, monster_send);
872 self.think = spawnproc;
873 self.nextthink = time;
876 void monsters_corpse_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
878 self.health -= damage;
880 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
882 if(self.health <= -100) // 100 health until gone?
884 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
886 self.think = SUB_Remove;
887 self.nextthink = time + 0.1;
893 self.think = monster_dead_think;
894 self.nextthink = self.ticrate;
895 self.ltime = time + 5;
899 MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
900 //monster_sound(self.msound_death, 0, FALSE);
902 if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
903 monsters_killed += 1;
905 if(self.candrop && self.weapon)
906 W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325');
908 if(IS_CLIENT(self.realowner))
909 self.realowner.monstercount -= 1;
911 self.event_damage = monsters_corpse_damage;
912 self.solid = SOLID_CORPSE;
913 self.takedamage = DAMAGE_AIM;
915 self.movetype = MOVETYPE_TOSS;
916 self.moveto = self.origin;
917 self.touch = MonsterTouch; // reset incase monster was pouncing
918 self.reset = func_null;
920 if not(self.flags & FL_FLY)
921 self.velocity = '0 0 0';
923 self.SendFlags |= MSF_MOVE;
925 // number of monsters spawned with mobspawn command
928 MON_ACTION(self.monsterid, MR_DEATH);
931 void monsters_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
933 if(self.frozen && deathtype != DEATH_KILL)
936 if(time < self.pain_finished && deathtype != DEATH_KILL)
939 if(time < self.spawnshieldtime)
945 v = healtharmor_applydamage(self.armorvalue, self.m_armor_blockpercent, damage);
951 self.dmg_time = time;
953 if(sound_allowed(MSG_BROADCAST, attacker) && deathtype != DEATH_DROWN)
954 spamsound (self, CH_PAIN, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
956 self.velocity += force * self.damageforcescale;
958 if(deathtype != DEATH_DROWN)
960 Violence_GibSplash_At(hitloc, force, 2, bound(0, take, 200) / 16, self, attacker);
962 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
964 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
969 if(deathtype == DEATH_KILL)
970 self.candrop = FALSE; // killed by mobkill command
973 activator = attacker;
976 self.target2 = self.oldtarget2; // reset to original target on death, incase we respawn
980 frag_attacker = attacker;
982 MUTATOR_CALLHOOK(MonsterDies);
984 if(self.health <= -100) // check if we're already gibbed
986 Violence_GibSplash(self, 1, 0.5, attacker);
988 self.think = SUB_Remove;
989 self.nextthink = time + 0.1;
993 self.SendFlags |= MSF_STATUS;
998 self.think = monster_think;
999 self.nextthink = self.ticrate;
1001 MON_ACTION(self.monsterid, MR_THINK);
1004 void monster_spawn()
1006 MON_ACTION(self.monsterid, MR_SETUP);
1008 if not(self.monster_respawned)
1009 Monster_CheckMinibossFlag();
1011 self.max_health = self.health;
1012 self.pain_finished = self.nextthink;
1013 self.anim_start_time = time;
1015 if not(self.noalign)
1017 setorigin(self, self.origin + '0 0 20');
1018 tracebox(self.origin + '0 0 100', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1019 setorigin(self, trace_endpos);
1022 if not(self.monster_respawned)
1024 self.skin = rint(random() * 4);
1026 if not(self.attack_range)
1027 self.attack_range = autocvar_g_monsters_attack_range;
1029 self.pos1 = self.origin;
1031 //monster_setupsounds(self.netname);
1032 precache_monstersounds();
1033 UpdateMonsterSounds();
1034 //monster_precachesounds(self);
1037 self.monster_attack = TRUE; // we can have monster enemies in team games
1039 //monster_sound(self.msound_spawn, 0, FALSE);
1040 MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
1042 self.think = monster_think;
1043 self.nextthink = time + self.ticrate;
1045 self.SendFlags |= MSF_SETUP;
1047 MUTATOR_CALLHOOK(MonsterSpawn);
1050 float monster_initialize(float mon_id, float nodrop)
1052 if not(autocvar_g_monsters)
1055 entity mon = get_monsterinfo(mon_id);
1057 // support for quake style removing monsters based on skill
1058 switch(monster_skill)
1061 case 1: if(self.spawnflags & MONSTERSKILL_NOTEASY) return FALSE; break;
1062 case 2: if(self.spawnflags & MONSTERSKILL_NOTMEDIUM) return FALSE; break;
1064 case 3: if(self.spawnflags & MONSTERSKILL_NOTHARD) return FALSE; break;
1067 if(self.team && !teamplay)
1070 if not(self.spawnflags & MONSTERFLAG_SPAWNED) // naturally spawned monster
1071 if not(self.monster_respawned)
1072 monsters_total += 1;
1074 setsize(self, mon.mins, mon.maxs);
1075 self.flags = FL_MONSTER;
1076 self.takedamage = DAMAGE_AIM;
1077 self.bot_attack = TRUE;
1078 self.iscreature = TRUE;
1079 self.teleportable = TRUE;
1080 self.damagedbycontents = TRUE;
1081 self.monsterid = mon_id;
1082 self.damageforcescale = 0;
1083 self.event_damage = monsters_damage;
1084 self.touch = MonsterTouch;
1085 self.use = monster_use;
1086 self.solid = SOLID_BBOX;
1087 self.movetype = MOVETYPE_WALK;
1088 self.spawnshieldtime = time + autocvar_g_monsters_spawnshieldtime;
1090 self.velocity = '0 0 0';
1091 self.moveto = self.origin;
1092 self.pos2 = self.angles;
1093 self.reset = monsters_reset;
1094 self.netname = mon.netname;
1095 self.monster_name = M_NAME(mon_id);
1096 self.candrop = TRUE;
1097 self.view_ofs = '0 0 1' * (self.maxs_z * 0.5);
1098 self.oldtarget2 = self.target2;
1099 self.deadflag = DEAD_NO;
1101 self.noalign = nodrop;
1102 self.spawn_time = time;
1104 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
1106 if(mon.spawnflags & MONSTER_TYPE_SWIM)
1107 self.flags |= FL_SWIM;
1109 if(mon.spawnflags & MONSTER_TYPE_FLY)
1111 self.flags |= FL_FLY;
1112 self.movetype = MOVETYPE_FLY;
1115 if(mon.spawnflags & MONSTER_SIZE_BROKEN)
1118 if not(self.ticrate)
1119 self.ticrate = autocvar_g_monsters_think_delay;
1121 self.ticrate = bound(sys_frametime, self.ticrate, 60);
1123 if not(self.m_armor_blockpercent)
1124 self.m_armor_blockpercent = 0.5;
1126 if not(self.target_range)
1127 self.target_range = autocvar_g_monsters_target_range;
1129 if not(self.respawntime)
1130 self.respawntime = autocvar_g_monsters_respawn_delay;
1132 if not(self.monster_moveflags)
1133 self.monster_moveflags = MONSTER_MOVE_WANDER;
1135 monster_link(monster_spawn);