Automatically enable / disable properties of units that are produced by factories
Description
This feature is inspired by https://github.com/FAForever/fa/pull/5495
When a unit is created there are properties from the factory that the unit can inherit. There are two examples that I am aware of:
- A unit can inherit the fire state of the factory
- A unit can inherit the control group of the factory
In this issue I propose we extend this feature through toggles. The reason for toggles as that they can be adjusted by the UI, and therefore we can update the toggle to match what is in the preference file of a user. A similar approach is done in https://github.com/FAForever/fa/issues/4524 by @haifron to automatically enable repeat build for a factory when you select it for the first time, except that it doesn't use a toggle 😃
Once the toggle exists we can interpret the toggle during the OnStopBuild event and update the properties of the unit that we're building. As an example of a few properties that may be interesting:
- (1) Automatically enable or disable the intel of a unit if it consumes maintenance (Cybran Mole, ASF, Strategic Bomber, ...)
- (2) Automatically enable or disable the construction of (strategic) missiles (strategic submarines, Seraphim battleship)
- (3) Automatically enable or disable the shield of a unit if it consumes maintenance
And I'm sure we can think of other examples in the (near) future. The goal of these changes is to reduce the 'initial maintenance' or the 'oh shit, I forgot' type of issues that players can perceive
It may also be interesting to add a general framework for this type of behavior. It doesn't need to be an extensive framework, but a way for user mods to hook into the event when a unit is selected for the first time by a user and apply behavior to the unit accordingly
Is automatically disabling shields something that is ever a good idea?
I don't know; it was just an example 😃
Relevant in an edge case (at the very least) where you're building a bunch of shielded units and are on a tight energy budget.
General thoughts on a general framework:
-
Control groups are difficult to access from the Sim (UserUnit:GetSelectionSets is pretty much it) and are (as you know) set by the engine in the UI with AddUnitToSelectionSet when construction begins. A system that modifies them would need to be UI based, or separate entirely from the ScriptBits.
-
When writing mods for the control group system, I've commented internally that an "AddUnitToSelectionSet" callback routine would really open that function up for UI mods to interact with units when a factory begins construction. Applying that to all factories regardless of their control group status requires a default dummy control group to be applied (literally just " "--hacky, but unobtrusive).
-
Is it possible to add more scriptbit toggles or are the ones defined by the engine it? (Not saying we need more, mostly just curious how much literature there is on their nature and function)
When writing mods for the control group system, I've commented internally that an "AddUnitToSelectionSet" callback routine would really open that function up for UI mods to interact with units when a factory begins construction. Applying that to all factories regardless of their control group status requires a default dummy control group to be applied (literally just " "--hacky, but unobtrusive).
In general, an event or two when things happen to user units would be nice to have 😃
@4z0t would that be possible? To have an event in the UI when a unit starts existing and when it is done building? There are other events in gamemain.lua, such as when a unit of the focus army receives damage
I know there is a part of code in sync loop instantiating user units. I'll take a look if it is responsible for new ones being created on sim side.
Okay okay. I had misread, and was operating under the assumption that you wanted a more extensible system for control groups and firestates, only to discover to my surprise (after a basic firestate applier implementation) that the base game had beat me to the punch. But that's all in the past, moving on.
In better news, because Sim<->UI toggle is well established, it means we can abandon all the dodgy "dummy selection set business", no engine patches required (UI side unit callback still useful on its own merits).
For the order buttons:
- My main concern is taking up space on the factory UI. Shields, missiles, intel, etc.--it's a lot of buttons.
- To that end, I suggest a "built units" order popup, similar to the current fire state popup, that shows all the possible toggles of all units that can be built by the builder (believe we could populate that with blueprints-units).
- Click the popup, a big stack of toggles comes up, you toggle the ones you want.
- This option would need art for the order icon that could communicate that all those options are in there.
EDIT: A tricky element of the above is, when the toggle is changed in orders.lua, how do we flip the bit on factories that (potentially, non in the base game as far as I know) have intel/shield/weapon toggles etc. I think we can use RULEUTC_SpecialToggle as an address bit--orders.lua can flip it when it's modifying the toggles intended for built units, which the sim side can then read and flip any of the relevant toggles back after storing their changes.