Dev: Techs are now recognized by their unique abilities, not by tech name

This commit is contained in:
Yair Morgenstern 2018-11-17 20:33:21 +02:00
parent ab255e5138
commit 69e30ce212
8 changed files with 28 additions and 20 deletions

View file

@ -93,6 +93,7 @@
cost:85, cost:85,
row:1, row:1,
prerequisites:["Sailing"], prerequisites:["Sailing"],
uniques:["Enables embarkation for land units"]
}, },
{ {
name:"Horseback Riding", name:"Horseback Riding",
@ -161,7 +162,7 @@
name:"Guilds", name:"Guilds",
row:7, row:7,
prerequisites:["Currency"], prerequisites:["Currency"],
baseDescription:"Enables conversion of city production to gold" uniques:["Enables conversion of city production to gold"]
}, },
{ {
name:"Metal Casting", name:"Metal Casting",
@ -186,7 +187,7 @@
name:"Education", name:"Education",
row:3, row:3,
prerequisites:["Theology","Civil Service"], prerequisites:["Theology","Civil Service"],
baseDescription:"Enables conversion of city production to science" uniques:["Enables conversion of city production to science"]
}, },
{ {
name:"Chivalry", name:"Chivalry",
@ -197,7 +198,7 @@
name:"Machinery", name:"Machinery",
row:8, row:8,
prerequisites:["Guilds","Engineering"], prerequisites:["Guilds","Engineering"],
baseDescription:"Improves movement speed on roads" uniques:["Improves movement speed on roads"]
}, },
{ {
name:"Physics", name:"Physics",
@ -221,7 +222,7 @@
{ {
name:"Astronomy", name:"Astronomy",
row:2, row:2,
baseDescription:"Increases embarked movement +1", uniques:["Increases embarked movement +1","Enables embarked units to enter ocean tiles"],
prerequisites:["Compass","Education"] prerequisites:["Compass","Education"]
}, },
{ {
@ -339,7 +340,7 @@
{ {
name:"Steam Power", name:"Steam Power",
row:7, row:7,
baseDescription:"Increases embarked movement +1", uniques:["Increases embarked movement +1"],
prerequisites:["Industrialization","Scientific Theory","Rifling"] prerequisites:["Industrialization","Scientific Theory","Rifling"]
}, },
{ {
@ -419,7 +420,7 @@
name:"Computers", name:"Computers",
row:5, row:5,
prerequisites:["Mass Media"], prerequisites:["Mass Media"],
baseDescription:"+10% science and production in all cities" uniques:["+10% science and production in all cities"]
}, },
{ {
name:"Nuclear Fission", name:"Nuclear Fission",
@ -486,7 +487,7 @@
name:"Future Tech", name:"Future Tech",
row:5, row:5,
prerequisites:["Nanotechnology","Particle Physics","Satellites"], prerequisites:["Nanotechnology","Particle Physics","Satellites"],
baseDescription:"Who knows what the future holds?" uniques:["Who knows what the future holds?"]
} }
] ]
} }

View file

@ -58,7 +58,10 @@ class CityStats {
private fun getStatPercentBonusesFromRailroad(): Stats { private fun getStatPercentBonusesFromRailroad(): Stats {
val stats = Stats() val stats = Stats()
if (cityInfo.civInfo.tech.isResearched("Combustion") val techEnablingRailroad = GameBasics.TileImprovements["Railroad"]!!.techRequired!!
// If we conquered enemy cities connected by railroad, but we don't yet have that tech,
// we shouldn't get bonuses, it's as if the tracks aare layed out but we can't operate them.
if (cityInfo.civInfo.tech.isResearched(techEnablingRailroad)
&& (cityInfo.isCapital() || isConnectedToCapital(RoadStatus.Railroad))) && (cityInfo.isCapital() || isConnectedToCapital(RoadStatus.Railroad)))
stats.production += 25f stats.production += 25f
return stats return stats
@ -79,7 +82,7 @@ class CityStats {
private fun getStatPercentBonusesFromComputers(): Stats { private fun getStatPercentBonusesFromComputers(): Stats {
val stats = Stats() val stats = Stats()
if (cityInfo.civInfo.tech.isResearched("Computers")) { if (cityInfo.civInfo.tech.getUniques().contains("+10% science and production in all cities")) {
stats.production += 10f stats.production += 10f
stats.science += 10f stats.science += 10f
} }

View file

@ -18,12 +18,12 @@ open class SpecialConstruction(override var name: String, override val descripti
fun getSpecialConstructions(): List<SpecialConstruction> { fun getSpecialConstructions(): List<SpecialConstruction> {
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){ val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
override fun isBuildable(construction: CityConstructions): Boolean { override fun isBuildable(construction: CityConstructions): Boolean {
return construction.cityInfo.civInfo.tech.isResearched("Education") return construction.cityInfo.civInfo.tech.getUniques().contains("Enables conversion of city production to science")
} }
} }
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){ val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
override fun isBuildable(construction: CityConstructions): Boolean { override fun isBuildable(construction: CityConstructions): Boolean {
return construction.cityInfo.civInfo.tech.isResearched("Guilds") return construction.cityInfo.civInfo.tech.getUniques().contains("Enables conversion of city production to gold")
} }
} }
val idle = object:SpecialConstruction("Nothing", "The city will not produce anything."){ val idle = object:SpecialConstruction("Nothing", "The city will not produce anything."){

View file

@ -48,7 +48,6 @@ class CivilizationInfo {
constructor(civName: String, gameInfo: GameInfo) { constructor(civName: String, gameInfo: GameInfo) {
this.civName = civName this.civName = civName
// this.gameInfo = gameInfo // already happens in setTransients
tech.techsResearched.add("Agriculture") tech.techsResearched.add("Agriculture")
} }
@ -236,7 +235,7 @@ class CivilizationInfo {
fun isDefeated()= cities.isEmpty() && !getCivUnits().any{it.name=="Settler"} fun isDefeated()= cities.isEmpty() && !getCivUnits().any{it.name=="Settler"}
fun getEra(): TechEra { fun getEra(): TechEra {
val maxEraOfTech = tech.techsResearched.map { GameBasics.Technologies[it]!! } val maxEraOfTech = tech.getResearchedTechs()
.map { it.era() } .map { it.era() }
.max() .max()
if(maxEraOfTech!=null) return maxEraOfTech if(maxEraOfTech!=null) return maxEraOfTech

View file

@ -56,6 +56,11 @@ class TechManager {
fun canBeResearched(TechName: String): Boolean { fun canBeResearched(TechName: String): Boolean {
return GameBasics.Technologies[TechName]!!.prerequisites.all { isResearched(it) } return GameBasics.Technologies[TechName]!!.prerequisites.all { isResearched(it) }
} }
fun getResearchedTechs() = techsResearched.map { GameBasics.Technologies[it]!! }
fun getUniques() = getResearchedTechs().flatMap { it.uniques }
//endregion //endregion
fun nextTurn(scienceForNewTurn: Int) { fun nextTurn(scienceForNewTurn: Int) {

View file

@ -109,9 +109,10 @@ class MapUnit {
fun canPassThrough(tile: TileInfo):Boolean{ fun canPassThrough(tile: TileInfo):Boolean{
val tileOwner = tile.getOwner() val tileOwner = tile.getOwner()
if(tile.isWater() && baseUnit.unitType.isLandUnit()){ if(tile.isWater() && baseUnit.unitType.isLandUnit()){
if(!civInfo.tech.isResearched("Optics")) val techUniques = civInfo.tech.getUniques()
if(!techUniques.contains("Enables embarkation for land units"))
return false return false
if(tile.baseTerrain == "Ocean" && !civInfo.tech.isResearched("Astronomy")) if(tile.baseTerrain == "Ocean" && !techUniques.contains("Enables embarked units to enter ocean tiles"))
return false return false
} }
if(tile.isLand() && baseUnit.unitType.isWaterUnit()) if(tile.isLand() && baseUnit.unitType.isWaterUnit())
@ -167,8 +168,7 @@ class MapUnit {
fun getEmbarkedMovement(): Int { fun getEmbarkedMovement(): Int {
var movement=2 var movement=2
movement += civInfo.tech.techsResearched.map { GameBasics.Technologies[it]!! } movement += civInfo.tech.getUniques().count { it == "Increases embarked movement +1" }
.count { it.baseDescription!=null && it.baseDescription!! == "Increases embarked movement +1" }
return movement return movement
} }

View file

@ -16,7 +16,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
if (from.roadStatus !== RoadStatus.None && to.roadStatus !== RoadStatus.None) //Road if (from.roadStatus !== RoadStatus.None && to.roadStatus !== RoadStatus.None) //Road
{ {
if (unit.civInfo.tech.isResearched("Machinery")) return 1 / 3f if (unit.civInfo.tech.getUniques().contains("Improves movement speed on roads")) return 1 / 3f
else return 1 / 2f else return 1 / 2f
} }
if (unit.hasUnique("Ignores terrain cost")) return 1f if (unit.hasUnique("Ignores terrain cost")) return 1f

View file

@ -10,7 +10,7 @@ class Technology : ICivilopedia {
override val description: String override val description: String
get(){ get(){
val SB=StringBuilder() val SB=StringBuilder()
if(baseDescription!=null) SB.appendln(baseDescription!!.tr()) for(unique in uniques) SB.appendln(unique.tr())
val improvedImprovements = GameBasics.TileImprovements.values.filter { it.improvingTech==name }.groupBy { it.improvingTechStats.toString() } val improvedImprovements = GameBasics.TileImprovements.values.filter { it.improvingTech==name }.groupBy { it.improvingTechStats.toString() }
for (improvement in improvedImprovements) { for (improvement in improvedImprovements) {
@ -42,9 +42,9 @@ class Technology : ICivilopedia {
} }
lateinit var name: String lateinit var name: String
var baseDescription: String? = null
var cost: Int = 0 var cost: Int = 0
var prerequisites = HashSet<String>() var prerequisites = HashSet<String>()
var uniques = ArrayList<String>()
var column: TechColumn? = null // The column that this tech is in the tech tree var column: TechColumn? = null // The column that this tech is in the tech tree
var row: Int = 0 var row: Int = 0