[BTS] How to make leader changing on time?

AstrokauzazITS994

Chieftain
Joined
Jan 15, 2023
Messages
25
Hello everyone, while playing Civilization IV, I'm Roosevelt from World War II and I meet *my laugh* Cleopatra who lived 50 B.C.E. The leaders there also live like 6,000 years, so I guess all of you want a lifespan like Cleopatra's in civilization IV, not Cleopatra's in real life.
As for the topic, it annoys me that leaders live like 6,000 years and I would like to do something to change it. For example, in the USSR at the beginning there was Lenin, then he died and was replaced by Stalin. Does anyone know the options to do this and if anyone knows, tell me where to write it down?
 
I recall that I've tried to answer this quite recently, let's see ... here: https://forums.civfanatics.com/threads/how-to-make-leader-who-will-be-change-in-time.681937/
So it depends on the mod you're working with. If it already has the changeLeader function from BBAI, then it should just take some coding in Python, otherwise, such a function would first have to be merged into the DLL, meaning that you'd have to set up a development environment for Visual C++.
 
I recall that I've tried to answer this quite recently, let's see ... here: https://forums.civfanatics.com/threads/how-to-make-leader-who-will-be-change-in-time.681937/
So it depends on the mod you're working with. If it already has the changeLeader function from BBAI, then it should just take some coding in Python, otherwise, such a function would first have to be merged into the DLL, meaning that you'd have to set up a development environment for Visual C++.
and do you know how to do it in both coding languages?
 
The C++ part would be to download the BBAI source code, and then to use some text search tool to find all code marked with comments that say "CHANGE_PLAYER". That would have to be copied into the source code of your mod. It's about a dozen code fragments in total. And you'd need to set up Visual Studio und the libraries used by the DLL. Unforeseen issues could crop up in the process (as evidenced by this thread), and I'm not sure if this forum could walk you through those.

The part that calls the changeLeader function can also be implemented in C++. If you need to re-compile the DLL anyway, then using C++ will actually be easier than Python. In any case, you'll need to write the logic for deciding whether to change a leader and for picking the new leader. For a start, you could try something like
Code:
if (GC.getGame().getElapsedGameTurns() % 100 == 0 && GC.getGame().getElapsedGameTurns() > 0 &&
	!isBarbarian())
{
	changeLeader((LeaderHeadTypes)((getLeaderType() + 1) % GC.getNumLeaderHeadInfos()));
}
at the end of CvPlayer::doTurn. I haven't tested it; it's supposed to change the leader every 100 turns by picking the leader with the next highest ID. The IDs correspond to the order in Civ4LeaderHeadInfos.xml. I think you'll need something a good deal more complex. At the least, you'd need to ensure that the new leader isn't already in use.

Generally, in my opinion, to mod the game beyond WorldBuilder and XML changes, it's necessary to - gradually - learn the basics of the programming languages – otherwise you can only ask others to write the code for you, and no one's willing to do that unless it's just a couple of lines. So "tell me where to write it down" – it's too big a task for that, I think.
 
The C++ part would be to download the BBAI source code, and then to use some text search tool to find all code marked with comments that say "CHANGE_PLAYER". That would have to be copied into the source code of your mod. It's about a dozen code fragments in total. And you'd need to set up Visual Studio und the libraries used by the DLL. Unforeseen issues could crop up in the process (as evidenced by this thread), and I'm not sure if this forum could walk you through those.

The part that calls the changeLeader function can also be implemented in C++. If you need to re-compile the DLL anyway, then using C++ will actually be easier than Python. In any case, you'll need to write the logic for deciding whether to change a leader and for picking the new leader. For a start, you could try something like
Code:
if (GC.getGame().getElapsedGameTurns() % 100 == 0 && GC.getGame().getElapsedGameTurns() > 0 &&
    !isBarbarian())
{
    changeLeader((LeaderHeadTypes)((getLeaderType() + 1) % GC.getNumLeaderHeadInfos()));
}
at the end of CvPlayer::doTurn. I haven't tested it; it's supposed to change the leader every 100 turns by picking the leader with the next highest ID. The IDs correspond to the order in Civ4LeaderHeadInfos.xml. I think you'll need something a good deal more complex. At the least, you'd need to ensure that the new leader isn't already in use.

Generally, in my opinion, to mod the game beyond WorldBuilder and XML changes, it's necessary to - gradually - learn the basics of the programming languages – otherwise you can only ask others to write the code for you, and no one's willing to do that unless it's just a couple of lines. So "tell me where to write it down" – it's too big a task for that, I think.
Thanks for letting you know how some of these things. But I also wanted to say that if you start the game, for example, I would like to be able to choose only Adolf Hitler and not Wilhelm I. And as for changing the leader every 100 turns, there is also a problem here because, for example, 100 turns is a hundred weeks and the next leader is supposed to be 120, after that it is supposed to be 80 and so on. But remember, I'm not disappointed, just happy.
 
But I also wanted to say that if you start the game, for example, I would like to be able to choose only Adolf Hitler and not Wilhelm I.
That makes sense. (Or perhaps the other way around – since Wilhelm reigned earlier.) I don't actually see a simple way to exclude a leader from the game setup screens. Those screens are implemented in the EXE. I'm sure it's possible, but it would require some elaborate workaround that hides the leader from the EXE during game setup.

The exact timing of the leader change could be tweaked relatively easily. There are also CvGame functions
Code:
int getTurnYear(int iGameTurn);
int getGameTurnYear();
that could be helpful to this end.
But remember, I'm not disappointed, just happy.
:thumbsup:
 
To ma sens. (A może odwrotnie – odkąd Wilhelm panował wcześniej.) Właściwie nie widzę prostego sposobu na wykluczenie lidera z ekranów przygotowania gry. Te ekrany są zaimplementowane w pliku EXE. Jestem pewien, że jest to możliwe, ale wymagałoby to skomplikowanego obejścia, które ukrywa lidera przed plikiem EXE podczas konfiguracji gry.

Dokładny czas zmiany lidera można stosunkowo łatwo dostosować. Istnieją również funkcje CvGame[kod]int getTurnYear(int iGameTurn);
int getGameTurnYear();[/code], które mogą być pomocne w tym celu.

:kciuki w górę:
Iand as for this code, it seems to me that the year is written after the colon
 
To ma sens. (A może odwrotnie – odkąd Wilhelm panował wcześniej.) Właściwie nie widzę prostego sposobu na wykluczenie lidera z ekranów przygotowania gry. Te ekrany są zaimplementowane w pliku EXE. Jestem pewien, że jest to możliwe, ale wymagałoby to skomplikowanego obejścia, które ukrywa lidera przed plikiem EXE podczas konfiguracji gry.

Dokładny czas zmiany lidera można stosunkowo łatwo dostosować. Istnieją również funkcje CvGame[kod]int getTurnYear(int iGameTurn);
int getGameTurnYear();[/code], które mogą być pomocne w tym celu.

:kciuki w górę:
C wait, but since you set the leader to change every 100 turns, what to do with that code below?
 
For the TurnYear functions, I've only posted the declarations (copied from CvGame.h). Just to show that functions for working with year numbers exist. To make use of them in CvPlayer::doTurn, you'd write e.g.:
GC.getGame().getGameTurnYear()
 
Hi.
I've got an option ("Dynasty") that you can check in my mod - https://forums.civfanatics.com/threads/beyond-the-play-community-mod.648750/

It has many options, but if you select NONE of the options except this one, it will do exactly what you asked.
With the Dynasty component on, you change leader when you change era.
If you checked unrestricted leaer, it can be any, unused, leader. Otherwise it will be a leader of the same civilization, so one of the (other) available russians leader in your example

Uploading version 2.33 as we speak.


1678659810871.png



1678659844169.png
 
Hi.
I've got an option ("Dynasty") that you can check in my mod - https://forums.civfanatics.com/threads/beyond-the-play-community-mod.648750/

It has many options, but if you select NONE of the options except this one, it will do exactly what you asked.
With the Dynasty component on, you change leader when you change era.
If you checked unrestricted leaer, it can be any, unused, leader. Otherwise it will be a leader of the same civilization, so one of the (other) available russians leader in your example

Uploading version 2.33 as we speak.


View attachment 656608


View attachment 656609
I guess this mod will bring me a lot of joy
 
Cześć.
Mam opcję („Dynastia”), którą możesz sprawdzić w moim modzie - https://forums.civfanatics.com/threads/beyond-the-play-community-mod.648750/

Ma wiele opcji, ale jeśli nie wybierzesz ŻADNEJ opcji oprócz tej, zrobi dokładnie to, o co prosiłeś.
Po włączeniu komponentu Dynastia zmieniasz przywódcę wraz ze zmianą epoki.
Jeśli zaznaczyłeś nieograniczony leaer, może to być dowolny, nieużywany lider. W przeciwnym razie będzie to przywódca tej samej cywilizacji, a więc jeden z (innych) dostępnych Rosjan jako przywódca w twoim przykładzie

Przesyłanie wersji 2.33 w tej chwili.


View attachment 656608


View attachment 656609
I wonder if it is possible to set in which eras it should change
 
Yes you can easily change that.
The whoIe logic of the Dynasty component is in : Beyond The Game\Assets\Python\BTG_Events\Dynasty.py

There is only one function in there "doLeaderChange", which is called by the C++,
in
Code:
void CvPlayer::setCurrentEra(EraTypes eNewValue)
I've added this at the end of the function
Code:
long lResult=0;
                CyArgsList argsList;
                argsList.add(getID());    // Player ID
                gDLL->getPythonIFace()->callFunction(PYGameModule, "doDynastyLeaderChange", argsList.makeFunctionArgs(), &lResult);
                if (lResult == 1)
                {
                    return;
                }
This is callback, don't worry about that and C++

Just edit the Python and tell it which era you want it to be limited to
 
Tak, możesz to łatwo zmienić.
Cała logika komponentu Dynasty znajduje się w: Beyond The Game\Assets\Python\BTG_Events\Dynasty.py

Jest tam tylko jedna funkcja „doLeaderChange”, która jest wywoływana przez C++,
W
[KOD]void CvPlayer::setCurrentEra(EraTypes eNewValue)[/KOD]
Dodałem to na końcu funkcji
[KOD]długi lWynik=0;
CyArgsList lista argumentów;
argsList.add(getID()); // Identyfikator gracza
gDLL->getPythonIFace()->callFunction(PYGameModule, "doDynastyLeaderChange", argsList.makeFunctionArgs(), &lResult);
jeśli (lWynik == 1)
{
powrót;
}[/KOD]
To jest wywołanie zwrotne, nie martw się o to i C++

Po prostu edytuj Pythona i powiedz mu, do której ery chcesz go ograniczyć
Cif I change currentEra to currentYear, will it change every year?
 
Top Bottom