Arrivals and departures

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Thanks, cim! Here's another technical question, though. I'm creating ships one of two ways: either via the stations launchShipWithRole, or with the systems addShips function. This is working fine, except that, when I create ships using "addShips", sometimes ships who have a destination system somewhere else will just turn around and try to dock with the station again, rather than jumping out to their destination. I'm assuming that I'm missing a step somewhere when I create the ships with addShips, but I can't for the life of me figure out where! Is there a command I can give the ship to say, "start heading for your destination system"?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6680
Joined: Wed Feb 28, 2007 7:54 am

Re: Arrivals and departures

Post by another_commander »

phkb wrote:
Is there a command I can give the ship to say, "start heading for your destination system"?
Would something like ship.exitSystem(DestinationSystemID) work for what you want to do? Note, the ship needs to have enough fuel to reach the designated destination and be far away enough from the main station for the command to trigger successfully.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Arrivals and departures

Post by cim »

phkb wrote:
I'm assuming that I'm missing a step somewhere when I create the ships with addShips, but I can't for the life of me figure out where! Is there a command I can give the ship to say, "start heading for your destination system"?
What role/AI of ships is this happening to?

A few ideas:
  • Are you setting home system to the current system?
  • I assume you're using the [shipkey] roles to add the ships in the first place: if so, are you then setting the primary role, AI script, and so on?
  • Are you making sure the ships have enough fuel on board to make at least one jump towards their destination?
  • If traders, are you giving them cargo?
A useful trick for working out why NPCs are doing what they're doing - at least, if it's got a new AI. Target the ship, then in the debug console:

Code: Select all

PS.target.AIScript.oolite_priorityai.setParameter("oolite_flag_behaviourLogging",true);
PS.target.AIScript.oolite_priorityai.reconsiderNow(); // or just wait for the next normal reconsideration
You'll get messages to the debug console and the Latest.log that will let you identify which branches and behaviours in the AI were executed (you'll need to have the AI script open to make sense of it). That should tell you which conditions are unexpectedly true / unexpectedly false, which should help.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Thanks cim and another_commander. I wasn't setting the fuel value, so that might have been the problem. I'll report back if that doesn't fix the issue.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Technical question: When a ship group docks with a station, does the leader always dock first?

Also:
cim wrote:
If it's using JS AI and intends to dock, asking the AI controller for controller.getParameter("oolite_selectedStation") will tell you where, at least for core AIs.
How do I access the controller for a ship with JS AI? I've tried these variations without success.

Code: Select all

var ctl = ship.AIScript.oolite_priorityai.controller;
var ctl = worldScripts["oolite-libPriorityAI"].PriorityAIController(ship);
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Arrivals and departures

Post by cim »

phkb wrote:
Technical question: When a ship group docks with a station, does the leader always dock first?
If it's an escort group, then the escorts won't request clearance until the leader has entered the docking approach pattern. If it's a normal group, it depends on the group AI: the group leader is likely to be the first to request clearance but if there's already a queue they might not be the first to dock.

Even in the escort group case, if the group leader were to be interrupted while docking and cancel its approach, it might then end up behind its former escorts in the docking queue. Extremely unlikely, but not impossible in the core game without player intervention.

Another detail is that the way core game NPC escort contracts work is that they're "to aegis". Once the freighter starts docking, the escorts are released from its escort group and become individual ships. Usually they'll dock next anyway, but if there was an outbound freighter looking for escorts, some of them might join it without docking.

The controller is at

Code: Select all

ship.AIScript.oolite_priorityai
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

cim wrote:
The controller is at

Code: Select all

ship.AIScript.oolite_priorityai
I've tried everything, but I can't seem to get a connection to the controller. Here's my code.

Code: Select all

	var ships = system.shipsWithPrimaryRole("trader");
	for (var i = 0; i < ships.length; i++) {
		log(this.name, "checking ship " + ships[i]);
		if (ships[i].AIScript != "oolite-nullAI.js") {
			log(this.name, ships[i].AIScript.name);
			if (ships[i].AIScript.oolite_priorityai) {
				var ctl = ships[i].AIScript.oolite_priorityai;
				var stn = ctl.getParameter("oolite_selectedStation");
				log(this.name, "result: " + stn);
			}
		}
	}
I'd expect at least one of the traders in the system to be heading for a station somewhere, or at least to get a blank value in the "stn" variable, but I never get the "Result" line in the log. I removed all OXP ships, so I only have core ships. All I get is this:

Code: Select all

13:08:23.973 [StationDockControl]: checking ship [Ship "Cobra Mark I" position: (17094.4, -65303.9, 447890) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:08:23.973 [StationDockControl]: Oolite Trader AI
13:08:23.973 [StationDockControl]: checking ship [Ship "Moray Star Boat" position: (-1450.88, -36299.3, 397332) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:08:23.973 [StationDockControl]: Oolite Trader AI
13:08:23.973 [StationDockControl]: checking ship [Ship "Moray Medical Boat" position: (-14943.8, 19470.3, 346846) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:08:23.973 [StationDockControl]: Oolite Trader AI
This indicates that the ships[i].AIScript.oolite_priorityai is always null or undefined. What am I doing wrong?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Arrivals and departures

Post by cim »

phkb wrote:
What am I doing wrong?
You might be checking too soon, depending on where you run that code. The AI controller is initialised in the aiStarted event in the ship's AI script. That doesn't happen until after the shipSpawned event, which only occurs on the next frame of the simulation after the ship is added.

The oolite_selectedStation parameter then won't be populated until the AI has evaluated its priorities at least once, which to avoid having every AI in the system try to do this on the same frame will happen at a randomised time, possibly up to a second later.

The code itself is fine - I pasted it into the debug console on a new game and got lines like

Code: Select all

07:23:29.125 [oolite-debug-console]: checking ship [Ship "Boa" position: (-34027.6, 17387.1, 190453) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
07:23:29.125 [oolite-debug-console]: Oolite Trader AI
07:23:29.125 [oolite-debug-console]: result: [Station "Coriolis Station" "Coriolis Station" position: (-49474.3, 60752.2, 427652) scanClass: CLASS_STATION status: STATUS_ACTIVE]
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

D'oh! Had the code in the startUpComplete! :oops:

Thanks cim.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Another technical question: How do I create a ship (via addShips or launchShipsWithRole) with a specific entityPersonality?

Perrhaps some context... I'm trying to create a ship that looks exactly like the one seen in the dock list. I'm using modelPersonality to control what the ship variant looks like on the mission screen, and I'd like to transfer that same look into a real ship. Is that possible?
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Arrivals and departures

Post by Norby »

phkb wrote:
I'm using modelPersonality to control what the ship variant looks like on the mission screen, and I'd like to transfer that same look into a real ship. Is that possible?
I am missing the personality parameter also from addShips long time ago, but regardless a possible improvement in trunk this is not in 1.80.

The only workaround what I can imagine is in Respray for Griffs which replace the whole outlook using setMaterials and contain a setDecal function to restore shader uniforms. You must give fix colors to the shaders in uniforms instead of entityPersonality and randomUnitVector to get the same ship.

This is a massive work due to the materials section in shipdata.plist is different for almost all ships and probably will not work for oxp ships what you are not verified. So I think a request for a personality parameter in addShips would be much better.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Norby wrote:
So I think a request for a personality parameter in addShips would be much better.
Well, that's annoying. I was hoping for a 1.80 release...

I can still do a 1.80 release with a caveat - ships will probably get an automatic respray on launch. What do people think? Immersion killer? Spells the end this this project?

To the devs, what's the chance of getting the ability to set the entitypersonality when creating ships, or a writable "entityPersonality" property in 1.81?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Arrivals and departures

Post by cim »

phkb wrote:
To the devs, what's the chance of getting the ability to set the entitypersonality when creating ships
Difficult. Most of the ship adding functions at least potentially add multiple ships, so adding per-ship customisations to them isn't straightforward in terms of syntax. There are also a lot of different ship adding functions, and this isn't the only "on initialisation" customisation which has been requested, so this feels like a larger project.
phkb wrote:
or a writable "entityPersonality" property in 1.81?
Straightforward enough to implement in theory - but I vaguely remember there being some reason it couldn't/shouldn't be done, which is why "create with personality" is an option for mission screens, rather than just making the entityPersonality writable in the first place and letting people update it on mission.displayModel. I'll look into it.
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Arrivals and departures

Post by Norby »

phkb wrote:
ships will probably get an automatic respray on launch. What do people think? Immersion killer?
No imho. EscortDeck has the same problem but nobody complained yet. Just a speciality of Ooniverse either the reason is a free respray in each dock or some kind of camofluage to forget the questionable actions happened last time in the deep space.
cim wrote:
potentially add multiple ships
I think to a new array-type parameter of addShips after the existing ones. If this personality array is smaller than the number of the added ships then others can get random numbers.
cim wrote:
there being some reason it couldn't/shouldn't be done
Personality should be read-only imho after a ship is created but a way would be good to set it at creation or right after.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Arrivals and departures

Post by phkb »

Norby wrote:
No imho. EscortDeck has the same problem but nobody complained yet. Just a speciality of Ooniverse either the reason is a free respray in each dock or some kind of camofluage to forget the questionable actions happened last time in the deep space.
I'm glad you think so -- I've come a bit too far to turn back now!
Post Reply