addStructure() in an AI script

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

addStructure() in an AI script

Post by aubergine »

I'm doing some unit tests in an AI script where I have a requirement to add a sat uplink to the map but am struggling to get addStructure() to work...

Here's my code (which runs after eventStartLevel):

Code: Select all

		// we will need a sat uplink (in particular for subsequent tests to work)
		var struct = enumStruct(me, SAT_UPLINK);

		if (struct.length) {
			struct = struct[0]; // get first uplink struct
		} else { // need to make us a sat up link!
			// id of sat uplink...
			var satUplink = "A0Sat-linkCentre";
			// find a truck
			var truck = enumDroid(me, DROID_CONSTRUCT)[0];
			hackNetOff();
				// make sure sat uplink is enabled
				enableStructure(satUplink, me);
				// find place to put uplink
				var pos = pickStructLocation(truck, SAT_UPLINK, truck.x, truck.y);
				// place structure
				addStructure(satUplink, me, pos.x, pos.y)
			hackNetOn();
			// get structure object
			struct = enumStruct(me, SAT_UPLINK)[0];
		}
I'm using sk-StartUp map with advanced bases, my AI script is running in position (the base near the scav mountain).

pickStuctLocation() is returning a valid position for the uplink, so it looks like the code is failing when gets to addStructure() but I can't work out why :(

Any ideas?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: addStructure() in an AI script

Post by NoQ »

var pos = pickStructLocation(truck, SAT_UPLINK, truck.x, truck.y);
That's exactly why i have to define what a command center is, instead of using COMMAND in all places in NullBot. What do you think is the tile size of SAT_UPLINK? (:
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: addStructure() in an AI script

Post by aubergine »

I changed that line to read:

Code: Select all

var pos = pickStructLocation(truck, satUplink, truck.x, truck.y);
Where satUplink was defined at the top of the script as "A0Sat-linkCentre"... but still didn't work :(

Maybe addStructure() function only works in rules.js or prior to the game starting?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: addStructure() in an AI script

Post by Shadow Wolf TJC »

I believe that enableStructure() and addStructure() may indeed only work properly in rules.js. You'll probably need to use orderDroidBuild() in your AI script instead.
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: addStructure() in an AI script

Post by Per »

pickStructLocation()'s second parameter must indeed be a string identifier. What is addStructure()'s return value? It can be called from anywhere, but calling it from an AI script will desync the game.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: addStructure() in an AI script

Post by aubergine »

addStructure() returned false
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: addStructure() in an AI script

Post by Per »

I see there is a bug in addStructure() that makes it use map coordinates rather than world coordinates... I will fix it when I get back to my dev box.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: addStructure() in an AI script

Post by aubergine »

Out of interest, what's the difference between those two co-ordinate systems? I've noticed them in the source code but never understood why a map would have two different types of co-ordinate?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply