mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
parallel node bugfixes
code cleanup
This commit is contained in:
@@ -151,24 +151,16 @@ function Player:startHarvesting()
|
||||
end
|
||||
end
|
||||
|
||||
extractors = self:getUnitsByClass(UnitClass.EXTRACTOR, 1)
|
||||
if #extractors == 0 then return BTNodeResult.FAILURE end
|
||||
extractor = self:getUnitsByClass(UnitClass.EXTRACTOR, 1)[1]
|
||||
if not extractor then return BTNodeResult.FAILURE end
|
||||
|
||||
self:deselectUnits()
|
||||
self:selectUnits({harvesters[1]})
|
||||
self:issueOrder(7, Vector3:new(0, 0, 0), {Target:new(extractors[1], Vector3:new(0, 0, 0))}, false)
|
||||
self:issueOrder(7, Vector3:new(0, 0, 0), {Target:new(extractor, Vector3:new(0, 0, 0))}, false)
|
||||
|
||||
return BTNodeResult.SUCCESS
|
||||
end
|
||||
|
||||
function Player:buildTaskforceUnitGroup(numUnits, currNumUnits, factory, buId)
|
||||
if currNumUnits < numUnits then
|
||||
for i = 1, numUnits - currNumUnits do
|
||||
factory:appendToQueue(buId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Player:buildTaskForces(arguments)
|
||||
landFactory = self:getUnitsByClass(UnitClass.LAND_FACTORY, 1)[1]
|
||||
|
||||
@@ -207,7 +199,6 @@ end
|
||||
|
||||
function Player:formTaskForce(arguments)
|
||||
if self.taskForces[arguments.tfId] then return BTNodeResult.SUCCESS end
|
||||
--elseif arguments.spId == self:getSpawnPointId() + 1 then return BTNodeResult.FAILURE
|
||||
|
||||
unitGroups = {}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ for i = 1, #game.players do
|
||||
{type = BTNodeType.FUNCTION, func = 'trainEngineers'},
|
||||
{
|
||||
type = BTNodeType.PARALLEL,
|
||||
numMinSuccesses = 3,
|
||||
children = {
|
||||
{
|
||||
type = BTNodeType.SEQUENCE,
|
||||
@@ -27,7 +26,6 @@ for i = 1, #game.players do
|
||||
},
|
||||
{
|
||||
type = BTNodeType.PARALLEL,
|
||||
numMinSuccesses = 2,
|
||||
children = {
|
||||
{type = BTNodeType.FUNCTION, func = 'buildTaskForces'},
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@ BTNodeType = {SELECTOR = 0, SEQUENCE = 1, PARALLEL = 2, FUNCTION = 3}
|
||||
BTNodeResult = {SUCCESS = 0, RUNNING = 1, FAILURE = 2}
|
||||
|
||||
function executeBtNode(agent, btNode)
|
||||
numParallelSuccesses = 0
|
||||
numParallelRunnings = 0
|
||||
local numParallelSuccesses = 0
|
||||
local numParallelRunnings = 0
|
||||
|
||||
for i = 1, #btNode.children do
|
||||
if btNode.children[i].type == BTNodeType.FUNCTION then
|
||||
@@ -17,13 +17,13 @@ function executeBtNode(agent, btNode)
|
||||
if btNode.type == BTNodeType.SELECTOR then
|
||||
failOnEnd = (i == #btNode.children and res == BTNodeResult.FAILURE)
|
||||
|
||||
if res == BTNodeResult.RUNNING or res == BTNodeResult.SUCCESS or failOnEnd then
|
||||
if res ~= BTNodeResult.FAILURE or failOnEnd then
|
||||
return res
|
||||
end
|
||||
elseif btNode.type == BTNodeType.SEQUENCE then
|
||||
succeedOnEnd = (i == #btNode.children and res == BTNodeResult.SUCCESS)
|
||||
|
||||
if res == BTNodeResult.RUNNING or res == BTNodeResult.FAILURE or succeedOnEnd then
|
||||
if res ~= BTNodeResult.SUCCESS or succeedOnEnd then
|
||||
return res
|
||||
end
|
||||
elseif btNode.type == BTNodeType.PARALLEL then
|
||||
@@ -35,8 +35,15 @@ function executeBtNode(agent, btNode)
|
||||
end
|
||||
|
||||
if i == #btNode.children then
|
||||
if numParallelRunnings > 0 then return BTNodeResult.RUNNING
|
||||
else return numParallelSuccesses <= btNode.numMinSuccesses and BTNodeResult.SUCCESS or BTNodeResult.FAILURE end
|
||||
if numParallelRunnings == 0 then
|
||||
successful = nil
|
||||
|
||||
if numParallelSuccesses == #btNode.children or (btNode.numMinSuccesses and numParallelSuccesses >= btNode.numMinSuccesses) then
|
||||
successful = true
|
||||
end
|
||||
|
||||
return successful and BTNodeResult.SUCCESS or BTNodeResult.FAILURE
|
||||
elseif numParallelRunnings > 0 then return BTNodeResult.RUNNING end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user