Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev RFC: MapUnit and automated - doc and roadmap? #11841

Closed
SomeTroglodyte opened this issue Jun 24, 2024 · 6 comments
Closed

Dev RFC: MapUnit and automated - doc and roadmap? #11841

SomeTroglodyte opened this issue Jun 24, 2024 · 6 comments

Comments

@SomeTroglodyte
Copy link
Collaborator

SomeTroglodyte commented Jun 24, 2024

Problem Description

The action and automated fields of MapUnit lack documentation and clarity. I tried to encapsulate - make just the set private, replace with accessors, and build a Kdoc from there - and gave up - I don't know all ramifications, and deducting them from code is effort.

  • Is an automated unit supposed to have action == null and automated == true in the near future?
  • If the boolean is derived from action at load time - why not for ConnectRoad, while the code that sets ConnectRoad also sets the boolean true?
  • What about the action clear in ImprovementPicker - that would leave the boolean on, but likely disturb ConnectRoad?
  • Who would advocate making all four of these private and how should the accessor signature look like? My opinion - at least the writing part, the knowledge about which combinations are good / which are not should be encapsulated. But to do that I'd need help with what the intentions actually are.

Code places to look into

Index: core/src/com/unciv/ui/screens/pickerscreens/ImprovementPickerScreen.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/ui/screens/pickerscreens/ImprovementPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/ImprovementPickerScreen.kt
--- a/core/src/com/unciv/ui/screens/pickerscreens/ImprovementPickerScreen.kt	(revision 3cd45dea458eda16afb54b6f219cf3a3ded11ca4)
+++ b/core/src/com/unciv/ui/screens/pickerscreens/ImprovementPickerScreen.kt	(date 1719217196700)
@@ -65,7 +65,7 @@
                 if (secondImprovement != null)
                     tile.queueImprovement(secondImprovement, currentPlayerCiv, unit)
             }
-            unit.action = null // this is to "wake up" the worker if it's sleeping
+            if (unit.isSleeping()) unit.action = null // "wake up" the worker
             onAccept()
         }
         game.popScreen()
Index: core/src/com/unciv/logic/map/mapunit/MapUnit.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt
--- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt	(revision 3cd45dea458eda16afb54b6f219cf3a3ded11ca4)
+++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt	(date 1719222664988)
@@ -58,7 +58,12 @@
     var health: Int = 100
     var id: Int = Constants.NO_ID
 
-    // work, automation, fortifying, ...
+    /** work, exploring, fortifying, ... This should be one of the [UnitActionType.value] entries.
+     *  - automation is a special case (TODO explain)
+     *  @see automated
+     *  @see automatedRoadConnectionPath
+     *  @see automatedRoadConnectionDestination
+     */
     // Connect roads implies automated is true. It is specified by the action type.
     var action: String? = null
     var automated: Boolean = false
@@ -621,7 +626,8 @@
                 ?: throw java.lang.Exception("Unit $name is not found!")
 
         updateUniques()
-        if (action == UnitActionType.Automate.value) automated = true
+        // Temporary, for compatibility - we want games serialized *moving through old versions* to come out the other end with units still automated
+        if (action == UnitActionType.Automate.value || action == UnitActionType.ConnectRoad.value) automated = true
     }
 
     fun updateUniques() {
@yairm210
Copy link
Owner

Automated units are supposed to have only "automated true" set, not the action - this is so that automated units can have a state, like "set up", "fortified", etc, without taking them out of automation

@SomeTroglodyte
Copy link
Collaborator Author

So UnitActionType.ConnectRoad isn't supposed to be treated as automated?

@yairm210
Copy link
Owner

ConnectRoad is a specific action we ask the unit to do. You could consider that automation or not, that's semantics.
What the unit is not, is Automated, with a capital A. Capital A Automated units are set into that mode by the user, and from then on do whatever they think is best. In fact an automated unit could decide that it needs to connect a road and then it's be doubly automated

@SomeTroglodyte
Copy link
Collaborator Author

What the unit is not, is Automated, with a capital A

Then the connect road code is bugged in a minor way - perfect, all perceived inconsistencies explained.

Copy link

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@github-actions github-actions bot added the Stale label Sep 24, 2024
Copy link

github-actions bot commented Oct 9, 2024

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants