Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce various transport and carrier callbacks #4921

Merged
merged 3 commits into from
May 18, 2023
Merged
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
68 changes: 68 additions & 0 deletions lua/aibrains/platoons/platoon-base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,74 @@ AIPlatoon = Class(moho.platoon_methods) {
OnShieldDisabled = function(self, unit)
end,

--- Called as a unit (with transport capabilities) of this platoon attached a unit to itself
---@param self AIPlatoon
---@param transport Unit
---@param attachBone Bone
---@param attachedUnit Unit
OnTransportAttach = function(self, transport, attachBone, attachedUnit)
end,

--- Called as a unit (with transport capabilities) of this platoon deattached a unit from itself
---@param self AIPlatoon
---@param transport Unit
---@param attachBone Bone
---@param deattachedUnit Unit
OnTransportDetach = function(self, transport, attachBone, deattachedUnit)
end,

--- Called as a unit (with transport capabilities) of this platoon aborts the a transport order
---@param self AIPlatoon
---@param transport Unit
OnTransportAborted = function(self, transport)
end,

--- Called as a unit (with transport capabilities) of this platoon initiates the a transport order
---@param self AIPlatoon
---@param transport Unit
OnTransportOrdered = function(self, transport)
end,

--- Called as a unit is killed while being transported by a unit (with transport capabilities) of this platoon
---@param self AIPlatoon
---@param transport Unit
OnAttachedKilled = function(self, transport, attached)
end,

--- Called as a unit (with transport capabilities) of this platoon is ready to load in units
---@param self AIPlatoon
---@param transport Unit
OnStartTransportLoading = function(self, transport)
end,

--- Called as a unit (with transport capabilities) of this platoon is done loading in units
---@param self AIPlatoon
---@param transport Unit
OnStopTransportLoading = function(self, transport)
end,

--- Called as a unit (with carrier capabilities) of this platoon has a change in storage
---@see `OnAddToStorage` and `OnRemoveFromStorage` for the unit in question
---@param self AIPlatoon
---@param carrier Unit
---@param loading boolean
OnStorageChange = function(self, carrier, loading)
end,

--- Called as a unit (with carrier capabilities) of this platoon adds a unit to its storage
---@param self AIPlatoon
---@param carrier Unit
---@param unit Unit
OnAddToStorage = function(self, carrier, unit)
end,

--- Called as a unit (with carrier capabilities) of this platoon removes a unit from its storage
---@param self AIPlatoon
---@param carrier Unit
---@param unit Unit
OnRemoveFromStorage = function(self, carrier, unit)
end,

-----------------------------------------------------------------
-- hooks

Expand Down
91 changes: 77 additions & 14 deletions lua/defaultunits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2267,8 +2267,6 @@ BaseTransport = ClassSimple {
unit.attachmentBone = i
end
end

unit:OnAttachedToTransport(self, attachBone)
end,

---@param self BaseTransport
Expand All @@ -2279,7 +2277,6 @@ BaseTransport = ClassSimple {
self:RequestRefreshUI()
self.slots[unit.attachmentBone] = nil
unit.attachmentBone = nil
unit:OnDetachedFromTransport(self, attachBone)
end,

-- When one of our attached units gets killed, detach it
Expand All @@ -2298,12 +2295,10 @@ BaseTransport = ClassSimple {
self:GetAIBrain().loadingTransport = self
end,

---comment
---@param ... BaseTransport
OnStopTransportLoading = function(...)
---@param self BaseTransport
OnStopTransportLoading = function(self)
end,

---comment
---@param self BaseTransport
DestroyedOnTransport = function(self)
end,
Expand Down Expand Up @@ -2338,20 +2333,50 @@ BaseTransport = ClassSimple {
--- Base class for air transports.
---@class AirTransport: AirUnit, BaseTransport
AirTransport = ClassUnit(AirUnit, BaseTransport) {
---@param self AirTransport
OnCreate = function(self)
AirUnit.OnCreate(self)
self.slots = {}
self.transData = {}
end,

---@param self AirTransport
---@param attachBone Bone
---@param unit Unit
OnTransportAttach = function(self, attachBone, unit)
AirUnit.OnTransportAttach(self, attachBone, unit)
BaseTransport.OnTransportAttach(self, attachBone, unit)
end,

---@param self AirTransport
OnTransportAborted = function(self)
---@param attachBone Bone
---@param unit Unit
OnTransportDetach = function(self, attachBone, unit)
AirUnit.OnTransportDetach(self, attachBone, unit)
BaseTransport.OnTransportDetach(self, attachBone, unit)
end,

OnAttachedKilled = function(self, attached)
AirUnit.OnAttachedKilled(self, attached)
BaseTransport.OnAttachedKilled(self, attached)
end,

---@param self AirTransport
OnTransportOrdered = function(self)
OnStartTransportLoading = function(self)
AirUnit.OnStartTransportLoading(self)
BaseTransport.OnStartTransportLoading(self)
end,

---@param self AirTransport
OnCreate = function(self)
AirUnit.OnCreate(self)
self.slots = {}
self.transData = {}
OnStopTransportLoading = function(self)
AirUnit.OnStopTransportLoading(self)
BaseTransport.OnStopTransportLoading(self)
end,

---@param self AirTransport
DestroyedOnTransport = function(self)
-- AirUnit.DestroyedOnTransport(self)
BaseTransport.DestroyedOnTransport(self)
end,

---@param self AirTransport
Expand Down Expand Up @@ -2586,8 +2611,46 @@ SeaUnit = ClassUnit(MobileUnit){
}

--- Base class for aircraft carriers.
---@class AircraftCarrier : SeaUnit
---@class AircraftCarrier : SeaUnit, BaseTransport
AircraftCarrier = ClassUnit(SeaUnit, BaseTransport) {
---@param self AircraftCarrier
---@param attachBone Bone
---@param unit Unit
OnTransportAttach = function(self, attachBone, unit)
SeaUnit.OnTransportAttach(self, attachBone, unit)
BaseTransport.OnTransportAttach(self, attachBone, unit)
end,

---@param self AircraftCarrier
---@param attachBone Bone
---@param unit Unit
OnTransportDetach = function(self, attachBone, unit)
SeaUnit.OnTransportDetach(self, attachBone, unit)
BaseTransport.OnTransportDetach(self, attachBone, unit)
end,

OnAttachedKilled = function(self, attached)
SeaUnit.OnAttachedKilled(self, attached)
BaseTransport.OnAttachedKilled(self, attached)
end,

---@param self AircraftCarrier
OnStartTransportLoading = function(self)
SeaUnit.OnStartTransportLoading(self)
BaseTransport.OnStartTransportLoading(self)
end,

---@param self AircraftCarrier
OnStopTransportLoading = function(self)
SeaUnit.OnStopTransportLoading(self)
BaseTransport.OnStopTransportLoading(self)
end,

---@param self AircraftCarrier
DestroyedOnTransport = function(self)
-- SeaUnit.DestroyedOnTransport(self)
BaseTransport.DestroyedOnTransport(self)
end,

---@param self AircraftCarrier
---@param instigator Unit
Expand Down
Loading