++ creating a building if you have a resource only in city radius -- help/ideas

cmhwak

Chieftain
Joined
Apr 24, 2006
Messages
40
not sure if the title really explains what im going for very well so ill try to elaborate:

im doing a "colonial/piracy" mod. im wanting there to be a much larger naval element than in vanilla. the main idea is... if you have a sugar bonus(etc), you can create a "sugar warehouse" building. this building doesnt really have any effect on gold or hammers or anything but it will be programmed in python to give a "sugar goods" unit every X amount of turns. this unit is pretty much like a great scientist but only with the ability to build the academy... only it wont be an academy it will be something like a "money vault" which will give an amount of gold. you will have to haul this across the oceans on a boat to your capital which will be the only place this money vault can be built. (the vaults will have to be buildings to get the effect but the concept is that you are obviously just getting money, not creating some kind of vault). so... youll have merchant ships that have to carry these over but the thing is, other civs will be able to capture this ship. the captured ship will turn into a unit similar to the sugar goods but it will just be a generic goods unit. you can build a money vault in your city with this or just use it as another ship if you really want. in that i hope to actually get the element of having to do stuff in the ocean and having to protect merchant ships into the game as well as put more emphasis on bonuses/city location and not just creating cities to gain pop(cities shouldnt be able to easily grow in the mod. eventually they can but not easily - a city not near a resource will be almost pointless.)

i can do this but im not wanting it to be half-arsed. the main problem is... any city connected to a city with sugar(etc) will be able to build that special building. i only want the city right at the sugar to be able to build it. i can just not have roads but id really prefer not to have to do this.

ive yet to come up with a good solution so do any of you have any good specific ideas? do you have a more elegant or simplified way to do what ive proposed? i know very little python so creating some elaborate code is really not going to work.

any help or ideas on this are welcome.
 
Lemme get this straight. You want a resource within the city's radius to MAKE the city generate a unit/item/goods that can be loaded onto a vessel and shipped for gold etc?

Very possible via python only. If you want to learn-while-you-play, download and canibalize some mods, a similar feature is available in greenmod I think with the city radius, though as I remember, it is implemented via python and xml. FfH deals with some real interesting if-then-else abd while loops which help you make and tweak the options you want, in great detail.

Hope this helps.
 
ocedius said:
Lemme get this straight. You want a resource within the city's radius to MAKE the city generate a unit/item/goods that can be loaded onto a vessel and shipped for gold etc?

Very possible via python only. If you want to learn-while-you-play, download and canibalize some mods, a similar feature is available in greenmod I think with the city radius, though as I remember, it is implemented via python and xml. FfH deals with some real interesting if-then-else abd while loops which help you make and tweak the options you want, in great detail.

Hope this helps.


the building is going to create the unit every x turns. i have code to do this. the problem is... without any modification, every city with access to tobacco, for example, will be able to create a tobacco warehouse... even if its some city surrounded by tundra where tobacco wont grow.

i want the process to simulate the goods coming only from that city in effect making city placement a bit more important. so i need something to check and see if a resource is x amount of tiles away or if it has a tobacco plantation or something within its radius for it to be able to build the specific building. ive been through a number of mods and i can mix and match code to get some effects that i want but i do not recall seeing anything dealing with what im trying to do. ill indeed check out green mod since ive yet to do that but i would hope someone has an idea rather than me just having to look at every line of code of every mod. :crazyeye: maybe somoene has done somethign similar and they can just point it out right away or maybe like i said someone has an even simpler idea which ive missed that may not even involve plython.
 
Its easy. In CvGameInterface.py or CvGameUtils.py (or your own gameutils), at the cannotConstruct function (called everytime you select what to build, check a city what can be built etc):

Code:
def cannotConstruct(argslist):
    pCity = argsList[0]
    eBuilding = argsList[1]
    bContinue = argsList[2]
    bTestVisible = argsList[3]
    bIgnoreCost = argsList[4]
    pPlayer = gc.getPlayer(pCity.getOwner())
    
    playerStartCross = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1),
     (-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]

   pCityPlot = pCity.plot()
   iX = pCityPlot.getX()
   iY = pCityPlot.getY()

   cantBuildSugarPlant = True
   cantBuildTobaccoWarehouse = True
   for iiX, iiY in playerStartCross:
       pPlot = CyMap().plot(iX+iiX,iY+iiY)
       if pPlot.getImprovementType() == gc.getInfoTypeForString("IMPROVEMENT_TOBACCO"):
          cantBuildSugarPlant = False
       elif pPlot.getImprovementType() == gc.getInfoTypeForString("IMPROVEMENT_SUGAR"):
          cantBuildSugarPlant = False


   if cantBuildSugarPlant and eBuilding == gc.getInfoTypeForString("BUILDING_SUGAR_PLANT"):
       return True
   if cantBuildTobaccoWarehouse and eBuilding == gc.getInfoTypeForString("BUILDING_TOBACCO_WAREHOUSE"):
       return True

   return False
 
thanks a ton for that. i feel a headache comming on from trying to understand all of it but i will understand it eventually (i hope). i never would have even thought to use either of those.py files for this. ive never looked in them before. thanks again!
 
If someone that understands my code catches a fault in it, please correct it... I was tired when writing it and had to edit it plenty of times cus I forgot something. And I still could have forgotten something.

P.S.
And cmhwak, you will of course have to change the improvement names and building names to whatever you have.
 
Grey Fox said:
If someone that understands my code catches a fault in it, please correct it... I was tired when writing it and had to edit it plenty of times cus I forgot something. And I still could have forgotten something.

P.S.
And cmhwak, you will of course have to change the improvement names and building names to whatever you have.


i created a quick little mod with it and everythign seems to be working exactly as planned. if a sugar plantation is within the city radius, im able to make a sugar warehouse to create my special unit.... i connected another city to the city with the suagr plantation and it could get sugar but it couldnt create the sugar warehouse.

very glad you were able to help here. this was the only really challenging part of the mod and now that im almost done with everything else i needed to do this. i was dreading this part but youve made it way simple.



i understand the code better now but not fully so i have one more question...

if im wanting to add more buildings that require the improvements, would i make the code look like...


(very simplified)
Code:
   cantBuildSugarPlant = True
   cantBuildTobaccoWarehouse = True
   blahblah
  
   if blah
   elif blah
   elif blah
   elif blah


or


Code:
   cantBuildSugarPlant = True
   cantBuildTobaccoWarehouse = True
   blahblah
  
   if blah
   if blah
   if blah
   elif blah

?

i think the first way is correct but i want to make sure im understanding correctly.
 
doesnt matter if its IF or Elif, an IF in this situation would work like an ELIF anyways, since only one of the IF's can be true at a single time.

(An ELIF has to be preceeded by an IF at the beginning though, so its either if,if,if... or if,elif,elif...)
 
Back
Top Bottom