Skip to content

Commit

Permalink
Introduce ModeQueue and ModeImmediate as an alternative to playing wi…
Browse files Browse the repository at this point in the history
…th bMultiMessages.

Makes campaign queue some messages, and fixes cancelling production queues in campaign.
  • Loading branch information
Cyp committed Oct 22, 2010
1 parent 714b465 commit fcdba75
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 93 deletions.
7 changes: 7 additions & 0 deletions lib/framework/frame.h
Expand Up @@ -55,6 +55,13 @@ extern uint32_t realSelectedPlayer; ///< The player number corresponding to thi
#define MAX_PLAYERS 8 /**< Maximum number of players in the game. */
#define MAX_PLAYER_SLOTS 10 /**< 8 players, 1 baba and 1 reserved for features. */

typedef enum
{
ModeQueue, ///< Sends a message on the game queue, which will get synchronised, by sending a GAME_ message.
ModeImmediate ///< Performs the action immediately. Must already have been synchronised, for example by sending a GAME_ message.
} QUEUE_MODE;


/** Initialise the framework library
* @param pWindowName the text to appear in the window title bar
* @param width the display widget
Expand Down
6 changes: 1 addition & 5 deletions src/design.c
Expand Up @@ -4094,11 +4094,7 @@ void intProcessDesign(UDWORD id)
/* remove template if found */
if ( psTempl )
{

if (bMultiMessages) //ajl. inform others of template destruction.
{
SendDestroyTemplate(psTempl);
}
SendDestroyTemplate(psTempl);

//update player template list.
{
Expand Down
2 changes: 1 addition & 1 deletion src/droid.c
Expand Up @@ -4608,7 +4608,7 @@ static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE
//power is returned by factoryProdAdjust()
if (psNextTemplate)
{
structSetManufacture(psStruct, psNextTemplate);
structSetManufacture(psStruct, psNextTemplate, ModeQueue); // ModeQueue because production lists aren't synchronised.
}
else
{
Expand Down
28 changes: 14 additions & 14 deletions src/hci.c
Expand Up @@ -2758,12 +2758,12 @@ static void intProcessObject(UDWORD id)
if (StructIsFactory((STRUCTURE *)psObj))
{
//might need to cancel the hold on production
releaseProduction((STRUCTURE *)psObj);
releaseProduction((STRUCTURE *)psObj, ModeQueue);
}
else if (((STRUCTURE *)psObj)->pStructureType->type == REF_RESEARCH)
{
//might need to cancel the hold on research facilty
releaseResearch((STRUCTURE *)psObj);
releaseResearch((STRUCTURE *)psObj, ModeQueue);
}
}
}
Expand Down Expand Up @@ -2832,7 +2832,7 @@ static void intProcessStats(UDWORD id)

if (!StructureIsManufacturingPending(psStructure))
{
structSetManufacture(psStructure, psNext);
structSetManufacture(psStructure, psNext, ModeQueue);
}

//need to check if this was the template that was mid-production
Expand All @@ -2844,7 +2844,7 @@ static void intProcessStats(UDWORD id)

if (StructureIsOnHoldPending(psStructure))
{
releaseProduction(psStructure);
releaseProduction(psStructure, ModeQueue);
}

// Reset the button on the object form
Expand All @@ -2864,7 +2864,7 @@ static void intProcessStats(UDWORD id)
{
if (psObjSelected->type == OBJ_STRUCTURE )
{
cancelResearch((STRUCTURE *)psObjSelected);
cancelResearch((STRUCTURE *)psObjSelected, ModeQueue);
}
}

Expand All @@ -2889,7 +2889,7 @@ static void intProcessStats(UDWORD id)
if (((RESEARCH_FACILITY *)((STRUCTURE *)psObjSelected)->
pFunctionality)->psSubject)
{
cancelResearch((STRUCTURE *)psObjSelected);
cancelResearch((STRUCTURE *)psObjSelected, ModeQueue);
}
}
}
Expand Down Expand Up @@ -6219,7 +6219,7 @@ static BOOL setResearchStats(BASE_OBJECT *psObj, BASE_STATS *psStats)
}
else
{
cancelResearch(psBuilding);
cancelResearch(psBuilding, ModeQueue);
}
psResFacilty->psSubjectPending = psStats; // Tell UI that we are going to research.
//stop the button from flashing once a topic has been chosen
Expand Down Expand Up @@ -6335,7 +6335,7 @@ static BOOL setManufactureStats(BASE_OBJECT *psObj, BASE_STATS *psStats)
if (psStats != NULL)
{
/* Set the factory to build droid(s) */
if (!structSetManufacture(Structure, (DROID_TEMPLATE *)psStats))
if (!structSetManufacture(Structure, (DROID_TEMPLATE *)psStats, ModeQueue))
{
return false;
}
Expand Down Expand Up @@ -6518,7 +6518,7 @@ static void intStatsRMBPressed(UDWORD id)

if (!StructureIsManufacturingPending(psStructure))
{
structSetManufacture(psStructure, psNext);
structSetManufacture(psStructure, psNext, ModeQueue);
}

//need to check if this was the template that was mid-production
Expand All @@ -6530,7 +6530,7 @@ static void intStatsRMBPressed(UDWORD id)

if (StructureIsOnHoldPending(psStructure))
{
releaseProduction(psStructure);
releaseProduction(psStructure, ModeQueue);
}

// Reset the button on the object form
Expand Down Expand Up @@ -6617,12 +6617,12 @@ static void intObjStatRMBPressed(UDWORD id)
//if not curently on hold, set it
if (!StructureIsOnHoldPending(psStructure))
{
holdProduction(psStructure);
holdProduction(psStructure, ModeQueue);
}
else
{
//cancel if have RMB-clicked twice
cancelProduction(psStructure);
cancelProduction(psStructure, ModeQueue);
//play audio to indicate cancelled
audio_PlayTrack(ID_SOUND_WINDOWCLOSE);
}
Expand All @@ -6636,12 +6636,12 @@ static void intObjStatRMBPressed(UDWORD id)
//if not curently on hold, set it
if (((RESEARCH_FACILITY *)psStructure->pFunctionality)->timeStartHold == 0)
{
holdResearch(psStructure);
holdResearch(psStructure, ModeQueue);
}
else
{
//cancel if have RMB-clicked twice
cancelResearch(psStructure);
cancelResearch(psStructure, ModeQueue);
//play audio to indicate cancelled
audio_PlayTrack(ID_SOUND_WINDOWCLOSE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mission.c
Expand Up @@ -949,11 +949,11 @@ void saveMissionLimboData(void)
{
if (StructIsFactory(psStruct))
{
holdProduction(psStruct);
holdProduction(psStruct, ModeQueue);
}
else if (psStruct->pStructureType->type == REF_RESEARCH)
{
holdResearch(psStruct);
holdResearch(psStruct, ModeQueue);
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/multiplay.c
Expand Up @@ -151,7 +151,7 @@ BOOL multiplayerWinSequence(BOOL firstCall)
{
if (((FACTORY *)psStruct->pFunctionality)->psSubject)//check if active
{
cancelProduction(psStruct);
cancelProduction(psStruct, ModeQueue);
}
}
}
Expand Down Expand Up @@ -1012,9 +1012,7 @@ BOOL recvResearchStatus(NETQUEUE queue)

if (psResFacilty->psSubject)
{
turnOffMultiMsg(true);
cancelResearch(psBuilding);
turnOffMultiMsg(false);
cancelResearch(psBuilding, ModeImmediate);
}

// Set the subject up
Expand Down Expand Up @@ -1077,9 +1075,7 @@ BOOL recvResearchStatus(NETQUEUE queue)
// Stop the facility doing any research
if (psBuilding)
{
turnOffMultiMsg(true);
cancelResearch(psBuilding);
turnOffMultiMsg(false);
cancelResearch(psBuilding, ModeImmediate);
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/multistruct.c
Expand Up @@ -487,19 +487,17 @@ void recvStructureInfo(NETQUEUE queue)

syncDebugStructure(psStruct, '<');

turnOffMultiMsg(true);
switch (structureInfo)
{
case STRUCTUREINFO_MANUFACTURE: structSetManufacture(psStruct, psTempl); break;
case STRUCTUREINFO_CANCELPRODUCTION: cancelProduction(psStruct); break;
case STRUCTUREINFO_HOLDPRODUCTION: holdProduction(psStruct); break;
case STRUCTUREINFO_RELEASEPRODUCTION: releaseProduction(psStruct); break;
case STRUCTUREINFO_HOLDRESEARCH: holdResearch(psStruct); break;
case STRUCTUREINFO_RELEASERESEARCH: releaseResearch(psStruct); break;
case STRUCTUREINFO_MANUFACTURE: structSetManufacture(psStruct, psTempl, ModeImmediate); break;
case STRUCTUREINFO_CANCELPRODUCTION: cancelProduction(psStruct, ModeImmediate); break;
case STRUCTUREINFO_HOLDPRODUCTION: holdProduction(psStruct, ModeImmediate); break;
case STRUCTUREINFO_RELEASEPRODUCTION: releaseProduction(psStruct, ModeImmediate); break;
case STRUCTUREINFO_HOLDRESEARCH: holdResearch(psStruct, ModeImmediate); break;
case STRUCTUREINFO_RELEASERESEARCH: releaseResearch(psStruct, ModeImmediate); break;
default:
debug(LOG_ERROR, "Invalid structureInfo %d", structureInfo);
}
turnOffMultiMsg(false);

syncDebugStructure(psStruct, '>');

Expand Down
14 changes: 7 additions & 7 deletions src/research.c
Expand Up @@ -1867,14 +1867,14 @@ void ResearchRelease(void)
}

/*puts research facility on hold*/
void holdResearch(STRUCTURE *psBuilding)
void holdResearch(STRUCTURE *psBuilding, QUEUE_MODE mode)
{
RESEARCH_FACILITY *psResFac;

ASSERT( psBuilding->pStructureType->type == REF_RESEARCH,
"holdResearch: structure not a research facility" );

if (bMultiMessages)
if (mode == ModeQueue)
{
sendStructureInfo(psBuilding, STRUCTUREINFO_HOLDRESEARCH, NULL);
return;
Expand All @@ -1896,14 +1896,14 @@ void holdResearch(STRUCTURE *psBuilding)
}

/*release a research facility from hold*/
void releaseResearch(STRUCTURE *psBuilding)
void releaseResearch(STRUCTURE *psBuilding, QUEUE_MODE mode)
{
RESEARCH_FACILITY *psResFac;

ASSERT( psBuilding->pStructureType->type == REF_RESEARCH,
"releaseResearch: structure not a research facility" );

if (bMultiMessages)
if (mode == ModeQueue)
{
sendStructureInfo(psBuilding, STRUCTUREINFO_RELEASERESEARCH, NULL);
return;
Expand Down Expand Up @@ -1942,7 +1942,7 @@ void CancelAllResearch(UDWORD pl)
)
{
debug( LOG_NEVER, "canceling research for %p\n", psCurr );
cancelResearch(psCurr);
cancelResearch(psCurr, ModeQueue);
}
}

Expand All @@ -1951,7 +1951,7 @@ void CancelAllResearch(UDWORD pl)

/* sets the status of the topic to cancelled and stores the current research
points accquired */
void cancelResearch(STRUCTURE *psBuilding)
void cancelResearch(STRUCTURE *psBuilding, QUEUE_MODE mode)
{
UDWORD topicInc;
PLAYER_RESEARCH *pPlayerRes;
Expand All @@ -1976,7 +1976,7 @@ void cancelResearch(STRUCTURE *psBuilding)

if (psBuilding->pStructureType->type == REF_RESEARCH)
{
if (bMultiMessages)
if (mode == ModeQueue)
{
// Tell others that we want to stop researching something.
sendResearchStatus(NULL, topicInc, psBuilding->player, false);
Expand Down
6 changes: 3 additions & 3 deletions src/research.h
Expand Up @@ -120,7 +120,7 @@ extern RESEARCH * getResearch(const char *pName, BOOL resName);

/* sets the status of the topic to cancelled and stores the current research
points accquired */
extern void cancelResearch(STRUCTURE *psBuilding);
extern void cancelResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);

/* For a given view data get the research this is related to */
extern RESEARCH * getResearchForMsg(struct _viewdata *pViewData);
Expand All @@ -141,9 +141,9 @@ extern SDWORD mapIconToRID(UDWORD iconID);
extern BOOL checkResearchStats(void);

/*puts research facility on hold*/
extern void holdResearch(STRUCTURE *psBuilding);
extern void holdResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);
/*release a research facility from hold*/
extern void releaseResearch(STRUCTURE *psBuilding);
extern void releaseResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);

/*checks the stat to see if its of type wall or defence*/
extern BOOL wallDefenceStruct(STRUCTURE_STATS *psStats);
Expand Down
2 changes: 1 addition & 1 deletion src/scriptfuncs.c
Expand Up @@ -1468,7 +1468,7 @@ BOOL scrBuildDroid(void)
{
debug(LOG_ERROR, "A script is trying to build a different number (%d) than 1 droid.", productionRun);
}
structSetManufacture(psFactory, psTemplate);
structSetManufacture(psFactory, psTemplate, ModeQueue);

return true;
}
Expand Down

0 comments on commit fcdba75

Please sign in to comment.