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

Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

Re: ..

Post by Screet »

Lestradae wrote:
This is a weird mix.

The fer-de-lance was the Constitution's mother? As the latter can only come from OSE on your system, that's impossible. They are never ever escorts?

UPS attacking Random Hits with an OSE ship in tow. Bizarre.

A friendly fire chain reaction perhaps?
The consitution I don't know about, it suddenly was gone while I was still fighting the asps...the asps had this upsescort script and were attacking in a way I've never seen before. I only noticed that these belong to the ferdy because I did shift-h them, but I shot down the ferdy before I checked the log and it wasn't flying that close together with the asps. You can see it on the screenshot - I did not notice it during that situation!
Image

Screet
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 »

Screet wrote:
Is UPS now attacking space bars?


Sadly, I shot down their master too early to know which AI he had to begin that attack. It was a pretty impressive sight and strangely the bar did have defenders in the air...there were a few yellow blips, but they did not fight these ships!

Screet
His master is a fer de lance and has the roleset:

Code: Select all

roles = "ups_pirate_leader hardpirate";
It is one of the more tricky pirates in ups therefor I also gave it a hardpirate role. So it could have been another oxp that called this one. ups itself calls him only for one or two special missions.
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 »

Eric Walch wrote:
It is one of the more tricky pirates in ups therefor I also gave it a hardpirate role. So it could have been another oxp that called this one. ups itself calls him only for one or two special missions.
That hardpirate thing would well explain why they attacked the space bar! It was really a strange thing to happen, especially these asps flying like they've been set up to attack the bar on purpose. Never seen anything like that before, they would not even turn hostile to me but try to shoot down the bar, approaching slowly and continuous lasering it instead of the usual NPC flying style...and as you can see on the screenshot, they pretty nicely flew in formation!

Screet
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 »

In some systems I do get the same target systems with the same victim name, ship and description almost 100% of the time. I really do wonder who is resurrecting these people...

I'm not sure if RH does determine these things similar to galactic navy, but that oxp also had a similar problem. I fixed it by using a slight modification to the code, based upon the clock:

Code: Select all

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

this.ReserveDutySystemDeterminationPt2 = function()
{
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 »

Curses: should have replied, not edited
Last edited by pmw57 on Mon Oct 26, 2009 10:29 pm, edited 2 times in total.
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 »

pmw57 wrote:
How on earth does that solve the problem? It looks more like a hack that relies on a side-effect.
It's a fix for Galactic Navy, put probably Random Hits does something similar.

The original code does use the many switches to determine the target system. That's done randomly from an array - but since random numbers in Oolite are pretty reproducible, it often happens that the player will get the same mission at the same target planet again and again.

By simply taking the current time into account to have the system being determined randomly multiple times it does change these numbers, not only for the target system but also for other things to happen ;)

Random Hits could probably do something as simple as to use the current seconds to request a random number up to seconds times just in order to get more different random numbers on later usage of random numbers ;)

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:
By simply taking the current time into account to have the system being determined randomly multiple times it does change these numbers, not only for the target system but also for other things to happen ;)
I added the ps. part on up above, but I'll reiterate here for clarity.

The method now takes on average, 30 time longer to run. Sometimes nearly 60 times longer!! :evil:
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 »

pmw57 wrote:
The method now takes on average, 30 time longer to run. Sometimes nearly 60 times longer!! :evil:
So what? It's not noticeable. All it executes is one line!

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:
pmw57 wrote:
The method now takes on average, 30 time longer to run. Sometimes nearly 60 times longer!! :evil:
So what? It's not noticeable. All it executes is one line!

Screet
The original this.ReserveDutySystemDetermination method consists of 738 lines of code. It's a large switch statement (that really needs to be rewritten) that is determined entirely upon galaxyNumber and system.ID

From what I see in that piece of code, its behaviour will not change no matter how many times it is run.
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 »

Screet wrote:
So what? It's not noticeable. All it executes is one line!
Err, if I may... You might have noticed that trunk is more responsive than 1.73.4
Why? Because we do remove inefficient code when we find it, and replace it with faster one. If you make changes that slow down oxps & Oolite, sooner or later - and my bet is sooner - you'll start to notice that the gameplay itself is compromised.

However, if you're happy to create inefficient code, or make not-that-efficient code more inefficient, I suppose it's really up to you. And yes, on average executing a 738 instruction 'one-liner' 30 times makes that part of the code 30 times slower than before, and is the equivalent of running 22140 lines.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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:
The original this.ReserveDutySystemDetermination method consists of 738 lines of code. It's a large switch statement (that really needs to be rewritten) that is determined entirely upon galaxyNumber and system.ID

From what I see in that piece of code, its behaviour will not change no matter how many times it is run.
When you want better random system numbers, those numbers should not be selected from the description.plist but selected with Math.random() from a number array within the JS script.

I think that the bad randomness of numbers is caused by patrolling police ships regularly asking for the witchpoint coordinates. To calculate that position it needs to reset one of the random seeds.
Last edited by Eric Walch on Mon Oct 26, 2009 9:29 pm, edited 1 time in total.
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:
Screet wrote:
And yes, on average executing a 738 instruction 'one-liner' 30 times makes that part of the code 30 times slower than before, and is the equivalent of running 22140 lines.
Well if it helps, here is a 20-line version for galnavymain.js instead of the 738-line one.

Code: Select all

this.ReserveDutySystemDetermination = function ()
{
	// sector is organised as [galaxy][system]
	var galaxySectors = [
		[0, 24, 193, 154, 188, 125, 109, 249, 150, 80, 175, 120, 220, 158, 15],
		[0, 248, 135, 106, 82, 150, 182, 33, 48, 227, 96, 127, 202, 243, 170],
		[0, 31, 165, 245, 84, 36, 21, 26, 139, 251, 205, 223, 204, 17, 247],
		[0, 39, 221, 188, 86, 9, 57, 186, 237, 49, 103, 254, 66, 140, 110],
		[0, 249, 71, 57, 144, 198, 153, 204, 73, 102, 222, 29, 233, 152, 190],
		[0, 151, 227, 6, 51, 60, 129, 8, 53, 85, 120, 208, 220, 146, 66],
		[0, 214, 161, 250, 127, 23, 154, 234, 24, 55, 64, 231, 140, 202, 35],
		[0, 26, 218, 9, 174, 156, 251, 75, 136, 184, 87, 212, 116, 98, 55]
	],
		sector = galaxySectors[galaxyNumber].indexOf(system.ID),
		description = 0;
	if (sector > 0) {
		description = expandDescription('[galaxy' + galaxyNumber + '_sector' + sector + ']');
	}
	missionVariables.reserve_planetnum = description;
};
Last edited by pmw57 on Mon Oct 26, 2009 9:46 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
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:
The original this.ReserveDutySystemDetermination method consists of 738 lines of code. It's a large switch statement (that really needs to be rewritten) that is determined entirely upon galaxyNumber and system.ID

From what I see in that piece of code, its behaviour will not change no matter how many times it is run.
It does change it, try that modification which I did post and then add a message to log the target systems number each time this is run ;)

Most probably, it would have been enough to simply request a random number and then finally call that other method once.

It's just when I did make that modification several months ago (for a much slower oolite version, BTW) I did want something which I could quickly do without much knowledge about those things.

As to the question of slowing things down, it's only run once when the player is docked and requests a new mission - and really, even on the much slower computer I had then with the much slower Oolite I was running then I did not notice any change in responsiveness ;)

Guess it's all simply running inside of the cache anyway, and although the switches are there, it's not that all those lines inside there would be executed: First you can divide it by 8 due to the galaxy switch and then it's still only checking values, which also is pretty fast, until it finally found the proper planet where it then only has to execute one line.

Of course, your shorter version does look much nicer. Would have to test, though, if it's also creating the desired 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:
It does change it, try that modification which I did post and then add a message to log the target systems number each time this is run ;)
So that we're on the same page, are these changes being made to galnavymain.js ?
Last edited by pmw57 on Mon Oct 26, 2009 9:54 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
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:
Screet wrote:
It does change it, try that modification which I did post and then add a message to log the target systems number each time this is run ;)
So that we're on the same page, are these changes being made to galnavymain.js ?
[/quote]

I made them to my local version of that file, yes. It's simply something which I thought I should suggest now, as it's a simple modification that solves the only problem there and I also did post it here because Random Hits suffers from the same problem (although I did not yet look at the cause). Really, most previous messages would have better been written in the GalNavy thread ;)

What I did to ensure that it's really changing the values selected, I did add something like
log("GalNavy",missionVariables.reserve_planetnum);
temporarily. When the selection is done multiple times, there's also a different random value being used for the mission selection, thus it's also helping to get more different missions, not only more different target systems.

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 ;)

If, as Eric writes, the Random Seed is reset during flight, RH most probably also would only require to use time or something like that to request random numbers it ignores before it begins to use some. That's (for seconds) at least giving 60x more diversity :)

Screet
Post Reply