Shard 0.4/dev - Page 17

Shard 0.4/dev

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.31.1 Not So Ballsey

Post by AF »

An experimental MorphInto method has also been added to the engine unit object, it takes a unit type object as a parameter and returns true/false.

It's assumed the Morphing implementation takes the command ID 32210 and takes the unit definition ID as its first parameter. Thanks to Knorke for the help.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.31.1 Not So Ballsey

Post by AF »

Here's 0.35RC1

http://www.darkstars.co.uk/downloads/vi ... d0.35RC.7z

This is built from git master, so it includes a raft of stability fixes and safeguards, the things I mentioned in the previous posts, and a lot of other small changes and architectural improvements.

Please use this build if you're developing with Shard or using it for your game, so that I can iterate quickly in the coming days.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

GetMapFeatures() does not work:
[i called: game.map:GetMapFeatures() and map:GetMapFeatures() neither works]

Code: Select all

[f=0000500] <SkirmishAI: Shard 0.35RC (team 1)>: Wrong arguments for overloaded function 'IMap_GetMapFeatures'
  Possible C/C++ prototypes are:
    IMap::GetMapFeatures()
    IMap::GetMapFeatures(Position,double)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

Oh dear =( I will look into this when I get home.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

Can you verify it used to work and doesn't now? ( and not that it never worked ), also does GetUnits work?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

Nevermind I've cleared up the ambiguity

There's now:

map:GetMapFeaturesAt
game:GetResourceByName

Redownload via the same link and extract over the top
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

When calling that function:

Code: Select all

local features = map:GetMapFeaturesAt(pos,5000)
it results in:

Code: Select all

[f=0000500] <SkirmishAI: Shard 0.35RC (team 1)>: ...\_Spring\AI\Skirmish\Shard\0.35RC\ai\preload\api.lua:174: attempt to index local 'fv' (a userdata value)
stack traceback:
	[C]: ?
	[C]: ?
still does not work .-.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

In api.lua replace it with:

Code: Select all

	function map:GetMapFeaturesAt(position,radius)
		local m = game_engine:Map()
		local fv = m:GetMapFeaturesAt(position,radius)
		local f = {}
		local i = 0
		if fv:empty() then
			fv = nil
			return nil
		else
			while i  < fv:size() do
				table.insert(f,fv[i])
				i = i + 1
			end
			fv = nil
			return f
		end
	end
My theory at the moment is that it could not handle the API returning no units. If true I'll modify the other functions accordingly, but I'm at work so I can't test atm
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

nope thats not it, i tried by grabbing all features on the map which has plenty of them. The error should be somwhere within the function since it has to do with the variable fv which is not even returned.


Also it would be really usefull to have not only a list of all functions that are available but also some example calls as there are some non intuitive things there.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by hoijui »

best thing to do if a call seems unintuitive to you, is to find out how it works yourself, and document it on your fork of spring on github, in this file:
https://github.com/spring/spring/blob/3 ... Callback.h

... that applies to calls from the spring AI Interface callback only, of course.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

fv is a C++ object wrapped by swig and then insulated via that proxy function so that what is returned is a pure lua table.

To be precise the fv object is of type std::vector<IMapFeature*>

My fix above works under the premise that iterating on an empty C++ STL container is never a good idea
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

Code: Select all

std::vector<IMapFeature*> CSpringMap::GetMapFeaturesAt(Position p, double radius){
	SAIFloat3 pos;
	pos.x = p.x;
	pos.y = p.y;
	pos.z = p.z;
	std::vector< IMapFeature*> mapFeatures;

	std::vector<springai::Feature*> features = callback->GetFeaturesIn(pos,radius);
	std::vector<springai::Feature*>::iterator i = features.begin();
	for(;i != features.end(); ++i){
		CSpringMapFeature* f = new CSpringMapFeature(callback,*i,game);
		mapFeatures.push_back(f);
	}
	return mapFeatures;
}
Is the implementation on the C++ side.

Can I see the code you're using to make the call to map:GetMapFeaturesAt() ?

My only other suggestion so far is to replace:

Code: Select all

table.insert(f,fv[i])
with

Code: Select all

table.insert(f,fv:at(i))
and to create a position:

Code: Select all

p = api.Position()
p.x = 0
p.y = 0
p.z = 0
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

I just called the function and assigned it to a new local variable, the same way it is done with "GetEnemies" in "attackhandler.lua".
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

So you're not passing any parameters in?
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

I tried with parameters and without neither worked
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

Can you send me your setup so I can debug without going back and forth?
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by Erik »

there you go
Attachments
0.35RC.7z
(339.38 KiB) Downloaded 15 times
SSvO
Posts: 10
Joined: 07 Oct 2011, 16:15

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by SSvO »

Hello all,

I'm new to the Forum, but have played Spring for the last 3 or 4 years,
and now i decide to write my own BA config for Shard, but i have a serious Problem:

My LUA skills are Bad... :cry:

I need your Help.

For my Build units i try to check how much units from a specific Typ are aleready build. (i.e. How many Solar Collectors are build)
Is there a way to count all units and see how many of them are Solar Collectors?
I Try fiddling arround with game:GetUnits, but i dont realy understand how it works. I am able to count all Units, but how can i find out how many are Solar Collectors

I have read through the Whole Thread, and looked into other Shard Config files, but i dont get it... :cry:

Maybe someone can explain it to me? In this Thread or via PN...

P.S. Sorry for my Bad englisch :oops:
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by AF »

The way I would reccomend is:
  • Add an empty module
  • This module will have a table such that tableobject[unittype] = XofThisType
  • Everytime a unit of yours is built, increment the number
  • Decrement on unit death
  • To get the number of units for say a corsolar, all you would need to do now is local solarCount = tableobject["corsolar"] or something similar.
We currently have something similar to this already to count factories for evo, and I'm thinking this is such a nice example of a module I'll probably write up a tutorial when I get home ( yay ). The code Erik posted above has 2 behaviours that do the same thing, basically acting as tags on a unit and doing nothing more than incrementing and decrementing a number on creation and death.

AttackBehaviour also does very little too, when an attack is built, it says to the Attack Handler, I'm here, and waits. It does this every time the attack is idle.

All in all you should be able to go quite far with just modifying taskqueues for BA, but there are a lot of primitive simple behaviours that will help a lot.
SSvO
Posts: 10
Joined: 07 Oct 2011, 16:15

Re: Shard 0.35RC1 & 0.31.1 Not So Ballsey

Post by SSvO »

Hi AF,

first of all i have to Thank you for your great AI.
I played al lot of games against NTai a few years ago, but Shard is much better, i think. :-)

I hope i can follow your instructions... :shock:

I have seen the 'Unit Inventory' stuff in the EvoRTS Config, but it seems very complex. (for me) I will try modify that functions for my BA Config if no one is angainst that.

Ah, and thanks for the quick Reply.
Post Reply

Return to “AI”