Units requiring resources, but the civ doesn't have that resource, get a combat penalty

This commit is contained in:
Yair Morgenstern 2018-11-12 11:44:21 +02:00
parent 5ef5ff572e
commit f127c9ac37
7 changed files with 27 additions and 11 deletions

View file

@ -47,6 +47,11 @@ class BattleDamage{
&& combatant.getTile().neighbors.flatMap { it.getUnits() }
.any { it.civInfo==combatant.getCivilization() && !it.baseUnit.unitType.isCivilian()})
modifiers["Discipline"] = 0.15f
val requiredResource = combatant.unit.baseUnit.requiredResource
if(requiredResource!=null && !combatant.getCivilization().hasResource(requiredResource)){
modifiers["Missing resource"]=-0.25f
}
}
if (combatant.getCivilization().policies.isAdopted("Honor") && enemy.getCivilization().isBarbarianCivilization())

View file

@ -70,7 +70,7 @@ class CityStats {
if (construction is Building
&& construction.isWonder
&& cityInfo.civInfo.getCivResources().containsKey(GameBasics.TileResources["Marble"]))
&& cityInfo.civInfo.hasResource("Marble"))
stats.production += 15f
return stats

View file

@ -174,10 +174,11 @@ class CivilizationInfo {
return statMap
}
/**
* Returns a counter of non-zero resources that the civ has
*/
fun getCivResources(): Counter<TileResource> {
val civResources = Counter<TileResource>()
// ToLists are so that when we update happiness on a different thread and we call this function,
// we don't modify the iterator as we're using it
for (city in cities) civResources.add(city.getCityResources())
for (dip in diplomacy.values) civResources.add(dip.resourcesFromTrade())
for(resource in getCivUnits().map { it.baseUnit.requiredResource }.filterNotNull().map { GameBasics.TileResources[it] })
@ -185,6 +186,18 @@ class CivilizationInfo {
return civResources
}
/**
* Returns a dictionary of ALL resource names, and the amount that the civ has of each
*/
fun getCivResourcesByName():HashMap<String,Int>{
val hashMap = HashMap<String,Int>()
for(resource in GameBasics.TileResources.keys) hashMap[resource]=0
for(entry in getCivResources()) hashMap[entry.key.name] = entry.value
return hashMap
}
fun hasResource(resourceName:String): Boolean = getCivResourcesByName()[resourceName]!!>0
fun getBuildingUniques(): List<String> = cities.flatMap { it.getBuildingUniques()}.distinct()
fun getCivUnits(): List<MapUnit> {

View file

@ -67,7 +67,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
else{
val civsWhoWillTradeUsForTheLux = ourCivilization.diplomacy.values.map { it.civInfo }
.filter { it!= otherCivilization }
.filter { it.getCivResources().keys.none { it.name==offer.name } } //they don't have
.filter { !it.hasResource(offer.name) } //they don't have
val ourResourceNames = ourCivilization.getCivResources().map { it.key.name }
val civsWithLuxToTrade = civsWhoWillTradeUsForTheLux.filter {
it.getCivResources().any {
@ -85,10 +85,8 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
TradeType.Technology -> return sqrt(GameBasics.Technologies[offer.name]!!.cost.toDouble()).toInt()*10
TradeType.Strategic_Resource -> {
if(otherCivIsRecieving) {
val resources = ourCivilization.getCivResources()
val stringmap = HashMap<String, Int>()
for (entry in resources) stringmap.put(entry.key.name, entry.value)
if (stringmap.containsKey(offer.name) && stringmap[offer.name]!! >= 2) return 0 // we already have enough.
val resources = ourCivilization.getCivResourcesByName()
if (resources[offer.name]!! >= 2) return 0 // we already have enough.
val canUseForBuildings = ourCivilization.cities
.any { city-> city.cityConstructions.getBuildableBuildings().any { it.requiredResource==offer.name } }
val canUseForUnits = ourCivilization.cities

View file

@ -183,7 +183,7 @@ class Building : NamedStats(), IConstruction{
if("Can only be built in coastal cities" in uniques
&& construction.cityInfo.getCenterTile().neighbors.none { it.baseTerrain=="Coast" })
return false
if (requiredResource != null && !civInfo.getCivResources().containsKey(GameBasics.TileResources[requiredResource!!]))
if (requiredResource != null && civInfo.hasResource(requiredResource!!))
return false

View file

@ -94,7 +94,7 @@ class BaseUnit : INamed, IConstruction, ICivilopedia {
if (obsoleteTech!=null && civInfo.tech.isResearched(obsoleteTech!!)) return false
if (uniqueTo!=null && uniqueTo!=civInfo.civName) return false
if (GameBasics.Units.values.any { it.uniqueTo==civInfo.civName && it.replaces==name }) return false
if (requiredResource!=null && !civInfo.getCivResources().keys.any { it.name == requiredResource }) return false
if (requiredResource!=null && !civInfo.hasResource(requiredResource!!)) return false
return true
}

View file

@ -105,7 +105,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
internal fun update(civInfo: CivilizationInfo) {
val revealedStrategicResources = GameBasics.TileResources.values
.filter { it.resourceType == ResourceType.Strategic } // && }
.filter { it.resourceType == ResourceType.Strategic }
val civResources = civInfo.getCivResources()
for (resource in revealedStrategicResources) {
val isRevealed = civInfo.tech.isResearched(resource.revealedBy!!)