summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-22 03:18:36 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-22 03:18:36 +0300
commit7e127f1832452953be6a9fd319174dbf91cbfcb6 (patch)
tree3d546678308b4d831d2f08993ddd2b2e30b6f295
parent01ee2e3e0272884388478e99eaf41e70f2acc77b (diff)
downloadplus-7e127f1832452953be6a9fd319174dbf91cbfcb6.tar.gz
plus-7e127f1832452953be6a9fd319174dbf91cbfcb6.tar.bz2
plus-7e127f1832452953be6a9fd319174dbf91cbfcb6.tar.xz
plus-7e127f1832452953be6a9fd319174dbf91cbfcb6.zip
Build path in SMSG_BEING_MOVE3 packet from back to forward and if need fix start position.
-rw-r--r--src/net/ea/beingrecv.cpp73
-rw-r--r--src/position.h1
2 files changed, 23 insertions, 51 deletions
diff --git a/src/net/ea/beingrecv.cpp b/src/net/ea/beingrecv.cpp
index c93d26a2c..39a0e26e1 100644
--- a/src/net/ea/beingrecv.cpp
+++ b/src/net/ea/beingrecv.cpp
@@ -449,71 +449,42 @@ void BeingRecv::processBeingMove3(Net::MessageIn &msg)
Path path;
if (moves)
{
- for (int f = 0; f < len; f ++)
+ int x2 = dstBeing->getCachedX();
+ int y2 = dstBeing->getCachedY();
+ Path path2;
+ path2.push_back(Position(x2, y2));
+ for (int f = len - 1; f >= 0; f --)
{
const unsigned char dir = moves[f];
if (dir <= 7)
{
- x += dirx[dir];
- y += diry[dir];
- path.push_back(Position(x, y));
+ x2 -= dirx[dir];
+ y2 -= diry[dir];
+ path2.push_back(Position(x2, y2));
+ if (x2 == x && y2 == y)
+ break;
}
else
{
logger->log("bad move packet: %d", dir);
}
}
- const int x1 = dstBeing->getCachedX();
- const int y1 = dstBeing->getCachedY();
- if (x1 != x || y1 != y)
+
+ if (!path2.empty())
{
-// reportAlways("Found desync being move. "
-// "Calculated target (%d,%d). "
-// "Actual target (%d,%d).",
-// static_cast<int>(x),
-// static_cast<int>(y),
-// static_cast<int>(x1),
-// static_cast<int>(y1));
- if (len > 0)
+ const Position &pos = path2.back();
+ if (x != pos.x ||
+ y != pos.y)
{
- const unsigned char dir = moves[0];
- int16_t x0 = x;
- int16_t y0 = y;
-
- if (dir <= 7)
- {
- x0 -= dirx[0];
- y0 -= diry[0];
- if (x1 == x0 && y1 == y0)
- {
- path.erase(path.begin());
- logger->log("Fixed being moving desync by "
- "removing one tile");
- }
- else
- {
- x0 = x;
- y0 = y;
- if (abs(x0 - x1) < 2 && abs(y0 - y1) < 2)
- {
- path.push_back(Position(x1, y1));
- logger->log("Fixed being moving desync by "
- "adding one tile");
- }
- else
- {
- reportAlways("Error: being moving desync. "
- "Calculated target (%d,%d). "
- "Actual target (%d,%d).",
- static_cast<int>(x),
- static_cast<int>(y),
- static_cast<int>(x1),
- static_cast<int>(y1));
- }
- }
- }
+ dstBeing->setTileCoords(pos.x, pos.y);
}
}
+
+ path2.pop_back();
+ FOR_EACHR (PathRIterator, it, path2)
+ {
+ path.push_back(*it);
+ }
delete [] moves;
}
diff --git a/src/position.h b/src/position.h
index caaca35ed..a2cb033f8 100644
--- a/src/position.h
+++ b/src/position.h
@@ -43,6 +43,7 @@ struct Position final
typedef std::list<Position> Path;
typedef Path::iterator PathIterator;
+typedef Path::reverse_iterator PathRIterator;
/**
* Appends a string representation of a position to the output stream.