Quick Modding Questions Thread

Trying to use gamefont icon but failing :(
Instead of "Oil" I want to use the icon from BONUS_FUEL

oil2-jpg.629335


gaf.JPG


I tried with:
iBonus = gc.getInfoTypeForString("BONUS_COPPER")
Code:
                szOutText = u"<font=2>%c:%d%%</font>" %(gc.getBonusInfo(iBonus).getChar(), pPlayer.getOil())

                screen.setLabel( "OilText", "Background", sColor + szOutText + u"</color>", CvUtil.FONT_LEFT_JUSTIFY, 14, 50 + (iCount * 19), -0.1, FontTypes.SMALL_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
                screen.show( "OilText" )

and a bunch of other stuff. But the UI completely disappears...

Right now I'm using
Code:
                szText = localText.getText("TXT_KEY_MISC_OIL", (pPlayer.getOil(), pPlayer.getOilPerTurn()))
                screen.setLabel( "OilText", "Background", szText, CvUtil.FONT_LEFT_JUSTIFY, 12, 50 + (iCount * 19), -0.1, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
                screen.show( "OilText" )
But would really like the icon....

My text:
Code:
    <TEXT>
        <Tag>TXT_KEY_MISC_OIL</Tag>
        <English>Fuel: %d1 (+%d2_Num/Turn)</English>
        <French>Fuel: %d1 (+%d2_Num/Turn)</French>
        <German>Fuel: %d1 (+%d2_Num/Turn)</German>
        <Italian>Fuel: %d1 (+%d2_Num/Turn)</Italian>
        <Spanish>Fuel: %d1 (+%d2_Num/Turn)</Spanish>
    </TEXT>
 
Well, just turned Python exceptions on, and even though this shows fine (still without the icon):
Code:
                szText = localText.getText("TXT_KEY_MISC_OIL", (pPlayer.getOil(), pPlayer.getOilPerTurn()))
                screen.setLabel( "OilText", "Background", szText, CvUtil.FONT_LEFT_JUSTIFY, 12, 50 + (iCount * 19), -0.1, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
                screen.show( "OilText" )
it comes up with tons of python exceptions, none of them makes sense to me, or why it doesnt work, so ANY help understanding what is going on would be greatly appreciated :)

Even if I just declare a variable the whole thing comes crashing down, and im totally clueless :(
 
Map graphics issue

Hi, I am modifying Genghis Kais giant earth map as a basis for my mod, however I am getting this graphical glitch specifically at the edge of the map, some sort of shadow effect:

View attachment 629196

Does anyone know what causes this? I have been working with the map in the excel map editor called Civ4 YAME

I did try to search the forums but could identify any threads about it specifically unless I missed it somewhere.

I'm pretty sure this type of thing comes from heightmaps, which are shading textures used to help represent different height maps. Sometimes when you change a tile type (like from ocean to land or vice versa), even in regular Worldbuilder, the game retains the original heightmap, and the tile looks pretty funny as a result.

I don't know how to fix it, though, sadly...perhaps by editing the WBSave itself?
 
Well, just turned Python exceptions on, and even though this shows fine (still without the icon):
Code:
                szText = localText.getText("TXT_KEY_MISC_OIL", (pPlayer.getOil(), pPlayer.getOilPerTurn()))
                screen.setLabel( "OilText", "Background", szText, CvUtil.FONT_LEFT_JUSTIFY, 12, 50 + (iCount * 19), -0.1, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
                screen.show( "OilText" )
it comes up with tons of python exceptions, none of them makes sense to me, or why it doesnt work, so ANY help understanding what is going on would be greatly appreciated :)

Even if I just declare a variable the whole thing comes crashing down, and im totally clueless :(

What exceptions are you getting? I know editing the GameFont file can cause some really frustrating errors if it's not done 100% perfectly (the game uses certain pixels in the file around each icon to tell where the icons are, I think, and changing those pixels can cause gobbledegook). But it looks like your file is fine tbh.
 
I think it comes down to me not understanding python very well.
The whole indentation /space/tabs got mixed as I used VS2022 and Notepad++.
At least that is what I suspect.

I got it working now. I teach programming, and I always tell my students, if they have an seemingly unsurmountable problem, sometimes its better to walk away. Take a break. Come back later and view it with "new eyes".
I also tell them to do as I tell, not as I do. ;)


Code:
                if not CyInterface().isCityScreenUp() and pPlayer.getOil() > 0:
                    szText = u"%c" %(gc.getBonusInfo(gc.getInfoTypeForString("BONUS_FUEL")).getChar())
                    szText += localText.getText("TXT_KEY_MISC_OIL", (pPlayer.getOil(), pPlayer.getOilPerTurn()))
                    screen.setLabel( "OilText", "Background", sColor + szText + u"</color>", CvUtil.FONT_LEFT_JUSTIFY, 12, 120, -0.1, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
                    screen.show( "OilText" )

Code:
    <TEXT>
        <Tag>TXT_KEY_MISC_OIL</Tag>
        <English>: %d1_Num [COLOR_POSITIVE_TEXT](+%d2_Num/Turn)[COLOR_REVERT]</English>
        <French>: %d1_Num [COLOR_POSITIVE_TEXT](+%d2_Num/Turn)[COLOR_REVERT]</French>
        <German>: %d1_Num [COLOR_POSITIVE_TEXT](+%d2_Num/Turn)[COLOR_REVERT]</German>
        <Italian>: %d1_Num [COLOR_POSITIVE_TEXT](+%d2_Num/Turn)[COLOR_REVERT]</Italian>
        <Spanish>: %d1_Num [COLOR_POSITIVE_TEXT](+%d2_Num/Turn)[COLOR_REVERT]</Spanish>
    </TEXT>

Civ4ScreenShot0001.jpg
 
Last edited:
Hi, Where are limits on the number of units, buildings, etc that can be used in a mod defined?
 
I had seemed to reach an upper limit years ago for unique buildings when working on the Ydil modmod,
Is there a limit on the number of unique buildings a civ can have? It seems to max out at 38 net new buildings. Any NONE buildings have to be identified first.
I’ve now run into a baffling issue when adding new spellinfos in my current mod, where spells that worked are ceasing to work when I add more and wondered if I had hit another limit.
 
Thanks for response.
I’ve found that the issue is related to pyrequirements, rather than a hard limit.
I’ve been able to add more simple spells and found some previously working spells are no longer working as they used to, so next I’ll see what I may have done in the python file to cause it to stop working.
 
DLL question.

I'm trying to limit recon in bool CvUnit::canReconAt(const CvPlot* pPlot, int iX, int iY) const so that its only available for a tile that can already be seen by the player.
I've tried
Code:
    TeamTypes eTeam = getTeam();
   if (!(pPlot->isVisible(eTeam, false)))
   {
       return false;
   }
and some variations without success.

Any ideas/suggestions what I should use?
 
Ah, it took some looking, but I think I found it. This is where the canReconAt gets called:

Code:
bool CvUnit::recon(int iX, int iY)
{
    if (!canReconAt(plot(), iX, iY))
        return false;
...

plot() refers to CvUnit::plot(), so apparently the pPlot is actually the reconning unit's plot, not the plot it is doing recon on. iX / iY are the coordinates of the plot being reconned.
edit: that's supposed to be CvUnit : : plot()

:lol: your check still applies though, technically. If a unit cannot see its own plot, then it definitely should not be trying to do recon... :rotfl:
 
So here is a thing I'd like to accomplish in my mod: Block certain religions (to be state religion) by civics.

I want atheism to be represented in a more realistic way. There is already an Atheist civic, when when the government bans all religions (no state-religion). I want to add Atheism also as a religion type that spreads like any other religion. The problem is if the AI picks this one as its state-religion, that would look silly.
So the idea is this: Civics blocking certain religion. Eg. State Church (civic) blocks Atheism (rel.) and Atheist (civic) blocks all religions but Atheism (rel.)

As I am still unable to compile a dll I am mainly interested in a Python solution (unless someone would be so kind to write the code an recompile the dll for me).
 
Unfortunately it looks like there is not a "canConvert" check exposed to CvGameUtils, which would allow you to tell the game whether or not a player is allowed to adopt a religion. (There is a mysterious "doReligion" call.)

However, there is a CyPlayer "convert" function you can use to change a player's religion. So, you could go to CvEventManager onEndTurn, and each turn, check if the civ has State Church; if so, check if their state religion is Atheism; and if so, change it back. Lol.
This would require either figuring out what the state religion used to be (probably using script data, I recommend SD toolkit for that) or setting it to "nothing" and hoping the AI picks a different one (but that would probably end up in the AI converting back to atheism every turn, the net result of which would be endless anarchy, unless they have Spiritual trait). News headline: The Holy State of Theocratic Spain has once again descended into anarchy after their befuddled king issued a proclamation establishing atheism as the state religion. This is the fourteenth time since 1908, when atheism overtook Buddhism as the dominant religion in the Spanish Empire...

A different way might be to check the civic, then if the civic is State Church, go purge every city of the Atheism religion using CyCity changeReligionInfluence. Or vice versa: when the civic is Atheism, get rid of all other religions. This way the AI might be prevented from doing silly conversions.

And one more way :crazyeye: might be on the civics end - there is a line in CvGameUtils "canDoCivic", which means you could prevent the player from switching to the State Church civic if they have Atheism state religion.




Also. Sorry if I have already asked you this and forgot. What is stopping you from compiling the dll? If it's not a hardware / software / legal / being kidnapped by barbarians issue I am happy to help :goodjob: For me, getting everything set up to compile was tricky, but once I got that going all I have to do is press a button.
 
Just FYI, the "doReligion" call is not so mysterious... it's called each turn by each city (it's called within CvCity::doReligion), it's basically (the possibility to override) the code that gives a small chance of religion propagating randomly.

(the code, with an option to turn this off that I made at the end)
Code:
void CvCity::doReligion()
{
    CvCity* pLoopCity;
    int iRandThreshold;
    int iSpread;
    int iLoop;
    int iI, iJ;

    CyCity* pyCity = new CyCity(this);
    CyArgsList argsList;
    argsList.add(gDLL->getPythonIFace()->makePythonObject(pyCity));    // pass in city class
    long lResult=0;
    gDLL->getPythonIFace()->callFunction(PYGameModule, "doReligion", argsList.makeFunctionArgs(), &lResult);
    delete pyCity;    // python fxn must not hold on to this pointer
    if (lResult == 1)
    {
        return;
    }

    if (getReligionCount() == 0)
    {
        for (iI = 0; iI < GC.getNumReligionInfos(); iI++)
        {
            if (!isHasReligion((ReligionTypes)iI))
            {
                if ((iI == GET_PLAYER(getOwnerINLINE()).getStateReligion()) || !(GET_PLAYER(getOwnerINLINE()).isNoNonStateReligionSpread()))
                {
                    iRandThreshold = 0;

                    for (iJ = 0; iJ < MAX_PLAYERS; iJ++)
                    {
                        if (GET_PLAYER((PlayerTypes)iJ).isAlive())
                        {
                            for (pLoopCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
                            {
                                if (pLoopCity->isConnectedTo(this))
                                {
                                    iSpread = pLoopCity->getReligionInfluence((ReligionTypes)iI);

                                    iSpread *= GC.getReligionInfo((ReligionTypes)iI).getSpreadFactor();

                                    if (iSpread > 0)
                                    {
                                        iSpread /= std::max(1, (((GC.getDefineINT("RELIGION_SPREAD_DISTANCE_DIVISOR") * plotDistance(getX_INLINE(), getY_INLINE(), pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE())) / GC.getMapINLINE().maxPlotDistance()) - 5));

                                        //iSpread /= (getReligionCount() + 1);

                                        iRandThreshold = std::max(iRandThreshold, iSpread);
                                    }
                                }
                            }
                        }
                    }

                    if (GC.getGameINLINE().getSorenRandNum(GC.getDefineINT("RELIGION_SPREAD_RAND"), "Religion Spread") < iRandThreshold)
                    {
                        if (!(GC.getGameINLINE().isOption(GAMEOPTION_PRAGMATIC_RELIGION)))//2.23r Akira condition
                        {
                            setHasReligion(((ReligionTypes)iI), true, true, true);
                            break;
                        }
                    }
                }
            }
        }
    }
}

Just because I looked it up to know but not the place to do anything for your usage here.
 
@Merkava120 and @P&nny:
Thanks for your answers :)

Also. Sorry if I have already asked you this and forgot. What is stopping you from compiling the dll? If it's not a hardware / software / legal / being kidnapped by barbarians issue I am happy to help :goodjob: For me, getting everything set up to compile was tricky, but once I got that going all I have to do is press a button.
I tried it before but failed without understanding the reason :undecide:
I may give it another try again but I'm really short on time, especially when it comes to learning new things.
And I also lack the programing skills :sad:
But thanks for offering your help. I may take it some day :thumbsup:
 
Hello team, a quick (maybe rethorical) one if I may...

Is there a way to make the color of the "X" in a checkbox something else than green ? I've seen a red "X" in a MOD somewhere but I don't know if it's a theme thing (therefore all checkbox are with a red cross) or we could have 3 values, empty/green/red
Similar question : can the text of the checkbox be changed into another color ? Usual string color modifier like "CyTranslator().changeTextColor(" don't seem to take effect... If not, what's the bes way here below you think ? Make the text empty and put a list of text ? Worried the layout setup will be a nightmare


This is the goal : a left column to be able to change all options in-game (I already have a menu for that) --- and a right column with duplicates just to CHECK what the reference value is

upload_2022-6-24_20-43-5.png




By the way if anyone is wondering this is how my option changer looks like, it's already part of BTG 2.27 & maybe couple of release before.
It's proving an excellent tool to TEST things

upload_2022-6-24_20-48-6.png
 
Quick C++ / SDK question.

In a header file, declaring

Code:
std::vector<std::pair<int,int>> thing;

results in compilation errors "expected '>' but found '>>' ".

The rest of the Internet seems to think declaring std::vectors of std:: pairs is fine, but the compiler disagrees. Is Civ4's version of C++ too old to do vectors of pairs?
 
Back
Top Bottom