Added movement cost for crossing rivers

This commit is contained in:
Yair Morgenstern 2020-05-30 23:32:53 +03:00
parent 58059fc59b
commit 84e4e58f23
5 changed files with 61 additions and 53 deletions

View File

@ -155,6 +155,7 @@
"name": "Engineering",
"row": 8,
"prerequisites": ["Mathematics","Construction"],
"uniques": ["Roads connect tiles across rivers"],
"quote": "'Instrumental or mechanical science is the noblest and, above all others, the most useful.' - Leonardo da Vinci"
},
{

View File

@ -53,7 +53,7 @@ class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
cityToConnectFrom,
transportType = road,
overridingTransportType = railroad,
tileFilter = { tile -> tile.hasRoad(civInfo) || tile.hasRailroad() || tile.isCityCenter() }
tileFilter = { tile -> tile.hasConnection(civInfo) || tile.isCityCenter() }
)
}

View File

@ -28,12 +28,15 @@ class TechManager {
// UnitMovementAlgorithms.getMovementCostBetweenAdjacentTiles is a close second =)
@Transient var movementSpeedOnRoadsImproved = false
@Transient var roadsConnectAcrossRivers = false
var freeTechs = 0
/** For calculating Great Scientist yields - see https://civilization.fandom.com/wiki/Great_Scientist_(Civ5) */
var scienceOfLast8Turns = IntArray(8) { 0 }
var scienceFromResearchAgreements = 0
var techsResearched = HashSet<String>()
/** When moving towards a certain tech, the user doesn't have to manually pick every one. */
var techsToResearch = ArrayList<String>()
private var techsInProgress = HashMap<String, Int>()
@ -314,6 +317,7 @@ class TechManager {
embarkedUnitsCanEnterOcean = true
if (researchedTechUniques.contains("Improves movement speed on roads")) movementSpeedOnRoadsImproved = true
if (researchedTechUniques.contains("Roads connect tiles across rivers")) roadsConnectAcrossRivers = true
}
fun getBestRoadAvailable(): RoadStatus {

View File

@ -451,9 +451,6 @@ open class TileInfo {
fun hasConnection(civInfo: CivilizationInfo) =
roadStatus != RoadStatus.None || forestOrJungleAreRoads(civInfo)
fun hasRoad(civInfo: CivilizationInfo) =
roadStatus == RoadStatus.Road || forestOrJungleAreRoads(civInfo)
fun hasRailroad() =
roadStatus == RoadStatus.Railroad

View File

@ -23,7 +23,13 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
if (from.roadStatus == RoadStatus.Railroad && to.roadStatus == RoadStatus.Railroad)
return 1 / 10f + extraCost
if (from.hasConnection(civInfo) && to.hasConnection(civInfo))
val areConnectedByRoad = from.hasConnection(civInfo) && to.hasConnection(civInfo)
if(from.isConnectedByRiver(to) &&
(!areConnectedByRoad || !civInfo.tech.roadsConnectAcrossRivers)){
return 100f // Rivers take the entire turn to cross
}
if (areConnectedByRoad)
{
return if (unit.civInfo.tech.movementSpeedOnRoadsImproved) 1 / 3f + extraCost
else 1 / 2f + extraCost