Page 1 of 1

AI script questions

Posted: 23 Apr 2017, 22:34
by Berserk Cyborg
Working on my AI lately and have some questions:
1. How do I go about finding the component name of a system droid? Most of the time I can just do droid.weapons[x].name to get whatever the name is of the component, but this fails if it has repairs/sensors/command-turret/spade and similar. Would be useful for recycling a sensor for a wide-spectrum sensor or light-repair for heavy-repair turrets.

2. Droids that have a command turret are considered the type DROID_WEAPON instead of DROID_COMMAND. I am experimenting to see if commanders would be useful (only built when the attack group is large enough). Not sure if this is a bug or is intentional.

3. Sometimes I see trucks that spin around in circles forever until they are destroyed or manually moved. This seems to happen almost immediately when something is built next to them and they are moving towards a different target. Any tips on how to stop that?

I may have more questions later.

Re: AI script questions

Posted: 23 Apr 2017, 23:43
by NoQ
1. I'm not sure if it's already uploaded into the in-game stats (see the jsdebug cheat to visualize everything you have). If not, it should be asked for^^ In any case you can look it up in JSON stat files.

2. Dunno. Because nobody has scripted commanders in JS so far, it may be all broken. Script constants may map incorrectly into engine-side enums, or maybe another issue.

3. It's so much better to fix this in the game's pathing/micro-AI than in AI scripts, because humans may be also affected.

Oh well, i guess i wasn't of much help.

Re: AI script questions

Posted: 24 Apr 2017, 00:16
by Per
Unfortunately, a lot of the droid stuff in the code is really, really messy, and sometimes that mess leaks through the API, although I tried to keep the insanity bottled up in the C++ code. System components is one of those things that leak out... They are not weapons, they are components, and as such is currently only available through a droid's template. And a droid's template is not immediately accessible through the droid object - you'll just have to keep track of that yourself at the moment. (It's a mess.)

Commanders should be DROID_COMMAND. I just tested it in the ctrl+o menu, and that info should be passed to the scripts.

I agree that truck spinning should be fixed in the C++ code. Is there some way to reliable reproduce it?

Re: AI script questions

Posted: 24 Apr 2017, 01:19
by Berserk Cyborg
Per wrote:Commanders should be DROID_COMMAND. I just tested it in the ctrl+o menu, and that info should be passed to the scripts.
I only see numbers for the droidType. When I produce a droid with the command turret it is 7. If the AI does it, then the droidType is 0.
Per wrote: I agree that truck spinning should be fixed in the C++ code. Is there some way to reliable reproduce it?
I have not found anything reliable yet. Usually it happens when the truck is close to a corner of the structure blocking it.

Re: AI script questions

Posted: 25 Apr 2017, 23:40
by Per
Berserk Cyborg wrote:
Per wrote:Commanders should be DROID_COMMAND. I just tested it in the ctrl+o menu, and that info should be passed to the scripts.
I only see numbers for the droidType. When I produce a droid with the command turret it is 7. If the AI does it, then the droidType is 0.
How did you create the commander? The API interface for creating droids is a bit messy and incomplete at the moment. It does, for example, not yet support creating repair / sensor droids. Commanders should, in theory at least, work, though.

The addDroid() function is not really up to the task, and so I'm thinking of creating another function that takes an object type instead of tons of function parameters.

Re: AI script questions

Posted: 26 Apr 2017, 17:38
by Berserk Cyborg
Per wrote:How did you create the commander?
I created it in the design menu and from there I spawned them from the add droid tab. They are still considered commanders even if I switch to another player. However, if the AI produces a unit with the command turret from a factory, then it is not considered a commander for whatever reason.

I can confirm that units other than trucks get stuck on structures as well (they just turn left and right slowly trying to go forward). In fact, the same thing happens when two droids try moving past each other, but instead just block each other.

Re: AI script questions

Posted: 16 Jul 2017, 07:09
by Berserk Cyborg
So I am updating my cyborg production code to include combat engineers. Only now I gained access to a terrifying secret "legs only" cyborg. I can order them to attack stuff... their choice of engagement is to try ramming the target.

Not sure why I can't produce the CyborgSpade component.

Code: Select all

function buildCyborg(fac, useEngineer) {
	var weap = "CyborgSpade";
	var body = "CyborgLightBody";
	var prop = "CyborgLegs";

	//Build combat engineer if requested.
	if(isDefined(useEngineer) && (useEngineer === true)) {
		if(buildDroid(fac, "Combat Engineer", body, prop, "", "", weap)) {
			return true;
		}

		return false;
	}
...

Re: AI script questions

Posted: 16 Jul 2017, 15:50
by Per
If you use Ctrl+o to switch player to the AI, and select the leg-only cyborg, then in the 'Selected' tab, you can see that it does indeed have the CyborgSpade construction part. However, it has the DROID type. That's where the problem lies - it should be CYBORG_CONSTRUCT. I think I broke a nasty hack I had made to set the droid type in the scripts previously, when I merged the cyborg bodies. I'll look at a better fix (does not look too hard).

Re: AI script questions

Posted: 16 Jul 2017, 20:14
by Per

Re: AI script questions

Posted: 17 Jul 2017, 00:20
by MIH-XTC
deleted - nvm - didn't see Per responded.

I was going to say that I don't think it's defined in the campaign templates.json (if that matters). This is how it's defined in mp templates.json

"Cyb-ComEng": {
"available": 1,
"body": "CyborgLightBody",
"construct": "CyborgSpade",
"id": "Cyb-ComEng",
"name": "Combat Engineer",
"propulsion": "CyborgLegs",
"type": "CYBORG_CONSTRUCT"
},

Re: AI script questions

Posted: 17 Jul 2017, 19:24
by Berserk Cyborg
The combat engineers are being produced correctly now.

...Except all other cyborgs are considered invalid (breaks other AI also):

Code: Select all

error   |12:05:35: [validTemplateForFactory:5611] Can only build cyborg in cyborg factory, not droidType 0 in Cyborg Factory.

error   |12:05:35: [js_buildDroid:1921] Invalid template CyborgChaingun Cyborg for factory Cyborg Factory
error   |12:05:35: [callFunction:209] 0 : buildCyborg(fac = [object Object], useEngineer = false) at /multiplay/skirmish/cobra_includes/production.js:293

error   |12:05:35: [callFunction:209] 1 : produce() at /multiplay/skirmish/cobra_includes/production.js:382
error   |12:05:35: [callFunction:209] 2 : <global>() at -1

info    |12:05:35: [callFunction:212] Uncaught exception calling function "produce" at line 293: ReferenceError: validTemplateForFactory(psTemplate, psStruct, true) failed in js_buildDroid at line 1921
info    |12:05:35: [callFunction:212] Assert in Warzone: qtscript.cpp:212 (false), last script event: 'N/A'

Re: AI script questions

Posted: 17 Jul 2017, 23:59
by Per
Oops. Hopefully fixed now.