Generation Ships OXP scripting

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

Moderators: winston, another_commander

Post Reply
User avatar
Phantom Hoover
Dangerous
Dangerous
Posts: 100
Joined: Mon Mar 22, 2010 9:06 pm

Generation Ships OXP scripting

Post 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?
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 »

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);
 }
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post 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.
Post Reply