Skip to content

Commit

Permalink
Fix synch error, don't let AIs bypass the message queue when starting…
Browse files Browse the repository at this point in the history
… researching.
  • Loading branch information
Cyp committed Oct 23, 2010
1 parent e8ebb11 commit 9b52ee4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 73 deletions.
3 changes: 0 additions & 3 deletions src/hci.c
Expand Up @@ -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
{
Expand Down
5 changes: 4 additions & 1 deletion src/multiplay.c
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
}

Expand Down
43 changes: 0 additions & 43 deletions src/scriptai.c
Expand Up @@ -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))
{
Expand All @@ -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];
Expand Down
23 changes: 0 additions & 23 deletions src/scriptfuncs.c
Expand Up @@ -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 ))
{
Expand Down Expand Up @@ -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];
Expand Down
31 changes: 28 additions & 3 deletions src/structure.c
Expand Up @@ -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,
Expand Down

0 comments on commit 9b52ee4

Please sign in to comment.