• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Quick Modding Questions Thread

Is there any way using Python to make a civilization win the game if they reach a certain population?
 
Is there any way using Python to make a civilization win the game if they reach a certain population?
Yes, it's fairly easy:
Code:
gc = CyGlobalContext()

if gc.getPlayer(<id>).getTotalPopulation() >= <required population>:
    gc.getGame().setWinner(<id>, <victory type>)
The victory type is an integer ID referring to the victory type as defined in Assets/GameInfo/CIV4VictoryInfo.xml. For example, the score victory is ID 0. If you want to have a special population victory (i.e. the game announcing and tracking it as you having reached a population victory specifically) you have to add it to this XML file. You can leave the actual conditions for this victory empty because you are going to trigger it from Python.

I left the part empty how and where you are going to check this. Please look into the Python event manager - you probably want to check it for the BeginGameTurn event.
 
I am using a custom map script with "custom map options", i.e. hooks defined like this:
Code:
def getNumCustomMapOptions():
    # ...

def getCustomMapOptionName(args):
    # ...

def getNumCustomMapOptionValues(args):
    # ...

def getCustomMapOptionDescAt(args):
    # ...

def getCustomMapOptionDefault(args):
    # ...
However, unlike the standard (non-custom) map options, they all always have the same static image associated with them. For standard options, the image on the right of the selection can change - for example when you select the sea level, you get shown different globe textures with more or less ocean area. Is something like this possible for custom options as well? If the Python API does not allow it I am also willing to "hack" this on the DLL level, but right now I do not know where to start.
 
If the Python API does not allow it I am also willing to "hack" this on the DLL level, but right now I do not know where to start.
Seems like you need to "hack" the exe rather than the DLL. The menu in question is inside the exe and I couldn't find any indication that the exe will ask python or the dll for graphics.
 
Seems like you need to "hack" the exe rather than the DLL. The menu in question is inside the exe and I couldn't find any indication that the exe will ask python or the dll for graphics.
Messing with the exe is usually where I draw the line, so I guess I will have to go without that feature. Thanks for looking into it!
 
A small question about the game's memory usage.


Do we have an - probably not clearly defined - upper limit for how many and large xml files, that can be processed on a somewhat old-fashioned Windows 7 64-bit machine with 8GB of memory?

The reason for my question is, that I am doing my best to add my own wishes to Walter Hawkwood's Realism:Invictus, since he has decided not to continue his work here.

This "work" has already added many lines to many of the xml files - and I still have a few ideas, that will add even more lines...... Problem is, that I "feel" the game in certain situations is slower and maybe a bit more wobbly than it always have been.

I have added the 4GB-patch 1½year ago - it seems to work as intended.
 
I think you presuppose a cause/effect relationship that is probably not entirely accurate. The issue is not with processing XML files but the memory footprint of an ongoing game. The memory used by an ongoing game is impacted more by the map size, number of players, number of entities on the map (especially units).

I think the main issue where the game is sensitive to "large XML files" is if you add a lot of buildings or units that each have unique art assets. So if you have a lot of art assets they will consume a lot of memory (and/or require a lot of disk reads depending on how the game manages dealing with excess memory) which slows down your game. Knowing RI there are already a lot of buildings and units in it, so if you expand on that it would make the impact worse.

However there is no hard limit or cut off point.
 
Do we have an - probably not clearly defined - upper limit for how many and large xml files, that can be processed on a somewhat old-fashioned Windows 7 64-bit machine with 8GB of memory?
There is no xml limit as such. The limit is that it's a 32 bit application.
I have added the 4GB-patch 1½year ago - it seems to work as intended.
That's the memory limit you have to deal with. Sure you can use less memory on xml files, but if you like, you can also use less memory on say CvPlot and that way reduce the overall memory usage. Reducing memory usage is generally a good thing, but it's the sum of many changes so it's non-trivial to achieve.
Problem is, that I "feel" the game in certain situations is slower and maybe a bit more wobbly than it always have been.
That's presumably not an xml issue, but more like a C++/python issue. If say there is a function, which loops all techs to figure out some value, then adding more techs to xml will make that loop take longer. If you add a cache to CvPlayer with the value, then the game performance will be mostly unaffected by the number of xml entries, but then you have to code the whole code around the cache, including figuring out when to update it to ensure it's not out of date.

How to improve performance is somewhat out of the scope for a quick question as it can easily be an ongoing task, which is years in the making because like memory usage, it is typically the sum of many small changes. It's rarely a single point, which eats it all up, like the one I found in vanilla colonization where caching yield cost of profession reduced AI CPU usage by 25%.
 
hi,
my aim in my modding,
was always to try to keep the game to proper speed.

As Nightinggale wrote, the more xml data, the longer hundreds of loops will run.
so try to keep the amount you add to an xml with already large entries base, to a minimum, like units or buildings or resources.

also, lots of the original code is very inefficient, kmod made lots of improvements to that.
about added arts -> its also something that i wondered about, even in PAK files, how large can they be withhout performance issues?

another thing thati wondered about is , what if i could split the large xml files to smaller sized xmls -> lets say i wanna put all wonders in another file.
then, when i have wonder related code, loop only on that xml.
stuff like that.

i guess "we the people" contain tons of speed changes cause i know Nightinggale did some amazing code work there.

--
i almost will never play on large or huge map with lots of AI, cause, there is too much data for the 32bit to process each turn.

Nightinggale,
If you add a cache to CvPlayer with the value
about this one, you meant more cache items are slowing the speed? or indiffrent?
 
Thanks for the answers - it surely lift off some of my "bad thoughts" if this I'm doing actually is particularly clever........


See, I'm not a skilled programmer - I'm just good at mathematics (of the old school from the time before what is called "quantity theory" or "theory of quantities" came to the fore). And then I am reasonably good at imagining how what I read can be combined and used for something else. So my "skills" are limited to what I can do in XML and XML only.

Therefore - nothing of my own - terrain, resources, units... what ever - are added to the last release of R:I.


What I'm doing is to "limit" some buildings and units by putting more prereqs in like this:

<Class>UNITCLASS_GALLIOT</Class>
.......
<PrereqAndBuildings/>
<PrereqOrBuildings/>
<PrereqTechs>
<TechType>TECH_OPTICS</TechType>
<TechType>TECH_BLACK_POWDER</TechType>
</PrereqTechs>
<PrereqAndBonuses>
<BonusType>BONUS_SALTPETER</BonusType>
</PrereqAndBonuses>
<PrereqOrBonuses/>

with this:
.........
<PrereqAndBuildings>
<BuildingClassType>BUILDINGCLASS_HARBOR</BuildingClassType>
<BuildingClassType>BUILDINGCLASS_ARSENAL</BuildingClassType>

</PrereqAndBuildings>
<PrereqOrBuildings/>
<PrereqTechs>
<TechType>TECH_OPTICS</TechType>
<TechType>TECH_BLACK_POWDER</TechType>
</PrereqTechs>
<PrereqAndBonuses>
<BonusType>BONUS_GUNPOWDER</BonusType>
</PrereqAndBonuses>
<PrereqOrBonuses/>

Reason why I do this is fx., that I do not like the possibility of building a fairly big warship with one or more guns on board in a small city with maybe only a fishing dock and without access to the most basic resources - resources, that must be produced within the nation or present as tradegoods that is - the techs alone isn't "enough" for me.

This type of Galliot alone give 3 more lines - and we have many different Galliots (and other shipclasses, units, buildings......name it) - in the game. The default file-size for the TR_Naval_CIV4UnitInfos.xml is 1.858Kb, my file is 1.881Kb. Not much in this case, but it all counts up.


But thanks again for your patience.
 
i guess "we the people" contain tons of speed changes cause i know @Nightinggale did some amazing code work there.
While I agree with this statement, I will say that I can't take credit for all good code in WTP. We are currently 4 skilled programmers working on the mod. If I am to point out something, which can easily be copied to BTS, then I will take this part, which is written by @devolution
PHP:
float CvGlobals::getDefineFLOAT( const char * szName ) const
{
    // the exe calls this functions fairly often, usually related to camera settings
    // since reading this uncached is slow, use static floats to store the values between calls
    // this way values are only read uncached once and responding to the exe over and over will take less CPU time

    if (0 == strcmp(szName, "MINIMAP_PARABOLA_Y_INTERCEPT_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("MINIMAP_PARABOLA_Y_INTERCEPT_PERCENT");
        return val;
    }
    else if (0 == strcmp(szName, "SADDLE_PARABOLA_MIN_Y_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("SADDLE_PARABOLA_MIN_Y_PERCENT");
        return val;
    }
    else if (0 == strcmp(szName, "SADDLE_PARABOLA_MIN_X_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("SADDLE_PARABOLA_MIN_X_PERCENT");
        return val;
    }
    else if (0 == strcmp(szName, "SADDLE_PARABOLA_Y_INTERCEPT_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("SADDLE_PARABOLA_Y_INTERCEPT_PERCENT");
        return val;
    }
    else if (0 == strcmp(szName, "MINIMAP_PARABOLA_MIN_X_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("MINIMAP_PARABOLA_MIN_X_PERCENT");
        return val;
    }
    else if (0 == strcmp(szName, "MINIMAP_PARABOLA_MIN_Y_PERCENT"))
    {
        static const float val = getDefineFLOATUncached("MINIMAP_PARABOLA_MIN_Y_PERCENT");
        return val;
    }
    else
    {
        return getDefineFLOATUncached(szName);
    }
}

// vanilla getDefineFLOAT. Used when wanting to ignore the cache, like when setting the cache
float CvGlobals::getDefineFLOATUncached(const char * szName) const
{
    float fReturn = 0;
    GC.getDefinesVarSystem()->GetValue(szName, fReturn);
    return fReturn;
}
It might require a bit of investigation to see how many of those are called in BTS. Judging by the names, it seems linked to the globe minimap, so that might be Colonization only.

I wrote something similar for getDefineINT, except it's not easy to copy. It's a script, which harvest Type from all xml files and creates enums out of them. If the compiler sets that it should not hardcode the enums, then it will create global read only ints using the same names based on a list, which specifies which values are used in the code. Not only is this way faster than getDefineINT, it will also cause a compiler error if a type vanished from xml, but is still used in c++. Needless to say the complexity of this feature goes far beyond "just a copy paste" if wanted in another mod.

about this one, you meant more cache items are slowing the speed? or indiffrent?
No, what I wrote is this:
If you add a cache to CvPlayer with the value, then the game performance will be mostly unaffected by the number of xml entries, but then you have to code the whole code around the cache, including figuring out when to update it to ensure it's not out of date.
If we say loop all traits and add an int from each owned one to get a combined value, then we need to loop each time, hence making the game slower by adding more traits. If this is done once and then cached, reading the cache will be faster than looping, hence in that case "game performance will be mostly unaffected by the number of xml entries". That statement is only true if the cache is in place.
 
I noticed that in the vanilla version the planes have the same interception, but in BTS the interception of the planes is different
Vanilia
fighter - 50% Jet fighter - 70%
BTS:
fighter- 100% Jet fighter -100%

explain how it is
 
I noticed that in the vanilla version the planes have the same interception, but in BTS the interception of the planes is different
Vanilia
fighter - 50% Jet fighter - 70%
BTS:
fighter- 100% Jet fighter -100%

explain how it is
When BTS was released this was done along with a patch to change the game balance which was required to accommodate the new things added as well as just generally "fix" game balance in aspects where the developers thought it needed doing.
 
I'm sorry, can someone explain to me how the <iAsset> and <iPower> tags works? (BTW tags are in CIV4UnitInfos.xml)(is this important in the operation of AI)
 
I'm sorry, can someone explain to me how the <iAsset> and <iPower> tags works? (BTW tags are in CIV4UnitInfos.xml)(is this important in the operation of AI)
It's used by the AI when evaluating other players. iPower is added up from everything the player owns and if an AI player has much more power than another player, it will be more willing to attack. On other other hand if it is low on power, it is more likely to accept diplomatic demands.

I can't remember offhand what iAsset is, but it's something similar. Something like AI estimating the value of the unit.
 
Why this 10tp tank model the underground is flooding
 
I wrote about my new xml editor and would like to share it with people here. It does currently require Colonization (even if it can edit BTS mods), but as luck would have it, GOG has a 75% discount on Colonization right now. (no I do not get any royalties from that link. It's just information on how to get the mod/editor working)

Feel free to contact me if you want to be a guinea pig early adopter and try out how well it works with BTS.

Yeah this isn't much of a question, but I don't know where else to put it. It's currently not in any stable release and you will have to compile yourself, so it's not like I feel like announcing some stable well tested tool.

 
I have one question why my in mod Alien invasion, AI doesn't use planes.
 
Last edited:
Back
Top Bottom