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
74 changes: 74 additions & 0 deletions src/OpenSHC/Map/Entities/AFireSpreadFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#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/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 0x004054E0
void Entities::AFireSpreadFunction(int playerID, int x, int y, int height, int fireStrength, int fireIntensity)
{
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;
if (tileX > 399 || tileY > 399
|| DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * 400 + tileX] == 0) {
return;
}
int const tile = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + tileX;
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;
}
if (DAT_TileMapState::instance.LogicLayer[tile]
& (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE | LogicHelpers::L_ROCKY
| LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_RIVER | LogicHelpers::L_FORD
| LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP
| LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_KEEP_NON_MANOR_HOUSE)) {
return;
}
short const buildingID = DAT_TileMapState::instance.BuildingLayer[tile];
if (buildingID != 0
&& !MACRO_CALL_MEMBER(Buildings::BuildingsState_Func::lightUpBuilding, DAT_BuildingsState::ptr)(
buildingID, playerID, fireIntensity)) {
return;
}
if ((DAT_TileMapState::instance.LogicLayer[tile] & LogicHelpers::L_TREE)
&& !MACRO_CALL_MEMBER(LandscapeState_Func::lightUpTree, DAT_LandscapeState::ptr)(tile, playerID)) {
return;
}
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 (newFireID != 0) {
DAT_EntityState::instance.entityArray[newFireID].fireParameter_0xb6 = fireStrength;
DAT_EntityState::instance.entityArray[newFireID].fireIntensity = fireIntensity;
}
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);
}
}

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

#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00401380
void EntityState::drawEntityEffect(int entityID, undefined4 entityType, int graphicType1, int graphicType2)
{
this->entityArray[entityID].entityType = (EntityTypeShort)entityType;
this->entityArray[entityID].graphicType2 = graphicType2;
this->entityArray[entityID].gmID = (short)graphicType1;
this->entityArray[entityID].originX
= (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[(short)graphicType1]
.originX;
this->entityArray[entityID].originY
= (short)DAT_TextureRenderCoreObject::instance.gmFileHeaderColorpaletteArray[(short)graphicType1]
.originY;
this->entityArray[entityID].unkOne_1 = (short)DAT_EntityDefinedData::instance.field_0x8b0;
this->entityArray[entityID].unkThree_1 = (short)DAT_EntityDefinedData::instance.field_0x7f8;
if (graphicType1 == 135) {
this->entityArray[entityID].unkOne_1 = 1;
this->entityArray[entityID].unkThree_1 = 3;
}
}

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

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00403790
void EntityState::initializeSeagullMovementVector(int seagullID, int x, int y, int targetX, int targetY)
{
int distanceY;
if (y > targetY) {
distanceY = y - targetY;
} else {
distanceY = targetY - y;
}
int distanceX;
if (x > targetX) {
distanceX = x - targetX;
} else {
distanceX = targetX - x;
}
if (x > targetX) {
this->seagullArray[seagullID].pathStepX = -1;
} else {
this->seagullArray[seagullID].pathStepX = 1;
}
if (y > targetY) {
this->seagullArray[seagullID].pathStepY = -1;
} else {
this->seagullArray[seagullID].pathStepY = 1;
}
if (distanceX == 0) {
if (distanceY == 0) {
this->seagullArray[seagullID].pathAxisCase = 0;
} else {
this->seagullArray[seagullID].pathAxisCase = 1;
}
} else if (distanceY == 0) {
this->seagullArray[seagullID].pathAxisCase = 2;
} else if (distanceY > distanceX) {
this->seagullArray[seagullID].pathAxisCase = 3;
} else {
this->seagullArray[seagullID].pathAxisCase = 4;
}
int majorLength;
if (distanceX > distanceY) {
majorLength = distanceX;
} else {
majorLength = distanceY;
}
this->seagullArray[seagullID].pathMajorLength = majorLength;
if (this->seagullArray[seagullID].pathAxisCase == 3) {
int const errorStep = distanceX * 2;
this->seagullArray[seagullID].pathErrorStepStraight = errorStep;
this->seagullArray[seagullID].pathErrorStepDiagonal = errorStep - distanceY * 2;
this->seagullArray[seagullID].pathError = errorStep - distanceY;
} else if (this->seagullArray[seagullID].pathAxisCase == 4) {
int const errorStep = distanceY * 2;
this->seagullArray[seagullID].pathErrorStepStraight = errorStep;
this->seagullArray[seagullID].pathErrorStepDiagonal = errorStep - distanceX * 2;
this->seagullArray[seagullID].pathError = errorStep - distanceX;
}
}

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

#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x004012F0
void EntityState::setEntityParameters(int entityID, undefined4 entityType, int gmLookupValue)
{
this->entityArray[entityID].entityType = (EntityTypeShort)entityType;
this->entityArray[entityID].gmLookupValue = (short)gmLookupValue;
this->entityArray[entityID].gmID = (short)DAT_EntityDefinedData::instance.EntityGmIDs[gmLookupValue];
this->entityArray[entityID].graphicType2RelatedOffset
= (short)DAT_EntityDefinedData::instance.EntityGraphicOffsets[gmLookupValue];
this->entityArray[entityID].originX = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID]
.originX;
this->entityArray[entityID].originY = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID]
.originY;
this->entityArray[entityID].unkOne_1 = (short)DAT_EntityDefinedData::instance.field_0x8a4[gmLookupValue];
this->entityArray[entityID].unkThree_1 = (short)DAT_EntityDefinedData::instance.field_0x7ec[gmLookupValue];
if (gmLookupValue == 1) {
this->entityArray[entityID].unkThree_1 = 5;
this->entityArray[entityID].unkOne_1 = 3;
this->entityArray[entityID].unkMinusOne = 16;
}
}

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

#include "OpenSHC/Globals/DAT_EntityDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x004011D0
void EntityState::setProjectileEntityValues2(int entityID, EntityType entityType)
{
this->entityArray[entityID].entityType = (EntityTypeShort)entityType;
this->entityArray[entityID].gmID = (short)DAT_EntityDefinedData::instance.EntityPropertyArray_1[entityType];
this->entityArray[entityID].graphicType2RelatedOffset
= (short)DAT_EntityDefinedData::instance.EntityPropertyArray_2[entityType];
this->entityArray[entityID].originX = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID]
.originX;
this->entityArray[entityID].originY = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->entityArray[entityID].gmID]
.originY;
this->entityArray[entityID].unkOne_1
= (short)DAT_EntityDefinedData::instance.EntityPropertyArray_3[entityType];
int const curveType = DAT_EntityDefinedData::instance.EntityArrayCurveTypeForProjectileType[entityType];
if (curveType != 0 && curveType != 6 && curveType != 9) {
this->entityArray[entityID].startingAngle
= (short)DAT_EntityDefinedData::instance.EntityArrayProjectileVelocityForProjectileType[entityType];
} else {
this->entityArray[entityID].velocityUnk
= (short)DAT_EntityDefinedData::instance.EntityArrayProjectileVelocityForProjectileType[entityType];
}
this->entityArray[entityID]._elapsedTimeOrGravityAccumulator
= DAT_EntityDefinedData::instance.ProjectileGravityPerEntityType[entityType];
this->entityArray[entityID].field_0x5a
= (short)DAT_EntityDefinedData::instance.field_0x2ac[entityType - 10];
this->entityArray[entityID].gmLookupValue
= (short)DAT_EntityDefinedData::instance.field_0x75c[entityType - 10];
switch (entityType) {
case 11:
this->entityArray[entityID].originX += -1;
this->entityArray[entityID].originY += -2;
break;
case 12:
this->entityArray[entityID].originX += 8;
this->entityArray[entityID].originY += -8;
break;
case 13:
this->entityArray[entityID].originX += 8;
this->entityArray[entityID].originY += -7;
break;
case 10:
case 14:
case 15:
this->entityArray[entityID].originX += -1;
this->entityArray[entityID].originY += -7;
break;
}
}

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

#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp"

#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp"

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00405CF0
void EntityState::setProjectileTargetPosition(
int entityID, int x, int y, int height, int targetX, int targetY, int targetZ)
{
this->entityArray[entityID].microX = x;
this->entityArray[entityID].x_2 = x;
this->entityArray[entityID].microY = y;
this->entityArray[entityID].y_2 = y;
this->entityArray[entityID].height = height;
this->entityArray[entityID].startingHeight_2 = height;
this->entityArray[entityID].height_2 = height;
this->entityArray[entityID].startingHeight = height;
this->entityArray[entityID].targetX = targetX;
this->entityArray[entityID].targetY = targetY;
this->entityArray[entityID].targetZ = targetZ;
this->entityArray[entityID].heightDifference = targetZ - height;
MACRO_CALL_MEMBER(Navigation::DirectionAlgorithmState_Func::somethingWithProjectileDistance,
DAT_DirectionAlgorithmState::ptr)(x, y, targetX, targetY);
this->entityArray[entityID].orientation = DAT_DirectionAlgorithmState::instance.orientation;
MACRO_CALL_MEMBER(EntityState_Func::initializeProjectileVelocities, this)(
entityID, x, y, height, targetX, targetY, targetZ);
}

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

namespace OpenSHC {
namespace Map {
namespace Entities {

// FUNCTION: STRONGHOLDCRUSADER 0x00402AE0
void EntityState::updateEntityMicroMovement(int entityID)
{
if (this->entityArray[entityID].entityType == 29 && this->entityArray[entityID].targetZ == 0
&& this->entityArray[entityID].microX == this->entityArray[entityID].targetX
&& this->entityArray[entityID].microY == this->entityArray[entityID].targetY) {
return;
}
switch (this->entityArray[entityID].pathAxisCase) {
case 0:
return;
case 2:
this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX;
break;
case 1:
this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY;
break;
case 4:
if (this->entityArray[entityID].pathError > 0) {
this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX;
this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY;
this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepDiagonal;
} else {
this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX;
this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepStraight;
}
break;
case 3:
if (this->entityArray[entityID].pathError > 0) {
this->entityArray[entityID].microX += this->entityArray[entityID].someMicroX;
this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY;
this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepDiagonal;
} else {
this->entityArray[entityID].microY += this->entityArray[entityID].someMicroY;
this->entityArray[entityID].pathError += this->entityArray[entityID].pathErrorStepStraight;
}
break;
}
}

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

#include "OpenSHC/Globals/DAT_CurrentEntityID.hpp"
#include "OpenSHC/Globals/DAT_EntityState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x00401BA0
void Entities::UpdateArrowEntity()
{
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2
= DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rotationFrameIndex * 16
+ DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].graphicType2RelatedOffset
+ DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].screenDirection;
if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround != 0) {
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround -= 1;
if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].rng_2 != 0) {
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround = 0;
}
if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].someCounter_OR_hitGround <= 0) {
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7;
}
}
if (DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation == 76) {
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].orientation = 60;
DAT_EntityState::instance.entityArray[DAT_CurrentEntityID::instance].logicalState = 7;
}
}

}
}
Loading
Loading