View topic - Lua Gadget: Detect what a builder was building when it died?



All times are UTC + 1 hour


Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 11 Jul 2011, 19:58 

Joined: 10 Jul 2009, 22:34
So I've been helping out with the Lua AI for Conflict Terra. And I need a way to detect what (if anything) a constructor unit was building when it dies (perhaps in the gadget:unitDestroyed function?), so that it's job can be rescheduled to another builder.


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 20:03 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
unitID_that_unit_is_building = Spring.GetUnitIsBuilding (unitID)


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 20:18 

Joined: 10 Jul 2009, 22:34
knorke wrote:
unitID_that_unit_is_building = Spring.GetUnitIsBuilding (unitID)


so, unitID_that_unit_is_building is the ID of the unit (still in nanoframe ) that (fully alive) unit unitID is building , right?

Does this still count if the builder is walking to the buildsite and has not yet started on the structure?


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 20:21 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
yanom wrote:
knorke wrote:
unitID_that_unit_is_building = Spring.GetUnitIsBuilding (unitID)


so, unitID_that_unit_is_building is the ID of the unit (still in nanoframe ) that (fully alive) unit unitID is building , right?


Yes.

Quote:
Does this still count if the builder is walking to the buildsite and has not yet started on the structure?


No. For that, you'll have to grab the command queue of the destroyed unit, and loop over it looking for build commands.


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 20:55 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
Since it is for an AI, you might find it simpler to store in table when the order is given, and check that table when it dies.

Like:

local BuilderOnMission={} -- table indexed by unitID
local DoItAgain={} -- table indexed by 1...n

...

function gadget:GameFrame(n)
...
Spring.GiveOrderToUnit(...
BuilderOnMission[UnitID]={some data that will help you know what and where it was building, like the cmd id and cmd parameters}
...
for Index,OrderToGiveAgain in ipairs(DoItAgain) do
-- type here some code to find a suitable builder and reissue order
...
table.remove(OrderToGiveAgain,index)
...
end
end



function gadget:UnitDestroyed(...
if BuilderOnMission[UnitID] then
table.insert(DoItAgain)=BuilderOnMission[UnitID]
BuilderOnMission[UnitID]=nil
end
end


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 21:26 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
yes, what zwzsg said.
also because GetUnitIsBuilding will probally fail on morphing/cloneing.


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 21:27 

Joined: 10 Jul 2009, 22:34
FLOZi wrote:
No. For that, you'll have to grab the command queue of the destroyed unit, and loop over it looking for build commands.


how do I do that?


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 21:54 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
You don't. Do it the way zwzsg suggested, it's a much better implementation.


Top
 Offline Profile  
 
PostPosted: 11 Jul 2011, 23:51 

Joined: 10 Jul 2009, 22:34
... this is beyond me.

I've never programmed much before.

But I'll keep trying...


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.