1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Merkava's Mods

Discussion in 'Civ4 - Mod Components' started by Merkava120, Apr 2, 2020.

  1. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    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.
    • My current goal is to get a nomadic start working well with a dynamic tech system, seasons, and animals, and then upload the first version.


    As I work on Dynamica, I will also upload standalone versions of everything I add to the game. Here are the ones I've finished:

    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.

    Here is what I am currently working on:
    • Nomadic start, where settlers are unavailable and if you don't have cities your units take damage from hunger.
    • Hunting system giving units health for killing animals.
    • Animal spawning system involving predator, prey, and plant animal units that spawn realistically across the map and reproduce like real animals (but balanced to make extinction less likely).
    • Upgrading platyping's Seasons modcomp to cause snowfall depending on map size and type (currently figuring out a way to let the game know if your map is a region like Europe, or the whole world).
    • Combining platyping's promotions with dynamic promotions, where promotions are mostly unavailable except when dynamically given for winning in certain situations.
    • Python-based defensive "withdrawal" where units that are defeated instead rout back a tile (unless they run into a river, ocean, or mountain).
    • Updating the Mongol Camp (by Fierabras) to be more streamlined and use non-hardcoded unit names (so it will just spawn whatever units you are able to create).
    • A completely unrelated project to convert Civ4 into a tactical game (starting with World War II but eventually including all eras).

    Please try out the modcomp(s) and let me know your thoughts or ideas!
     
    Last edited: Jul 1, 2020 at 12:00 AM
    Zeta Nexus and topsecret like this.
  2. Dancing Hoskuld

    Dancing Hoskuld Deity

    Joined:
    Jul 5, 2004
    Messages:
    23,518
    Gender:
    Male
    Location:
    Canberra, Australia
    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.
     
  3. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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



    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: Apr 23, 2020
  4. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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.
     
  5. keldath

    keldath LivE LonG AnD PrOsPeR

    Joined:
    Dec 20, 2005
    Messages:
    6,591
    Location:
    israel
    בהצלחה חבר

    Good luck friend,
    Sounds like a promising project, ill be following this one closely.
     
  6. Dancing Hoskuld

    Dancing Hoskuld Deity

    Joined:
    Jul 5, 2004
    Messages:
    23,518
    Gender:
    Male
    Location:
    Canberra, Australia
    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
     
  7. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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...
     
  8. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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.
     
  9. Dancing Hoskuld

    Dancing Hoskuld Deity

    Joined:
    Jul 5, 2004
    Messages:
    23,518
    Gender:
    Male
    Location:
    Canberra, Australia
    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.
     

    Attached Files:

  10. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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
     
  11. Dancing Hoskuld

    Dancing Hoskuld Deity

    Joined:
    Jul 5, 2004
    Messages:
    23,518
    Gender:
    Male
    Location:
    Canberra, Australia
    Yes I did get Mining on the second turn.
     
  12. Zeta Nexus

    Zeta Nexus Deity

    Joined:
    Jan 23, 2014
    Messages:
    3,785
    Gender:
    Male
    Location:
    In a constant brainstorm...
    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.
     
  13. Zeta Nexus

    Zeta Nexus Deity

    Joined:
    Jan 23, 2014
    Messages:
    3,785
    Gender:
    Male
    Location:
    In a constant brainstorm...
    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: Apr 9, 2020
  14. Zeta Nexus

    Zeta Nexus Deity

    Joined:
    Jan 23, 2014
    Messages:
    3,785
    Gender:
    Male
    Location:
    In a constant brainstorm...
    I keep receiving these error massages each and every turn:
    upload_2020-4-9_17-30-55.png
     
  15. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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.
     
  16. Zeta Nexus

    Zeta Nexus Deity

    Joined:
    Jan 23, 2014
    Messages:
    3,785
    Gender:
    Male
    Location:
    In a constant brainstorm...
    That would be perfectly fine ;)
     
  17. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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: Apr 23, 2020
  18. Zeta Nexus

    Zeta Nexus Deity

    Joined:
    Jan 23, 2014
    Messages:
    3,785
    Gender:
    Male
    Location:
    In a constant brainstorm...
    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.
     
  19. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    Good idea! Only took 2 lines to add it, too. Now the minimum beakers you can get per turn is 1

    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...)
     
    Zeta Nexus likes this.
  20. Merkava120

    Merkava120 Oberleutnant

    Joined:
    Feb 2, 2013
    Messages:
    375
    Gender:
    Male
    Location:
    Socially distant
    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: May 22, 2020

Share This Page