Add district unemployment signals and workplace features#140
Add district unemployment signals and workplace features#140Toon-Red wants to merge 1 commit intoihsoft:timberborn-1.0from
Conversation
District signals: - District.UnemployedBeavers: number of unemployed beaver workers - District.UnemployedBots: number of unemployed bot workers Uses the game's PopulationDataCollector.CollectData() to read the same unemployment values displayed in the top-left UI panel. Change tracking subscribes to CitizenAssigned/Unassigned events and per-workplace WorkerAssigned/Unassigned events so the signal updates when workers are hired, fired, or reassigned. Workplace signal: - Workplace.AssignedWorkers: current number of workers at a building Tracks via WorkerAssigned/WorkerUnassigned events on the Workplace. Workplace action: - Workplace.SetPriority: sets the building's worker priority level (VeryLow/Low/Normal/High/VeryHigh) via WorkplacePriority component. Uses the game's built-in Priorities localization keys for the dropdown display names. Localization: - Added English (enUS) and Russian (ruRU) strings for all new signals and actions.
|
Thanks for the PR! I will verify it shortly. At the first glance, it seems, some of the singlas may trigger even if the value hasn't actually changed, but itis a minor issue at this point due to these events are not high frequency. |
ihsoft
left a comment
There was a problem hiding this comment.
With the v1.0 release approaching, this code won't live long unless merged to the appropriate branch. However, the latter can be not that easy due to the big changes made to the game.
| if (!Enum.TryParse<Priority>(priorityName, out var priority)) { | ||
| throw new ScriptError.ValueOutOfRange($"Unknown priority: {priorityName}"); | ||
| } | ||
| var workplacePriority = behavior.GetComponentFast<WorkplacePriority>(); |
There was a problem hiding this comment.
This is known at the stage of getting action def/executor. It should be checked there to allow the parser detecting improper usage, and the priority instance can be passed instead of the behavior.
GetActionNamesForBuilding is only used by the UI constructor, in the plain text mode player can specify any action/signal.
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void UnregisterSignalChangeCallback(SignalOperator signalOperator, ISignalListener host) { |
There was a problem hiding this comment.
Wrong signal names should be checked here too. It helps catching errors in the core implementation.
|
|
||
| void FinishedBuildingUnregisteredEvent(object sender, FinishedBuildingUnregisteredEventArgs arg) { | ||
| ScheduleSignal(NumberOfBedsSignalName, ignoreErrors: true); | ||
| // Re-subscribe to drop the destroyed workplace's worker events. |
There was a problem hiding this comment.
Full re-subscription on every event can be a problem on big game setups or when many buildings get destroyed at once (e.g. when detonating dynamates). Dam construction is another example of many objects being created without any impact to the workplaces, but they will trigger re-subscription and the relevant events.
The event has the entity that was unregistered. If it's not a workplace - skip. Otherwise, it's only one element to update: subscribe or unsubscribe.
|
|
||
| sealed class WorkplaceChangeTracker : AbstractStatusTracker { | ||
|
|
||
| void Start() { |
There was a problem hiding this comment.
FYI, in v1.0 the concept of dynamic components has significantly changed. They are not MonoBehaviours anymore.
|
So, on a second thought:
|
|
Merged workplace signal and action to v1.0: 35cb314 |
Summary
Implements Issue #78 — district-level unemployment signals — plus two related workplace features:
PopulationDataCollectorAll four use existing game APIs and follow the established
ScriptableComponentBasepatterns (signal definitions, change trackers, localization).Changes
DistrictScriptableComponent.cs— added unemployment signals + district-wide workplace event trackingWorkplaceScriptableComponent.cs— added assigned workers signal + set priority action with dropdownenUS.txt/ruRU.txt— localization strings for all new signals/actionsTest plan