Skip to content

Commit

Permalink
Update stratModelsHelper.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 3, 2024
1 parent c6aec26 commit 10533a9
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions M2TWEOP Code/M2TWEOP library/stratModelsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,27 @@ namespace stratModelsChange
return newMod;
}


bool isVanillaCultureWatchtower(const DWORD addr)
{
const auto cultureDb = cultures::getCultureDb();
const auto cultureCount = cultureDb->culturesCount;
for (int i = 0; i < cultureCount; i++)
{
const auto culture = &cultureDb->cultures[i];
if (reinterpret_cast<DWORD>(&culture->watchTower) == addr)
return true;
}
return false;
}

void changeWatchTowerStratModel(watchTowerStruct* tower, model_Rigid* modelP)
{
if (tower->model->model == modelP)
return;

tower->model = newCasEntry(tower->model);

if (isVanillaCultureWatchtower(reinterpret_cast<DWORD>(tower->model)))
tower->model = newCasEntry(tower->model);
tower->model->model = modelP;
}
void changeResourceStratModel(resourceStruct* resource, model_Rigid* modelP)
Expand Down Expand Up @@ -103,19 +118,53 @@ namespace stratModelsChange
}
fort->stratModel = newMod;
}


bool isVanillaCulturePort(const DWORD addr)
{
const auto cultureDb = cultures::getCultureDb();
const auto cultureCount = cultureDb->culturesCount;
for (int i = 0; i < cultureCount; i++)
{
const auto culture = &cultureDb->cultures[i];
for (auto& portBuilding : culture->portBuildings)
{
if (reinterpret_cast<DWORD>(&portBuilding) == addr)
return true;
}
}
return false;
}

bool isVanillaCulturePortDock(const DWORD addr)
{
const auto cultureDb = cultures::getCultureDb();
const auto cultureCount = cultureDb->culturesCount;
for (int i = 0; i < cultureCount; i++)
{
const auto culture = &cultureDb->cultures[i];
for (auto& portBuilding : culture->portWalls)
{
if (reinterpret_cast<DWORD>(&portBuilding) == addr)
return true;
}
}
return false;
}

void changePortStratModel(portBuildingStruct* port, model_Rigid* modelP, model_Rigid* modelP2)
{
if (!port->portDock && port->portStratModel->model == modelP)
return;
if (port->portDock && port->portDock->dockStratModel->model == modelP2 && port->portStratModel->model == modelP)
return;
port->portStratModel = newCasEntry(port->portStratModel);
return;
if (isVanillaCulturePort(reinterpret_cast<DWORD>(port->portStratModel)))
port->portStratModel = newCasEntry(port->portStratModel);
port->portStratModel->model = modelP;

if (port->portDock->dockStratModel->model == modelP2)
return;
port->portDock->dockStratModel = newCasEntry(port->portStratModel);
if (isVanillaCulturePortDock(reinterpret_cast<DWORD>(port->portDock->dockStratModel)))
port->portDock->dockStratModel = newCasEntry(port->portDock->dockStratModel);
port->portDock->dockStratModel->model = modelP2;
}

Expand Down

0 comments on commit 10533a9

Please sign in to comment.