Page 28 of 70
Posted: Mon Oct 26, 2009 9:57 pm
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.
Posted: Mon Oct 26, 2009 10:15 pm
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'.
Posted: Mon Oct 26, 2009 10:29 pm
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
Posted: Mon Oct 26, 2009 10:30 pm
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:
Posted: Mon Oct 26, 2009 10:31 pm
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
Posted: Mon Oct 26, 2009 10:31 pm
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.
Posted: Mon Oct 26, 2009 10:34 pm
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!
Posted: Mon Oct 26, 2009 10:37 pm
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.
Posted: Tue Oct 27, 2009 12:21 am
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.
Its like the old joke: "Q: How do I get to Dublin?", "A: Well I woudn't start from here."
Posted: Tue Oct 27, 2009 12:46 am
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.
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?
Posted: Tue Oct 27, 2009 9:30 am
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.
Posted: Tue Oct 27, 2009 10:35 am
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.
Posted: Tue Oct 27, 2009 11:19 am
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)
Posted: Tue Oct 27, 2009 11:37 am
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!
Posted: Tue Oct 27, 2009 11:50 am
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