Skip to content

Commit

Permalink
Implements initial ScenarioClass extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Sep 15, 2021
1 parent 444841e commit 3eb9620
Show file tree
Hide file tree
Showing 6 changed files with 568 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/extensions/saveload/saveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "rulesext.h"
#include "sessionext.h"
#include "scenarioext.h"
#include "tacticalext.h"

#include "objecttypeext.h"
Expand Down Expand Up @@ -89,6 +90,7 @@ unsigned ViniferaSaveGameVersion =
*/
+ sizeof(RulesClassExtension)
+ sizeof(SessionClassExtension)
+ sizeof(ScenarioClassExtension)
+ sizeof(TacticalExtension)

/**
Expand Down Expand Up @@ -327,6 +329,38 @@ static bool Vinifera_Load_SessionExtension(IStream *pStm)
}


static bool Vinifera_Save_ScenarioExtension(IStream *pStm)
{
if (!pStm) {
return false;
}

if (!ScenarioExtension) {
return false;
}

ScenarioExtension->Save(pStm, true);

return true;
}


static bool Vinifera_Load_ScenarioExtension(IStream *pStm)
{
if (!pStm) {
return false;
}

if (!ScenarioExtension) {
return false;
}

ScenarioExtension->Load(pStm);

return true;
}


static bool Vinifera_Save_TacticalExtension(IStream *pStm)
{
if (!pStm) {
Expand Down Expand Up @@ -477,6 +511,12 @@ bool Vinifera_Put_All(IStream *pStm)
return false;
}

DEBUG_INFO("Saving ScenarioExtension\n");
if (!Vinifera_Save_ScenarioExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
return false;
}

DEBUG_INFO("Saving TacticalExtension\n");
if (!Vinifera_Save_TacticalExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
Expand Down Expand Up @@ -761,6 +801,12 @@ bool Vinifera_Load_All(IStream *pStm)
return false;
}

DEBUG_INFO("Loading ScenarioExtension\n");
if (!Vinifera_Load_ScenarioExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
return false;
}

DEBUG_INFO("Loading TacticalExtension\n");
if (!Vinifera_Load_TacticalExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
Expand Down
173 changes: 173 additions & 0 deletions src/extensions/scenario/scenarioext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file SCENARIOEXT.CPP
*
* @author CCHyper
*
* @brief Extended ScenarioClass class.
*
* @license Vinifera is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* Vinifera is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "scenarioext.h"
#include "asserthandler.h"
#include "debughandler.h"


ScenarioClassExtension *ScenarioExtension = nullptr;


/**
* Class constructor.
*
* @author: CCHyper
*/
ScenarioClassExtension::ScenarioClassExtension(ScenarioClass *this_ptr) :
Extension(this_ptr)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension constructor - 0x%08X\n", (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("ScenarioClassExtension constructor - 0x%08X\n", (uintptr_t)(ThisPtr));

/**
* This copies the behavior of the games ScenarioClass.
*/
Init_Clear();

IsInitialized = true;
}


/**
* Class no-init constructor.
*
* @author: CCHyper
*/
ScenarioClassExtension::ScenarioClassExtension(const NoInitClass &noinit) :
Extension(noinit)
{
IsInitialized = false;
}


/**
* Class deconstructor.
*
* @author: CCHyper
*/
ScenarioClassExtension::~ScenarioClassExtension()
{
//DEV_DEBUG_TRACE("ScenarioClassExtension deconstructor - 0x%08X\n", (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("ScenarioClassExtension deconstructor - 0x%08X\n", (uintptr_t)(ThisPtr));

IsInitialized = false;
}


/**
* Initializes an object from the stream where it was saved previously.
*
* @author: CCHyper
*/
HRESULT ScenarioClassExtension::Load(IStream *pStm)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Load - 0x%08X\n", (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Load(pStm);
if (FAILED(hr)) {
return E_FAIL;
}

new (this) ScenarioClassExtension(NoInitClass());

return hr;
}


/**
* Saves an object to the specified stream.
*
* @author: CCHyper
*/
HRESULT ScenarioClassExtension::Save(IStream *pStm, BOOL fClearDirty)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Save - 0x%08X\n", (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Save(pStm, fClearDirty);
if (FAILED(hr)) {
return hr;
}

return hr;
}


/**
* Return the raw size of class data for save/load purposes.
*
* @author: CCHyper
*/
int ScenarioClassExtension::Size_Of() const
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Size_Of - 0x%08X\n", (uintptr_t)(ThisPtr));

return sizeof(*this);
}


/**
* Removes the specified target from any targeting and reference trackers.
*
* @author: CCHyper
*/
void ScenarioClassExtension::Detach(TARGET target, bool all)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Detach - 0x%08X\n", (uintptr_t)(ThisPtr));

}


/**
* Compute a unique crc value for this instance.
*
* @author: CCHyper
*/
void ScenarioClassExtension::Compute_CRC(WWCRCEngine &crc) const
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Compute_CRC - 0x%08X\n", (uintptr_t)(ThisPtr));

}


/**
* Initialises any values for this instance.
*
* @author: CCHyper
*/
void ScenarioClassExtension::Init_Clear()
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("ScenarioClassExtension::Init - 0x%08X\n", (uintptr_t)(ThisPtr));

}
63 changes: 63 additions & 0 deletions src/extensions/scenario/scenarioext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file SCENARIOEXT.H
*
* @author CCHyper
*
* @brief Extended ScenarioClass class.
*
* @license Vinifera is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* Vinifera is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#pragma once

#include "extension.h"
#include "container.h"

#include "noinit.h"


class ScenarioClass;


class ScenarioClassExtension final : public Extension<ScenarioClass>
{
public:
ScenarioClassExtension(ScenarioClass *this_ptr);
ScenarioClassExtension(const NoInitClass &noinit);
~ScenarioClassExtension();

virtual HRESULT Load(IStream *pStm) override;
virtual HRESULT Save(IStream *pStm, BOOL fClearDirty) override;
virtual int Size_Of() const override;

virtual void Detach(TARGET target, bool all = true) override;
virtual void Compute_CRC(WWCRCEngine &crc) const override;

void Init_Clear();

public:

};


/**
* Global instance of the extended class.
*/
extern ScenarioClassExtension *ScenarioExtension;
7 changes: 7 additions & 0 deletions src/extensions/scenario/scenarioext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
*
******************************************************************************/
#include "scenarioext_hooks.h"
#include "scenarioext_init.h"
#include "scenarioext_functions.h"
#include "scenarioext.h"
#include "tibsun_globals.h"
#include "multiscore.h"
#include "scenario.h"
Expand Down Expand Up @@ -81,6 +83,11 @@ DECLARE_PATCH(_Do_Lose_Skip_MPlayer_Score_Screen_Patch)
*/
void ScenarioClassExtension_Hooks()
{
/**
* Initialises the extended class.
*/
ScenarioClassExtension_Init();

/**
* Hooks in the new Assign_Houses() function.
*
Expand Down
Loading

0 comments on commit 3eb9620

Please sign in to comment.