Bazaar developer reference

CvGameQueries::GetTeamClosenessScore(int **, int *)

Defined in
CvGameQueries.cpp, line 141
Class
CvGameQueries
Hook name
CivHooks::CvGameQueries_GetTeamClosenessScore

Hooks

static bool BeforeCvGameQueries_GetTeamClosenessScore(int** aaiDistances, int* aiStartingLocs, int& result);static void AfterCvGameQueries_GetTeamClosenessScore(int** aaiDistances, int* aiStartingLocs, int& result);static int ReplaceCvGameQueries_GetTeamClosenessScore(int (*original)(int**, int*), int** aaiDistances, int* aiStartingLocs);CivRegisterBefore<CivHooks::CvGameQueries_GetTeamClosenessScore>(host, &BeforeCvGameQueries_GetTeamClosenessScore);CivRegisterAfter<CivHooks::CvGameQueries_GetTeamClosenessScore>(host, &AfterCvGameQueries_GetTeamClosenessScore);CivRegisterReplace<CivHooks::CvGameQueries_GetTeamClosenessScore>(host, &ReplaceCvGameQueries_GetTeamClosenessScore);

Code

136// For each of n teams, let the closeness score for that team be the average distance of an edge between two players on that team.137// This function calculates the closeness score for each team and returns the sum of those n scores.138// The lower the result, the better "clumped" the players' starting locations are.139//140// Note: for the purposes of this function, player i will be assumed to start in the location of player aiStartingLocs[i]141int CvGameQueries::GetTeamClosenessScore(int** aaiDistances, int* aiStartingLocs)142{143	int iScore = 0;144145	for(int iTeam = 0; iTeam < MAX_CIV_TEAMS; iTeam++)146	{147		if(GET_TEAM((TeamTypes)iTeam).isAlive())148		{149			int iTeamTotalDist = 0;150			int iNumEdges = 0;151			for(int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; iPlayer++)152			{153				if(GET_PLAYER((PlayerTypes)iPlayer).isAlive())154				{155					if(GET_PLAYER((PlayerTypes)iPlayer).getTeam() == (TeamTypes)iTeam)156					{157						for(int iOtherPlayer = 0; iOtherPlayer < iPlayer; iOtherPlayer++)158						{159							if(GET_PLAYER((PlayerTypes)iOtherPlayer).getTeam() == (TeamTypes)iTeam)160							{161								// Add the edge between these two players that are on the same team162								iNumEdges++;163								int iPlayerStart = aiStartingLocs[iPlayer];164								int iOtherPlayerStart = aiStartingLocs[iOtherPlayer];165166								if(iPlayerStart < iOtherPlayerStart)  // Make sure that iPlayerStart > iOtherPlayerStart167								{168									int iTemp = iPlayerStart;169									iPlayerStart = iOtherPlayerStart;170									iOtherPlayerStart = iTemp;171								}172								else if(iPlayerStart == iOtherPlayerStart)173								{174									CvAssertMsg(false, "Two players are (hypothetically) assigned to the same starting location!");175								}176								iTeamTotalDist += aaiDistances[iPlayerStart][iOtherPlayerStart];177							}178						}179					}180				}181			}182183			int iTeamScore;184			if(iNumEdges == 0)185			{186				iTeamScore = 0;187			}188			else189			{190				iTeamScore = iTeamTotalDist/iNumEdges; // the avg distance between team edges is the team score191			}192193			iScore += iTeamScore;194		}195	}196	return iScore;197}

Calls