Naval Mines

The values for the moves field are not the standard MPs you see on-screen (1 or 2) but rather 12 (IIRC) per MP. This is controlled by an XML value. First, remove the first red line you posted. The MP reduction should happen in the function that does the sweep. Second, change that line to

Code:
pUnit.setMoves(pUnit.getMoves() - [B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])

Edit: And yes, using changeMoves() is better than set(get() - x):

Code:
pUnit.changeMoves(-[B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])
 
The values for the moves field are not the standard MPs you see on-screen (1 or 2) but rather 12 (IIRC) per MP. This is controlled by an XML value. First, remove the first red line you posted. The MP reduction should happen in the function that does the sweep. Second, change that line to

Code:
pUnit.setMoves(pUnit.getMoves() - [B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])

Edit: And yes, using changeMoves() is better than set(get() - x):

Code:
pUnit.changeMoves(-[B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])

OK. I'll try it and let you know if it worked.
 
The values for the moves field are not the standard MPs you see on-screen (1 or 2) but rather 12 (IIRC) per MP. This is controlled by an XML value. First, remove the first red line you posted. The MP reduction should happen in the function that does the sweep. Second, change that line to

Code:
pUnit.setMoves(pUnit.getMoves() - [B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])

Edit: And yes, using changeMoves() is better than set(get() - x):

Code:
pUnit.changeMoves(-[B][COLOR="Red"]gc.getMOVE_DENOMINATOR()[/COLOR][/B])

OK. Both worked with one change: Replace the minus to a plus. Leaving the minus sign actually gave the minesweeper 2 more moves. :eek: I'll go with what works. The sweeper has 3 moves, so I used one movement to get to a plot that had 2 mines. I removed the mines and had no further movements left. :goodjob:

As always, thanks for your help.

Sincerely,

Orion Veteran :cool:
 
Ah yes, "moves" is how much the unit has moved this turn--not how much it has left.

So it seems. The first units are looking good, but the mod would work better if I could use python to force combat between 2 units. Are you sure there is no way to force combat?
 
There's no way to make two units fight? Wouldn't you just move one onto the tile of the other?
 
There's no way to make two units fight? Wouldn't you just move one onto the tile of the other?

Sorry. I forgot to tell you tht the mine is invisible to all units except the owner of the mine. It is also hidden nationality. A unit that moves into a plot, with an invisible mine, will not engage in combat with the mine. Hence, my request to try and force combat using python. If you notice my code, I use python to warn the mine sweeper ship that he has discovered a mine and the action button completely removes the mine, when executed. When an unsuspecting ship lands on the plot, with the mine, I would prefer to engage in combat instead of forcing a lethal kill every time.

Orion Veteran :cool:
 
I'm trying to get the Era for the specified pUnit2 and keep getting errors. My approach was to get the Prerequisite tech and then get the Era for the tech.

Code:
for iUnitLoop in range (pPlot.getNumUnits()):
	pUnit2 = pPlot.getUnit(iUnitLoop)
	[COLOR="Red"][B]preReqTech = gc.getTechInfo(pUnit2.getID).getTechPrereq()[/B][/COLOR]			
	iTech = preReqTech.getID
	Age = gc.getTechInfo(iTech).getEra()

Any idea how to fix this?

Orion Veteran :cool:
 
You need ()s after your function calls such as getID()--even when there are no parameters. Plus, a unit's ID does not have any functions you can call on it. You need to get the unit's type and then query its CvUnitInfo. Finally, once you have a UnitType or TechType, you don't need to look up the info to get its ID--that is the ID.

Code:
pUnit2 = pPlot.getUnit(iUnitLoop)
info = gc.getUnitInfo(pUnit2.getUnitType())
iTech = info.getPrereqAndTech()

Now the kicker: CvUnitInfo has getPrereqAndTech() which returns an int (is it a TechType? Probably) and getPrereqAndTechs(int i) that also returns an int (also a TechType). I don't recall offhand how these work. I suspect they combine to form all the required techs.

You can look in the Civilopedia's PediaUnit.py module for "getPrereqAndTech" to see how they are used.
 
They are used like this:

Code:
# add tech buttons
iPrereq = gc.getUnitInfo(self.iUnit).getPrereqAndTech()
if (iPrereq >= 0):
	screen.attachImageButton( panelName, "", gc.getTechInfo(iPrereq).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iPrereq, 1, False )
				
for j in range(gc.getDefineINT("NUM_UNIT_AND_TECH_PREREQS")):
	iPrereq = gc.getUnitInfo(self.iUnit).getPrereqAndTechs(j)
	if (iPrereq >= 0):

I get NoneType Object errors when attempting to plug either of them in.
 
Now the kicker: CvUnitInfo has getPrereqAndTech() which returns an int (is it a TechType? Probably) and getPrereqAndTechs(int i) that also returns an int (also a TechType). I don't recall offhand how these work. I suspect they combine to form all the required techs.

You can look in the Civilopedia's PediaUnit.py module for "getPrereqAndTech" to see how they are used.

These are a rather unique way of storing save data. I figured out what they were doing after I saw some code from FF.

Anyway, what is happening is that instead of saving an array of techs with each unit, which is inefficient and uses a LOT of memory, they decided to use say, 5 values instead (It's set in the global defines). This creates a much smaller array.

How it works is like this: Each of the values, 0 - 4 get assigned a value, either a -1 for NO_TECH or an actual tech value, like 44. So you loop over 0 - 4 and get each tech value out of it.

It's a bit odd to think about, but if you do analyze it for a few minutes, you'll understand what's going on.


Anyway, to the point. Your code should look something like this:

Code:
for j in range(gc.getDefineINT("NUM_UNIT_AND_TECH_PREREQS")):
	iPrereq = gc.getUnitInfo(self.iUnit).getPrereqAndTechs(j)
	if (iPrereq >= 0):
		Age = gc.getTechInfo(iPrereq).getEra()
 
Yes, the array makes perfect sense, but the extra single-value accessor is odd. I suppose they had the single value first and then needed multiple values and added the array instead of replacing the single value. C'est la vie.

In that code, self.iUnit accesses a value from the screen. You won't have that. Instead you have the pUnit2.getUnitType().

Code:
pUnit2 = pPlot.getUnit(iUnitLoop)
info = gc.getUnitInfo(pUnit2.getUnitType())
iMaxEra = -1
iTech = info.getPrereqAndTech()
if iTech != -1:
    iEra = gc.getTechInfo(iTech).getEra()
    if iEra > iMaxEra:
        iMaxEra = iEra
for i in range(gc.getNUM_AND_TECH_PREREQS()):
    iTech = info.getPrereqAndTechs(i)
    if iTech != -1:
        iEra = gc.getTechInfo(iTech).getEra()
        if iEra > iMaxEra:
            iMaxEra = iEra

iMaxEra is now the latest era of all required techs or -1 if there were no required techs. This assumes that eras are in natural order (they normally are).
 
Yes, the array makes perfect sense, but the extra single-value accessor is odd. I suppose they had the single value first and then needed multiple values and added the array instead of replacing the single value. C'est la vie.

No, it's intentional. The tech's are all OR prereq's, and the single value is an AND prereq.
 
Yes, the array makes perfect sense, but the extra single-value accessor is odd. I suppose they had the single value first and then needed multiple values and added the array instead of replacing the single value. C'est la vie.

The UnitInfo has a single valued PrereqTech field. It also has a separate multi-valued TechTypes field that takes multiple PrereqTech fields.

The difference is that the single valued field is used for which tech the unit appears on in the tech tree. The others are required, but it doesn't put the icon for the unit on those techs in the tree.
 
No, it's intentional. The tech's are all OR prereq's, and the single value is an AND prereq.

I hadn't realized they were ORs - I've never used more than one of them (which makes it AND with the other one).

I have also never tried using the TechTypes without also using the single valued PrereqTech. If you do that, where does the unit appear in the tech tree?
 
Back
Top Bottom