Work on relay algorthm

This commit is contained in:
2024-05-19 01:28:31 -04:00
parent 32f21862a5
commit 1cc658c330

View File

@@ -5,11 +5,12 @@
local RelayAlgorithm = {}
RelayAlgorithm.__index = RelayAlgorithm
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes)
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes, DoorAttributes)
return setmetatable({
BoxAlignPosition = BoxAlignPosition,
Attributes = ElevatorAttributes,
FloorQueue = {}
BoxAlignPosition = BoxAlignPosition,
ElevatorAttributes = ElevatorAttributes,
DoorAttributes = DoorAttributes,
__FloorQueue = {}
}, RelayAlgorithm)
end
@@ -33,27 +34,27 @@ end
[4] = 1
}
]]
function RelayAlgorithm:SortQueue(ElevatorGoingUp)
table.sort(self.FloorQueue, function(a: number, b: number): boolean
function RelayAlgorithm:Sort(ElevatorGoingUp)
table.sort(self.__FloorQueue, function(a: number, b: number): boolean
if ElevatorGoingUp then
return a<b
else
return a>b
end
end)
print(table.unpack(self.FloorQueue))
print(table.unpack(self.__FloorQueue))
end
function RelayAlgorithm:CheckQueue()
if self.FloorQueue[1] == self.Attributes.CurrentFloor.Value then
table.remove(self.FloorQueue, 1)
function RelayAlgorithm:Check(ElevatorGoingUp)
if self.__FloorQueue[1] == self.ElevatorAttributes.CurrentFloor.Value then
table.remove(self.__FloorQueue, 1)
end
if #self.FloorQueue ~= 0 then
local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, self.FloorQueue[1])
self.Attributes.GoingUp.Value = ElevatorGoingUp
if #self.__FloorQueue ~= 0 then
--local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, self.__FloorQueue[1])
--self.Attributes.GoingUp.Value = ElevatorGoingUp
self:SortQueue(self, ElevatorGoingUp)
--self:__GoToFloor(Leveling[self.FloorQueue[1]], ElevatorGoingUp)
self:SortQueue(ElevatorGoingUp)
--self:__GoToFloor(Leveling[self.__FloorQueue[1]], ElevatorGoingUp)
return true
end
@@ -61,33 +62,25 @@ function RelayAlgorithm:CheckQueue()
return false
end
function RelayAlgorithm:Insert(ElevatorGoingUp, RequestedLevel)
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
self:SortQueue(ElevatorGoingUp)
end
function RelayAlgorithm:Proceed(ElevatorGoingUp, RequestedLevel)
self:Insert(RequestedLevel, ElevatorGoingUp)
return self.ElevatorAttributes.GoingUp.Value and not self.DoorAttributes.DoorsOpen.Value
end
--[==[
local function CheckQueue(self: ClassConstructor)
if self.FloorQueue[1] == Attributes.CurrentFloor.Value then
table.remove(self.FloorQueue, 1)
end
if #self.FloorQueue ~= 0 then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, self.FloorQueue[1])
Attributes.GoingUp.Value = ElevatorGoingUp
SortQueue(self, ElevatorGoingUp)
self:__GoToFloor(Leveling[self.FloorQueue[1]], ElevatorGoingUp)
end
end
local function InsertFloorQueue(self: ClassConstructor, RequestedLevel: number, ElevatorGoingUp: boolean)
table.insert(self.FloorQueue, ElevatorGoingUp == Attributes.GoingUp.Value and 1 or #self.FloorQueue+1, RequestedLevel)
SortQueue(self, ElevatorGoingUp)
end
local function ToFloorQueue(self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number, GoalLevelVEC: number)
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
InsertFloorQueue(self, RequestedLevel, ElevatorGoingUp)
if ElevatorGoingUp == Attributes.GoingUp.Value and not Doors.Attributes.DoorsOpen.Value then
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, self.FloorQueue[1], ElevatorBoxCurrentPos.Z)
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, self.__FloorQueue[1], ElevatorBoxCurrentPos.Z)
end
end