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

Random Hits OXP

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

Moderators: winston, another_commander

pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Screet wrote:
Thus, should your much more readable code still have the old tendency of selecting the same systems, maybe it's enough to simply request n times (for n seconds) a random number before running that code - and I'd guess that the next version of GalNavy would then come with a shorter and better script ;)
What's this about random numbers? The existing code from the OXP (Galactic Navy 5.0) doesn't use random numbers for ReserveDutySystemDetermination

It only uses galaxy and system.ID for one description per system. The same description per system.
Last edited by pmw57 on Mon Oct 26, 2009 10:16 pm, edited 1 time in total.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Hey guys. Maybe you should spend some time with OSE and fix the bugs there instead of talking about Galactic Navy or RH. It seems you haven't took a look at all in RH, then you'd know that LB has scripted it in XML, not in JS (only the ship-scripts are JS). And before you say 'I can translate it'. LB is still here and HE has to work work with it, so this wouldn't be a great help and would stop any further development.

If you really want to do something, give him a pm and talk about it, instead of posting non-existing 'fixes', or write a JS-Tutorial for Oolite for us 'noobs'.
Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

Post by Screet »

pmw57 wrote:
What's this about random numbers? The existing code from the OXP (Galactic Navy 5.0) doesn't use random numbers for ReserveDutySystemDetermination

It only uses galaxy and system.ID for one description per system. The same description per system.
That's wrong, really. Add the log line and give the modified version from me a try...it's selecting randomly one of the values in that array. Since the random generator is usually using the same random seed, it usually does select the same all the time.

What my modification does is that it add's some more randomness to the selection process (even more than there are numbers, thus surely enough).

I was astonished about how JS works when I did have a look at that code myself.

Hmmm...and I really do wish that I could simply move all these messages from here to the GalNavy thread...

Screet
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Screet wrote:

Code: Select all

this.ReserveDutySystemDetermination = function()
{
	var sec = clock.secondsComponent;
	for(var i = 0 ; i <= sec ; i++) {
		this.ReserveDutySystemDeterminationPt2();
	}
}

this.ReserveDutySystemDeterminationPt2 = function()
{
Instead of bickering, here is a better way to seed a random number based on the time.

Code: Select all

this.ReserveDutySystemDetermination = function()
{
	var sec = clock.minutesComponent * 60 + clock.secondsComponent,
		dummy;
	for (var i = 0 ; i < sec ; i++) {
		dummy = Math.random();
	}
	this.ReserveDutySystemDeterminationPt2();
}
And if you don't want the number of loops to be as high as 3600, you can limit them to 1000, or some other acceptable number with:

Code: Select all

sec = sec % 1000;
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

Post by Screet »

Svengali wrote:
It seems you haven't took a look at all in RH, then you'd know that LB has scripted it in XML, not in JS (only the ship-scripts are JS).
If XML cannot use time or something like that to achive more randomness before it uses random values, maybe it'd be an idea to call a JS that simply "uses up" some random numbers before it's using random numbers so that it also does achieve more randomness?

Screet
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Screet wrote:
Add the log line and give the modified version from me a try...
I will do that when I'm not at work.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

About modernising older OXPs: pmw57, what about converting Taranis?

Provided you contact the original oxp maker and they give you the go-ahead, I'm sure there won't be any problem with you converting that to js. Plus the Taranis HQ could really do with some shadery updates, instead of using flashers - they look so old-fashioned!
Last edited by Kaks on Mon Oct 26, 2009 10:38 pm, edited 2 times in total.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Kaks wrote:
About modernising older OXPs: pmw57, what about converting Taranis?

Provided you contact the original oxp maker and they give you the go-ahead, I'm sure there won't be any problem with you converting that to js. Plus the Taranis HQ could really do with some shader update, instead of using flashers!
I will certainly take a look, however regarding graphical stuff, be warned: my artistic skills are below sub-par.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2868
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Because of the size of the project, I started writing it on Oolite 1.65 (no JS available then), so the script is written in legacy with some bolt on JS scripts for ships and other objects which set legacy mission variables which the main legacy script then acts on. The randomness of system selection isn't therefore as random as it could be as the systems are picked from a list in descriptions (as this was the only way to do it when I wrote it). If I was starting it now I'd have written in JS, but I haven't got the heart (or the time really) to translate the legacy script to a JS one. Its just too darn big, so when I have the time to finishs it, it'll just have to be left in legacy as it would be too time consuming (and would probabley break stuff) to re-write it. :wink: Its like the old joke: "Q: How do I get to Dublin?", "A: Well I woudn't start from here."
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

LittleBear wrote:
If I was starting it now I'd have written in JS, but I haven't got the heart (or the time really) to translate the legacy script to a JS one. Its just too darn big, so when I have the time to finishs it, it'll just have to be left in legacy as it would be too time consuming (and would probabley break stuff) to re-write it. :wink: Its like the old joke: "Q: How do I get to Dublin?", "A: Well I woudn't start from here."
There are cunning techniques that can reduce the conversion time. It's amazing what can be done with regular expressions (not necessarily within the game, but for converting the code).

Would you consider my taking a look at things?
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2868
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Yeah sure, if you want to convert it. I've put comments in the script so you can see what each bit is meant to be doing, but its a real looooong script!

I don't think though there is a way though to calculate the position on the map to a system picked with a random number though. ATM the position is done manually ie: system oneof a, b, c, d, e, etc set sector = "North West". Basically I had to look at the map and manually code in where each system that RH could generate a mission was. Wouldn't fancy doing that with over 2000 systems, which is partly why lists are used! Also some systems are unreachable. Eg there are about 50 systems in G7 that you cannot actually get to as the cluster is more than 7 light years from anywhere else. ATM Random Hits won't generate missions at these systems as they would be impossible to complete (I just didn't include them on the lists). Again the disadvantage of a random number picked system is I don't think there'd be a way for Ooolite to know that a system it picked at random from all 255 systems in the current Galaxy (rather than picking a system at random from a pre-set list) is one that the player cannot actually reach.

I'd checked this with another commander before resorting to lists and there is not a mathmetical relationship between planetnumbers that can be used to calaculate distance between two systems or the position of a given system, only between the co-ordinates of two system, which I don't think is accessable with an OXP script.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

LittleBear wrote:
Yeah sure, if you want to convert it. I've put comments in the script so you can see what each bit is meant to be doing, but its a real looooong script!
So was OSE but most of that was duplicate repeating structures that were easily brought down to size.

When I separate bits that change from the bits that don't (there's a fancy name for that somewhere) the code will be a lot smaller, and easier to follow.
I don't think there'd be a way for Ooolite to know that a system it picked at random from all 255 systems in the current Galaxy (rather than picking a system at random from a pre-set list) is one that the player cannot actually reach.

I'd checked this with another commander before resorting to lists and there is not a mathmetical relationship between planetnumbers that can be used to calaculate distance between two systems or the position of a given system, only between the co-ordinates of two system, which I don't think is accessable with an OXP script.
There is systemNameForID but apart from that, nothing else that's useful.

It would be nice if there was a systemDistance(targetID [, sourceID]) which returned false (or -1) for not reachable.

Hmm, maybe that should be a scripting request for the developers.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
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 »

pmw57 wrote:
So was OSE but most of that was duplicate repeating structures that were easily brought down to size.

When I separate bits that change from the bits that don't (there's a fancy name for that somewhere) the code will be a lot smaller, and easier to follow.
Random Hits also contains a fair part of repeating code. Legacy does not allow for functions so when you need some code part 20 times, you must add it 20 times.

When you look at Galactic Navy, you see that its legacy version of over 16000 code lines was reduced to about 1850 lines by Nemordicus.

Random hits is a bit smaller (about 9000 lines) and has less repeating code that GN had, but a reduction to one quarter would be a very realistic number. (But still a hell of a job)
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

pmw57 wrote:
It would be nice if there was a systemDistance(targetID [, sourceID]) which returned false (or -1) for not reachable.

Hmm, maybe that should be a scripting request for the developers.
You mean something like this?

Code: Select all

system.info.distanceToSystem(System.infoForSystem(0, 55));
Hmmm, it's not on the wiki yet.

Double hmmm, it looks like I need to create a completely new SystemInfo page to add that to the wiki. I suppose I better do that. And we still need to add a lot of the future stuff mentioned in the Progress thread.

You might want to have a look at the Progress thread. It's a goldmine of information not yet ported to the wiki, like this post! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Kaks wrote:
You might want to have a look at the Progress thread. It's a goldmine of information not yet ported to the wiki, like this post! :)
That's great to know that they're on the horizon.

In the mean-time, a look-up table will be a suitable alternative until the minimum supported version can be brought forward to 1.73.4
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
Post Reply