From 9b52ee44b4087db8b859a319a89f35cfd3437413 Mon Sep 17 00:00:00 2001 From: Cyp Date: Sat, 23 Oct 2010 16:44:12 +0200 Subject: [PATCH] Fix synch error, don't let AIs bypass the message queue when starting researching. --- src/hci.c | 3 --- src/multiplay.c | 5 ++++- src/scriptai.c | 43 ------------------------------------------- src/scriptfuncs.c | 23 ----------------------- src/structure.c | 31 ++++++++++++++++++++++++++++--- 5 files changed, 32 insertions(+), 73 deletions(-) diff --git a/src/hci.c b/src/hci.c index 2cb071e8f..dfefec3a9 100644 --- a/src/hci.c +++ b/src/hci.c @@ -6213,9 +6213,6 @@ static BOOL setResearchStats(BASE_OBJECT *psObj, BASE_STATS *psStats) { // Say that we want to do reseach [sic]. sendResearchStatus(psBuilding, ((RESEARCH *)psStats)->ref - REF_RESEARCH_START, selectedPlayer, true); - - // Tell UI to remove from the list of available research. - MakeResearchStartedPending(asPlayerResList[selectedPlayer] + (((RESEARCH *)psStats)->ref - REF_RESEARCH_START)); } else { diff --git a/src/multiplay.c b/src/multiplay.c index a1d1e251e..442c0c42a 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -904,7 +904,7 @@ static BOOL recvResearch(NETQUEUE queue) } pPlayerRes = asPlayerResList[player] + index; - syncDebug("research status = %d", pPlayerRes->ResearchStatus); + syncDebug("research status = %d", pPlayerRes->ResearchStatus & RESBITS); if (!IsResearchCompleted(pPlayerRes)) { @@ -968,6 +968,9 @@ BOOL sendResearchStatus(STRUCTURE *psBuilding, uint32_t index, uint8_t player, B NETuint32_t(&index); NETend(); + // Tell UI to remove from the list of available research. + MakeResearchStartedPending(asPlayerResList[selectedPlayer] + index); + return true; } diff --git a/src/scriptai.c b/src/scriptai.c index 5c99d65e8..d854feb2c 100644 --- a/src/scriptai.c +++ b/src/scriptai.c @@ -1637,8 +1637,6 @@ BOOL scrSkDoResearch(void) STRUCTURE *psBuilding; RESEARCH_FACILITY *psResFacilty; - PLAYER_RESEARCH *pPlayerRes; - RESEARCH *pResearch; if (!stackPopParams(3, ST_STRUCTURE, &psBuilding, VAL_INT, &player, VAL_INT, &bias)) { @@ -1664,48 +1662,7 @@ BOOL scrSkDoResearch(void) if(i != numResearch) { - pResearch = (asResearch + i); - pPlayerRes = asPlayerResList[player] + i; - psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up - - if (IsResearchCancelled(pPlayerRes)) - { - psResFacilty->powerAccrued = pResearch->researchPower; //set up as if all power available for cancelled topics - } - else - { - pPlayerRes = asPlayerResList[player]+ i; - psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up - - if (IsResearchCancelled(pPlayerRes)) - { - psResFacilty->powerAccrued = pResearch->researchPower;//set up as if all power available for cancelled topics - } - else - { - psResFacilty->powerAccrued = 0; - } - - MakeResearchStarted(pPlayerRes); - psResFacilty->timeStarted = ACTION_START_TIME; - psResFacilty->timeStartHold = 0; - psResFacilty->timeToResearch = pResearch->researchPoints / psResFacilty->researchPoints; - if (psResFacilty->timeToResearch == 0) - { - psResFacilty->timeToResearch = 1; - } - } - sendResearchStatus(psBuilding, i, player, true); // inform others, I'm researching this. - MakeResearchStarted(pPlayerRes); - psResFacilty->timeStarted = ACTION_START_TIME; - psResFacilty->timeStartHold = 0; - psResFacilty->timeToResearch = pResearch->researchPoints / psResFacilty->researchPoints; - - if (psResFacilty->timeToResearch == 0) - { - psResFacilty->timeToResearch = 1; - } #if defined (DEBUG) { char sTemp[128]; diff --git a/src/scriptfuncs.c b/src/scriptfuncs.c index 415b5e6ab..bf716b80c 100644 --- a/src/scriptfuncs.c +++ b/src/scriptfuncs.c @@ -10448,7 +10448,6 @@ BOOL scrPursueResearch(void) PLAYER_RESEARCH *pPlayerRes; STRUCTURE *psBuilding; RESEARCH_FACILITY *psResFacilty; - RESEARCH *pResearch; if (!stackPopParams(3,ST_STRUCTURE, &psBuilding, VAL_INT, &player, ST_RESEARCH, &psResearch )) { @@ -10586,29 +10585,7 @@ BOOL scrPursueResearch(void) if (found && foundIndex < numResearch) { - pResearch = (asResearch + foundIndex); - pPlayerRes = asPlayerResList[player] + foundIndex; - psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up - - if (IsResearchCancelled(pPlayerRes)) - { - psResFacilty->powerAccrued = pResearch->researchPower; //set up as if all power available for cancelled topics - } - else - { - psResFacilty->powerAccrued = 0; - } - sendResearchStatus(psBuilding, foundIndex, player, true); // inform others, I'm researching this. - MakeResearchStarted(pPlayerRes); - psResFacilty->timeStarted = ACTION_START_TIME; - psResFacilty->timeStartHold = 0; - psResFacilty->timeToResearch = pResearch->researchPoints / psResFacilty->researchPoints; - - if (psResFacilty->timeToResearch == 0) - { - psResFacilty->timeToResearch = 1; - } #if defined (DEBUG) { char sTemp[128]; diff --git a/src/structure.c b/src/structure.c index b5789ebcf..cd9eba0fa 100644 --- a/src/structure.c +++ b/src/structure.c @@ -3825,14 +3825,39 @@ static float CalcStructureSmokeInterval(float damage) void _syncDebugStructure(const char *function, STRUCTURE *psStruct, char ch) { - // TODO psBuilding->status == SS_BEING_BUILT test is because structure ids are not synchronised until after they start building... - _syncDebug(function, "%c structure%d = p%d;pos(%d,%d,%d),stat%d,type%d,bld%d,pwr%d,bp%d, power = %"PRId64"", ch, + int ref = 0; + char const *refStr = ""; + + // Print what the structure is producing, too. + switch (psStruct->pStructureType->type) + { + case REF_RESEARCH: + if (psStruct->pFunctionality->researchFacility.psSubject != NULL) + { + ref = psStruct->pFunctionality->researchFacility.psSubject->ref; + refStr = ",research"; + } + break; + case REF_FACTORY: + case REF_CYBORG_FACTORY: + case REF_VTOL_FACTORY: + if (psStruct->pFunctionality->factory.psSubject != NULL) + { + ref = psStruct->pFunctionality->factory.psSubject->ref; + refStr = ",production"; + } + break; + default: + break; + } + + _syncDebug(function, "%c structure%d = p%d;pos(%d,%d,%d),stat%d,type%d%s%.0d,bld%d,pwr%d,bp%d, power = %"PRId64"", ch, psStruct->id, psStruct->player, psStruct->pos.x, psStruct->pos.y, psStruct->pos.z, psStruct->status, - psStruct->pStructureType->type, + psStruct->pStructureType->type, refStr, ref, psStruct->currentBuildPts, psStruct->currentPowerAccrued, psStruct->body,