• Civilization 7 has been announced. For more info please check the forum here .

AI Civilizations Restarting Modification

OK, let me try and get a handle on this. So the Python stuff is all the files i see with the .h and .cpp suffixes. And I assume it is the files with the .py suffix?
The h and ccp files would be the C++ and the py would be Python. All of these can be edited with just about any text editor, but only the Python files can be run as is. The C++ files need to be compiled into machine code (computer language) and this is what makes it so fast.

The way the game is setup is that the game itself is a compiled executable file programmed with C++. It is augmented by additional C++ code in the DLL file - and the "makefiles" for this is what people refer to as the System Developer's Kit, or SDK - it is made up of the .h and .ccp files you mentioned.

But the DLL also code offers "hooks" that the modder can attach Python code to. This is what mechaerik was talking about. But you don't need to figure out where to connect you Python stuff quite yet, because you need to make some decisions first. Like if your mod is going to be based on an existing mod (like BUG) - or if you are going to attempt to make everything from scratch yourself (which isn't the easier option, but could prove to be better for learning).

I assume anything I change from the BTS version, I place in my Mod directory in the exact same file structure?
No, no... Look at any mod you've downloaded. It was a Assets folder of its own, and it in turn has a Python folder. This is where the Python modules for your mod go.

The Idea: A city can generate revolutionaries matching some or all of the entrenched soldiers of the city.

The Trigger: Any time the city goes into revolt through conquest, espionage, or event.

Length: 100 turns

Results: a 5 percent chance per turn that "revolutionaries" spawn next to the city equal to one-quarter (rounded down) of the entrenched troops.

These "Revolutionaries" take on the flag of the barbarians and behave thus.
I have one question - what is the 100 turn length? :confused: From what turn to what turn? When does it begin? Why doesn't this apply to the whole game session?

Is there a place where each of the .py files are detailed as to what they do? For example, can I reference something that tells me what "AbandonRazeDemolish.py" does? Or do I just need to open each one and figure it out?
No, no... There are practically no pre-defined Python modules (except for the interface stuff) in CivIV. You make up your own and get to set things up exactly as you like.

If you look at other peoples mods, then you need to be able to read and understand what their Python modules do. Some are documented, some are not. But you wanna be able to make you own modules, not just use other's.

So, in the following tutorial we will first be creating the code for your script, then we will be putting the whole script together into a Python module. Only then will we need to worry about what to do with your .py file. Hopefully you are a bit clearer on what (if anything) you wanna base your mod on by then.

To what extent you will be reading up on Python as this thing progresses is up to you, but things will be much clearer if you try to study the topics we will be covering... (I'll even post helpful links.)

I'll post a first "lesson" soon. Perhaps I should start another thread, in case anyone else wants to follow this also?
 
I would very much like a tutorial on simple python. Just the real basic stuff -- something I could do and then see results immediately in the game.

That's how I learn. Do something small, then say "Oh I see how this connects to that, and why when I do this, that happens." From there, I can leap frog into bigger things.

For example, I would love to have a simple screen pop up in the beginning of the game that I can list credits and simple starting hints?

As for my Revolutionary modification, the only reason I have a 100 turn limit is that I don't want all the cities in the empire to constantly have rebels (that doesn't make sense to me), but rather a small duration of time after a revolt that the rebels can form -- after that I assume the city has become comfortable with being in the empire/culture.
 
I would very much like a tutorial on simple python. Just the real basic stuff -- something I could do and then see results immediately in the game.
Yeah, I get that. But you will be limiting yourself to only doing some basic stuff that you don't even really understand yourself. Its like you only wanna have 7% programming skill, when the full 70% is readily available. Suit yourself.

That's how I learn. Do something small, then say "Oh I see how this connects to that, and why when I do this, that happens." From there, I can leap frog into bigger things.
So lets do this then. :king: I will basically need to write a textbook for you, bit by bit, but so be it. I actually enjoy this sort of thing. (Getting paid doing it would rock though. :p)

For example, I would love to have a simple screen pop up in the beginning of the game that I can list credits and simple starting hints?
Yeah, we can add that to your revolution mod from scratch. It'll be a separate lesson then.

As for my Revolutionary modification, the only reason I have a 100 turn limit is that I don't want all the cities in the empire to constantly have rebels (that doesn't make sense to me), but rather a small duration of time after a revolt that the rebels can form -- after that I assume the city has become comfortable with being in the empire/culture.
Ah, that actually makes sense. I'll try to find the easiest way to implement something along these lines then. (Like once there is no foreign culture left in a city it will never spawn rebels, or something. Having an actual counter for every single city is somewhat cumbersome though.)

This is what I remembered of trying to implement into the game.
I haven't looked at it myself, but anything is possible. Even merge any mod with any other one. But the question you wanna ask yourself is if you'd rather have you own thing?

So test that setup and evaluate it. If you can't think of any better implementation then you only have to learn Python for real, read the code and find a way to add it to your mod. If you know programming you will be able to do this. (Merging mods requires a somewhat different set of skills though, but its basically programming.)

But if you can think of something even better, then learn Python and do that instead. You need to learn programming in either case. (Or you could just rely on dumb luck and hope you can manage to merge the mods by accident. And the time spent on bumbling around could have been enough to learn how to actually do it...)

And if you really want it in your mod I can help you merge it, no problem. But don't ask me to rewrite it also, because then I will just ask you to do your own code. :lol:

So, I'll start building your mod and then we'll go through it in segments. One lesson at a time. It'll be easy enough and you will learn many useful things along the way. And at the end you will have your mod - and we can figure out how to make it work as part of your mod. No problems. :goodjob:
 
Its ok! I apologize for getting impatient with modders who refuse to learn how to do things proper. :lol:

I just wrote the first draft of the script (currently 37 lines of code) for your mod. Now I have to check it for errors and then test it. Should I do this properly and start the tutorial in another thread?
 
That's how I learn. Do something small, then say "Oh I see how this connects to that, and why when I do this, that happens." From there, I can leap frog into bigger things.

Then i suggest, you take something small and change it.
e.g. look at the mod components forum, the tsentom1 python wonders.
Many are only small changes in 1 or 2 places.
I suggest you take one, look at the python, try to understand it, and if you can't, then ask here.

For example, I would love to have a simple screen pop up in the beginning of the game that I can list credits and simple starting hints?

click me.
 
I downloaded the little box python change and looked it over. The mod I am working on already has a CvEventManager.py file.

I don't think I can just swap yours for the one in there, but wonder if there is a certain section I could copy from yours to the one in the mod?
 
A tool you need is something that compares files, and possibly will move sections from one to the other.

Like WinMerge.

That would tell you exactly what is different and allow you to merge extra/different code from one into the other. It isn't perfect at merging, but it makes things easier.
 
We'll get to the Event Manager thing eventually in the tutorial, no worries. Also, you won't be needing the XML popups once you learn Python - unless you remain more comfortable with XML. But then you probably never bothered to learn programming proper. :p
 
I downloaded the little box python change and looked it over. The mod I am working on already has a CvEventManager.py file.

I don't think I can just swap yours for the one in there, but wonder if there is a certain section I could copy from yours to the one in the mod?

Yes, there is a section ;).
From the download description:
There's one change in CvEventManager.py, search for "starting popup".


Normally, it is mentioned, in which file something has been changed, and for what you have to search to find the changes.
 
I've been talking about Object-Oriented Programming a lot lately, and while I'm not gonna go into what it is, I thought I'd tell you what it could be used for.

The tutorial I made uses the regular kind of programming, procedural programming I believe I've seen it referred to as. While CivIV - and most major mods adding new game features to the game - uses OOP. Things like the EventManager, PyHelpers and Popup modules are also in OOP, so its clearly an advantage to know what it is and how it works!

But for the Rebels mod, it could be rewritten in OOP and while it could still work exactly the same, the fact that we put the function making up the mod into a class (making the functions class methods) offers some pretty huge opportunities to add to the mod. So instead of simply running the code every turn and detect possible sites for rebellion - spawning a few units where applicable - there would be a Rebellion constructor. Each time the code calls upon it an instance of the Rebellion class would be created. This "object" would actually exist in the memory as an independent entity of sorts. Like a CyPlayer instance is one of the Civs in the game, or like a CyUnit instance is one of the actual units moving around on the map.

So for developing the the base mod further, each Rebellion instance could have a unique name. Like the "Baghdad Insurgency", the "Boston Massacre", the "Dublin Rebellion" or the "Moscow Revolution". While cool in its own right, a name generator like this is peanuts compared to what else could be done with such an object!

Like have each Rebellion instance have a defined opposition, be it political, religious or nationalistic. Each with its own set of challenges to the player facing these rebels. It could be possible to yield into some of the demands made by the particular disenfranchised fraction, like change a civic, your state religion or grant the city independence. This would possible make all but some lone rogue unit disappear into thin air.

Why give in to demands made by terrorists, then? Well, each type of rebellion could come with its own set of problems. Like terrorism, destroying your buildings and improvements - given the time to ferment also in your capital and other cities! And your citizens would start to get really upset - and not only in the rebellion hotspot...

What makes OOP good for such a setup is also the possibility to enlarge the conflict - like if all the units aren't dealt with within a certain number of game turns. So one Rebellion instance could in fact affect several cities - even if it all originally started with that one city in disorder. There is no end to what features could be added.

So once you wanna start adding your own game concept like the expanded Rebels mod described above, you wanna know about classes and the instances that are created with them. Because these things actually get quite easy to program in this particular style. :king: And its a far cry from anything that can be accomplished confined within the limitations of the XML files. :rolleyes:

edit: Writing this really makes me wanna mod full-time! :cry:
 
Top Bottom