simplistic autowalk

* add simple and stupid autowalk algorithm
* fix issue in classic control
This commit is contained in:
Eduardo Bart 2012-03-23 11:48:00 -03:00
parent 239f58296e
commit 8bc63e25df
11 changed files with 85 additions and 22 deletions

View File

@ -49,16 +49,6 @@ AlignTopCenter = 20
AlignBottomCenter = 24 AlignBottomCenter = 24
AlignCenter = 48 AlignCenter = 48
North = 0
East = 1
South = 2
West = 3
NorthEast = 4
SouthEast = 5
SouthWest = 6
NorthWest = 7
KeyUnknown = 0 KeyUnknown = 0
KeyEscape = 1 KeyEscape = 1
KeyTab = 2 KeyTab = 2

View File

@ -22,3 +22,12 @@ EmblemNone = 0
EmblemGreen = 1 EmblemGreen = 1
EmblemRed = 2 EmblemRed = 2
EmblemBlue = 3 EmblemBlue = 3
North = 0
East = 1
South = 2
West = 3
NorthEast = 4
SouthEast = 5
SouthWest = 6
NorthWest = 7

View File

@ -211,7 +211,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
return true return true
end end
if not Options['classicControl'] then if not Options.getOption('classicControl') then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing) GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true return true

View File

@ -59,6 +59,38 @@ end
function UIGameMap:onMouseRelease(mousePosition, mouseButton) function UIGameMap:onMouseRelease(mousePosition, mouseButton)
local tile = self:getTile(mousePosition) local tile = self:getTile(mousePosition)
if tile and GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end if tile == nil then return false end
if GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then
return true
elseif mouseButton == MouseLeftButton then
local fromPos = g_game.getLocalPlayer():getPosition()
local toPos = tile:getPosition()
if fromPos.z ~= toPos.z then
TextMessage.displayStatus('There is no way.')
return true
end
-- simple and stupid pathfinding algorithm
local dirs = {}
local pathPos = fromPos
while pathPos.x ~= toPos.x or pathPos.y ~= toPos.y do
if pathPos.x < toPos.x then
pathPos.x = pathPos.x + 1
table.insert(dirs, East)
elseif pathPos.x > toPos.x then
pathPos.x = pathPos.x - 1
table.insert(dirs, West)
elseif pathPos.y < toPos.y then
pathPos.y = pathPos.y + 1
table.insert(dirs, South)
else --if pathPos.y > toPos.y then
pathPos.y = pathPos.y - 1
table.insert(dirs, North)
end
end
g_game.autoWalk(dirs)
return true
end
return false return false
end end

View File

@ -113,7 +113,7 @@ function TextMessage.clearMessages()
end end
function TextMessage.displayStatus(msg, time) function TextMessage.displayStatus(msg, time)
displayMessage(MessageTypes.warning, msg) displayMessage(MessageTypes.statusSmall, msg)
end end
function TextMessage.displayEventAdvance(msg, time) function TextMessage.displayEventAdvance(msg, time)

View File

@ -372,7 +372,7 @@ void Game::walk(Otc::Direction direction)
forceWalk(direction); forceWalk(direction);
} }
void Game::walkPath(const std::vector<Otc::Direction>& dir) void Game::autoWalk(const std::vector<Otc::Direction>& dir)
{ {
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
@ -380,7 +380,7 @@ void Game::walkPath(const std::vector<Otc::Direction>& dir)
if(isFollowing()) if(isFollowing())
cancelFollow(); cancelFollow();
m_protocolGame->sendWalkPath(dir); m_protocolGame->sendAutoWalk(dir);
} }
void Game::forceWalk(Otc::Direction direction) void Game::forceWalk(Otc::Direction direction)

View File

@ -123,7 +123,7 @@ public:
// walk related // walk related
void walk(Otc::Direction direction); void walk(Otc::Direction direction);
void walkPath(const std::vector<Otc::Direction>& dir); void autoWalk(const std::vector<Otc::Direction>& dir);
void forceWalk(Otc::Direction direction); void forceWalk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void stop(); void stop();

View File

@ -82,7 +82,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_game", "forceLogout", std::bind(&Game::forceLogout, &g_game)); g_lua.bindClassStaticFunction("g_game", "forceLogout", std::bind(&Game::forceLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "safeLogout", std::bind(&Game::safeLogout, &g_game)); g_lua.bindClassStaticFunction("g_game", "safeLogout", std::bind(&Game::safeLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "walk", std::bind(&Game::walk, &g_game, _1)); g_lua.bindClassStaticFunction("g_game", "walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "walkPath", std::bind(&Game::walkPath, &g_game, _1)); g_lua.bindClassStaticFunction("g_game", "autoWalk", std::bind(&Game::autoWalk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "forceWalk", std::bind(&Game::forceWalk, &g_game, _1)); g_lua.bindClassStaticFunction("g_game", "forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "turn", std::bind(&Game::turn, &g_game, _1)); g_lua.bindClassStaticFunction("g_game", "turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game)); g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game));

View File

@ -155,7 +155,7 @@ namespace Proto {
ClientEnterGame = 10, ClientEnterGame = 10,
ClientLeaveGame = 20, ClientLeaveGame = 20,
ClientPingResponse = 30, ClientPingResponse = 30,
ClientWalkPath = 100, ClientAutoWalk = 100,
ClientWalkNorth = 101, ClientWalkNorth = 101,
ClientWalkEast = 102, ClientWalkEast = 102,
ClientWalkSouth = 103, ClientWalkSouth = 103,

View File

@ -42,7 +42,7 @@ public:
void sendLogout(); void sendLogout();
void sendPingResponse(); void sendPingResponse();
void sendWalkPath(const std::vector<Otc::Direction>& path); void sendAutoWalk(const std::vector<Otc::Direction>& path);
void sendWalkNorth(); void sendWalkNorth();
void sendWalkEast(); void sendWalkEast();
void sendWalkSouth(); void sendWalkSouth();

View File

@ -79,12 +79,44 @@ void ProtocolGame::sendPingResponse()
send(msg); send(msg);
} }
void ProtocolGame::sendWalkPath(const std::vector<Otc::Direction>& path) void ProtocolGame::sendAutoWalk(const std::vector<Otc::Direction>& path)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientAutoWalk);
msg.addU8(path.size()); msg.addU8(path.size());
for(Otc::Direction dir : path) for(Otc::Direction dir : path) {
msg.addU8(dir); uint8 byte;
switch(dir) {
case Otc::East:
byte = 1;
break;
case Otc::NorthEast:
byte = 2;
break;
case Otc::North:
byte = 3;
break;
case Otc::NorthWest:
byte = 4;
break;
case Otc::West:
byte = 5;
break;
case Otc::SouthWest:
byte = 6;
break;
case Otc::South:
byte = 7;
break;
case Otc::SouthEast:
byte = 8;
break;
default:
byte = 0;
break;
}
msg.addU8(byte);
}
send(msg); send(msg);
} }