diff --git a/Engine/ac/character.cpp b/Engine/ac/character.cpp index 034858e2f16..33a738a559d 100644 --- a/Engine/ac/character.cpp +++ b/Engine/ac/character.cpp @@ -179,11 +179,6 @@ void Character_AddWaypoint(CharacterInfo *chaa, int x, int y) { } MoveList &cmls = mls[chaa->walking % TURNING_AROUND]; - if (cmls.numstage >= MAXNEEDSTAGES) - { - debug_script_warn("Character::AddWaypoint: move is too complex, cannot add any further paths"); - return; - } // They're already walking there anyway const Point &last_pos = cmls.GetLastPos(); @@ -201,7 +196,7 @@ void Character_AddWaypoint(CharacterInfo *chaa, int x, int y) { // so we do this trick: convert last step to game resolution, before calling // a pathfinder api, and then we'll convert old and new last step back. // TODO: figure out a better way of processing this! - const int last_stage = cmls.numstage - 1; + const uint32_t last_stage = cmls.GetNumStages() - 1; cmls.pos[last_stage] = { data_to_game_coord(last_pos.X), data_to_game_coord(last_pos.Y) }; const int dst_x = data_to_game_coord(x); const int dst_y = data_to_game_coord(y); @@ -1414,7 +1409,7 @@ int Character_GetMoving(CharacterInfo *chaa) { int Character_GetDestinationX(CharacterInfo *chaa) { if (chaa->walking) { MoveList *cmls = &mls[chaa->walking % TURNING_AROUND]; - return cmls->pos[cmls->numstage - 1].X; + return cmls->pos.back().X; } else return chaa->x; @@ -1423,7 +1418,7 @@ int Character_GetDestinationX(CharacterInfo *chaa) { int Character_GetDestinationY(CharacterInfo *chaa) { if (chaa->walking) { MoveList *cmls = &mls[chaa->walking % TURNING_AROUND]; - return cmls->pos[cmls->numstage - 1].Y; + return cmls->pos.back().Y; } else return chaa->y; @@ -1868,8 +1863,8 @@ void start_character_turning (CharacterInfo *chinf, int useloop, int no_diagonal } void fix_player_sprite(MoveList*cmls,CharacterInfo*chinf) { - const fixed xpmove = cmls->xpermove[cmls->onstage]; - const fixed ypmove = cmls->ypermove[cmls->onstage]; + const fixed xpmove = cmls->permove[cmls->onstage].X; + const fixed ypmove = cmls->permove[cmls->onstage].Y; // if not moving, do nothing if ((xpmove == 0) && (ypmove == 0)) diff --git a/Engine/ac/character.h b/Engine/ac/character.h index 9e963aba2c3..849552fca94 100644 --- a/Engine/ac/character.h +++ b/Engine/ac/character.h @@ -164,7 +164,7 @@ int Character_GetSpeakingFrame(CharacterInfo *chaa); //============================================================================= -struct MoveList; +class MoveList; namespace AGS { namespace Common { class Bitmap; } } using namespace AGS; // FIXME later diff --git a/Engine/ac/draw.cpp b/Engine/ac/draw.cpp index f73335e8747..322f6585d11 100644 --- a/Engine/ac/draw.cpp +++ b/Engine/ac/draw.cpp @@ -2938,7 +2938,7 @@ void update_room_debug() if (game.chars[debugMoveListChar].walking >= TURNING_AROUND) mlsnum %= TURNING_AROUND; const MoveList &cmls = mls[mlsnum]; - for (int i = 0; i < cmls.numstage - 1; i++) { + for (uint32_t i = 0; i < cmls.GetNumStages() - 1; i++) { short srcx = cmls.pos[i].X; short srcy = cmls.pos[i].Y; short targetx = cmls.pos[i + 1].X; diff --git a/Engine/ac/movelist.cpp b/Engine/ac/movelist.cpp index f8711c32ed3..e7c28b0c6d2 100644 --- a/Engine/ac/movelist.cpp +++ b/Engine/ac/movelist.cpp @@ -22,23 +22,23 @@ using namespace AGS::Engine; float MoveList::GetStepLength() const { - assert(numstage > 0); - float permove_x = fixtof(xpermove[onstage]); - float permove_y = fixtof(ypermove[onstage]); + assert(GetNumStages() > 0); + float permove_x = fixtof(permove[onstage].X); + float permove_y = fixtof(permove[onstage].Y); return std::sqrt(permove_x * permove_x + permove_y * permove_y); } float MoveList::GetPixelUnitFraction() const { - assert(numstage > 0); - float distance = GetStepLength() * onpart; + assert(GetNumStages() > 0); + const float distance = GetStepLength() * onpart; return distance - std::floor(distance); } void MoveList::SetPixelUnitFraction(float frac) { - assert(numstage > 0); - float permove_dist = GetStepLength(); + assert(GetNumStages() > 0); + const float permove_dist = GetStepLength(); onpart = permove_dist > 0.f ? (1.f / permove_dist) * frac : 0.f; } @@ -51,17 +51,13 @@ HSaveError MoveList::ReadFromSavegame(Stream *in, int32_t cmp_ver) } *this = MoveList(); // reset struct - numstage = in->ReadInt32(); + uint32_t numstage = in->ReadInt32(); + pos.resize(numstage); + permove.resize(numstage); if ((numstage == 0) && cmp_ver >= kMoveSvgVersion_36109) { return HSaveError::None(); } - // TODO: reimplement MoveList stages as vector to avoid these limits - if (numstage > MAXNEEDSTAGES) - { - return new SavegameError(kSvgErr_IncompatibleEngine, - String::FromFormat("Incompatible number of movelist steps (count: %d, max : %d).", numstage, MAXNEEDSTAGES)); - } from.X = in->ReadInt32(); from.Y = in->ReadInt32(); @@ -72,13 +68,19 @@ HSaveError MoveList::ReadFromSavegame(Stream *in, int32_t cmp_ver) doneflag = in->ReadInt8(); direct = in->ReadInt8(); - for (int i = 0; i < numstage; ++i) + for (uint32_t i = 0; i < numstage; ++i) { // X & Y was packed as high/low shorts, and hence reversed in lo-end pos[i].Y = in->ReadInt16(); pos[i].X = in->ReadInt16(); } - in->ReadArrayOfInt32(xpermove, numstage); - in->ReadArrayOfInt32(ypermove, numstage); + for (uint32_t i = 0; i < numstage; ++i) + { + permove[i].X = in->ReadInt32(); + } + for (uint32_t i = 0; i < numstage; ++i) + { + permove[i].Y = in->ReadInt32(); + } // Some variables require conversion depending on a save version if (cmp_ver < kMoveSvgVersion_36109) @@ -91,6 +93,7 @@ HSaveError MoveList::ReadFromSavegame(Stream *in, int32_t cmp_ver) void MoveList::WriteToSavegame(Stream *out) const { + const uint32_t numstage = GetNumStages(); out->WriteInt32(numstage); if (numstage == 0) return; @@ -104,11 +107,17 @@ void MoveList::WriteToSavegame(Stream *out) const out->WriteInt8(doneflag); out->WriteInt8(direct); - for (int i = 0; i < numstage; ++i) + for (uint32_t i = 0; i < numstage; ++i) { // X & Y was packed as high/low shorts, and hence reversed in lo-end out->WriteInt16(pos[i].Y); out->WriteInt16(pos[i].X); } - out->WriteArrayOfInt32(xpermove, numstage); - out->WriteArrayOfInt32(ypermove, numstage); + for (uint32_t i = 0; i < numstage; ++i) + { + out->WriteInt32(permove[i].X); + } + for (uint32_t i = 0; i < numstage; ++i) + { + out->WriteInt32(permove[i].Y); + } } diff --git a/Engine/ac/movelist.h b/Engine/ac/movelist.h index 709840b9bef..2f0277a5fdd 100644 --- a/Engine/ac/movelist.h +++ b/Engine/ac/movelist.h @@ -21,7 +21,7 @@ namespace AGS { namespace Common { class Stream; } } using namespace AGS; // FIXME later -#define MAXNEEDSTAGES 256 +#define LEGACY_MAXMOVESTAGES 256 #define MAXNEEDSTAGES_LEGACY 40 enum MoveListDoneFlags @@ -38,19 +38,22 @@ enum MoveListSvgVersion kMoveSvgVersion_36109, // skip empty lists, progress as float }; -struct MoveList +class MoveList { - int numstage = 0; +public: + // TODO: protect all these fields! + // Waypoints, per stage - Point pos[MAXNEEDSTAGES]; - // xpermove and ypermove contain number of pixels done per a single step - // along x and y axes; i.e. this is a movement vector, per path stage - fixed xpermove[MAXNEEDSTAGES]{}; - fixed ypermove[MAXNEEDSTAGES]{}; - int onstage = 0; // current path stage + std::vector pos; + // permove contain number of pixels done per a single step + // along x and y axes; i.e. this is a movement vector, per path stage; + // these values are treated as "fixed" (fixed-point) type. + // TODO: perhaps turn Point class into a template, and use Point here. + std::vector permove; + uint32_t onstage = 0; // current path stage Point from; // current stage's starting position // Steps made during current stage; - // distance passed is calculated as xpermove[onstage] * onpart; + // distance passed is calculated as permove[onstage] * onpart; // made a fractional value to let recalculate movelist dynamically float onpart = 0.f; uint8_t doneflag = 0u; @@ -62,7 +65,9 @@ struct MoveList fixed fin_move = 0; float fin_from_part = 0.f; - const Point &GetLastPos() const { return numstage > 0 ? pos[numstage - 1] : pos[0]; } + bool IsEmpty() const { return pos.empty(); } + uint32_t GetNumStages() const { return pos.size(); } + const Point &GetLastPos() const { return pos.back(); } // Gets a movelist's step length, in coordinate units // (normally the coord unit is a game pixel) diff --git a/Engine/ac/room.cpp b/Engine/ac/room.cpp index 9c9ce46fe7e..363a43102fb 100644 --- a/Engine/ac/room.cpp +++ b/Engine/ac/room.cpp @@ -1087,20 +1087,18 @@ int mask_to_room_coord(int coord) return coord * thisroom.MaskResolution / game.GetDataUpscaleMult(); } -void convert_move_path_to_data_resolution(MoveList &mls, int from_step, int to_step) +void convert_move_path_to_data_resolution(MoveList &mls, uint32_t from_step, uint32_t to_step) { - if (to_step < 0) - to_step = mls.numstage; - to_step = Math::Clamp(to_step, 0, mls.numstage - 1); - from_step = Math::Clamp(from_step, 0, to_step); + to_step = Math::Clamp(to_step, 0u, mls.GetNumStages() - 1); + from_step = Math::Clamp(from_step, 0u, to_step); // If speed is independent from MaskResolution... if ((game.options[OPT_WALKSPEEDABSOLUTE] != 0) && game.GetDataUpscaleMult() > 1) { for (int i = from_step; i <= to_step; i++) { // ...we still need to convert from game to data coords - mls.xpermove[i] = game_to_data_coord(mls.xpermove[i]); - mls.ypermove[i] = game_to_data_coord(mls.ypermove[i]); + mls.permove[i].X = game_to_data_coord(mls.permove[i].X); + mls.permove[i].Y = game_to_data_coord(mls.permove[i].Y); } } // If speed is scaling with MaskResolution... @@ -1108,8 +1106,8 @@ void convert_move_path_to_data_resolution(MoveList &mls, int from_step, int to_s { for (int i = from_step; i <= to_step; i++) { - mls.xpermove[i] = mask_to_room_coord(mls.xpermove[i]); - mls.ypermove[i] = mask_to_room_coord(mls.ypermove[i]); + mls.permove[i].X = mask_to_room_coord(mls.permove[i].X); + mls.permove[i].Y = mask_to_room_coord(mls.permove[i].Y); } } diff --git a/Engine/ac/room.h b/Engine/ac/room.h index b7020d0e5f8..4379fc27b35 100644 --- a/Engine/ac/room.h +++ b/Engine/ac/room.h @@ -73,10 +73,10 @@ int room_to_mask_coord(int coord); // coordinate conversion (room mask) ---> game ---> (data) int mask_to_room_coord(int coord); -struct MoveList; +class MoveList; // Convert move path from room (eq. game) resolution to data resolution; // applies move speed factor, according to the game settings -void convert_move_path_to_data_resolution(MoveList &mls, int from_step = 0, int to_step = -1); +void convert_move_path_to_data_resolution(MoveList &mls, uint32_t from_step = 0, uint32_t to_step = UINT32_MAX); // The single global "current room" instance extern AGS::Common::RoomStruct thisroom; diff --git a/Engine/ac/route_finder.cpp b/Engine/ac/route_finder.cpp index e408ff9cab5..5f9c7a59c72 100644 --- a/Engine/ac/route_finder.cpp +++ b/Engine/ac/route_finder.cpp @@ -148,8 +148,8 @@ void calculate_move_stage(MoveList &mls, uint32_t stage, fixed move_speed_x, fix // work out the x & y per move. First, opp/adj=tan, so work out the angle if (mls.pos[stage] == mls.pos[stage + 1]) { - mls.xpermove[stage] = 0; - mls.ypermove[stage] = 0; + mls.permove[stage].X = 0; + mls.permove[stage].Y = 0; return; } @@ -161,19 +161,19 @@ void calculate_move_stage(MoveList &mls, uint32_t stage, fixed move_speed_x, fix // Special case for vertical and horizontal movements if (ourx == destx) { - mls.xpermove[stage] = 0; - mls.ypermove[stage] = move_speed_y; + mls.permove[stage].X = 0; + mls.permove[stage].Y = move_speed_y; if (desty < oury) - mls.ypermove[stage] = -mls.ypermove[stage]; + mls.permove[stage].Y = -mls.permove[stage].Y; return; } if (oury == desty) { - mls.xpermove[stage] = move_speed_x; - mls.ypermove[stage] = 0; + mls.permove[stage].X = move_speed_x; + mls.permove[stage].Y = 0; if (destx < ourx) - mls.xpermove[stage] = -mls.xpermove[stage]; + mls.permove[stage].X = -mls.permove[stage].X; return; } @@ -197,8 +197,8 @@ void calculate_move_stage(MoveList &mls, uint32_t stage, fixed move_speed_x, fix if (desty < oury) newymove = -newymove; - mls.xpermove[stage] = newxmove; - mls.ypermove[stage] = newymove; + mls.permove[stage].X = newxmove; + mls.permove[stage].Y = newymove; #ifdef DEBUG_PATHFINDER AGS::Common::Debug::Printf("stage %d from %d,%d to %d,%d Xpermove:%X Ypm:%X", stage, ourx, oury, destx, desty, newxmove, newymove); @@ -207,16 +207,13 @@ void calculate_move_stage(MoveList &mls, uint32_t stage, fixed move_speed_x, fix bool CalculateMoveList(MoveList &mls, const std::vector path, int move_speed_x, int move_speed_y) { - // Ensure that it does not exceed MoveList limit - const size_t stage_count = std::min((size_t)MAXNEEDSTAGES, path.size()); - MoveList mlist; - mlist.numstage = stage_count; - std::copy(path.begin(), path.begin() + stage_count, &mlist.pos[0]); + mlist.pos = path; + mlist.permove.resize(path.size()); const fixed fix_speed_x = input_speed_to_fixed(move_speed_x); const fixed fix_speed_y = input_speed_to_fixed(move_speed_y); - for (uint32_t i = 0; i < stage_count - 1; i++) + for (uint32_t i = 0; i < mlist.GetNumStages() - 1; i++) calculate_move_stage(mlist, i, fix_speed_x, fix_speed_y); mlist.from = mlist.pos[0]; @@ -226,14 +223,12 @@ bool CalculateMoveList(MoveList &mls, const std::vector path, int move_sp bool AddWaypointDirect(MoveList &mls, int x, int y, int move_speed_x, int move_speed_y) { - if (mls.numstage >= MAXNEEDSTAGES) - return false; - const fixed fix_speed_x = input_speed_to_fixed(move_speed_x); const fixed fix_speed_y = input_speed_to_fixed(move_speed_y); - mls.pos[mls.numstage] = { x, y }; - calculate_move_stage(mls, mls.numstage - 1, fix_speed_x, fix_speed_y); - mls.numstage++; + const uint32_t last_stage = mls.GetNumStages() - 1; + mls.pos.emplace_back( x, y ); + mls.permove.resize(mls.pos.size()); + calculate_move_stage(mls, last_stage, fix_speed_x, fix_speed_y); return true; } @@ -244,19 +239,19 @@ void RecalculateMoveSpeeds(MoveList &mls, int old_speed_x, int old_speed_y, int const fixed new_movspeed_x = input_speed_to_fixed(new_speed_x); const fixed new_movspeed_y = input_speed_to_fixed(new_speed_y); // save current stage's step lengths, for later onpart's update - const fixed old_stage_xpermove = mls.xpermove[mls.onstage]; - const fixed old_stage_ypermove = mls.ypermove[mls.onstage]; + const fixed old_stage_xpermove = mls.permove[mls.onstage].X; + const fixed old_stage_ypermove = mls.permove[mls.onstage].Y; - for (int i = 0; (i < mls.numstage) && ((mls.xpermove[i] != 0) || (mls.ypermove[i] != 0)); ++i) + for (uint32_t i = 0; (i < mls.GetNumStages()) && ((mls.permove[i].X != 0.f) || (mls.permove[i].Y != 0.f)); ++i) { // First three cases where the speed is a plain factor, therefore // we may simply divide on old one and multiple on a new one if ((old_movspeed_x == old_movspeed_y) || // diagonal move at straight 45 degrees - (mls.xpermove[i] == 0) || // straight vertical move - (mls.ypermove[i] == 0)) // straight horizontal move + (mls.permove[i].X == 0) || // straight vertical move + (mls.permove[i].Y == 0)) // straight horizontal move { - mls.xpermove[i] = fixdiv(fixmul(mls.xpermove[i], new_movspeed_x), old_movspeed_x); - mls.ypermove[i] = fixdiv(fixmul(mls.ypermove[i], new_movspeed_y), old_movspeed_y); + mls.permove[i].X = fixdiv(fixmul(mls.permove[i].X, new_movspeed_x), old_movspeed_x); + mls.permove[i].Y = fixdiv(fixmul(mls.permove[i].Y, new_movspeed_y), old_movspeed_y); } else { @@ -271,8 +266,8 @@ void RecalculateMoveSpeeds(MoveList &mls, int old_speed_x, int old_speed_y, int fixed old_speed_at_angle = calc_move_speed_at_angle(old_movspeed_x, old_movspeed_y, xdist, ydist); fixed new_speed_at_angle = calc_move_speed_at_angle(new_movspeed_x, new_movspeed_y, xdist, ydist); - mls.xpermove[i] = fixdiv(fixmul(mls.xpermove[i], new_speed_at_angle), old_speed_at_angle); - mls.ypermove[i] = fixdiv(fixmul(mls.ypermove[i], new_speed_at_angle), old_speed_at_angle); + mls.permove[i].X = fixdiv(fixmul(mls.permove[i].X, new_speed_at_angle), old_speed_at_angle); + mls.permove[i].Y = fixdiv(fixmul(mls.permove[i].Y, new_speed_at_angle), old_speed_at_angle); } } @@ -280,9 +275,9 @@ void RecalculateMoveSpeeds(MoveList &mls, int old_speed_x, int old_speed_y, int if (mls.onpart >= 0.f) { if (old_stage_xpermove != 0) - mls.onpart = (mls.onpart * fixtof(old_stage_xpermove)) / fixtof(mls.xpermove[mls.onstage]); + mls.onpart = (mls.onpart * fixtof(old_stage_xpermove)) / fixtof(mls.permove[mls.onstage].X); else - mls.onpart = (mls.onpart * fixtof(old_stage_ypermove)) / fixtof(mls.ypermove[mls.onstage]); + mls.onpart = (mls.onpart * fixtof(old_stage_ypermove)) / fixtof(mls.permove[mls.onstage].Y); } } diff --git a/Engine/ac/route_finder.h b/Engine/ac/route_finder.h index dc0e3aa21fb..d1cfa07dd9b 100644 --- a/Engine/ac/route_finder.h +++ b/Engine/ac/route_finder.h @@ -19,7 +19,7 @@ #include "ac/game_version.h" #include "util/geometry.h" -struct MoveList; +class MoveList; namespace AGS { diff --git a/Engine/ac/route_finder_impl.cpp b/Engine/ac/route_finder_impl.cpp index c9feac5f959..9ab3c570797 100644 --- a/Engine/ac/route_finder_impl.cpp +++ b/Engine/ac/route_finder_impl.cpp @@ -87,10 +87,7 @@ bool JPSRouteFinder::FindRouteJPS(std::vector &nav_path, int fromx, int f nav_path.clear(); - // new behavior: cut path if too complex rather than abort with error message - int count = std::min((int)cpath.size(), MAXNAVPOINTS); - - for (int i = 0; i < count; i++) + for (int i = 0; i < cpath.size(); i++) { int x, y; nav.UnpackSquare(cpath[i], x, y); @@ -125,8 +122,6 @@ bool JPSRouteFinder::FindRouteImpl(std::vector &nav_path, int srcx, int s if (nav_path.size() == 1) nav_path.push_back(nav_path[0]); - assert(nav_path.size() <= MAXNAVPOINTS); - #ifdef DEBUG_PATHFINDER AGS::Common::Debug::Printf("Route from %d,%d to %d,%d - %zu stages", srcx,srcy,xx,yy,nav_path.size()); #endif diff --git a/Engine/ac/route_finder_impl.h b/Engine/ac/route_finder_impl.h index 8d698a199eb..eefc981f62e 100644 --- a/Engine/ac/route_finder_impl.h +++ b/Engine/ac/route_finder_impl.h @@ -46,7 +46,6 @@ class JPSRouteFinder : public MaskRouteFinder void SyncNavWalkablearea(); bool FindRouteJPS(std::vector &nav_path, int fromx, int fromy, int destx, int desty); - static const int MAXNAVPOINTS = MAXNEEDSTAGES; Navigation &nav; // declare as reference, because we must hide real Navigation decl here std::vector path, cpath; }; diff --git a/Engine/ac/route_finder_impl_legacy.cpp b/Engine/ac/route_finder_impl_legacy.cpp index 6eeee835e70..5b3174f891c 100644 --- a/Engine/ac/route_finder_impl_legacy.cpp +++ b/Engine/ac/route_finder_impl_legacy.cpp @@ -736,8 +736,6 @@ bool LegacyRouteFinder::FindRouteImpl(std::vector &path, int srcx, int sr if ( (nearestpos.X + nearestpos.Y) > 0) { // NOTE: we only deal with positive coordinates here path.push_back(nearestpos); - if (path.size() >= MAXNEEDSTAGES - 1) - quit("too many stages for auto-walk"); srcx = nearestpos.X; srcy = nearestpos.Y; #ifdef DEBUG_PATHFINDER diff --git a/Engine/ac/route_finder_impl_legacy.h b/Engine/ac/route_finder_impl_legacy.h index ed74322b587..69f743f3165 100644 --- a/Engine/ac/route_finder_impl_legacy.h +++ b/Engine/ac/route_finder_impl_legacy.h @@ -18,7 +18,6 @@ // Forward declaration namespace AGS { namespace Common { class Bitmap; }} -struct MoveList; namespace AGS { diff --git a/Engine/main/update.cpp b/Engine/main/update.cpp index 7ebc0c76470..525c100c809 100644 --- a/Engine/main/update.cpp +++ b/Engine/main/update.cpp @@ -112,9 +112,9 @@ static void movelist_handle_remainer(const fixed xpermove, const fixed ypermove, // Handle remaining move fixup, but only if necessary static void movelist_handle_remainer(MoveList &m) { - assert(m.numstage > 0); - const fixed xpermove = m.xpermove[m.onstage]; - const fixed ypermove = m.ypermove[m.onstage]; + assert(m.GetNumStages() > 0); + const fixed xpermove = m.permove[m.onstage].X; + const fixed ypermove = m.permove[m.onstage].Y; const Point target = m.pos[m.onstage + 1]; // Apply remainer to movelists where LONGER axis was completed, and SHORTER remains if ((xpermove != 0) && (ypermove != 0)) @@ -161,8 +161,8 @@ int do_movelist_move(short &mslot, int &pos_x, int &pos_y) int need_to_fix_sprite = 0; // TODO: find out what this value means and refactor MoveList &cmls = mls[mslot]; - const fixed xpermove = cmls.xpermove[cmls.onstage]; - const fixed ypermove = cmls.ypermove[cmls.onstage]; + const fixed xpermove = cmls.permove[cmls.onstage].X; + const fixed ypermove = cmls.permove[cmls.onstage].Y; const fixed fin_move = cmls.fin_move; const float main_onpart = (cmls.fin_from_part > 0.f) ? cmls.fin_from_part : cmls.onpart; const float fin_onpart = cmls.onpart - main_onpart; @@ -211,15 +211,15 @@ int do_movelist_move(short &mslot, int &pos_x, int &pos_y) cmls.fin_from_part = 0.f; cmls.fin_move = 0; cmls.doneflag = 0; - if (cmls.onstage < cmls.numstage) + if (cmls.onstage < cmls.GetNumStages()) { xps = cmls.from.X; yps = cmls.from.Y; } - if (cmls.onstage >= cmls.numstage - 1) + if (cmls.onstage >= cmls.GetNumStages() - 1) { // last stage is just dest pos - cmls.numstage=0; + cmls = {}; mslot = 0; need_to_fix_sprite = 1; // TODO: find out what this means } @@ -241,7 +241,7 @@ void restore_movelists() // Recalculate move remainer fixups, where necessary for (auto &m : mls) { - if (m.numstage > 0) + if (m.GetNumStages() > 0) movelist_handle_remainer(m); } } diff --git a/Engine/plugin/agsplugin.cpp b/Engine/plugin/agsplugin.cpp index f1a05821a87..226bc9428bd 100644 --- a/Engine/plugin/agsplugin.cpp +++ b/Engine/plugin/agsplugin.cpp @@ -736,7 +736,7 @@ void IAGSEngine::SimulateMouseClick(int32 button) { } int IAGSEngine::GetMovementPathWaypointCount(int32 pathId) { - return mls[pathId % TURNING_AROUND].numstage; + return mls[pathId % TURNING_AROUND].GetNumStages(); } int IAGSEngine::GetMovementPathLastWaypoint(int32 pathId) { @@ -749,8 +749,8 @@ void IAGSEngine::GetMovementPathWaypointLocation(int32 pathId, int32 waypoint, i } void IAGSEngine::GetMovementPathWaypointSpeed(int32 pathId, int32 waypoint, int32 *xSpeed, int32 *ySpeed) { - *xSpeed = mls[pathId % TURNING_AROUND].xpermove[waypoint]; - *ySpeed = mls[pathId % TURNING_AROUND].ypermove[waypoint]; + *xSpeed = mls[pathId % TURNING_AROUND].permove[waypoint].X; + *ySpeed = mls[pathId % TURNING_AROUND].permove[waypoint].Y; } int IAGSEngine::IsRunningUnderDebugger()