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

Training Barracks mod

Discussion in 'Civ4 - Mod Components' started by RogerBacon, Jan 1, 2006.

  1. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    [edit] 02/07/2006 version 1.1


    Hello all,

    This is a mod that replaces the 4 experience you get from barracks and drydock with a chance of getting 1 experience each turn. You can customize the chance of getting experience (currently set to 10%) and also you can customize the maximum amount of experience you can get from a barracks or drydock (currently set to 10).
    Units must be in a city with a barracks (land units) or drydock (naval units) to have a chance of gaining experience each turn. Each unit is checked for independently to see if it gets experience each turn.

    Version history:

    Version 1.1 (02/07/2006)
    Changed the requirement for naval units to "Harbor" rather than "Drydock" because drydocks come so late in the game and the naval aspects of Civ need as much of a boost as they can get.

    Added an alternative method for calculating the chance of a unit getting an exp point each turn:

    # Linear chance method
    #iRandNum = gc.getGame().getMapRand().get(pUnit.getExperience()*2+1, "Barracks Training")

    Lowered max exp to 8

    Version 1.01 (1/02/2006) (247 downloads)
    Optimized some code to help with make it compatible with future patches.
    Added code to make sure the units in the city belonged to the player before giving the exp bonus.

    Version 1.0 (1/01/2006)
    Initial release. Designed to work with Civ4 version 1.52
    Roger Bacon
     

    Attached Files:

  2. Bhruic

    Bhruic Emperor

    Joined:
    Nov 15, 2005
    Messages:
    1,457
    Now I see what you wanted it for. ;)

    A couple points :
    Code:
    if ( (uType > 0) and (uType != 8)):
    Not really a good idea. If someone mods the combat types, or worse, a new patch comes out that changes them, it'll break your mod. A better way:
    Code:
    if ( (uType != gc.getInfoTypeForString("UNITCOMBAT_NAVAL") and (uType > gc.getInfoTypeForString("NO_UNITCOMBAT")) ):
    Second, and more importantly, your mod doesn't check the owner of a unit. So if you have an open borders agreement with someone, you could put your unit in their city (with a barracks) and gain a bunch of XP. That would be somewhat exploitable.

    Otherwise, a nice little mod. I haven't tried it yet, have you tested it with a 10% chance? Thought that seemed a little high to me, although it's easy enough to change.

    Good job. :)

    Bh
     
  3. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    Thanks for the advice. I have updated the mod to make the changes you suggested.

    I had thought of the open borders thing and I was going to leave it that way. I was thinking that it is kind of like how the US and UK or US and Japan train together. After some more thought, however, I decided that such things didn't happen very often during more of the time period in Civ4 so I changed it.

    Roger Bacon
     
  4. jollyroger3

    jollyroger3 Chieftain

    Joined:
    Dec 29, 2005
    Messages:
    94
    It's a really good idea - I like it very much :) Today I'll try out your mod :goodjob:
     
  5. AAGamer

    AAGamer Hauptman-JG53

    Joined:
    May 5, 2002
    Messages:
    67
    Location:
    Sparta, WI, USA
    Interestiing. I like this very much thanks.
     
  6. Thalassicus

    Thalassicus Bytes and Nibblers

    Joined:
    Nov 9, 2005
    Messages:
    11,057
    Location:
    Texas
    It definitely makes make defensive units much more useful, balances out the steamrolling advantage. It'd probably be best to limit the cap to below 10 until you build the Heroic Epic, as 10 XP enables that wonder :)

    You can also calculate the percentage required to gain an average of 1 experience per X turns with the formula: 1-0.5^(1/x). It can be made a factor of game speed this way:

    dTurnsPerXP = turns * gc.getGame().getGameSpeedType().getTrainPercent() / 100.0
    dPercentage = 1.0 - 0.5 ^ (1.0 / dTurnsPerXP)
     
  7. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    Thanks for the idea. I'll probably implement that in the next version.

    I don't think I am understanding the formula correctly though? If X = 1 ( expect 1 exp per turn) you would get:
    1 - 0.5^(1/1)
    = 1- 0.5
    = 0.5
    This would be 50% chance, which would average out to 1 exp per 2 turns.

    Roger Bacon
     
  8. fishhead

    fishhead Chieftain

    Joined:
    Jan 9, 2006
    Messages:
    38
    no, x is not the exp per turn in this formula... x is the game speed.. when the game speed is faster (less turns) the chance of a unit getting exp is higher and when game speed is slow (more turns) the chance is lower
     
  9. Defectiv

    Defectiv Chieftain

    Joined:
    Nov 19, 2001
    Messages:
    43
    Location:
    Rotterdam, The Netherlands
    Nice idea, i do agree with Thalassicus that it should be capped, because i feel only battle should produce high exp. units. Training can only harden and train you upto a certain point. Maybe 8 EXP as a max? And 10% seems too high but i havn't tried it yet so don't know that for sure.
     
  10. Kidinnu

    Kidinnu Chieftain

    Joined:
    Dec 10, 2005
    Messages:
    92
    Location:
    North Carolina
    At 10%, it'll take your defenders somewhere around 100 turns to reach 10 xp; that's, what, a quarter of the game? So your capital might have l4 defenders by the time anybody attacks it (non-blitz), but there'll certainly be a window of vulnerability in all your new conquests, unless you're training up large masses of defenders in your core cities and rotating them out to the provinces as they top out.

    Another idea would be to make it exponentially decaying: chance of gaining a new experience point in the next turn is 1/(current xp + 4). So 25% chance for a new unit, but lower for an older unit. Or 1/(2*current xp + 1) makes it certain for a new unit, but a unit that just dinged lvl 3 (5 xp) only has a 9% chance of gaining, and a unit is expected to take 20 turns to go from 9 xp to 10. This only increases expected time to 10xp from 100 turns to 110, but it means you get the early levels faster (more like the current barracks) and the last level much slower. And if you uncap XP, it shouldn't be too horrible - I think it'd take an expected 300+ turns to reach 20 xp.
     
  11. kevjm

    kevjm Warlord

    Joined:
    Dec 31, 2005
    Messages:
    279
    Location:
    England
    Perhaps the civics and wonders which affect exp could be changed too? affecting the cap or the rate of increas?
     
  12. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    Yes, I plan to do something like that this weekend. I've also got an idea to incoprorate an element from someone else's mod into mine. I'll be able to do something with it that he wanted to do but couldn't do the way old barracks worked.

    @Kidinnu
    I thought about more complicated, non-linear ideas but I wanted to keep the formula simple so people could customize it easily. Also, as suggested above, I plan to eventually add in modifiers such as civic type, leader traits, etc.

    Roger Bacon
     
  13. AAGamer

    AAGamer Hauptman-JG53

    Joined:
    May 5, 2002
    Messages:
    67
    Location:
    Sparta, WI, USA
    Hi,

    Does this mod set the starting barracks level to 1 from 4?

    If so How do I reset it back to 4?

    Thanks.
     
  14. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    I'm not sure I understand your question but I think you are asking if it changes the exp you get when a unit is created.

    Yes, this barracks gives you zero exp when a unit is created instead of the 4 you normally get. To change it back to 4 just don't install the CIV4BuildingInfos.xml file (or delete mine if you already installed it). That was the only change in my CIV4BuildingInfos.xml file.

    Roger Bacon
     
  15. Thalassicus

    Thalassicus Bytes and Nibblers

    Joined:
    Nov 9, 2005
    Messages:
    11,057
    Location:
    Texas
    Half the values in a range fall below average, half fall above it. So if X=1, then half the time it takes 1 turn to gain 1 experience, and half the time it takes more than that: the average time is one elapsed turn. :)

    To give another example, if the percentage to gain XP is 15%, you have an 85% chance per turn of not gaining XP. After 4 turns, the chance of not having gained XP is 0.85*0.85*0.85*0.85 (or 0.85 ^ 4) = 50%. So after 4 turns, you have a 50% chance of having gained/not having gained 1 XP, and 4 turns is thus the average time required to gain experience at a 15% chance per turn. Working this formula backwards gives you the one listed previously, allowing you to calculate the percentage required when given the average time.


    On a side note, this can also be solved the other way to calculate the average number of turns with a given percentage using the formula log(0.5)/log(1-P), where P is the percent chance per turn in decimal. So for example, with a 0.1 chance per turn, the average turns required to gain one XP is about 6.5, or 65 turns to gain 10 XP. (A normal length game is something like 450 turns, in comparison.)
     
  16. AAGamer

    AAGamer Hauptman-JG53

    Joined:
    May 5, 2002
    Messages:
    67
    Location:
    Sparta, WI, USA
    Roger,

    Yes you got my question right. Only problem is I want the units to start out with 4 xp and then use your mod.. LOL>. so I guess I have to find out what you changed in the building file.. Time for digging about in it now.
     
  17. AAGamer

    AAGamer Hauptman-JG53

    Joined:
    May 5, 2002
    Messages:
    67
    Location:
    Sparta, WI, USA
    I did find out my own answer, rather quickly actually. (Thanks again for the reply it is appreciated. )

    The lines to place back into your mod to add the experience back and use your mod are..

    <DomainFreeExperiences>
    <DomainFreeExperience>
    <DomainType>DOMAIN_LAND</DomainType>
    <iExperience>4</iExperience>
    </DomainFreeExperience>
     
  18. Martock

    Martock Warlord

    Joined:
    Jun 19, 2003
    Messages:
    254
    Location:
    South Carolina, USA
    Sadly, while I followed the instructions on making this the 'default' setting for my CIV IV, I've noticed that it didn't seem to work with the 'Graves Mega Mod v2.1'. It's a shame as I really like this idea and think it should be implemented as a default addition to Civ IV.
     
  19. RogerBacon

    RogerBacon King

    Joined:
    Nov 16, 2003
    Messages:
    649
    Graves Mega Mod v2.1 uses a CustomEventManager, just like my mod. You can only have one file with the same name laoded at one time. Since files in the MODS folder load before those inthe CumstomAssets folder, the Graves one will load and keep mine from loading.

    You can combine mine with Granves. It's pretty simple.

    1 Open Graves CustomEventManager and add one more "import" line:

    import TrainingBarracks

    2 Add this to Graves CustomEventManager on the line after sr = SettlerReligion.SettlerReligion():

    sho = TrainingBarracks.TrainingBarracks()

    3 Add this to Graves CustomEventManager on the line after
    def onBeginGameTurn(self, argsList):
    iGameTurn = argsList[0]
    researchProgress.onBeginGameTurn(argsList)
    self.parent.onBeginGameTurn(self, argsList):

    sho.onBeginGameTurn(argsList)



    4 Add TrainingBarracks.py into the same directory as Graves CustomEvenManager (You can also keep a copy in CustomAssets like my readme says so that you can continue to use TrainingBarracks with and without Graves mod.

    I hope that helps.

    Roger Bacon
     
  20. Martock

    Martock Warlord

    Joined:
    Jun 19, 2003
    Messages:
    254
    Location:
    South Carolina, USA
    Sweet! I'll give that a try when I get back home later. Can this be added to a game already in progress or will I have to start a new one?
     

Share This Page