regicide sdk code is needed (like civ3 vic condition)

keldath

LivE LonG AnD PrOsPeR
Joined
Dec 20, 2005
Messages
7,578
Location
israel
hi,

i hope someone can help me and the dune wars team,


i wanna have a regicide victory condition just like in civ 3 -


idea:

when you start the game - you start with a leader unit:

to win the game: you need to eliminate all of the opponents leader units.

lose the game : your leader unit gets killed.

simple and easy huh?

i guess theres should be a tag under the unit thats says - <bregicide>1 to set the leader unit, and some thing in the victory sdk/xml.
and of course the ai should know it needs to kill this unit if regicide vic is chosen.

i really
hope someone can do this for us,
im sure many civ players on the site would be very very happy with this component.

thanks in advance,
keldath and the dune team.
 
onCombatResult is part of the solution. The other, harder part is changing the AI so that (a) it protects its own king, and (b) it attacks yours. If the king unit is done well, it is so powerful that it is tempting to use it on offensives. Otherwise you just leave it in your capitol with a bunch of strong defensive units, and you mostly cannot lose. And when the unit is powerful, but the AI does not realize it is key to losing the game, the AI will take silly risks with it.
 
I'm working on a regicide game option in my mod for FFH, mine's a little different from your idea however I'm sure it could be adapted.

I created a new game option for it "Regicide" this isn't actually meant to do anything, then I put this code into CvEventManager:

Code:
def onGameStart(self, argsList):
		'Called at the start of the game'

if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_REGICIDE):
    if pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_FALAMAR'):
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FALAMAR'), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

The only problem is I cant get the unit to spawn, does anyone know how to get a unit to spawn like this?
With the game option "Regicide" activated it should spawn the unit when the game starts but nothing happens :( I've been trying to figure it out for hours and hours :lol: (I've got about 20 variations of this code..) if anyone knows how to get this working I'd be very grateful :)
 
1. If that's really how you have things indented, the if() test isn't part of the onGameStart function.

2. You shouldn't mix tabs and spaces for indentation. It invites error and makes it hard to modify the file.

3. You haven't given pPlayer a value here, so you're probably getting a Python exception. Either turn off Hide Python Exceptions in CivilizationIV.ini or turn on Logging Enabled and look in PythonErr.log.

4. onGameStart is called once when the game starts, so you need to loop over all the players in the game. Perhaps you only showed a snippet of the code, for I don't see you checking for the other leader types, and I guess that each leader type has a specific unit type that goes with it. You can simplify this code a bit using a dictionary, an associative data structure in Python.

Code:
# This goes outside the event manager class near the top of the module

KING_UNITS_BY_LEADER = {
	"LEADER_FALAMAR": "UNIT_FALAMAR",
	"LEADER_BOB": "UNIT_BOB",
	"LEADER_FRANK": "UNIT_FRANK",
	...
}

Of course, if every unit type matches the leader type exactly like these ones do, this could be much simpler, but lets assume there's at least one that doesn't match such as "LEADER_BILL_THE_CAT" with "UNIT_FRODO".

Code:
def onGameStart(self, argsList):
	'Called at the start of the game'
	for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
		pPlayer = gc.getPlayer(ePlayer)
		szLeader = gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getType()
		if szLeader in KING_UNITS_BY_LEADER:
			szUnit = KING_UNITS_BY_LEADER[szLeader]
			eUnit = gc.getInfoTypeForString(szUnit)
			if eUnit != -1:
				pNewUnit = pPlayer.initUnit(eUnit, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
 
onCombatResult is part of the solution. The other, harder part is changing the AI so that (a) it protects its own king, and (b) it attacks yours. If the king unit is done well, it is so powerful that it is tempting to use it on offensives. Otherwise you just leave it in your capitol with a bunch of strong defensive units, and you mostly cannot lose. And when the unit is powerful, but the AI does not realize it is key to losing the game, the AI will take silly risks with it.

Yes, AI is a problem.

Possible solution:
After onUnitMove, put a check, how many units have moved (or are on the plot, however). If it seems, that it's a stack, check, who's the enemy, check, where his king is, and set the route of the stack to that point. This will suck performance, is not really intelligent, but it's just a first try.


For the use: What would happen, if you give the unit a high strength, but a low value for the iAsset?
 
Do you get Python exceptions? Did you turn on logging? Did you try adding a print statement to see if it gets to your code?
 
Ok so I got this from PythonErr.log

Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvEventManager", line 217, in handleEvent

File "CvEventManager", line 395, in onGameStart

AttributeError: 'CyGlobalContext' object has no attribute 'getLeaderType'
ERR: Python function onEvent failed, module CvEventInterface

What is a print statement? Thanks for the help :)
 
I fixed the error in the second code block. Change

Code:
... gc.getLeaderType ...

to

Code:
... gc.getLeaderType[B]Info[/B] ...

Though it may need to be getLeaderInfo instead.
 
I think that worked sort of but also got a new error :p

Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvEventManager", line 217, in handleEvent

File "CvEventManager", line 400, in onGameStart

ArgumentError: Python argument types in
CyPlayer.initUnit(CyPlayer, int, CvPythonExtensions.UnitAITypes, CvPythonExtensions.DirectionTypes)
did not match C++ signature:
initUnit(class CyPlayer {lvalue}, int, int, int, enum UnitAITypes, enum DirectionTypes)
ERR: Python function onEvent failed, module CvEventInterface

I am using
Code:
szLeader = gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getType()
for that part of the code, is it the getleadertype after getleaderheadinfo that is causing the problem? if I make them the same then it gets a no attribute error for CyPlayer.
 
No, now it's getting down to the initUnit() call. You need to put the x and y location in there I think.

Code:
pNewUnit = pPlayer.initUnit(eUnit, x, y, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

Of course you need to pick the x and y location somehow.
 
Ah I see, well I tried using

Code:
pPlot = gc.getStartingPlot(ePlayer)
		if eUnit != -1:
			pNewUnit = pPlayer.initUnit(eUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

Theres no attribute for it in CyGlobalContext though, is there a way to use getinfotypeforstring to find the starting plot?
 
You want

Code:
pPlot = gc.getPlayer(ePlayer).getStartingPlot()

Check out the online Python API.
 
Back
Top Bottom