Skip to content

Commit

Permalink
Added modoptions unique for disabling city-state spawning with only a…
Browse files Browse the repository at this point in the history
… settler (yairm210#4691)
  • Loading branch information
xlenstra authored Aug 1, 2021
1 parent 3cf9191 commit 78dddac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions core/src/com/unciv/logic/GameStarter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.unciv.logic.map.TileMap
import com.unciv.logic.map.mapgenerator.MapGenerator
import com.unciv.models.metadata.GameParameters
import com.unciv.models.ruleset.Era
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.ruleset.tile.ResourceType
Expand Down Expand Up @@ -235,6 +236,7 @@ object GameStarter {
// An unusually bad spawning location
addConsolationPrize(gameInfo, startingLocation, 45 - startingLocation.getTileStartScore().toInt())
}

if(civ.isCityState())
addCityStateLuxury(gameInfo, startingLocation)

Expand Down Expand Up @@ -308,13 +310,21 @@ object GameStarter {
return civ.getEquivalentUnit(unit).name
}

// City states & one city challengers should spawn with one settler only regardless of era and difficulty
if (civ.isCityState() || civ.playerType==PlayerType.Human && gameInfo.gameParameters.oneCityChallenge) {
// City states should only spawn with one settler regardless of difficulty, but this may be disabled in mods
if (civ.isCityState() && !ruleSet.modOptions.uniques.contains(ModOptionsConstants.allowCityStatesSpawnUnits)) {
val startingSettlers = startingUnits.filter { settlerLikeUnits.contains(it) }

startingUnits.clear()
startingUnits.add(startingSettlers.random())
}

// One city challengers should spawn with one settler only regardless of era and difficulty
if (civ.playerType == PlayerType.Human && gameInfo.gameParameters.oneCityChallenge) {
val startingSettlers = startingUnits.filter { settlerLikeUnits.contains(it) }

startingUnits.removeAll(startingSettlers)
startingUnits.add(startingSettlers.random())
}

for (unit in startingUnits) {
val unitToAdd = getEquivalentUnit(civ, unit)
Expand Down
3 changes: 2 additions & 1 deletion core/src/com/unciv/logic/city/CityStats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.logic.map.RoadStatus
import com.unciv.models.Counter
import com.unciv.models.ruleset.Building
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.ruleset.Unique
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stat
Expand Down Expand Up @@ -457,7 +458,7 @@ class CityStats {
}

// AFTER we've gotten all the gold stats figured out, only THEN do we plonk that gold into Science
if (cityInfo.getRuleset().modOptions.uniques.contains("Can convert gold to science with sliders")) {
if (cityInfo.getRuleset().modOptions.uniques.contains(ModOptionsConstants.convertGoldToScience)) {
val amountConverted = (newFinalStatList.values.sumByDouble { it.gold.toDouble() }
* cityInfo.civInfo.tech.goldPercentConvertedToScience).toInt().toFloat()
if (amountConverted > 0) // Don't want you converting negative gold to negative science yaknow
Expand Down
8 changes: 6 additions & 2 deletions core/src/com/unciv/models/ruleset/Ruleset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import kotlin.collections.set

object ModOptionsConstants {
const val diplomaticRelationshipsCannotChange = "Diplomatic relationships cannot change"
const val convertGoldToScience = "Can convert gold to science with sliders"
const val allowCityStatesSpawnUnits = "Allow City States to spawn with additional units"
}

class ModOptions {
Expand All @@ -29,13 +31,15 @@ class ModOptions {
var buildingsToRemove = HashSet<String>()
var unitsToRemove = HashSet<String>()
var nationsToRemove = HashSet<String>()
var uniques = HashSet<String>()
val maxXPfromBarbarians = 30


var lastUpdated = ""
var modUrl = ""
var author = ""
var modSize = 0

val maxXPfromBarbarians = 30
var uniques = HashSet<String>()
}

class Ruleset {
Expand Down
3 changes: 2 additions & 1 deletion core/src/com/unciv/ui/overviewscreen/StatsOverviewTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Slider
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.models.ruleset.ModOptionsConstants
import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import kotlin.math.roundToInt
Expand Down Expand Up @@ -62,7 +63,7 @@ class StatsOverviewTable (
goldTable.add("Total".tr())
goldTable.add(total.roundToInt().toString()).right()

if (viewingPlayer.gameInfo.ruleSet.modOptions.uniques.contains("Can convert gold to science with sliders")) {
if (viewingPlayer.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.convertGoldToScience)) {
goldTable.addSeparator()
val sliderTable = Table()
sliderTable.add("Convert gold to science".toLabel()).row()
Expand Down

0 comments on commit 78dddac

Please sign in to comment.