Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add monsters walking back to spawn" #3610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ rateSpawn = 1
-- despawnRange is the amount of floors a monster can be from its spawn position
-- despawnRadius is how many tiles away it can be from its spawn position
-- removeOnDespawn will remove the monster if true or teleport it back to its spawn position if false
-- walkToSpawnRadius is the allowed distance that the monster will stay away from spawn position when left with no targets, 0 to disable
deSpawnRange = 2
deSpawnRadius = 50
removeOnDespawn = true
walkToSpawnRadius = 15

-- Stamina
staminaSystem = true
Expand Down
7 changes: 2 additions & 5 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "configmanager.h"
#include "game.h"
#include "monster.h"
#include "pugicast.h"

#if LUA_VERSION_NUM >= 502
Expand Down Expand Up @@ -259,9 +258,8 @@ bool ConfigManager::load()

integer[MAX_PLAYERS] = getGlobalNumber(L, "maxPlayers");
integer[PZ_LOCKED] = getGlobalNumber(L, "pzLocked", 60000);
integer[DEFAULT_DESPAWNRANGE] = Monster::despawnRange = getGlobalNumber(L, "deSpawnRange", 2);
integer[DEFAULT_DESPAWNRADIUS] = Monster::despawnRadius = getGlobalNumber(L, "deSpawnRadius", 50);
integer[DEFAULT_WALKTOSPAWNRADIUS] = getGlobalNumber(L, "walkToSpawnRadius", 15);
integer[DEFAULT_DESPAWNRANGE] = getGlobalNumber(L, "deSpawnRange", 2);
integer[DEFAULT_DESPAWNRADIUS] = getGlobalNumber(L, "deSpawnRadius", 50);
integer[RATE_EXPERIENCE] = getGlobalNumber(L, "rateExp", 5);
integer[RATE_SKILL] = getGlobalNumber(L, "rateSkill", 3);
integer[RATE_LOOT] = getGlobalNumber(L, "rateLoot", 2);
Expand Down Expand Up @@ -301,7 +299,6 @@ bool ConfigManager::load()

loaded = true;
lua_close(L);

return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class ConfigManager
PZ_LOCKED,
DEFAULT_DESPAWNRANGE,
DEFAULT_DESPAWNRADIUS,
DEFAULT_WALKTOSPAWNRADIUS,
RATE_EXPERIENCE,
RATE_SKILL,
RATE_LOOT,
Expand Down
2 changes: 2 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ void Game::saveGameState()

bool Game::loadMainMap(const std::string& filename)
{
Monster::despawnRange = g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRANGE);
Monster::despawnRadius = g_config.getNumber(ConfigManager::DEFAULT_DESPAWNRADIUS);
return map.loadMap("data/world/" + filename + ".otbm", true);
}

Expand Down
1 change: 0 additions & 1 deletion src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::PZ_LOCKED)
registerEnumIn("configKeys", ConfigManager::DEFAULT_DESPAWNRANGE)
registerEnumIn("configKeys", ConfigManager::DEFAULT_DESPAWNRADIUS)
registerEnumIn("configKeys", ConfigManager::DEFAULT_WALKTOSPAWNRADIUS)
registerEnumIn("configKeys", ConfigManager::REMOVE_ON_DESPAWN)
registerEnumIn("configKeys", ConfigManager::RATE_EXPERIENCE)
registerEnumIn("configKeys", ConfigManager::RATE_SKILL)
Expand Down
22 changes: 5 additions & 17 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,6 @@ void Monster::onCreatureLeave(Creature* creature)
if (isOpponent(creature)) {
removeTarget(creature);
if (targetList.empty()) {
int32_t walkToSpawnRadius = g_config.getNumber(ConfigManager::DEFAULT_WALKTOSPAWNRADIUS);
if (walkToSpawnRadius > 0 && !Position::areInRange(position, masterPos, walkToSpawnRadius, walkToSpawnRadius)) {
std::vector<Direction> dirList;
if (getPathTo(masterPos, dirList, 0, 0, true, true)) {
startAutoWalk(dirList);
return;
}
}

updateIdleStatus();
}
}
Expand Down Expand Up @@ -683,10 +674,6 @@ void Monster::updateIdleStatus()
}) == conditions.end();
}

if (idle) {
idle = listWalkDir.empty();
}

setIdle(idle);
}

Expand Down Expand Up @@ -738,13 +725,14 @@ void Monster::onThink(uint32_t interval)
}

if (!isInSpawnRange(position)) {
g_game.addMagicEffect(this->getPosition(), CONST_ME_POFF);
if (g_config.getBoolean(ConfigManager::REMOVE_ON_DESPAWN)) {
g_game.removeCreature(this, false);
} else {
g_game.internalTeleport(this, masterPos);
setIdle(true);
}

g_game.addMagicEffect(this->getPosition(), CONST_ME_POFF);
} else {
updateIdleStatus();

Expand Down Expand Up @@ -1133,20 +1121,20 @@ void Monster::pushCreatures(Tile* tile)

bool Monster::getNextStep(Direction& direction, uint32_t& flags)
{
if (listWalkDir.empty() && (isIdle || getHealth() <= 0)) {
if (isIdle || getHealth() <= 0) {
//we don't have anyone watching, might as well stop walking
eventWalk = 0;
return false;
}

bool result = false;
if (listWalkDir.empty() && (!followCreature || !hasFollowPath) && (!isSummon() || !isMasterInRange)) {
if ((!followCreature || !hasFollowPath) && (!isSummon() || !isMasterInRange)) {
if (getTimeSinceLastMove() >= 1000) {
randomStepping = true;
//choose a random direction
result = getRandomStep(getPosition(), direction);
}
} else if ((isSummon() && isMasterInRange) || followCreature || !listWalkDir.empty()) {
} else if ((isSummon() && isMasterInRange) || followCreature) {
randomStepping = false;
result = Creature::getNextStep(direction, flags);
if (result) {
Expand Down
4 changes: 0 additions & 4 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ struct Position
return Position::getDistanceX(p1, p2) <= deltax && Position::getDistanceY(p1, p2) <= deltay && Position::getDistanceZ(p1, p2) <= deltaz;
}

static bool areInRange(const Position& p1, const Position& p2, int_fast32_t deltax, int_fast32_t deltay) {
return Position::getDistanceX(p1, p2) <= deltax && Position::getDistanceY(p1, p2) <= deltay;
}

static int_fast32_t getOffsetX(const Position& p1, const Position& p2) {
return p1.getX() - p2.getX();
}
Expand Down