Skip to content
Merged
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
20 changes: 12 additions & 8 deletions modules/game_walk/walk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,28 @@ end

--- Generalized floor change check.
local function canChangeFloor(pos, deltaZ)
if deltaZ == 0 then
return false
end
local player = g_game.getLocalPlayer()
if not player then
return false
end

local fromTile = g_map.getTile(player:getPosition())
local toPos = {x = pos.x, y = pos.y, z = pos.z + deltaZ}
local toTile = g_map.getTile(toPos)
if not toTile then
return false
end

if deltaZ > 0 then
-- Going DOWN: just check if destination is walkable (can step down onto it)
return toTile and toTile:isWalkable() and toTile:hasElevation(3)
elseif deltaZ < 0 then
-- Going UP: check if current tile has elevation (stairs to climb) AND destination is walkable
return fromTile and fromTile:hasElevation(3) and toTile and toTile:isWalkable()
-- Going DOWN
return toTile:isWalkable() and (toTile:hasElevation(3) or toTile:hasFloorChange())
end

return false
-- deltaZ < 0
-- Going UP: check if current tile has elevation (stairs to climb) AND destination is walkable
local fromTile = g_map.getTile(player:getPosition())
return fromTile and fromTile:hasElevation(3) and toTile:isWalkable()
end

--- Makes the player walk in the given direction.
Expand Down
1 change: 1 addition & 0 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ enum ThingFlagAttr :uint64_t
ThingFlagAttrDecoKit = static_cast<uint64_t>(1) << 45,
ThingFlagAttrNPC = static_cast<uint64_t>(1) << 46,
ThingFlagAttrAmmo = static_cast<uint64_t>(1) << 47,
ThingFlagAttrFloorChange = static_cast<uint64_t>(1) << 48,
};

enum STACK_PRIORITY : uint8_t
Expand Down
2 changes: 2 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<ThingType>("isTranslucent", &ThingType::isTranslucent);
g_lua.bindClassMemberFunction<ThingType>("hasDisplacement", &ThingType::hasDisplacement);
g_lua.bindClassMemberFunction<ThingType>("hasElevation", &ThingType::hasElevation);
g_lua.bindClassMemberFunction<ThingType>("hasFloorChange", &ThingType::hasFloorChange);
g_lua.bindClassMemberFunction<ThingType>("isLyingCorpse", &ThingType::isLyingCorpse);
g_lua.bindClassMemberFunction<ThingType>("isAnimateAlways", &ThingType::isAnimateAlways);
g_lua.bindClassMemberFunction<ThingType>("hasMiniMapColor", &ThingType::hasMiniMapColor);
Expand Down Expand Up @@ -926,6 +927,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("getGround", &Tile::getGround);
g_lua.bindClassMemberFunction<Tile>("isWalkable", &Tile::isWalkable);
g_lua.bindClassMemberFunction<Tile>("hasElevation", &Tile::hasElevation);
g_lua.bindClassMemberFunction<Tile>("hasFloorChange", &Tile::hasFloorChange);

g_lua.bindClassMemberFunction<Tile>("isCovered", &Tile::isCovered);
g_lua.bindClassMemberFunction<Tile>("isCompletelyCovered", &Tile::isCompletelyCovered);
Expand Down
9 changes: 8 additions & 1 deletion src/client/thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@ bool Thing::hasElevation() const {
return t->hasElevation();
return false;
}
bool Thing::hasFloorChange() const
{
if (const auto t = getThingType(); t)
return t->hasFloorChange();
return false;
}

bool Thing::hasAction() const {
if (const auto t = getThingType(); t)
return t->hasAction();
Expand Down Expand Up @@ -571,4 +578,4 @@ const Color& Thing::getHighlightColor() {

m_highlightColor.setAlpha(0.1f + std::abs(500 - g_clock.millis() % 1000) / 1000.0f);
return m_highlightColor;
}
}
3 changes: 2 additions & 1 deletion src/client/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class Thing : public AttachableObject
bool hasLensHelp() const;
bool hasDisplacement() const;
bool hasElevation() const;
bool hasFloorChange() const;
bool hasAction() const;
bool hasWearOut() const;
bool hasClockExpire() const;
Expand Down Expand Up @@ -242,4 +243,4 @@ class Thing : public AttachableObject
friend class Client;
friend class Tile;
};
#pragma pack(pop)
#pragma pack(pop)
7 changes: 6 additions & 1 deletion src/client/thingtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ void ThingType::unserializeAppearance(const uint16_t clientId, const ThingCatego

void ThingType::applyAppearanceFlags(const appearances::AppearanceFlags& flags)
{
if (flags.floorchange()) {
m_flags |= ThingFlagAttrFloorChange;
}

if (flags.has_bank()) {
m_groundSpeed = flags.bank().waypoints();
m_flags |= ThingFlagAttrGround;
Expand Down Expand Up @@ -946,6 +950,7 @@ ThingFlagAttr ThingType::thingAttrToThingFlagAttr(const ThingAttr attr) {
case ThingAttrDisplacement: return ThingFlagAttrDisplacement;
case ThingAttrLight: return ThingFlagAttrLight;
case ThingAttrElevation: return ThingFlagAttrElevation;
case ThingAttrFloorChange: return ThingFlagAttrFloorChange;
case ThingAttrGround: return ThingFlagAttrGround;
case ThingAttrWritable: return ThingFlagAttrWritable;
case ThingAttrWritableOnce: return ThingFlagAttrWritableOnce;
Expand Down Expand Up @@ -1139,4 +1144,4 @@ void ThingType::exportImage(const std::string& fileName)

image->savePNG(fileName);
}
#endif
#endif
1 change: 1 addition & 0 deletions src/client/thingtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class ThingType final : public LuaObject
bool isTranslucent() { return (m_flags & ThingFlagAttrTranslucent); }
bool hasDisplacement() { return (m_flags & ThingFlagAttrDisplacement); }
bool hasElevation() { return (m_flags & ThingFlagAttrElevation); }
bool hasFloorChange() const { return (m_flags & ThingFlagAttrFloorChange); }
bool isLyingCorpse() { return (m_flags & ThingFlagAttrLyingCorpse); }
bool isAnimateAlways() { return (m_flags & ThingFlagAttrAnimateAlways); }
bool hasMiniMapColor() { return (m_flags & ThingFlagAttrMinimapColor); }
Expand Down
10 changes: 9 additions & 1 deletion src/client/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ ThingPtr Tile::getTopThing()

bool Tile::hasGround() { return (getGround() && getGround()->isSingleGround()) || m_thingTypeFlag & HAS_GROUND_BORDER; };
bool Tile::hasTopGround(const bool ignoreBorder) { return (getGround() && getGround()->isTopGround()) || (!ignoreBorder && m_thingTypeFlag & HAS_TOP_GROUND_BORDER); }
bool Tile::hasFloorChange() const
{
for (const auto& thing : m_things) {
if (thing->hasFloorChange())
return true;
}
return false;
}
ItemPtr Tile::getGround() { const auto& ground = getThing(0); return ground && ground->isGround() ? ground->static_self_cast<Item>() : nullptr; }

std::vector<ItemPtr> Tile::getItems()
Expand Down Expand Up @@ -1109,4 +1117,4 @@ bool Tile::isLoading() const {
}

return false;
}
}
1 change: 1 addition & 0 deletions src/client/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Tile final : public AttachableObject
}

bool hasElevation(const int elevation = 1) { return m_elevation >= elevation; }
bool hasFloorChange() const;

#ifdef FRAMEWORK_EDITOR
void overwriteMinimapColor(uint8_t color) { m_minimapColor = color; }
Expand Down
1 change: 1 addition & 0 deletions src/protobuf/appearances.proto
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ message AppearanceFlags {
optional bool hook_south = 70;
optional bool hook_east = 71;
optional AppearanceFlagTransparencyLevel transparencylevel = 72;
optional bool floorchange = 73;
}

message AppearanceFlagUpgradeClassification {
Expand Down
Loading