Gaius Octavius
Deity
- Joined
- Jul 28, 2006
- Messages
- 4,016
When I was messing around with my WWII Pacific scenario, a thought occurred to me about naval units and how they travel. In the real world, when the Japanese attacked Pearl Harbor on December 7, 1941, they were not able to stay around for very long (or to advance beyond Pearl Harbor) due to supply constraints and fuel consumption.
In Civ 4, this is not really represented. A battleship may travel around the world without regard to its supply capacity and does not need ports. While this makes sense in the standard game for balance reasons, scenarios are much more flexible there. I therefore started toying with the idea of creating maximum naval ranges, like air unit ranges.
Right now, I'm thinking along the lines of one max range for all naval types (though that could be changed later on), and a unit would not be able to move beyond its effective range. Range is defined as the distance between one of that civ's (or one of its vassals') coastal cities and the unit itself.
Looking through some of the code I've used already, I can foresee three needed mechanisms in Python: 1, a test to see where the nearest coastal city is, 2, a comparison of how far away the unit is from it, and 3, the actual "cannotmove" command itself.
Off the top of my head, I think it would look something like this:
This is from Desert War, so there are a lot of scenario-specific examples in it. The coastal finder is also not perfect, since it only locates a city and not the nearest city. Yet I think you can understand where I'm going here, and I was curious if anyone had already done anything in this area or has any suggestions for me.
Potential problems: what happens if your unit is far away, and your nearest city gets captured, thus putting your ships beyond their maximum range?
In Civ 4, this is not really represented. A battleship may travel around the world without regard to its supply capacity and does not need ports. While this makes sense in the standard game for balance reasons, scenarios are much more flexible there. I therefore started toying with the idea of creating maximum naval ranges, like air unit ranges.
Right now, I'm thinking along the lines of one max range for all naval types (though that could be changed later on), and a unit would not be able to move beyond its effective range. Range is defined as the distance between one of that civ's (or one of its vassals') coastal cities and the unit itself.
Looking through some of the code I've used already, I can foresee three needed mechanisms in Python: 1, a test to see where the nearest coastal city is, 2, a comparison of how far away the unit is from it, and 3, the actual "cannotmove" command itself.
Off the top of my head, I think it would look something like this:
Spoiler :
Code:
tMarrakech = (1, 6) # example of a city plot
tCityList = [ tMarrakech,
tRabat,
tTangiers,
tBechar,
tGibraltar,
tOran,
tAlgiers,
tTunis,
tGabes ]
bForceCoastal = True
MaxNavalRange = [some # of plots, say 20]
city = self.findCity(tCityList, [], iPlayerTeam, bForceCoastal)
cityPlot = city.plot()
distance = self.plotDistance(cityPlot, unit.plot())
if distance > MaxNavalRange:
[Cannot move into plot]
# Functions called
def findCity( self, tRegionList, tExceptionList, iTeam, bForceCoastal ):
"""If possible, returns a (coastal) city from tRegionList that belongs to team iTeam
and is not in tExceptionList."""
if iTeam == iAxis:
for tCoords in tRegionList:
city = getCity(tCoords)
if self.isCityAxis(city):
if not tCoords in tExceptionList:
if bForceCoastal:
if city.isCoastal():
return city
else:
return city
def plotDistance( self, tFirst, tSecond ):
"""Returns the number distance between tFirst and tSecond in the number of plots."""
xDistance = tFirst[iX] - tSecond[iX]
yDistance = tFirst[iY] - tSecond[iY]
if xDistance < 0:
xDistance = -xDistance
if yDistance < 0:
yDistance = -yDistance
if xDistance >= yDistance:
return xDistance
else:
return yDistance
def unitCannotMoveInto(self,argsList):
ePlayer = argsList[0]
iUnitId = argsList[1]
iPlotX = argsList[2]
iPlotY = argsList[3]
return False
This is from Desert War, so there are a lot of scenario-specific examples in it. The coastal finder is also not perfect, since it only locates a city and not the nearest city. Yet I think you can understand where I'm going here, and I was curious if anyone had already done anything in this area or has any suggestions for me.
Potential problems: what happens if your unit is far away, and your nearest city gets captured, thus putting your ships beyond their maximum range?