[PYTHON] How to python code the palace to give random resources?

Miuna

Chieftain
Joined
Jul 29, 2020
Messages
13
Hi

I am wondering if there is a way to make the palace give random resources settling (out of a set pool)?
So, the intention i have is actually for the mod "Fall from Heaven" which uses "mana" as resources, i want a palace to distribute 3 of these at random, but for generalisation sake, "mana" are basically just a resources (think like gold or gems from the main game if you will) which provide access to spells and abilities, but in the simplest form, think of them as just another resource.

I was making a new civ which is heavily built on a random function, in the Fall from heaven, all civs start with 3 mana (fixed), I was wondering if instead of using 3 fixed resources, it would be possible to generate these at random.

I am learning some basic python but my trials have yet to yield result, i was wondering if someone could assist in this. I could associate this with either a trait or palace so lock it to certain leaders only and possibly to make it easier for the game to understand as i only want this to affect one civ. This doesn't have to reflect the Fall from heaven stuff specifically as the general use would just require the changing of the resource as a sole entity.


Side note:

I did some researching around and did find a seperate mod which used a similar function with the following code
Code:
       if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_IMPERIALIST")) and city.isCapital():
           Bonus = [gc.getInfoTypeForString("BONUS_GEMS"), gc.getInfoTypeForString("BONUS_SILVER"), gc.getInfoTypeForString("BONUS_GOLD")]
           LuxuryPlot = []
           for i in xrange(21):
               pPlot = city.getCityIndexPlot(i)
               if pPlot.getBonusType(-1) == -1:
                   if not pPlot.isPeak() and not pPlot.isWater() and not pPlot.isCity():
                       LuxuryPlot.append(pPlot)
           if len(LuxuryPlot) > 0:
               pPlot = LuxuryPlot[CyGame().getSorenRandNum(len(LuxuryPlot), "where")]
               pPlot.setBonusType(Bonus[CyGame().getSorenRandNum(3, "which")])
           else:
               pPlot = city.plot()
               if pPlot.getBonusType(-1) == -1:
                   pPlot.setBonusType(Bonus[CyGame().getSorenRandNum(3, "which")])
               else:
                   city.changeFreeBonus(Bonus[CyGame().getSorenRandNum(3, "which")], 1)"

           if pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_IMPERIALIST")):
               pCapital = pPlayer.getCity(0)
               Bonus = [gc.getInfoTypeForString("BONUS_GEMS"), gc.getInfoTypeForString("BONUS_SILVER"), gc.getInfoTypeForString("BONUS_GOLD")]
               LuxuryPlot = []
               for i in xrange(21):
                   pPlot = pCapital.getCityIndexPlot(i)
                   if pPlot.getBonusType(-1) == -1:
                       if not pPlot.isPeak() and not pPlot.isWater() and not pPlot.isCity():
                           LuxuryPlot.append(pPlot)
               if len(LuxuryPlot) > 0:
                   pPlot = LuxuryPlot[CyGame().getSorenRandNum(len(LuxuryPlot), "where")]
                   pPlot.setBonusType(Bonus[CyGame().getSorenRandNum(3, "which")])
               else:
                   pPlot = pCapital.plot()
                   if pPlot.getBonusType(-1) == -1:
                       pPlot.setBonusType(Bonus[CyGame().getSorenRandNum(3, "which")])
                   else:
                       pCapital.changeFreeBonus(Bonus[CyGame().getSorenRandNum(3, "which")], 1)

I tried adapting this for my own uses by changing the resources and the trait required but sadly this didn't yield much result after some trial and error. Sadly i have little understanding to the above code, so its pretty troublesome to adapt (its equally possible it was designed for a specific use within a mod and adapting it isn't ethical.)

TLDR; Does anyone know a python code which would generate 3 random resources from the palace at the start of each game (randomly every game)?
(I understand i would need to set these values for the resources, for exmaple; "Bonus = [gc.getInfoTypeForString("BONUS_MANA_AIR"), gc.getInfoTypeForString("BONUS_MANA_BODY"), gc.getInfoTypeForString("BONUS_MANA_CHAOS")," etc.

It would be greatly appreciated with some help on this one, making the resources random is one of my final steps to finishing and its thrown me for days with no progress.
 
you're lucky I just have a look here to learn the sdk part of civ IV.
so I can help you. for each palace, do you want just one of those three resources per palace or do want up to this three resources per palace?

the code above adds the bonus on the plot. A building can only have 1 bonus but with endless amount (standard 1). So to have more than one resources per palace, you have to add at least two more resouces to the plots around the starting plot (or first city).

And remember to give access to the bonus resource via improvement (XML)!
 
Last edited:
I just realized sthg. If you don't want bonus resources on plots (what is bad, when your capital is razed)! Create Buildings (BuildingClass, BuildingInfos) where you get 1 FreeBonus. With python you can add those buildings to your capital.
but it's bad, when your capital is razed, so you should place this info to ScriptData (Plot).

Another plan: you give all new cities (onCityFound) these buildings. (dep. on random from founding the first city). then you can copy these buildings from city(0) when founding new ones.
 
Top Bottom