Scripters cove

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

Moderators: another_commander, winston

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

It depends a little on the desired nature and look of things as collision detection will get in the way if the parts are too close together. Similarly they would appear as separate targets to the player for ident or missile lock (unless given a mil scanner jammer to stop that) and separately on the scanner (again unless shipdata'd otherwise to be scanner-invisible).

Something similar could be done with the player ship, although it could get in the way of docking as well.

But it would need to be done with a frame callback or else things would look very odd and jerky.
User avatar
Cmdr. Maegil
Sword-toting nut-job
Sword-toting nut-job
Posts: 1294
Joined: Tue Feb 27, 2007 10:28 pm
Location: On the mend in Western Africa

Re: Scripters cove

Post by Cmdr. Maegil »

Thargoid wrote:
It depends a little on the desired nature and look of things as collision detection will get in the way if the parts are too close together.
The idea was to use it on:

- turreted freighters, simply divided between top and bottom to target two enemies at a time (plus the player's own target, which if empty could default back to the first enemy that hits either side of the ship),

- Borg cubes composed by 5^3 to 10^3 (5^3=125, 6^3=216, 8^3=512 ,10^3=1000) fixed but independent frangible armed entities (with some fancy programming so the inner entities won't try to shoot trough the outer ones before they are exposed).

- larger ships, such as a [wiki]Long Range Cruiser (Oolite)[/wiki], could be split like a centipede in 3 or four sections along its length wrapped around the flying entity (the one controlling the engine and main weapons), each subdivided in top, bottom, port and starboard sections - 12 or more independent fire control centres can make much sense on a ship so large.

Thargoid wrote:
Similarly they would appear as separate targets to the player for ident or missile lock (unless given a mil scanner jammer to stop that)
Actually I think it could be even more fun that way... to be able of picking off a large NPC bit by bit, while what's left still poses great danger, or if in a player ship, it can contribute immensely to immersion:
"Brace for impact!"
BOOOM
"Damage report!"
"Sir, we lost section seven and the turrets 6-3 thru 8-1! Damage control and medical aid parties are on their way, but are having trouble going around the debris."
"Sir, Shielding on sector 8 is now failing. Sir, sector 8 is taking damage."
"Helm, emergency roll to 150."
"Aye-aye, Sir, rolling 1-5-0 degrees; Sir, 1-5-0 my helm is on full burst clockwise."
"Tactical, give me a firing solution to that destroyer up ahead."
"Sir, sectors 4 and 6 are under attack but their shields are holding... also sector 12, Sir:"
"Sir, the plasma accelerator is fully charged and ready to fire, main armament trigger failsafes active; Sir, please validate the firing order."
Sounds like fun!!!
Such a player ship should necessarily have at least a couple of cinematic POVs to catch itself on action screenshots.

Thargoid wrote:
and separately on the scanner (again unless shipdata'd otherwise to be scanner-invisible).
Ideally, only the main element should appear - but if the complete set's size warranted it, it should rather appear as a blob.

Thargoid wrote:
Something similar could be done with the player ship, although it could get in the way of docking as well. But it would need to be done with a frame callback or else things would look very odd and jerky.
Yay, it can be done... or so I thought, and then you lost me on "frame callback". In any case, the (original) concept isn't to use it on fast moving and turning ships, but on things Python-sized or bigger.
You know those who, having been mugged and stabbed, fired, dog run over, house burned down, wife eloped with best friend, daughters becoming prostitutes and their countries invaded - still say that "all is well"?
I'm obviously not one of them.
User avatar
RyanHoots
---- E L I T E ----
---- E L I T E ----
Posts: 958
Joined: Fri May 20, 2011 8:10 pm
Location: Nowhere
Contact:

Re: Scripters cove

Post by RyanHoots »

Quick question: Can you change the main station's orbital altitude via script? If so, how?
Image
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Ryan - the answer is yes as you can change the position of any entity via script.

e.g. this will move the main station when it is spawned 500 metres closer to the planet

Code: Select all

this.shipSpawned = function(spawnedship)
{
if (spawnedShip.isMainStation)
{
var newPosition = spawnedShip.position.add(spawnedShip.vectorForward.multiply(500));
spawnedShip.position = newPosition;
}
}
to move it away from the planet.

Code: Select all

var newPosition = spawnedShip.position.subtract(spawnedShip.vectorForward.multiply(500));

Edit to add - don't forget to move the navigation bouy as well. :)
Last edited by Capt. Murphy on Sat Dec 10, 2011 4:47 am, edited 1 time in total.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Cmdr. Maegil wrote:
Yay, it can be done... or so I thought, and then you lost me on "frame callback". In any case, the (original) concept isn't to use it on fast moving and turning ships, but on things Python-sized or bigger.
I'll comment on most of it, but just quote the above bit to save space. Frame callback is the new(ish) method of doing actions on every frame displayed by the game. You'd need to do that to keep everything synchronised and in their correct positions. If you just did it by a script/timer set-up, you'd get a maximum firing of once every 0.25s (ie 4FPS). Visually it would be jerky as the entities moved (or didn't) at your normal game frame-rate but then every 0.25s things got moved around into their correct place.

By using the callback you can shift the position of all the sub-bits once per frame (ie 40FPS, or whatever rate your machine achieves) and everything will move smoothly. But it's a little more complicated to script.

As I said the biggest thing to get around will be the entity collision detection. If things get too close they will crash together, lose energy and to the extreme explode. That may limit how tightly you can keep all the bits together, hence the overall look of the thing.

But the general concept is fairly sound, but the devil will be in the detail.
User avatar
Cmdr. Maegil
Sword-toting nut-job
Sword-toting nut-job
Posts: 1294
Joined: Tue Feb 27, 2007 10:28 pm
Location: On the mend in Western Africa

Re: Scripters cove

Post by Cmdr. Maegil »

So it's really not something the likes of me can do on the back yard with a plasma cutter and a welding torch...
Anyway, thanks for the info.
You know those who, having been mugged and stabbed, fired, dog run over, house burned down, wife eloped with best friend, daughters becoming prostitutes and their countries invaded - still say that "all is well"?
I'm obviously not one of them.
User avatar
RyanHoots
---- E L I T E ----
---- E L I T E ----
Posts: 958
Joined: Fri May 20, 2011 8:10 pm
Location: Nowhere
Contact:

Re: Scripters cove

Post by RyanHoots »

Capt. Murphy wrote:
Ryan - the answer is yes as you can change the position of any entity via script.

e.g. this will move the main station when it is spawned 500 metres closer to the planet

Code: Select all

this.shipSpawned(spawnedShip)
{
if (spawnedShip.isMainStation)
{
var newPosition = spawnedShip.position.add(spawnedShip.vectorForward.multiply(500));
spawnedShip.position = newPosition;
}
}
to move it away from the planet.

Code: Select all

var newPosition = spawnedShip.position.subtract(spawnedShip.vectorForward.multiply(500));
Thanks. In my Ooniverse, I'd prefer a higher orbit for those stations. :)
Capt. Murphy wrote:
Edit to add - don't forget to move the navigation bouy as well. :)
Thanks for reminding me... this gives me so many funny ideas...
Image
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Cmdr. Maegil wrote:
So it's really not something the likes of me can do on the back yard with a plasma cutter and a welding torch...
Anyway, thanks for the info.
Have a look at the inner workings of Stellar Serpents OXP.

The head of the serpent is the "master" entity, but all of the body segments and the tail are each individual and distinct entities. It's just that they are not armed in any way, unlike in your thought. But the general concept is the same as what you are thinking of - a master entity with other ones being moved around and oriented in a suitable fashion to make the whole thing appear as a single entity.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1244
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove - Can't get ship to perform actions

Post by UK_Eliter »

Dear all

I've got a (very, very large) ship defined as a carrier. It launches defense ships (under certain conditions). But these ships do not, even after they've received a 'launched okay' message, intercept or attack when I - a script - tells them to. I've verified that (1) the script is actually running, (2) the defence ships in question have targets defined, (3) those ships are in the right AI state. And yet they just fly in a straight line forever (unless they get attacked). So I'm stumped. I've found existing stuff on the boards that looks a bit similar . .

Can anyone help, please?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

I think the best route there would be to upload a beta somewhere to let people have a look. It's a little too complex a question I think to do via posts here.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1244
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove

Post by UK_Eliter »

Dear Thargoid

Thanks. Actually, though, I've fixed it. I was summoning up one of my own derelicts, instead of a live ship. But the ship still got animated by the carrier when it was launched - until it has 'launched okay', at which point it just kept its trajectory. The confusion had something - I don't fully understand it, though I've fixed it - to do with roles. Anyway, thanks again!
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Have recently discovered the array.forEach method for iterating across an array I thought I do some profiling to compare it's performance against a standard for loop doing the same job. I was quite surprised to find that array.forEach seems to have a significantly higher JS overhead than a standard for loop. Any thoughts?

The code I profiled was:

Code: Select all

this.forwardforloop = function()
{
 var counter = 0;
 this.arrayOfSystemNames = new Array;
 for (counter = 0; counter < this.arrayOfSystemID.length;counter++)
 {
  this.arrayOfSystemNames.push(System.systemNameForID(this.arrayOfSystemID[counter]))
 }
}
and

Code: Select all

this.forEachloop = function()
{
 this.arrayOfSystemNames = this.arrayOfSystemID.forEach(function (systemID){ return System.systemNameForID(systemID)},this);
}
where this.arrayOfSystemID is an array of the numbers 0 through to 255.

In both cases the vast majority of the overhead is the native functions, but the JS overhead for this.forEachloop() is several time slower than this.forwardforloop.
:time worldScripts["Array_Iteration_Profiling"].forwardforloop()
> console.profile(eval("(function codeToBeProfiled() { (" + "worldScripts[\"Array_Iteration_Profiling\"].forwardforloop()" + ") })"), this)
Total time: 571.113 ms
JavaScript: 4.384 ms, native: 566.716 ms
Counted towards limit: 567.311 ms, excluded: 3.8018 ms
Profiler overhead: 3.897 ms
NAME T COUNT TOTAL SELF TOTAL% SELF% SELFMAX
-[Universe generateSystemData:useCache:] N 256 560.27 560.27 98.1 98.1 9.88
SystemStaticSystemNameForID N 256 566.56 5.19 99.2 0.9 0.13
(../AddOns/Array_Iteration_Profiling.oxp/Config/script.js:19) <anonymous> J 1 570.86 4.30 100.0 0.8 4.30
-[NSString(OOJavaScriptExtensions) oo:jsValueInContext:] N 256 1.10 1.10 0.2 0.2 0.01
WorldScriptsGetProperty N 1 0.16 0.15 0.0 0.0 0.15
(<console input>) codeToBeProfiled J 1 571.10 0.09 100.0 0.0 0.09
OOStringFromJSString N 1 0.01 0.01 0.0 0.0 0.01
:time worldScripts["Array_Iteration_Profiling"].forEachloop()
> console.profile(eval("(function codeToBeProfiled() { (" + "worldScripts[\"Array_Iteration_Profiling\"].forEachloop()" + ") })"), this)
Total time: 585.927 ms
JavaScript: 14.21 ms, native: 571.703 ms
Counted towards limit: 582.617 ms, excluded: 3.30982 ms
Profiler overhead: 7.757 ms
NAME T COUNT TOTAL SELF TOTAL% SELF% SELFMAX
-[Universe generateSystemData:useCache:] N 256 565.16 565.16 96.5 96.5 9.76
(../AddOns/Array_Iteration_Profiling.oxp/Config/script.js:61) <anonymous> J 512 1161.73 11.43 198.3 2.0 2.23
SystemStaticSystemNameForID N 256 571.53 5.24 97.5 0.9 0.13
(../AddOns/Array_Iteration_Profiling.oxp/Config/script.js:61) <anonymous> J 1 585.66 2.70 100.0 0.5 2.70
-[NSString(OOJavaScriptExtensions) oo:jsValueInContext:] N 256 1.13 1.13 0.2 0.2 0.02
WorldScriptsGetProperty N 1 0.17 0.17 0.0 0.0 0.17
(<console input>) codeToBeProfiled J 1 585.91 0.08 100.0 0.0 0.08
OOStringFromJSString N 1 0.01 0.01 0.0 0.0 0.01
Edit to add - a reverse for loop appears to have the least JS overhead.

Code: Select all

this.reversedforloop = function()
{
 var counter;
 this.arrayOfSystemNames = new Array;
 for (counter = this.arrayOfSystemID.length - 1; counter >= 0;counter--)
 {
  this.arrayOfSystemNames.push(System.systemNameForID(this.arrayOfSystemID[counter]))
 }
}
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander »

Capt. Murphy, are you using a debug build for your tests? Note that JS in debug is significantly slower than in release mode.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post by Capt. Murphy »

Nope it's a standard nightly type build. A bit of googling suggests that forEach is known to be a slower method for array iteration.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
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: Scripters cove

Post by Eric Walch »

Capt. Murphy wrote:
A bit of googling suggests that forEach is known to be a slower method for array iteration.
One other JS construction that is relative slow is the 'yield' operator. That also allows similar actions on an array. Kaks used it in the Kestrel&Falcon.oxp. In the previous JS version that very often gave time-outs on my computer when using debug builds. The current JS version is much faster but I think that it still will be a slow method.
Last edited by Eric Walch on Wed Dec 14, 2011 4:13 pm, edited 1 time in total.
Post Reply