Skip to content

Commit

Permalink
Reduce dependence on MAX_FACTORY.
Browse files Browse the repository at this point in the history
Fixes some assertions on some maps.
  • Loading branch information
Cyp committed Dec 3, 2011
1 parent 8ee9e67 commit 9474ae3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 108 deletions.
2 changes: 1 addition & 1 deletion src/display3d.cpp
Expand Up @@ -2483,7 +2483,7 @@ void renderDeliveryPoint(FLAG_POSITION *psPosition, bool blueprint)
pie_TRANSLATE(dv.x,dv.y,dv.z);

//quick check for invalid data
ASSERT( psPosition->factoryType < NUM_FLAG_TYPES && psPosition->factoryInc < MAX_FACTORY, "Invalid assembly point" );
ASSERT_OR_RETURN(, psPosition->factoryType < NUM_FLAG_TYPES && psPosition->factoryInc < MAX_FACTORY_FLAG_IMDS, "Invalid assembly point");

if(!psPosition->selected && !blueprint)
{
Expand Down
5 changes: 5 additions & 0 deletions src/droid.cpp
Expand Up @@ -4281,6 +4281,11 @@ void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, unsigned player, Q
{
FACTORY *psFactory = &psStruct->pFunctionality->factory;

if (psFactory->psAssemblyPoint->factoryInc >= asProductionRun[psFactory->psAssemblyPoint->factoryType].size())
{
continue; // No production run to check.
}

ProductionRun &productionRun = asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc];
for (unsigned inc = 0; inc < productionRun.size(); ++inc)
{
Expand Down
8 changes: 7 additions & 1 deletion src/game.cpp
Expand Up @@ -4717,6 +4717,10 @@ static bool loadSaveStructure2(const char *pFileName, STRUCTURE **ppList)
currentProd.psTemplate = psTempl;
ASSERT(psTempl, "No template found for template ID %d for %s (%d)", tid, objInfo(psStructure), id);
}
if (psFactory->psAssemblyPoint->factoryInc >= asProductionRun[psFactory->psAssemblyPoint->factoryType].size())
{
asProductionRun[psFactory->psAssemblyPoint->factoryType].resize(psFactory->psAssemblyPoint->factoryInc + 1);
}
asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc].push_back(currentProd);
}
break;
Expand Down Expand Up @@ -4923,7 +4927,9 @@ bool writeStructFile(const char *pFileName)
ini.setValue("Factory/commander/player", psFactory->psCommander->player);
}
ini.setValue("Factory/secondaryOrder", psFactory->secondaryOrder);
ProductionRun &productionRun = asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc];
ProductionRun emptyRun;
bool haveRun = psFactory->psAssemblyPoint->factoryInc < asProductionRun[psFactory->psAssemblyPoint->factoryType].size();
ProductionRun const &productionRun = haveRun? asProductionRun[psFactory->psAssemblyPoint->factoryType][psFactory->psAssemblyPoint->factoryInc] : emptyRun;
ini.setValue("Factory/productionRuns", (int)productionRun.size());
for (int runNum = 0; runNum < productionRun.size(); runNum++)
{
Expand Down
9 changes: 4 additions & 5 deletions src/miscimd.cpp
Expand Up @@ -138,7 +138,7 @@ iIMDShape *getRandomDebrisImd( void )
}
// -------------------------------------------------------------------------------

iIMDShape *pAssemblyPointIMDs[NUM_FLAG_TYPES][MAX_FACTORY];
iIMDShape *pAssemblyPointIMDs[NUM_FLAG_TYPES][MAX_FACTORY_FLAG_IMDS];

static bool initMiscImd(unsigned i, unsigned n, const char *nameFormat, unsigned flagType)
{
Expand All @@ -156,17 +156,16 @@ static bool initMiscImd(unsigned i, unsigned n, const char *nameFormat, unsigned

bool initMiscImds( void )
{
unsigned i;

/* Do the new loading system */
multiLoadMiscImds();

/* Now load the multi array stuff */
for (i=0; i < MAX_FACTORY; i++)
for (unsigned i = 0; i < MAX_FACTORY_FLAG_IMDS; ++i)
{
unsigned n = i + 1;

STATIC_ASSERT(MAX_FACTORY <= 32); // Need to add more assembly point graphics, if increasing MAX_FACTORY.
STATIC_ASSERT(MAX_FACTORY <= MAX_FACTORY_FLAG_IMDS);
STATIC_ASSERT(MAX_FACTORY_FLAG_IMDS <= 32); // Need to add more assembly point graphics, if increasing MAX_FACTORY_FLAG_IMDS.
if (!initMiscImd(i, n, "minum%u.pie", FACTORY_FLAG) ||
!initMiscImd(i, n, "micnum%u.pie", CYBORG_FLAG) ||
!initMiscImd(i, n, "mivnum%u.pie", VTOL_FLAG) ||
Expand Down
4 changes: 2 additions & 2 deletions src/miscimd.h
Expand Up @@ -48,8 +48,8 @@ extern iIMDShape *waterImd;
extern iIMDShape *droidDamageImd;
extern iIMDShape *smallSteamImd;
extern iIMDShape *plasmaImd;
//extern iIMDShape *pAssemblyPointIMDs[NUM_FACTORY_TYPES][MAX_FACTORY];
extern iIMDShape *pAssemblyPointIMDs[NUM_FLAG_TYPES][MAX_FACTORY];
#define MAX_FACTORY_FLAG_IMDS 32
extern iIMDShape *pAssemblyPointIMDs[NUM_FLAG_TYPES][MAX_FACTORY_FLAG_IMDS];
extern iIMDShape *blipImd;
extern iIMDShape *shadowImd;
extern iIMDShape *transporterShadowImd;
Expand Down
38 changes: 15 additions & 23 deletions src/objmem.cpp
Expand Up @@ -46,10 +46,6 @@
#include "visibility.h"
#include "qtscript.h"

#ifdef DEBUG
static SDWORD factoryDeliveryPointCheck[MAX_PLAYERS][NUM_FLAG_TYPES][MAX_FACTORY];
#endif

// the initial value for the object ID
#define OBJ_ID_INIT 20000

Expand Down Expand Up @@ -700,38 +696,34 @@ void freeAllFlagPositions(void)
// check all flag positions for duplicate delivery points
void checkFactoryFlags(void)
{
FLAG_POSITION *psFlag;
SDWORD player, type, factory;
static std::vector<unsigned> factoryDeliveryPointCheck[NUM_FLAG_TYPES]; // Static to save allocations.

//clear the check array
for(player=0; player<MAX_PLAYERS; player++)
//check the flags
for (unsigned player = 0; player < MAX_PLAYERS; ++player)
{
//for(type=0; type<NUM_FACTORY_TYPES; type++)
for(type=0; type<NUM_FLAG_TYPES; type++)
//clear the check array
for (int type = 0; type < NUM_FLAG_TYPES; ++type)
{
for(factory=0; factory<MAX_FACTORY; factory++)
{
factoryDeliveryPointCheck[player][type][factory] = 0;
}
factoryDeliveryPointCheck[type].clear();
}
}

//check the flags
for(player=0; player<MAX_PLAYERS; player++)
{
psFlag = apsFlagPosLists[player];
FLAG_POSITION *psFlag = apsFlagPosLists[player];
while (psFlag)
{
if ((psFlag->type == POS_DELIVERY) &&//check this is attached to a unique factory
(psFlag->factoryType != REPAIR_FLAG))
{
type = psFlag->factoryType;
factory = psFlag->factoryInc;
ASSERT( factoryDeliveryPointCheck[player][type][factory] == 0,"DUPLICATE FACTORY DELIVERY POINT FOUND" );
factoryDeliveryPointCheck[player][type][factory] = 1;
unsigned type = psFlag->factoryType;
unsigned factory = psFlag->factoryInc;
factoryDeliveryPointCheck[type].push_back(factory);
}
psFlag = psFlag->psNext;
}
for (int type = 0; type < NUM_FLAG_TYPES; ++type)
{
std::sort(factoryDeliveryPointCheck[type].begin(), factoryDeliveryPointCheck[type].end());
ASSERT(std::unique(factoryDeliveryPointCheck[type].begin(), factoryDeliveryPointCheck[type].end()) == factoryDeliveryPointCheck[type].end(), "DUPLICATE FACTORY DELIVERY POINT FOUND");
}
}
}
#endif
Expand Down

0 comments on commit 9474ae3

Please sign in to comment.