Skip to content

Add district unemployment signals and workplace features#140

Open
Toon-Red wants to merge 1 commit intoihsoft:timberborn-1.0from
Toon-Red:feature/district-unemployed-signals
Open

Add district unemployment signals and workplace features#140
Toon-Red wants to merge 1 commit intoihsoft:timberborn-1.0from
Toon-Red:feature/district-unemployed-signals

Conversation

@Toon-Red
Copy link

Summary

Implements Issue #78 — district-level unemployment signals — plus two related workplace features:

  • District.UnemployedBeavers / District.UnemployedBots signals — reads the same values the game UI shows, via PopulationDataCollector
  • Workplace.AssignedWorkers signal — current number of assigned workers for a building
  • Workplace.SetPriority action — set workplace priority (VeryLow through VeryHigh) via dropdown

All four use existing game APIs and follow the established ScriptableComponentBase patterns (signal definitions, change trackers, localization).

Changes

  • DistrictScriptableComponent.cs — added unemployment signals + district-wide workplace event tracking
  • WorkplaceScriptableComponent.cs — added assigned workers signal + set priority action with dropdown
  • enUS.txt / ruRU.txt — localization strings for all new signals/actions

Test plan

  • Verified unemployment signals reflect game UI values
  • Verified assigned workers signal updates on worker assign/unassign
  • Verified set priority action works with all five priority levels
  • Verified dropdown displays localized priority names
  • Built against game version 0.7.x with no warnings

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.
@ihsoft
Copy link
Owner

ihsoft commented Feb 25, 2026

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.

Copy link
Owner

@ihsoft ihsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, in v1.0 the concept of dynamic components has significantly changed. They are not MonoBehaviours anymore.

@ihsoft ihsoft changed the base branch from main to timberborn-1.0 February 27, 2026 04:46
@ihsoft
Copy link
Owner

ihsoft commented Feb 27, 2026

So, on a second thought:

  1. Merging to main branch makes no sense, it's game v0.7, which will gone in less than a month. If making changes, then to v1.0 directly.
  2. The approach with the employment tracking, as it is, would be slow. Every building, which needs to use any district signal, will endup subscribing to all workplaces in the district. It's O(n2) complexity, which is not acceptable. To go forward, the whole approach of tracking district stats needs to change. All stats should be tracked by a single component on the district center building, and all other listeners should just subscribe to it.
  3. The Workplace changes are fine. I'll merge them into v1.0 branch.

@ihsoft
Copy link
Owner

ihsoft commented Feb 27, 2026

Merged workplace signal and action to v1.0: 35cb314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants