Skip to content

Commit

Permalink
feat: GameNegativeOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah authored Mar 22, 2024
1 parent fe6b5e4 commit 08581ab
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions modules/game_features/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ controller:registerEvents(g_game, {
onClientVersionChange = function(version)
-- g_game.enableFeature(GameKeepUnawareTiles)
-- g_game.enableFeature(GameSmoothWalkElevation)
-- g_game.enableFeature(GameNegativeOffset)
g_game.enableFeature(GameFormatCreatureName)

if version >= 750 then
Expand Down
1 change: 1 addition & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ GameWrapKit = 112
GameContainerFilter = 113
GameEnterGameShowAppearance = 114
GameSmoothWalkElevation = 115
GameNegativeOffset = 116

TextColors = {
red = '#f55e5e', -- '#c83200'
Expand Down
3 changes: 2 additions & 1 deletion src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ namespace Otc
GameContainerFilter = 113,
GameEnterGameShowAppearance = 114,
GameSmoothWalkElevation = 115,
LastGameFeature = 116
GameNegativeOffset = 116,
LastGameFeature = 117
};

enum MagicEffectsType_t : uint8_t
Expand Down
12 changes: 9 additions & 3 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, boo
if (isDead() || !canBeSeen() || !(drawFlags & Otc::DrawCreatureInfo) || !mapRect.isInRange(m_position))
return;

const auto displacementX = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : getDisplacementX();
const auto displacementY = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : getDisplacementY();

const auto& parentRect = mapRect.rect;
const auto& creatureOffset = Point(16 - getDisplacementX(), -getDisplacementY() - 2) + getDrawOffset();
const auto& creatureOffset = Point(16 - displacementX, -displacementY - 2) + getDrawOffset();

Point p = dest - mapRect.drawOffset;
p += (creatureOffset - Point(std::round(m_jumpOffset.x), std::round(m_jumpOffset.y))) * mapRect.scaleFactor;
Expand Down Expand Up @@ -565,8 +568,11 @@ void Creature::updateWalkingTile()
// determine new walking tile
TilePtr newWalkingTile;

const Rect virtualCreatureRect(g_gameConfig.getSpriteSize() + (m_walkOffset.x - getDisplacementX()),
g_gameConfig.getSpriteSize() + (m_walkOffset.y - getDisplacementY()),
const auto displacementX = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : getDisplacementX();
const auto displacementY = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : getDisplacementY();

const Rect virtualCreatureRect(g_gameConfig.getSpriteSize() + (m_walkOffset.x - displacementX),
g_gameConfig.getSpriteSize() + (m_walkOffset.y - displacementY),
g_gameConfig.getSpriteSize(), g_gameConfig.getSpriteSize());

for (int xi = -1; xi <= 1 && !newWalkingTile; ++xi) {
Expand Down
6 changes: 5 additions & 1 deletion src/client/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,12 @@ void Map::updateAttachedWidgets(const MapViewPtr& mapView)

if (object->isThing() && object->static_self_cast<Thing>()->isCreature()) {
const auto& creature = object->static_self_cast<Thing>()->static_self_cast<Creature>();

const auto displacementX = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : creature->getDisplacementX();
const auto displacementY = g_game.getFeature(Otc::GameNegativeOffset) ? 0 : creature->getDisplacementY();

const auto& jumpOffset = creature->getJumpOffset() * g_drawPool.getScaleFactor();
const auto& creatureOffset = Point(16 - creature->getDisplacementX(), -creature->getDisplacementY() - 2) + creature->getWalkOffset();
const auto& creatureOffset = Point(16 - displacementX, -displacementY - 2) + creature->getWalkOffset();
p += creatureOffset * g_drawPool.getScaleFactor() - Point(std::round(jumpOffset.x), std::round(jumpOffset.y));
}

Expand Down
11 changes: 8 additions & 3 deletions src/client/thingtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,13 @@ void ThingType::unserialize(uint16_t clientId, ThingCategory category, const Fil
case ThingAttrDisplacement:
{
if (g_game.getClientVersion() >= 755) {
m_displacement.x = fin->getU16();
m_displacement.y = fin->getU16();
if (g_game.getFeature(Otc::GameNegativeOffset)) {
m_displacement.x = fin->get16();
m_displacement.y = fin->get16();
} else {
m_displacement.x = fin->getU16();
m_displacement.y = fin->getU16();
}
} else {
m_displacement.x = 8;
m_displacement.y = 8;
Expand Down Expand Up @@ -1068,4 +1073,4 @@ void ThingType::exportImage(const std::string& fileName)

image->savePNG(fileName);
}
#endif
#endif
2 changes: 2 additions & 0 deletions vc17/otclient.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@
</ClCompile>
<ClCompile Include="..\src\framework\ui\uiqrcode.cpp">
<Filter>Source Files\framework\ui</Filter>
</ClCompile>
<ClCompile Include="..\src\framework\net\httplogin.cpp">
<Filter>Source Files\framework\net</Filter>
</ClCompile>
Expand Down Expand Up @@ -1077,6 +1078,7 @@
</ClInclude>
<ClInclude Include="..\src\framework\ui\uiqrcode.h">
<Filter>Header Files\framework\ui</Filter>
</ClInclude>
<ClInclude Include="..\src\framework\net\httplogin.h">
<Filter>Header Files\framework\net</Filter>
</ClInclude>
Expand Down

0 comments on commit 08581ab

Please sign in to comment.