Page 2 of 2

Posted: Sun Nov 08, 2009 11:58 am
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.

Posted: Sun Nov 08, 2009 1:31 pm
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. :-)

Posted: Sun Nov 08, 2009 2:35 pm
by JensAyton
Here’s another example graph: PDF, dot.

Posted: Sun Nov 08, 2009 11:14 pm
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.

Posted: Sun Nov 08, 2009 11:17 pm
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 ;)

Posted: Sun Nov 08, 2009 11:28 pm
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

Posted: Sun Nov 08, 2009 11:29 pm
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?).

Posted: Sun Nov 08, 2009 11:37 pm
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.