Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions engine/Sim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@ end
function MetaImpact(instigator, location, maxRadius, amount, affectsCategory, damageFriendly)
end

--- Handles command structure when a unit upgrades to another:
--- - Adds the new unit to the old unit's queued commands.
--- - Retargets assisters onto the new unit.
--- - Sets repeat queue.
--- - Sets missing health proportion of the new unit.
---@param from Unit
---@param to Unit
function NotifyUpgrade(from, to)
Expand Down
28 changes: 14 additions & 14 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2844,20 +2844,6 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni
return false -- Report failure of OnStartBuild
end

-- If desired, prevent engineer stations from building their upgrades as a separate unit
-- We need a separate table for this just in case a unit is intended to be able to build its own upgrade as a separate unit too
-- Its type is `UnparsedCategory[]` to make it behave identically to `Blueprint.Economy.BuildableCategory`
local upgradeOnlyCategory = self.Blueprint.Economy.UpgradeOnlyCategory
if upgradeOnlyCategory and order == "MobileBuild" then
for _, unparsedCat in upgradeOnlyCategory do
if EntityCategoryContains(ParseEntityCategory(unparsedCat), built) then
-- Destroying the built unit will clear the command too, so we don't need to clear the entire queue (in case this exploit was done on accident).
built:Destroy()
return false
end
end
end

-- We just started a construction (and haven't just been tasked to work on a half-done
-- project.)
if built:GetHealth() == 1 then
Expand Down Expand Up @@ -4101,11 +4087,25 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni
return false
end,

--- Called by the engine on `FactoryBuild` and `MobileBuild` orders to determine if a unit is allowed to be built.
---@param self Unit
---@param target_bp UnitBlueprint
---@return boolean
CheckBuildRestriction = function(self, target_bp)
if self:CanBuild(target_bp.BlueprintId) then

-- If desired, prevent engineer stations and factories from building their upgrades as a separate unit
-- We need a separate table for this just in case a unit is intended to be able to build its own upgrade as a separate unit too
-- Its type is `UnparsedCategory[]` to make it behave identically to `Blueprint.Economy.BuildableCategory`
local upgradeOnlyCategory = self.Blueprint.Economy.UpgradeOnlyCategory
if upgradeOnlyCategory then
for _, unparsedCat in upgradeOnlyCategory do
if EntityCategoryContains(ParseEntityCategory(unparsedCat), target_bp.BlueprintId) then
return false
end
end
end

return true
else
return false
Expand Down
19 changes: 4 additions & 15 deletions lua/sim/units/FactoryUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ FactoryUnit = ClassUnit(StructureUnit) {
---@param self FactoryUnit
---@param unitBeingBuilt Unit
---@param order string
---@return boolean
OnStartBuild = function(self, unitBeingBuilt, order)
StructureUnitOnStartBuild(self, unitBeingBuilt, order)
if not StructureUnitOnStartBuild(self, unitBeingBuilt, order) then return false end

self.FactoryBuildFailed = nil
self.BuildingUnit = true
Expand All @@ -120,6 +121,8 @@ FactoryUnit = ClassUnit(StructureUnit) {
self:RemoveCommandCap('RULEUCC_Guard')
self.DisabledAssist = true
end

return true
end,

--- Introduce a rolloff delay, where defined.
Expand Down Expand Up @@ -288,20 +291,6 @@ FactoryUnit = ClassUnit(StructureUnit) {
end
end,

---@param self FactoryUnit
---@param target_bp any
---@return boolean
CheckBuildRestriction = function(self, target_bp)
-- Check basic build restrictions first (Unit.CheckBuildRestriction but we only go up one inheritance level)
if not StructureUnitCheckBuildRestriction(self, target_bp) then
return false
end
-- Factories never build factories (this does not break Upgrades since CheckBuildRestriction is never called for Upgrades)
-- Note: We check for the primary category, since e.g. AircraftCarriers have the FACTORY category.
-- TODO: This is a hotfix for --1043, remove when engymod design is properly fixed
return target_bp.General.Category ~= 'Factory'
end,

---@param self FactoryUnit
CalculateRollOffPoint = function(self)
local px, py, pz = self:GetPositionXYZ()
Expand Down
5 changes: 4 additions & 1 deletion lua/sim/units/StructureUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,11 @@ StructureUnit = ClassUnit(Unit, BlinkingLightsUnitComponent) {
---@param self StructureUnit
---@param unitBeingBuilt Unit
---@param order string
---@return boolean
OnStartBuild = function(self, unitBeingBuilt, order)
-- Check for death loop
if not UnitOnStartBuild(self, unitBeingBuilt, order) then
return
return false
end
self.UnitBeingBuilt = unitBeingBuilt

Expand Down Expand Up @@ -635,6 +636,8 @@ StructureUnit = ClassUnit(Unit, BlinkingLightsUnitComponent) {
end
end
end

return true
end,

---@param self StructureUnit
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0101/UAB0101_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY AEON STRUCTURE LAND",
"BUILTBYTIER1FACTORY AEON MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY AEON STRUCTURE LAND",
},
RebuildBonusIds = { "uab0101" },
StorageEnergy = 0,
StorageMass = 80,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0102/UAB0102_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY AEON MOBILE AIR",
"TRANSPORTBUILTBYTIER1FACTORY AEON MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY AEON STRUCTURE AIR",
},
RebuildBonusIds = { "uab0102" },
StorageEnergy = 0,
StorageMass = 80,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0103/UAB0103_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY AEON STRUCTURE NAVAL",
"BUILTBYTIER1FACTORY AEON MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY AEON STRUCTURE NAVAL",
},
InitialRallyX = 0,
InitialRallyZ = 10,
RebuildBonusIds = { "uab0103" },
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0201/UAB0201_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY AEON STRUCTURE LAND",
"BUILTBYTIER2FACTORY AEON MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY AEON STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "uab0201" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0202/UAB0202_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY AEON MOBILE AIR",
"TRANSPORTBUILTBYTIER2FACTORY AEON MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY AEON STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "uab0202" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0203/UAB0203_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY AEON STRUCTURE NAVAL",
"BUILTBYTIER2FACTORY AEON MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY AEON STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0301/UAB0301_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY AEON STRUCTURE LAND",
"BUILTBYTIER3FACTORY AEON MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY AEON STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "uab0301" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0302/UAB0302_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY AEON MOBILE AIR",
"TRANSPORTBUILTBYTIER3FACTORY AEON MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY AEON STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "uab0302" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UAB0303/UAB0303_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY AEON STRUCTURE NAVAL",
"BUILTBYTIER3FACTORY AEON MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY AEON STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0101/UEB0101_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY UEF STRUCTURE LAND",
"BUILTBYTIER1FACTORY UEF MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY UEF STRUCTURE LAND",
},
RebuildBonusIds = { "ueb0101" },
StorageEnergy = 0,
StorageMass = 80,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0102/UEB0102_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY UEF MOBILE AIR",
"TRANSPORTBUILTBYTIER1FACTORY UEF MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY UEF STRUCTURE AIR",
},
RebuildBonusIds = { "ueb0102" },
StorageEnergy = 0,
StorageMass = 80,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0103/UEB0103_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY UEF STRUCTURE NAVAL",
"BUILTBYTIER1FACTORY UEF MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY UEF STRUCTURE NAVAL",
},
InitialRallyX = 0,
InitialRallyZ = 10,
RebuildBonusIds = { "ueb0103" },
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0201/UEB0201_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY UEF MOBILE LAND",
"BUILTBYLANDTIER2FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY UEF STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "ueb0201" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0202/UEB0202_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ UnitBlueprint{
"TRANSPORTBUILTBYTIER2FACTORY UEF MOBILE AIR",
"BUILTBYAIRTIER2FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY UEF STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "ueb0202" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0203/UEB0203_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY UEF MOBILE NAVAL",
"BUILTBYNAVALTIER2FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY UEF STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0301/UEB0301_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY UEF MOBILE LAND",
"BUILTBYLANDTIER3FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY UEF STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "ueb0301" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0302/UEB0302_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ UnitBlueprint{
"TRANSPORTBUILTBYTIER3FACTORY UEF MOBILE AIR",
"BUILTBYAIRTIER3FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY UEF STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "ueb0302" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/UEB0303/UEB0303_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY UEF MOBILE NAVAL",
"BUILTBYNAVALTIER3FACTORY UEF MOBILE CONSTRUCTION",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY UEF STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0101/URB0101_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY CYBRAN STRUCTURE LAND",
"BUILTBYTIER1FACTORY CYBRAN MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY CYBRAN STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "urb0101" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0102/URB0102_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY CYBRAN MOBILE AIR",
"TRANSPORTBUILTBYTIER1FACTORY CYBRAN MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY CYBRAN STRUCTURE AIR",
},
RebuildBonusIds = { "urb0102" },
StorageEnergy = 0,
StorageMass = 80,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0103/URB0103_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ UnitBlueprint{
"BUILTBYTIER1FACTORY CYBRAN STRUCTURE NAVAL",
"BUILTBYTIER1FACTORY CYBRAN MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER1FACTORY CYBRAN STRUCTURE NAVAL",
},
InitialRallyX = 0,
InitialRallyZ = 10,
RebuildBonusIds = { "urb0103" },
Expand Down
3 changes: 3 additions & 0 deletions units/URB0201/URB0201_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY CYBRAN STRUCTURE LAND",
"BUILTBYTIER2FACTORY CYBRAN MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY CYBRAN STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "urb0201" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0202/URB0202_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY CYBRAN MOBILE AIR",
"TRANSPORTBUILTBYTIER2FACTORY CYBRAN MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY CYBRAN STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "urb0202" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0203/URB0203_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ UnitBlueprint{
"BUILTBYTIER2FACTORY CYBRAN STRUCTURE NAVAL",
"BUILTBYTIER2FACTORY CYBRAN MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER2FACTORY CYBRAN STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0301/URB0301_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY CYBRAN STRUCTURE LAND",
"BUILTBYTIER3FACTORY CYBRAN MOBILE LAND",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY CYBRAN STRUCTURE LAND",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "urb0301" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0302/URB0302_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY CYBRAN MOBILE AIR",
"TRANSPORTBUILTBYTIER3FACTORY CYBRAN MOBILE AIR",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY CYBRAN STRUCTURE AIR",
},
DifferentialUpgradeCostCalculation = true,
RebuildBonusIds = { "urb0302" },
StorageEnergy = 0,
Expand Down
3 changes: 3 additions & 0 deletions units/URB0303/URB0303_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ UnitBlueprint{
"BUILTBYTIER3FACTORY CYBRAN STRUCTURE NAVAL",
"BUILTBYTIER3FACTORY CYBRAN MOBILE NAVAL",
},
UpgradeOnlyCategory = {
"BUILTBYTIER3FACTORY CYBRAN STRUCTURE NAVAL",
},
DifferentialUpgradeCostCalculation = true,
InitialRallyX = 0,
InitialRallyZ = 10,
Expand Down
Loading