Skip to content

Commit

Permalink
kesz_de_nincs_tesztelve
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Oct 17, 2024
1 parent 2282e93 commit 429b53a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 120 deletions.
58 changes: 15 additions & 43 deletions src/smw/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ int popNextInt(std::list<std::string_view>& list, int defval = 0)
* WorldMovingObject
**********************************/

WorldMovingObject::WorldMovingObject()
{
SetPosition(0, 0);
}

void WorldMovingObject::Init(short iCol, short iRow, short iSprite, short iInitialDirection, short tilesize)
WorldMovingObject::WorldMovingObject(short iCol, short iRow, short iSprite, short iInitialDirection, short tilesize)
{
iTileSize = tilesize;
iTileSheet = tilesize == TILESIZE ? 0 : 1;
Expand Down Expand Up @@ -171,10 +166,8 @@ WorldPlayer::WorldPlayer()
{}

WorldPlayer::WorldPlayer(short iCol, short iRow)
: WorldMovingObject()
{
WorldMovingObject::Init(iCol, iRow, 0, 0, 32);
}
: WorldMovingObject(iCol, iRow, 0, 0, 32)
{}

void WorldPlayer::Draw(short iMapOffsetX, short iMapOffsetY) const
{
Expand All @@ -196,41 +189,21 @@ void WorldPlayer::SetSprite(short iPlayer)
* WorldVehicle
**********************************/

WorldVehicle::WorldVehicle() :
WorldMovingObject()
{}

WorldVehicle::~WorldVehicle()
WorldVehicle::WorldVehicle()
: WorldMovingObject(0, 0, 0, 0, 0)
{}

void WorldVehicle::Init(short iCol, short iRow, short iAction, short iSprite, short minMoves, short maxMoves, bool spritePaces, short iInitialDirection, short boundary, short tilesize)
WorldVehicle::WorldVehicle(short iCol, short iRow, short iAction, short iSprite, short minMoves, short maxMoves, bool spritePaces, short iInitialDirection, short boundary, short tilesize)
: WorldMovingObject(iCol, iRow, iSprite, iInitialDirection, tilesize)
, iMinMoves(minMoves)
, iMaxMoves(maxMoves)
, iActionId(iAction)
, fEnabled(true)
, fSpritePaces(spritePaces)
, iBoundary(boundary)
{
WorldMovingObject::Init(iCol, iRow, iSprite, iInitialDirection, tilesize);

fEnabled = true;

short iRectOffsetX = 0;
short iRectOffsetY = 0;

if (iDrawSprite >= 0 && iDrawSprite <= 8) {
iRectOffsetX = 0;
iRectOffsetY = iDrawSprite * tilesize;
}

for (short iRect = 0; iRect < 5; iRect++)
srcRects[iRect] = {iRect * tilesize + iRectOffsetX, iRectOffsetY, tilesize, tilesize};

iNumMoves = 0;
iActionId = iAction;

iMinMoves = minMoves;
iMaxMoves = maxMoves;

fSpritePaces = spritePaces;
iPaceOffset = 0;
iPaceTimer = 0;

iBoundary = boundary;
srcRects[iRect] = {iRect * tilesize, 0, tilesize, tilesize};
}

void WorldVehicle::Move()
Expand Down Expand Up @@ -653,8 +626,7 @@ WorldMap::WorldMap(const std::string& path, short tilesize)

short iBoundary = popNextInt(tokens);

vehicles.emplace_back(WorldVehicle());
vehicles.back().Init(iCol, iRow, iStage, iSprite, iMinMoves, iMaxMoves, fSpritePaces, iInitialDirection, iBoundary, iTileSize);
vehicles.emplace_back(iCol, iRow, iStage, iSprite, iMinMoves, iMaxMoves, fSpritePaces, iInitialDirection, iBoundary, iTileSize);

if (vehicles.size() >= iNumVehicles)
iReadType = 16;
Expand Down
50 changes: 23 additions & 27 deletions src/smw/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ struct WorldMapTile {

class WorldMovingObject {
public:
WorldMovingObject();
WorldMovingObject(short iCol, short iRow, short iSprite, short iInitialDirection, short tilesize);
virtual ~WorldMovingObject() = default;

void Init(short iCol, short iRow, short iSprite, short iInitialDirection, short tilesize);

virtual void Move(short iDirection);
virtual bool Update();

Expand Down Expand Up @@ -80,38 +78,36 @@ class WorldPlayer : public WorldMovingObject {
void Draw(short iWorldOffsetX, short iWorldOffsetY) const;
};

class WorldVehicle : public WorldMovingObject
{
public:

WorldVehicle();
~WorldVehicle();

void Init(short iCol, short iRow, short iAction, short iSprite, short iMinMoves, short iMaxMoves, bool fSpritePaces, short iInitialDirection, short iBoundary, short tilesize);
void Move();

bool Update();
void Draw(short iWorldOffsetX, short iWorldOffsetY, bool fVehiclesSleeping) const;
class WorldVehicle : public WorldMovingObject {
public:
WorldVehicle();
WorldVehicle(short iCol, short iRow, short iAction, short iSprite,
short iMinMoves, short iMaxMoves,
bool fSpritePaces, short iInitialDirection,
short iBoundary, short tilesize);

private:
void Move();
bool Update();
void Draw(short iWorldOffsetX, short iWorldOffsetY, bool fVehiclesSleeping) const;

void SetNextDest();
private:
void SetNextDest();

SDL_Rect srcRects[5];
SDL_Rect srcRects[5];

short iMinMoves;
short iMaxMoves;
short iNumMoves;
short iMinMoves = 5;
short iMaxMoves = 8;
short iNumMoves = 0;

short iActionId;
short iActionId = 0;

bool fEnabled;
bool fEnabled = false;

bool fSpritePaces;
short iPaceOffset;
short iPaceTimer;
bool fSpritePaces = true;
short iPaceOffset = 0;
short iPaceTimer = 0;

short iBoundary;
short iBoundary = 0;

friend class WorldMap;
friend void AddVehicleToTile(short iCol, short iRow, short iType);
Expand Down
61 changes: 11 additions & 50 deletions src/worldeditor/worldeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,19 +1967,7 @@ void ReadVehiclesIntoEditor()
vehiclelist.clear();

for (const WorldVehicle& vehicle : g_worldmap.vehicles) {
WorldVehicle * vehiclecopy = new WorldVehicle();

vehiclecopy->iDrawSprite = vehicle.iDrawSprite;
vehiclecopy->iActionId = vehicle.iActionId;
vehiclecopy->currentTile.x = vehicle.currentTile.x;
vehiclecopy->currentTile.y = vehicle.currentTile.y;
vehiclecopy->iMinMoves = vehicle.iMinMoves;
vehiclecopy->iMaxMoves = vehicle.iMaxMoves;
vehiclecopy->fSpritePaces = vehicle.fSpritePaces;
vehiclecopy->iDrawDirection = vehicle.iDrawDirection;
vehiclecopy->iBoundary = vehicle.iBoundary;

vehiclelist.push_back(vehiclecopy);
vehiclelist.push_back(new WorldVehicle(vehicle));
}
}

Expand All @@ -1992,48 +1980,21 @@ void WriteVehiclesIntoWorld()
g_worldmap.vehicles.reserve(vehiclelist.size());

for (const WorldVehicle* vehicle : vehiclelist) {
WorldVehicle vehiclecopy;
vehiclecopy.iDrawSprite = vehicle->iDrawSprite;
vehiclecopy.iActionId = vehicle->iActionId;
vehiclecopy.currentTile.x = vehicle->currentTile.x;
vehiclecopy.currentTile.y = vehicle->currentTile.y;
vehiclecopy.iMinMoves = vehicle->iMinMoves;
vehiclecopy.iMaxMoves = vehicle->iMaxMoves;
vehiclecopy.fSpritePaces = vehicle->fSpritePaces;
vehiclecopy.iDrawDirection = vehicle->iDrawDirection;
vehiclecopy.iBoundary = vehicle->iBoundary;
g_worldmap.vehicles.emplace_back(std::move(vehiclecopy));
g_worldmap.vehicles.emplace_back(*vehicle);
}
}

void AddVehicleToTile(short iCol, short iRow, short iType)
{
std::vector<WorldVehicle*>::iterator itr = vehiclelist.begin(), lim = vehiclelist.end();
WorldVehicle * newvehicle = NULL;
while (itr != lim) {
WorldVehicle * vehicle = *itr;
if (vehicle->currentTile.x == iCol && vehicle->currentTile.y == iRow) {
newvehicle = vehicle;
break;
}

itr++;
}

if (!newvehicle) {
newvehicle = new WorldVehicle();
newvehicle->currentTile.x = iCol;
newvehicle->currentTile.y = iRow;
vehiclelist.push_back(newvehicle);
}

newvehicle->iDrawSprite = g_wvVehicleStamp.iDrawSprite;
newvehicle->iActionId = g_wvVehicleStamp.iActionId;
newvehicle->iMinMoves = g_wvVehicleStamp.iMinMoves;
newvehicle->iMaxMoves = g_wvVehicleStamp.iMaxMoves;
newvehicle->fSpritePaces = g_wvVehicleStamp.fSpritePaces;
newvehicle->iDrawDirection = g_wvVehicleStamp.iDrawDirection;
newvehicle->iBoundary = g_wvVehicleStamp.iBoundary;
const auto it = std::find_if(vehiclelist.begin(), vehiclelist.end(),
[iCol, iRow](WorldVehicle* vehicle) {
return vehicle->currentTile.x == iCol && vehicle->currentTile.y == iRow;
});

WorldVehicle* newvehicle = (it != vehiclelist.cend())
? *it
: vehiclelist.emplace_back(new WorldVehicle(g_wvVehicleStamp));
newvehicle->SetPosition(iCol, iRow);
}

void RemoveVehicleFromTile(short iCol, short iRow)
Expand Down

0 comments on commit 429b53a

Please sign in to comment.