Page 1 of 2

Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 12:27 am
by CommRLock78
"...........5,4,3,2,1... witchjump failed", asteroid/station too close.
or
a piece of equipment breaks while going to into witchspace.

We have all had this happen to us when 'somehow' we were too close to something while jumping to another system, particularly after exiting a station or seedy space bar. Would it be possible to create a piece of equipment to detect a coming failure to witchspace, or equipment failure while trying?

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 12:39 am
by Fatleaf
It would be possible, but I prefer the look behind you and see how big the object is compared to my distance from it, approach. And with the stuff breaking then to prevent that keep your ship maintained and it will never happen.

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 12:52 am
by CommRLock78
Fatleaf wrote:
And with the stuff breaking then to prevent that keep your ship maintained and it will never happen.
I do; which would explain why it happens so infrequently ( :oops: ). I didn't realize that was a maintenance issue :shock: .

Thanks for clearing that up. About the being too close, I have always kept of a habit of no jumping while in close proximity to anything; perhaps it has to do with how close you are to something when the button is pressed?

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 1:01 am
by Fatleaf
CommRLock78 wrote:
...perhaps it has to do with how close you are to something when the button is pressed?
It is all about the entities mass and the distance you are at the end of the countdown. It works around a formula which I can't seem to find, I know I read it on the BB somewhere but lost it. I'm sure a Dev will enlighten us!

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 2:58 am
by Wildeblood
Fatleaf wrote:
CommRLock78 wrote:
...perhaps it has to do with how close you are to something when the button is pressed?
It is all about the entities mass and the distance you are at the end of the countdown. It works around a formula which I can't seem to find, I know I read it on the BB somewhere but lost it.
I dunno, CommRLock78, I don't think you looked very hard. Both these threads are less than a week old:-

https://bb.oolite.space/viewtopic.php?f=4&t=12145

Download this before I update it to a new version. The function $checkForSaveBeforeJump checks whether the player is too close to another mass to make a successful jump:
https://bb.oolite.space/viewtopic.php?f=4&t=12150
The log file BuggyBY posted shows him repeatedly trying to jump while too close to a station, and $checkForSaveBeforeJump correctly predicting the jump would fail.

The mis-jumps, which take three forms - exiting in interstellar space, fuel leak on arrival, or failure to jump with internal damage - can't be predicted before they happen. Cim sent me a detailed explanation, but basically on each jump there's a 1/128 chance of a mis-jump with a well-maintained ship, and slightly higher chance with a poorly-maintained ship.

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 3:37 am
by CommRLock78
Wildeblood wrote:
basically on each jump there's a 1/128 chance of a mis-jump with a well-maintained ship, and slightly higher chance with a poorly-maintained ship.
That would explain some of the mis-jumps and whay they happen even on a well-maintained ship.
I'm not sure if I'm looking to add an OXP that changes that much of the game-play, that's why I never did installed the save anywhere OXP

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 3:53 am
by Wildeblood
CommRLock78 wrote:
I'm not sure if I'm looking to add an OXP that changes that much of the game-play, that's why I never did installed the save anywhere OXP
I'm not asking you to add anything to your game, I'm saying the function that does what you asked about is there in that script to be copy/pasted.

Re: Witchspace Jump Failure Detection

Posted: Sat Jul 21, 2012 4:41 am
by CommRLock78
Wildeblood wrote:
CommRLock78 wrote:
I'm not sure if I'm looking to add an OXP that changes that much of the game-play, that's why I never did installed the save anywhere OXP
I'm not asking you to add anything to your game, I'm saying the function that does what you asked about is there in that script to be copy/pasted.
Ach, I see now :oops: . You're speaking of this, it appears:

Code: Select all

function() {
// get all entities within scanner range of player ship
  var blockers = system.filteredEntities(this, function() {return true; }, player.ship, 25600);
  for (var i=0; i<blockers.length; i++) {
// if they are a ship
    if (blockers[i].isShip) {
// get distance by comparing positions
      var d = player.ship.position.subtract(blockers[i].position).magnitude();
      if (blockers[i].mass / d*d >= 10) {
// too close and heavy, return the blocking entity
        return blockers[i];
      }
    }
  }
// if we get this far, nothing is blocking
  return null;
}
Thanks, Wildeblood. That really is exactly what I was thinking of (I'll be sure to check the bulletins a bit more thoroughly in the future ;) ). However, I'm not sure how to implement this script :oops:, as a worldScript.plist, or a script.js?

Re: Witchspace Jump Failure Detection

Posted: Thu Aug 30, 2012 4:01 pm
by Wildeblood
A couple of weeks ago now I got a PM asking about this, and my immediate reaction was to assume it would be simple to check for blocking masses when the jump countdown started, and advise the player whether the jump would likely succeed or fail. It's been surprisingly frustrating: it took me a while to figure out the mistake in the following. (See if you can guess what it is, kids. :twisted: ) It leaves the expected messages in the log file, but nothing on screen.

Code: Select all

"use strict";

this.name    = "Check For Likely Jump Success";
this.version = "0.1";

/* ====================================================================================
			EXAMPLE CHECK WHEN COUNTDOWN STARTS
======================================================================================= */

this.playerStartedJumpCountdown = function(type, countdown)
	{
     if (type === "standard")
		{
		var message = this.$checkForLikelyJumpSuccess();
		player.consoleMessage(("Hyperspace jump " + message + "."),6);
		player.commsMessage(("Hyperspace jump " + message + "."),6);
		log(this.name,("Hyperspace jump " + message + "."));
		}
	}

this.$checkForLikelyJumpSuccess = function()
	{
	var howfar = System.infoForSystem(galaxyNumber, system.ID).distanceToSystem(System.infoForSystem(galaxyNumber, player.ship.targetSystem));
	if (howfar > player.ship.fuel) return "insufficient fuel";

	// Thanks, Ahruman & cim
	var psPos = player.ship.position;
	var blockers = system.filteredEntities(this, function (entity) {
		return entity.isShip &&
		entity.mass / psPos.squaredDistanceTo(entity) >= 10;
		}, player.ship, 25600);
	if (blockers.length > 0) return "blocked";

	else return "will likely succeed";
	}
Latest.log wrote:
14:55:54.121 [Check For Likely Jump Success]: Hyperspace jump will likely succeed.
14:57:59.478 [Check For Likely Jump Success]: Hyperspace jump will likely succeed.
15:34:55.480 [Check For Likely Jump Success]: Hyperspace jump blocked.
15:36:46.663 [Check For Likely Jump Success]: Hyperspace jump will likely succeed.
15:37:30.663 [Check For Likely Jump Success]: Hyperspace jump will likely succeed.

Re: Witchspace Jump Failure Detection

Posted: Thu Aug 30, 2012 7:41 pm
by Tricky
Not sure what I did but I got it to work.

I just cleaned it up a bit and put a few more test lines using player.ship.commsMessage. As you can see from the screenshot it shows all messages.

(commsMessage also outputs to the console)

Code: Select all

    this.playerStartedJumpCountdown = function(type, countdown) {
        if (type === "standard") {
            var message = this.$checkForLikelyJumpSuccess();

//            player.consoleMessage("Hyperspace jump " + message + ".", 6);
            player.commsMessage("Hyperspace jump " + message + ".", 6);
            player.ship.commsMessage("* Hyperspace jump " + message + ".");
            player.ship.commsMessage("** Hyperspace jump " + message + ".", player.ship);
            log(this.name, "Hyperspace jump " + message + ".");
        }
    }

    this.$checkForLikelyJumpSuccess = function() {
        var ps = player.ship,
        howfar = System.infoForSystem(galaxyNumber, system.ID).
            distanceToSystem(System.infoForSystem(galaxyNumber, ps.targetSystem));

        if (howfar > ps.fuel) {
            return "insufficient fuel";
        }

        // Thanks, Ahruman & cim
        var psPos = ps.position;
        var blockers = system.filteredEntities(this, function (entity) {
            return entity.isShip && entity.mass / psPos.squaredDistanceTo(entity) >= 10;
        }, ps, ps.scannerRange);

        if (blockers.length > 0) {
            return "blocked";
        } else {
            return "will likely succeed";
        }
    }
Image

Re: Witchspace Jump Failure Detection

Posted: Fri Aug 31, 2012 3:07 am
by Wildeblood
Tricky wrote:
Not sure what I did but I got it to work.
Commenting out the console message was the crucial fix. Remove the console message, thus, and it will work fine:

Code: Select all

   // player.consoleMessage(("Hyperspace jump " + message + "."),6);
      player.commsMessage(("Hyperspace jump " + message + "."),6);
      log(this.name,("Hyperspace jump " + message + "."));
You never get to see the console message, because it's immediately over-written by the countdown messages. (Notice in your screen-shot both countdown messages say 15s, not one 15s and one 14s) Twice or thrice in several dozen trials I actually saw a glimpse of it. So I added the comms message, and wondered why it never appeared.

Oolite automatically suppresses messages that are identical to the previous message, so-

Code: Select all

   player.consoleMessage("Hello world!",6);
   player.consoleMessage("Hello world!",6);
-produces only one "Hello world!" on screen. But crucially, this:-

Code: Select all

   player.consoleMessage("Hello world!",6);
   player.commsMessage("Hello world!",6);
-causes the comms message to be suppressed. I'll PM you your prize, Tricky. :D

Re: Witchspace Jump Failure Detection

Posted: Fri Aug 31, 2012 2:16 pm
by UK_Eliter
This is a nice OXP / idea. Excellent! :)

However [EDITED]:

(1) The 'likely to succeed' message is a bit misleading, since it somewhat suggests there will be no misjump, i.e. that you won't end up in interstellar space. How about saying that the jump will not be 'mass locked' or something like that? [This does not apply to the 'Check For Likely Witchspace Jump Failure' OXP, but only - at most - to the test OXP 'Check For Likely Jump Success'.]

(2) In my brief testing I saw the 'likely succeed' message only some of the times that the jump succeeded. [Ditto above parenthetical comment.]

(3) Sometimes part of a message from the OXP got obscured on my screen. (I have such messages appearing in the bottom-ish right of the screen).

(4) 'Avoid nearby mass' is not quite the best English / as specific as it could be. How about 'Distance yourself from nearby mass' or 'Depart from nearby mass' or just 'Mass locked'?

Re: Witchspace Jump Failure Detection

Posted: Fri Aug 31, 2012 4:57 pm
by Rese249er
Point is, it works as intended. The text could Ghurka pickles and I'd smile as I injected a little farther. Great OXP!

Re: Witchspace Jump Failure Detection

Posted: Fri Aug 31, 2012 5:03 pm
by Wildeblood
UK_Eliter wrote:
(2) In my brief testing I saw the 'likely succeed' message only some of the times that the jump succeeded.

(4) 'Avoid nearby mass' is not quite the best English / as specific as it could be. How about 'Distance yourself from nearby mass' or 'Depart from nearby mass' or just 'Mass locked'?
UK_Eliter, you appear to be commenting on both the test script above (Check For Likely Jump Success 0.1), and the version I packaged as an OXP (Check For Likely Witchspace Jump Failure 1.0) over there, and not discriminating between them. This is the only message the OXP will produce:-
this.playerStartedJumpCountdown = function(type, countdown)
{
if (type === "standard")
{
if (this.$checkForLikelyJumpSuccess() == "blocked") player.commsMessage("Witchspace jump blocked. Avoid nearby mass before countdown ends.",5);
}
}
So I'd be very surprised :shock: if you ever saw the "likely to succeed" message.

Re: Witchspace Jump Failure Detection

Posted: Sat Sep 01, 2012 9:41 pm
by CommRLock78
Hat's off to Tricky and Wildeblood. Many thanks indeed fellas :D ! I just tested it and I have to say, I love this "OXP"; it's exactly what I was thinking when I created the thread. Now, I have my usual noob kind of question: I placed the script.js in the /AddOns/Config folder, which I had to create, so the question is, is a folder named Config in the AddOns folder an extension to the "main" Config folder :?: .