Skip to content

Commit

Permalink
Fix desynch on offering an AI an alliance.
Browse files Browse the repository at this point in the history
Only triggers in the rarely-used 'Allow Alliances' game mode, in games with AIs. When
offering an AI an alliance, the AI would sometimes accept instantly, and the acceptance
was not synchronised.
  • Loading branch information
Cyp committed Feb 4, 2012
1 parent 415f6fe commit b4f24bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/astar.cpp
Expand Up @@ -295,7 +295,6 @@ static inline void fpathNewNode(PathfindContext &context, PathCoord dest, PathCo
// The distance gradient is now known to be somewhere between the direction from A to P and the direction from B to P.
static const uint8_t gradYLookup[99] = {140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 139, 139, 139, 139, 139, 139, 139, 139, 139, 138, 138, 138, 138, 138, 138, 137, 137, 137, 137, 137, 136, 136, 136, 136, 135, 135, 135, 134, 134, 134, 134, 133, 133, 133, 132, 132, 132, 131, 131, 130, 130, 130, 129, 129, 128, 128, 127, 127, 126, 126, 126, 125, 125, 124, 123, 123, 122, 122, 121, 121, 120, 119, 119, 118, 118, 117, 116, 116, 115, 114, 113, 113, 112, 111, 110, 110, 109, 108, 107, 106, 106, 105, 104, 103, 102, 101, 100};
int gradientY = gradYLookup[gradientX]; // = sqrt(140² - gradientX²), rounded to nearest integer
//int gradientY = iSqrt(70*70 - gradientX*gradientX); // TODO Faster to use a (small, 50 entries) lookup table?
unsigned distP = gradientY*costFactor + distB;
node.est -= node.dist - distP;
node.dist = distP;
Expand Down Expand Up @@ -619,7 +618,7 @@ void fpathSetBlockingMap(PATHJOB *psJob)
for (int x = 0; x < mapWidth; ++x)
{
dangerMap[x + y*mapWidth] = auxTile(x, y, type.owner) & AUXBITS_THREAT;
checksumDangerMap ^= map[x + y*mapWidth]*(factor = 3*factor + 1);
checksumDangerMap ^= dangerMap[x + y*mapWidth]*(factor = 3*factor + 1);
}
}
syncDebug("blockingMap(%d,%d,%d,%d) = %08X %08X", gameTime, psJob->propulsion, psJob->owner, psJob->moveType, checksumMap, checksumDangerMap);
Expand Down
9 changes: 3 additions & 6 deletions src/multigifts.cpp
Expand Up @@ -349,6 +349,7 @@ void requestAlliance(uint8_t from, uint8_t to, bool prop, bool allowAudio)
return; // Wait for our message.
}

syncDebug("Request alliance %d %d", from, to);
alliances[from][to] = ALLIANCE_REQUESTED; // We've asked
alliances[to][from] = ALLIANCE_INVITATION; // They've been invited

Expand Down Expand Up @@ -397,6 +398,7 @@ void breakAlliance(uint8_t p1, uint8_t p2, bool prop, bool allowAudio)
}
}

syncDebug("Break alliance %d %d", p1, p2);
alliances[p1][p2] = ALLIANCE_BROKEN;
alliances[p2][p1] = ALLIANCE_BROKEN;
alliancebits[p1] &= ~(1 << p2);
Expand All @@ -421,6 +423,7 @@ void formAlliance(uint8_t p1, uint8_t p2, bool prop, bool allowAudio, bool allow
CONPRINTF(ConsoleString,(ConsoleString,_("%s Forms An Alliance With %s"),tm1,getPlayerName(p2)));
}

syncDebug("Form alliance %d %d", p1, p2);
alliances[p1][p2] = ALLIANCE_FORMED;
alliances[p2][p1] = ALLIANCE_FORMED;
if (game.alliance == ALLIANCES_TEAMS) // this is for shared vision only
Expand Down Expand Up @@ -491,19 +494,13 @@ bool recvAlliance(NETQUEUE queue, bool allowAudio)
case ALLIANCE_NULL:
break;
case ALLIANCE_REQUESTED:
turnOffMultiMsg(true);
requestAlliance(from, to, false, allowAudio);
turnOffMultiMsg(false);
break;
case ALLIANCE_FORMED:
turnOffMultiMsg(true);
formAlliance(from, to, false, allowAudio, true);
turnOffMultiMsg(false);
break;
case ALLIANCE_BROKEN:
turnOffMultiMsg(true);
breakAlliance(from, to, false, allowAudio);
turnOffMultiMsg(false);
break;
default:
debug(LOG_ERROR, "Unknown alliance state recvd.");
Expand Down

0 comments on commit b4f24bf

Please sign in to comment.