Page 73 of 115

Re: Scripters' cove: station interfaces, the mystery thereof

Posted: Sat Oct 18, 2014 8:41 am
by cim
Wildeblood wrote:
I want an unfriendly station, where dockside services are not available. How do I prevent or undo your OXP setting an interface on my station? Is there an array I can loop through and null them all? If not, why not? Is there a way to prevent them being set in the first place? Basically, the problem is this: you've installed the It's Not For Everyone OXP, when you dock at INFE Station, you should see only the interfaces set by the INFE OXP, and no others.
You can do station.setInterface("interface-name",null) to remove an interface.

The only core game interface which appears outside main stations is the "manage primable equipment" one - the logic being that it's not a station interface, it's a ship control, so it doesn't matter where you dock. Its key is "oolite-primable-equipment-manager" if you want to disable it anyway.
Wildeblood wrote:
Do interfaces have to be set from a world script [...] Are there any restrictions on the callback function of an interface?
No, and no.
Wildeblood wrote:
Lastly, if I have a reference to a station object, can I execute the callback function of an interface on that station while player.ship.docked === false or while docked at another station?
Yes, provided you retain a reference to the callback function somewhere you can reach.

Re: Scripters cove

Posted: Sat Oct 18, 2014 9:09 am
by Thargoid
Or the other option (depending on what you want to offer instead) could be to intercept opening the Interfaces screen for your station and then reroute it to a mission screen where you make your station-specific offers. It's perhaps not quite as elegant, but it works (see the Lave Academy station course offer screen for example, which intercepts the market screen).

Re: Scripters cove

Posted: Fri Nov 28, 2014 6:38 pm
by spara
I'm trying to write a js AI for a hoopy casino station that would make the ship do circles around the main station. I'm obviously not getting something, so maybe someone can help me here. This script just makes the ship zig-zag away from the main station.

Code: Select all

"use strict";

this.name = "hOopy Casino AI";

this.aiStarted = function() {
	var ai = new worldScripts["oolite-libPriorityAI"].PriorityAIController(this.ship);
	ai.setWaypointGenerator(ai.waypointsStationPatrol);
	ai.setPriorities([
		/* Cruise around the main station*/
		{
			condition: ai.conditionHasWaypoint,
			configuration: ai.configurationSetDestinationToWaypoint,
			behaviour: ai.behaviourApproachDestination,
			reconsider: 30
		},
		{
			configuration: ai.configurationSetWaypoint,
            behaviour: ai.behaviourApproachDestination,
            reconsider: 30
		}
	]);
}

Re: Scripters cove

Posted: Fri Nov 28, 2014 6:50 pm
by cim
The waypointsStationPatrol method picks the station to patrol around by:
1) if the ship is in a group, and the group has a leader, and the leader is a station, use that station
2) otherwise use the main station

The casino is a station, and likely the leader of its group by default. So it's probably trying to patrol in circles around itself.

You'll need to define your own waypoint method.

Re: Scripters cove

Posted: Fri Nov 28, 2014 7:01 pm
by spara
cim wrote:
The waypointsStationPatrol method picks the station to patrol around by:
1) if the ship is in a group, and the group has a leader, and the leader is a station, use that station
2) otherwise use the main station

The casino is a station, and likely the leader of its group by default. So it's probably trying to patrol in circles around itself.

You'll need to define your own waypoint method.
Ok. I was suspecting that was the case.

Re: Scripters cove

Posted: Sun Nov 30, 2014 11:29 am
by spara
I'm tackling with priorityAI and trying to understand things. If I shoot at the station this code just keeps printing "test2" messages to the log:

Code: Select all

		{
			preconfiguration: ai.configurationStationValidateTarget,
			condition: ai.conditionInCombat,
			behaviour: function() {
				log("test","test1");
			},
			reconsider: 5
		},
		{
			configuration: ai.configurationStationReduceAlertLevel,
			behaviour: function() {
				log("test","test2");
				},
			reconsider: 60
		},
But this code:

Code: Select all

		{
			preconfiguration: ai.configurationStationValidateTarget,
			condition: ai.conditionInCombat,
			behaviour: function() {
				log("test","test1");
			},
			reconsider: 5
		},
		{
			configuration: ai.configurationStationReduceAlertLevel,
			behaviour: function() {
				log("test","test2");
				ai.behaviourStationManageTraffic();
				},
			reconsider: 60
		},
produces "test1" too. It looks like running behaviourStationManageTraffic (or any other behaviour function?) does something that enables ai.conditionInCombat to be true. If I write my own finishing behaviour function, is there something that needs to be there for things to work? Something that initializes something?

Re: Scripters cove

Posted: Sun Nov 30, 2014 11:48 am
by cim
spara wrote:
It looks like running behaviourStationManageTraffic (or any other behaviour function?) does something that enables ai.conditionInCombat to be true. If I write my own finishing behaviour function, is there something that needs to be there for things to work? Something that initializes something?
It's the event handlers which need setting up. Response definition functions and components.

Without these, the station won't have a "shipBeingAttacked" event handler, which means that it won't target its attacker, which means that conditionInCombat won't be true.

To begin with this will give you the standard station event handlers.

Code: Select all

var handlers = {}; // new handler object
this.responsesAddStation(handlers); // add standard response set
this.applyHandlers(handlers);

Re: Scripters cove

Posted: Sun Nov 30, 2014 12:35 pm
by spara
Ah. That explains a lot. Thanks.

Re: Scripters cove

Posted: Mon Dec 01, 2014 12:08 pm
by spara
I've got things pretty much working the way I want, so it's up to finer details. This one gives me nothing but "null" to the log and I don't understand why.

Code: Select all

		{
			preconfiguration: ai.configurationCheckScanner,
			condition: ai.conditionScannerContainsCleanShip,
			behaviour: function() {
				log("test", ai.getParameter("oolite_scanResultsSpecific"));
			},
			reconsider: 30
		}
The way I understand it, oolite_scanResultsSpecific should never be "null" in this case.


Found it. It's a typo in the wiki. It should be oolite_scanResultSpecific. Wiki fixed.

Another question about the "has_npc_traffic" in shipdata.plist. Wiki states that only rotating stations will launch traders. Is this correct and is there some simple reason for it? Is it also correct, if I assume that the moving casino cruiser will never get any NPC visitors by the populator?

Re: Scripters cove

Posted: Mon Dec 01, 2014 2:08 pm
by Lone_Wolf
I'm currently working on making shieldcycler devices breakable, and got a question about the worldScritps equipmentDestroyed event handler.
oolite worldscripts event handler entry wrote:
equipmentDestroyed

The equipmentDestroyed handler is called when equipment gets destroyed completely beyond repair. (in strict mode) (world script only)

this.equipmentDestroyed = function(equipment)
{
// Your code here
}
Announcing Oolite v1.80 wrote:
* Strict mode now only disables OXPs rather than making other gameplay
changes
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?

Re: Scripters cove

Posted: Mon Dec 01, 2014 5:22 pm
by cim
Lone_Wolf wrote:
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?
It shouldn't be necessary.
spara wrote:
Another question about the "has_npc_traffic" in shipdata.plist. Wiki states that only rotating stations will launch traders. Is this correct and is there some simple reason for it?
This is a leftover in the docs from 1.77's populator. In 1.80 the core populator determines whether to launch ships of any sort based just on the "has_npc_traffic" value, with the station's allegiance property used to determine which ships to launch. I'll update the docs.
spara wrote:
Is it also correct, if I assume that the moving casino cruiser will never get any NPC visitors by the populator?
This also depends on its allegiance. "private" is the correct value for a station which shouldn't get any normal NPCs docking (this doesn't stop you writing specific AIs which will dock with it anyway, though)

Re: Scripters cove

Posted: Tue Dec 02, 2014 12:27 pm
by Lone_Wolf
cim wrote:
Lone_Wolf wrote:
Do oxps need an equipmentDestroyed handler, or is this event only triggered for core game scripts when the game is in strict mode ?
It shouldn't be necessary.
Thanks, maybe you could clarify the text for the equipmentDestroyed handler on the wiki ?

(I don't feel comfortable editing pages that are the closest to official documentation we got).

Re: Scripters cove

Posted: Tue Dec 02, 2014 5:09 pm
by cim
Done. (Indeed, checking more closely, there is no longer any code in the core game which will call that handler)

Re: Scripters cove

Posted: Wed Dec 03, 2014 6:28 am
by Rese249er
Two questions and a sidenote...

First question: can the player's ship be referenced in a shipdata.plist so that it would adjust to any ship the player is flying?
Second Question: Could someone point out a ship script to remove the ship after X seconds without affecting the AI?
Sidenote: While tweaking the OXP this will go towards, I did a little... combat testing, so to speak, at Ceesxe. G1. I undocked from the main station and swung around to point myself at the nearrby Super Hub to fire upon it. A single burst got me a sternly worded message to offline my weapons if I couldn't keep them from firing. Sustained fire... Well, Vipers launched from the main station, and along with the usual messages calling me out Vipers also started firing on the SuperHub! [shameless tease]I was simply flabbergasted and probably would've popped in a second if it weren't for my OXP![/shameless tease] As it was they got around to me in about ten seconds...

Re: Scripters cove

Posted: Wed Dec 03, 2014 6:46 am
by cim
Rese249er wrote:
First question: can the player's ship be referenced in a shipdata.plist so that it would adjust to any ship the player is flying?
No.
Rese249er wrote:
Second Question: Could someone point out a ship script to remove the ship after X seconds without affecting the AI?
Easiest way is to use a timer.

Code: Select all

this.$removeTimer = new Timer(this,function() { this.ship.remove(); },delay);
and put that in whatever event handler you want in the ship script.

(The AI will be removed along with the ship - I'm not sure what you mean by that bit)