Animal Placement

Now i completely agree with that. So the code above does just that?

Sorry, should have been more precise. That code should replace the code in canBuild.

EDIT: Darn! I noticed it still uses isAdjacentPlotGroupConnectedBonus when it should be isPlotGroupConnectedBonus. :mad:
This code should be the correct one:
Spoiler :
Code:
	plot = CyMap.plot(iX, iY)
	bonusHorse = gc.getInfoTypeForString("BONUS_HORSE")
	bonusCow = gc.getInfoTypeForString("BONUS_COW")
	bonusDeer = gc.getInfoTypeForString("BONUS_DEER")
	bonusPig = gc.getInfoTypeForString("BONUS_PIG")
	bonusSheep = gc.getInfoTypeForString("BONUS_SHEEP")
	bonusFur = gc.getInfoTypeForString("BONUS_FUR")
	bonusIvory = gc.getInfoTypeForString("BONUS_IVORY")
		
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusHorse) and plot.getBonusType() != bonusHorse:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusCow) and plot.getBonusType() != bonusCow:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusDeer) and plot.getBonusType() != bonusDeer:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusPig) and plot.getBonusType() != bonusPig:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusSheep) and plot.getBonusType() != bonusSheep:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusFur) and plot.getBonusType() != bonusFur:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusIvory) and plot.getBonusType() != bonusIvory:
			return 1
		else:
			return 0
 
Sorry, should have been more precise. That code should replace the code in canBuild.

EDIT: Darn! I noticed it still uses isAdjacentPlotGroupConnectedBonus when it should be isPlotGroupConnectedBonus. :mad:
This code should be the correct one:
Spoiler :
Code:
	plot = CyMap.plot(iX, iY)
	bonusHorse = gc.getInfoTypeForString("BONUS_HORSE")
	bonusCow = gc.getInfoTypeForString("BONUS_COW")
	bonusDeer = gc.getInfoTypeForString("BONUS_DEER")
	bonusPig = gc.getInfoTypeForString("BONUS_PIG")
	bonusSheep = gc.getInfoTypeForString("BONUS_SHEEP")
	bonusFur = gc.getInfoTypeForString("BONUS_FUR")
	bonusIvory = gc.getInfoTypeForString("BONUS_IVORY")
		
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusHorse) and plot.getBonusType() != bonusHorse:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusCow) and plot.getBonusType() != bonusCow:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusDeer) and plot.getBonusType() != bonusDeer:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusPig) and plot.getBonusType() != bonusPig:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusSheep) and plot.getBonusType() != bonusSheep:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusFur) and plot.getBonusType() != bonusFur:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusIvory) and plot.getBonusType() != bonusIvory:
			return 1
		else:
			return 0

Since i used this code, ALL of my settlers no matter what civ i play freezes when trying to start the game?:(

Even on a game i had started before it freezes right away even the ingame already started.

I took out that one in your post above and replaced it with the older one and it does NOT freeze?


But i dont like where i had a resource that i have and can place these AP resources anyplace, and overrides the other resource, not good.



EDIT: Is thing line correct?

plot = CyMap.plot(iX, iY)

or should it be:

pPlot = CyMap().plot(iX, iY)


EDIT EDIT: ok I used what i have above: pPlot = CyMap().plot(iX, iY)

and at least the settler didnt freeze

but now i get this:

Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 67, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 72, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 77, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 82, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 87, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 92, in canBuild
NameError: global name 'plot' is not defined
Traceback (most recent call last):
File "BugGameUtils", line 342, in callHandler
File "AnimalPlacing", line 97, in canBuild
NameError: global name 'plot' is not defined
 
It turns out that except for the TXT and the being able to place horses on horses etc that the code I posted acutally worked! i have even replaced all isAdjacentPlotGroupConnectedBonus with isPlotGroupConnectedBonus. Also SO I had changed the name around in the slaves mod to get the game text working so don't know why I missed that here.

Edit: it should have been
Code:
and pPlot.getBonusType() != bonusHorse

in NotSoGood's code not
Code:
and plot.getBonusType() != bonusHorse

No that does not work either I get
Code:
Traceback (most recent call last):
  File "BugGameUtils", line 342, in callHandler
  File "AnimalPlacing", line 67, in canBuild
ArgumentError: Python argument types in
    CyPlot.getBonusType(CyPlot)
did not match C++ signature:
    getBonusType(class CyPlot {lvalue}, int)
Traceback (most recent call last):

Edit 2: we still need to add in these actions for the other "worker" units like clones et al.

Edit 3: yes it slows the game down - that is what PythonCallBacks do. ;)
 
:mad: I thought that code was fixed. :mad:
Lets try again, this one should work without problems, mayby little faster but I don't know if it's possible to notice it:
Spoiler :
Code:
	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		bonusHorse = gc.getInfoTypeForString("BONUS_HORSE")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusHorse) and plot.getBonusType(player.getTeam()) != bonusHorse:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		bonusCow = gc.getInfoTypeForString("BONUS_COW")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusCow) and plot.getBonusType(player.getTeam()) != bonusCow:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		bonusDeer = gc.getInfoTypeForString("BONUS_DEER")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusDeer) and plot.getBonusType(player.getTeam()) != bonusDeer:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		bonusPig = gc.getInfoTypeForString("BONUS_PIG")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusPig) and plot.getBonusType(player.getTeam()) != bonusPig:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		bonusSheep = gc.getInfoTypeForString("BONUS_SHEEP")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusSheep) and plot.getBonusType(player.getTeam()) != bonusSheep:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		bonusFur = gc.getInfoTypeForString("BONUS_FUR")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusFur) and plot.getBonusType(player.getTeam()) != bonusFur:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		bonusIvory = gc.getInfoTypeForString("BONUS_IVORY")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusIvory) and plot.getBonusType(player.getTeam()) != bonusIvory:
			return 1
		else:
			return 0
 
:mad: I thought that code was fixed. :mad:
Lets try again, this one should work without problems, mayby little faster but I don't know if it's possible to notice it:
Spoiler :
Code:
	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		bonusHorse = gc.getInfoTypeForString("BONUS_HORSE")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusHorse) and plot.getBonusType(player.getTeam()) != bonusHorse:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		bonusCow = gc.getInfoTypeForString("BONUS_COW")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusCow) and plot.getBonusType(player.getTeam()) != bonusCow:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		bonusDeer = gc.getInfoTypeForString("BONUS_DEER")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusDeer) and plot.getBonusType(player.getTeam()) != bonusDeer:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		bonusPig = gc.getInfoTypeForString("BONUS_PIG")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusPig) and plot.getBonusType(player.getTeam()) != bonusPig:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		bonusSheep = gc.getInfoTypeForString("BONUS_SHEEP")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusSheep) and plot.getBonusType(player.getTeam()) != bonusSheep:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		bonusFur = gc.getInfoTypeForString("BONUS_FUR")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusFur) and plot.getBonusType(player.getTeam()) != bonusFur:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		bonusIvory = gc.getInfoTypeForString("BONUS_IVORY")
		if plot.isPlotGroupConnectedBonus(iPlayer, bonusIvory) and plot.getBonusType(player.getTeam()) != bonusIvory:
			return 1
		else:
			return 0


Nope didnt work, i can STILL build over other resources:(
 
Hmm, I never thought about that. I think it should prevent you from placing the bonuses over other bonuses. Currently it just prevents you to spam the same resource if it already excists on the plot.
Was that what you were thinking?

Yeah both of these will work great together then, if thats ok.
 
Okay, this code should prevent you from placing the bonuses over other bonuses:
Spoiler :
Code:
	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_HORSE")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_COW")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_DEER")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_PIG")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_SHEEP")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_FUR")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_IVORY")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
 
ehmm... i think you should swap the ifs in your code... first check if there is a resource on a tile and then set the iBuild... will be more efficient and shorten up the code.

EDIT: sry, nvm. i misunderstood your code.
however you could generalize your code somewhat when you make the bonus names into a variable list. then you can reduce the redundancy in the code. but i don't know python commands for string operations so i can't give you the code.

EDIT2: with some help of the internet:
Code:
plot = CyMap().plot(iX, iY)
player = gc.getPlayer(iPlayer)
	
sBonusName = ["BONUS_HORSE","BONUS_COW"]
for n in range (0,1):
	if iBuild == gc.getInfoTypeForString("BUILD_"+ sBonusName[n]):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString(sBonusName[n])) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
just wrote it down here. so no warranty its bug free.
 
Okay, this code should prevent you from placing the bonuses over other bonuses:
Spoiler :
Code:
	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if iBuild == gc.getInfoTypeForString("BUILD_BONUS_HORSE"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_HORSE")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_COW"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_COW")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_DEER"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_DEER")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_PIG"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_PIG")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_SHEEP"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_SHEEP")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_FUR"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_FUR")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
	elif iBuild == gc.getInfoTypeForString("BUILD_BONUS_IVORY"):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString("BONUS_IVORY")) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0


OK the code works, WHEN the bonus is already been acquired, but like in the pic, i have not yet founded sulphur so it does NOT show up yet, but i still can build a horse on it, thus removing the sulphur, which i will need BADLY when Gunpowder tech is founded.:(:(
 
ehmm... i think you should swap the ifs in your code... first check if there is a resource on a tile and then set the iBuild... will be more efficient and shorten up the code.

EDIT: sry, nvm. i misunderstood your code.
however you could generalize your code somewhat when you make the bonus names into a variable list. then you can reduce the redundancy in the code. but i don't know python commands for string operations so i can't give you the code.

EDIT2: with some help of the internet:
Code:
plot = CyMap().plot(iX, iY)
player = gc.getPlayer(iPlayer)
	
sBonusName = ["BONUS_HORSE","BONUS_COW"]
for n in range (0,1):
	if iBuild == gc.getInfoTypeForString("BUILD_"+ sBonusName[n]):
		if plot.isPlotGroupConnectedBonus(iPlayer, gc.getInfoTypeForString(sBonusName[n])) and plot.getBonusType(player.getTeam()) == -1:
			return 1
		else:
			return 0
just wrote it down here. so no warranty its bug free.

You mean something like this?
Spoiler :
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2006
## 
## Animal Placing - placing of an animal resource on the map. 


from CvPythonExtensions import *
import CvUtil
import sys
import BugUtil
import PyHelpers
#~ import CvEventInterface
#~ import CvWorldBuilderScreen

# globals
gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo

g_aiAnimalPlacementRules = []

def onGameStart(argList);
	asAnimalRules = [
	['IMPROVEMENT_BONUS_HORSE', 'BONUS_HORSE', 'BUILD_BONUS_HORSE'],
	['IMPROVEMENT_BONUS_COW', 'BONUS_COW', 'BUILD_BONUS_COW'],
	['IMPROVEMENT_BONUS_DEER', 'BONUS_DEER', 'BUILD_BONUS_DEER'],
	['IMPROVEMENT_BONUS_PIG', 'BONUS_PIG', 'BUILD_BONUS_PIG'],
	['IMPROVEMENT_BONUS_SHEEP', 'BONUS_SHEEP', 'BUILD_BONUS_SHEEP'],
	['IMPROVEMENT_BONUS_FUR', 'BONUS_FUR', 'BUILD_BONUS_FUR'],
	['IMPROVEMENT_BONUS_IVORY', 'BONUS_IVORY', 'BUILD_BONUS_IVORY'],
	]
	# Convert these into integers for speed when used in game
	BugUtil.debug("Animals placement definitions:-")
	g_aiAnimalPlacementRules = []
	for i in range(asAnimalRules.__len__()):
		iImprovement = gc.getInfoTypeForString(asSubdueRules[i][0])
		iBonus = gc.getInfoTypeForString(asSubdueRules[i][1])
		iBUild = gc.getInfoTypeForString(asSubdueRules[i][2])
		BugUtil.debug("Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBUild)
		if (iImprovement >= 0 ) and (iBonus >= 0) and (iBUild > = 0):
			g_aiAnimalPlacementRules.append([iImprovement, iBonus, iBUild])
		else:
			BugUtil.warn("Bad Rule. Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBUild)


###################################################

def onImprovementBuilt(argsList):
	'Improvement Built'
	iImprovement, iX, iY = argsList
	# NotSoGood start
	pPlot = CyMap().plot(iX, iY)
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iImprovement == g_aiAnimalPlacementRules[i][0]:
			pPlot.setImprovementType(-1)
			pPlot.setBonusType(g_aiAnimalPlacementRules[i][1])
			return
	# NotSoGood end
	

def canBuild(argsList):
	iX, iY, iBuild, iPlayer = argsList
	# NotSoGood start

	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if plot.getBonusType(player.getTeam()) == -1:
		return 1
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iBuild == g_aiAnimalPlacementRules[i][2]:
		if plot.isPlotGroupConnectedBonus(iPlayer, g_aiAnimalPlacementRules[i][1]) and :
			return 1
		else:
			return 0
	# NotSoGood end
	return -1	# Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can
I also only just wrote it down so there is no reason to expect it is bug free. Note I test for something on the plot and exit before I test for these improvements, giving a slight speed improvement. As is the bit that converts the strings to integers first. I also have the XML done for clones etc. so as soon as I test this I will post the code.

StrategyOnly has a point in that this overwrites unknown resources. If we stop it doing that people will complain of a bug because they will not be able to place animals where they like :crazyeye:
 
You mean something like this?
Spoiler :
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2006
## 
## Animal Placing - placing of an animal resource on the map. 


from CvPythonExtensions import *
import CvUtil
import sys
import BugUtil
import PyHelpers
#~ import CvEventInterface
#~ import CvWorldBuilderScreen

# globals
gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo

g_aiAnimalPlacementRules = []

def onGameStart(argList);
	asAnimalRules = [
	['IMPROVEMENT_BONUS_HORSE', 'BONUS_HORSE', 'BUILD_BONUS_HORSE'],
	['IMPROVEMENT_BONUS_COW', 'BONUS_COW', 'BUILD_BONUS_COW'],
	['IMPROVEMENT_BONUS_DEER', 'BONUS_DEER', 'BUILD_BONUS_DEER'],
	['IMPROVEMENT_BONUS_PIG', 'BONUS_PIG', 'BUILD_BONUS_PIG'],
	['IMPROVEMENT_BONUS_SHEEP', 'BONUS_SHEEP', 'BUILD_BONUS_SHEEP'],
	['IMPROVEMENT_BONUS_FUR', 'BONUS_FUR', 'BUILD_BONUS_FUR'],
	['IMPROVEMENT_BONUS_IVORY', 'BONUS_IVORY', 'BUILD_BONUS_IVORY'],
	]
	# Convert these into integers for speed when used in game
	BugUtil.debug("Animals placement definitions:-")
	g_aiAnimalPlacementRules = []
	for i in range(asAnimalRules.__len__()):
		iImprovement = gc.getInfoTypeForString(asSubdueRules[i][0])
		iBonus = gc.getInfoTypeForString(asSubdueRules[i][1])
		iBUild = gc.getInfoTypeForString(asSubdueRules[i][2])
		BugUtil.debug("Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBUild)
		if (iImprovement >= 0 ) and (iBonus >= 0) and (iBUild > = 0):
			g_aiAnimalPlacementRules.append([iImprovement, iBonus, iBUild])
		else:
			BugUtil.warn("Bad Rule. Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBUild)


###################################################

def onImprovementBuilt(argsList):
	'Improvement Built'
	iImprovement, iX, iY = argsList
	# NotSoGood start
	pPlot = CyMap().plot(iX, iY)
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iImprovement == g_aiAnimalPlacementRules[i][0]:
			pPlot.setImprovementType(-1)
			pPlot.setBonusType(g_aiAnimalPlacementRules[i][1])
			return
	# NotSoGood end
	

def canBuild(argsList):
	iX, iY, iBuild, iPlayer = argsList
	# NotSoGood start

	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	if plot.getBonusType(player.getTeam()) == -1:
		return 1
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iBuild == g_aiAnimalPlacementRules[i][2]:
		if plot.isPlotGroupConnectedBonus(iPlayer, g_aiAnimalPlacementRules[i][1]) and :
			return 1
		else:
			return 0
	# NotSoGood end
	return -1	# Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can
I also only just wrote it down so there is no reason to expect it is bug free. Note I test for something on the plot and exit before I test for these improvements, giving a slight speed improvement. As is the bit that converts the strings to integers first. I also have the XML done for clones etc. so as soon as I test this I will post the code.

yeah, that looks good. if you use the + operator for strings you can shorten it up a bit so you don't need the three of these 'IMPROVEMENT_BONUS_HORSE', 'BONUS_HORSE', 'BUILD_BONUS_HORSE' for one resource. (so you can write "BUILD_" + asSubdueRules)

it's no big deal to write code in a well structured way; the code is easier readable and reusable for other modders. it's just that when i look at some functions in the dll source code... they all look like everyone added his part to it and no one ever cleaned it up. (e.g. city AI has a something about 2000 lines of code to decide what it builds next in a city and no one fully understands what this code does. making any improvements to such functions now cost a lot of time.)

StrategyOnly has a point in that this overwrites unknown resources. If we stop it doing that people will complain of a bug because they will not be able to place animals where they like :crazyeye:

true.

fast solution:
display the 'build horses' button for invisible resources tiles but if someone attempts it display a message that this terrain is not habitable for horses.

good/complicated solution:
allow to replace the iron with horses. but when you when you can see iron, the iron will replace the horses back. (requires to store additional data in a tile)
 
yeah, that looks good. if you use the + operator for strings you can shorten it up a bit so you don't need the three of these 'IMPROVEMENT_BONUS_HORSE', 'BONUS_HORSE', 'BUILD_BONUS_HORSE' for one resource. (so you can write "BUILD_" + asSubdueRules)


Except I am only using them for this function (onGameStart) then converting them to integers so that I only use the getInfoTypeForString function at game start not multiple times every turn and player. So readability is better this way. And it should have been asAnimalRules not asSubdueRules - see I said it probably was bad code:p.


good/complicated solution:
allow to replace the iron with horses. but when you when you can see iron, the iron will replace the horses back. (requires to store additional data in a tile)

Needs to keep the information in the saves also, which I now know how to do. which means a load function as well.
 
OK which is which here guys, i need to test as much as i can with the best one out there right now, thx.

On the above by Dancing H,(http://forums.civfanatics.com/showpost.php?p=9278015&postcount=71) i got these errors:

Traceback (most recent call last):
File "BugConfig", line 110, in unknown_endtag
File "BugConfig", line 334, in endChild
File "BugConfig", line 337, in end
File "BugConfig", line 318, in process
File "BugConfig", line 565, in handle
File "BugUtil", line 642, in getFunction
File "BugUtil", line 629, in lookupFunction
File "BugUtil", line 621, in lookupModule
File "<string>", line 35, in load_module
File "<string>", line 13, in _get_code
File "AnimalPlacing", line 23

def onGameStart(argList);

^

SyntaxError: invalid syntax
 
It is not ready at all yet. Currently it is letting me scrub fallout from day one.

That's because you have the check in canBuild if the plot has no bonuses you can build what ever you want.
Code:
def canBuild(argsList):
	iX, iY, iBuild, iPlayer = argsList
	# NotSoGood start

	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	[COLOR="Red"]if plot.getBonusType(player.getTeam()) == -1:
		return 1[/COLOR]
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iBuild == g_aiAnimalPlacementRules[i][2]:
		if plot.isPlotGroupConnectedBonus(iPlayer, g_aiAnimalPlacementRules[i][1]) and :
			return 1
		else:
			return 0
	# NotSoGood end
I fixed some syntax errors in your code but when testing it doesn't have any effects. No errors, no bonus placing.
Spoiler :
This is the code I edited a little, it's possible and very likely that I have done something wrong:
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2006
## 
## Animal Placing - placing of an animal resource on the map. 


from CvPythonExtensions import *
import CvUtil
import sys
import BugUtil
import PyHelpers
#~ import CvEventInterface
#~ import CvWorldBuilderScreen

gc = CyGlobalContext()
localText = CyTranslator()
#~ PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo

g_aiAnimalPlacementRules = []

# globals
def onGameStart(argList):
	asAnimalRules = [
	['IMPROVEMENT_BONUS_HORSE', 'BONUS_HORSE', 'BUILD_BONUS_HORSE'],
	['IMPROVEMENT_BONUS_COW', 'BONUS_COW', 'BUILD_BONUS_COW'],
	['IMPROVEMENT_BONUS_DEER', 'BONUS_DEER', 'BUILD_BONUS_DEER'],
	['IMPROVEMENT_BONUS_PIG', 'BONUS_PIG', 'BUILD_BONUS_PIG'],
	['IMPROVEMENT_BONUS_SHEEP', 'BONUS_SHEEP', 'BUILD_BONUS_SHEEP'],
	['IMPROVEMENT_BONUS_FUR', 'BONUS_FUR', 'BUILD_BONUS_FUR'],
	['IMPROVEMENT_BONUS_IVORY', 'BONUS_IVORY', 'BUILD_BONUS_IVORY'],
	]
	# Convert these into integers for speed when used in game
	BugUtil.debug("Animals placement definitions:-")
	g_aiAnimalPlacementRules = []
	for i in range(asAnimalRules.__len__()):
		iImprovement = gc.getInfoTypeForString(asAnimalRules[i][0])
		iBonus = gc.getInfoTypeForString(asAnimalRules[i][1])
		iBuild = gc.getInfoTypeForString(asAnimalRules[i][2])
		BugUtil.debug("Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBuild)
		if (iImprovement >= 0 ) and (iBonus >= 0) and (iBuild >= 0):
			g_aiAnimalPlacementRules.append([iImprovement, iBonus, iBuild])
		else:
			BugUtil.warn("Bad Rule. Improvement %s (%d) bonus %s (%d) build %s (%d).", asAnimalRules[i][0],  iImprovement, asAnimalRules[i][1], iBonus, asAnimalRules[i][2], iBuild)


###################################################

def onImprovementBuilt(argsList):
	'Improvement Built'
	iImprovement, iX, iY = argsList
	# NotSoGood start
	pPlot = CyMap().plot(iX, iY)
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iImprovement == g_aiAnimalPlacementRules[i][0]:
			pPlot.setImprovementType(-1)
			pPlot.setBonusType(g_aiAnimalPlacementRules[i][1])
			return
	# NotSoGood end


def canBuild(argsList):
	iX, iY, iBuild, iPlayer = argsList
	# NotSoGood start

	plot = CyMap().plot(iX, iY)
	player = gc.getPlayer(iPlayer)
	
	for i in range(g_aiAnimalPlacementRules.__len__()):
		if iBuild == g_aiAnimalPlacementRules[i][2]:
			if plot.isPlotGroupConnectedBonus(iPlayer, g_aiAnimalPlacementRules[i][1]) and plot.getBonusType(player.getTeam()) == -1:
				return 1
			else:
				return 0
	# NotSoGood end
	return -1	# Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can
 
Yes I fixed it in mine also but the onGameStart debug messages are not being displayed/printed which means that there is nothing in the arrays. But It seems to mean that everything is failing instead of just the.....
 
Back
Top Bottom