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

Merkava's Mods

Merkava120

Oberleutnant
Joined
Feb 2, 2013
Messages
450
Location
Socially distant
Hello!

Since I am working on lots of python mods lately, and planning a big project or two, I thought I'd make a thread to organize all of it.

My main project:

Civ 4 Dynamica -
making every part of Civ4 dynamic, including techs, civilizations, promotions, etc. etc., to make Civ4 games feel like real developing worlds.

Features & included mods:

Spoiler :

  • Dynamic Techs - disables the tech tree and gives tech beakers slowly over time. (Thanks to Zeta Nexus for the mechanics ideas.)
  • Seasons - changes Platyping's seasons modcomp to be based around snowfall rather than improvement changes. Also pays attention to hemispheres.
  • 100-Civs DLL
  • Animal Spawning - spawns animals according to terrain and animal type. Damages units every turn (because of "hunger") and heals units who attack ("eat") other animals. Includes about a dozen animal units from C2C.


I also upload every mod I make for Dynamica as its own standalone in case you want to merge it with something.

Next up: Fully dynamic tech tree!! It's time!

Coming soon:
Spoiler :

  • Updated dynamic techs to allow techs based on population growth
  • Smoothed-out Dynamica mod (updates to seasons/snowfall/hunting to make them less hokey)
  • Eventually, disasters, factions, dynamic promotions and traits, and so on...but first things first.



My secondary project:

Civ 4 Tactical

Originally conceived as a World War II mod, this is a total conversion that replaces your normal civ game with a fast-paced tactical combat game. Take your civilization from the stone age to the modern age, adapting to new weapons and combat styles across history.


Main features so far (see the link for details):
  • Ranged combat that is highly customizable through XML and is used by the AI
  • Tweaks to combat to make it more realistic in tactical settings
  • Stripped down starts - one city per civ, no yields from tiles, no unique improvements, just you, your supplies and your units.
The mod is currently in a pre-alpha mess, but I'm slowly developing it into a playable mod. I plan to develop tactical units for each of the main Civ4 civilizations across ~20 combat eras, fully usable and understood by the AI.



Please try out the modcomp(s) and let me know your thoughts or ideas!
 
Last edited:
Sounds both interesting and useful. When you work on the Seasons part at least consider not imposing the northern hemisphere seasons on the whole world. The southern hemisphere seasons are offset by half a cycle and many parts of the tropics only get two seasons not four. This offset in seasons and trade is the main reason modern supermarkets in the richer countries have the variety of food they do.
 
Dynamic Techs

How it works:
Spoiler :

The game chooses a designated tech for each flavor for each player at the beginning of the game.

Flavors:
FLAVOR_MILITARY
FLAVOR_RELIGION
FLAVOR_CULTURE
FLAVOR_SCIENCE
FLAVOR_COMMERCE
FLAVOR_GROWTH
FLAVOR_ESPIONAGE
FLAVOR_PRODUCTION

To be chosen as a "designated tech", the flavor value must be at least self.minFlavorValue (currently set to 5 for the vanilla tech tree).

It's set to re-choose all of these techs when you load the game, but it should choose techs you already have beakers toward, so that it keeps roughly the same ones.

There are random bonuses given from certain actions, and trickling bonuses given each turn.

Random bonuses

Formula for random bonus for a flavor: (giveFlavorTech_Rand)

Base = self.iBase (30)
Randomness = self.iRandomness (20) unless specified in the function
Divisor = 1 unless specified in the function

Rand = Random number between -Randomness and +Randomness


Amount to change = (base + rand) / divisor

These bonuses are given:
*Military bonus after combat (both participants)
*Military bonus on declaring war or peace
*Military bonus for capturing a city
*Small military bonus for promoting a unit
*Bonus for the flavor of a building built
*Bonus for the flavor of a unit created
*Religion bonus for attempting to spread a religion
*Additional religion bonus for successfully spreading a religion
*Additional religion bonus when a religion is removed (doesn't apply to vanilla BTS)
*Religion bonus when changing state religions
*Growth, production, or commerce bonus on building an improvement


Trickling Bonuses

giveFlavorTech_Num gives a commerce amount (which will be divided by self.iCommerceDivisor, now 1, but you can change that if you feel like the commerce trickle is too much)

giveFlavorTech just gives a specified amount. (Currently unused, I think.)


Bonuses each turn (commerce bonuses):


## Divisors for turn bonuses
self.fMilitaryUnitsDivisor = 1
self.fReligionCitiesDivisor = 0.25
self.fProductionDivisor = 1
self.fCommerceRoutesDivisor = 0.025
self.fResearchDivisor = 1
self.fCultureDivisor = 5
self.fFoodDivisor = 1
self.fEspionageDivisor = 10

In addition the religion bonus is now minimum 1 beaker per turn.



How to use it in any mod:
Spoiler :

  1. Winmerge the CvEventManager.py file with the mod's CvEventManager
  2. Drop in Dynamica.py next to CvEventManager
  3. Go to the mod's Civ4TechInfos.xml, replace all instances of <bDisable>0 with <bDisable>1


Current issues:
  • No known errors. If you get one (or if you see some weird messages from my internal error catching) let me know!
  • The base game tech tree was not built with this mod in mind, so there will be some weird side effects. For example, no one gets religion techs.
How will the AI handle this?
  • They will be pleasantly surprised to receive new techs when that happens, and make good use of them
  • They will not know how to plan ahead to weight themselves toward new techs (for example, a human could figure out that they're getting beakers toward archery and spam military units until they get the tech, but the AI's will have no idea).
  • So, to balance it in favor of the AI a little, I suggest disabling the tech screen if you want to use this in a real mod.
 
Last edited:
Sounds both interesting and useful. When you work on the Seasons part at least consider not imposing the northern hemisphere seasons on the whole world. The southern hemisphere seasons are offset by half a cycle and many parts of the tropics only get two seasons not four. This offset in seasons and trade is the main reason modern supermarkets in the richer countries have the variety of food they do.

Yeah that's super important! That's one thing I'm trying to upgrade with Platyping's version, which just applies the season effects to everyone regardless of hemisphere...

I'm also making the effects scale with latitude. After all, Canada has far worse winters than Brazil.
 
I tried Dynamic Techs as a stand alone mod.
  1. Yes you can get techs for which you don't have the prerequisite tech

  2. I got the C++ error
    Code:
    Traceback (most recent call last):
    
      File "CvEventInterface", line 23, in onEvent
    
      File "CvEventManager", line 190, in handleEvent
    
      File "CvEventManager", line 386, in onEndPlayerTurn
    
      File "Dynamica", line 233, in giveTurnBonuses
    
      File "Dynamica", line 128, in giveFlavorTech_Num
    
    RuntimeError: unidentifiable C++ exception
    ERR: Python function onEvent failed, module CvEventInterface

  3. I got my first tech Meditation at the end of the first turn
 
I tried Dynamic Techs as a stand alone mod.
  1. Yes you can get techs for which you don't have the prerequisite tech

  2. I got the C++ error
    Code:
    Traceback (most recent call last):
    
      File "CvEventInterface", line 23, in onEvent
    
      File "CvEventManager", line 190, in handleEvent
    
      File "CvEventManager", line 386, in onEndPlayerTurn
    
      File "Dynamica", line 233, in giveTurnBonuses
    
      File "Dynamica", line 128, in giveFlavorTech_Num
    
    RuntimeError: unidentifiable C++ exception
    ERR: Python function onEvent failed, module CvEventInterface

  3. I got my first tech Meditation at the end of the first turn
All right, after MUCH debugging the C++ exception is gone. Turned out it was not finding an espionage tech, and then trying to give beakers to it anyway.

The insta-giving of religion techs was because the game got confused about how many state religion cities a player had, decided it was infinity, and gave that many beakers toward the player's religion tech. Fixed that too.

Still working on the prerequisite thing...
 
Prerequisite thing seems to have been fixed. Apparently, according to Civ4, all players "own" the tech that has index "-1", so if a tech has no AndPrereqs, my method was saying you could research it even if you couldn't actually. What a weird problem.

That means there are no errors currently. I think the balancing still needs some work though.
 
I am now getting this error every turn
Code:
Traceback (most recent call last):

  File "CvEventInterface", line 23, in onEvent

  File "CvEventManager", line 190, in handleEvent

  File "CvEventManager", line 694, in onUnitBuildImprovement

AttributeError: 'NoneType' object has no attribute 'getYieldChange'
ERR: Python function onEvent failed, module CvEventInterface

Note: I don't have a worker so it isn't me building an improvement.
 

Attachments

  • dyna.CivBeyondSwordSave
    83.9 KB · Views: 199
I got that error too but I was building an improvement...that's really weird. I'll have to look at that.

Also, found out the trickling bonuses are NOT doing what I thought they were, so you're probably getting Mining on turn 2
 
I got that error too but I was building an improvement...that's really weird. I'll have to look at that.

Also, found out the trickling bonuses are NOT doing what I thought they were, so you're probably getting Mining on turn 2
Yes I did get Mining on the second turn.
 
Wow! Pretty awesome! I will try it ASAP and probably merge into CoM. Thanx for your work :goodjob:

Question:
Does it also work, if I disable only Ancient tech? I want to give back control over research with the Classical era. Still, having some dynamic "Eurekas" from this modcomp would be even better.
 
Okay, so I tried Dynamic tech. Not Much, but I tried and some strange error massages:
upload_2020-4-9_16-29-49.png

I also want to mention that after researching Hunting I received no further :science: to any techs 10 or 20 turns. :confused:

EDIT:
And now when settling my 2nd city on the coast I suddenly received Fishing. It went from 0:science: to fully researched in a single turn. Is that normal?
 
Last edited:
Hahaha wow! I have no idea what's happening there

But I'll take a look. finals are over now so I have some time lol

I know some of the trickle numbers were really screwed up. It counts you as always having one trade route, for example, and doesn't seem to count hammers or food at all. So it might have something to do with that.

Edit: Flavor 2 is production, flavor 6 is growth, so I'm 99% sure it's the method that is supposed to count how many hammers/food you have. (I don't know why it doesn't just count them. Gosh dang it.)

Fishing is coming from the trade routes problem, right now it's set to give you 40 beakers toward an economic tech for every trade route you have (probably too much) and it decides you have a trade route from the very beginning (which is why you get mining right off the bat).

As far as allowing research when you get to a certain era, all you'd have to do is change bDisable to 0 in the xml file. You still might get beakers toward techs you're researching, though.
 
As far as allowing research when you get to a certain era, all you'd have to do is change bDisable to 0 in the xml file. You still might get beakers toward techs you're researching, though.
That would be perfectly fine ;)
 
Ok I've uploaded a new version with 6 bugs fixed (lol).

  1. I changed the trickle for gold from trade routes to just base commerce. (My original thinking was that trade routes were a better predictor but I realized people trade within cities too.)
  2. I fixed the calculation for the hammers/food/commerce yields (apparently using gc.getTypesEnum there didn't work, I'm guessing they are not enums).
  3. Figuring out the highest flavor of a building when it's built works now
  4. There should no longer be any weird errors about building "nonetype" improvements (basically whenever a worker chopped a tree or built a road, the tech chooser would get confused at how many yields that improvement had, because there was no improvement. fixed now.)
  5. Revamped how the tech choose figures out if you can "research" a disabled tech. (I just copied over line by line from the C++, changed it to python syntax, and removed the check for being disabled.) It works quite well now.
  6. As part of that, the tech chooser will no longer try to give you beakers for techs you already have. (hehe.) that is why no one was getting techs after the first one.
After some testing it looks like it works pretty well! I got hunting, fishing, then it moved to pottery, bronze working, animal husbandry, later gave me writing and iron working and was working on alphabet. A different time it picked different techs (including sailing) which is the main goal of the mod, so I'm very happy with it.

There are still two possible problems.
  1. There's not really a way to get religious techs until you have religions. hm. That also counts out things that require religious techs, like masonry.
  2. I haven't done anything to balance this based on game speed, so right now you pop a bunch of techs pretty dang quickly.

Edit: I realized game speed already does affect tech rates, so no need to balance. So I just turned down the trickle rates a bit and the mod should run really well.

Also, the vanilla tech tree has two problems with this mod -
  1. The tree is very interconnected, so if you can't get a certain tech at the beginning (masonry) then you're out of luck for a whole bunch of different techs down the line
  2. Some techs don't have obvious flavors, or don't have any flavors that are big enough for this mod to choose them to fill a category. (Sailing is a science flavor tech, apparently.)
 
Last edited:
Some techs don't have obvious flavors, or don't have any flavors that are big enough for this mod to choose them to fill a category. (Sailing is a science flavor tech, apparently.)
So there is nothing to fill FLAVOR_SCIENCE and FLAVOR_RELIGION techs? Maybe there could be an extra check if player has any building or whatever that that fills that specific flavor. If there are none, than he gets a constant +1:science: each turn toward that tech. So it wont happen that you don't get :science: for TECH_X because the only source of of :science: to TECH_X is unlocked by TECH_X. (Maybe this should be applied to all flavors)

An other thing: Can you make the modcomp optional? So if I merge it with my mod I don't make it mandatory for players but they can decide at game start? Well, of course you need to handle tech disabling somehow.
 
So there is nothing to fill FLAVOR_SCIENCE and FLAVOR_RELIGION techs? Maybe there could be an extra check if player has any building or whatever that that fills that specific flavor. If there are none, than he gets a constant +1:science: each turn toward that tech. So it wont happen that you don't get :science: for TECH_X because the only source of of :science: to TECH_X is unlocked by TECH_X. (Maybe this should be applied to all flavors)

Good idea! Only took 2 lines to add it, too. Now the minimum beakers you can get per turn is 1

An other thing: Can you make the modcomp optional? So if I merge it with my mod I don't make it mandatory for players but they can decide at game start? Well, of course you need to handle tech disabling somehow.

I've never added a game option before but it seems straightforward enough. I would like all these things I'm adding to be optional in my mod eventually too. So at some point I'll add that to this mod. But it'll take some work to convert the python to work with game options, especially the disabled tech part. (My new method would ignore techs being disabled through CvGameUtil, so it's definitely possible to disable them only if the option is available...)
 
Seasons with Snowfall

Adds random snowfall to Platyping's original Seasons modcomp.

Edit 5/14: Fixed the melting, but snow is sporadic and random. I'd like it to be more predictable like real winter (It basically always snows in winter in Russia for example) so I'm thinking about how to revamp it right now.

Edit 5/22: I changed the snow system. It's now based on a "snow line" that moves poleward in the winter and equatorward in the summer. Details in this nifty spoiler

Spoiler Details :


There are actually two snowlines. One starts at 80 degrees and goes down to 45, the other starts at 70 and goes down to 30. The maximum is on turn 4 of winter, and the minimum is on turn 4 of summer.

If a tile is poleward of the first line, it will have snow no matter what. If it is in between the two lines, it has a 50% chance of having snow, much higher if it's a hill or peak.

All of these numbers are included as globals in the top of the file.



I also put variables in the top of Seasons.py called "self.iTopLatitude" and "self.iBottomLatitude". They are currently set to cover the whole world, 90 and -90. You can change these numbers to fit whatever scenario you are in! The snow works based on latitude, not y-coordinates, so it will fit any map. You just need to change it each time you load a different scenario.

I also removed Platyping's changes to improvements. Eventually I'm going to have some different improvements for the different seasons, but I figure "snowy terrain" with 0 food does the trick for now.
 
Last edited:
Top Bottom