Shard 0.4/dev
Moderators: hoijui, Moderators
Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey
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.
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.
Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey
Something along these lines:
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
Code: Select all
UnitTypeCounter = class(Module)
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
Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey
As a note for those with existing code.
Where you see this:
It's faster/quicker to use:
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.
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 )
Where you see this:
Code: Select all
if unit:Internal():ID() == self.unit:Internal():ID() then
Code: Select all
if unit.engineID == self.unit.engineID then
Code: Select all
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 )
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
http://www.darkstars.co.uk/downloads/vi ... 0.35RC2.7z
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 )
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 )
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
No area reclaim makes me a sad panda.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
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.
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.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Normal reclaim order seems to have no effect aswell.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
=/
I'll have to see about sourcing a new C++ wrapper from someone
For reference here are the two C++ methods, if anyone can see something wrong below let me know:
I'll have to see about sourcing a new C++ wrapper from someone
For reference here are the two C++ methods, if anyone can see something wrong below let me know:
Code: Select all
bool CSpringUnit::Reclaim(IMapFeature* mapFeature){
SReclaimUnitCommand c;
c.unitId = this->unit->GetUnitId();
c.toReclaimUnitIdOrFeatureId = mapFeature->ID();
int e = callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_UNIT_RECLAIM,&c);
return (e == 0);
}
bool CSpringUnit::AreaReclaim(Position p, double radius){
SReclaimAreaUnitCommand c;
c.unitId = this->unit->GetUnitId();
c.radius = radius;
SAIFloat3 pos;
pos.x = p.x;
pos.y = p.y;
pos.z = p.z;
c.pos = pos;
int e = callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_UNIT_RECLAIM_AREA,&c);
return (e == 0);
}
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Error:
http://pastebin.com/PWtSZfxx << Infolog
Relevant bits:
http://pastebin.com/PWtSZfxx << Infolog
Relevant bits:
Code: Select all
[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>
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Use game:GetResourceByName instead of game:GetResource
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
http://pastebin.com/zhE6KQK1
Code: Select all
[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>
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
I assume you're using the wait command? Quickfix is to remove waiting while I summon up a quickfix for waiting
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
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.
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.
- Attachments
-
- taskqueuebehaviour.lua
- (3.81 KiB) Downloaded 103 times
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Linux .so, untested, built using spring 0.82.7.1 under a Ubuntu 11.10 VM
- Attachments
-
- libSkirmishAI.zip
- (1.23 MiB) Downloaded 14 times
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Does the reclaim work for you by now? I can't get it to work, neither single feature reclaim nor area reclaim
yields
What am I doing something wrong? It works in notsoballsey version.
Code: Select all
self.unit:Internal():Reclaim(feat[target])
Code: Select all
[f=0001113] <SkirmishAI: Shard 0.35RC2 (team 1)>: ...sh\Shard\0.35RC\ai\Void\builderregisterbehaviour.lua:8: attempt to call method 'Internal' (a nil value)
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
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
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
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
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 )
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 )
- Attachments
-
- SkirmishAI.7z
- (332.56 KiB) Downloaded 17 times
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Context
Code: Select all
function AutoReclaimBehaviour:Update()
local f = game:Frame()
if math.mod(f,500) == 0 then
game:SendToConsole("updating collector targets ------------")
pos = self.unit:Internal():GetPosition()
local feat = map:GetMapFeaturesAt(pos,50000)
local Eval = {}
if #feat > 0 then
for i=1,#feat do
local e = feat[i]
posf = e:GetPosition()
if (e:ResourceValue(0)>0) then --check for metal
--Formula(Distance^2)
local dist= math.sqrt((posf.x-pos.x)*(posf.x-pos.x) +(posf.z-pos.z)*(posf.z-pos.z))
Eval[i]=dist
else
Eval[i]=1000000
end--check for metal
end
end --loop over features
game:SendToConsole("now evaluating table")
local rec_targ=1
local rec_val=1000000
for i=1,#feat do
if (Eval[i]<rec_val) then
rec_targ=i
rec_val=Eval[i]
end
end --loop over table
game:SendToConsole("done evaluating winner is:")
game:SendToConsole(rec_targ)
game:SendToConsole("with value")
game:SendToConsole(rec_val)
self.unit:Internal():Reclaim(feat[rec_targ])
end --#feat > 0
end
I have no idea how, perhaps you could supply some example calls because its pretty hard to derive working calls from nothing.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
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Hmmm this is not based on the near working auto reclaim behaviour in the 0.35rc2 download?
Your code even if it works would send the unit off reclaiming every 500 frames regardless of what it's currently doing.
Your also not checking to see if the unit belongs to your AI
As for chaining commands
Versus
Your code even if it works would send the unit off reclaiming every 500 frames regardless of what it's currently doing.
Your also not checking to see if the unit belongs to your AI
As for chaining commands
Code: Select all
Self.unit:Internal()Reclaim(feat[x])
Code: Select all
Local unit = self.unit
Local engineunit = unit:Internal()
If engineunit ~= nil then
Local feature = feat[x]
Engineunit:Reclaim(feature)
End
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
That is intended.Your code even if it works would send the unit off reclaiming every 500 frames regardless of what it's currently doing.
Reclaim commands as such are not working neither area nor single feature.