"like_ship" not visible with Ship.shipDataForKey

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

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
phkb
Commodore
Commodore
Posts: 2433
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

"like_ship" not visible with Ship.shipDataForKey

Post by phkb » Sun Aug 14, 2016 10:42 pm

I'm not sure if this is a bug or a feature request. Here's what I have:

Code: Select all

{
	"myship_default" = {
		... some settings ...
		escort_roles = (
			{role:"escort-light"; min:-2; max:2;}
		);
	};
	"myship_second" = {
		... some settings ...
		like_ship = "myship_default";
		escorts = 0;
	};
}
I'm trying to work out whether the "escorts" and "escort_roles" settings are being set in the child or parent data. When I use "var dta = Ship.shipDataForKey("myship_second")" and look at the data I can see both definitions, but I don't know which one is going to be used. I believe the "escorts = 0" will override the "escort_roles" when I create a "myship_second" type ship, but I can't tell from looking at the data.

So, is it possible to get the "like_ship" value visible in the "shipDataForKey" function? Or, can the escorts/escort_roles settings be populated only when they are in use for a ship definition (that is, "escorts" should return null if "escort_roles" are taking precedence, or "escort_roles" should return null if "escorts" is taking precedence).

I appreciate that "escorts" has been deprecated in favour of "escort_roles" but until the time when "escorts" is no longer supported it would be nice to have some clarity in the ship data object.

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2553
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: "like_ship" not visible with Ship.shipDataForKey

Post by spara » Mon Aug 15, 2016 5:17 am

The wiki states for escort_roles that:

Code: Select all

This property overrules escorts, escort_role and escort_ship...
To my understanding escort_rules is always used, if it's defined. I recall I struggled with this a bit with Random Hits, which like_shipped core ships and then tried to assign escorts to them using the old escorts method.

User avatar
phkb
Commodore
Commodore
Posts: 2433
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: "like_ship" not visible with Ship.shipDataForKey

Post by phkb » Mon Aug 15, 2016 10:12 pm

<looks sheepish>
spara, it's actually Random Hits that I'm having problems with.

<wanders away to do some testing>

OK, let me break this down. And prepare yourself for a long post!

The Issue
Station Dock Control is trying to create a standalone version of Random Hits ships. For example, the "rhs_mark_vamppurg_shipset". The reason for wanting to create an individual ship is two-fold: (1) to maintain the docked ship list so a ship can be seen with the escort ships, and (2) when I try to launch the ship, if the ship has escorts defined it will add them to the launch queue, potentially overfilling it. My solution to this is to create "dock" versions of any ships that need escorts, setting it up in a way that clears any pre-existing escort roles, and allows me to launch a single ship.

The Details
"rhs_mark_vamppurg_shipset" is defined as follows:

Code: Select all

	"rhs_mark_vamppurg_shipset" = {
		"aft_weapon_type" = "WEAPON_NONE";
		"auto_weapons" = "true";
		escorts = 0;
		"escape_pod_model" = "escape-capsule";
		"has_energy_bomb" = "0";
		"is_external_dependency" = yes;
		"like_ship" = "random_hits_mark_vamppurg";
		"roles" = "trader(0.01) pirate-heavy-fighter(0.01) pirate-aegis-raider(0.01) pirate-interceptor(0.01) assassin-heavy(0.01)";
		script = "rh_mark_shipset.js";
		"script_info" = {
			"randomshipnames" = "no";
		};
	};
The "like_ship" is defined as follows:

Code: Select all

	"random_hits_mark_vamppurg" = {
		"ai_type" = "randomhitsmarkAI.plist";
		bounty = 142;
		escort_roles = ({
			role = "random_hits_markguard_medium"; min = 4; max = 5;
		});
		fuel = 42;
		"has_energy_bomb" = "0.99";
		"likely_cargo" = 2;
		"like_ship" = "random_hits_patrol_vamppurg";
		"missile_role" = "EQ_HARDENED_MISSILE";
		pilot = "oolite-pirate";
		roles = "random_hits_mark_vamppurg bigBos_revenge_clan random_hits_mark_3";
		script = "oolite-random-hits-mark.js";
		"script_info" = {
			extraMissileLauncher = 0;
			markLevel = 3;
			podChance = "0.55";
			podType = "random_hits_pod2";
			qmineChance = "0.75";
		};
	};
I won't go higher than this here, although the "random_hits_mark_vamppurg" also has a like ship.

When I do a var dta = Ships.shipDataForKey("rhs_mark_vamppurg_shipset"); I find that escorts is defined with a value of 0, and escort_roles is defined as per the "random_hits_mark_vamppurg" definition.

In Game Testing
If I do this:

Code: Select all

var myship = system.addShips("[rhs_mark_vamppurg_shipset]", 1, p.position.add(p.vectorForward.multiply(10000)), 1000)[0];
I get a Vampire with a number of escorts. So the "escorts" setting in the rhs_mark_vamppurg_shipset definiton is doing nothing.

OK, so I want a single version of this ship. In SDC I create a "dock" version that looks like this:

Code: Select all

	"dock_rhs_mark_vamppurg_shipset" = {
		like_ship = "rhs_mark_vamppurg_shipset";
		escort_roles = (
			{role = ""; min = 16; max = 16;}
		);
		roles = "dockonly";
		is_external_dependency = yes;
	};
Now when I do this:

Code: Select all

var myship = system.addShips("[dock_rhs_mark_vamppurg_shipset]", 1, p.position.add(p.vectorForward.multiply(10000)), 1000)[0];
I get the result I'm looking for - a single ship.

But now I want to attach some escorts to this ship. So I do this:

Code: Select all

			var mygroup = new ShipGroup("mygroup1", myship);
			myship.group = mygroup;
			
			var grd1 = system.addShips("random_hits_markguard_medium", 1, myship.position, 1000)[0];
			grd1.shipUniqueName = "My Guard 1";
			var result = grd1.offerToEscort(myship);
			if (result === false) log(this.name, "fail 1");
			mygroup.addShip(grd1);
			grd1.group = mygroup;

			var grd2 = system.addShips("random_hits_markguard_medium", 1, myship.position, 1000)[0];
			grd2.shipUniqueName = "My Guard 2";
			result = grd2.offerToEscort(myship);
			if (result === false) log(this.name, "fail 2");
			mygroup.addShip(grd2);
			grd2.group = mygroup;
In both cases the result for offering to escort is false.

To prove that my code is doing things reasonably correctly, if I change the first ship creation to be a "dock_anaconda", and the two escorts to be "escort-medium", the offers to escort are accepted.

The Conclusion
I'm confused! On the one hand a straight creation of a "rhs_mark_vamppurg_shipset" adds escorts based on the escort_roles from the like_ship definition. But if I used my "dock" version and try to do things manually it fails.

So, I'm either doing things wrong (which is a highly likely scenario, by the way!), or there's some sort of issue in play. I even tried hacking the Random Hits shipset shipdata.plist file and removing the "escorts = 0" entry entirely, but got the same results.

Any suggestions, anyone?

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2553
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: "like_ship" not visible with Ship.shipDataForKey

Post by spara » Tue Aug 16, 2016 2:11 pm

Just a stab in the dark. Could it be an AI thing? Have you tried to give the ship a core js AI?

User avatar
phkb
Commodore
Commodore
Posts: 2433
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: "like_ship" not visible with Ship.shipDataForKey

Post by phkb » Thu Aug 18, 2016 1:49 am

spara wrote:Have you tried to give the ship a core js AI?
Just tried this on the leader to no avail. But after a bit more experimentation I got to the root cause of the issue. I think the issue is the script attached to the escort ships. For RH escorts, this is "oolite-random-hits-guard.js". Something about the way this works prevents the escort from being attached as an escort - maybe because in the shipSpawned event the it expects to find a group already established with a leader identified. I have a feeling that if the ship is part of a group it can't also be assigned as an escort.

This gives me two options for SDC: (1) I can include an exception list of ship datakeys that won't have escorts created (just groups), or (2) I can do a process of removing any group membership the escort might be in so it can be attached correctly as an escort. There might be another option I haven't thought of, too.

In any case, getting back to the original topic of the thread: I still think it would be good to expose the "like_ship" value in the shipDataForKey function, although my immediate need for this has diminished.

Post Reply