View Full Version : [PYTHON] Scout to summon my armies


Zindar
Mar 30, 2007, 03:48 PM
While playing civ I had two minor problems:

what should I use my scouts to, after reveling the whole map
while building my large armies, there was a lot of mouse action to move them into place


So, reading talchas Action Button MOD I found a simple solution. If you have a scout unit then all other units will display a "Goto the flag" button. When pressed the unit will automaticly move to the scout unit plot.

The interesting bit of code is in CvActionButtonsGameUtils.py It will show how to add a GOTO mission to a player unit (SelectionGroup).

def moveUnitToFlagScout(unit):
iScoutType = gc.getInfoTypeForString("UNIT_SCOUT")

# find first scout unit
(loopUnit, iter) = gc.getActivePlayer().firstUnit(false)
while (loopUnit):
if (loopUnit.getUnitType() == iScoutType) and unit.canMoveThrough(loopUnit.plot()):
break
(loopUnit, iter) = gc.getActivePlayer().nextUnit(iter, false)

# move whole selectiongroup to scout if found
if ((not type(loopUnit) is NoneType) and (not loopUnit.isNone())):
unit.getGroup().pushMission(MissionTypes.MISSION_M OVE_TO, loopUnit.getX(), loopUnit.getY(), 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)


goFlag = ActionButtons.ActionButton("Art/Interface/Buttons/gotoflag.dds", moveUnitToFlagScout)

def buttons(unit):
iScoutType = gc.getInfoTypeForString("UNIT_SCOUT")

# no sence with goFlag for boats and confusing with scouts
if (unit.getUnitType() == iScoutType) or (unit.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")):
return []

# enable (return) goFlag button only if any scout unit found among player units
(loopUnit, iter) = gc.getActivePlayer().firstUnit(false)
while (loopUnit):
if (loopUnit.getUnitType() == iScoutType) and unit.canMoveThrough(loopUnit.plot()):
return [goFlag]
(loopUnit, iter) = gc.getActivePlayer().nextUnit(iter, false)
return []


The rest is no different from the Action Button MOD. The zip-file includes button graphics (although I'm no Picasso ;) ) and complete MOD working for the v1.61 patch. Unzip in your my document's\my games\sid... folder as usual.

I choosed Python instead of C++/SDK, but those modding at that level shouldn't have any problems with porting. As always when coding more ideas came along...

I'we stopped naval units but what about airplanes?
How should multiple scouts be handled?
What if my scout dies in late 1970's, should the action belong to UNITCOMBAT_RECON instead?
Maybe this should be done with some "Army Flag" promotion?


Here's some sample code (not complete) for the promotion version, but personally I think I'll stick with the scout version.


def moveUnitToFlagPromotion(unit):
(loopUnit, iter) = gc.getActivePlayer().firstUnit(false)
iFlagPromotion = gc.getInfoTypeForString('PROMOTION_WOODSMAN1')
while (loopUnit):
if (loopUnit.isHasPromotion(iFlagPromotion) and unit.canMoveThrough(loopUnit.plot())):
break
(loopUnit, iter) = gc.getActivePlayer().nextUnit(iter, false)


Cheat & balancing issues: none, the AI doesn't have a mouse and the purpose is to enhance the game interface nothing more.

ClassicThunder
Mar 30, 2007, 03:57 PM
Welcome to civfanatics, and nice first post.

Anyways how exactly is this better than ctr-clicking a plot of units then right clicking?

Zindar
Mar 31, 2007, 12:52 PM
Well, right clicking my SoD is fine when it has been formed and we are at battle grounds. But I normally end up building units in a large number of cities while waging a war far far away so there used to be a lot of scrolling and panning over the map. Now I fortify my scout in a safe place near battle grounds and just press the GotoFlag button for every newly built unit. When a sufficiently large number of units has arrived they form a new SoD.

Dancing Hoskuld
Mar 31, 2007, 04:26 PM
Excellent, a selective rally point. No more will those units I am building to defend a city head off to the front lines!

Dancing Hoskuld
Mar 31, 2007, 05:00 PM
Rats! I just tried this and it has some unexpected side effects. The income per turn displayed value is wrong hundreds of thousands wrong.

It does not effect the actual money you get but it does cause the percentages towards tech and culture to go to zero if the displayed value is negative.

Zindar
Apr 02, 2007, 02:47 PM
Glad you liked the idea. Sorry for the side effects but I can't repeat your problems on my computer:sad: , so here's some remote debugging...

a) Are you using the v1.61 patch, no Warlords. Good
[otherwize you have to create a new mod version from copies of CvMainInterface.py etc. ]

a2) Have you cleared the game cash? Any mods including CvMainInterface needs this first time. One way is to ALT-TAB twice between Civ and some other program.

b) Running any other mods at the same time? Try using only one at the time.

c) The calculation of gold per turn is done inside the DLL, you haven't compiled your own?

d) The calculation is based on values in CIV4CivicInfos.xml and the is a possibility to add python code in CvGameUtils.py / CvGameInterface.py, look for def doGold.

e) The CvGameUtils class reference in CvGameInterface is changed to CvActionButtonGameUtils (which should inherit CvGameUtils). If you merged the mod, my first guess would be a missing line in this area.


I hope any or all of the above will help you. It's a new experience with this type of remote debugging without real time response and knowing your experience level, novice or expert programmer.

Dancing Hoskuld
Apr 03, 2007, 03:12 AM
Oops, I am using Warlords!

woodelf
Apr 03, 2007, 05:26 AM
Interesting and a needed modcomp. Nice.