Bizarre locations of Stranger's World Stations

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

Moderators: another_commander, winston

User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

dybal wrote: Fri Aug 19, 2022 4:11 pm
So it was just the distance from the sun (and the fact that the solar wind was too low there) breaking immersion/verisimilitude? Were they close enough to the lane to be seen while Torusing from main station to sun?

Let us know how it goes... if using START_ORBIT* regions proves not to be satisfactory, I have a some other ways to do that (but no immediate easy way to test in my currant game)
Thank you again!

I never try to find them without ASC/Telescope (apart from the Rock Hermit at Isinor, where I have half a chance, finding anything without ASC or Telescope is too difficult for me), so I don't know the answer to this one. But they are within the sun's glare and invisible from a distance.


I hope to try your much more informed version on Sunday, so will let you know then. It is so good that you came back to us! Thank you for that too! I really missed you... (Just ask Montana05)
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Bizarre locations of Stranger's World Stations

Post by dybal »

Alnivel wrote: Fri Aug 19, 2022 5:41 pm
As it turns out, the systemWillPopulate handler (where Commies calculate the spawn position for their stations and probably many other OXPs do the same) is called before shipWillExitWitchspace (where Planetary Systems changes the position of the sun).
As a result, space objects are placed without taking into account the new positions of celestial bodies.

Rustem, the author of the original Orbits, has tweaked versions for several OXPs, including Commies where he moved the position calculation to callbacks. Another possible way to solve the problem could be to move Planetary Systems calculation execution before systemWillPopulate, but I'm not even sure if there is a suitable handler for this.
Planetary Systems could move the changes in sun position to a System Populator callback with lower priority value (101, for example) value than the priority used by the station OXPs (I guess 200), so it gets executed before the station creation - assuming there is no stale cache of planets/sun positions in the populator.

The other solution I can see is for the station OXPs' System populator callbacks to set a timer with a delay for creating the stations, and they would have to ignore the position the callback received from the populator, look for the planet, witchpoint and sun positions, and place the stations in the lane with the pseudo-randomness keyed by the systemID.

I think the first solution is easier.
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Bizarre locations of Stranger's World Stations

Post by Alnivel »

dybal wrote: Fri Aug 19, 2022 6:35 pm
Planetary Systems could move the changes in sun position to a System Populator callback with lower priority value (101, for example) value than the priority used by the station OXPs (I guess 200), so it gets executed before the station creation - assuming there is no stale cache of planets/sun positions in the populator.
It won't help, station positions are calculated not in callbacks, but in systemWillPopulate itself, any populator callback will be called later than this handler and probably even later than shipWillExitWitchspace.

Is there a way to make one script's systemWillPopulate is guaranteed to be called before all the others? If yes, then it will be possible to simply move the code from shipWillExitWitchspace from Planetary Systems into this function.
User avatar
stranger
---- E L I T E ----
---- E L I T E ----
Posts: 351
Joined: Thu Apr 05, 2018 5:31 am
Location: Vladivostok, Russia

Re: Bizarre locations of Stranger's World Stations

Post by stranger »

dybal wrote: Fri Aug 19, 2022 3:16 pm
I run Sun Gear, but I haven't tried Planetary Systems... does this mean that the OXP's planets/moons/stations relative positions change with time? (perhaps even initial populator positions based on the in-game clock?)
Yes and no. Planets/moons positions recalculates on events this.shipWillLaunchFromStation and this.shipWillExitWitchspace using in-game clock, but remains fixed during flight.
Alnivel wrote: Fri Aug 19, 2022 5:41 pm
As it turns out, the systemWillPopulate handler (where Commies calculate the spawn position for their stations and probably many other OXPs do the same) is called before shipWillExitWitchspace (where Planetary Systems changes the position of the sun).
As a result, space objects are placed without taking into account the new positions of celestial bodies.
Bingo! I omit the fact that Planetary Systems changes not only positions of additional planets/moons, but position of sun too! :oops:
User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

Ahem!

I've messed up again.

I created this:

Code: Select all

"use strict";
this.name      = "communist_population"; 
this.author    = "eric walch, dybal"; 
this.copyright = "� 2009 Dr Nil."; 
this.description = "Code for a communist_population"; 

this._shipSpawnOverride = false;
this._sourceGov = -1;
this._destGov = -1;
this._debug = false;

this.startUpComplete = function() {
    // remove the original interstellar space populator from commies (which doesn't work anyway)
    delete worldScripts.communist_population.shipWillExitWitchspace;
}

this.shipWillEnterWitchspace = function (cause) {
    this._sourceGov = system.info.government;
    this._destGov = System.infoForSystem(galaxyNumber, player.ship.nextSystem).government;
}

this.interstellarSpaceWillPopulate = function() {
    if (this._sourceGov === 4 || this._destGov === 4) {
        if (Math.random() > 0.80) {
			system.setPopulator("commies_comgrc_1", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 2);
            //system.legacy_addShips("comgrc-defender", 2);
        }
        if (Math.random() > 0.90) {
			system.setPopulator("commies_comgrc_2", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 3);
            //system.legacy_addShips("comgrc-defender", 3);
        }
    }
}

/*this.shipWillExitWitchspace = function () {
    if (system.info.government === 4) {
        if (system.isInterstellarSpace) this.witchspacePopulator()
    }
}*/

this.systemWillPopulate = function () {
    if (system.info.government !== 4) return;

	// get the witchpoint position for later calculations that replace the deprecated function "legacy_addSystemShips"
	// which works on the WP - Main Station lane. However, that lane isn't directly accessible via the "fromCoordinateSystem" functions
	// so we have to create our own lane
	var wpPos = null;
	var wp = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
	if (!wp || wp.length === 0) {
		wpPos = new Vector3D(0, 0, 0);
	} else {
		wpPos = wp.position;
	}
	
    for (var i = 0; i < 4; i++) {
		if (Math.random() > 0.50) {
			var posCom = Vector3D.interpolate(wpPos, system.mainStation.position, 0.55 + i * 0.12);
			system.setPopulator("commies_workcom_" + i, {
				location: "COORDINATES",
				coordinates: posCom,
				callback: function(pos) {
					var wc = system.addShips("workcom", 1, pos, 0);
					if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("workcom", 1, 0.55+i*0.12)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.75) {
		var pos1 = Vector3D(0, 0.45, 2.6).fromCoordinateSystem("sps");
		system.setPopulator("commies_workcom_a", {
			location: "COORDINATES",
			coordinates: pos1,
			callback: function(pos) {
				var wc = system.addShips("workcom", 1, pos, 0);
				if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("workcom", 1, "sps", [0, 0.45, 2.6]);
	}
    for (var i = 0; i < 2; i++) {
		if (Math.random() > 0.75) {
			var posLiner = Vector3D.interpolate(wpPos, system.mainStation.position, 0.3 + i * 0.05);
			system.setPopulator("commies_comliner_" + i, {
				location: "COORDINATES",
				coordinates: posLiner,
				callback: function(pos) {
					var lin = system.addShips("comlim", 1, pos, 0);
					if (!lin || lin.length === 0) log("commies.populator", "OOPS! No com liners spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("comlim", 1, 0.3+i*0.05)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.90) {
		var pos2 = Vector3D(0, 0.6, 2.8).fromCoordinateSystem("sps");
		system.setPopulator("commies_comlin_a", {
			location: "COORDINATES",
			coordinates: pos2,
			callback: function(pos) {
				var lin = system.addShips("comlim", 1, pos, 0);
				if ((!lin || lin.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com liners spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("comlim", 1, "sps", [0, 0.6, 2.8]);
	}
    if (Math.random() > 0.75) {
		var posViper = Vector3D.interpolate(wpPos, system.mainStation.position, 0.47);
		system.setPopulator("commies_comviper", {
			location: "COORDINATES",
			coordinates: posViper,
			callback: function(pos) {
				var vp = system.addShips("comviper", 5, pos, 0);
				if ((!vp || vp.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com vipers spawned");
			}}
		);
		//system.legacy_addSystemShips("comviper", 5, 0.47);
	}
    if (Math.random() > 0.10) {
		var posPol = Vector3D.interpolate(wpPos, system.mainStation.position, 0.48);
		system.setPopulator("commies_politicop", {
			location: "COORDINATES",
			coordinates: posPol,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0);
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned (1)");
			}}
		);
		//system.legacy_addSystemShips("politicop", 1, 0.48);
	}
    if (system.techLevel > 6 && Math.random() > 0.95) {
		var posPol2 = Vector3D(0, 0.45, 2.7).fromCoordinateSystem("sps");
		system.setPopulator("commies_politicop_a", {
			location: "COORDINATES",
			coordinates: posPol2,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0)[0];
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned");
			}}
		);
		//system.legacy_addShipsAt("politicop", 1, "sps", [0, 0.45, 2.7]);
	}
    if (system.techLevel > 6 && system.techLevel < 10) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
//			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
			system.setPopulator("commies_comczgf", {
//				location: "COORDINATES",
//				coordinates: posFct,
//This old stuff has been blanked out - new location follows:
			priority: 200,
			location: "STAR_ORBIT_HIGH",
			locationSeed: 67777,
			groupCount: 1,	
			deterministic: true,// and now back to the original
			callback: function(pos) {
					var fct = system.addShips("comczgf", 1, pos, 0)[0];
					if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
		//system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
	}
    if (system.techLevel > 9) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comslapu").length === 0) {
			//var posSlapu = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps"); original line
			var posSlapu = Vector3D(0, 0.20, 1.3).fromCoordinateSystem("pss"); // new line (Alnivel's)
			system.setPopulator("commies_slapu", {
				location: "COORDINATES",
				coordinates: posSlapu,
				deterministic: true,
				callback: function(pos) {
					var sla = system.addShips("comslapu", 1, pos, 0)[0];
					if ((!sla || sla.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No slapu's spawned");
				}}
			);
		}
		//system.legacy_addShipsAt("comslapu", 1, "sps", [0, 0.40, 2.6]);
	}
	// note: astromines are not spawned directly, but are set up to be the Rock Hermits in the system.
}

/*this.witchspacePopulator = function() {
    if (Math.random() > 0.80)  {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 2);
        //system.legacy_addShips("comgrc-defender", 2);
    }
    if (Math.random() > 0.90) {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 3);
        //system.legacy_addShips("comgrc-defender", 3);
    }
}*/

Which elicited this:

~/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp
23:46:59.196 [script.javaScript.exception.curlyAfterList] ReportJSError (OOJavaScriptEngine.m:204): ***** JavaScript exception (commies.js.anon-script): SyntaxError: missing } after property list
23:46:59.196 [script.javaScript.load.failed] -[OOJSScript initWithPath:properties:] (OOJSScript.m:267): ***** Error loading JavaScript script /Users/accountname/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp/Scripts/commies.js -- compilation failed
23:46:59.197 [script.load.notFound] +[OOScript scriptsFromFileNamed:] (OOScript.m:137): ***** ERROR: Could not find script file commies.js.

I presume that the fault is mine - some idiotic mistake in cut and pasting which I'm too ignorant to recognise as a mistake. My copy of SubEthaEdit does not recognise anything anymore. When I first downloaded it, it recognised errors in javascript. I moved the application out of my download folder to somewhere more sensible and it has failed to recognise anything since, despite my deleting the application and redownloading....
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Bizarre locations of Stranger's World Stations

Post by Alnivel »

Cholmondely wrote: Sat Aug 20, 2022 10:08 pm
Ahem!

I've messed up again.

I created this:

Code: Select all

"use strict";
this.name      = "communist_population"; 
this.author    = "eric walch, dybal"; 
this.copyright = "� 2009 Dr Nil."; 
this.description = "Code for a communist_population"; 

this._shipSpawnOverride = false;
this._sourceGov = -1;
this._destGov = -1;
this._debug = false;

this.startUpComplete = function() {
    // remove the original interstellar space populator from commies (which doesn't work anyway)
    delete worldScripts.communist_population.shipWillExitWitchspace;
}

this.shipWillEnterWitchspace = function (cause) {
    this._sourceGov = system.info.government;
    this._destGov = System.infoForSystem(galaxyNumber, player.ship.nextSystem).government;
}

this.interstellarSpaceWillPopulate = function() {
    if (this._sourceGov === 4 || this._destGov === 4) {
        if (Math.random() > 0.80) {
			system.setPopulator("commies_comgrc_1", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 2);
            //system.legacy_addShips("comgrc-defender", 2);
        }
        if (Math.random() > 0.90) {
			system.setPopulator("commies_comgrc_2", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 3);
            //system.legacy_addShips("comgrc-defender", 3);
        }
    }
}

/*this.shipWillExitWitchspace = function () {
    if (system.info.government === 4) {
        if (system.isInterstellarSpace) this.witchspacePopulator()
    }
}*/

this.systemWillPopulate = function () {
    if (system.info.government !== 4) return;

	// get the witchpoint position for later calculations that replace the deprecated function "legacy_addSystemShips"
	// which works on the WP - Main Station lane. However, that lane isn't directly accessible via the "fromCoordinateSystem" functions
	// so we have to create our own lane
	var wpPos = null;
	var wp = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
	if (!wp || wp.length === 0) {
		wpPos = new Vector3D(0, 0, 0);
	} else {
		wpPos = wp.position;
	}
	
    for (var i = 0; i < 4; i++) {
		if (Math.random() > 0.50) {
			var posCom = Vector3D.interpolate(wpPos, system.mainStation.position, 0.55 + i * 0.12);
			system.setPopulator("commies_workcom_" + i, {
				location: "COORDINATES",
				coordinates: posCom,
				callback: function(pos) {
					var wc = system.addShips("workcom", 1, pos, 0);
					if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("workcom", 1, 0.55+i*0.12)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.75) {
		var pos1 = Vector3D(0, 0.45, 2.6).fromCoordinateSystem("sps");
		system.setPopulator("commies_workcom_a", {
			location: "COORDINATES",
			coordinates: pos1,
			callback: function(pos) {
				var wc = system.addShips("workcom", 1, pos, 0);
				if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("workcom", 1, "sps", [0, 0.45, 2.6]);
	}
    for (var i = 0; i < 2; i++) {
		if (Math.random() > 0.75) {
			var posLiner = Vector3D.interpolate(wpPos, system.mainStation.position, 0.3 + i * 0.05);
			system.setPopulator("commies_comliner_" + i, {
				location: "COORDINATES",
				coordinates: posLiner,
				callback: function(pos) {
					var lin = system.addShips("comlim", 1, pos, 0);
					if (!lin || lin.length === 0) log("commies.populator", "OOPS! No com liners spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("comlim", 1, 0.3+i*0.05)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.90) {
		var pos2 = Vector3D(0, 0.6, 2.8).fromCoordinateSystem("sps");
		system.setPopulator("commies_comlin_a", {
			location: "COORDINATES",
			coordinates: pos2,
			callback: function(pos) {
				var lin = system.addShips("comlim", 1, pos, 0);
				if ((!lin || lin.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com liners spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("comlim", 1, "sps", [0, 0.6, 2.8]);
	}
    if (Math.random() > 0.75) {
		var posViper = Vector3D.interpolate(wpPos, system.mainStation.position, 0.47);
		system.setPopulator("commies_comviper", {
			location: "COORDINATES",
			coordinates: posViper,
			callback: function(pos) {
				var vp = system.addShips("comviper", 5, pos, 0);
				if ((!vp || vp.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com vipers spawned");
			}}
		);
		//system.legacy_addSystemShips("comviper", 5, 0.47);
	}
    if (Math.random() > 0.10) {
		var posPol = Vector3D.interpolate(wpPos, system.mainStation.position, 0.48);
		system.setPopulator("commies_politicop", {
			location: "COORDINATES",
			coordinates: posPol,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0);
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned (1)");
			}}
		);
		//system.legacy_addSystemShips("politicop", 1, 0.48);
	}
    if (system.techLevel > 6 && Math.random() > 0.95) {
		var posPol2 = Vector3D(0, 0.45, 2.7).fromCoordinateSystem("sps");
		system.setPopulator("commies_politicop_a", {
			location: "COORDINATES",
			coordinates: posPol2,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0)[0];
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned");
			}}
		);
		//system.legacy_addShipsAt("politicop", 1, "sps", [0, 0.45, 2.7]);
	}
    if (system.techLevel > 6 && system.techLevel < 10) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
//			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
			system.setPopulator("commies_comczgf", {
//				location: "COORDINATES",
//				coordinates: posFct,
//This old stuff has been blanked out - new location follows:
			priority: 200,
			location: "STAR_ORBIT_HIGH",
			locationSeed: 67777,
			groupCount: 1,	
			deterministic: true,// and now back to the original
			callback: function(pos) {
					var fct = system.addShips("comczgf", 1, pos, 0)[0];
					if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
		//system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
	}
    if (system.techLevel > 9) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comslapu").length === 0) {
			//var posSlapu = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps"); original line
			var posSlapu = Vector3D(0, 0.20, 1.3).fromCoordinateSystem("pss"); // new line (Alnivel's)
			system.setPopulator("commies_slapu", {
				location: "COORDINATES",
				coordinates: posSlapu,
				deterministic: true,
				callback: function(pos) {
					var sla = system.addShips("comslapu", 1, pos, 0)[0];
					if ((!sla || sla.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No slapu's spawned");
				}}
			);
		}
		//system.legacy_addShipsAt("comslapu", 1, "sps", [0, 0.40, 2.6]);
	}
	// note: astromines are not spawned directly, but are set up to be the Rock Hermits in the system.
}

/*this.witchspacePopulator = function() {
    if (Math.random() > 0.80)  {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 2);
        //system.legacy_addShips("comgrc-defender", 2);
    }
    if (Math.random() > 0.90) {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 3);
        //system.legacy_addShips("comgrc-defender", 3);
    }
}*/

Which elicited this:

~/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp
23:46:59.196 [script.javaScript.exception.curlyAfterList] ReportJSError (OOJavaScriptEngine.m:204): ***** JavaScript exception (commies.js.anon-script): SyntaxError: missing } after property list
23:46:59.196 [script.javaScript.load.failed] -[OOJSScript initWithPath:properties:] (OOJSScript.m:267): ***** Error loading JavaScript script /Users/accountname/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp/Scripts/commies.js -- compilation failed
23:46:59.197 [script.load.notFound] +[OOScript scriptsFromFileNamed:] (OOScript.m:137): ***** ERROR: Could not find script file commies.js.
Missing closing braces for body of callback function, parameter object and parenthesis for function call. Try this, starting at line 157.

Code: Select all

    if (system.techLevel > 6 && system.techLevel < 10) {
        if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
            //			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
            system.setPopulator("commies_comczgf", {
            //	location: "COORDINATES",
            //	coordinates: posFct,
            //This old stuff has been blanked out - new location follows:
                priority: 200,
                location: "STAR_ORBIT_HIGH",
                locationSeed: 67777,
                groupCount: 1,
                deterministic: true,// and now back to the original
                callback: function (pos) {
                    var fct = system.addShips("comczgf", 1, pos, 0)[0];
                    if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
                }
            }
            );
            //system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
        }
    }
    if (system.techLevel > 9) {
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Bizarre locations of Stranger's World Stations

Post by dybal »

Alnivel wrote: Fri Aug 19, 2022 7:18 pm
dybal wrote: Fri Aug 19, 2022 6:35 pm
Planetary Systems could move the changes in sun position to a System Populator callback with lower priority value (101, for example) value than the priority used by the station OXPs (I guess 200), so it gets executed before the station creation - assuming there is no stale cache of planets/sun positions in the populator.
It won't help, station positions are calculated not in callbacks, but in systemWillPopulate itself, any populator callback will be called later than this handler and probably even later than shipWillExitWitchspace.

Is there a way to make one script's systemWillPopulate is guaranteed to be called before all the others? If yes, then it will be possible to simply move the code from shipWillExitWitchspace from Planetary Systems into this function.
Perhaps it's not hopeless...

I think this could work:
* Planetary Systems moves the redefinition of the sun (and main planet, if changed) position to a callback with priority 101, ignoring whatever position the System Populator passes in the call
* Any OXP that positions thing relative to the sun uses a System Populator callback with priority greater than 101, and in the callback function ignores the position received as parameter from the System Populator, but recovers the sun and main planet positions (which should have been already altered by Planetary Systems) and then calculate the desired position relative to the new main planet to sun lane and places the station there.

That would require a revision of all OXPs that position thing relative to the sun though...

Thoughts?
User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

dybal wrote: Sun Aug 21, 2022 8:39 pm
Alnivel wrote: Fri Aug 19, 2022 7:18 pm
dybal wrote: Fri Aug 19, 2022 6:35 pm
Planetary Systems could move the changes in sun position to a System Populator callback with lower priority value (101, for example) value than the priority used by the station OXPs (I guess 200), so it gets executed before the station creation - assuming there is no stale cache of planets/sun positions in the populator.
It won't help, station positions are calculated not in callbacks, but in systemWillPopulate itself, any populator callback will be called later than this handler and probably even later than shipWillExitWitchspace.

Is there a way to make one script's systemWillPopulate is guaranteed to be called before all the others? If yes, then it will be possible to simply move the code from shipWillExitWitchspace from Planetary Systems into this function.
Perhaps it's not hopeless...

I think this could work:
* Planetary Systems moves the redefinition of the sun (and main planet, if changed) position to a callback with priority 101, ignoring whatever position the System Populator passes in the call
* Any OXP that positions thing relative to the sun uses a System Populator callback with priority greater than 101, and in the callback function ignores the position received as parameter from the System Populator, but recovers the sun and main planet positions (which should have been already altered by Planetary Systems) and then calculate the desired position relative to the new main planet to sun lane and places the station there.

That would require a revision of all OXPs that position thing relative to the sun though...

Thoughts?
How necessary is it? Due to failure, I don't know what the solar orbits really are, but I do know that the non-SW CZGF's & SLAPU's are so close to the sun that one is dazzled by the corona on approach. And that the corona renders them pretty much invisible. While I've failed to achieve it, I've yet to see how high-orbit should be a problem...
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

And, yet again, ignominious failure.

The code currently looks like this:

Code: Select all

"use strict";
this.name      = "communist_population"; 
this.author    = "eric walch, dybal"; 
this.copyright = "� 2009 Dr Nil."; 
this.description = "Code for a communist_population"; 

this._shipSpawnOverride = false;
this._sourceGov = -1;
this._destGov = -1;
this._debug = false;

this.startUpComplete = function() {
    // remove the original interstellar space populator from commies (which doesn't work anyway)
    delete worldScripts.communist_population.shipWillExitWitchspace;
}

this.shipWillEnterWitchspace = function (cause) {
    this._sourceGov = system.info.government;
    this._destGov = System.infoForSystem(galaxyNumber, player.ship.nextSystem).government;
}

this.interstellarSpaceWillPopulate = function() {
    if (this._sourceGov === 4 || this._destGov === 4) {
        if (Math.random() > 0.80) {
			system.setPopulator("commies_comgrc_1", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 2);
            //system.legacy_addShips("comgrc-defender", 2);
        }
        if (Math.random() > 0.90) {
			system.setPopulator("commies_comgrc_2", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 3);
            //system.legacy_addShips("comgrc-defender", 3);
        }
    }
}

/*this.shipWillExitWitchspace = function () {
    if (system.info.government === 4) {
        if (system.isInterstellarSpace) this.witchspacePopulator()
    }
}*/

this.systemWillPopulate = function () {
    if (system.info.government !== 4) return;

	// get the witchpoint position for later calculations that replace the deprecated function "legacy_addSystemShips"
	// which works on the WP - Main Station lane. However, that lane isn't directly accessible via the "fromCoordinateSystem" functions
	// so we have to create our own lane
	var wpPos = null;
	var wp = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
	if (!wp || wp.length === 0) {
		wpPos = new Vector3D(0, 0, 0);
	} else {
		wpPos = wp.position;
	}
	
    for (var i = 0; i < 4; i++) {
		if (Math.random() > 0.50) {
			var posCom = Vector3D.interpolate(wpPos, system.mainStation.position, 0.55 + i * 0.12);
			system.setPopulator("commies_workcom_" + i, {
				location: "COORDINATES",
				coordinates: posCom,
				callback: function(pos) {
					var wc = system.addShips("workcom", 1, pos, 0);
					if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("workcom", 1, 0.55+i*0.12)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.75) {
		var pos1 = Vector3D(0, 0.45, 2.6).fromCoordinateSystem("sps");
		system.setPopulator("commies_workcom_a", {
			location: "COORDINATES",
			coordinates: pos1,
			callback: function(pos) {
				var wc = system.addShips("workcom", 1, pos, 0);
				if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("workcom", 1, "sps", [0, 0.45, 2.6]);
	}
    for (var i = 0; i < 2; i++) {
		if (Math.random() > 0.75) {
			var posLiner = Vector3D.interpolate(wpPos, system.mainStation.position, 0.3 + i * 0.05);
			system.setPopulator("commies_comliner_" + i, {
				location: "COORDINATES",
				coordinates: posLiner,
				callback: function(pos) {
					var lin = system.addShips("comlim", 1, pos, 0);
					if (!lin || lin.length === 0) log("commies.populator", "OOPS! No com liners spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("comlim", 1, 0.3+i*0.05)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.90) {
		var pos2 = Vector3D(0, 0.6, 2.8).fromCoordinateSystem("sps");
		system.setPopulator("commies_comlin_a", {
			location: "COORDINATES",
			coordinates: pos2,
			callback: function(pos) {
				var lin = system.addShips("comlim", 1, pos, 0);
				if ((!lin || lin.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com liners spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("comlim", 1, "sps", [0, 0.6, 2.8]);
	}
    if (Math.random() > 0.75) {
		var posViper = Vector3D.interpolate(wpPos, system.mainStation.position, 0.47);
		system.setPopulator("commies_comviper", {
			location: "COORDINATES",
			coordinates: posViper,
			callback: function(pos) {
				var vp = system.addShips("comviper", 5, pos, 0);
				if ((!vp || vp.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com vipers spawned");
			}}
		);
		//system.legacy_addSystemShips("comviper", 5, 0.47);
	}
    if (Math.random() > 0.10) {
		var posPol = Vector3D.interpolate(wpPos, system.mainStation.position, 0.48);
		system.setPopulator("commies_politicop", {
			location: "COORDINATES",
			coordinates: posPol,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0);
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned (1)");
			}}
		);
		//system.legacy_addSystemShips("politicop", 1, 0.48);
	}
    if (system.techLevel > 6 && Math.random() > 0.95) {
		var posPol2 = Vector3D(0, 0.45, 2.7).fromCoordinateSystem("sps");
		system.setPopulator("commies_politicop_a", {
			location: "COORDINATES",
			coordinates: posPol2,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0)[0];
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned");
			}}
		);
		//system.legacy_addShipsAt("politicop", 1, "sps", [0, 0.45, 2.7]);
	}
	{if (system.techLevel > 6 && system.techLevel < 10) { // added in 0) { at start of line (Alnivel)
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
//			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
			system.setPopulator("commies_comczgf", {
//				location: "COORDINATES",
//				coordinates: posFct,
//This old stuff has been blanked out - new location follows:
			priority: 200,
			location: "STAR_ORBIT_HIGH",
			locationSeed: 67777,
			groupCount: 1,	
			deterministic: true,// and now back to the original
			callback: function(pos) {
					var fct = system.addShips("comczgf", 1, pos, 0)[0];
					if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
		//system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
	}
    if (system.techLevel > 9) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comslapu").length === 0) {
			//var posSlapu = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps"); original line
			var posSlapu = Vector3D(0, 0.20, 1.3).fromCoordinateSystem("pss"); // new line (Alnivel's)
			system.setPopulator("commies_slapu", {
				location: "COORDINATES",
				coordinates: posSlapu,
				deterministic: true,
				callback: function(pos) {
					var sla = system.addShips("comslapu", 1, pos, 0)[0];
					if ((!sla || sla.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No slapu's spawned");
				}}
			);
		}
		//system.legacy_addShipsAt("comslapu", 1, "sps", [0, 0.40, 2.6]);
	}
	// note: astromines are not spawned directly, but are set up to be the Rock Hermits in the system.
}

/*this.witchspacePopulator = function() {
    if (Math.random() > 0.80)  {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 2);
        //system.legacy_addShips("comgrc-defender", 2);
    }
    if (Math.random() > 0.90) {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 3);
        //system.legacy_addShips("comgrc-defender", 3);
    }
}*/

Error messages in latest log:
~/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp
12:34:01.117 [script.javaScript.exception.curlyAfterList] ReportJSError (OOJavaScriptEngine.m:204): ***** JavaScript exception (commies.js.anon-script): SyntaxError: missing } after property list
12:34:01.117 [script.javaScript.load.failed] -[OOJSScript initWithPath:properties:] (OOJSScript.m:267): ***** Error loading JavaScript script /Users/accountname/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp/Scripts/commies.js -- compilation failed
12:34:01.117 [script.load.notFound] +[OOScript scriptsFromFileNamed:] (OOScript.m:137): ***** ERROR: Could not find script file commies.js.


I did try faffing with it a bit. Failure there too!

Can anybody tell me where I've gone wrong - and how many Thargoids I need to sacrifice to the Witchspace Lobster to fix it?
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Alnivel
Dangerous
Dangerous
Posts: 100
Joined: Fri Jun 10, 2022 7:05 pm

Re: Bizarre locations of Stranger's World Stations

Post by Alnivel »

Cholmondely wrote: Mon Aug 22, 2022 10:04 pm
And, yet again, ignominious failure.

The code currently looks like this:

Code: Select all

"use strict";
this.name      = "communist_population"; 
this.author    = "eric walch, dybal"; 
this.copyright = "� 2009 Dr Nil."; 
this.description = "Code for a communist_population"; 

this._shipSpawnOverride = false;
this._sourceGov = -1;
this._destGov = -1;
this._debug = false;

this.startUpComplete = function() {
    // remove the original interstellar space populator from commies (which doesn't work anyway)
    delete worldScripts.communist_population.shipWillExitWitchspace;
}

this.shipWillEnterWitchspace = function (cause) {
    this._sourceGov = system.info.government;
    this._destGov = System.infoForSystem(galaxyNumber, player.ship.nextSystem).government;
}

this.interstellarSpaceWillPopulate = function() {
    if (this._sourceGov === 4 || this._destGov === 4) {
        if (Math.random() > 0.80) {
			system.setPopulator("commies_comgrc_1", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 2);
            //system.legacy_addShips("comgrc-defender", 2);
        }
        if (Math.random() > 0.90) {
			system.setPopulator("commies_comgrc_2", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 3);
            //system.legacy_addShips("comgrc-defender", 3);
        }
    }
}

/*this.shipWillExitWitchspace = function () {
    if (system.info.government === 4) {
        if (system.isInterstellarSpace) this.witchspacePopulator()
    }
}*/

this.systemWillPopulate = function () {
    if (system.info.government !== 4) return;

	// get the witchpoint position for later calculations that replace the deprecated function "legacy_addSystemShips"
	// which works on the WP - Main Station lane. However, that lane isn't directly accessible via the "fromCoordinateSystem" functions
	// so we have to create our own lane
	var wpPos = null;
	var wp = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
	if (!wp || wp.length === 0) {
		wpPos = new Vector3D(0, 0, 0);
	} else {
		wpPos = wp.position;
	}
	
    for (var i = 0; i < 4; i++) {
		if (Math.random() > 0.50) {
			var posCom = Vector3D.interpolate(wpPos, system.mainStation.position, 0.55 + i * 0.12);
			system.setPopulator("commies_workcom_" + i, {
				location: "COORDINATES",
				coordinates: posCom,
				callback: function(pos) {
					var wc = system.addShips("workcom", 1, pos, 0);
					if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("workcom", 1, 0.55+i*0.12)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.75) {
		var pos1 = Vector3D(0, 0.45, 2.6).fromCoordinateSystem("sps");
		system.setPopulator("commies_workcom_a", {
			location: "COORDINATES",
			coordinates: pos1,
			callback: function(pos) {
				var wc = system.addShips("workcom", 1, pos, 0);
				if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("workcom", 1, "sps", [0, 0.45, 2.6]);
	}
    for (var i = 0; i < 2; i++) {
		if (Math.random() > 0.75) {
			var posLiner = Vector3D.interpolate(wpPos, system.mainStation.position, 0.3 + i * 0.05);
			system.setPopulator("commies_comliner_" + i, {
				location: "COORDINATES",
				coordinates: posLiner,
				callback: function(pos) {
					var lin = system.addShips("comlim", 1, pos, 0);
					if (!lin || lin.length === 0) log("commies.populator", "OOPS! No com liners spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("comlim", 1, 0.3+i*0.05)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.90) {
		var pos2 = Vector3D(0, 0.6, 2.8).fromCoordinateSystem("sps");
		system.setPopulator("commies_comlin_a", {
			location: "COORDINATES",
			coordinates: pos2,
			callback: function(pos) {
				var lin = system.addShips("comlim", 1, pos, 0);
				if ((!lin || lin.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com liners spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("comlim", 1, "sps", [0, 0.6, 2.8]);
	}
    if (Math.random() > 0.75) {
		var posViper = Vector3D.interpolate(wpPos, system.mainStation.position, 0.47);
		system.setPopulator("commies_comviper", {
			location: "COORDINATES",
			coordinates: posViper,
			callback: function(pos) {
				var vp = system.addShips("comviper", 5, pos, 0);
				if ((!vp || vp.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com vipers spawned");
			}}
		);
		//system.legacy_addSystemShips("comviper", 5, 0.47);
	}
    if (Math.random() > 0.10) {
		var posPol = Vector3D.interpolate(wpPos, system.mainStation.position, 0.48);
		system.setPopulator("commies_politicop", {
			location: "COORDINATES",
			coordinates: posPol,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0);
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned (1)");
			}}
		);
		//system.legacy_addSystemShips("politicop", 1, 0.48);
	}
    if (system.techLevel > 6 && Math.random() > 0.95) {
		var posPol2 = Vector3D(0, 0.45, 2.7).fromCoordinateSystem("sps");
		system.setPopulator("commies_politicop_a", {
			location: "COORDINATES",
			coordinates: posPol2,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0)[0];
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned");
			}}
		);
		//system.legacy_addShipsAt("politicop", 1, "sps", [0, 0.45, 2.7]);
	}
	{if (system.techLevel > 6 && system.techLevel < 10) { // added in 0) { at start of line (Alnivel)
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
//			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
			system.setPopulator("commies_comczgf", {
//				location: "COORDINATES",
//				coordinates: posFct,
//This old stuff has been blanked out - new location follows:
			priority: 200,
			location: "STAR_ORBIT_HIGH",
			locationSeed: 67777,
			groupCount: 1,	
			deterministic: true,// and now back to the original
			callback: function(pos) {
					var fct = system.addShips("comczgf", 1, pos, 0)[0];
					if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
		//system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
	}
    if (system.techLevel > 9) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comslapu").length === 0) {
			//var posSlapu = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps"); original line
			var posSlapu = Vector3D(0, 0.20, 1.3).fromCoordinateSystem("pss"); // new line (Alnivel's)
			system.setPopulator("commies_slapu", {
				location: "COORDINATES",
				coordinates: posSlapu,
				deterministic: true,
				callback: function(pos) {
					var sla = system.addShips("comslapu", 1, pos, 0)[0];
					if ((!sla || sla.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No slapu's spawned");
				}}
			);
		}
		//system.legacy_addShipsAt("comslapu", 1, "sps", [0, 0.40, 2.6]);
	}
	// note: astromines are not spawned directly, but are set up to be the Rock Hermits in the system.
}

/*this.witchspacePopulator = function() {
    if (Math.random() > 0.80)  {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 2);
        //system.legacy_addShips("comgrc-defender", 2);
    }
    if (Math.random() > 0.90) {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 3);
        //system.legacy_addShips("comgrc-defender", 3);
    }
}*/

Error messages in latest log:
~/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp
12:34:01.117 [script.javaScript.exception.curlyAfterList] ReportJSError (OOJavaScriptEngine.m:204): ***** JavaScript exception (commies.js.anon-script): SyntaxError: missing } after property list
12:34:01.117 [script.javaScript.load.failed] -[OOJSScript initWithPath:properties:] (OOJSScript.m:267): ***** Error loading JavaScript script /Users/accountname/Library/Application Support/Oolite/AddOns/oolite.oxp.DrNil.Commies.oxp/Scripts/commies.js -- compilation failed
12:34:01.117 [script.load.notFound] +[OOScript scriptsFromFileNamed:] (OOScript.m:137): ***** ERROR: Could not find script file commies.js.


I did try faffing with it a bit. Failure there too!

Can anybody tell me where I've gone wrong - and how many Thargoids I need to sacrifice to the Witchspace Lobster to fix it?
Looks like I worded it wrong in my previous post, I'm sorry. I meant not to add brakets on the specified line, but to substitute the proposed code in the if block that starts on the specified line.

Here is the code with brackets corrected. I add comments with "<--" just to indicate where I added brackets, so feel free to remove them so they don't get in the way.

Code: Select all

"use strict";
this.name      = "communist_population"; 
this.author    = "eric walch, dybal"; 
this.copyright = "� 2009 Dr Nil."; 
this.description = "Code for a communist_population"; 

this._shipSpawnOverride = false;
this._sourceGov = -1;
this._destGov = -1;
this._debug = false;

this.startUpComplete = function() {
    // remove the original interstellar space populator from commies (which doesn't work anyway)
    delete worldScripts.communist_population.shipWillExitWitchspace;
}

this.shipWillEnterWitchspace = function (cause) {
    this._sourceGov = system.info.government;
    this._destGov = System.infoForSystem(galaxyNumber, player.ship.nextSystem).government;
}

this.interstellarSpaceWillPopulate = function() {
    if (this._sourceGov === 4 || this._destGov === 4) {
        if (Math.random() > 0.80) {
			system.setPopulator("commies_comgrc_1", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 2);
            //system.legacy_addShips("comgrc-defender", 2);
        }
        if (Math.random() > 0.90) {
			system.setPopulator("commies_comgrc_2", {
				location: "WITCHPOINT",
				callback: function(pos) {
                    system.addShips("comgrc", 1, pos);
                }}
			);
            //system.legacy_addShips("comgrc", 1);
            //system.addShips("comgrc-defender", 3);
            //system.legacy_addShips("comgrc-defender", 3);
        }
    }
}

/*this.shipWillExitWitchspace = function () {
    if (system.info.government === 4) {
        if (system.isInterstellarSpace) this.witchspacePopulator()
    }
}*/

this.systemWillPopulate = function () {
    if (system.info.government !== 4) return;

	// get the witchpoint position for later calculations that replace the deprecated function "legacy_addSystemShips"
	// which works on the WP - Main Station lane. However, that lane isn't directly accessible via the "fromCoordinateSystem" functions
	// so we have to create our own lane
	var wpPos = null;
	var wp = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
	if (!wp || wp.length === 0) {
		wpPos = new Vector3D(0, 0, 0);
	} else {
		wpPos = wp.position;
	}
	
    for (var i = 0; i < 4; i++) {
		if (Math.random() > 0.50) {
			var posCom = Vector3D.interpolate(wpPos, system.mainStation.position, 0.55 + i * 0.12);
			system.setPopulator("commies_workcom_" + i, {
				location: "COORDINATES",
				coordinates: posCom,
				callback: function(pos) {
					var wc = system.addShips("workcom", 1, pos, 0);
					if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("workcom", 1, 0.55+i*0.12)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.75) {
		var pos1 = Vector3D(0, 0.45, 2.6).fromCoordinateSystem("sps");
		system.setPopulator("commies_workcom_a", {
			location: "COORDINATES",
			coordinates: pos1,
			callback: function(pos) {
				var wc = system.addShips("workcom", 1, pos, 0);
				if ((!wc || wc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No worker's commuters spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("workcom", 1, "sps", [0, 0.45, 2.6]);
	}
    for (var i = 0; i < 2; i++) {
		if (Math.random() > 0.75) {
			var posLiner = Vector3D.interpolate(wpPos, system.mainStation.position, 0.3 + i * 0.05);
			system.setPopulator("commies_comliner_" + i, {
				location: "COORDINATES",
				coordinates: posLiner,
				callback: function(pos) {
					var lin = system.addShips("comlim", 1, pos, 0);
					if (!lin || lin.length === 0) log("commies.populator", "OOPS! No com liners spawned (1)");
				}}
			);
			//system.legacy_addSystemShips("comlim", 1, 0.3+i*0.05)
		}
	};
    if (system.techLevel > 6 && Math.random() > 0.90) {
		var pos2 = Vector3D(0, 0.6, 2.8).fromCoordinateSystem("sps");
		system.setPopulator("commies_comlin_a", {
			location: "COORDINATES",
			coordinates: pos2,
			callback: function(pos) {
				var lin = system.addShips("comlim", 1, pos, 0);
				if ((!lin || lin.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com liners spawned (a)");
			}}
		);
		//system.legacy_addShipsAt("comlim", 1, "sps", [0, 0.6, 2.8]);
	}
    if (Math.random() > 0.75) {
		var posViper = Vector3D.interpolate(wpPos, system.mainStation.position, 0.47);
		system.setPopulator("commies_comviper", {
			location: "COORDINATES",
			coordinates: posViper,
			callback: function(pos) {
				var vp = system.addShips("comviper", 5, pos, 0);
				if ((!vp || vp.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No com vipers spawned");
			}}
		);
		//system.legacy_addSystemShips("comviper", 5, 0.47);
	}
    if (Math.random() > 0.10) {
		var posPol = Vector3D.interpolate(wpPos, system.mainStation.position, 0.48);
		system.setPopulator("commies_politicop", {
			location: "COORDINATES",
			coordinates: posPol,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0);
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned (1)");
			}}
		);
		//system.legacy_addSystemShips("politicop", 1, 0.48);
	}
    if (system.techLevel > 6 && Math.random() > 0.95) {
		var posPol2 = Vector3D(0, 0.45, 2.7).fromCoordinateSystem("sps");
		system.setPopulator("commies_politicop_a", {
			location: "COORDINATES",
			coordinates: posPol2,
			callback: function(pos) {
				var pc = system.addShips("politicop", 1, pos, 0)[0];
				if ((!pc || pc.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No politicops spawned");
			}}
		);
		//system.legacy_addShipsAt("politicop", 1, "sps", [0, 0.45, 2.7]);
	}
	if (system.techLevel > 6 && system.techLevel < 10) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comczgf").length === 0) {
//			var posFct = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps");
			system.setPopulator("commies_comczgf", {
//				location: "COORDINATES",
//				coordinates: posFct,
//This old stuff has been blanked out - new location follows:
				priority: 200,
				location: "STAR_ORBIT_HIGH",
				locationSeed: 67777,
				groupCount: 1,	
				deterministic: true,// and now back to the original
				callback: function(pos) {
						var fct = system.addShips("comczgf", 1, pos, 0)[0];
						if ((!fct || fct.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No factories spawned");
				}} // <-- missing closing braces for callback body and parameters object was here
			); // <-- missing closing parenthesis for function call was here
		//system.legacy_addShipsAt("comczgf", 1, "sps", [0, 0.40, 2.6]);
		} // <-- missing closing brace for inner if block was here
	}
    if (system.techLevel > 9) {
		if (!worldScripts.station_validator || worldScripts.station_validator.$deaths("comslapu").length === 0) {
			//var posSlapu = Vector3D(0, 0.40, 2.6).fromCoordinateSystem("sps"); original line
			var posSlapu = Vector3D(0, 0.20, 1.3).fromCoordinateSystem("pss"); // new line (Alnivel's)
			system.setPopulator("commies_slapu", {
				location: "COORDINATES",
				coordinates: posSlapu,
				deterministic: true,
				callback: function(pos) {
					var sla = system.addShips("comslapu", 1, pos, 0)[0];
					if ((!sla || sla.length === 0) && worldScripts.communist_population._debug === true) log("commies.populator", "OOPS! No slapu's spawned");
				}}
			);
		}
		//system.legacy_addShipsAt("comslapu", 1, "sps", [0, 0.40, 2.6]);
	}
	// note: astromines are not spawned directly, but are set up to be the Rock Hermits in the system.
}

/*this.witchspacePopulator = function() {
    if (Math.random() > 0.80)  {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 2);
        //system.legacy_addShips("comgrc-defender", 2);
    }
    if (Math.random() > 0.90) {
		system.addShips("comgrc", 1);
        //system.legacy_addShips("comgrc", 1);
		system.addShips("comgrc-defender", 3);
        //system.legacy_addShips("comgrc-defender", 3);
    }
}*/
User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

Alnivel, thank you.

I'm embarrassed to have to say that, despite having driven you desperately dotty, the new code seems to make absolutely no difference! The CZGF duly appeared, some 30,000-odd km from the orbital station and also some 30,000-odd km from the star (which was also some 30,000km from the station).

But the HIMSN code (which this was cribbed from) works for the HIMSN stations. I originally suspected that it might be due to the location seed. Changing it and then deleting it made little difference.

Unless Stranger's code moves the star twice and the CZGF was stuck into "high orbit" around the first such move, I fail to understand what is going wrong. Might it be more hypothetical code elsewhere in Commies trying to stop the CZGF burning up in too close orbit?

Distances:
First try (Alnivels code with location seed of 67777): star was 30,000km from station, CZGF was quite distant and also 32,000km from station.
Second try (different location seed - 60000): star was 30,000km from station, CZGF in a slightly different location and some 35,000km from station.
Third try (no location seed): star was 30,000km from station, CZGF was 36,000km from station and in another slightly different some 26,000km from the star...
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16059
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cody »

You have now entered the Twilight Zone! Beware, young Cholly - should you venture into the Darkside, there is no turning back! You would be forever lost in the game-within-the-game, and your happy days as a dumb pilot will become nothing more than a distant memory!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Bizarre locations of Stranger's World Stations

Post by dybal »

Cholmondely wrote: Tue Aug 23, 2022 3:24 pm
Alnivel, thank you.

I'm embarrassed to have to say that, despite having driven you desperately dotty, the new code seems to make absolutely no difference! The CZGF duly appeared, some 30,000-odd km from the orbital station and also some 30,000-odd km from the star (which was also some 30,000km from the station).

But the HIMSN code (which this was cribbed from) works for the HIMSN stations. I originally suspected that it might be due to the location seed. Changing it and then deleting it made little difference.

Unless Stranger's code moves the star twice and the CZGF was stuck into "high orbit" around the first such move, I fail to understand what is going wrong. Might it be more hypothetical code elsewhere in Commies trying to stop the CZGF burning up in too close orbit?

Distances:
First try (Alnivels code with location seed of 67777): star was 30,000km from station, CZGF was quite distant and also 32,000km from station.
Second try (different location seed - 60000): star was 30,000km from station, CZGF in a slightly different location and some 35,000km from station.
Third try (no location seed): star was 30,000km from station, CZGF was 36,000km from station and in another slightly different some 26,000km from the star...
As Alnivel has said, Planetary Systems is moving the sun in shipWillExitWitchspace, and that happens *after* the system populator calls the callbacks... that means the sun position that "defined" the positions used by the callbacks to create the stations are based on the old, "original" sun position.

I see two ways to deal with that:

* Planetary Systems moving the sun relocation to a high priority system populator callback (lower priority number) and the callbacks that place stations relative to the sun retrieving the sun position explicitly in the callback body (instead of using the position received from the system populator) and using it as base for the station placement

or

* duplicating the code used by Planetary Systems to calculate the new sun position in those callbacks that place stations relative to the sun, so even if called before Planetary Systems redefines the sun position they place the stations relative to where the sun will be after Planetary Systems has its say...
User avatar
Cholmondely
Archivist
Archivist
Posts: 4999
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Bizarre locations of Stranger's World Stations

Post by Cholmondely »

dybal wrote: Tue Aug 23, 2022 4:26 pm
As Alnivel has said, Planetary Systems is moving the sun in shipWillExitWitchspace, and that happens *after* the system populator calls the callbacks... that means the sun position that "defined" the positions used by the callbacks to create the stations are based on the old, "original" sun position.

I see two ways to deal with that:

* Planetary Systems moving the sun relocation to a high priority system populator callback (lower priority number) and the callbacks that place stations relative to the sun retrieving the sun position explicitly in the callback body (instead of using the position received from the system populator) and using it as base for the station placement

or

* duplicating the code used by Planetary Systems to calculate the new sun position in those callbacks that place stations relative to the sun, so even if called before Planetary Systems redefines the sun position they place the stations relative to where the sun will be after Planetary Systems has its say...
Umm - it can't quite be the original sun position - that would be much, much closer to the planet/main orbital, no?

But I had mentioned some time ago that I'd seen two fake suns highlighted at Riredi:
Littlebear (#3, above): ...Stranger's World makes no checks that another OXZ has added moons or planets. This is why you got the three suns issue at Riredi. All other OXZs including very old ones such as Lave, Diso and Riredi add planets / moons on start up. On launching Strangers World adds its own moons / planets and moves them, but makes no checks for existing OXZ added planets or moons. It can therefore move a planet to a space occupied by an existing planet or moon. Oolite won't let two objects occupy the same space, so the moon or planet added by another OXZ is destroyed, but its beacon remains as a 'Ghost'. I worked round this in the Almanac by naming broken beacons "Cosmic Strings" and then excluding them from the ASC, F4 Screen and MFD. This fixes the problem, but moons and planets added by other OXZs are still removed from the game. That is quite a major problem when missions have been scripted to add targets near a planet or moon. The ships will still appear at the co-ordinates, but as the mission text refers to a planet which no longer exists the player has no way to find the ship and no idea where to look.

If I understand what I found inside SunGear, Stranger hand-positioned every single sun in each of the 8 galaxies...

Code: Select all

	"0 0" = {
		"sun_radius" = 900000;
		"sun_distance" = 34125780;
		"sun_color" = "0.999 0.782 0.611 1";
	};
	"0 1" = {
		"sun_radius" = 939961;
		"sun_distance" = 40311580;
		"sun_color" = "0.999 0.817 0.667 1";
	};
	"0 2" = {
		"sun_radius" = 829922;
		"sun_distance" = 30520420;
		"sun_color" = "0.999 0.721 0.520 1";
	};
	"0 3" = {
		"sun_radius" = 679883;
		"sun_distance" = 17388740;
		"sun_color" = "0.999 0.591 0.349 1";
	};
Maybe there is also an older, more generic sun-moving code elsewhere tucked away inside his magnum opus... that might account for the confusion... I don't see anything in my current cocktail of oxp's which would obviously move the sun...

But if one tweaks with Stranger's code, might it make sense to do it in such a way that LittleBear's Galactic Almanac registers the SW solar systems before launching from a station in a reloaded game? It would also make sense to tweak it so that his in-system cargo delivery oxp recognises the Galactic Almanac replacements for Thargoid's Planetary Compass.

My apologies, gentlemen. I had no idea that this issue would prove to be so intractable!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Bizarre locations of Stranger's World Stations

Post by dybal »

dybal wrote: Tue Aug 23, 2022 4:26 pm
<snip>
As Alnivel has said, Planetary Systems is moving the sun in shipWillExitWitchspace, and that happens *after* the system populator calls the callbacks... that means the sun position that "defined" the positions used by the callbacks to create the stations are based on the old, "original" sun position.

I see two ways to deal with that:

* Planetary Systems moving the sun relocation to a high priority system populator callback (lower priority number) and the callbacks that place stations relative to the sun retrieving the sun position explicitly in the callback body (instead of using the position received from the system populator) and using it as base for the station placement

or

* duplicating the code used by Planetary Systems to calculate the new sun position in those callbacks that place stations relative to the sun, so even if called before Planetary Systems redefines the sun position they place the stations relative to where the sun will be after Planetary Systems has its say...
I was wrong, those alternatives would not work...

I looked at the Planetary Systems code... it adjusts the planetary system objects' positions every time the player launches from a station to simulate those objects moving along their orbits.

The trouble is: in Oolite, the witchpoint is the origin of the coordinate system and the main station MUST be deterministic (i.e., its coordinates MUST NOT change), so the main planet's (always near the main station) coordinates can't change much... that means that THE SUN must change coordinates to give the impression the main planet is moving around in its orbit... and that is being done every time the player launches...

In a nutshell: moving other OXPs' "relative to the sun" or "relative to the main planet to sun lane" stations as the sun is moved would involve each of those OXPs creating a callback to reposition its station(s) and supplying it to Planetary Systems so it could call them once the sun is moved, and those OXPs' stations would not be deterministic - the player would not be able to save the game there.
Post Reply