Cleanup. Fix indentation. Use enum on structure types to help prevent bugs like

the satlink bug from creeping back in.


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1736 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2007-05-28 21:44:52 +00:00
parent 1cc2b86251
commit 34b1ca108f
10 changed files with 97 additions and 235 deletions

View File

@ -236,78 +236,6 @@ BOOL actionInsideMinRange(DROID *psDroid, BASE_OBJECT *psObj, int weapon_slot)
}
/* Find a new location by a structure when building */
/*static BOOL actionNewBuildPos(DROID *psDroid, UDWORD *pX, UDWORD *pY)
{
//STRUCTURE_STATS *psStructStats;
BASE_STATS *psStats;
// get the structure stats
switch (psDroid->action)
{
case DACTION_MOVETOBUILD:
case DACTION_FOUNDATION_WANDER:
if ( psDroid->order == DORDER_BUILD || psDroid->order == DORDER_LINEBUILD )
{
//psStructStats = (STRUCTURE_STATS *)psDroid->psTarStats;
psStats = psDroid->psTarStats;
}
else
{
ASSERT( psDroid->order == DORDER_HELPBUILD,
"actionNewBuildPos: invalid order" );
//psStructStats = ((STRUCTURE *)psDroid->psTarget)->pStructureType;
psStats = (BASE_STATS *)((STRUCTURE *)psDroid->psTarget)->pStructureType;
}
break;
case DACTION_BUILD:
case DACTION_BUILDWANDER:
case DACTION_MOVETODEMOLISH:
//case DACTION_MOVETOREPAIR:
case DACTION_MOVETORESTORE:
//psStructStats = ((STRUCTURE *)psDroid->psTarget)->pStructureType;
psStats = (BASE_STATS *)((STRUCTURE *)psDroid->psTarget)->pStructureType;
break;
case DACTION_MOVETOREPAIR:
case DACTION_MOVETOREARM:
psStats = (BASE_STATS *)((STRUCTURE *)psDroid->psActionTarget)->pStructureType;
break;
case DACTION_MOVETOCLEAR:
psStats = (BASE_STATS *)((FEATURE *)psDroid->psTarget)->psStats;
break;
default:
ASSERT( FALSE,
"actionNewBuildPos: invalid action" );
return FALSE;
break;
}
//ASSERT( psStructStats != NULL,
// "actionNewBuildPos: invalid structure stats pointer" );
// find a new destination
//if (getDroidDestination(psStructStats, psDroid->orderX, psDroid->orderY,pX,pY))
if (psDroid->action == DACTION_MOVETOREARM || psDroid->action == DACTION_MOVETOREPAIR)
{
//use action target
if (getDroidDestination(psStats, psDroid->actionX, psDroid->actionY, pX, pY))
{
return TRUE;
}
}
else
{
//use order target
if (getDroidDestination(psStats, psDroid->orderX, psDroid->orderY, pX, pY))
{
return TRUE;
}
}
return FALSE;
}*/
// Realign turret
void actionAlignTurret(BASE_OBJECT *psObj, int weapon_slot)
{
@ -1991,25 +1919,6 @@ void actionUpdateDroid(DROID *psDroid)
(SDWORD)psDroid->orderX,(SDWORD)psDroid->orderY, psDroid->psTarStats[0]))
{
moveStopDroid(psDroid);
/* xdiff = (SDWORD)psDroid->x - (SDWORD)psDroid->actionX;
ydiff = (SDWORD)psDroid->y - (SDWORD)psDroid->actionY;
if ( xdiff*xdiff + ydiff*ydiff >= TILE_UNITS*TILE_UNITS )
{
debug( LOG_NEVER, "DACTION_MOVETOBUILD: new location\n");
// Couldn't reach destination - try and find a new one
if (actionNewBuildPos(psDroid, &droidX,&droidY))
{
psDroid->actionX = droidX;
psDroid->actionY = droidY;
moveDroidTo(psDroid, droidX,droidY);
}
else
{
debug( LOG_NEVER, "DACTION_MOVETOBUILD: giving up\n");
psDroid->action = DACTION_NONE;
}
}
else*/
bDoHelpBuild = FALSE;
// Got to destination - start building
@ -2020,8 +1929,6 @@ void actionUpdateDroid(DROID *psDroid)
// calculate the top left of the structure
tlx = (SDWORD)psDroid->orderX - (SDWORD)(psStructStats->baseWidth * TILE_UNITS)/2;
tly = (SDWORD)psDroid->orderY - (SDWORD)(psStructStats->baseBreadth * TILE_UNITS)/2;
// tlx = tlx >> TILE_UNITS;
// tly = tly >> TILE_UNITS;
//need to check if something has already started building here?
//unless its a module!
@ -2061,7 +1968,6 @@ void actionUpdateDroid(DROID *psDroid)
}
}
else if (!validLocation((BASE_STATS*)psDroid->psTarStats[0],
// psDroid->orderX >> TILE_SHIFT, psDroid->orderY >> TILE_SHIFT))
tlx >> TILE_SHIFT, tly >> TILE_SHIFT, psDroid->player, FALSE))
{
debug( LOG_NEVER, "DACTION_MOVETOBUILD: !validLocation\n");

View File

@ -372,6 +372,8 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
case REF_REPAIR_FACILITY:
targetTypeBonus = WEIGHT_MILITARY_STRUCT;
break;
default:
break;
}
/* Now calculate the overall weight */

View File

@ -490,9 +490,6 @@ void displayStructureStatButton(STRUCTURE_STATS *Stats,UDWORD Player, Vector3i *
//can only have the one
if (Stats->psWeapStat[i] != NULL)
{
/*nWeaponStat = Stats->defaultWeap;
weaponImd = Stats->asWeapList[nWeaponStat]->pIMD;
mountImd = Stats->asWeapList[nWeaponStat]->pMountGraphic;*/
weaponImd[i] = Stats->psWeapStat[i]->pIMD;
mountImd[i] = Stats->psWeapStat[i]->pMountGraphic;
}
@ -522,9 +519,6 @@ void displayStructureStatButton(STRUCTURE_STATS *Stats,UDWORD Player, Vector3i *
{
if (Stats->psWeapStat[0] != NULL)
{
/*nWeaponStat = Stats->defaultWeap;
weaponImd = Stats->asWeapList[nWeaponStat]->pIMD;
mountImd = Stats->asWeapList[nWeaponStat]->pMountGraphic;*/
weaponImd[0] = Stats->psWeapStat[0]->pIMD;
mountImd[0] = Stats->psWeapStat[0]->pMountGraphic;
}

View File

@ -6650,6 +6650,8 @@ BOOL loadSaveStructureV7(char *pFileData, UDWORD filesize, UDWORD numStructures)
psRepair->psObj = NULL;
psRepair->currentPtsAdded = 0;
break;
default:
break;
}
}
@ -7081,6 +7083,8 @@ BOOL loadSaveStructureV19(char *pFileData, UDWORD filesize, UDWORD numStructures
psRepair->psDeliveryPoint = NULL;
}
break;
default:
break;
}
//get the base body points
psStructure->body = (UWORD)structureBody(psStructure);
@ -7162,8 +7166,6 @@ BOOL loadSaveStructureV(char *pFileData, UDWORD filesize, UDWORD numStructures,
UDWORD sizeOfSaveStructure = 0;
UDWORD researchId;
if (version <= VERSION_20)
{
sizeOfSaveStructure = sizeof(SAVE_STRUCTURE_V20);
@ -7521,6 +7523,8 @@ BOOL loadSaveStructureV(char *pFileData, UDWORD filesize, UDWORD numStructures,
psReArmPad->timeStarted = 0;
}
break;
default:
break;
}
//get the base body points
psStructure->body = (UWORD)structureBody(psStructure);

View File

@ -7183,6 +7183,8 @@ void intCheckReticuleButtons(void)
case REF_HQ:
ReticuleEnabled[RETBUT_DESIGN].Enabled = TRUE;
break;
default:
break;
}
}
}

View File

@ -916,8 +916,6 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
Buffer->State = Form->state;
// Down = Form->state & (WCLICK_DOWN | WCLICK_LOCKED | WCLICK_CLICKLOCK);
Object = NULL;
Image = -1;
psObj = (BASE_OBJECT*)Buffer->Data; // Get the object associated with this widget.
@ -932,14 +930,12 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
}
if(psObj) {
// screenTextOut(64,48,"psObj: %p",psObj);
switch (psObj->type) {
case OBJ_DROID: // If it's a droid...
Droid = (DROID*)psObj;
if(DroidIsBuilding(Droid)) {
Structure = DroidGetBuildStructure(Droid);
// DBPRINTF(("%p : %p",Droid,Structure));
if(Structure) {
Object = Structure; //(void*)StructureGetIMD(Structure);
IMDType = IMDTYPE_STRUCTURE;
@ -952,17 +948,14 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
Player = selectedPlayer;
IMDType = IMDTYPE_STRUCTURESTAT;
RENDERBUTTON_INITIALISED(Buffer);
} else if (orderState(Droid, DORDER_DEMOLISH))
{
} else if (orderState(Droid, DORDER_DEMOLISH)) {
Stats = (BASE_STATS *)structGetDemolishStat();
ASSERT( Stats!=NULL,"intDisplayStatusButton : NULL Stats pointer." );
Object = (void*)Stats;
Player = selectedPlayer;
IMDType = IMDTYPE_STRUCTURESTAT;
RENDERBUTTON_INITIALISED(Buffer);
}
else if (Droid->droidType == DROID_COMMAND)
{
} else if (Droid->droidType == DROID_COMMAND) {
Structure = droidGetCommandFactory(Droid);
if (Structure) {
Object = Structure;
@ -974,11 +967,13 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
case OBJ_STRUCTURE: // If it's a structure...
Structure = (STRUCTURE*)psObj;
switch(Structure->pStructureType->type) {
switch(Structure->pStructureType->type)
{
case REF_FACTORY:
case REF_CYBORG_FACTORY:
case REF_VTOL_FACTORY:
if(StructureIsManufacturing(Structure)) {
if (StructureIsManufacturing(Structure))
{
IMDType = IMDTYPE_DROIDTEMPLATE;
Object = (void*)FactoryGetTemplate(StructureGetFactory(Structure));
RENDERBUTTON_INITIALISED(Buffer);
@ -991,33 +986,27 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
break;
case REF_RESEARCH:
if(StructureIsResearching(Structure)) {
Stats = (BASE_STATS*)Buffer->Data2;
if(Stats) {
/*StatGetResearchImage(Stats,&Image,(iIMDShape**)&Object,FALSE);
//if Object != NULL the there must be a IMD so set the object to
//equal the Research stat
if (Object != NULL)
if (StructureIsResearching(Structure))
{
Object = (void*)Stats;
Stats = (BASE_STATS*)Buffer->Data2;
if (!Stats)
{
break;
}
IMDType = IMDTYPE_RESEARCH;*/
if (((RESEARCH_FACILITY *)Structure->
pFunctionality)->timeStartHold)
if (((RESEARCH_FACILITY *)Structure->pFunctionality)->timeStartHold)
{
bOnHold = TRUE;
}
StatGetResearchImage(Stats,&Image,(iIMDShape**)&Object,
&psResGraphic, FALSE);
StatGetResearchImage(Stats,&Image,(iIMDShape**)&Object, &psResGraphic, FALSE);
if (psResGraphic)
{
//we have a Stat associated with this research topic
// we have a Stat associated with this research topic
if (StatIsStructure(psResGraphic))
{
//overwrite the Object pointer
// overwrite the Object pointer
Object = (void*)psResGraphic;
Player = selectedPlayer;
//this defines how the button is drawn
// this defines how the button is drawn
IMDType = IMDTYPE_STRUCTURESTAT;
}
else
@ -1025,15 +1014,14 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
compID = StatIsComponent(psResGraphic);
if (compID != COMP_UNKNOWN)
{
//this defines how the button is drawn
// this defines how the button is drawn
IMDType = IMDTYPE_COMPONENT;
//overwrite the Object pointer
// overwrite the Object pointer
Object = (void*)psResGraphic;
}
else
{
ASSERT( FALSE,
"intDisplayStatsButton:Invalid Stat for research button" );
ASSERT(FALSE, "intDisplayStatsButton:Invalid Stat for research button");
Object = NULL;
IMDType = IMDTYPE_RESEARCH;
}
@ -1041,9 +1029,9 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
}
else
{
//no Stat for this research topic so just use the graphic provided
//if Object != NULL the there must be a IMD so set the object to
//equal the Research stat
// no Stat for this research topic so just use the graphic provided
// if Object != NULL the there must be a IMD so set the object to
// equal the Research stat
if (Object != NULL)
{
Object = (void*)Stats;
@ -1052,8 +1040,8 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
}
RENDERBUTTON_INITIALISED(Buffer);
}
// Image = ResearchGetImage((RESEARCH_FACILITY*)Structure);
}
break;
default:
break;
}
break;
@ -1081,10 +1069,6 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, UD
} else {
RenderBlankToButton(Buffer,Down,TOPBUTTON);
}
// RENDERBUTTON_INITIALISED(Buffer);
}
CloseButtonRender();

View File

@ -2078,6 +2078,8 @@ void aiUpdateMissionStructure(STRUCTURE *psStructure)
}
break;
}
default:
break;
}
if (pSubject != NULL)

View File

@ -921,7 +921,6 @@ static UDWORD scrStructTargetMask(STRUCTURE *psStruct)
//else if (psStats->numWeaps > 0)
else if (psStats->psWeapStat != NULL)
{
//psWStats = psStats->asWeapList[0];
psWStats = psStats->psWeapStat[0];
if (!proj_Direct(psWStats))
{

View File

@ -790,13 +790,9 @@ BOOL loadStructureStats(char *pStructData, UDWORD bufferSize)
&psStructure->buildPoints, &psStructure->height,
&psStructure->armourValue, &psStructure->bodyPoints,
&psStructure->repairSystem, &psStructure->powerToBuild,
//&psStructure->minimumPower, &psStructure->resistance,
&dummyVal, &psStructure->resistance,
//&psStructure->quantityLimit, &psStructure->sizeModifier,
&dummyVal, &psStructure->sizeModifier,
//&ecmType, &sensorType, &psStructure->weaponSlots, &GfxFile,
ecmType, sensorType, &weapSlots, GfxFile,
//&baseIMD, &psStructure->numFuncs, &psStructure->numWeaps);
baseIMD, &psStructure->numFuncs, &numWeaps);
#if MAX_PLAYERS != 4 && MAX_PLAYERS != 8
@ -3425,7 +3421,9 @@ static void aiUpdateStructure(STRUCTURE *psStructure)
psReArmPad->currentPtsAdded = 0;
}
}
break;
}
default:
break;
}
@ -4464,6 +4462,11 @@ BOOL validLocation(BASE_STATS *psStats, UDWORD x, UDWORD y, UDWORD player,
switch(psBuilding->type)
{
case NUM_DIFF_BUILDINGS:
case REF_DEMOLISH:
case REF_BRIDGE:
ASSERT(FALSE, "validLocation: Bad structure type %u", psBuilding->type);
break;
case REF_HQ:
case REF_FACTORY:
case REF_LAB:
@ -4714,10 +4717,6 @@ BOOL validLocation(BASE_STATS *psStats, UDWORD x, UDWORD y, UDWORD player,
}
}
break;
default:
valid = TRUE;
break;
}
//if setting up a build queue need to check against future sites as well - AB 4/5/99
if (ctrlShiftDown() && player == selectedPlayer && bCheckBuildQueue)
@ -5465,6 +5464,8 @@ BOOL structureIdle(STRUCTURE *psBuilding)
pSubject = ((FACTORY*)psBuilding->pFunctionality)->psSubject;
break;
}
default:
break;
}
if (pSubject != NULL)
@ -7926,7 +7927,8 @@ STRUCTURE * giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, BOOL
case REF_VTOL_FACTORY:
capacity = ((FACTORY *)psStructure->pFunctionality)->capacity;
break;
//no default case cos don't care!
default:
break;
}
}
//get rid of the structure
@ -7960,6 +7962,8 @@ STRUCTURE * giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, BOOL
capacity--;
}
break;
default:
break;
}
}
if (buildPoints)
@ -8111,7 +8115,8 @@ UDWORD structPowerToBuild(STRUCTURE *psStruct)
case REF_VTOL_FACTORY:
capacity = ((FACTORY *)psStruct->pFunctionality)->capacity;
break;
//no default case cos don't care!
default:
break;
}
if (capacity)
{
@ -8171,11 +8176,8 @@ void resetResistanceLag(STRUCTURE *psBuilding)
}
}
}
/*
case REF_REPAIR_FACILITY: - this is catered for in the aiUpdateStructure function
case REF_REARM_PAD: - this structure is taken over completely
*/
//default: //do nothing
default: //do nothing
break;
}
}
}

View File

@ -37,7 +37,7 @@
#define REF_ANY 255 // Used to indicate any kind of building when calling intGotoNextStructureType()
/* Defines for indexing an appropriate IMD object given a buildings purpose. */
enum
typedef enum _structure_type
{
REF_HQ,
REF_FACTORY,
@ -53,7 +53,7 @@ REF_RESEARCH,
REF_RESEARCH_MODULE,
REF_REPAIR_FACILITY,
REF_COMMAND_CONTROL, //control centre for command droids
REF_BRIDGE,
REF_BRIDGE, //NOT USED, but removing it would change savegames
REF_DEMOLISH, //the demolish structure type - should only be one stat with this type
REF_CYBORG_FACTORY,
REF_VTOL_FACTORY,
@ -61,29 +61,8 @@ REF_LAB,
REF_REARM_PAD,
REF_MISSILE_SILO,
REF_SAT_UPLINK, //added for updates - AB 8/6/99
//REF_WALLH, //the following are needed for the demo
//REF_WALLV,
//REF_CORNER1,
//REF_CORNER2,
//REF_CORNER3,
//REF_CORNER4,
//REF_GATE1,
//REF_GATE2,
//REF_GATE3,
//REF_GATE4,
//REF_TOWER1,
//REF_TOWER2,
//REF_TOWER3,
//REF_TOWER4,
//REF_VANH,
//REF_VANV,
//REF_JEEP,
//REF_TANKERH,
//REF_TANKERV,
NUM_DIFF_BUILDINGS, //need to keep a count of how many types for IMD loading
};
} STRUCTURE_TYPE;
typedef enum _position_type
{
@ -151,7 +130,7 @@ typedef UWORD STRUCTSTRENGTH_MODIFIER;
typedef struct _structure_stats
{
STATS_BASE; /* basic stats */
UDWORD type; /* the type of structure */
STRUCTURE_TYPE type; /* the type of structure */
TECH_LEVEL techLevel; /* technology level of the structure */
STRUCT_STRENGTH strength; /* strength against the weapon effects */
UDWORD terrainType; /*The type of terrain the structure has to be
@ -171,15 +150,9 @@ typedef struct _structure_stats
points until fully restored . The points are
then added to the Armour Points*/
UDWORD powerToBuild; /*How much power the structure requires to build*/
//NOT USED ANYMORE - AB 24/01/99
/*UDWORD minimumPower; The minimum power requirement to start building
the structure*/
UDWORD resistance; /*The number used to determine whether a
structure can resist an enemy takeover -
0 = cannot be attacked electrically*/
//NOT USED ANYMORE - AB 24/01/99
/*UDWORD quantityLimit; The maximum number that a player can have -
0 = no limit 1 = only 1 allowed etc*/
UDWORD sizeModifier; /*The larger the target, the easier to hit*/
struct iIMDShape *pIMD; /*The IMD to draw for this structure */
struct iIMDShape *pBaseIMD; /*The base IMD to draw for this structure */
@ -187,17 +160,11 @@ typedef struct _structure_stats
if any*/
struct _sensor_stats *pSensor; /*Which Sensor is standard for the structure -
if any*/
//NOT USED ANYMORE - AB 24/01/99
//Watermelon:pfft
UDWORD weaponSlots; /*Number of weapons that can be attached to the
building*/
UDWORD numWeaps; /*Number of weapons for default */
//SDWORD defaultWeap; /The default weapon/
//struct _weapon_stats **asWeapList; /*List of pointers to default weapons*/
//Watermelon:can only have STRUCT_MAXWEAPS now...
struct _weapon_stats *psWeapStat[STRUCT_MAXWEAPS]; //can only have one weapon now
struct _weapon_stats *psWeapStat[STRUCT_MAXWEAPS];
UDWORD numFuncs; /*Number of functions for default*/
SDWORD defaultFunc; /*The default function*/