Skip to content

Commit

Permalink
Minor reorganization and cleanup in the world code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Oct 17, 2024
1 parent 3ae27ad commit 95b4336
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
61 changes: 30 additions & 31 deletions src/smw/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,18 +1182,27 @@ void WorldMap::SetPlayerSprite(short iPlayerSprite)
player.SetSprite(iPlayerSprite);
}

bool WorldMap::IsVehicleMoving() const
void WorldMap::SetPlayerPosition(short iPlayerCol, short iPlayerRow)
{
for (const WorldVehicle& vehicle : vehicles) {
if (vehicle.fEnabled && vehicle.iState > 0)
return true;
}
return false;
player.SetPosition(iPlayerCol, iPlayerRow);
}

void WorldMap::SetPlayerPosition(short iPlayerCol, short iPlayerRow)
void WorldMap::MovePlayer(short iDirection)
{
player.SetPosition(iPlayerCol, iPlayerRow);
player.Move(iDirection);
}

void WorldMap::FacePlayer(short iDirection)
{
player.FaceDirection(iDirection);
}

bool WorldMap::IsVehicleMoving() const
{
return std::any_of(vehicles.cbegin(), vehicles.cend(),
[](const WorldVehicle& vehicle) {
return vehicle.fEnabled && vehicle.iState > 0;
});
}

short WorldMap::GetVehicleInPlayerTile(short * vehicleIndex) const
Expand All @@ -1204,7 +1213,7 @@ short WorldMap::GetVehicleInPlayerTile(short * vehicleIndex) const
if (!vehicle.fEnabled)
continue;

if (vehicle.currentTile.x == player.currentTile.x && vehicle.currentTile.y == player.currentTile.y) {
if (vehicle.currentTile == player.currentTile) {
*vehicleIndex = i;
return vehicle.iActionId;
}
Expand All @@ -1214,28 +1223,6 @@ short WorldMap::GetVehicleInPlayerTile(short * vehicleIndex) const
return -1;
}

bool WorldMap::GetWarpInPlayerTile(short * iWarpCol, short * iWarpRow) const
{
short iWarp = tiles[player.currentTile.x][player.currentTile.y].iWarp;
if (iWarp < 0)
return false;

Vec2s pos = warps[iWarp].getOtherSide({player.currentTile.x, player.currentTile.y});
*iWarpCol = pos.x;
*iWarpRow = pos.y;
return true;
}

void WorldMap::MovePlayer(short iDirection)
{
player.Move(iDirection);
}

void WorldMap::FacePlayer(short iDirection)
{
player.FaceDirection(iDirection);
}

void WorldMap::MoveVehicles()
{
for (WorldVehicle& vehicle : vehicles) {
Expand All @@ -1262,6 +1249,18 @@ short WorldMap::GetVehicleStageScore(short iVehicleIndex) const
return game_values.tourstops[vehicles[iVehicleIndex].iActionId]->iPoints;
}

bool WorldMap::GetWarpInPlayerTile(short * iWarpCol, short * iWarpRow) const
{
short iWarp = tiles[player.currentTile.x][player.currentTile.y].iWarp;
if (iWarp < 0)
return false;

Vec2s pos = warps[iWarp].getOtherSide(player.currentTile);
*iWarpCol = pos.x;
*iWarpRow = pos.y;
return true;
}

void WorldMap::MoveBridges()
{
for (short iRow = 0; iRow < iHeight; iRow++) {
Expand Down
26 changes: 10 additions & 16 deletions src/smw/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,41 +160,35 @@ class WorldMap {
void DrawMapToSurface(SDL_Surface* surface) const;
void DrawMapToSurface(short iCycleIndex, bool fFullRefresh, SDL_Surface* surface, short iMapDrawOffsetCol, short iMapDrawOffsetRow, short iAnimationFrame);

void SetPlayerSprite(short iPlayerSprite);
bool IsVehicleMoving() const;

void GetWorldSize(short * w, short * h) const {
*w = iWidth;
*h = iHeight;
}

Vec2s GetPlayerPosition() const { return player.pos; }
void SetPlayerPosition(short iPlayerCol, short iPlayerRow);

Vec2s GetPlayerCurrentTile() const { return player.currentTile; }
Vec2s GetPlayerDestTile() const { return player.destTile; };
short GetPlayerState() const { return player.iState; };

short GetVehicleInPlayerTile(short * iVehicleIndex) const;
bool GetWarpInPlayerTile(short * iWarpCol, short * iWarpRow) const;

Vec2s GetPlayerPosition() const { return player.pos; }
void SetPlayerPosition(short iPlayerCol, short iPlayerRow);
void SetPlayerSprite(short iPlayerSprite);
void MovePlayer(short iDirection);
void FacePlayer(short iDirection);
void MoveVehicles();

void RemoveVehicle(short iVehicleIndex);

bool IsVehicleMoving() const;
short GetVehicleInPlayerTile(short * iVehicleIndex) const;
size_t NumVehiclesInTile(Vec2s iTile) const;

short GetVehicleStageScore(short iVehicleIndex) const;
void MoveVehicles();
void RemoveVehicle(short iVehicleIndex);
short GetVehicleBoundary(short iCol, short iRow) const;

bool GetWarpInPlayerTile(short * iWarpCol, short * iWarpRow) const;
void MoveBridges();

void IsTouchingDoor(short iCol, short iRow, bool doors[4]) const;
bool IsDoor(short iCol, short iRow) const;
short UseKey(short iKeytype, short iCol, short iRow, bool fCloud);

short GetVehicleBoundary(short iCol, short iRow) const;

short GetNextInterestingMove(short iCol, short iRow) const;

void SetInitialPowerups();
Expand Down

0 comments on commit 95b4336

Please sign in to comment.