Skip to content

Commit

Permalink
Fix ticket:1478 "Non-host players do not get info about the research …
Browse files Browse the repository at this point in the history
…in progress by allied AIs in MP"

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/branches/2.3@11556 4a71c877-e1ca-e34f-864e-861f7616d084
(cherry picked from commit edadbb8)

Conflicts:

	src/scriptai.c
	src/scriptfuncs.c
  • Loading branch information
buginator committed Oct 19, 2010
1 parent 5f83b41 commit ccb286c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
23 changes: 18 additions & 5 deletions src/scriptai.c
Expand Up @@ -1640,7 +1640,7 @@ BOOL scrSkDoResearch(void)
PLAYER_RESEARCH *pPlayerRes;
RESEARCH *pResearch;

if (!stackPopParams(3,ST_STRUCTURE, &psBuilding, VAL_INT, &player, VAL_INT,&bias ))
if (!stackPopParams(3, ST_STRUCTURE, &psBuilding, VAL_INT, &player, VAL_INT, &bias))
{
return false;
}
Expand All @@ -1654,7 +1654,7 @@ BOOL scrSkDoResearch(void)
}

// choose a topic to complete.
for(i=0;i<numResearch;i++)
for(i=0; i < numResearch; i++)
{
if (skTopicAvail(i, player) && (!bMultiPlayer || !beingResearchedByAlly(i, player)))
{
Expand All @@ -1664,10 +1664,13 @@ BOOL scrSkDoResearch(void)

if(i != numResearch)
{
pResearch = asResearch + i;
if (bMultiMessages)
pResearch = (asResearch + i);
pPlayerRes = asPlayerResList[player] + i;
psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up

if (IsResearchCancelled(pPlayerRes))
{
sendResearchStatus(psBuilding, pResearch->ref - REF_RESEARCH_START, player, true);
psResFacilty->powerAccrued = pResearch->researchPower; //set up as if all power available for cancelled topics
}
else
{
Expand All @@ -1693,6 +1696,16 @@ BOOL scrSkDoResearch(void)
}
}

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
70 changes: 29 additions & 41 deletions src/scriptfuncs.c
Expand Up @@ -10441,16 +10441,13 @@ BOOL objectInRangeVis(BASE_OBJECT *psList, SDWORD x, SDWORD y, SDWORD range, SDW
BOOL scrPursueResearch(void)
{
RESEARCH *psResearch;
SDWORD foundIndex = 0,player,cur,tempIndex,Stack[400];
SDWORD foundIndex = 0, player, cur, tempIndex, Stack[400];
UDWORD index;
SWORD top;

BOOL found;
PLAYER_RESEARCH *pPlayerRes;

STRUCTURE *psBuilding;
RESEARCH_FACILITY *psResFacilty;

RESEARCH *pResearch;

if (!stackPopParams(3,ST_STRUCTURE, &psBuilding, VAL_INT, &player, ST_RESEARCH, &psResearch ))
Expand All @@ -10459,15 +10456,15 @@ BOOL scrPursueResearch(void)
return false;
}

if(psResearch == NULL)
if (psResearch == NULL)
{
ASSERT(false, ": no such research topic");
return false;
}

psResFacilty = (RESEARCH_FACILITY*)psBuilding->pFunctionality;

if(psResFacilty->psSubject != NULL) // not finished yet
if (psResFacilty->psSubject != NULL) // not finished yet
{
scrFunctionResult.v.bval = false;
if (!stackPushResult(VAL_BOOL, &scrFunctionResult))
Expand All @@ -10488,28 +10485,27 @@ BOOL scrPursueResearch(void)

found = false;

if(beingResearchedByAlly(index, player)) //an ally is already researching it
if (beingResearchedByAlly(index, player)) //an ally is already researching it
{
found = false;
}
else if(IsResearchCompleted(&pPlayerRes[index]))
else if (IsResearchCompleted(&pPlayerRes[index]))
{
found = false;
//DbgMsg("Research already completed: %d", index);
}
else if(IsResearchStarted(&pPlayerRes[index]))
else if (IsResearchStarted(&pPlayerRes[index]))
{
found = false;
//DbgMsg("Research already in progress, %d", index);
}
else if(IsResearchPossible(&pPlayerRes[index])
|| IsResearchCancelled(&pPlayerRes[index]))
else if (IsResearchPossible(&pPlayerRes[index]) || IsResearchCancelled(&pPlayerRes[index]))
{
foundIndex = index;
found = true;
//DbgMsg("Research possible or cancelled: %d", index);
}
else if(skTopicAvail(index,player))
else if (skTopicAvail(index, player))
{
foundIndex = index;
found = true;
Expand All @@ -10526,12 +10522,12 @@ BOOL scrPursueResearch(void)
{
//DbgMsg("Going on with %d, numPR: %d, %s", index, asResearch[index].numPRRequired, asResearch[index].pName);

if(cur >= asResearch[index].numPRRequired) //node has nodes?
if (cur >= asResearch[index].numPRRequired) //node has nodes?
{
//DbgMsg("cur >= numPRRequired : %d (%d >= %d)", index, cur, asResearch[index].numPRRequired);

top = top - 2;
if(top < (-1))
if (top < (-1))
{
//DbgMsg("Nothing on stack");
break; //end of stack
Expand All @@ -10545,17 +10541,17 @@ BOOL scrPursueResearch(void)
tempIndex = asResearch[index].pPRList[cur]; //get cur node's index
//DbgMsg("evaluating node: %d, (cur = %d), %s", tempIndex, cur, asResearch[tempIndex].pName);

if(skTopicAvail(tempIndex,player) && (!beingResearchedByAlly(tempIndex, player))) //<NEW> - ally check added
if (skTopicAvail(tempIndex,player) && (!beingResearchedByAlly(tempIndex, player))) //<NEW> - ally check added
{
//DbgMsg("avail: %d (cur=%d), %s", tempIndex, cur, asResearch[tempIndex].pName);
found = true;
foundIndex = tempIndex; //done
break;
}
else if((IsResearchCompleted(&pPlayerRes[tempIndex])==false) && (IsResearchStarted(&pPlayerRes[tempIndex])==false)) //not avail and not busy with it, can check this PR's PR
else if ((IsResearchCompleted(&pPlayerRes[tempIndex]) == false) && (IsResearchStarted(&pPlayerRes[tempIndex]) == false)) //not avail and not busy with it, can check this PR's PR
{
//DbgMsg("node not complete, not started: %d, (cur=%d), %s", tempIndex,cur, asResearch[tempIndex].pName);
if(asResearch[tempIndex].numPRRequired > 0) //node has any nodes itself
if (asResearch[tempIndex].numPRRequired > 0) //node has any nodes itself
{
//DbgMsg("node has nodes, so selecting as main node: %d, %s", tempIndex, asResearch[tempIndex].pName);

Expand All @@ -10582,43 +10578,36 @@ BOOL scrPursueResearch(void)
cur++; //try next node of the main node
if((cur >= asResearch[index].numPRRequired) && (top <= (-1))) //nothing left
{
//DbgMsg("END");
break;
}

} // while(true)
}

if(found
&& foundIndex < numResearch)
if (found && foundIndex < numResearch)
{
pResearch = (asResearch + foundIndex);
if (bMultiMessages)
pPlayerRes = asPlayerResList[player] + foundIndex;
psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up

if (IsResearchCancelled(pPlayerRes))
{
sendResearchStatus(psBuilding, pResearch->ref - REF_RESEARCH_START, player, true);
psResFacilty->powerAccrued = pResearch->researchPower; //set up as if all power available for cancelled topics
}
else
{
pPlayerRes = asPlayerResList[player]+ foundIndex;
psResFacilty->psSubject = (BASE_STATS*)pResearch; //set the subject up
psResFacilty->powerAccrued = 0;
}

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;

MakeResearchStarted(pPlayerRes);
psResFacilty->timeStarted = ACTION_START_TIME;
psResFacilty->timeStartHold = 0;
psResFacilty->timeToResearch = pResearch->researchPoints / psResFacilty->researchPoints;
if (psResFacilty->timeToResearch == 0)
{
psResFacilty->timeToResearch = 1;
}
if (psResFacilty->timeToResearch == 0)
{
psResFacilty->timeToResearch = 1;
}
#if defined (DEBUG)
{
Expand All @@ -10628,7 +10617,6 @@ BOOL scrPursueResearch(void)
}
#endif
}

scrFunctionResult.v.bval = found;
if (!stackPushResult(VAL_BOOL, &scrFunctionResult))
{
Expand Down

0 comments on commit ccb286c

Please sign in to comment.