-
Notifications
You must be signed in to change notification settings - Fork 215
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
First draft of economist AI, still a lot to do #4837
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loose thoughts from briefly skimming the file
local minEffectiveDist = 9999999 | ||
local bestPylon = -1 | ||
local bestPylonRange = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave nil
if there's no good value; also use math.huge
:
local minEffectiveDist = 9999999 | |
local bestPylon = -1 | |
local bestPylonRange = -1 | |
local minEffectiveDist = math.huge | |
local bestPylon | |
local bestPylonRange |
local minEffectiveDist = 9999999 | ||
local bestPylon = -1 | ||
local bestPylonRange = -1 | ||
for _, gridPylonData in ipairs(gridMates) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer a normal loop over ipairs
(much faster):
for _, gridPylonData in ipairs(gridMates) do | |
for i = 1, #gridMates do | |
local gridPylonData = gridMates[i] |
function GG.SetPriorityState(unitID, state) | ||
SetPriorityState(unitID, state, CMD_PRIORITY) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the use of this func should be replaced by some sort of Spring.GiveOrderToUnit(unitId, CMD_PRIORITY, state, 0)
if not gadgetHandler:IsSyncedCode() then | ||
return | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The synced code check should be at the very top of the gadget.
------------------------------------------------------------ | ||
-- Debug | ||
------------------------------------------------------------ | ||
local function printThing(theKey, theTable, indent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something like Spring.Utilities.TableEcho
(or maybe EchoTable
?), use it
if next(teamdata) == nil then | ||
initializeTeams() | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would ideally be done once, likely in Initialize
, instead of in half the callins
end | ||
end | ||
end | ||
if frame%5 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This produces a number so is always a truthy value.
spGiveOrderToUnit(unitId, -conjurerDefID, {}, {}) | ||
spGiveOrderToUnit(unitId, 115, {1}, {}) -- repeat build | ||
spGiveOrderToUnit(unitId, 34220, {0}, {}) -- priority low |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer named order constants over magic numbers, table-less parameters when there's a single one, and numerical command options:
spGiveOrderToUnit(unitId, -conjurerDefID, {}, {}) | |
spGiveOrderToUnit(unitId, 115, {1}, {}) -- repeat build | |
spGiveOrderToUnit(unitId, 34220, {0}, {}) -- priority low | |
spGiveOrderToUnit(unitId, -conjurerDefID, 0, 0) | |
spGiveOrderToUnit(unitId, CMD.REPEAT, 1, 0) -- repeat build | |
spGiveOrderToUnit(unitId, CMD_PRIORITY, 0, 0) -- priority low |
if current > 200 then | ||
spGiveOrderToUnit(unitId, 13921, {1}, {}) | ||
else | ||
spGiveOrderToUnit(unitId, 13921, {0}, {}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto:
if current > 200 then | |
spGiveOrderToUnit(unitId, 13921, {1}, {}) | |
else | |
spGiveOrderToUnit(unitId, 13921, {0}, {}) | |
end | |
spGiveOrderToUnit(unitId, CMD_FACTORY_GUARD, current > 200 and 1 or 0, 0) |
|
||
local function updateRoleList(teamData) | ||
for unitId,role in pairs(teamData.conRoles) do | ||
if spGetUnitIsDead ( unitId ) == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this belongs in gadget:UnitDestroyed
TODO: