Scripting requests

An area for discussing new ideas and additions to Oolite.

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

Re: Scripting requests

Post by Eric Walch »

I still don't see the problem. Is your request not the same what you are already doing for years in the Hammerhead?

Doing it in one function gives:

Code: Select all

globalPosition = this.ship.position.add(localPosition.rotateBy(this.ship.orientation));
localPosition being the position in ship coordinates and globalPosition the position in system coordinates.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

Not quite - it's actually the inverse (the Hammerhead is converting local to global, whereas I needed to go the other way). But it was indeed that coding which gave me the inspiration check about how to invert a quaternion. A quick hunt around the net gave me a solution, which is what Cim has now kindly integrated into trunk as noted as it's quite a useful thing to have available.

The code above isn't quite right I think (not tried it) as you need to rotate by the inverse of the player ship orientation, not by just the orientation itself.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripting requests

Post by Smivs »

Something I mentioned in passing on the Progress thread but perhaps got lost in the general discussion-
Can we have the ability to attach exhausts to sub-entities please? At the moment they have to be attached to the 'main' ship, which means if the sub-entity is removed or destroyed the exhaust prevails (which is/looks silly!). This feature would be of great help to me in my current project, and would also make shoot-off-able engine sub-ents a realistic and workable possibility. :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

Or as an alternative (as I think exhausts are a special kind of sub-ent themselves, and so you'd end up with the sub-ent of a sub-ent question) could the current special sub-entities (exhausts and flashers) be exposed with r/w to scripting? Either within the usual subEntities array, or perhaps in an array (or two) of their own.

That way we could do the tweaks like Smivs suggests, but also for flashers have them more independently controlled and controllable.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripting requests

Post by cim »

Thargoid wrote:
Or as an alternative (as I think exhausts are a special kind of sub-ent themselves, and so you'd end up with the sub-ent of a sub-ent question)
Which normally works, but because of the way exhaust display is calculated might be more troublesome. Making the sub-ent types scriptable seems better to me, at least in so far as allowing remove/restore, but probably not for 1.77/8.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripting requests

Post by Smivs »

Ah, OK. Something to look forward to then. :)

<Smivs goes off to ponder how to sort out his current issue :? >
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Cmd. Cheyd
---- E L I T E ----
---- E L I T E ----
Posts: 934
Joined: Tue Dec 16, 2008 2:52 pm
Location: Deep Horizon Industries Manufacturing & Research Site somewhere in G8...

Re: Scripting requests

Post by Cmd. Cheyd »

I realize we're in a freeze for 1.77, but after - How hard would it be to make the camera position readable? We can set camera position (player.ship.setCustomView), so why can't we read it? (Or can we, and I just didn't find it?)
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripting requests

Post by spara »

This is a big request :D.

A functionality for an oxp to add dynamic text layers to the screen. I've been abusing message_gui for this, which not a very clean solution.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

event handler that runs after a game is loaded

Post by GGShinobi »

I'm currently working with spara on an update for his [wiki]Updating TSC[/wiki].oxp, and I ran into a little problem there:

We want the equipment to be automatically awarded to the players ship if the ship has an [wiki]Advanced Space Compass[/wiki] (ASC) installed.

I've looked at the event list that can be found in the wiki, and I already use playerBoughtEquipment and playerBoughtNewShip to add the equipment in the respective cases. But I have not found a nice way to add it if the player's ship already had an ASC installed before he installed the oxp.

My current workaround will be to use another event, for example shipWillLaunchFromStation for the check if an ASC is installed and add the equipment if so. But this is a little bit of overkill, since it would be sufficient to check it only after a game is loaded. So, something like a "playerHasLoadedGame" (similar to the playerWillSaveGame-event) would be nice in the future :)
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
submersible
Commodore
Commodore
Posts: 264
Joined: Thu Nov 10, 2011 7:49 am

Re: event handler that runs after a game is loaded

Post by submersible »

GGShinobi wrote:
We want the equipment to be automatically awarded to the players ship if the ship has an [wiki]Advanced Space Compass[/wiki] (ASC) installed.
Can you test

Code: Select all

player.ship.equipmentStatus("EQ_???")


http://wiki.alioth.net/index.php/Oolite ... mentStatus
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

That would be the simplest way. Do a test on game start-up (see below) and if that fails (ie they don't have the ASC) then do a test on equipment purchase as already noted below.

Alternatively this.playerHasLoadedGame is otherwise known as [url=http://wiki.alioth.net/index.php/Oolite_JavaScript_Reference:_world_script_event_handlers#startUp]this.startUp[/url].
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: Scripting requests

Post by GGShinobi »

Thank you submersible and Thargoid for your answers! :)
Thargoid wrote:
Alternatively this.playerHasLoadedGame is otherwise known as [url=http://wiki.alioth.net/index.php/Oolite_JavaScript_Reference:_world_script_event_handlers#startUp]this.startUp[/url].
:shock: :!: That is exactly what I've been looking for! I didn't get that from the description in the wiki - there it sounded to me like that event is run (only once) after the game has been started. And I already wondered why no one else has been missing such an event. :lol:

I made an edit to the wiki to point out that the event is called also when a game is loaded. Question :?:: Does this mean that everytime I load a new game, all OXPs are reloaded? If so, the entry in the wiki should be edited, e.g. by changing the sentence to "This also means that it is also called after the player has loaded a game."

Anyway, thanks again! :D
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: Scripting requests

Post by Lone_Wolf »

GGShinobi wrote:
Question :?:: Does this mean that everytime I load a new game, all OXPs are reloaded? If so, the entry in the wiki should be edited, e.g. by changing the sentence to "This also means that it is also called after the player has loaded a game."
Yes, OXPs are reloaded when you load a new game.
Below is a partial copy of my latest.log .
At 11:16:19 i started oolite, answered yes to 'Load previous commander' .
The oxp loading entries for the loadgame start at 11:16:29.058 .

Code: Select all

11:16:19.359 [shipData.load.begin]: Loading ship data.
11:16:20.535 [script.javascript.init]: JavaScript reset successful.
11:16:20.670 [script.load.world.listAll]: Loaded 39 world scripts:
    BGS-M 1.6
    Cabal_Common_Briefing 1.7
    Cabal_Common_Comms 1.7
    Cabal_Common_Functions 1.7
    Cabal_Common_Keyboard 1.7
    Cabal_Common_MissionHandling 1.7
    Cabal_Common_Music 1.7
    Cabal_Common_Overlay 1.7
    Cabal_Common_OXPStrength 1.7
    Cabal_Common_SpecialMarkets 1.7
    Famous Planets 2.5.1
    genericHUDswitch - MilHUD.js 1.05, modified by Wyvern for MilHUD
    long_way_round
    Missile Spoof 1.02 - for Oolite 1.75
    oolite-cloaking-device 1.77
    oolite-constrictor-hunt 1.77
    oolite-contracts-cargo 1.77
    oolite-contracts-helpers 1.77
    oolite-contracts-parcels 1.77
    oolite-contracts-passengers 1.77
    oolite-nova 1.77
    oolite-thargoid-plans 1.77
    oolite-trumbles 1.77
    OXPConfig 2.0.14
    Povray Planets 1
    Povray Planets Galaxy1 Textures 1.1
    Povray Planets Galaxy2 Textures 0.1
    Povray Planets Galaxy3 Textures 0.1
    Povray Planets Galaxy4 Textures 0.1
    Povray Planets Galaxy5 Textures 0.1
    Povray Planets Galaxy6 Textures 0.1
    Povray Planets Galaxy7 Textures 0.1
    Povray Planets Galaxy8 Textures 0.1
    randomshipnames 1.2
    Repair system 2.08
    Shield Cycler 0.30.3
    Shield Cycler External Events 0.30.3
    shieldequalizercapacitors 1.3
    targetAutolock 1.11
11:16:23.726 [Povray Planets]: Startup
11:16:23.727 [Povray Planets]: Povray Planets Galaxy1 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy1 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy2 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy2 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy3 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy3 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy4 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy4 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy5 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy5 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy6 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy6 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy7 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy7 Textures
11:16:23.727 [Povray Planets]: Povray Planets Galaxy8 Textures
11:16:23.727 [Povray Planets]: Monkey patch Povray Planets Galaxy8 Textures
11:16:23.882 [startup.complete]: ========== Loading complete in 5.49 seconds. ==========
11:16:28.058 [script.javascript.init]: JavaScript reset successful.
11:16:28.078 [script.load.world.listAll]: Loaded 39 world scripts:
    BGS-M 1.6
    Cabal_Common_Briefing 1.7
    Cabal_Common_Comms 1.7
    Cabal_Common_Functions 1.7
    Cabal_Common_Keyboard 1.7
    Cabal_Common_MissionHandling 1.7
    Cabal_Common_Music 1.7
    Cabal_Common_Overlay 1.7
    Cabal_Common_OXPStrength 1.7
    Cabal_Common_SpecialMarkets 1.7
    Famous Planets 2.5.1
    genericHUDswitch - MilHUD.js 1.05, modified by Wyvern for MilHUD
    long_way_round
    Missile Spoof 1.02 - for Oolite 1.75
    oolite-cloaking-device 1.77
    oolite-constrictor-hunt 1.77
    oolite-contracts-cargo 1.77
    oolite-contracts-helpers 1.77
    oolite-contracts-parcels 1.77
    oolite-contracts-passengers 1.77
    oolite-nova 1.77
    oolite-thargoid-plans 1.77
    oolite-trumbles 1.77
    OXPConfig 2.0.14
    Povray Planets 1
    Povray Planets Galaxy1 Textures 1.1
    Povray Planets Galaxy2 Textures 0.1
    Povray Planets Galaxy3 Textures 0.1
    Povray Planets Galaxy4 Textures 0.1
    Povray Planets Galaxy5 Textures 0.1
    Povray Planets Galaxy6 Textures 0.1
    Povray Planets Galaxy7 Textures 0.1
    Povray Planets Galaxy8 Textures 0.1
    randomshipnames 1.2
    Repair system 2.08
    Shield Cycler 0.30.3
    Shield Cycler External Events 0.30.3
    shieldequalizercapacitors 1.3
    targetAutolock 1.11
11:16:29.071 [Povray Planets]: Startup
11:16:29.071 [Povray Planets]: Povray Planets Galaxy1 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy1 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy2 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy2 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy3 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy3 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy4 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy4 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy5 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy5 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy6 Textures
11:16:29.071 [Povray Planets]: Monkey patch Povray Planets Galaxy6 Textures
11:16:29.071 [Povray Planets]: Povray Planets Galaxy7 Textures
11:16:29.072 [Povray Planets]: Monkey patch Povray Planets Galaxy7 Textures
11:16:29.072 [Povray Planets]: Povray Planets Galaxy8 Textures
11:16:29.072 [Povray Planets]: Monkey patch Povray Planets Galaxy8 Textures
11:16:33.148 [exit.context]: Exiting: Exit Game selected on options screen.
11:16:33.162 [gameController.exitApp]: .GNUstepDefaults synchronized.

Closing log at 2013-01-16 11:16:33 +0100.
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: Scripting requests

Post by GGShinobi »

Lone_Wolf wrote:
Yes, OXPs are reloaded when you load a new game.
Lone_Wolf, thanks for the info. I've updated the wiki accordingly.
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Cmd. Cheyd
---- E L I T E ----
---- E L I T E ----
Posts: 934
Joined: Tue Dec 16, 2008 2:52 pm
Location: Deep Horizon Industries Manufacturing & Research Site somewhere in G8...

Re: Scripting requests

Post by Cmd. Cheyd »

Would it be possible to make galaxy and system writable from JS (i.e. - change the current system) during startup?
Post Reply