Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/OpenSHC/Global/DetectDXVersionByLoadingDDRAW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "../Global.func.hpp"

#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/IID_IDirectDraw7.hpp"

namespace OpenSHC {

typedef HRESULT(WINAPI* DirectDrawCreateExFunc)(GUID* guid, void** directDraw, REFIID iid, IUnknown* unkOuter);

// FUNCTION: STRONGHOLDCRUSADER 0x0046F4F0
Global::DirectDrawStatus Global::DetectDXVersionByLoadingDDRAW()
{
// "DDRAW.DLL"
HMODULE const ddrawModule = LoadLibraryA(s_DDRAW_DLL_005a61ec);
if (ddrawModule == NULL) {
return Rendering::Enums::DD7_NOT_LOADED;
}
IUnknown* directDraw;
// "DirectDrawCreate"
if (GetProcAddress(ddrawModule, s_DirectDrawCreate_005a61d8) == NULL) {
FreeLibrary(ddrawModule);
return Rendering::Enums::DD7_NOT_LOADED;
}
// "DirectDrawCreateEx"
DirectDrawCreateExFunc const directDrawCreateEx
= (DirectDrawCreateExFunc)GetProcAddress(ddrawModule, s_DirectDrawCreateEx_005a61c4);
if (directDrawCreateEx == NULL) {
FreeLibrary(ddrawModule);
return Rendering::Enums::DD7_NOT_LOADED;
}
if (directDrawCreateEx(NULL, (void**)&directDraw, IID_IDirectDraw7::instance, NULL) < 0) {
FreeLibrary(ddrawModule);
return Rendering::Enums::DD7_NOT_LOADED;
}
directDraw->Release();
FreeLibrary(ddrawModule);
return Rendering::Enums::DD7_LOADED;
}

}
25 changes: 25 additions & 0 deletions src/OpenSHC/Global/TestOSVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../Global.func.hpp"

namespace OpenSHC {

// FUNCTION: STRONGHOLDCRUSADER 0x0046F570
byte Global::TestOSVersion()
{
byte isSupported = 0;
OSVERSIONINFOEXA versionInfo;
memset(&versionInfo, 0, sizeof(versionInfo));
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
GetVersionExA((OSVERSIONINFOA*)&versionInfo);
if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && versionInfo.dwMajorVersion > 4) {
if (versionInfo.dwMajorVersion == 6) {
if (versionInfo.dwMinorVersion >= 2) {
isSupported = 1;
}
} else if (versionInfo.dwMajorVersion > 6) {
isSupported = 1;
}
}
return isSupported;
}

}
21 changes: 21 additions & 0 deletions src/OpenSHC/Map/Entities/EntityState/computeVelocity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "../EntityState.func.hpp"

#include "math.h"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00402DA0
int EntityState::computeVelocity(int param_2, double angleDegrees, int distance, int heightDifference)
{
double const angle = angleDegrees * 3.1415926535 / 180.0;
double const range = distance * 2;
double const cosAngle = cos(angle);
double const scaledGravity = 9.812 * range * range / (cosAngle * cosAngle);
return (int)sqrt(scaledGravity / (tan(angle) * range - heightDifference / 4));
}

}
}
}
85 changes: 85 additions & 0 deletions src/OpenSHC/Map/Entities/EntityState/createSeagull.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "../EntityState.func.hpp"

#include "OpenSHC/IO/LowLevelMemory.func.hpp"
#include "OpenSHC/Random/RNG.func.hpp"

#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp"
#include "OpenSHC/Globals/SEC_RNG.hpp"

#include "math.h"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00406650
int EntityState::createSeagull(int x, int y)
{
int seagullID = 1;
for (; seagullID < countof(this->seagullArray); ++seagullID) {
if (this->seagullArray[seagullID].field_0x8 == 0) {
break;
}
if (this->seagullArray[seagullID].entityUID
!= this->entityArray[this->seagullArray[seagullID].entityID].uid) {
MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)(
sizeof(this->seagullArray[seagullID]), 0, &this->seagullArray[seagullID]);
}
if (seagullID >= countof(this->seagullArray) - 1) {
return 0;
}
}
this->seagullArray[seagullID].field_0x8 = 2;
this->seagullArray[seagullID].field_0xa = 0;
this->seagullArray[seagullID].someCountDown = 0;
this->seagullArray[seagullID].x = x;
this->seagullArray[seagullID].x_2 = x;
this->seagullArray[seagullID].y = y;
this->seagullArray[seagullID].y_2 = y;
this->seagullArray[seagullID].angle = SEC_RNG::instance.currentNumber2 % 360;
this->seagullArray[seagullID].angle_2 = (char)(SEC_RNG::instance.currentNumber2 >> 8) % 360;
MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
this->seagullArray[seagullID].unknownCounter_0x16 = SEC_RNG::instance.currentNumber2 % 16 + 24;
this->seagullArray[seagullID].numberBetween60And100
= (char)(SEC_RNG::instance.currentNumber2 >> 8) % 40 + 60;
MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
if (SEC_RNG::instance.currentNumber2 & 1) {
this->seagullArray[seagullID].someAngle = 1;
} else {
this->seagullArray[seagullID].someAngle = -1;
}
if (SEC_RNG::instance.currentNumber2 & 2) {
this->seagullArray[seagullID].angleStep = 1;
} else {
this->seagullArray[seagullID].angleStep = -1;
}
double const angle = (this->seagullArray[seagullID].angle - 180) * 3.1415926535 / 180.0;
Comment thread
TheRedDaemon marked this conversation as resolved.
Resolved
this->seagullArray[seagullID].angle += this->seagullArray[seagullID].someAngle * 20;
// fixme: the original adds 360 when the angle is too big and subtracts it when it is negative
if (this->seagullArray[seagullID].angle >= 360) {
this->seagullArray[seagullID].angle += 360;
}
if (this->seagullArray[seagullID].angle < 0) {
this->seagullArray[seagullID].angle -= 360;
}
this->seagullArray[seagullID].field_0x1a = -20;
int const offsetX = (int)(sin(angle) * this->seagullArray[seagullID].unknownCounter_0x16);
int const offsetY = (int)(cos(angle) * this->seagullArray[seagullID].unknownCounter_0x16);
this->seagullArray[seagullID].rngMax799_countdown = 400;
this->seagullArray[seagullID].x_3 = x;
this->seagullArray[seagullID].y_3 = y;
MACRO_CALL_MEMBER(EntityState_Func::initializeSeagullMovementVector, this)(seagullID,
this->seagullArray[seagullID].x, this->seagullArray[seagullID].y, this->seagullArray[seagullID].x_3,
this->seagullArray[seagullID].y_3);
this->seagullArray[seagullID].pathStepDelay = 5;
this->seagullArray[seagullID].entityID = MACRO_CALL_MEMBER(EntityState_Func::spawnProjectileEntity, this)(
seagullID, 0, 0, x, y, 250, x + offsetX, y + offsetY, 250, ET_SEAGULLUnk, 0);
this->seagullArray[seagullID].entityUID = this->entityArray[this->seagullArray[seagullID].entityID].uid;
this->seagullArray[seagullID].randomNumber = SEC_RNG::instance.currentNumber2;
MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
return seagullID;
}

}
}
}
79 changes: 79 additions & 0 deletions src/OpenSHC/Map/Entities/SomeFireSpreadFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "../Entities.func.hpp"

#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp"
#include "OpenSHC/Map/Entities/EntityState.func.hpp"
#include "OpenSHC/Map/LandscapeState.func.hpp"
#include "OpenSHC/Random/RNG.func.hpp"
#include "OpenSHC/Map/LogicHelpers/Logic1.hpp"
#include "OpenSHC/Map/MapConstants.hpp"

#include "OpenSHC/Globals/DAT_BuildingsState.hpp"
#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp"
#include "OpenSHC/Globals/DAT_EntityState.hpp"
#include "OpenSHC/Globals/DAT_LandscapeState.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"
#include "OpenSHC/Globals/SEC_RNG.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x00405130
uint Entities::SomeFireSpreadFunction(int playerID, int x, int y, int height, int fireStrength)
{
int const random = SEC_RNG::instance.currentNumber2;
MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
x += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[random & 0x3f][0];
y += DAT_EntityDefinedData::instance.XYOffsetsInAllDirections[random & 0x3f][1];
uint const tileX = x / 8;
uint const tileY = y / 8;
bool const onMap = tileX <= MC_MAP_XY_LIMIT_INCLUSIVE && tileY <= MC_MAP_XY_LIMIT_INCLUSIVE
&& DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + tileX] != 0;
if (!onMap) {
return 0;
}
int const tile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX;
int const logic = DAT_TileMapState::instance.LogicLayer[tile];
if (logic
& (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE
| LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD
| LogicHelpers::L_KEEP_NON_MANOR_HOUSE)) {
return 0;
}
short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile];
if (buildingID != 0) {
int const buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType;
if (buildingType != Buildings::BT_TUNNEL && buildingType != Buildings::BT_KILLINGPIT
&& buildingType != Buildings::BT_UNKNOWN4) {
MACRO_CALL_MEMBER(Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)(
buildingID, playerID, 0);
return 0;
}
}
int const fireID
= MACRO_CALL_MEMBER(Entities::EntityState_Func::getFireEntityIDAtTile, DAT_EntityState::ptr)(tile);
if (fireID != 0) {
DAT_EntityState::instance.entityArray[fireID].someTracker = 0;
if (fireStrength > DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6) {
DAT_EntityState::instance.entityArray[fireID].fireParameter_0xb6 = fireStrength;
}
DAT_EntityState::instance.entityArray[fireID].unknownAnimationFrameRelated = 0;
return 0;
}
if (logic & LogicHelpers::L_TREE) {
MACRO_CALL_MEMBER(LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID);
}
uint const newFireID = MACRO_CALL_MEMBER(Entities::EntityState_Func::spawnProjectileEntity,
DAT_EntityState::ptr)(0, playerID, 0, x, y, height, 0, 0, 0, Entities::ET_FIRE, 0);
if (fireStrength >= 3 && (DAT_TileMapState::instance.RandomLayer[tile] & 3) == 0) {
MACRO_CALL_MEMBER(Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(
0, playerID, 0, x, y, height, 0, 0, 0, Entities::EntityTypeInt__ET_EXPLOSION, 0);
}
if (newFireID != 0) {
DAT_EntityState::instance.entityArray[newFireID].fireParameter_0xb6 = fireStrength;
}
return newFireID;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "../MapPropertiesState.func.hpp"

#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Text/UserTextHandler.func.hpp"
#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp"
#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x004BE590
void MapPropertiesState::setStartingYearAndStartingResources()
{
DAT_MapPropertiesState::instance.SEC_StartingYear = 1181;
DAT_GameState::instance.mapAndTime.year = 1181;
for (int i = 0; i < countof(DAT_MapPropertiesState::instance.SEC_StartingResources); ++i) {
DAT_MapPropertiesState::instance.SEC_StartingResources[i] = 0;
}
for (int i = 0; i < countof(DAT_MapPropertiesState::instance.SEC_Section1065.tradeabilityArray); ++i) {
DAT_MapPropertiesState::instance.SEC_Section1065.tradeabilityArray[i] = 1;
}
DAT_MapPropertiesState::instance.SEC_StartingMonth = 0;
DAT_GameState::instance.mapAndTime.month = 0;
DAT_MapPropertiesState::instance.eventsCount = 0;
// the siege information is a block of 20 unit counts
for (int i = 0; i < countof(DAT_MapPropertiesState::instance.SEC_SiegeInformation); ++i) {
DAT_MapPropertiesState::instance.SEC_SiegeInformation[i] = 0;
}
for (int i = 0; i < countof(DAT_MapPropertiesState::instance.SEC_Section1067.siegeEngineCounts); ++i) {
DAT_MapPropertiesState::instance.SEC_Section1067.siegeEngineCounts[i] = 0;
}
DAT_MapPropertiesState::instance.SEC_StartingPopularity = 100;
MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(10);
char yearText[12];
// "%d"
MACRO_CALL(OS_Func::_sprintf)(yearText, s__d_005aa7f0, DAT_MapPropertiesState::instance.SEC_StartingYear);
MACRO_CALL_MEMBER(Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(yearText);
DAT_MapPropertiesState::instance.eventListSelection = -1;
DAT_MapPropertiesState::instance.eventListScrollOffset = 0;
for (int i = 0; i < countof(this->buildingAvailability); ++i) {
this->buildingAvailability[i] = 1;
}
MACRO_CALL_MEMBER(MapPropertiesState_Func::commitBuildingAvailability, this)();
MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(9);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../MapPropertiesState.func.hpp"

#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Text/UserTextHandler.func.hpp"
#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp"
#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x004BEB20
void MapPropertiesState::updateEventYearsAndCommitBuildingAvailability()
{
if (DAT_MapPropertiesState::instance.SEC_StartingYear < 1000) {
DAT_MapPropertiesState::instance.SEC_StartingYear = 1181;
}
MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(10);
char yearText[12];
// "%d"
MACRO_CALL(OS_Func::_sprintf)(yearText, s__d_005aa7f0, this->SEC_StartingYear);
MACRO_CALL_MEMBER(Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)(yearText);
DAT_MapPropertiesState::instance.eventListSelection = -1;
DAT_MapPropertiesState::instance.eventListScrollOffset = 0;
this->year_copy = this->SEC_StartingYear;
for (int i = 0; i < this->eventsCount; ++i) {
if (DAT_GameState::instance.mapAndTime.year < this->scenarioEvents[i].header.year) {
continue;
}
if (DAT_GameState::instance.mapAndTime.year == this->scenarioEvents[i].header.year
&& DAT_GameState::instance.mapAndTime.month >= this->scenarioEvents[i].header.month) {
continue;
}
if (this->scenarioEvents[i].header.tl_type == 1
&& this->scenarioEvents[i].data.invasion.repeatMonths != 0) {
if (this->scenarioEvents[i].data.invasion.messageYear != 0) {
this->scenarioEvents[i].header.year = this->scenarioEvents[i].data.invasion.messageYear;
} else {
this->scenarioEvents[i].data.invasion.messageYear = this->scenarioEvents[i].header.year;
}
}
}
MACRO_CALL_MEMBER(MapPropertiesState_Func::commitBuildingAvailability, this)();
}

}
}
Loading
Loading