if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_HORSE_ARCHER'):
iUnit = gc.getInfoTypeForString('UNIT_CATAPULT')
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
iMission = MissionTypes.MISSION_MOVE_TO_UNIT
iMissionAIType = MissionAITypes.NO_MISSIONAI
pUnit.getGroup().pushMission(iMission, 18, iUnit, 0, False, True, iMissionAIType, pPlot, pUnit)
For a start, perhapsHow can I check if it works?
So you're adding code to AI_unitUpdate (CvGameInterface.py) I assume. That's what I'd try anyway. The function receives a unit object (let's say 'u') as parameter and can return 0 to let the DLL move the unit. I guess you should return 1 if you push a mission – to make sure that the DLL doesn't push a different mission. When the DLL moves a unit, then it may decide to break the group up, but usually it'll move the entire group. So, to make sure that you check every Horse Archer etc., it would be desirable to go through all units in the group of u; however, it seems that the interface for going through all units in a group isn't exposed to Python. Maybe you could go through all units in the plot instead (CyPlot::getUnit(int iIndex)). At any rate, you can at least catch units that happen to lead a group.
To move u into separate (single-unit) group, u.setXY(u.getX(), u.getY()) might work. That's not how setXY is supposed to be used – the DLL code states through an assertion that the target coordinates are supposed to differ from the unit's current coordinates – but perhaps it'll work anyway.
Though, before breaking up the group, you'd have to look for a nearby target,
for (deltaX in range(-...check that the target is alone and has the proper unit type, and check CySelectionGroup::generatePath to ensure that the target is reachable on the current turn.
But, before writing code for that, I'd do some simple experiment with pushMoveToMission to verify that you can indeed move units this way.
for iPlayer in range(gc.getMAX_PLAYERS()):
for pUnit in PyPlayer(iPlayer).getUnitList():
for tUnit in PyPlayer(18).getUnitList():
iUnit = gc.getInfoTypeForString('UNIT_HORSE_ARCHER')
if pUnit.getUnitType() == iUnit:
if tUnit.getUnitType() == gc.getInfoTypeForString('UNIT_INFANTRY'):
iX = tUnit.getX()
iY = tUnit.getY()
tPlot = CyMap().plot(iX, iY)
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
if tPlot.getOwner() == pUnit.getOwner():
if pUnit.getGroup().generatePath(pPlot, tPlot, 0, False, None):
iMission = MissionTypes.MISSION_MOVE_TO
iMissionAIType = MissionAITypes.NO_MISSIONAI
CyMap().resetPathDistance()
iDist = CyMap().calculatePathDistance(pPlot, tPlot) * 60
iMoves = pUnit.movesLeft()
pUnit.setXY(pUnit.getX(), pUnit.getY())
if iDist > iMoves:
pUnit.getGroup().pushMission(iMission, iX, iY, 0, False, True, iMissionAIType, pPlot, pUnit)
pUnit.finishMoves()
else:
pUnit.setXY(iX, iY)
pUnit.finishMoves()
int iFlags = 0, bool bAppend = false, bool bManual = false, MissionAITypes eMissionAI = NO_MISSIONAI,
CvPlot* pMissionAIPlot = NULL, CvUnit* pMissionAIUnit = NULL
for pUnit in PyPlayer(iPlayer).getUnitList():
for tUnit in PyPlayer(18).getUnitList():
def AI_unitUpdate(self,argsList):
pUnit = argsList[0]
for iPlayer in range(gc.getMAX_PLAYERS()):
for pUnit in PyPlayer(iPlayer).getUnitList():
if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_CHRISTIAN_MISSIONARY'):
for tUnit in PyPlayer(18).getUnitList():
if tUnit.getUnitType() == gc.getInfoTypeForString('UNIT_ERETICO'):
iX = tUnit.getX()
iY = tUnit.getY()
tPlot = CyMap().plot(iX, iY)
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
if tPlot.getOwner() == pUnit.getOwner():
if pUnit.generatePath(tPlot, 0, False, None):
pUnit.getGroup().pushMoveToMission(iX, iY)
return True
elif pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MONATTO'):
for tUnit in PyPlayer(18).getUnitList():
if tUnit.getUnitType() == gc.getInfoTypeForString('UNIT_UNTORE'):
iX = tUnit.getX()
iY = tUnit.getY()
tPlot = CyMap().plot(iX, iY)
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
if tPlot.getOwner() == pUnit.getOwner():
if pUnit.generatePath(tPlot, 0, False, None):
pUnit.getGroup().pushMoveToMission(iX, iY)
return True
return False
def AI_unitUpdate(self,argsList):
pUnit = argsList[0]
if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_CHRISTIAN_MISSIONARY'):
for iPlayer in range(gc.getMAX_PLAYERS()):
if gc.getPlayer(iPlayer).isHuman() == False:
for tUnit in PyPlayer(18).getUnitList():
if tUnit.getUnitType() == gc.getInfoTypeForString('UNIT_ERETICO'):
iX = tUnit.getX()
iY = tUnit.getY()
tPlot = CyMap().plot(iX, iY)
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
if tPlot.getOwner() == pUnit.getOwner():
if pUnit.generatePath(tPlot, 0, False, None):
pUnit.getGroup().pushMoveToMission(iX, iY)
return True
elif pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MONATTO'):
for iPlayer in range(gc.getMAX_PLAYERS()):
if gc.getPlayer(iPlayer).isHuman() == False:
for tUnit in PyPlayer(18).getUnitList():
if tUnit.getUnitType() == gc.getInfoTypeForString('UNIT_UNTORE'):
iX = tUnit.getX()
iY = tUnit.getY()
tPlot = CyMap().plot(iX, iY)
pPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
if tPlot.getOwner() == pUnit.getOwner():
if pUnit.generatePath(tPlot, 0, False, None):
pUnit.getGroup().pushMoveToMission(iX, iY)
return True
return False