Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

AI Scripting for mine/turret

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

When you are on a mac you could try to get the plist editor that shipped with Tiger. That one placed the ending comma in a way that it works on all platforms. Even Tiger refuses to open the open-step plist files saved with the newer plist editor that ships with Leopard. When you only want to use the code yourself, you can use the new one and its better features but when you want to share the saved plists with others, better try getting the old one or maybe switch to plistEditPro. When you save in XML format, there is no problem with the newer mac plistEdit between platforms.

On the "checkEnergy"; it is future code. Maybe I should have written it even more clear that it is future code, or only add it after 1.74 becomes a release. But my experience it that when you don't add the the documentation immediately in the wiki after adding it to the code, it tends to get forgotten to add it at all.

In your case you don't need it at all because oolite itself is already sending a "ENERGY_LOW" message every time you ships gets a hit under low energy conditions.

I added this new command in Oolite to improve future pirateAI. In the next Oolite version, pirates that have fled into space will return to their original position in the spacelane after their energy has recovered. In current Oolite, a pirate can flee for a missile while undamaged himself. So there currently is no guarantee that he always receives a "ENERGY_FULL" message after fleeing. Therefor I added the "checkEnergy" command to query the energy state. For an "ENERGY_LOW" while under attack you don't need it, Oolite already sends it on every hit.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

I’ve filed a bug with Apple about the comma issue. Either I’ll be told I should be using XML or the bug will be marked as a duplicate, but I tried. :-)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Here’s another example graph: PDF, dot.
User avatar
McSpider
Average
Average
Posts: 14
Joined: Tue Sep 22, 2009 10:45 pm
Location: Milky Way Galaxy

Post by McSpider »

Thargoid wrote:
see my hired guns or drones OXPs for examples
I looked at you'r OXPs and came up with this:

Code: Select all

this.checkTargetDistance = function()
	{
	this.targetDistance = this.ship.position.distanceTo(player.ship.position);
	if(this.targetDistance > 6000) // check distance from mine to target
		{
		this.ship.AIState = "TARGET_RANGE_HIGH";
		}
	else
		{
		this.ship.AIState = "TARGET_RANGE_LOW";
		}
	}


this.shipDestroyedTarget = function(target)
	{
	player.score += 1; // accredit kills & bounty to player
	player.credits += target.bounty;
	log("Krypton Mine Kill - " + target.name + " : " + target.bounty);
	}
It works except that it checks the distance to the player's ship and not the current target.
I think (player.ship.position) should be something like this (target.ship.position).
I searched for target position on the wiki but didn't find anything suitable.
McSpider
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

You'll want this.ship.target.position . But it would also there be worth checking that the mine actually has a target (or else you'll generate errors). Something like:

if(!this.ship.target) {return;}

That will exit the function if the mine doesn't have a target. You get the idea, you can have it do other things too (the ! means not in JS - basically the above says "if this ship does not have a target, perform "return;" (return; means stop processing this function at this point).

If you want a reference for that, check target autolock OXP ;)
User avatar
McSpider
Average
Average
Posts: 14
Joined: Tue Sep 22, 2009 10:45 pm
Location: Milky Way Galaxy

Post by McSpider »

Thanks for the Quick reply.
Now my code looks like this:

Code: Select all

this.checkTargetDistance = function()
	{
    if(!this.ship.target) {return;}
	this.playerDistance = this.ship.position.distanceTo(this.ship.target.position);
	if(this.playerDistance > 5000) // check target distance
		{
		this.ship.AIState = "TARGET_RANGE_HIGH";
		}
	else
		{
		this.ship.AIState = "TARGET_RANGE_LOW";
		}
	}


this.shipDestroyedTarget = function(target)
	{
	player.score += 1;
	player.credits += target.bounty;
	log("Krypton Mine Kill - " + target.name + " : " + target.bounty);
	}
And it works perfectly. :D
My Ai now shoots missiles in 8 sec intervals (till it runs out) if target is out of range of the plasma accelerator.

EDIT: spelling & grammar fixed
Last edited by McSpider on Mon Nov 09, 2009 12:14 am, edited 2 times in total.
McSpider
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The only other comment I would add is you may want to change this.playerDistance to something more appropriate now (this.targetDistance perhaps?).
User avatar
McSpider
Average
Average
Posts: 14
Joined: Tue Sep 22, 2009 10:45 pm
Location: Milky Way Galaxy

Post by McSpider »

Thargoid wrote:
The only other comment I would add is you may want to change this.playerDistance to something more appropriate now (this.targetDistance perhaps?).
Done. And thanks for the help.
McSpider
Post Reply