Skip to content

Commit

Permalink
another update (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 18, 2023
1 parent 20f3007 commit 0c67fa0
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 143 deletions.
55 changes: 54 additions & 1 deletion M2TWEOP Code/M2TWEOP library/realGameTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,17 @@ struct factionDiplomacy
int trade; /* trade rights(0 or 1) */
int protectorate; /* protectorate or not(15 or 6) */
float factionStanding; //0x0010
char pad_0014[116]; //0x0014
char pad_0014[4]; //0x0014
int32_t numTurnsAllied; //0x0018
int32_t numTurnsWar; //0x001C
int32_t numTurnsPeace; //0x0020
int32_t numTurnsTrade; //0x0024
int32_t numTurnsAccess; //0x0028
char pad_002C[72]; //0x002C
int32_t turnsSinceMapInfoGiven; //0x0074 -no start at 0 but like 10 on campaign start
char pad_0078[8]; //0x0078
int32_t turnsSinceMapInfoTaken; //0x0080 -no start at 0 but like 10 on campaign start
int32_t numTurnsCeasefire; //0x0084
}; //Size: 0x0088

struct trackedCharacter
Expand Down Expand Up @@ -2878,6 +2888,49 @@ struct recruitRome
};


struct militaryValuesLTGD
{
int32_t totalPopulation; //0x0000
int32_t tileCount; //0x0004
int32_t averagePopulation; //0x0008
int32_t productionValue; //0x000C
int32_t nonAlliedBorderLength; //0x0010
int32_t enemyBorderLength; //0x0014
int32_t fleetCount; //0x0018
int32_t navalPowerPerFleet; //0x001C
int32_t navalStrength; //0x0020
int32_t armyCount; //0x0024
int32_t strengthPerArmy; //0x0028
int32_t totalStrength; //0x002C
int32_t freeStrength; //0x0030
int32_t neighbourEnemyNum; //0x0034
int32_t enemyStrength; //0x0038
int32_t protectorateOf; //0x003C
};

struct strategyValuesLTGD
{
int32_t borderTiles; //0x0000
int32_t frontLineBalance; //0x0004
int8_t hasAllianceAgainst; //0x0008
int8_t isStrongestNeighbour; //0x0009
int8_t isWeakestNeighbour; //0x000A
char pad_000B[1]; //0x000B

};

struct dataLTGD
{
public:
struct factionStruct *currentFaction; //0x0000
char pad_0004[8]; //0x0004
uint32_t N00024EDA; //0x000C
char pad_0010[4]; //0x0010
struct militaryValuesLTGD militaryValuesLTGD[31]; //0x0014
struct strategyValuesLTGD strategyValuesLTGD[31][31]; //0x07D4
};


struct decisionValuesLTGD
{
public:
Expand Down
6 changes: 3 additions & 3 deletions M2TWEOP-luaPlugin/luaPlugin/basicFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ class basicFuncs
ProcLoader<void(__cdecl*)(general*, general*)> attackCharacter;


ProcLoader<int(__cdecl*)(namedCharacter*, anchillary*)> addAnchillary;
ProcLoader<void(__cdecl*)(namedCharacter*, anchillary*)> removeAnchillary;
ProcLoader<anchillary* (__cdecl*)(char*)> findAnchillary;
ProcLoader<int(__cdecl*)(namedCharacter*, ancillary*)> addAncillary;
ProcLoader<void(__cdecl*)(namedCharacter*, ancillary*)> removeAncillary;
ProcLoader<ancillary* (__cdecl*)(char*)> findAncillary;

ProcLoader<void(__cdecl*)(namedCharacter*, const char*, int)> addTrait;
ProcLoader<void(__cdecl*)(namedCharacter*, const char*)> removeTrait;
Expand Down
111 changes: 111 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/gameHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,61 @@ namespace gameHelpers

oneTile* getRegionSeaEdge(const regionStruct* region, const int index)
{
if (index >= region->regionSeaEdgesCount)
return nullptr;
gameDataAllStruct* gameDataAll = gameDataAllHelper::get();
stratMap* map = gameDataAll->stratMap;

return &map->tilesArr[region->regionSeaEdges[index]];
}

oneTile* getDevastatedTile(const regionStruct* region, const int index)
{
if (index >= region->devastatedTilesCount)
return nullptr;
gameDataAllStruct* gameDataAll = gameDataAllHelper::get();
stratMap* map = gameDataAll->stratMap;

return &map->tilesArr[region->devastatedTiles[index]];
}

int getHostileArmiesStrength(const regionStruct* region, const int factionID)
{
return region->armiesHostileToArrayIndexIDStrength[factionID];
}

bool isDevastated(const oneTile* tile)
{
return tile->hasRoad & 1;
}

oneTileDouble* tileToDoubleTile(const oneTile* tile)
{
gameDataAllStruct* gameDataAll = gameDataAllHelper::get();
stratMap* map = gameDataAll->stratMap;
int mapWidth = map->mapWidth * 2 + 1;
auto coords = getTileCoords(tile);
return &map->climateTileArray[(coords->yCoord * 2) * mapWidth + (coords->xCoord * 2)];
}

float getTileHeight(const oneTile* tile)
{
return tileToDoubleTile(tile)->height;
}

int getTileClimate(const oneTile* tile)
{
return tileToDoubleTile(tile)->climate;
}

int getTileHeatValue(const oneTile* tile)
{
gameDataAllStruct* gameDataAll = gameDataAllHelper::get();
stratMap* map = gameDataAll->stratMap;
auto climate = tileToDoubleTile(tile)->climate;
return map->climates->climateArray[climate].heatValue;
}

float getReligionHistory(const regionStruct* region, const int religionID, int turnsAgo)
{
if (turnsAgo > 19)
Expand Down Expand Up @@ -874,6 +923,68 @@ namespace gameHelpers
return region->resourceTypesBitMap & (1 << resourceType);
}

/*
strategy map object types
0 -> 27 = resource ID
28 = character
29 = settlement
30 = fort
31 = port
32 = watchTower
33 = sundry
34 = rally point
35 = floatingGeneral
36 = battleSiteMarker
*/

DWORD* getTileObject(const oneTile* tile, int type)
{
DWORD* object = tile->object;

while (object)
{
int objectType = CallVFunc<4, int>(object);
if (objectType == type || (type == 0 && objectType < 28))
return object;
object = reinterpret_cast<DWORD*>(*(object + 1));
}

return nullptr;
}

resStrat* getTileResource(const oneTile* tile)
{
return reinterpret_cast<resStrat*>(getTileObject(tile, 0));
}

general* getTileCharacter(const oneTile* tile)
{
return reinterpret_cast<general*>(getTileObject(tile, 28));
}

settlementStruct* getTileSettlement(const oneTile* tile)
{
return reinterpret_cast<settlementStruct*>(getTileObject(tile, 29));
}

fortStruct* getTileFort(const oneTile* tile)
{
return reinterpret_cast<fortStruct*>(getTileObject(tile, 30));
}

portBuildingStruct* getTilePort(const oneTile* tile)
{
return reinterpret_cast<portBuildingStruct*>(getTileObject(tile, 31));
}

watchTowerStruct* getTileWatchtower(const oneTile* tile)
{
return reinterpret_cast<watchTowerStruct*>(getTileObject(tile, 32));
}






}
14 changes: 14 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/gameHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,32 @@ namespace gameHelpers
bool tileHasSettlement(const oneTile* tile);
bool factionHasArmyNearTile(const oneTile* tile, int factionID);
bool factionHasCharacterOnTile(const oneTile* tile, int factionID);
int getHostileArmiesStrength(const regionStruct* region, const int factionID);
coordPair* convertTileCoords(DWORD arrayIndex);
coordPair* getTileCoords(const oneTile* tile);
seaConnectedRegion* getSeaConnectedRegion(const regionStruct* region, const int index);
seaConnectedRegion* getSeaImportRegion(const regionStruct* region, const int index);
oneTile* getRegionSeaEdge(const regionStruct* region, const int index);
oneTile* getDevastatedTile(const regionStruct* region, const int index);
float getReligionHistory(const regionStruct* region, const int religionID, int turnsAgo);
oneTile* getTileBorderingEdgeOfMap(const regionStruct* region, const int index);
oneTile* getTileRegion(const regionStruct* region, const int index);
oneTile* getFertileTile(const regionStruct* region, const int index);
bool hasResourceType(const regionStruct* region, const int resourceType);
oneTile* getReachableTile(const seaConnectedRegion* region, int index);
coordPair* getTradeLaneCoord(const seaConnectedRegion* region, int index);
bool isDevastated(const oneTile* tile);
oneTileDouble* tileToDoubleTile(const oneTile* tile);
float getTileHeight(const oneTile* tile);
int getTileClimate(const oneTile* tile);
int getTileHeatValue(const oneTile* tile);
DWORD* getTileObject(const oneTile* tile, int type);
resStrat* getTileResource(const oneTile* tile);
general* getTileCharacter(const oneTile* tile);
settlementStruct* getTileSettlement(const oneTile* tile);
fortStruct* getTileFort(const oneTile* tile);
portBuildingStruct* getTilePort(const oneTile* tile);
watchTowerStruct* getTileWatchtower(const oneTile* tile);

int getMercUnitNum(mercPool* mercPool);
mercPoolUnit* getMercUnit(mercPool* pool, int index);
Expand Down
16 changes: 8 additions & 8 deletions M2TWEOP-luaPlugin/luaPlugin/generalCharactericticsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ namespace generalCharactericticsHelpers
{
return character->traits;
}
anchillary* getAnchillary(namedCharacter* character, int index)
ancillary* getAncillary(namedCharacter* character, int index)
{
return character->anchillaries[index]->dataAnch;
return character->ancillaries[index]->dataAnc;

}
int addAnchillary(namedCharacter* character, std::string anchName)
int addAncillary(namedCharacter* character, std::string ancName)
{
anchillary* anch = (*(*plugData::data.funcs.findAnchillary))((char*)anchName.c_str());
if (anch == nullptr)return 0;
ancillary* anc = (*(*plugData::data.funcs.findAncillary))((char*)ancName.c_str());
if (anc == nullptr)return 0;

return (*(*plugData::data.funcs.addAnchillary))(character, anch);
return (*(*plugData::data.funcs.addAncillary))(character, anc);
}
void removeAnchillary(namedCharacter* character, anchillary* anch)
void removeAncillary(namedCharacter* character, ancillary* anc)
{
(*(*plugData::data.funcs.removeAnchillary))(character, anch);
(*(*plugData::data.funcs.removeAncillary))(character, anc);
}
void addTrait(namedCharacter* character, const char* traitName, int traitLevel)
{
Expand Down
6 changes: 3 additions & 3 deletions M2TWEOP-luaPlugin/luaPlugin/generalCharactericticsHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace generalCharactericticsHelpers
{
traitContainer* getTraits(namedCharacter* character);
anchillary* getAnchillary(namedCharacter* character, int index);
int addAnchillary(namedCharacter* character, std::string anchName);
ancillary* getAncillary(namedCharacter* character, int index);
int addAncillary(namedCharacter* character, std::string ancName);

void removeAnchillary(namedCharacter* character, anchillary* anch);
void removeAncillary(namedCharacter* character, ancillary* anc);


void addTrait(namedCharacter* character, const char* traitName, int traitLevel);
Expand Down
28 changes: 14 additions & 14 deletions M2TWEOP-luaPlugin/luaPlugin/luaGetSetFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define EduEntryStruct_InfoCardTga 4


#define anchillaryStruct_name 1
#define anchillaryStruct_imagePath 2
#define ancillaryStruct_name 1
#define ancillaryStruct_imagePath 2
#include <string>
#include "realGameTypes.h"
namespace luaGetSetFuncs
Expand All @@ -35,19 +35,19 @@ namespace luaGetSetFuncs



#pragma region anchillary
//anchillary
#pragma region ancillary
//ancillary
template <char fieldIndex>
std::string getStringPropertyAnc(const anchillary* anch)
std::string getStringPropertyAnc(const ancillary* anc)
{
char* retS = nullptr;
if (fieldIndex == anchillaryStruct_name)
if (fieldIndex == ancillaryStruct_name)
{
retS = anch->anchName;
retS = anc->ancName;
}
else if (fieldIndex == anchillaryStruct_imagePath)
else if (fieldIndex == ancillaryStruct_imagePath)
{
retS = anch->patchToAnchImage;
retS = anc->patchToAncImage;
}

if (retS != nullptr)
Expand All @@ -61,18 +61,18 @@ namespace luaGetSetFuncs
}

template <char fieldIndex>
void setStringPropertyAnc(anchillary* anch, std::string newS)
void setStringPropertyAnc(ancillary* anc, std::string newS)
{
char* arg = nullptr;
if (fieldIndex == anchillaryStruct_name)
if (fieldIndex == ancillaryStruct_name)
{

arg = reinterpret_cast<char*>(&anch->anchName);
arg = reinterpret_cast<char*>(&anc->ancName);
}
else if (fieldIndex == anchillaryStruct_imagePath)
else if (fieldIndex == ancillaryStruct_imagePath)
{

arg = reinterpret_cast<char*>(&anch->patchToAnchImage);
arg = reinterpret_cast<char*>(&anc->patchToAncImage);
}
setGameString(arg, newS.c_str());
}
Expand Down
Loading

0 comments on commit 0c67fa0

Please sign in to comment.