// =========================
-void monster_item_spawn()
-{
- if(self.monster_loot)
- self.monster_loot();
-
- self.gravity = 1;
- self.reset = SUB_Remove;
- self.noalign = TRUE;
- self.velocity = randomvec() * 175 + '0 0 325';
- self.classname = "droppedweapon"; // hax
- self.item_spawnshieldtime = time + 0.7;
-
- SUB_SetFade(self, time + autocvar_g_monsters_drop_time, 1);
-}
-
void monster_dropitem()
{
if(!self.candrop || !self.monster_loot)
return;
vector org = self.origin + ((self.mins + self.maxs) * 0.5);
- entity e = spawn();
-
- setorigin(e, org);
+ entity e = spawn(), oldself = self;
e.monster_loot = self.monster_loot;
MUTATOR_CALLHOOK(MonsterDropItem);
e = other;
- if(e)
+ if(e && e.monster_loot)
{
- e.think = monster_item_spawn;
- e.nextthink = time + 0.3;
+ self = e;
+ e.noalign = TRUE;
+ e.monster_loot();
+ e.gravity = 1;
+ e.movetype = MOVETYPE_TOSS;
+ e.reset = SUB_Remove;
+ setorigin(e, org);
+ e.velocity = randomvec() * 175 + '0 0 325';
+ e.item_spawnshieldtime = time + 0.7;
+ e.classname = "droppedweapon"; // use weapon handling to remove it on touch
+ SUB_SetFade(e, time + autocvar_g_monsters_drop_time, 1);
+ self = oldself;
}
}
if(targ == ent)
return FALSE; // don't attack ourselves
- traceline(ent.origin, targ.origin, MOVE_NORMAL, ent);
+ //traceline(ent.origin, targ.origin, MOVE_NORMAL, ent);
- if(trace_ent != targ)
- return FALSE;
+ //if(trace_ent != targ)
+ //return FALSE;
if(targ.vehicle_flags & VHF_ISVEHICLE)
if(!((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED))
if(time < game_starttime)
return FALSE; // monsters do nothing before the match has started
- if(vlen(targ.origin - ent.origin) >= ent.target_range)
- return FALSE; // enemy is too far away
-
if(targ.takedamage == DAMAGE_NO)
return FALSE; // enemy can't be damaged
if (targ.freezetag_frozen)
return FALSE; // ignore frozen
- if(autocvar_g_monsters_target_infront || ent.spawnflags & MONSTERFLAG_INFRONT)
+ if(autocvar_g_monsters_target_infront || (ent.spawnflags & MONSTERFLAG_INFRONT))
if(ent.enemy != targ)
{
float dot;
entity head, closest_target = world;
head = findradius(ent.origin, ent.target_range);
+ //head = WarpZone_FindRadius(ent.origin, ent.target_range, TRUE);
while(head) // find the closest acceptable target to pass to
{
{
// if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
vector head_center = CENTER_OR_VIEWOFS(head);
+ //vector head_center = WarpZone_UnTransformOrigin(head, CENTER_OR_VIEWOFS(head));
vector ent_center = CENTER_OR_VIEWOFS(ent);
- //if(ctf_CheckPassDirection(head_center, ent_center, ent.v_angle, head.WarpZone_findradius_nearest))
+ traceline(ent_center, head_center, MOVE_NORMAL, ent);
+
+ if(trace_ent == head)
if(closest_target)
{
vector closest_target_center = CENTER_OR_VIEWOFS(closest_target);
+ //vector closest_target_center = WarpZone_UnTransformOrigin(closest_target, CENTER_OR_VIEWOFS(closest_target));
if(vlen(ent_center - head_center) < vlen(ent_center - closest_target_center))
{ closest_target = head; }
}
void MonsterSound(.string samplefield, float sound_delay, float delaytoo, float chan)
{
- if(delaytoo && time < self.msound_delay)
+ if(delaytoo)
+ if(time < self.msound_delay)
return; // too early
GlobalSound(self.samplefield, chan, VOICETYPE_PLAYERSOUND);
return TRUE;
}
+float Monster_CheckAppearFlags(entity ent, float monster_id);
+float monster_initialize(float mon_id);
+void monster_respawn()
+{
+ // is this function really needed?
+ if(!Monster_CheckAppearFlags(self, self.monsterid))
+ monster_initialize(self.monsterid);
+}
+
void Monster_Fade ()
{
if(Monster_CanRespawn(self))
{
self.spawnflags |= MONSTERFLAG_RESPAWNED;
- self.think = self.monster_spawnfunc;
+ self.think = monster_respawn;
self.nextthink = time + self.respawntime;
- self.ltime = 0;
+ self.monster_lifetime = 0;
self.deadflag = DEAD_RESPAWNING;
if(self.spawnflags & MONSTER_RESPAWN_DEATHPOINT)
{
// enemy is always preferred target
if(self.enemy)
{
- makevectors(self.angles);
+ vector targ_origin = ((self.enemy.absmin + self.enemy.absmax) * 0.5);
+ targ_origin = WarpZone_RefSys_TransformOrigin(self.enemy, self, targ_origin); // origin of target as seen by the monster (us)
+ WarpZone_TraceLine(self.origin, targ_origin, MOVE_NOMONSTERS, self);
+
+ if((self.enemy == world)
+ || (self.enemy.deadflag != DEAD_NO || self.enemy.health < 1)
+ || (self.enemy.freezetag_frozen)
+ || (self.enemy.flags & FL_NOTARGET)
+ || (self.enemy.alpha < 0.5)
+ || (self.enemy.takedamage == DAMAGE_NO)
+ || (vlen(self.origin - targ_origin) > self.target_range)
+ || ((trace_fraction < 1) && (trace_ent != self.enemy)))
+ //|| (time > self.ctf_droptime + autocvar_g_ctf_pass_timelimit)) // TODO: chase timelimit?
+ {
+ self.enemy = world;
+ self.pass_distance = 0;
+ }
+
+ if(self.enemy)
+ {
+ /*WarpZone_TrailParticles(world, particleeffectnum("red_pass"), self.origin, targ_origin);
+ print("Trace origin: ", vtos(targ_origin), "\n");
+ print("Target origin: ", vtos(self.enemy.origin), "\n");
+ print("My origin: ", vtos(self.origin), "\n"); */
+
+ self.monster_movestate = MONSTER_MOVE_ENEMY;
+ self.last_trace = time + 1.2;
+ return targ_origin;
+ }
+
+ /*makevectors(self.angles);
self.monster_movestate = MONSTER_MOVE_ENEMY;
self.last_trace = time + 1.2;
- return self.enemy.origin;
+ return self.enemy.origin; */
}
switch(self.monster_moveflags)
{
vector pos;
self.monster_movestate = MONSTER_MOVE_WANDER;
- self.last_trace = time + 2;
-
- self.angles_y = rint(random() * 500);
- makevectors(self.angles);
- pos = self.origin + v_forward * 600;
-
- if(self.flags & FL_FLY || self.flags & FL_SWIM)
- if(self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
- {
- pos_z = random() * 200;
- if(random() >= 0.5)
- pos_z *= -1;
- }
if(targ)
{
self.last_trace = time + 0.5;
pos = targ.origin;
}
+ else
+ {
+ self.last_trace = time + self.wander_delay;
+
+ self.angles_y = rint(random() * 500);
+ makevectors(self.angles);
+ pos = self.origin + v_forward * self.wander_distance;
+
+ if((self.flags & FL_FLY) || (self.flags & FL_SWIM))
+ if(self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
+ {
+ pos_z = random() * 200;
+ if(random() >= 0.5)
+ pos_z *= -1;
+ }
+ }
return pos;
}
}
}
+void monster_CalculateVelocity(entity mon, vector to, vector from, float turnrate, float movespeed)
+{
+ float current_distance = vlen((('1 0 0' * to_x) + ('0 1 0' * to_y)) - (('1 0 0' * from_x) + ('0 1 0' * from_y))); // for the sake of this check, exclude Z axis
+ float initial_height = 0; //min(50, (targ_distance * tanh(20)));
+ float current_height = (initial_height * min(1, (current_distance / self.pass_distance)));
+ //print("current_height = ", ftos(current_height), ", initial_height = ", ftos(initial_height), ".\n");
+
+ vector targpos;
+ if(current_height) // make sure we can actually do this arcing path
+ {
+ targpos = (to + ('0 0 1' * current_height));
+ WarpZone_TraceLine(mon.origin, targpos, MOVE_NOMONSTERS, mon);
+ if(trace_fraction < 1)
+ {
+ //print("normal arc line failed, trying to find new pos...");
+ WarpZone_TraceLine(to, targpos, MOVE_NOMONSTERS, mon);
+ targpos = (trace_endpos + '0 0 -10');
+ WarpZone_TraceLine(mon.origin, targpos, MOVE_NOMONSTERS, mon);
+ if(trace_fraction < 1) { targpos = to; /* print(" ^1FAILURE^7, reverting to original direction.\n"); */ }
+ /*else { print(" ^3SUCCESS^7, using new arc line.\n"); } */
+ }
+ }
+ else { targpos = to; }
+
+ //mon.angles = normalize(('0 1 0' * to_y) - ('0 1 0' * from_y));
+
+ vector desired_direction = normalize(targpos - from);
+ if(turnrate) { mon.velocity = (normalize(normalize(mon.velocity) + (desired_direction * 50)) * movespeed); }
+ else { mon.velocity = (desired_direction * movespeed); }
+
+ mon.angles = vectoangles(mon.velocity);
+}
+
void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_run, float manim_walk, float manim_idle)
{
fixedmakevectors(self.angles);
monster_speed_run = runspeed;
monster_speed_walk = walkspeed;
- 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)
+ if(MUTATOR_CALLHOOK(MonsterMove) || gameover || self.draggedby != world || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || time < game_starttime || (autocvar_g_campaign && !campaign_bots_may_start) || time < self.spawn_time)
{
runspeed = walkspeed = 0;
if(time >= self.spawn_time)
if(DIFF_TEAM(self.monster_owner, self))
self.monster_owner = world;
- if(self.enemy && self.enemy.health < 1)
- self.enemy = world; // enough!
-
if(time >= self.last_enemycheck)
{
- if(!monster_isvalidtarget(self.enemy, self))
- self.enemy = world;
-
if(!self.enemy)
{
self.enemy = FindTarget(self);
if(self.enemy)
+ {
+ WarpZone_RefSys_Copy(self.enemy, self);
+ WarpZone_RefSys_AddInverse(self.enemy, self); // wz1^-1 ... wzn^-1 receiver
+ self.moveto = WarpZone_RefSys_TransformOrigin(self.enemy, self, (0.5 * (self.enemy.absmin + self.enemy.absmax)));
+
+ self.pass_distance = vlen((('1 0 0' * self.enemy.origin_x) + ('0 1 0' * self.enemy.origin_y)) - (('1 0 0' * self.origin_x) + ('0 1 0' * self.origin_y)));
MonsterSound(monstersound_sight, 0, FALSE, CH_VOICE);
+ }
}
- self.last_enemycheck = time + 0.5;
+ self.last_enemycheck = time + 1; // check for enemies every second
}
if(self.state == MONSTER_STATE_ATTACK_MELEE && time >= self.attack_finished_single)
if(!self.enemy)
MonsterSound(monstersound_idle, 7, TRUE, CH_VOICE);
- if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
- self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
-
if(self.state == MONSTER_STATE_ATTACK_LEAP && (self.flags & FL_ONGROUND))
{
self.state = 0;
self.touch = MonsterTouch;
}
- //self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
-
- float turny = 0;
- vector real_angle = vectoangles(self.steerto) - self.angles;
-
- if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
- turny = 20;
-
- if(self.flags & FL_SWIM)
- turny = vlen(self.angles - self.moveto);
-
- if(turny)
- {
- turny = bound(turny * -1, shortangle_f(real_angle_y, self.angles_y), turny);
- self.angles_y += turny;
- }
-
if(self.state == MONSTER_STATE_ATTACK_MELEE)
self.moveto = self.origin;
if(self.enemy && self.enemy.vehicle)
runspeed = 0;
- if(((self.flags & FL_FLY) || (self.flags & FL_SWIM)) && self.spawnflags & MONSTERFLAG_FLY_VERTICAL)
+ if(((self.flags & FL_FLY) || (self.flags & FL_SWIM)) && (self.spawnflags & MONSTERFLAG_FLY_VERTICAL))
v_forward = normalize(self.moveto - self.origin);
else
self.moveto_z = self.origin_z;
if(vlen(self.origin - self.moveto) > 64)
{
- if(self.flags & FL_FLY || self.flags & FL_SWIM)
+ if((self.flags & FL_ONGROUND) || ((self.flags & FL_FLY) || (self.flags & FL_SWIM)))
+ monster_CalculateVelocity(self, self.moveto, self.origin, TRUE, ((self.enemy) ? runspeed : walkspeed));
+
+ /*&if(self.flags & FL_FLY || self.flags & FL_SWIM)
movelib_move_simple(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
else
- movelib_move_simple_gravity(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6);
+ movelib_move_simple_gravity(v_forward, ((self.enemy) ? runspeed : walkspeed), 0.6); */
if(time > self.pain_finished)
if(time > self.attack_finished_single)
CSQCMODEL_AUTOUPDATE();
- if(self.ltime != 0)
- if(time >= self.ltime)
+ if(self.monster_lifetime != 0)
+ if(time >= self.monster_lifetime)
{
Monster_Fade();
return;
void Monster_Appear()
{
self.enemy = activator;
- self.spawnflags &= ~MONSTERFLAG_APPEAR;
- self.monster_spawnfunc();
+ //self.spawnflags &= ~MONSTERFLAG_APPEAR;
+ monster_initialize(self.monsterid);
}
-float Monster_CheckAppearFlags(entity ent)
+float Monster_CheckAppearFlags(entity ent, float monster_id)
{
if(!(ent.spawnflags & MONSTERFLAG_APPEAR))
return FALSE;
ent.think = func_null;
+ ent.monsterid = monster_id; // set so this monster is properly registered (otherwise, normal initialization is used)
ent.nextthink = 0;
ent.use = Monster_Appear;
ent.flags = FL_MONSTER; // set so this monster can get butchered
self.think = SUB_Remove;
self.nextthink = time + 0.1;
+ self.event_damage = func_null;
}
}
{
self.think = monster_dead_think;
self.nextthink = time;
- self.ltime = time + 5;
+ self.monster_lifetime = time + 5;
monster_dropitem();
if(self.candrop && self.weapon)
W_ThrowNewWeapon(self, self.weapon, 0, self.origin, randomvec() * 150 + '0 0 325');
- self.event_damage = monsters_corpse_damage;
+ self.event_damage = ((gibbed) ? func_null : monsters_corpse_damage);
self.solid = SOLID_CORPSE;
self.takedamage = DAMAGE_AIM;
self.deadflag = DEAD_DEAD;
void monsters_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
{
+ if((self.spawnflags & MONSTERFLAG_INVINCIBLE) && deathtype != DEATH_KILL)
+ return;
+
if(time < self.pain_finished && deathtype != DEATH_KILL)
return;
if(time < self.spawnshieldtime && deathtype != DEATH_KILL)
return;
+ if(deathtype == DEATH_FALL && self.draggedby != world)
+ return;
+
vector v;
float take, save;
self.think = monster_think;
self.nextthink = self.ticrate;
- if(self.ltime)
- if(time >= self.ltime)
+ if(self.monster_lifetime)
+ if(time >= self.monster_lifetime)
{
Damage(self, self, self, self.health + self.max_health, DEATH_KILL, self.origin, self.origin);
return;
if(!self.attack_range)
self.attack_range = autocvar_g_monsters_attack_range;
+ if(!self.wander_delay) { self.wander_delay = 2; }
+ if(!self.wander_distance) { self.wander_distance = 600; }
+
precache_monstersounds();
UpdateMonsterSounds();
MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
WaypointSprite_Spawn(M_NAME(self.monsterid), 0, 1024, self, '0 0 1' * (self.maxs_z + 15), world, self.team, self, sprite, TRUE, RADARICON_DANGER, ((self.team) ? Team_ColorRGB(self.team) : '1 0 0'));
- WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
- WaypointSprite_UpdateHealth(self.sprite, self.health);
+ if(!(self.spawnflags & MONSTERFLAG_INVINCIBLE))
+ {
+ WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
+ WaypointSprite_UpdateHealth(self.sprite, self.health);
+ }
self.think = monster_think;
self.nextthink = time + self.ticrate;
return TRUE;
}
-float monster_initialize(float mon_id, float nodrop)
+float monster_initialize(float mon_id)
{
if(!autocvar_g_monsters)
return FALSE;
self.team = 0;
if(!(self.spawnflags & MONSTERFLAG_SPAWNED)) // naturally spawned monster
- if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+ if(!(self.spawnflags & MONSTERFLAG_RESPAWNED)) // don't count re-spawning monsters either
monsters_total += 1;
setmodel(self, mon.model);
self.candrop = TRUE;
self.view_ofs = '0 0 1' * (self.maxs_z * 0.5);
self.oldtarget2 = self.target2;
+ self.pass_distance = 0;
self.deadflag = DEAD_NO;
self.scale = 1;
- self.noalign = nodrop;
+ self.noalign = (mon.spawnflags & MONSTER_TYPE_FLY);
self.spawn_time = time;
self.spider_slowness = 0;
self.gravity = 1;
self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
+ if(autocvar_g_monsters_edit)
+ self.grab = 1; // owner may carry their monster
+
if(autocvar_g_fullbrightplayers)
self.effects |= EF_FULLBRIGHT;