New feature documentation time! With a recent code addition to OXCE+, you can now 'upgrade' existing facilities by building over them, and you can also make it such that removing a facility can 'downgrade' it to another facility.
The rules for this feature are as follows:
When a facility is removed, the ruleset is checked for a list of facility names leaveBehindOnSell
- If the first facility on the list is equal to the size of original, then that facility is placed over the previous one
- If the list contains all size 1 facilities, then the list is iterated over, placing facilities until the size of the previous is reach
- If the sizes don't match one of the above conditions, an exception is thrown letting the player/modder know the sizes don't match up
The facilities left behind are given a build time according to the previous facility's removalTime:
- If removalTime: 0, then the facility is instantly built (default behavior)
- If removalTime: -1, then the build time is set to the new facility's normal build time
- If removalTime is a number greater than 0, then the build time for the new facility is set to that number
Any facility placed by this left behind method is flagged for having a facility there previously; this flag makes the facility count as already built for base connectivity, makes it so the facility cannot be removed until it is fully built (this is to represent deconstruction time), and makes the new facility have it's map placed during base defense missions.
When a facility is built, the buildings under where it's being placed are checked for the tag canBeBuiltOver; if the tag is true, then new facility can be built over the previous one. The refund for removal of each of the facilities being replaced is applied, and the build time for the new facility is reduced by the build time of each of those previous facilities, normalized by the size of the new facility. This build time can never be reduced below 1 day. The new facility is flagged similarly to ones left behind after being removed, unless all the facilities being replaced are under construction.
You can further specify which facilities one building is allowed to replace by the buildOverFacilities list - if this list is empty, no filter is applied. Otherwise, the facilities which are being replaced have to be on this list, otherwise the facility building is blocked. Upgrading an existing facility is also blocked if all of the other ones connecting to it are under construction, even if build queue is turned on.
I'm attaching a mod to test this code - many of the beginning facilities will leave corridors behind when they're deconstructed, corridors can be upgraded to living quarters and any other facility, general stores can be upgraded to anything but living quarters, and small radar can't be built over anything. You can also build over hangars, but only with other hangars; this is just to test the code with 2x2 buildings. The sectoid research mission at the beginning of the game is replaced with a retaliation mission to make sure the base maps are generated correctly.
This code also adds the following messages to let you know exactly why a facility can't be built:
#BasescapeState.cpp
STR_CANNOT_DISMANTLE_FACILITY_UPGRADING: "CANNOT DISMANTLE FACILITY!{SMALLLINE}Facility cannot be removed during upgrading."
#BaseView.cpp
STR_CANNOT_UPGRADE_FACILITY_ALREADY_UPGRADING: "CANNOT BUILD HERE!{SMALLLINE}Existing facility is already being built over."
STR_CANNOT_UPGRADE_FACILITY_WRONG_SIZE: "CANNOT BUILD HERE!{SMALLLINE}Selected facility must completely cover existing facility."
STR_CANNOT_UPGRADE_FACILITY_WRONG_TYPE: "CANNOT BUILD HERE!{SMALLLINE}Existing facility cannot be upgraded over by selected facility."
STR_CANNOT_UPGRADE_FACILITY_DISALLOWED: "CANNOT BUILD HERE!{SMALLLINE}Existing facility cannot be built over."
STR_CANNOT_BUILD_QUEUE_OFF: "CANNOT BUILD HERE!{SMALLLINE}Connecting facilities must finish construction first."