More work towards autowalking (needs more work).

* Added tile minimap color override.
* Changed zoom in and out of minimap from inverted control.
master
BeniS 11 years ago
parent f470cba09e
commit 01e48fbcc8

@ -539,7 +539,7 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
end end
local player = g_game.getLocalPlayer() local player = g_game.getLocalPlayer()
player:stopAutoWalkUpdate() player:stopAutoWalk()
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
if not player:autoWalk(autoWalkPos) then if not player:autoWalk(autoWalkPos) then

@ -398,9 +398,9 @@ function onMinimapMouseWheel(self, mousePos, direction)
local keyboardModifiers = g_keyboard.getModifiers() local keyboardModifiers = g_keyboard.getModifiers()
if direction == MouseWheelUp and keyboardModifiers == KeyboardNoModifier then if direction == MouseWheelUp and keyboardModifiers == KeyboardNoModifier then
miniMapZoomIn()
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardNoModifier then
miniMapZoomOut() miniMapZoomOut()
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardNoModifier then
miniMapZoomIn()
elseif direction == MouseWheelDown and keyboardModifiers == KeyboardCtrlModifier then elseif direction == MouseWheelDown and keyboardModifiers == KeyboardCtrlModifier then
minimapFloorUp(1) minimapFloorUp(1)
elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then

@ -592,7 +592,7 @@ bool Game::walk(Otc::Direction direction)
return false; return false;
} }
m_localPlayer->stopAutoWalkUpdate(); m_localPlayer->stopAutoWalk();
g_lua.callGlobalField("g_game", "onWalk", direction); g_lua.callGlobalField("g_game", "onWalk", direction);
@ -857,7 +857,7 @@ void Game::attack(CreaturePtr creature)
cancelFollow(); cancelFollow();
setAttackingCreature(creature); setAttackingCreature(creature);
m_localPlayer->stopAutoWalkUpdate(); m_localPlayer->stopAutoWalk();
if(m_protocolVersion >= 963) { if(m_protocolVersion >= 963) {
if(creature) if(creature)
@ -881,7 +881,7 @@ void Game::follow(CreaturePtr creature)
cancelAttack(); cancelAttack();
setFollowingCreature(creature); setFollowingCreature(creature);
m_localPlayer->stopAutoWalkUpdate(); m_localPlayer->stopAutoWalk();
if(m_protocolVersion >= 963) { if(m_protocolVersion >= 963) {
if(creature) if(creature)
@ -902,7 +902,7 @@ void Game::cancelAttackAndFollow()
if(isAttacking()) if(isAttacking())
setAttackingCreature(nullptr); setAttackingCreature(nullptr);
m_localPlayer->stopAutoWalkUpdate(); m_localPlayer->stopAutoWalk();
m_protocolGame->sendCancelAttackAndFollow(); m_protocolGame->sendCancelAttackAndFollow();

@ -162,57 +162,38 @@ void LocalPlayer::cancelWalk(Otc::Direction direction)
if(direction != Otc::InvalidDirection) if(direction != Otc::InvalidDirection)
setDirection(direction); setDirection(direction);
updateAutoWalkSteps(true);
callLuaField("onCancelWalk", direction); callLuaField("onCancelWalk", direction);
} }
void LocalPlayer::updateAutoWalkSteps(bool walkFailed)
{
if(!m_lastAutoWalkDestination.isValid()) {
return;
}
m_autoWalkSteps.push_back(m_position);
if(m_lastAutoWalkDestination != m_position && (m_autoWalkSteps.size() >= Otc::MAX_AUTOWALK_STEPS_RETRY || walkFailed)) {
autoWalk(m_lastAutoWalkDestination);
}
else if(m_position == m_lastAutoWalkDestination && !m_autoWalkQueue.empty()) {
m_autoWalkQueue.pop_back();
// task the next destination
if(!m_autoWalkQueue.empty()) {
std::vector<Position> destinations = m_position.translatedToDirections(m_autoWalkQueue.back());
autoWalk(destinations.back());
}
}
}
bool LocalPlayer::autoWalk(const Position& destination) bool LocalPlayer::autoWalk(const Position& destination)
{ {
m_autoWalkSteps.clear(); m_autoWalkDestination = destination;
m_lastAutoWalkDestination = destination;
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result = g_map.findPath(m_position, destination, 1000, Otc::PathFindAllowNullTiles); std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result = g_map.findPath(m_position, destination, 1000, Otc::PathFindAllowNullTiles);
if(std::get<1>(result) != Otc::PathFindResultOk)
std::vector<Otc::Direction> dirs = std::get<0>(result);
if(dirs.size() == 0)
return false; return false;
if(dirs.size() > Otc::MAX_AUTOWALK_DIST) { Position currentPos = m_position;
dirs = calculateAutoWalk(dirs); std::vector<Otc::Direction> limitedPath;
m_lastAutoWalkDestination = m_position.translatedToDirections(dirs).back();
for(auto dir : std::get<0>(result)) {
currentPos = currentPos.translatedToDirection(dir);
if(!hasSight(currentPos))
break;
else
limitedPath.push_back(dir);
} }
g_game.autoWalk(dirs); m_lastAutoWalkPosition = m_position.translatedToDirections(limitedPath).back();
g_game.autoWalk(limitedPath);
return true; return true;
} }
void LocalPlayer::stopAutoWalkUpdate() void LocalPlayer::stopAutoWalk()
{ {
m_lastAutoWalkDestination = Position(); m_autoWalkDestination = Position();
m_autoWalkSteps.clear(); m_lastAutoWalkPosition = Position();
m_autoWalkQueue.clear();
} }
void LocalPlayer::stopWalk() void LocalPlayer::stopWalk()
@ -223,29 +204,6 @@ void LocalPlayer::stopWalk()
m_lastPrewalkDestionation = Position(); m_lastPrewalkDestionation = Position();
} }
std::vector<Otc::Direction>& LocalPlayer::calculateAutoWalk(std::vector<Otc::Direction>& dirs)
{
if(dirs.size() > Otc::MAX_AUTOWALK_DIST) {
// populate auto walk queue
m_autoWalkQueue.clear();
size_t blocks = std::ceil((float)dirs.size() / Otc::MAX_AUTOWALK_DIST);
size_t size = Otc::MAX_AUTOWALK_DIST;
for(size_t i = 0, offset=0 ; i < blocks ; ++i) {
std::vector<Otc::Direction>::iterator next = dirs.begin() + offset;
if((offset + size) < dirs.size())
m_autoWalkQueue.push_back(std::vector<Otc::Direction>(next, next + size));
else
m_autoWalkQueue.push_back(std::vector<Otc::Direction>(next, dirs.end()));
offset += size;
}
std::reverse(m_autoWalkQueue.begin(), m_autoWalkQueue.end());
return m_autoWalkQueue.back();
}
return dirs;
}
void LocalPlayer::updateWalkOffset(int totalPixelsWalked) void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
{ {
// pre walks offsets are calculated in the oposite direction // pre walks offsets are calculated in the oposite direction
@ -310,7 +268,8 @@ void LocalPlayer::onPositionChange(const Position& newPos, const Position& oldPo
{ {
Creature::onPositionChange(newPos, oldPos); Creature::onPositionChange(newPos, oldPos);
updateAutoWalkSteps(); if(m_autoWalkDestination.isValid() && newPos == m_lastAutoWalkPosition)
autoWalk(m_autoWalkDestination);
} }
void LocalPlayer::setStates(int states) void LocalPlayer::setStates(int states)
@ -318,6 +277,7 @@ void LocalPlayer::setStates(int states)
if(m_states != states) { if(m_states != states) {
int oldStates = m_states; int oldStates = m_states;
m_states = states; m_states = states;
callLuaField("onStatesChange", states, oldStates); callLuaField("onStatesChange", states, oldStates);
} }
} }

@ -37,11 +37,9 @@ public:
void unlockWalk() { m_walkLockExpiration = 0; } void unlockWalk() { m_walkLockExpiration = 0; }
void lockWalk(int millis = 250); void lockWalk(int millis = 250);
void stopAutoWalkUpdate(); void stopAutoWalk();
void updateAutoWalkSteps(bool walkFailed = false);
bool autoWalk(const Position& destination); bool autoWalk(const Position& destination);
bool canWalk(Otc::Direction direction); bool canWalk(Otc::Direction direction);
std::vector<Otc::Direction>& calculateAutoWalk(std::vector<Otc::Direction>& dirs);
void setStates(int states); void setStates(int states);
void setSkill(Otc::Skill skill, int level, int levelPercent); void setSkill(Otc::Skill skill, int level, int levelPercent);
@ -91,7 +89,6 @@ public:
double getOfflineTrainingTime() { return m_offlineTrainingTime; } double getOfflineTrainingTime() { return m_offlineTrainingTime; }
std::vector<int> getSpells() { return m_spells; } std::vector<int> getSpells() { return m_spells; }
ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; } ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; }
std::vector<Position> getAutoWalkSteps() { return m_autoWalkSteps; }
bool hasSight(const Position& pos); bool hasSight(const Position& pos);
bool isKnown() { return m_known; } bool isKnown() { return m_known; }
@ -123,7 +120,8 @@ private:
// walk related // walk related
Timer m_walkPingTimer; Timer m_walkPingTimer;
Position m_lastPrewalkDestionation; Position m_lastPrewalkDestionation;
Position m_lastAutoWalkDestination; Position m_autoWalkDestination;
Position m_lastAutoWalkPosition;
ScheduledEventPtr m_autoWalkEndEvent; ScheduledEventPtr m_autoWalkEndEvent;
ticks_t m_walkLockExpiration; ticks_t m_walkLockExpiration;
int m_lastWalkPing; int m_lastWalkPing;
@ -143,8 +141,6 @@ private:
std::array<int, Otc::LastSkill> m_skillsBaseLevel; std::array<int, Otc::LastSkill> m_skillsBaseLevel;
std::array<int, Otc::LastSkill> m_skillsLevelPercent; std::array<int, Otc::LastSkill> m_skillsLevelPercent;
std::vector<int> m_spells; std::vector<int> m_spells;
std::vector<Position> m_autoWalkSteps;
std::vector<std::vector<Otc::Direction> > m_autoWalkQueue;
int m_states; int m_states;
int m_vocation; int m_vocation;

@ -477,10 +477,8 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking); g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("hasSight", &LocalPlayer::hasSight); g_lua.bindClassMemberFunction<LocalPlayer>("hasSight", &LocalPlayer::hasSight);
g_lua.bindClassMemberFunction<LocalPlayer>("isAutoWalking", &LocalPlayer::isAutoWalking); g_lua.bindClassMemberFunction<LocalPlayer>("isAutoWalking", &LocalPlayer::isAutoWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("stopAutoWalkUpdate", &LocalPlayer::stopAutoWalkUpdate); g_lua.bindClassMemberFunction<LocalPlayer>("stopAutoWalk", &LocalPlayer::stopAutoWalk);
g_lua.bindClassMemberFunction<LocalPlayer>("updateAutoWalkSteps", &LocalPlayer::updateAutoWalkSteps);
g_lua.bindClassMemberFunction<LocalPlayer>("autoWalk", &LocalPlayer::autoWalk); g_lua.bindClassMemberFunction<LocalPlayer>("autoWalk", &LocalPlayer::autoWalk);
g_lua.bindClassMemberFunction<LocalPlayer>("getAutoWalkSteps", &LocalPlayer::getAutoWalkSteps);
g_lua.registerClass<Tile>(); g_lua.registerClass<Tile>();
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean); g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);
@ -508,6 +506,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("hasCreature", &Tile::hasCreature); g_lua.bindClassMemberFunction<Tile>("hasCreature", &Tile::hasCreature);
g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty); g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty);
g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable); g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable);
g_lua.bindClassMemberFunction<Tile>("overwriteMinimapColor", &Tile::overwriteMinimapColor);
g_lua.registerClass<UIItem, UIWidget>(); g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); }); g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });

@ -34,6 +34,7 @@
Tile::Tile(const Position& position) : Tile::Tile(const Position& position) :
m_position(position), m_position(position),
m_drawElevation(0), m_drawElevation(0),
m_minimapColor(0),
m_flags(0) m_flags(0)
{ {
} }
@ -338,6 +339,10 @@ int Tile::getGroundSpeed()
uint8 Tile::getMinimapColorByte() uint8 Tile::getMinimapColorByte()
{ {
uint8 color = 0; uint8 color = 0;
if(m_minimapColor != 0) {
return m_minimapColor;
}
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()) if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break; break;

@ -110,6 +110,7 @@ public:
bool limitsFloorsView(); bool limitsFloorsView();
bool canErase(); bool canErase();
bool hasElevation(int elevation = 1); bool hasElevation(int elevation = 1);
void overwriteMinimapColor(uint8 color) { m_minimapColor = color; }
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; }
@ -128,6 +129,7 @@ private:
stdext::packed_vector<ThingPtr> m_things; stdext::packed_vector<ThingPtr> m_things;
Position m_position; Position m_position;
uint8 m_drawElevation; uint8 m_drawElevation;
uint8 m_minimapColor;
uint32 m_flags, m_houseId; uint32 m_flags, m_houseId;
}; };
#pragma pack(pop) #pragma pack(pop)

Loading…
Cancel
Save