legacy_addShipsWithinRadius and 1.72

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

legacy_addShipsWithinRadius and 1.72

Post by Thargoid »

I'm trying a script on 1.72 that used to work on 1.71.2, and it's giving some weird things (under WinXP). The original line is

Code: Select all

system.legacy_addShipsWithinRadius("aquatics_pHauler", 1, "wpu", 0, 0, zloc, 10000);
where zloc is defined a couple of lines up the script. This worked under 1.71.2, but under 1.72 I get the following warning in the debug console
Warning: The ability to pass three numbers instead of a vector is deprecated and will be removed in a future version of Oolite. Use an array literal instead (for instance, replace v.add(1, 2, z) with v.add([1, 2, z]).
Active script: "aquatics_systemSetUp" 0.1
aquatics_systemSetUp.js, line 23:
system.legacy_addShipsWithinRadius("aquatics_pHauler", 1, "wpu", 0, 0, zloc, 10000);
However if I try and add square brackets around the 0, 0, zloc part I get the following log error (and no spawned ship):
[script.addShips.failed]: SCRIPT ERROR in <anonymous actions> ***** CANNOT 'addShipsWithinRadius: aquatics_pHauler 1 wpu 0.000000 0.000000 0.150052 10000.000000' (should be 'addShipsWithinRadius: role number coordinate_system x y z r')
So I've got a warning telling me one thing, and then an error telling me no, go back to how you were :roll:

Any clues from anyone who knows these things?
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

I've just tried it on my computer and it works very well (XP). I would say post the line with the brackets.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: legacy_addShipsWithinRadius and 1.72

Post by Eric Walch »

Thargoid wrote:
I'm trying a script on 1.72 that used to work on 1.71.2, and it's giving some weird things (under WinXP). The original line is

Code: Select all

system.legacy_addShipsWithinRadius("aquatics_pHauler", 1, "wpu", 0, 0, zloc, 10000);
It must be: [0, 0, zloc], not [0, 0, zloc,]
(This seems the only logical error you can make)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

That's what I was using, this snippet:

Code: Select all

{
let zloc = 0.1 + (Math.random() * 0.8); // add hauler between 10% and 90% of the way between witchpoint and planet within a 10km axial radius.
if(Math.random() < 0.25)
	{
	system.legacy_addShipsWithinRadius("aquatics_wHauler", 1, "wpu", [0, 0, zloc], 10000);
	}
else
	{
	system.legacy_addShipsWithinRadius("aquatics_pHauler", 1, "wpu", [0, 0, zloc], 10000);
	system.mainStation.switchAI("aquatics_stationAI.plist");
	}
}
and it chokes on me. Perhaps it's using the variable in there? However the log error shows the variable is being parsed correctly :roll:
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

without really knowing what i'm on about, maybe it should look like this:

([0, 0, zloc])

with curly brackets as well as the square ones?
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 »

No, curly brackets are not needed.

Try to replace zloc with this.zloc, in order to avoid a problem with a local variable.

Another possible source of error: Does 'aquatics_pHauler' actually exist as role? Perhaps the problem is in shipdata?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

It does, I can spawn it "manually" via the console (using player.ship.spawn), and as I said it used to work under 1.71.2 (although it is using a template-style "mother-entity", will have to confirm it's not a weird incarnation of the is_template issue, although I don't think I used that in this script).

I'll try the this.zloc idea when I get chance and see if that helps, it's a good idea. Weird one though.
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 »

McLane is right, it is a wrong role you are using. All other thing I see are correct. I spawned a ship without problems or errors, but when I used a fake role I got:

Code: Select all

Oolite [script.addShips.failed] -[PlayerEntity(Scripting) addShipsWithinRadius:] (PlayerEntityLegacyScriptEngine.m:1644): SCRIPT ERROR in <anonymous actions> ***** CANNOT 'addShipsWithinRadius: leviathan-pirates 1 wsp 0.000000 0.000000 1.000000 5000.000000' (should be 'addShipsWithinRadius: role number coordinate_system x y z r')
In this case the error report is not helping to much.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The shipdata.plist is below. The ship entries you want are towards the bottom, the ones above are the sub-entities and template ships.

Basically there are two new haulers (the Orca and the HammerHead), and two variants on each, prefixed p and w. These have their destinations as either the planet (main station) or witchpoint respectively (different AIs).

The second role in each is the aquatics_wHauler or aquatics_pHauler role. Or does addWithinRadius in 1.72 now only work with primary roles, in contrast to 1.71.2 which was any listed role? And if the roles are wrong, why does the ship actually spawn in the first version in my original post (the one that gives the JS console warning)? I'm something of a confused alien this afternoon... :twisted:

Code: Select all

{
	"aquatics_orcaHauler_template" = {
	bounty = 0;
	cargo_type = "CARGO_NOT_CARGO";
	exhaust = ( 
		"-488.791 -188.253 -1746.028 44 44 500", 
		"487.906 -188.253 -1746.028 44 44 500",
		"-424.248, -45.080 678.394 30 30 200",
		"424.044, -45.080 678.394 30 30 200" 
		);
	forward_weapon_type = "WEAPON_MILITARY_LASER";
	weapon_position_forward = "-0.463 46.586 1980.445";
	aft_weapon_type = "WEAPON_MILITARY_LASER";
	weapon_position_aft = "-0.463 275.753 -1647.596";
	equipment_price_factor = 1.5;
	has_ecm = true;
	has_npc_traffic = true;
	isCarrier = true;
	likely_cargo = 200;
	max_cargo = 5000;
	energy_recharge_rate = 20;
	max_energy = 2000;
	max_flight_pitch = 1;
	max_flight_roll = 1;
	max_flight_speed = 100;
	model = "aquatics_haulerOrca.dat";
	name = "Orca Heavy Hauler";
	roles = "aquatics_orcaTemplate";
	thrust = 20;
	laser_color = "blueColor";
	frangible = false;
	subentities = ( 
		"aquatics_hauler_Dock 0.462887 83.044776 -1766.18531 1 0 0 0", 
		"aquatics_haulerRedPod -151.911478 242.052437 771.765309 1 0 0 0",
		"aquatics_haulerRedPod 151.544131 242.052437 771.765309 1 0 0 0",
		"aquatics_haulerRedPod 151.544131 -58.532062 771.765309 1 0 0 0",
		"aquatics_haulerRedPod -151.911478 -58.532062 771.765309 1 0 0 0",
		"aquatics_haulerBluePod -151.911478 242.052437 368.587143 1 0 0 0",
		"aquatics_haulerBluePod 151.544131 242.052437 368.587143 1 0 0 0",
		"aquatics_haulerBluePod 151.544131 -58.532062 368.587143 1 0 0 0",
		"aquatics_haulerBluePod -151.911478 -58.532062 368.587143 1 0 0 0",
		"aquatics_haulerGreenPod -151.911478 242.052437 -36.630584 1 0 0 0",
		"aquatics_haulerGreenPod 151.544131 242.052437 -36.630584 1 0 0 0",
		"aquatics_haulerGreenPod 151.544131 -58.532062 -36.630584 1 0 0 0",
		"aquatics_haulerGreenPod -151.911478 -58.532062 -36.630584 1 0 0 0",
		"aquatics_haulerPurplePod -151.911478 242.052437 -441.559828 1 0 0 0",
		"aquatics_haulerPurplePod 151.544131 242.052437 -441.559828 1 0 0 0",
		"aquatics_haulerPurplePod 151.544131 -58.532062 -441.559828 1 0 0 0",
		"aquatics_haulerPurplePod -151.911478 -58.532062 -441.559828 1 0 0 0"
		 );
	escort-ship = "aquatics_MantaRay";
	escorts = 4;
	beacon = "Hauler";
	};

	"aquatics_hammerHeadHauler_template" = {
	bounty = 0;
	cargo_type = "CARGO_NOT_CARGO";
	exhaust = ( 
		"-534.204 -0.292 -1423.658 150 50 50 500",
		"532.462 -0.292 -1423.658 150 50 50 500" 
		);
	forward_weapon_type = "WEAPON_MILITARY_LASER";
	weapon_position_forward = "-0.871 -0.292 1576.342";
	aft_weapon_type = "WEAPON_MILITARY_LASER";
	weapon_position_aft = "-0.871 99.708 -1523.658";
	equipment_price_factor = 1.5;
	has_ecm = true;
	has_npc_traffic = true;
	isCarrier = true;
	likely_cargo = 200;
	max_cargo = 5000;
	energy_recharge_rate = 20;
	max_energy = 2000;
	max_flight_pitch = 1;
	max_flight_roll = 1;
	max_flight_speed = 100;
	model = "aquatics_haulerHammerHead.dat";
	name = "HammerHead Heavy Hauler";
	roles = "aquatics_hammerHeadTemplate";
	thrust = 20;
	laser_color = "blueColor";
	frangible = false;
	subentities = ( 
		"aquatics_hauler_Dock -0.97114 -0.291829 -1473.658047 1 0 0 0",
		"aquatics_haulerRedPod 606.901723 0.291829 873.128215 1 0 0 0",
		"aquatics_haulerRedPod 305.130638 0.291829 873.128215 1 0 0 0",
		"aquatics_haulerRedPod -305.188394 0.291829 873.128215 1 0 0 0",
		"aquatics_haulerRedPod -608.644033 0.291829 873.128215 1 0 0 0",
		"aquatics_haulerBluePod 606.901723 0.291829 275.440582 1 0 0 0",
		"aquatics_haulerBluePod 305.130638 0.291829 275.440582 1 0 0 0",
		"aquatics_haulerBluePod -305.188394 0.291829 275.440582 1 0 0 0",
		"aquatics_haulerBluePod -608.644033 0.291829 275.440582 1 0 0 0",
		"aquatics_haulerGreenPod 606.901723 0.291829 -327.688411 1 0 0 0",
		"aquatics_haulerGreenPod 305.130638 0.291829 -327.688411 1 0 0 0",
		"aquatics_haulerGreenPod -305.188394 0.291829 -327.688411 1 0 0 0",
		"aquatics_haulerGreenPod -608.644033 0.291829 -327.688411 1 0 0 0",
		"aquatics_haulerPurplePod 606.901723 0.291829 -925.81212 1 0 0 0",
		"aquatics_haulerPurplePod 305.130638 0.291829 -925.81212 1 0 0 0",
		"aquatics_haulerPurplePod -305.188394 0.291829 -925.81212 1 0 0 0",
		"aquatics_haulerPurplePod -608.644033 0.291829 -925.81212 1 0 0 0"
		 );
	escort-ship = "aquatics_MantaRay";
	escorts = 4;
	beacon = "Hauler";
	};
	
	"aquatics_hauler_Dock" = {
	energy_recharge_rate = 20;
	max_energy = 2000;
	ai_type = "nullAI.plist";
	forward_weapon_type = "WEAPON_NONE";
	model = "aquatics_haulerDock.dat";
	name = "Aquatics Hauler Dock";
	roles = "dock";	
	};

	"aquatics_haulerRedPod" = {
	energy_recharge_rate = 20;
	max_energy = 2000;
	ai_type = "nullAI.plist";
	forward_weapon_type = "WEAPON_NONE";
	model = "aquatics_haulerRedPod.dat";
	name = "Red Pod";
	roles = "aquatics_haulerRedPod";	
	};
	
	"aquatics_haulerBluePod" = {
	energy_recharge_rate = 20;
	max_energy = 2000;
	ai_type = "nullAI.plist";
	forward_weapon_type = "WEAPON_NONE";
	model = "aquatics_haulerBluePod.dat";
	name = "Blue Pod";
	roles = "aquatics_haulerBluePod";	
	};

	"aquatics_haulerGreenPod" = {
	energy_recharge_rate = 20;
	max_energy = 2000;
	ai_type = "nullAI.plist";
	forward_weapon_type = "WEAPON_NONE";
	model = "aquatics_haulerGreenPod.dat";
	name = "Green Pod";
	roles = "aquatics_haulerGreenPod";	
	};

	"aquatics_haulerPurplePod" = {
	energy_recharge_rate = 20;
	max_energy = 2000;
	ai_type = "nullAI.plist";
	forward_weapon_type = "WEAPON_NONE";
	model = "aquatics_haulerPurplePod.dat";
	name = "Purple Pod";
	roles = "aquatics_haulerPurplePod";	
	};

	"aquatics_pOrcaHauler" = {
	like_ship = "aquatics_orcaHauler_template";
	ai_type = "aquatics_haulerPlanetAI.plist";
	launch_actions = ("switchAITo: aquatics_haulerPlanetAI.plist");
	roles = "aquatics_largeHauler aquatics_pHauler aquatics_orca aquatics_pOrca";
	};

	"aquatics_wOrcaHauler" = {
	like_ship = "aquatics_orcaHauler_template";
	ai_type = "aquatics_haulerWitchAI.plist";
	launch_actions = ("switchAITo: aquatics_haulerWitchAI.plist");
	roles = "aquatics_largeHauler aquatics_wHauler aquatics_orca aquatics_wOrca";
	};

	"aquatics_pHammerHeadHauler" = {
	like_ship = "aquatics_hammerHeadHauler_template";
	ai_type = "aquatics_haulerPlanetAI.plist";
	launch_actions = ("switchAITo: aquatics_haulerPlanetAI.plist");
	roles = "aquatics_largeHauler aquatics_pHauler aquatics_hammerHead aquatics_pHammerHead";
	};

	"aquatics_wHammerHeadHauler" = {
	like_ship = "aquatics_hammerHeadHauler_template";
	ai_type = "aquatics_haulerWitchAI.plist";
	launch_actions = ("switchAITo: aquatics_haulerWitchAI.plist");
	roles = "aquatics_largeHauler aquatics_wHauler aquatics_hammerHead aquatics_wHammerHead";
	};

	"aquatics_haulerTender" = {
	like_ship = "python";
	ai_type = "aquatics_haulerTenderAI.plist";
	launch_actions = ("switchAITo: aquatics_haulerTenderAI.plist");
	name = "Hauler Tender";
	roles = "aquatics_haulerTender";
	script = "aquatics_tenderScript.js";
	};
}

User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Hello Thargoid,

try the line below in your console (instead of using spawn):

Code: Select all

var zloc = 0.5; system.legacy_addShipsWithinRadius("aquatics_pHauler", 1, "wpu", [0.0, 0.0, zloc], 10000.0);
This line is well working on my computer and add a little bit to your shipdata.

For the templates:

Code: Select all

is_template = true;
For the 'real' entities:

Code: Select all

name = "whatever you have in mind";
And if this doesn't help, please try to remove (comment out) the subents and escorts and try again.
And if you still have the problem avoid like_ship at all. Oolites shipdata only uses this key for asteroids and wrecks - I think Ahruman knows why - maybe like_ship doesn't take all keys from the 'template'?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

To be honest, from the trials I've done elsewhere (for Missile Rack), the is_template key seems to be broken somewhere and stops anything appearing (as Griff also found iirc from the thread on this topic), so I'm avoiding using it at all anywhere unless I have to.

This OXP is giving me grief anyway (I can't get the models to look right in-game), so I keep getting distracted by other thoughts and OXPs anyway. It just seemed a very strange pair of warnings/errors to get, as they were almost circular in what they instructed.

I'll give it some more play over the next few days though and see what comes of it, starting with your console suggestion I think.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

OK now I'm confused, tried it again without (knowinly) changing anything and no errors, just a hauler :roll:

I guess there was a glitch somewhere in the file or something, opening and resaving has sorted it or something. Hmmmm
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Thargoid wrote:
guess there was a glitch somewhere in the file or something, opening and resaving has sorted it or something. Hmmmm
*waves a shift key*
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Routinely pressed (these days I seem to always press it when starting up, but then I seem to script more than play these days), but not impossible that I let up too early or 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 »

Thargoid wrote:
Routinely pressed (these days I seem to always press it when starting up, but then I seem to script more than play these days), but not impossible that I let up too early or something.
I am sometimes also in doubt if I pressed it down fast enough. The key is checked quite early in starting up. But when in doubt I always look in the log file if it detected my shiftkey down.
Post Reply