Page 1 of 1

Generation Ships OXP scripting

Posted: Wed Dec 29, 2010 3:44 pm
by Phantom Hoover
I haven't had time to test this, but it seems to me that the code for populating generation ships in interstellar space:

Code: Select all

this.shipWillExitWitchspace = function()
{
	if(!system.isInterstellarSpace) return
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-1", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-2", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-3", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-4", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-5", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-6", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-7", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-8", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-9", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-10", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-11", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-12", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-13", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-14", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-15", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-16", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-17", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-18", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-19", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-20", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-21", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-22", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-23", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-24", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-25", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-26", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-27", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-28", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-29", 1, "wpm", [0, 0, 0], 250000)
	if(Math.random() < 0.02) system.legacy_addShipsWithinRadius("generationship-30", 1, "wpm", [0, 0, 0], 250000)
}
Will add a ship with probability 0.02 30 times; i.e., there is a 1-(1-0.02)^30 ~= 0.5 probability that at least one ship will be added. This seems way too high, so am I missing something?

Posted: Wed Dec 29, 2010 5:46 pm
by Eric Walch
I haven't installed it but your addition sounds correct. And the code looks somewhat inefficient. As it is set up, it could add two ships at the same time. I thought they should be solitary. Than would it be better to use one rondom number to decide if a ship must be added and a second random number to decide which ship has to be added :

Code: Select all

this.shipWillExitWitchspace = function() 
{ 
   if(!system.isInterstellarSpace) return;
   if(Math.random() < 0.3) system.legacy_addShipsWithinRadius("generationship-"+Math.ceil(Math.random()*30), 1, "abs", [0, 0, 0], 250000);
 }

Posted: Thu Dec 30, 2010 10:02 am
by Commander McLane
That's the way Draco_Caeles wrote the populator of the original script. I merely translated it into JS. So it is intentional that you may occasionally see more than one Generation Ship (I never encountered more than two).

However, for version 1.2 (not yet released) I already reduced the single probabilities to 0.015 each. Together with the more widespread distribution of the ships (it may be spawned far away on the left behind you) this makes for encounters to get much more rare.