Proposal: Custom Barbarian Spawn Python Module

I was thinking more on this while away and figured that it won't be useful for my locust units because I need them to spawn inside cultural boarders as well. However it will still be good for animals. I may even get round to posting my subdue animals mod which is currently only useful on marathon or slower games.. :)
 
Hey now, don't give up on developing this. It could prove very useful to create historic and non-historic "barbarian" invasions along with other interesting gameplay dynamics. In fact, this would work great for moded scenarios in the way that Roman or Medieval Europe could experience devastating barbarian invasions.
 
Baldyr have you built anything? I haven't as I have been side tracked by other stuff. Mostly on how to make my Subdue Animals mod better - it still needs to be played on marathon or slower games until this mod is made.

An alternative to random plots for animals may be to go the "lair" route used in a number of mods. Basically at the start of the game a number of lairs are placed around the map and then animals spawn from those lairs. The lairs could sort of be an improvement that needs to be pillaged to stop the spawning at least until a new lair is spawned. This lair idea may also be useful for barbarian invasions. It needs some thought, I know.

My current idea on it would be that lairs would always go on the animal resources and spawn those animals, if in game, plus the animals that normally feed off them.

Code:
era         type        num     interval    random     resource
"Ancient",   "Wolf",     1,      20,         False,     Any Animal
"Ancient",   "Elephant", 1,      100,        True,      "Ivory"

So while Elephants would spawn on ivory resources, wolves would spawn on horses, dear, cattle, sheep etc resources.

This may just be extra work for no game play improvement but it would be slightly more "realistic" :p

On a side note; I think we have been confusing Python Callbacks and Python function calls to the dll. The former are very slow and in most cases not needed. The latter are used all the time and can increase the time between turns significantly if not coded properly.
 
No, as I see it there is no consensus on what exactly the module should do. I, for instance, see a need for limiting spawns to specific map areas, but that hardly applies to generated maps. Whether or not to spawn Barbarians (animals) on resources might also be controversial. So there basically needs to be more discussion or any actual work might be wasted.

What the actual technical implementation would look like depends on the design, obviously. Lets assume that it works in the end and is well coded, for the sake of argument.
 
Well, I would like to voice an opinion on a Python Module for a custon barbarian spawn. My idea is something of a departure from the aforementioned ideas, but I think it interesting enough to merit consideration.

I did a little experiment where I started a custom scenario and then entered the World Builder. I selected one AI Civ (The Americans) and I removed all their start units (i.e. Settler, Worker, Archers, etc.). Then I exited the world builder and played for five turns. Next I went back into the World Builder and re-created the AI American Civ's start units. After exiting the world builder I played five more turns and made contact with the American Civ to find they had established a city.

My point being that it seems the game retained that AI starting Civ (America) regardless of whether any units were actually on the map and did not crash when I added them later. This brings to mind the possibility for a "Barbarian" spawn Python Module that would spawn the units of an actual civ on a specific game turn.

As such it could possibly be an Event.py? The general elements (in layman's terms) might be something like; On game turn (), spawn units (), player (), plot (), etc. I think such an approach would be simple and resource friendly while adding some interesting game dynamics. Perhaps too, civs used like this would have to be made unplayable for the human player (although I suspect that a lack of any starting units might make that happen automatically at the start of the scenario).

Of course one would have to set the python values and the civs up specifically for each scenario being created, but that is the whole point of moding. One could in theory (if this idea can work) use civs to have something like a Goth or Mongol invasion of Europe, Crusaders appearing in the Holy Land, or to simulate a "Rhyse" type arrival of new civilizations. In addition, I think that if such a concept proves to be impractical to impliment, a somewhat similar concept using customised barbarian units may be a worthwhile substitute.
 
Acronym2, I actually already did what your looking for, but its currently for RFC:E/M only. But my intention was always to make a BUG compatible version also.

Is there interest in something like this?

The dynamic spawning idea we actually used in Jamie's Rome Mod, but for 10 "rebel" civilizations that replace barbarians, basically.
 
Acronym2, I actually already did what your looking for, but its currently for RFC:E/M only. But my intention was always to make a BUG compatible version also.

Is there interest in something like this?

The dynamic spawning idea we actually used in Jamie's Rome Mod, but for 10 "rebel" civilizations that replace barbarians, basically.

Rather than my continuing to make "amateurish" suggestions I have been studying your Python lessons along with the API and feel I may be able to learn to write a module that does what I proposed in the above post. I am interested in doing this for BTS 3.19 without BUG or RFC and I have some very interesting ideas and custom artwork in the making that should render both of those somewhat irrelevant. (Although some of BUG's tweaks and fixes would really be nice to have.)

I just took a brief look at your PyScenario and it admittedly has just what I had suggested earlier. Perhaps it would be interesting to adapt it for the BUG Mod and I am "onboard" with that. However, I still would like to try and learn to write my own Python Spawning Module for BTS to gain the experience and a sense of accomplishment.
 
Start with learning some proper Python and you'll be able to pretty much anything you want. PyScenario was my first programming project after reading a entry level textbook. I'm just saying...
 
Start with learning some proper Python and you'll be able to pretty much anything you want. PyScenario was my first programming project after reading a entry level textbook. I'm just saying...

What! Your first programming project after reading an entry level textbook? That is a surprize as I had always had the impression from the way you approached a Python project that you were a "Veterani" of the Python field.
 
I spent my first few months with this programming thing bumbling around looking at other people's code. I did of course learn a lot, but once I read the said textbook I realized that I could have learned what little I knew in a matter of hours - not weeks or months. And I had to relearn a lot of things I've gotten all wrong, so I should of course have picked up the textbook first and started modding only afterwards. Because it was pretty painful at the beginning... :p
 
I'm big on the idea of having barbs or animals spawn from features or resources, but I'm not a Python expert like you two (Interestingly enough, SDK is sometimes EASIER to understand that Python, because everything's defined right in front of you). What would also be nice would be to have barbs stick to certain terrains when moving, although I think SDK would be in order there (I could try). But it would be nice to have Lions sticking to plains and wolves sticking to forest and tundra.
 
Well, getting back to it........Baldyr, I understand how to set up the standard first few "general" entries for a Python module (thanks to your tutorial). It is already clear that one can write the actual spawning code part in several different ways. However I was thinking of "if iTurn ()= True :" as the first line of my script. I do not believe a "getUnit" or "getPlayer" type of entry along with anything else is neccessary for the game to read until after that initial condition is met. Assumably the rest of the code would not be read until the "iTurn" arrived.

Incidentally, the "textbook" may explain python functions and the API list CivIV Python terms but the API sometimes appears a little vague and hard to understand. Has someone here at the forums produced a thread that discusses the API in practical terms?

(Oh, Voyhkah......this is my first attempt at doing some simple modding with Python. It is probably unfair to the real "Python People" to refer to me as an expert.)
 
... But it would be nice to have Lions sticking to plains and wolves sticking to forest and tundra.

This can partly be done using the unit XML and terrain/feature impassible tags. It is not perfect because feature overwrites terrain when it comes to movement. I have been playing around with it and get lions appearing on plains but in forest and then not being able to move because I have forest as impassible.
 
However I was thinking of "if iTurn ()= True :" as the first line of my script. I do not believe a "getUnit" or "getPlayer" type of entry along with anything else is neccessary for the game to read until after that initial condition is met. Assumably the rest of the code would not be read until the "iTurn" arrived.
That makes sense, sorta. But if you learn some basic Python all that will become clear to you. Because programming is about logic.

Incidentally, the "textbook" may explain python functions and the API list CivIV Python terms but the API sometimes appears a little vague and hard to understand. Has someone here at the forums produced a thread that discusses the API in practical terms?
I've considered writing one myself, but right now I don't have the time. What exactly is unclear at this point?
 
That makes sense, sorta. But if you learn some basic Python all that will become clear to you. Because programming is about logic.


I've considered writing one myself, but right now I don't have the time. What exactly is unclear at this point?

Okay, I think I will study the "Textbook" a little more closely......(which should explain the "sorta" in your post) instead of jumping in too quickly. It is obvious that I am not familiar enough to start writing a simple module yet.
 
One distinction you should do in your module is between constants and variables. Constants are references to values that aren't supposed to be changed. (In some languages they can't be changed.) Those can be defined before any logic, because they aren't affected by it.

So the "sorta" comment is dependent of what you're defining with those statements you mentioned. If you, for example, need a pointer to the CyPlayer object of the Barbarian civilization, then that could be a constant thus it is only defined once. So it would make an appearance before any of the actual logic. But if you need to fetch the CyPlayer belonging to some player dependent on the circumstances, then that would be a "proper" variable, and would probably be defined within a function.

But reading up on the basics is a good thing. It might seem like an investment of your time, but its really just plain saving time. Because there is no way you could go wrong with that. (The only thing you don't need to learn, as far as Python programming goes, is file in/out procedures. Because the game uses the save game as the default I/O. Note however that you will eventually need to know about pickling, which is used with CivIV modding as a way of storing you custom game data, so you still need to pick that up from the file operations chapter. :p)
 
Without reading the whole thread, it appears you want a way to define groups of units that spawn, with some fine control over it, yes?

Python control may be a quick way to do it, but likely to be fairly inefficient (entirely due to communication between the engine and python; Nothing to do with how any code may be written). We have a similar setup in Rise from Erebus (and have had it for half a year :p), done in the DLL; You are welcome to merge it if you'd like. :mischief:

Essentially, it creates a new file in XML/GameInfos, titled SpawnGroupInfos.xml. Within this file you define a SpawnGroup object, listing any units you want to spawn (array form, so you can have multiple units of the same type), any unitclasses (yes, it will take any unit of that class, for more random spawns. Weighted towards whatever the owning civ (barbarian, generally, but not hardcoded) has set as the UU), and commanderunits (a list of commanders for the group, reliant on a separate mechanic in RifE). You can also set promotions for the spawned units, as well as a variety of reqs.

Here's a dummy SpawnGroup object:

Code:
<SpawnGroupInfo>	<!-- Dummy -->
	<Type>SPAWN_GROUP_TEST</Type>
	<Description>TXT_KEY_SPAWN_GROUP_TEST</Description>
	<Civilopedia>TXT_KEY_SPAWN_GROUP_TEST_PEDIA</Civilopedia>
	<Strategy>TXT_KEY_SPAWN_GROUP_TEST_STRATEGY</Strategy>
	<bGraphicalOnly>1</bGraphicalOnly>
	<bUnique>0</bUnique>
	<bAlwaysSpawn>0</bAlwaysSpawn>
	<bNeverSpawn>0</bNeverSpawn>
	<bNaval>0</bNaval>
	<iPrereqMinTurn>0</iPrereqMinTurn>
	<iPrereqMaxTurn>0</iPrereqMaxTurn>
	<iPrereqMinAC>0</iPrereqMinAC>
	<iPrereqMaxAC>0</iPrereqMaxAC>
	<PrereqRitual/>
	<iWeight>0</iWeight>
	<CommanderUnits/>
	<GroupUnits/>
	<GroupUnitClasses/>
	<GroupPromotions/>
	<CommanderPromotions/>
	<SpawnTerrains/>
	<SpawnFeatures/>
	<PrereqTechANDs/>
	<PrereqTechORs/>
	<BlockTechANDs/>
	<BlockTechORs/>
	<PyOnSpawn/>
	<PyRequirement/>
</SpawnGroupInfo>

Many of the arrays are actually Lists, so you'd need to either convert them, or import the code necessary for lists to work (I'd highly recommend taking it), and the two Py tags utilize CvSpellInterface.py; Would have to make use of a different python file. Probably just define an onSpawnGroupCreated, and use that, rather than tags directly referencing python functions.

Adding a tag controlling the number of turns between spawns shouldn't be hard either; Just an array, size of SpawnGroupInfos, in CvGame(), which is incremented each turn. Spawn logic would need to be rewritten somewhat, but not difficult. ;)

If you're interested, all code can be found by searching "Spawn Groups" in our source files; I document using a very clear comment system.

Code:
/*************************************************************************************************/
/**	Spawn Groups						08/05/10									Valkrionn	**/
/**																								**/
/**					New spawn mechanic, allowing us to customize stacks							**/
/*************************************************************************************************/
 
Back
Top Bottom