[Python] zUnit Enslavement

Zebra 9

Emperor
Joined
May 17, 2006
Messages
1,554
Location
Middle of Cyberspace
zUnit Enslavement v0.21

Patch Compatibility: 1.61, 2.00, 2.08 (All Versions Of Civ 4 That Are worth Haveing)
Multiplayer Compatiblity: Not tested but should work

Description:
A basic Python component that allows you to set any number of units to enslave any
unit at any chance that you want. I made every attempt to make it as user friendly
as possible and I belive that anyone how has at least read the first 2-3 pages of any
good Python tutorial should be able to use it.

Usage:
I have defined 3 basic functions to allow the user to interact with the Python
classes I created. I'm not going in depth here (I provided documentation) but the 3
functions that I defined allow you to set data on unit classes & unit types, as well
one that allows you to set a land and sea unit type for enslavement by any unit.:king:

Here are the instructions for instaling as a MOD:
1) Unzip into "My Documents\My Games\Warlords\MODS".
2) Load the game.
3) Click on "Advanced"-->"Load A MOD"-->"zUnitEnslavement", the Game will restart.
4) Now you can play as normal. :goodjob:

Instaling into a MOD takes only about 5 lines of code and copying a file into the
python directory.

Things Changed In v0.21:
Fixed the tech bug that prevented you from enslaveing under certain circumstances

Things Changed In v0.2:
I fixed a misspelling (thanks to strategyonly for pointing this out).
I added prerequisite and obsoleteing technology options.
I added new functions that allow you to set Land and Sea units seperatly or you can still use the setAllEnslave.
Changed the math after realizing that 0% actually meant 1% that is now fixed so 0% is 0%.

Credits:
Well I did the whole thing but I would like to thank strategyonly for asking me to
make this for him.

Located Here:)
 
I had a question about this mode.

I created a unit called "Javelineer", and I want it to enslave other units into workers.

If I define it as this:

self.addUnitClass("UNITCLASS_JAVELINEER", "UNIT_WORKER", 25)

does the Javelineer have a 25% chance to enslave just workers, or a 25% chance to enslave any unit it defeats as a worker (much like the effect in civ3)
 
I have this already in my MOD and its GREAT, THX!! Everything i asked for i want generic so others could use it and not just one MOD and the README file is VERY VERY good, explains everything.
 
Edgecrusher
It would give the Javelineer a 25% chance of enslaving a worker no matter what unit it fights. Actually that might not be a bad idea to allow you to set a list of units that you can enslave from.:goodjob:

Fixed a new bug! I'm a dope! This will not affect anything that you have already done!
 
Just wondering.

I set it to 100% and started to attack, just to get it to work. I must be missing something becuase I havent been able to solve it yet.

This is my first attemt at editing Python and am using this to learn some basics. So not being able to work wasn't unexpected.


What did you attempt to do: post code?
 
does enslaving apply to barbarin animals?
 
It applies to everything. In the future I want to make it so you have a more control over what you enslave from.

Edgecrusher could you post the code you put after the line that sayes
def __init__(self):​
.
 
I thought I was following the directions you had provided Here is what i did.

I edited the CvEventManager file. At the top I put this line of code.

from CvPythonExtensions import *
from zUnitEnslavement import *

A little bit down, after #globals I put
PHP:
[B]class enslave(enslavement):
    def __init__(self):
        self.addUnitType("UNIT_JAVELINEER", UNITCLASS_WORKER, 100)[/B]

I skipped down and under the def onCombatResult section I put just this

PHP:
	def onCombatResult(self, argsList):
		'Combat Result'
		pWinner,pLoser = argsList
		
		self.enslave().doEnslavement(pWinner, pLoser, self.enslave())
		playerX = PyPlayer(pWinner.getOwner())
		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
		playerY = PyPlayer(pLoser.getOwner())
		unitY = PyInfo.UnitInfo(pLoser.getUnitType())
		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()))

Anyway I havent been home to play with it in a bit. Tomorrow I will have some time. I appreciate any help you can give. but like I said, I'm learning.
 
Strategyonly I don't see anything wrong with your code. The only thing I can think might be wrong is that maybe the unit class for A1 is diferent than A2 (See below image), this could be anj oversight or a misspelling.

Edgecrusher I will test your code and let you know.
 

Attachments

  • Archers.gif
    Archers.gif
    312.6 KB · Views: 234
class enslave(enslavement):
def __init__(self):
self.setAllEnslave("UNIT_WORKER", None, 100, 0) #Remove This When You add Your Own Code
self.addUnitClass("UNITCLASS_ARCHER", "UNIT_ARCHER", 100)
self.addUnitClass("UNITCLASS_MACEMAN", "UNIT_WARRIOR", 100)
self.addUnitClass("UNITCLASS_TANK", "UNIT_MACEMAN", 100)

Strategy, Im wondering, Was it because of the bolded sections?

The 2 lines of code, If I am interpreting it correctly, self.AllEnslave, makes all units enslave workers.

then the self.addunitclass line is making it so all archers create an archer.

So in a sense, the archer is getting the ability to enslave an archer and a worker?
 
No the addUnitClass overides the setAllEnslave. His archer would only enslave an archer and never a worker. His problem is most likely in the unitinfos.xml, the unit class is wrong on A2 (see my above post).
 
No the addUnitClass overides the setAllEnslave. His archer would only enslave an archer and never a worker. His problem is most likely in the unitinfos.xml, the unit class is wrong on A2 (see my above post).

Yeppers your right, i had one as a LONGBOWMAN Archer and the other just as an Archer, DUH!!!
 
Edgecrusher I found your problem.
Right now you have:
Code:
class enslave(enslavement):
    def __init__(self):
        self.addUnitType("UNIT_JAVELINEER", [B]UNITCLASS_WORKER[/B], 100)

You need to put quotes on both sides of UNITCLASS_WORKER, so it would look like:
Code:
class enslave(enslavement):
    def __init__(self):
        self.addUnitType("UNIT_JAVELINEER", [B]"UNITCLASS_WORKER"[/B], 100)
If you use this code it should work!:goodjob:
 
Hi :)
Its possible to add a civic prerequesit, for exemple only in slavery civic it can enslave.
Maybe possibility to choose civicXORcivicY if we want POW in later eras.
 
Hi,
I plan to use this ModComp in my future Spain 1936 for BtS Mod (with credits given to :bowdown: Zebra 9, of course).

So I had to add few modifications to render it BtS compatible. It's done (it was really a little job : only the "initUnit" to change...:p ).
While modifiing, I added too the possibility to translate the Mod. And I translated it into French. :D
NB: German, Italian and Spanish versions actually return english text, but you just have to modify the xml file to add these languages. :goodjob:

@Zebra 9 :
Spoiler :

I let you add the file to the database : it's still your Mod, no credit for me, here.
 

Attachments

  • zUnitEnslavement_BtS.zip
    32 KB · Views: 145
Top Bottom