CvTeamAI::AI_permanentAllianceTrade

cotdamn

Chieftain
Joined
Nov 30, 2005
Messages
50
In CvTeamAI::AI_permanentAllianceTrade:

Code:
if ((getPower(true) + GET_TEAM(eTeam).getPower(true)) > (GC.getGameINLINE().countTotalCivPower() / 2))
	{
		if (getPower(true) > GET_TEAM(eTeam).getPower(true))
		{
			return DENIAL_POWER_US;
		}
		else
		{
			return DENIAL_POWER_YOU;
		}
	}


How could I change this code to make it so that the average (total power divided by number of members) power of the resulting team has to be greater than the power of the potential new member?

For example: team 1 has players 1, 2, and 3. their average power is 500, player 4 has a power of 450, so he may potentially join team 1, however player 5 has a power of 550 so there is no chance of him joining until team 1 has an average power higher than 550.

thanks,
cotdamn
 
any ideas on this? the main thing i need to figure out is how to divide the power of a team, by the number of players on the team. the reason i want to do it this way is that my mod will allow for unlimited number of players on a team, so long as the players joining are weaker than the average of the team.
 
Do you want to limit the AI from doing this, or everyone? The function you mention is only checked if it's the AI that is to be offered it, not if someone offer it to a human.

Dividing the power by the number of players is easy. getPower(true) / getNumMembers(). That true means vassals are included, set it to false if you don't want them to count.
 
Do you want to limit the AI from doing this, or everyone? The function you mention is only checked if it's the AI that is to be offered it, not if someone offer it to a human.

I want this to work for the just the AI, but I also want the AI to be limited by this when asking other AI players to join their team.


If i replaced the code in the OP with the below, would I be on the right track?

Code:
if (getPower(true) > (GET_TEAM(eTeam).getPower(true))/getNumMembers())
	{
		
			return DENIAL_POWER_US;
		
	}

thanks
 
You are dividing the power of the other team with the number of members on this team. This should be what you want:
Code:
if (getPower(true) > (GET_TEAM(eTeam).getPower(true))/GET_TEAM(eTeam).getNumMembers())
{
	return DENIAL_POWER_US;
}

The problem with your solution is either side can be the one making the offer. Imagine this situation: team 1 has two players, average power 500. Team 2 has one member, power 1500. Team 1 can't offer alliance to team 2 (team 2 power > team 1 average power). But team 2 CAN offer alliance to team 1 (team 2 average power > team 1 power).

I can think of two ways to solve that.
The quick - prevent the team with the fewer members from making the offer. Problem: Players (humans) in smaller alliances can't offer to AI in larger alliance. Doesn't have to be a problem, perhaps you want the larger alliance to "choose" who to offer alliance to and not the other way around. (I say "choose" because if everything else is acceptable ultimatly a random number decides if the AI offer it or not.)

The longer - First check which team is larger, then check if the average of this team is more than the total of the other team.
 
Back
Top Bottom