Page 1 of 1

addStructure() in an AI script

Posted: 03 Dec 2012, 11:41
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?

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 13:20
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? (:

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 15:00
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?

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 15:38
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.

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 18:01
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.

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 19:11
by aubergine
addStructure() returned false

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 20:26
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.

Re: addStructure() in an AI script

Posted: 03 Dec 2012, 21:55
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?