Fixed Hanse special ability

This commit is contained in:
Yair Morgenstern 2019-06-21 14:01:33 +03:00
parent 418bc140e8
commit ee1aa61221
3 changed files with 16 additions and 5 deletions

View File

@ -213,8 +213,14 @@ class GameInfo {
} }
for (civInfo in civilizations){ for (civInfo in civilizations){
// Since this depends on the cities of ALL civilizations,
// we need to wait until we've set the transients of all the cities before we can run this.
// Hence why it's not in CivInfo.setTransients().
civInfo.setCitiesConnectedToCapitalTransients()
// We need to determine the GLOBAL happiness state in order to determine the city stats // We need to determine the GLOBAL happiness state in order to determine the city stats
for(cityInfo in civInfo.cities) cityInfo.cityStats.updateCityHappiness() for(cityInfo in civInfo.cities) cityInfo.cityStats.updateCityHappiness()
for (cityInfo in civInfo.cities) cityInfo.cityStats.update() for (cityInfo in civInfo.cities) cityInfo.cityStats.update()
} }
} }

View File

@ -39,6 +39,7 @@ class CivilizationInfo {
@Transient private var units=listOf<MapUnit>() @Transient private var units=listOf<MapUnit>()
@Transient var viewableTiles = setOf<TileInfo>() @Transient var viewableTiles = setOf<TileInfo>()
@Transient var viewableInvisibleUnitsTiles = setOf<TileInfo>() @Transient var viewableInvisibleUnitsTiles = setOf<TileInfo>()
/** Contains cities from ALL civilizations connected by trade routes to the capital */ /** Contains cities from ALL civilizations connected by trade routes to the capital */
@Transient var citiesConnectedToCapital = listOf<CityInfo>() @Transient var citiesConnectedToCapital = listOf<CityInfo>()
@ -437,7 +438,6 @@ class CivilizationInfo {
cityInfo.civInfo = this // must be before the city's setTransients because it depends on the tilemap, that comes from the currentPlayerCivInfo cityInfo.civInfo = this // must be before the city's setTransients because it depends on the tilemap, that comes from the currentPlayerCivInfo
cityInfo.setTransients() cityInfo.setTransients()
} }
setCitiesConnectedToCapitalTransients()
updateViewableTiles() updateViewableTiles()
updateHasActiveGreatWall() updateHasActiveGreatWall()
updateDetailedCivResources() updateDetailedCivResources()
@ -550,8 +550,9 @@ class CivilizationInfo {
val citiesReachedToMediums = HashMap<CityInfo,ArrayList<String>>() val citiesReachedToMediums = HashMap<CityInfo,ArrayList<String>>()
var citiesToCheck = mutableListOf(getCapital()) var citiesToCheck = mutableListOf(getCapital())
citiesReachedToMediums[getCapital()] = arrayListOf("Start") citiesReachedToMediums[getCapital()] = arrayListOf("Start")
val allCivCities = gameInfo.civilizations.flatMap { it.cities }
while(citiesToCheck.isNotEmpty() && citiesReachedToMediums.size<cities.size){ while(citiesToCheck.isNotEmpty() && citiesReachedToMediums.size<allCivCities.size){
val newCitiesToCheck = mutableListOf<CityInfo>() val newCitiesToCheck = mutableListOf<CityInfo>()
for(cityToConnectFrom in citiesToCheck){ for(cityToConnectFrom in citiesToCheck){
val reachedMediums = citiesReachedToMediums[cityToConnectFrom]!! val reachedMediums = citiesReachedToMediums[cityToConnectFrom]!!
@ -561,7 +562,7 @@ class CivilizationInfo {
val roadBfs = BFS(cityToConnectFrom.getCenterTile()){it.roadStatus!=RoadStatus.None} val roadBfs = BFS(cityToConnectFrom.getCenterTile()){it.roadStatus!=RoadStatus.None}
roadBfs.stepToEnd() roadBfs.stepToEnd()
val reachedCities = cities.filter { roadBfs.tilesReached.containsKey(it.getCenterTile())} val reachedCities = allCivCities.filter { roadBfs.tilesReached.containsKey(it.getCenterTile())}
for(reachedCity in reachedCities){ for(reachedCity in reachedCities){
if(!citiesReachedToMediums.containsKey(reachedCity)){ if(!citiesReachedToMediums.containsKey(reachedCity)){
newCitiesToCheck.add(reachedCity) newCitiesToCheck.add(reachedCity)
@ -578,7 +579,7 @@ class CivilizationInfo {
&& cityToConnectFrom.cityConstructions.containsBuildingOrEquivalent("Harbor")){ && cityToConnectFrom.cityConstructions.containsBuildingOrEquivalent("Harbor")){
val seaBfs = BFS(cityToConnectFrom.getCenterTile()){it.isWater || it.isCityCenter()} val seaBfs = BFS(cityToConnectFrom.getCenterTile()){it.isWater || it.isCityCenter()}
seaBfs.stepToEnd() seaBfs.stepToEnd()
val reachedCities = cities.filter { seaBfs.tilesReached.containsKey(it.getCenterTile())} val reachedCities = allCivCities.filter { seaBfs.tilesReached.containsKey(it.getCenterTile())}
for(reachedCity in reachedCities){ for(reachedCity in reachedCities){
if(!citiesReachedToMediums.containsKey(reachedCity)){ if(!citiesReachedToMediums.containsKey(reachedCity)){
newCitiesToCheck.add(reachedCity) newCitiesToCheck.add(reachedCity)

View File

@ -75,7 +75,7 @@ class TileMap {
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit? { fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit? {
val unit = GameBasics.Units[unitName]!!.getMapUnit() val unit = GameBasics.Units[unitName]!!.getMapUnit()
val tilesInDistance = getTilesInDistance(position, 2) val tilesInDistance = getTilesInDistance(position, 2)
unit.assignOwner(civInfo) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn unit.assignOwner(civInfo,false) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn
var unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand) } var unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand) }
if (unitToPlaceTile==null) if (unitToPlaceTile==null)
unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) } unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) }
@ -88,6 +88,10 @@ class TileMap {
// Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles // Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles
for(promotion in unit.baseUnit.promotions) for(promotion in unit.baseUnit.promotions)
unit.promotions.addPromotion(promotion,true) unit.promotions.addPromotion(promotion,true)
// And update civ stats, since the new unit changes both unit upkeep and resource consumption
civInfo.updateStatsForNextTurn()
civInfo.updateDetailedCivResources()
} }
else { else {
civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner