View Full Version : Question about units


Shiggs713
Jul 16, 2007, 08:37 PM
Is it possible to limit a units movement to only railroads for example? I'm trying to create a unit (train) than can transport troops but must stay on rails, for civil war mod. thanks in advance :)

Davinci Fan
Jul 16, 2007, 09:42 PM
I know this can be done with 6 or seven lines of code in the SDK, but I'm not sure off the top of my head of the best way. My guess is something revolving around getinfostringfor Train units and the canMoveInto function.

Sorry i can't be more helpful.

Zebra 9
Jul 17, 2007, 10:13 AM
I'll see what I can do.

Shiggs713
Jul 17, 2007, 10:29 AM
thank you :)

Zebra 9
Jul 17, 2007, 10:56 AM
Ok, I checked it out and this will do it: def cannotSelectionListMove(self,argsList):
pPlot = argsList[0]
bAlt = argsList[1]
bShift = argsList[2]
bCtrl = argsList[3] if pPlot.getRouteType() != gc.getInfoTypeForString("ROUTE_RAILROAD"):
if CyInterface().getHeadSelectedUnit():
if CyInterface().getHeadSelectedUnit().getUnitClassTy pe() == gc.getInfoTypeForString("UNITCLASS_WARRIOR"):
return True

return FalseBut there is a problem, it only prevents the human player from moving!!! :mad:

So I found the sdk code and well if you change the beginning of canMoveInto function in CvUnit.cpp to look like this:bool CvUnit::canMoveInto(const CvPlot* pPlot, bool bAttack, bool bDeclareWar, bool bIgnoreLoad) const
{
TeamTypes ePlotTeam;

FAssertMsg(pPlot != NULL, "Plot is not assigned a valid value");

// Changed
CyUnit* pyUnit = new CyUnit(this);
CyArgsList argsList;
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit)); // pass in unit class

CyPlot* pyPlot = new CyPlot(pPlot);
CyArgsList argsList;
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyPlot)); // pass in plot class

long lResult=0;
gDLL->getPythonIFace()->callFunction(PYGameModule, "cannotMoveInto", argsList.makeFunctionArgs(), &lResult);
delete pyUnit; // python fxn must not hold on to this pointer
delete pyPlot; // python fxn must not hold on to this pointer
if (lResult == 1)
{
return false;
}
// Changed ... and you add this python to CvGameUtils.py def cannotMoveInto(self, argsList):
pUnit, pPlot = argsList
if pPlot.getRouteType() != gc.getInfoTypeForString("ROUTE_RAILROAD"):
if pUnit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_WARRIOR"):
return True

return False

PS I think BtS will allow us to do this.

Shiggs713
Jul 17, 2007, 02:03 PM
ah this is great. thanks.. I'm trying to get a solid working model done before bts comes out, so I can at least release the WIP to warlords people who are not upgrading, cause most of my efforts are soon going only bts.

EDIT:
Ah crap, this means I will need to re-compile? I haven't figured out how to do that quite yet. :(

Ambreville
Jul 17, 2007, 08:57 PM
Using the same idea, is it possible to do a riverboat that can only sail up and down rivers?

Zebra 9
Jul 18, 2007, 12:48 PM
Sorta. The problem is that rivers are on the side of plots, where as the railroad is on the plot. Because of this it would be possible to move a riverboat from one plot to the othere back and forth across the river.