NTai is evolved code, Shard has a defined structure and design.
NTai still has a lot more in it, if you look back at it you can find many little tricks and behaviours you can steal to make your version of Shard even better!
As a sidenote, if you build your own configs for say BA or Evo that differ from those in the standard distribution, maybe you've decided to take a different approach, I'm perfectly happy for you to release it as a separate AI alongside Shard with a new name, as long as you keep it up to date and make it quite clear it's based on Shard.
function UnitTypeCounter:Name() return "UnitTypeCounter" end
function UnitTypeCounter:internalName() return "TypeCounter" end
function UnitTypeCounter:Init() self.typeCount = {} end
function UnitTypeCounter:UnitCreated(engineunit) if engineunit:Team() == game:GetTeamID() then local t = engineunit:Type() local name = t:Name() local count = 0 if self.typeCount[name] ~= nil count = self.typeCount[name] end self.typeCount = count + 1 end end
function UnitTypeCounter:UnitBuilt(engineunit)
end
function UnitTypeCounter:UnitDead(engineunit) if engineunit:Team() == game:GetTeamID() then local t = engineunit:Type() local name = t:Name() local count = 0 if self.typeCount[name] ~= nil count = self.typeCount[name] end self.typeCount = count - 1 end end
Put in a file UnitTypeCounter.lua, and include it in modules.lua which is straight forward. Add it to the table which is just a comma separated list, and add in the file at the top with the others
if unit:Internal():ID() == self.unit:Internal():ID() then
It's faster/quicker to use:
Code:
if unit.engineID == self.unit.engineID then
Also remember to check if the unit is actually on your team if your listening out for a unit in a behaviour other than the unit it belongs to, as it may not be one of Shards units.
Code:
if engineunit:Team() == game:GetTeamID() then
RC2 contains various fixes regarding this check, it appears past versions of Shard added taskqueue behaviours etc to Shards units AND the players units. I've also renamed parameters in some places from unit to engineunit to make it clearer the distinction ( specifically attackhandler )
I've fixed the map features API, I've also fixed some logic errors in the auto reclaim behaviour and included it, however, at the moment I cannot get area reclaim to work. Individual reclaiming of features works however.
I suspect I need to build Shard with a newer version of the C++ Wrapper, but none is provided in the source download, and I'm incapable of generating one by myself ( I've spent hours trying via CMake under windows with little or no progress )
The alternative is to just figure out which features are the closest and then add them to a queue of features to reclaim. You'd need to modify the behaviour though to follow the new logic
The behaviour will make the unit reclaim the feature at the front of the queue when idle and elect a new behaviour when the queue is empty.
On Update at regular intervals, it will search the local viscinity of say 1000 for features. If none are found do a wider search for the nearest feature and tell the builder to reclaim it.
[f=0000006] Skirmish AI "Bot1" took over control of team 0 [f=0000147] <SkirmishAI: Shard 3.0 (team 0)>: Error in IGame::GetResource (arg 2), expected 'int' got 'string' stack traceback: [C]: ? [C]: ? [C]: in function 'GetResource' D:\Spring\AI\Skirmish\Shard\3.0\ai\preload\api.lua:114: in function 'GetResource' ...\Skirmish\Shard\3.0\ai\EvoRTS\lowenergybehaviour.lua:16: in function 'UnitIdle' D:\Spring\AI\Skirmish\Shard\3.0\ai\unit.lua:72: in function 'UnitIdle' D:\Spring\AI\Skirmish\Shard\3.0\ai\unithandler.lua:97: in function 'UnitIdle' D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:85: in function <D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:75>
[f=0004249] <SkirmishAI: Shard 3.0 (team 0)>: ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:120: attempt to index field 'unit' (a nil value) stack traceback: [C]: ? [C]: ? ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:120: in function 'ProgressQueue' ...ring\AI\Skirmish\Shard\3.0\ai\taskqueuebehaviour.lua:110: in function 'wakeup' D:\Spring\AI\Skirmish\Shard\3.0\ai\sleep.lua:44: in function 'Wakeup' D:\Spring\AI\Skirmish\Shard\3.0\ai\sleep.lua:19: in function 'Update' D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:32: in function <D:\Spring\AI\Skirmish\Shard\3.0\ai\ai.lua:24>
Try the attached version, I'm not in a position to test at the moment, so if it doesn't work or there's a silly syntax error please post any fixes or missing commas or brackets you find.
Basically I've added a check to see if the unit is still alive, and cleaned up after the waiting objects.
There was also the chance that a wait command would never be cancelled on a units death because the task behaviour never kept track of it properly so it wouldn't kill the wait on unit death. Leading to the error when it tried to progress the taskqueue on a dead unit, meaning it would never be removed, and it would repeat the following frame leading to yet another stack trace.
I can't further diagnose the issue until I know the context of that call.
I'd also keep to the convention of unit vs engineunit. One is the AIs representation of an API object, the other IS an API object. I'd also avoid chaining commands like that as it makes it harder to debug which operation is at fault
Try the attached dll, it's been rebuilt with newer cpp wrapper bindings, I can't vouch for whether it fixed reclaiming however also, make sure you check if the unit is your own unit, and not an enemy unit
Unit Destroyed means a unit was destroyed, not your unit was destroyed, it's up to you to double check these things while I track down any holes for bad values to seep through. ( and its important you let me know the logic path so I know where to look for these things to see if I can help )
I'd also keep to the convention of unit vs engineunit. One is the AIs representation of an API object, the other IS an API object. I'd also avoid chaining commands like that as it makes it harder to debug which operation is at fault
I have no idea how, perhaps you could supply some example calls because its pretty hard to derive working calls from nothing.
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