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

[BTS Module] Slaves

Discussion in 'Civ4 - Mod Components' started by Gurra09, Apr 9, 2009.

  1. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    Unfortunately that flag only sets military support costs, not support costs per unit. You still pay 1 gold per unit per round, including for workers. Military units have additional costs depending on what civics you have and whether they are in your own territory or not. Some civics like pacifism can add more costs, and then you pay extra if you're not in your own territory (for military units). But anyway there is still a support cost for a unit whether that flag is checked or not.
     
  2. Chrill

    Chrill Chieftain

    Joined:
    Aug 19, 2002
    Messages:
    26
    Location:
    Sweden
    I've toyed around with the capuring of units under certain criteras as well. The basic python code is presented below, won't work in other mods as it's designed for my own, however the idea of it is quite simple and can easily be modified. It works like this: if you won the battle, and have a military civic called slave army (can easily be changed to LABOR / SLAVERY) and the unitcombat type is either MELEE, GUN or SPEAR (can easily be modified) and after that a check to see if the winning unit doesn't have a promotion called "ENSLAVE". Last a random number is calculated (25% chance of enslavement).

    Now after the battle is won and all the above criterias have been met a unit (the type is the defeated unit type) is created with 25% health that cannot move this turn and the promotion ENSLAVE (basically indicating it's an enslaved unit and cannot enslave others thus the check above).

    The coding is quite crude as I'm no expert, but it works and shows it's not all that difficult to add in cveventmanager. Just change a few criterias and what kind of unit you want from the battle (iUnit). I Hope all this could give some inspiration :)

    Code:
    	def onCombatResult(self, argsList):
    		'Combat Result'
    		pWinner,pLoser = argsList
    		playerX = PyPlayer(pWinner.getOwner())
    		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
    		playerY = PyPlayer(pLoser.getOwner())
    		unitY = PyInfo.UnitInfo(pLoser.getUnitType())
    ## Enslaver! ##
    		pPlayer = gc.getPlayer(pWinner.getOwner())
    		if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_MILITARY')) == gc.getInfoTypeForString('CIVIC_SLAVE_ARMY'):
    			if (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MELEE")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_GUN")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_SPEAR")):
    				if not pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENSLAVE')):
    					if CyGame().getSorenRandNum(100, "Bob") <= 25:
    						iUnit = pLoser.getUnitType()
    						newUnit = pPlayer.initUnit(iUnit, pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
    						newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENSLAVE'), True)	
    						newUnit.finishMoves()
    						newUnit.setDamage(75, False)
    ## Enslaver! ##
    		if (not self.__LOG_COMBAT):
    			return
    		if playerX and playerX and unitX and playerY:
    			CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s' 
    				%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(), 
    				playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
    
     
  3. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    I have two ideas for thought:

    1. There should be function to eliminate all of the slave units, when switching over to the emancipation civic. This would simulate freedom for all and the end of slavery. Thus, no more slaves, as they all disappear.

    2. There should be function to limit the production of slave units to only the slavery civic. If you switch away from the slavery civic, you can't produce any more slaves. The existing slaves remain until used up or disappear when switching to the emancipation civic.


    Orion Veteran :cool:
     
  4. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    Chrill (or anyone else who might know):

    How would you set a specific unit type using that code, rather than just a unit of the type that was defeated?

    I get the impression it's contained in this line:

    newUnit = pPlayer.initUnit(iUnit, pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)

    But I don't know Python well enough to alter that to what I want. I gather that it's set by Y() ... would it be like this?:

    newUnit = pPlayer.initUnit(iUnit, pWinner.getX(), "UNIT_WORKER", UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
     
  5. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    33,101
    Location:
    DE/NL/FR
    X and Y is only the position for the new unit.

    What you want:

    PHP:
    newUnit pPlayer.initUnit(gc.getInfoTypeForString'UNIT_WHATEVER' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAIDirectionTypes.NO_DIRECTION)
     
  6. Gurra09

    Gurra09 First Consul

    Joined:
    Jan 1, 2008
    Messages:
    1,285
    Slaves have always only been able to be produced if using the Slavery Civic. But that's coded in Python and doesn't show up in the Civilopedia.
     
  7. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    Perfect ... thanks ... I got it working great.

    I even managed to figure out how to restrict it so that only certain types of units could be enslaved. Once I got it going, I noticed that it would produce slaves from panthers, catapults, and when a worker or settler was captured you'd get the worker plus a slave (at 100% odds). So ... I restricted it to reasonable unit types (mounted, melee, archery, gun, and spear). Only these kinds of units will produce a slave when defeated, now.

    In case anyone's interested:

    PHP:
    ## Enslaver! ##
            
    pPlayer gc.getPlayer(pWinner.getOwner())
            if 
    pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_LABOR')) == gc.getInfoTypeForString('CIVIC_SLAVERY'):
                if (
    pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MELEE")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_GUN")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_SPEAR")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MOUNTED")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_ARCHER")):
                    if (
    unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MELEE")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_GUN")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_SPEAR")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MOUNTED")) or (pWinner.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_ARCHER")):
                        if 
    CyGame().getSorenRandNum(100"Bob") <= 5:
                            
    iUnit pLoser.getUnitType()
                            
    newUnit pPlayer.initUnit(gc.getInfoTypeForString'UNIT_SLAVE' ), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAIDirectionTypes.NO_DIRECTION)
                            
    newUnit.finishMoves()
    ## Enslaver! ##
    Oh yeah, and I reduced it to 5% chance.

    There's just one thing more that would make it perfect, and that would be a message to come up.

    EDIT; if anyone decides to use this, I noticed one little error. Chrill must have been using it with some sort of mod that featured a new unitcombat class, namely UNITCOMBAT_SPEAR. Such does not exist in the base game, so omit it from the above unless you've got a UNITCOMBAT_SPEAR.
     
  8. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    33,101
    Location:
    DE/NL/FR
    Try
    PHP:
    CyInterface().addMessage(pWinner.getOwner(),False,15,CyTranslator().getText("TXT_KEY_WHATEVERIWANT",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(44), pWinner.getX(), pWinner.getY(), True,True)
    The button can also be changed to whatever you want.



    And good work for the first time :thumbsup:.
     
  9. Gurra09

    Gurra09 First Consul

    Joined:
    Jan 1, 2008
    Messages:
    1,285
    I have uploaded a new file with a few text changes.

    Two lines are added for the Slave in the Civilopedia:

    Destroyed upon Completion of Work
    Requires Slavery

    One line is added for Slavery in the Civilopedia and the Civics Screen:

    Required to Train Slave

    One line is added for the Work Boat in the Civilopedia:

    Destroyed upon Completion of Work
     
  10. Melendor

    Melendor Warlord

    Joined:
    Aug 7, 2008
    Messages:
    185
    Location:
    Rio de Janeiro, Brazil
    Suggestions:

    1 – Gladiators: you can use a slave as gladiator in any city with colosseum. It would give +1 :) per 10 turns; 2% of the times you would receive a gladiator after that time (axeman or maceman);

    2 – Sacrifice: it would generate 25:culture:. Paganism and/or pagan temple would be necessary.
     
  11. Chrill

    Chrill Chieftain

    Joined:
    Aug 19, 2002
    Messages:
    26
    Location:
    Sweden
    I experienced some really strange Ai behavior from my workers when i tried the concept of the above mod (especially adding the XML changes that add slave specífic improvements). First of all the ai trains slaves in an endless loop really, they never build workers if they can. And regular workers did some really weird stuff like never building cottages or farms ever, just roads. Only after removing all slave specific improvements the worker ai worked "properly" again...

    I would suggest having the slave non-buildable and only availible from succesful combat (as the AI won't understand the differance when building a lave and a worker other than the cost as of it as of now...) and have it build all the same improvements the worker can, but perhaps decreasing the workrate.

    Adding some python code could kill of slaves when switching from slavery.
     

Share This Page