Automated workers will build camps on forest tiles where they can

This commit is contained in:
Yair Morgenstern 2018-07-10 12:29:29 +03:00
parent f9ec46a376
commit 3425c117ff
4 changed files with 15 additions and 13 deletions

View file

@ -113,12 +113,13 @@ class WorkerAutomation(val unit: MapUnit) {
private fun chooseImprovement(tile: TileInfo): TileImprovement {
val improvementString = when {
tile.improvementInProgress != null -> tile.improvementInProgress
tile.terrainFeature == "Forest" -> "Lumber mill"
tile.terrainFeature == "Jungle" -> "Trading post"
tile.terrainFeature == "Marsh" -> "Remove Marsh"
tile.resource != null -> tile.tileResource.improvement
tile.terrainFeature == "Forest" &&
(tile.resource == null || tile.getTileResource().improvement!="Camp") -> "Lumber mill"
tile.resource != null -> tile.getTileResource().improvement
tile.baseTerrain == "Hill" -> "Mine"
tile.baseTerrain == "Grassland" || tile.baseTerrain == "Desert" || tile.baseTerrain == "Plains" -> "Farm"
tile.baseTerrain in listOf("Grassland","Desert","Plains") -> "Farm"
tile.baseTerrain == "Tundra" -> "Trading post"
else -> null
}

View file

@ -42,7 +42,7 @@ class CityInfo {
val cityResources = Counter<TileResource>()
for (tileInfo in getTiles().filter { it.resource != null }) {
val resource = tileInfo.tileResource
val resource = tileInfo.getTileResource()
if(resource.revealedBy!=null && !civInfo.tech.isResearched(resource.revealedBy!!)) continue
if (resource.improvement == tileInfo.improvement || tileInfo.isCityCenter()){
if(resource.resourceType == ResourceType.Strategic) cityResources.add(resource, 2)

View file

@ -37,8 +37,9 @@ open class TileInfo {
val lastTerrain: Terrain
get() = if (terrainFeature == null) getBaseTerrain() else getTerrainFeature()!!
val tileResource: TileResource
get() = if (resource == null) throw Exception("No resource exists for this tile!") else GameBasics.TileResources[resource!!]!!
fun getTileResource(): TileResource =
if (resource == null) throw Exception("No resource exists for this tile!")
else GameBasics.TileResources[resource!!]!!
fun isCityCenter(): Boolean = getCity()?.location == position
@ -95,8 +96,8 @@ open class TileInfo {
}
if (hasViewableResource(observingCiv)) {
val resource = tileResource
stats.add(tileResource) // resource base
val resource = getTileResource()
stats.add(getTileResource()) // resource base
if (resource.building != null && city != null && city.cityConstructions.isBuilt(resource.building!!)) {
stats.add(resource.getBuilding()!!.resourceBonusStats!!) // resource-specific building (eg forge, stable) bonus
}
@ -104,8 +105,8 @@ open class TileInfo {
val improvement = tileImprovement
if (improvement != null) {
if (resource != null && tileResource.improvement == improvement.name)
stats.add(tileResource.improvementStats!!) // resource-specifc improvement
if (resource != null && getTileResource().improvement == improvement.name)
stats.add(getTileResource().improvementStats!!) // resource-specifc improvement
else
stats.add(improvement) // basic improvement
@ -140,7 +141,7 @@ open class TileInfo {
if (improvement.name == "Road" && this.roadStatus === RoadStatus.None) return true
if (improvement.name == "Railroad" && this.roadStatus !== RoadStatus.Railroad) return true
if (topTerrain.unbuildable && !(topTerrain.name=="Forest" && improvement.name=="Camp")) return false
return hasViewableResource(civInfo) && tileResource.improvement == improvement.name
return hasViewableResource(civInfo) && getTileResource().improvement == improvement.name
}
@ -178,7 +179,7 @@ open class TileInfo {
}
fun hasViewableResource(civInfo: CivilizationInfo): Boolean {
return resource != null && (tileResource.revealedBy == null || civInfo.tech.isResearched(tileResource.revealedBy!!))
return resource != null && (getTileResource().revealedBy == null || civInfo.tech.isResearched(getTileResource().revealedBy!!))
}
fun hasIdleUnit(): Boolean {

View file

@ -179,7 +179,7 @@ class Building : NamedStats(), IConstruction{
.any {
it.resource != null
&& requiredNearbyImprovedResources!!.contains(it.resource!!)
&& it.tileResource.improvement == it.improvement
&& it.getTileResource().improvement == it.improvement
&& it.getOwner() == civInfo
}
if (!containsResourceWithImprovement) return false