Skip to content

Commit 4b261a9

Browse files
tuvusyairm210SomeTroglodytekarmaBonfireSeventhM
authored
Initial AutoPlay implementation (yairm210#10315)
* AutoPlay initial hack * Removed extra changes * Added canceling AutoPlay and its own button * Victory screen showing up stops AutoPlay * Removed AutomateTurn for the spectator * Right Clicking AutoPlay Button starts AutoPlay immediately * Renamed NextTurnMenu to AutoPlayMenu * AutoPlay can now only begin on the players turn * Added specific unit actions AutoPlay * AutoPlay stops on VictoryScreen and GreatPersonPickerScreen * AutoPlay now stops when loading a new game * Hovering the mouse over the AutoPlayStatusButton now stops AutoPlay * Removed temporary right click NextTurnButton functionality * Removed multi-turn AutoPlay from multiplayer games * Loading a multiplayer game now stops AutoPlay * AutoPlayStatusButton persists over reloading WorldScreen * Victory popup now stops autoplay * AutoPlay now automatically picks great person * Full AutoPlay now captures cities * Added settings.isAutoPlaying and fixed bug with closing game in the middle of AutoPlaying a turn * AutoPlay now correctly stops when a victory screen is shown * AutoPlay now automates city constructions without autoAssignCityProduction being on * Reordered NextTurnAction * Removed extra condition for displaying AutoPlay text on next turn button * Moved AutoPlay settings to new tab * Changed AutoPlay slider * Refactored Settings to have AutoPlay to be in a new subclass * Added an show AutoPlay button setting, commented out unimplemented settings * Opening the exit game window stops autoPlay * Made cyclopedia entry * Added translations * AutoPlayStatusButton now ends with a new line * Commented out extra code and removed extra import statements * Fixed UncivSlider Change * Fixed merge conflicts * Settlers no longer stuck in endless loops wanting to found cities on tiles they can't reach @tuvus * Support for Leader voices (yairm210#10395) * Prepare Leader Voices: Framework * Leader Voices: Hooks and corresponding text field comments * Leader Voices: wiki * Leader Voices: oops, comments * Decouple voice play calls to make global modification easier * Move voices to own folder and give them a separate volume setting * Oops, template needed too * Oops, wiki needed too * Resolved yairm210#10366 - City centers don't provide resources you don't have tech to extract * Add a TriggerUponDiscoveringTile unique type (yairm210#10523) * Add a TriggerUponDiscoveringTile unique type * Add a check for trigger presence * Add gain stat modified by speed and improvement speed by filter uniques (yairm210#10443) * Add gain stat modified by speed and improvement speed by filter uniques * Fix rulesets * Remove nonfunctional leftover resource text * Reword improvement unqiue as suggested * Add the SellBuilding Unique (yairm210#10514) * Restored the SellBuilding Unique * Rephrased SellBuilding unique * Version rollout (yairm210#10530) * Bump version and create initial changelog entry * Update Brazilian_Portuguese.properties (yairm210#10528) * Update French.properties (yairm210#10524) * Update Italian.properties (yairm210#10522) * Update Polish.properties (yairm210#10521) * Update Polish.properties * Added Fastlane_short_description * Update Malay.properties (yairm210#10520) Translated line 33 to line 325. Not at all finished. This time though I didn't mess up. --------- Co-authored-by: yairm210 <[email protected]> Co-authored-by: Vitor Gabriel <[email protected]> Co-authored-by: Ouaz <[email protected]> Co-authored-by: Giuseppe D'Addio <[email protected]> Co-authored-by: Lesiakower <[email protected]> Co-authored-by: Mikhail <[email protected]> * Better performance for 'best tile to found city' (minimized canReach calls) @tuvus * 4.9.0 * [Translation] Add back "general" unit types (yairm210#10526) * Add back "general" unit types These entries have been removed from translation files, making them untranslated in-game (in Civilopedia articles) * Revert changes in template.properties * Fix missing unit type translations Fix by @SomeTroglodyte * Changed some parts of GameSettings back to master. * Changed right clicking to call startAutoPlay instead of setting it itself * Fixed some !isHuman() conditions to also include full AutoPlay and refactored some other AutoPlay code --------- Co-authored-by: Yair Morgenstern <[email protected]> Co-authored-by: SomeTroglodyte <[email protected]> Co-authored-by: Sergey <[email protected]> Co-authored-by: SeventhM <[email protected]> Co-authored-by: PLynx <[email protected]> Co-authored-by: yairm210 <[email protected]> Co-authored-by: Vitor Gabriel <[email protected]> Co-authored-by: Ouaz <[email protected]> Co-authored-by: Giuseppe D'Addio <[email protected]> Co-authored-by: Lesiakower <[email protected]> Co-authored-by: Mikhail <[email protected]>
1 parent 03698e4 commit 4b261a9

File tree

27 files changed

+375
-21
lines changed

27 files changed

+375
-21
lines changed

android/assets/jsons/Tutorials.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@
284284
"What you don't see: The phone/tablet's back button will pop the question whether you wish to leave Unciv and go back to Real Life. On desktop versions, you can use the ESC key."
285285
]
286286
},
287+
{
288+
"name": "AutoPlay",
289+
"steps": ["When at later stages of the game, you might have a lot of units but only a little to do. To help you we have implemented an AutoPlay feature that lets you use the AI to play part or all of your turn.",
290+
"To enable AutoPlay, go to options and open the AutoPlay tab and press \"Show AutoPlay button\".",
291+
"Clicking on the AutoPlay button opens a popup menue for choosing to AutoPlay parts or all of your turn.",
292+
"Clicking Start AutoPlay in the pop-up menue or long pressing the AutoPlay button begins the multi-turn AutoPlay. This will play your next turns as if you were an AI.",
293+
"To cancel multi-turn AutoPlay you can press the AutoPlay button, next turn button or open the options menue.",
294+
"Multi-turn AutoPlay is not advised on harder difficulty levels as your AI will not play better against an AI with modifiers.",
295+
"Multi-turn AutoPlay for multiplayer is not yet supported."
296+
]
297+
},
287298
{
288299
"name": "Faith",
289300
"steps": [

android/assets/jsons/translations/template.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,16 @@ Hide =
857857
HIGHLY EXPERIMENTAL - YOU HAVE BEEN WARNED! =
858858
You need to restart the game for this change to take effect. =
859859

860+
# AutoPlay
861+
AutoPlay =
862+
Show AutoPlay button =
863+
Multi-turn AutoPlay amount =
864+
865+
Start AutoPlay =
866+
AutoPlay End Turn =
867+
AutoPlay Military Once =
868+
AutoPlay Civilians Once =
869+
AutoPlay Economy Once =
860870

861871
# Notifications
862872

core/src/com/unciv/UncivGame.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci
292292
fun popScreen(): BaseScreen? {
293293
if (screenStack.size == 1) {
294294
musicController.pause()
295+
UncivGame.Current.settings.autoPlay.stopAutoPlay()
295296
ConfirmPopup(
296297
screen = screenStack.last(),
297298
question = "Do you want to exit the game?",

core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ object NextTurnAutomation {
339339
for (unit in sortedUnits) UnitAutomation.automateUnitMoves(unit)
340340
}
341341

342-
private fun getUnitPriority(unit: MapUnit, isAtWar: Boolean): Int {
342+
fun getUnitPriority(unit: MapUnit, isAtWar: Boolean): Int {
343343
if (unit.isCivilian() && !unit.isGreatPersonOfType("War")) return 1 // Civilian
344344
if (unit.baseUnit.isAirUnit()) return 2
345345
val distance = if (!isAtWar) 0 else unit.civ.threatManager.getDistanceToClosestEnemyUnit(unit.getTile(),6)
@@ -356,7 +356,7 @@ object NextTurnAutomation {
356356
for (city in civInfo.cities) UnitAutomation.tryBombardEnemy(city)
357357
}
358358

359-
private fun automateCities(civInfo: Civilization) {
359+
fun automateCities(civInfo: Civilization) {
360360
val ownMilitaryStrength = civInfo.getStatForRanking(RankingType.Force)
361361
val sumOfEnemiesMilitaryStrength =
362362
civInfo.gameInfo.civilizations

core/src/com/unciv/logic/automation/unit/UnitAutomation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ object UnitAutomation {
125125
}
126126

127127
internal fun tryUpgradeUnit(unit: MapUnit): Boolean {
128-
val isHuman = unit.civ.isHuman()
129-
if (!UncivGame.Current.settings.automatedUnitsCanUpgrade && isHuman) return false
128+
if (unit.civ.isHuman() && (!UncivGame.Current.settings.automatedUnitsCanUpgrade
129+
|| UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())) return false
130130
if (unit.baseUnit.upgradesTo == null) return false
131131
val upgradedUnit = unit.upgrade.getUnitToUpgradeTo()
132132
if (!upgradedUnit.isBuildable(unit.civ)) return false // for resource reasons, usually

core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class WorkerAutomation(
5050
private val bestRoadAvailable: RoadStatus =
5151
cloningSource?.bestRoadAvailable ?:
5252
//Player can choose not to auto-build roads & railroads.
53-
if (civInfo.isHuman() && !UncivGame.Current.settings.autoBuildingRoads)
53+
if (civInfo.isHuman() && (!UncivGame.Current.settings.autoBuildingRoads
54+
|| UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI()))
5455
RoadStatus.None
5556
else civInfo.tech.getBestRoadAvailable()
5657

@@ -340,11 +341,12 @@ class WorkerAutomation(
340341

341342
//If the tile is a junk improvement or a fort placed in a bad location.
342343
val junkImprovement = tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedWorkersWillReplace) == true
343-
|| (tile.improvement == Constants.fort && !evaluateFortSuroundings(tile, false) && !civInfo.isHuman())
344+
|| (tile.improvement == Constants.fort && !evaluateFortSuroundings(tile, false)
345+
&& (!civInfo.isHuman() || UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI()))
344346

345347
if (tile.improvement != null && !junkImprovement
346348
&& !UncivGame.Current.settings.automatedWorkersReplaceImprovements
347-
&& unit.civ.isHuman())
349+
&& unit.civ.isHuman() && !UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())
348350
return false
349351

350352
if (tile.improvement == null || junkImprovement) {

core/src/com/unciv/logic/battle/Battle.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.unciv.logic.battle
22

33
import com.badlogic.gdx.math.Vector2
44
import com.unciv.Constants
5+
import com.unciv.GUI
56
import com.unciv.UncivGame
67
import com.unciv.logic.automation.civilization.NextTurnAutomation
78
import com.unciv.logic.city.City
@@ -535,7 +536,7 @@ object Battle {
535536
city.puppetCity(attackerCiv)
536537
//Although in Civ5 Venice is unable to re-annex their capital, that seems a bit silly. No check for May not annex cities here.
537538
city.annexCity()
538-
} else if (attackerCiv.isHuman()) {
539+
} else if (attackerCiv.isHuman() && !(UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())) {
539540
// we're not taking our former capital
540541
attackerCiv.popupAlerts.add(PopupAlert(AlertType.CityConquered, city.id))
541542
} else automateCityConquer(attackerCiv, city)

core/src/com/unciv/logic/city/CityConstructions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ class CityConstructions : IsPartOfGameInfoSerialization {
697697

698698
val isCurrentPlayersTurn = city.civ.gameInfo.isUsersTurn()
699699
|| !city.civ.gameInfo.gameParameters.isOnlineMultiplayer
700-
if ((UncivGame.Current.settings.autoAssignCityProduction && isCurrentPlayersTurn) // only automate if the active human player has the setting to automate production
700+
if ((isCurrentPlayersTurn && (UncivGame.Current.settings.autoAssignCityProduction
701+
|| UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())) // only automate if the active human player has the setting to automate production
701702
|| !city.civ.isHuman() || city.isPuppet) {
702703
ConstructionAutomation(this).chooseNextConstruction()
703704
}

core/src/com/unciv/logic/civilization/diplomacy/DiplomacyFunctions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class DiplomacyFunctions(val civInfo: Civilization) {
156156
if (diplomacyManager != null && (diplomacyManager.hasOpenBorders || diplomacyManager.diplomaticStatus == DiplomaticStatus.War))
157157
return true
158158
// Players can always pass through city-state tiles
159-
if (civInfo.isHuman() && otherCiv.isCityState()) return true
159+
if ((civInfo.isHuman() && !UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI()) && otherCiv.isCityState()) return true
160160
return false
161161
}
162162

core/src/com/unciv/logic/multiplayer/OnlineMultiplayer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class OnlineMultiplayer {
244244
} else if (onlinePreview != null && hasNewerGameState(preview, onlinePreview)) {
245245
onlineGame.doManualUpdate(preview)
246246
}
247+
UncivGame.Current.settings.autoPlay.stopAutoPlay()
247248
UncivGame.Current.loadGame(gameInfo)
248249
}
249250

0 commit comments

Comments
 (0)