Check walk collisions in client side

This commit is contained in:
Eduardo Bart 2012-08-01 22:33:56 -03:00
parent 773d58da01
commit daea7cab65
4 changed files with 49 additions and 4 deletions

View File

@ -489,12 +489,44 @@ void Game::walk(Otc::Direction direction)
if(!m_localPlayer->canWalk(direction)) if(!m_localPlayer->canWalk(direction))
return; return;
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
TilePtr toTile = g_map.getTile(toPos);
// only do prewalks to walkable tiles (like grounds and not walls) // only do prewalks to walkable tiles (like grounds and not walls)
TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
if(toTile && toTile->isWalkable()) if(toTile && toTile->isWalkable())
m_localPlayer->preWalk(direction); m_localPlayer->preWalk(direction);
else // check walk to another floor (e.g: when above 3 parcels)
m_localPlayer->lockWalk(100); else {
// check if can walk to a lower floor
auto canChangeFloorDown = [&] {
Position pos = toPos;
if(!pos.down())
return false;
toTile = g_map.getTile(pos);
if(toTile && toTile->hasElevation(3)) {
return true;
}
return false;
};
// check if can walk to a higher floor
auto canChangeFloorUp = [&] {
TilePtr fromTile = m_localPlayer->getTile();
if(!fromTile || !fromTile->hasElevation(3))
return false;
Position pos = toPos;
if(!pos.up())
return false;
toTile = g_map.getTile(pos);
if(!toTile || !toTile->isWalkable())
return false;
return true;
};
if(canChangeFloorDown() || canChangeFloorUp()) {
m_localPlayer->lockWalk();
} else
return;
}
forceWalk(direction); forceWalk(direction);

View File

@ -29,6 +29,7 @@
#include "container.h" #include "container.h"
#include "map.h" #include "map.h"
#include "houses.h" #include "houses.h"
#include "game.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
@ -302,7 +303,9 @@ int Item::getSubType()
{ {
if(isSplash() || isFluidContainer()) if(isSplash() || isFluidContainer())
return m_countOrSubType; return m_countOrSubType;
if(g_game.getClientVersion() >= 900)
return 0; return 0;
return 1;
} }
int Item::getCount() int Item::getCount()

View File

@ -513,3 +513,12 @@ bool Tile::canErase()
{ {
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty(); return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty();
} }
bool Tile::hasElevation(int elevation)
{
int count = 0;
for(const ThingPtr& thing : m_things)
if(thing->getElevation() > 0)
count++;
return count >= elevation;
}

View File

@ -102,6 +102,7 @@ public:
bool hasCreature(); bool hasCreature();
bool limitsFloorsView(); bool limitsFloorsView();
bool canErase(); bool canErase();
bool hasElevation(int elevation = 1);
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; } void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
uint32 getFlags() { return m_flags; } uint32 getFlags() { return m_flags; }