make far mobs less likely to move, and thus send less data

This commit is contained in:
darkrose 2015-08-15 18:29:21 +10:00
parent 1955f8d4e4
commit 148413d311
1 changed files with 77 additions and 55 deletions

View File

@ -510,6 +510,7 @@ void MobSAO::step(float dtime, bool send_recommended)
v3f disturbing_player_norm = v3f(0,1,0);
float disturbing_player_distance = 1000000;
float disturbing_player_dir = 0;
bool dont_move = false;
m_age += dtime;
m_last_sound += dtime;
@ -520,6 +521,25 @@ void MobSAO::step(float dtime, bool send_recommended)
return;
}
/* don't do anything if there's no nearby player */
if (m_disturbing_player == "") {
float distance = 40*BS;
core::list<Player*> players = m_env->getPlayers(true);
for (core::list<Player*>::Iterator i = players.begin(); i != players.end(); i++) {
Player *player = *i;
v3f playerpos = player->getPosition();
f32 dist = m_base_position.getDistanceFrom(playerpos);
if (dist < distance)
distance = dist;
if (distance < 32*BS)
break;
}
if (distance > 32*BS)
return;
if (distance > 16*BS && myrand_range(0,4) != 0)
dont_move = true;
}
/* if it isn't a swimmer, kill it in liquid */
if (m.motion_type != MMT_SWIM) {
v3s16 p = floatToInt(m_base_position,BS);
@ -691,6 +711,7 @@ void MobSAO::step(float dtime, bool send_recommended)
m_removed = true;
}
if (!dont_move) {
MobMotion mot = getMotion();
if (mot != MM_CONSTANT && mot != MM_STATIC) {
@ -758,6 +779,7 @@ void MobSAO::step(float dtime, bool send_recommended)
}else if (mot == MM_CONSTANT) {
stepMotionConstant(dtime);
}
}
if (send_recommended == false)
return;