Load player actor from DOS saved game

This commit is contained in:
ArnoAnsems committed 2022-08-08 22:56:31 +02:00
1 parent f05438a664
commit 01ffc131c6
5 files changed
+41 -1

No files matched your search

+2 -1
View File
@@ -3277,7 +3277,8 @@ void EngineCore::LoadDosGameFromFile(const std::string filename)
{
m_playerInventory.LoadFromDosGame(*savedGame);
UnloadLevel();
m_level = m_game.GetGameMaps()->GetLevelFromStart((uint8_t)savedGame->GetMapOn());
m_level = m_game.GetGameMaps()->GetLevelFromDosSavedGame(savedGame);
m_level->LoadActorsFromDosSavedGame(*savedGame, m_game.GetDecorateActors());
m_score.SetPoints(savedGame->GetScore());
// Information that is not stored in the DOS format is set to default values.
+20
View File
@@ -16,6 +16,7 @@
#include "GameMaps.h"
#include <fstream>
#include "Decompressor.h"
#include "SavedGameInDosFormat.h"
static const uint16_t MaxMapWidth = 128;
static const uint16_t MaxMapHeight = 128;
@@ -190,6 +191,25 @@ Level* GameMaps::GetLevelFromSavedGame(std::ifstream& file) const
return level;
}
Level* GameMaps::GetLevelFromDosSavedGame(const SavedGameInDosFormat* savedGameInDosFormat) const
{
Logging::Instance().AddLogMessage("Loading map " + savedGameInDosFormat->GetName() + " from DOS saved game");
const uint8_t mapIndex = (uint8_t)savedGameInDosFormat->GetMapOn();
// The dimensions of the map are retrieved from the GameMaps data
const uint8_t* headerStart = m_rawData->GetChunk() + m_staticData.offsets.at(mapIndex);
const uint16_t mapWidth = *(uint16_t*)(&(headerStart[18]));
const uint16_t mapHeight = *(uint16_t*)(&(headerStart[20]));
const uint16_t* plane0 = (const uint16_t*)savedGameInDosFormat->GetPlane0()->GetChunk();
const uint16_t* plane2 = (const uint16_t*)savedGameInDosFormat->GetPlane2()->GetChunk();
Level* level = new Level(mapIndex, mapWidth, mapHeight, plane0, plane2, m_staticData.mapsInfo.at(mapIndex), m_staticData.wallsInfo);
return level;
}
uint8_t GameMaps::GetNumberOfLevels() const
{
return (uint8_t)m_staticData.mapsInfo.size();
+3
View File
@@ -26,6 +26,8 @@
#include "Level.h"
#include "Logging.h"
class SavedGameInDosFormat;
const uint16_t wallSolid = 1;
const uint16_t wallSpecial = 2;
const uint16_t wallRequiresKey = 4;
@@ -48,6 +50,7 @@ public:
Level* GetLevelFromStart(const uint8_t mapIndex) const;
Level* GetLevelFromSavedGame(std::ifstream& file) const;
Level* GetLevelFromDosSavedGame(const SavedGameInDosFormat* savedGameInDosFormat) const;
uint8_t GetNumberOfLevels() const;
uint16_t GetTileWallExplosion(const bool isWaterLevel) const;
+14
View File
@@ -22,6 +22,7 @@
#include "RenderableAutoMapIso.h"
#include "Renderable3DScene.h"
#include "LevelLocationNames.h"
#include "SavedGameInDosFormat.h"
Level::Level(
const uint8_t mapIndex,
@@ -117,6 +118,19 @@ bool Level::LoadActorsFromFile(std::ifstream& file, const std::map<uint16_t, con
return true;
}
bool Level::LoadActorsFromDosSavedGame(const SavedGameInDosFormat& savedGameInDosFormat, const std::map<uint16_t, const DecorateActor>& decorateActors)
{
const SavedGameInDosFormat::ObjectInDosFormat& playerObject = savedGameInDosFormat.GetObject(0);
const float playerX = (float)playerObject.x / 65536.0f;
const float playerY = (float)playerObject.y / 65536.0f;
m_playerActor = new Actor(playerX, playerY, 0, decorateActors.at(11));
m_playerActor->SetAngle(playerObject.angle);
m_playerActor->SetHealth(savedGameInDosFormat.GetBody());
m_playerActor->SetTile(playerObject.tilex, playerObject.tiley);
return true;
}
bool Level::LoadFogOfWarFromFile(std::ifstream& file)
{
file.read((char*)m_fogOfWarMap, m_levelWidth * m_levelHeight * sizeof(m_fogOfWarMap[0]));
+2
View File
@@ -32,6 +32,7 @@
#include "RenderableAutoMapIso.h"
class EgaGraph;
class SavedGameInDosFormat;
struct LevelInfo
{
@@ -106,6 +107,7 @@ public:
const LevelInfo& mapInfo,
const std::vector<WallInfo>& wallsInfo);
bool LoadActorsFromFile(std::ifstream& file, const std::map<uint16_t, const DecorateActor>& decorateActors);
bool LoadActorsFromDosSavedGame(const SavedGameInDosFormat& savedGameInDosFormat, const std::map<uint16_t, const DecorateActor>& decorateActors);
bool LoadFogOfWarFromFile(std::ifstream& file);
~Level();