Skip to content

Commit

Permalink
Make research button flash more consistently.
Browse files Browse the repository at this point in the history
Flash research button, if there is a free lab and a new research becomes available, or if
a lab becomes available and there is something to research.

Stop flashing the research button, if there is nothing to research, or no free labs; for
example, due to a lab being upgraded or destroyed.

Available researches which are already being researched by an ally no longer count towards
the button flashing.

Do not randomly start flashing the research button again, even if there are still free
labs which are not researching.

Fixes ticket:1835.
  • Loading branch information
Cyp committed Feb 7, 2012
1 parent 24d0d1b commit 8d92594
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/game.cpp
Expand Up @@ -2456,7 +2456,7 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
//cancel first
stopReticuleButtonFlash(IDRET_RESEARCH);
//then see if needs to be set
intCheckResearchButton();
intNotifyResearchButton(0);

//set up the mission countdown flag
setMissionCountDown();
Expand Down
45 changes: 32 additions & 13 deletions src/hci.cpp
Expand Up @@ -6111,39 +6111,58 @@ void intCheckReticuleButtons(void)

/*Checks to see if there are any research topics to do and flashes the button -
only if research facility is free*/
void intCheckResearchButton(void)
int intGetResearchState()
{
UWORD index, count;
STRUCTURE *psStruct;
bool resFree = false;

for (psStruct = interfaceStructList(); psStruct != NULL; psStruct =
psStruct->psNext)
bool resFree = false;
for (STRUCTURE *psStruct = interfaceStructList(); psStruct != NULL; psStruct = psStruct->psNext)
{
if (psStruct->pStructureType->type == REF_RESEARCH &&
psStruct->status == SS_BUILT &&
getResearchStats((BASE_OBJECT *)psStruct) == NULL)
getResearchStats(psStruct) == NULL)
{
resFree = true;
break;
}

}

int count = 0;
if (resFree)
{
//set to value that won't be reached in fillResearchList
index = asResearch.size() + 1;
int index = asResearch.size() + 1;
//calculate the list
count = fillResearchList(pList,selectedPlayer, index, MAXRESEARCH);
if (count)
int preCount = fillResearchList(pList, selectedPlayer, index, MAXRESEARCH);
count = preCount;
for (int n = 0; n < preCount; ++n)
{
//set the research reticule button to flash
flashReticuleButton(IDRET_RESEARCH);
for (int player = 0; player < MAX_PLAYERS; ++player)
{
if (aiCheckAlliances(player, selectedPlayer) && IsResearchStarted(&asPlayerResList[player][pList[n]]))
{
--count; // An ally is already researching this topic, so don't flash the button because of it.
break;
}
}
}
}

return count;
}

void intNotifyResearchButton(int prevState)
{
int newState = intGetResearchState();
if (newState > prevState)
{
// Set the research reticule button to flash.
flashReticuleButton(IDRET_RESEARCH);
}
else if (newState == 0 && prevState > 0)
{
stopReticuleButtonFlash(IDRET_RESEARCH);
}
}

// see if a reticule button is enabled
bool intCheckReticuleButEnabled(UDWORD id)
Expand Down
7 changes: 5 additions & 2 deletions src/hci.h
Expand Up @@ -414,8 +414,11 @@ STRUCTURE *intFindAStructure(void);
STRUCTURE* intGotoNextStructureType(UDWORD structType,bool JumpTo,bool CancelDrive);
DROID *intGotoNextDroidType(DROID *CurrDroid,UDWORD droidType,bool AllowGroup);

/*Checks to see if there are any research topics to do and flashes the button*/
extern void intCheckResearchButton(void);
/// Returns the number of researches that selectedPlayer is not already researching, or 0 if there are no free laboratories.
int intGetResearchState();
/// Flashes the button if the research button should flash, and more researches are available to research than before.
/// Stops the button from flashing, if the research button shouldn't flash, and prevState is non-zero.
void intNotifyResearchButton(int prevState);

// see if a reticule button is enabled
extern bool intCheckReticuleButEnabled(UDWORD id);
Expand Down
9 changes: 8 additions & 1 deletion src/multiplay.cpp
Expand Up @@ -907,6 +907,12 @@ bool recvResearchStatus(NETQUEUE queue)
return false;
}

int prevResearchState = 0;
if (aiCheckAlliances(selectedPlayer, player))
{
prevResearchState = intGetResearchState();
}

pPlayerRes = &asPlayerResList[player][index];

// psBuilding may be null if finishing
Expand Down Expand Up @@ -973,9 +979,10 @@ bool recvResearchStatus(NETQUEUE queue)
}
}

if (alliances[selectedPlayer][player] == ALLIANCE_FORMED)
if (aiCheckAlliances(selectedPlayer, player))
{
intAlliedResearchChanged();
intNotifyResearchButton(prevResearchState);
}

return true;
Expand Down
20 changes: 4 additions & 16 deletions src/research.cpp
Expand Up @@ -1819,8 +1819,6 @@ the research list next time the Research Facilty is selected */
bool enableResearch(RESEARCH *psResearch, UDWORD player)
{
UDWORD inc;
STRUCTURE *psStruct;
bool resFree = false;

inc = psResearch->index;
if (inc > asResearch.size())
Expand All @@ -1829,25 +1827,15 @@ bool enableResearch(RESEARCH *psResearch, UDWORD player)
return false;
}

int prevState = intGetResearchState();

//found, so set the flag
MakeResearchPossible(&asPlayerResList[player][inc]);

if(player == selectedPlayer)
if (player == selectedPlayer)
{
//set the research reticule button to flash if research facility is free
for (psStruct = apsStructLists[selectedPlayer]; psStruct != NULL; psStruct=psStruct->psNext)
{
if (psStruct->pStructureType->type == REF_RESEARCH && psStruct->status == SS_BUILT &&
((RESEARCH_FACILITY *)psStruct->pFunctionality)->psSubject == NULL)
{
resFree = true;
break;
}
}
if (resFree)
{
flashReticuleButton(IDRET_RESEARCH);
}
intNotifyResearchButton(prevState);
}

return true;
Expand Down
39 changes: 34 additions & 5 deletions src/structure.cpp
Expand Up @@ -759,6 +759,13 @@ int32_t getStructureDamage(const STRUCTURE *psStructure)
/// Also can deconstruct (demolish) a building if passed negative buildpoints
void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int buildRate)
{
bool checkResearchButton = psStruct->status == SS_BUILT; // We probably just started demolishing, if this is true.
int prevResearchState = 0;
if (checkResearchButton)
{
prevResearchState = intGetResearchState();
}

if (psDroid && !aiCheckAlliances(psStruct->player,psDroid->player))
{
// Enemy structure
Expand Down Expand Up @@ -810,8 +817,6 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int bu
//check if structure is built
if (buildPoints > 0 && psStruct->currentBuildPts >= (SDWORD)psStruct->pStructureType->buildPoints)
{
psStruct->currentBuildPts = (SWORD)psStruct->pStructureType->buildPoints;
psStruct->status = SS_BUILT;
buildingComplete(psStruct);

if (psDroid)
Expand Down Expand Up @@ -876,6 +881,11 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int bu
{
removeStruct(psStruct, true);
}

if (checkResearchButton)
{
intNotifyResearchButton(prevResearchState);
}
}

static bool structureHasModules(STRUCTURE *psStruct)
Expand Down Expand Up @@ -1630,6 +1640,8 @@ STRUCTURE* buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y
return NULL;
}

int prevResearchState = intGetResearchState();

int capacity = 0; // Dummy initialisation.

if (pStructureType->type == REF_FACTORY_MODULE)
Expand Down Expand Up @@ -1736,6 +1748,7 @@ STRUCTURE* buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y
intRefreshScreen();
}
}
intNotifyResearchButton(prevResearchState);
}
if(pStructureType->type!=REF_WALL && pStructureType->type!=REF_WALLCORNER)
{
Expand Down Expand Up @@ -3123,6 +3136,8 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
//check if Research is complete
if (pPlayerRes->currentPoints >= pResearch->researchPoints)
{
int prevState = intGetResearchState();

if(bMultiMessages)
{
if (myResponsibility(psStructure->player) && !isInSync())
Expand All @@ -3147,8 +3162,6 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psResFacility->psSubject = NULL;
intResearchFinished(psStructure);
researchResult(researchIndex, psStructure->player, true, psStructure, true);
//check if this result has enabled another topic
intCheckResearchButton();

// Update allies research accordingly
if (game.type == SKIRMISH)
Expand All @@ -3165,6 +3178,8 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
}
}
}
//check if this result has enabled another topic
intNotifyResearchButton(prevState);
}
}
else
Expand Down Expand Up @@ -4492,6 +4507,8 @@ bool removeStruct(STRUCTURE *psDel, bool bDestroy)

ASSERT_OR_RETURN(false, psDel != NULL, "Invalid structure pointer");

int prevResearchState = intGetResearchState();

if (bDestroy)
{
removeStructFromMap(psDel);
Expand Down Expand Up @@ -4601,6 +4618,8 @@ bool removeStruct(STRUCTURE *psDel, bool bDestroy)

delPowerRequest(psDel);

intNotifyResearchButton(prevResearchState);

return resourceFound;
}

Expand Down Expand Up @@ -5416,6 +5435,12 @@ void buildingComplete(STRUCTURE *psBuilding)
{
CHECK_STRUCTURE(psBuilding);

int prevState = 0;
if (psBuilding->pStructureType->type == REF_RESEARCH)
{
prevState = intGetResearchState();
}

psBuilding->currentBuildPts = (SWORD)psBuilding->pStructureType->buildPoints;
psBuilding->status = SS_BUILT;

Expand Down Expand Up @@ -5451,9 +5476,9 @@ void buildingComplete(STRUCTURE *psBuilding)

break;
case REF_RESEARCH:
intCheckResearchButton();
//this deals with research facilities that are upgraded whilst mid-research
releaseResearch(psBuilding, ModeImmediate);
intNotifyResearchButton(prevState);
break;
case REF_FACTORY:
case REF_CYBORG_FACTORY:
Expand Down Expand Up @@ -7115,6 +7140,8 @@ STRUCTURE * giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool
ASSERT_OR_RETURN(NULL, bFromScript || selectedPlayer != 0 || attackPlayer != selectedPlayer, "EW attack by selectedPlayer on a structure");
}

int prevState = intGetResearchState();

//don't want the hassle in multiplayer either
//and now we do! - AB 13/05/99

Expand Down Expand Up @@ -7183,6 +7210,7 @@ STRUCTURE * giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool
psStructure->visible[attackPlayer] = UINT8_MAX;
triggerEventObjectTransfer(psStructure, attackPlayer);
}
intNotifyResearchButton(prevState);
return NULL;
}

Expand Down Expand Up @@ -7291,6 +7319,7 @@ STRUCTURE * giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool
}
}
powerCalculated = bPowerOn;
intNotifyResearchButton(prevState);
return psNewStruct;
}

Expand Down

0 comments on commit 8d92594

Please sign in to comment.