Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

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 »

Frame wrote:
Javascript

loadSound("sound.ogg")
playSound.("sound.ogg")

whereby sounds can overlap... playMusic will stop any current music playing...
Already done. Hmm, I thought I’d documented it, but apparently not. Still, look here. Note that sound names enclosed in square brackets will be looked up in customsounds.plist.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Done. – Ahruman

Ahruman wrote:
Commander McLane wrote:
Not a request for a new functionality, but for a change in the existing one. I would like the shipLaunchedEscapePod-event handler to fire a little earlier. To be precise: before player.bounty is reset to 0.
Done.
Thanks! :D

What about the pseudoFixedDxyz_numbers? (See one post above the quoted one.)

It would also help if one of the code wizards could provide us with the formula used for the calculation of pseudoFixedD100_numbers and pseudoFixedD256_numbers. Then we could recreate it as a JS-resource.

(I was even thinking of flying around through all systems in all galaxies, writing down the respective numbers and putting them in an array. But this is a really tedious undertaking, so I wouldn't really like to do it.)
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

An event handler that fires when the player has bought an equipment item. I've checked that guiScreenChanged does not fire in that case. Would be useful for the equipment items in Anarchies that reset the player.bounty.
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Post by Frame »

Request

Code: Select all

ship.dock(entity)
player.ship.dock(entity)
Very simple, forces the player to dock with entity (if entity can be docked with)

Similar to instant dock with auto pilot, which however only works for the build in stations afaik...
Bounty Scanner
Number 935
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 »

Done by another_commander – Ahruman

I like to see an event handler for buying equipment. That would it make possible to immediately initialise equipment after purchase. e.g. this equipment could be a custom "remove specific equipment", like the remove passenger berth or remove missiles.
A script could than divine a remove equipment that only shows as he has the equipment. With the handler the oxp can immediately remove the just bought remove-equipment and the equipment itself. After this the normal code will update the screen were the just removed equipment is probably shown again when the tech level is right.

The right place to put the handler would be in "playerEntity.m" in the function "buySelectedItem":

Code: Select all

	if ([self tryBuyingItem:item])
	{
		if (credits == old_credits)
		{
			[self playCantBuyCommodity];
		}
		else
		{
			[self playBuyCommodity];
			
			// wind the clock forward by 10 minutes plus 10 minutes for every 60 credits spent
			double time_adjust = (old_credits > credits) ? (old_credits - credits) : 0.0;
			ship_clock_adjust += time_adjust + 600.0;
			[self doScriptEvent:@"boughtEquipment" withArgument:[[equipdata arrayAtIndex:index] stringAtIndex:EQUIPMENT_KEY_INDEX]];
		}
It should offer the equipment name as parameter. I added the line in above code. I'm not sure if the argument is defined right. (I just copied it from a few lines below in the code)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6668
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Eric Walch wrote:
I like to see an event handler for buying equipment. That would it make possible to immediately initialise equipment after purchase. e.g. this equipment could be a custom "remove specific equipment", like the remove passenger berth or remove missiles.
A script could than divine a remove equipment that only shows as he has the equipment. With the handler the oxp can immediately remove the just bought remove-equipment and the equipment itself. After this the normal code will update the screen were the just removed equipment is probably shown again when the tech level is right.

Code: Select all


It should offer the equipment name as parameter. I added the line in above code. I'm not sure if the argument is defined right. (I just copied it from a few lines below in the code)[/quote]

Done. The handler is called [b]playerBoughtEquipment[/b] and is taking the EQ_* key string as parameter. The handler is used in a script as shown here:
[code]
this.playerBoughtEquipment = function(equipmentKey)
{
	log("playerBoughtEquipment","Player has bought equipment: " + equipmentKey);
}
The above example handler will generate on the stderr:

Code: Select all

2008-09-17 14:19:39.369 oolite.exe[5604] [playerBoughtEquipment]: Player has bought equipment: EQ_WEAPON_MILITARY_LASER
2008-09-17 14:19:40.994 oolite.exe[5604] [playerBoughtEquipment]: Player has bought equipment: EQ_PASSENGER_BERTH
2008-09-17 14:19:44.119 oolite.exe[5604] [playerBoughtEquipment]: Player has bought equipment: EQ_ADVANCED_NAVIGATIONAL_ARRAY
Thanks for pointing out the correct place to look at the code, Eric. It made things really easy.
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 »

Thanks Another Commander,

I immediately have an other request. Probably just as simple to implement:

Make the destination of a ship available to the script as read/write.

Currently oolites JS engine offers a bunch of very interesting vector- and quarternion functions to do geometrical calculations. It would be very useful when you could send a ship to such a calculated spot.

e.g
a) For the launches of the GRS station I original had problems that launching ships, often hit the planet. Because of its size it mass locked the exiting ships quite long. With the AI I only can send it to an existing object. Now I sent it to the witchspace coordinates with the special AI command, but for some station locations it still blocks the way and I would rather have used a calculated spot near the station.

b) For the next buoyRepair.oxp release, I send ships between the external GRS structures. I do this by giving each ship his unique a marker in deep space. Than I calculate a position, move the marker to that position, let the AI set the destination to the marker, and move the marker back to deep space. The marker moves in and out in one update so it never shows on the screen. Direct changing of the ships destination variable by JS would be much easier.

c) I also see a good use of this in combat. I always find it very stupid that a fleeing ship goes directly away from the player. When the player is following him he can just toast him from behind as there are no direction changes while fleeing. However, with JS you could in regular intervals check the angle between the headings of the fleeing and attacking ship. When the are close to zero (same heading), the fleeing ship could switch course. This will make it a much harder target.(But maybe this behaviour should be build in Oolite itself : BEHAVIOUR_FLEEING?)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Done – Ahruman

And one from me, based on the same discussion with Eric. Would it be possible to expand the AI command sendScriptMessage to accept parameters, so we can use it to pass them to the function in the script?

I was trying to use it yesterday to sort out messaging by passing the message needed from the AI "sendScriptMessage: playerComms('Your message here')" to a function this.playerComms(message) in the ships script which diplayed the parameter message, but nothing was passed hence nothing displayed...

Having to code each message as a separate function works, but is rather a bodged way of doing it. I know the messaging from unpiloted craft is due in 1.72, but consider this just an example ;)
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 »

Eric Walch wrote:
Thanks Another Commander,

I immediately have an other request. Probably just as simple to implement:

Make the destination of a ship available to the script as read/write.
This is problematic because the meaning of destination depends on AI state, and various bits of code write to it at potentially unpredictable times. Its meaning varies; it’s sometimes in absolute coordinates, sometimes relative to the ship. Its usages may change in future, as well.
Thargoid wrote:
color=green]And one from me, based on the same discussion with Eric. Would it be possible to expand the AI command sendScriptMessage to accept parameters, so we can use it to pass them to the function in the script?
Done. Syntax is:

Code: Select all

sendScriptMessage: functionName parameter string
In the usual legacy script way, the parameters after functionName are concatenated with single spaces between them and passed as a single string, so this:

Code: Select all

sendScriptMessage: functionName foo bar     baz
is equivalent to JS functionName("foo bar baz").
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Eric Walch wrote:
Done by another_commander – Ahruman[/b]

I like to see an event handler for buying equipment. That would it make possible to immediately initialise equipment after purchase. e.g. this equipment could be a custom "remove specific equipment", like the remove passenger berth or remove missiles.
A script could than divine a remove equipment that only shows as he has the equipment. With the handler the oxp can immediately remove the just bought remove-equipment and the equipment itself. After this the normal code will update the screen were the just removed equipment is probably shown again when the tech level is right.

The right place to put the handler would be in "playerEntity.m" in the function "buySelectedItem":

Code: Select all

	if ([self tryBuyingItem:item])
	{
		if (credits == old_credits)
		{
			[self playCantBuyCommodity];
		}
		else
		{
			[self playBuyCommodity];
			
			// wind the clock forward by 10 minutes plus 10 minutes for every 60 credits spent
			double time_adjust = (old_credits > credits) ? (old_credits - credits) : 0.0;
			ship_clock_adjust += time_adjust + 600.0;
			[self doScriptEvent:@"boughtEquipment" withArgument:[[equipdata arrayAtIndex:index] stringAtIndex:EQUIPMENT_KEY_INDEX]];
		}
It should offer the equipment name as parameter. I added the line in above code. I'm not sure if the argument is defined right. (I just copied it from a few lines below in the code)
Hey, I had already requested the same thing two posts (and seven weeks) earlier. Why am I not stroken out? :P
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 »

Ahruman wrote:
Eric Walch wrote:
Make the destination of a ship available to the script as read/write.
This is problematic because the meaning of destination depends on AI state, and various bits of code write to it at potentially unpredictable times. Its meaning varies; it’s sometimes in absolute coordinates, sometimes relative to the ship. Its usages may change in future, as well.
In that case maybe make it possible to write coordinates that are used by the AI command "setDestinationFromCoordinates". This way the coordinates can be set by a script message that does something similar as "setCoordinates: wpu 0 0 0.3".
It makes use a little bit more complicated but will work like:
"setCoordinates: wpu 0 0 0.3", setDestinationFromCoordinates, but not with fixed coordinates but coordinates calculated by a scriptMessage.
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 »

Commander McLane wrote:
Hey, I had already requested the same thing two posts (and seven weeks) earlier. Why am I not stroken out? :P
Because I got bored. :-)
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 »

I like to have a remove method. It should work the same as the explode method but without the explosion itself. Currently people are using the landOnPlanet AI command for this or the new JS explode method. Both however have undesired side effects.

With a remove method it will also become possible to selectively remove subentities and replace them with normal entities on the same spot.
With the current explode method you already can selectively explode subentities away. That means just a copy of this current method without the explosion itself would be sufficient.
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Post by Frame »

Eric Walch wrote:

With the current explode method you already can selectively explode subentities away. That means just a copy of this current method without the explosion itself would be sufficient.
A js work around could be

Code: Select all


subentity = ship.subEntitties[x]
subentity.setPosition(0,0,15000000)
subentity.explode()

This works as i am using it for my locator objects in save anywhere oxp..
of course a ship.remove() would be more clean..

so i second that...
Bounty Scanner
Number 935
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 »

Frame wrote:
A js work around could be
I know, it can even be more complex. Currently I move my copy to deep space, explode the subents away that are also missing on the original and than move it over the original and as last I move the original to deep space. With just a single remove option it would be a lot easier.

Code: Select all

this.removeSubs = function()
{
    let subPresent = false
    for(let i=0;i<this.reverseShip.subEntities.length;i++)
    {
        subPresent = false
        for(let j=0;j<this.ship.subEntities.length;j++)
        {
            let Org = this.ship.subEntities[j].position
            let Copy = this.reverseShip.subEntities[i].position
            if(Copy.x == -Org.x && Copy.y == Org.y && Copy.z == -Org.z) subPresent = true
            // Ships copy is rotated over the y-axis. x and z position are inverted!
        }
        if(!subPresent) this.reverseShip.subEntities[i].explode()
    }
}
Post Reply