Mod Request - Inter-AI diplomacy

Mylon

Amateur Game Designer
Joined
Nov 4, 2005
Messages
1,013
I would greatly appreciate it if someone would write a mod so the AIs would conduct diplomacy with one another. Specifically trading and making gift/tribute requests. Perhaps more importantly, is that all of the appropriate modifiers go along with these.

The AIs get along very well together and this is mostly because they never trade/demand tribute with one another and never get those "You refused to give us tribute" and "You traded with our worst enemy" modifiers which really tick other civs off and make them declare war.

I imagine this would ramp up difficulty a bit, but the extra wars would make the game more fun.
 
Well I haven't had too much luck. Using a fresh slate I edited CvEventManager.py to include this:

Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList

#               Make a list of valid AI players
                PlayerList = []
		for i in range(gc.getMAX_CIV_PLAYERS()):
			if (gc.getPlayer(i).isAlive()):
				loopPlayer = PyPlayer(gc.getPlayer(i).getID())
				if (loopPlayer.isNone() or not loopPlayer.isAlive() or gc.getPlayer(i).isHuman()):
					continue
				else:
					PlayerList.append(loopPlayer.getID())

#               Make a list of valid AI Teams
                TeamList = []
		for i in range(gc.getMAX_CIV_PLAYERS()):
			if (gc.getPlayer(i).isAlive()):
				loopPlayer = PyPlayer(gc.getPlayer(i).getID())
				if (loopPlayer.isNone() or not loopPlayer.isAlive()):
					continue
				else:
                                    if not gc.getPlayer(i).getTeam() in TeamList:
					PlayerList.append(gc.getPlayer(i).getTeam())

#               First make sure this player is an AI:
                if not gc.getPlayer(iPlayer).isHuman():
#                  This set makes the AIs demand each other to stop trading.
#                   Pick two teams to demand that trading ceases.
                    iTarget1 = PlayerList[CyRandom().get(len(PlayerList), "Get a random number.")]
                    iTarget2 = TeamList[CyRandom().get(len(TeamList), "Get a random number.")]
#                   Check for trading.
                    if gc.getPlayer(iTarget1).canStopTradingWithTeam(gc.getTeam(iTarget2).getID()):
#                       Determine Yes or No response
                        Response = CyRandom().get(2, "Get a random number.")
#                       If the target accepts, stop trading.  This may or may not trigger reputation as normal.
                        if Reponse == 1:
                            gc.getPlayer(iTarget1).stopTradingWithTeam(gc.getTeam(iTarget2).getID())
#                       If the target refuses, change attitudes appropriately
                        if Reponse == 0:
                            gc.getPlayer(iPlayer).AI_changeAttitudeExtra(iTarget1, -1)

#                   This part tries to make AIs convert each other.
                    iTarget1 = PlayerList[CyRandom().get(len(PlayerList), "Get a random number.")]
                    if not gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isAtWar(gc.getPlayer(iTarget1).getTeam()) and gc.getPlayer(iTarget1).canConvert(gc.getPlayer(iPlayer).getStateReligion()):
                        Response = CyRandom().get(2, "Get a random number.")
                        if Response == 1:
                            gc.getPlayer(iTarget1).convert(gc.getPlayer(iPlayer).getStateReligion())
                            gc.getPlayer(iPlayer).AI_changeAttitudeExtra(iTarget1, 1)
                        if Response == 0:
                            gc.getPlayer(iPlayer).AI_changeAttitudeExtra(iTarget1, -1)

Ideally, every turn an AI should pick a player and simulate the effects of making some silly demand: "Stop trading with X" or "adopt my religion" and modify inter-AI relationships appropriately.

Initially I had a check in the teamlist generating block to also check if the player was human, but that caused a python exception when it came time to pick a random team from the list which suggested the list size was 0. Even more odd was that the exception occured 4 times per turn in a 4 player game. It only should have been called 3 times, because one player (myself) was human so that block should not have been processed for myself.

Anyway, none of the AI seem to be getting disfavorable towards one another, which is a bit of a dissapointment. If anyone else wants to try and troubleshoot my code and help get it working I'd be very grateful.
 
Back
Top Bottom