Oolite Bulletins

For information and discussion about Oolite.
It is currently Wed Jun 28, 2017 8:51 pm

All times are UTC




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Mar 26, 2017 2:26 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 21, 2013 12:26 pm
Posts: 410
Below is a patch generated with git format-patch. I cannot submit a pull request cause I don't have a Github account (yet?).

It makes playerShip.compassMode writable, mainly in order to let scripts set it to COMPASS_MODE_TARGET. I wanted this because the compass is more accurate than the HUD arrow when the target is off-screen, and also shows clearly when the target is behind the ship.
Code:
From c7ccf914d836b53acba4578d175efc789b6c5d16 Mon Sep 17 00:00:00 2001
From: Astrobe <REDACTED@REDACTED>
Date: Sun, 26 Mar 2017 16:13:31 +0200
Subject: [PATCH] Script-writable compass mode

---
 src/Core/Scripting/OOJSPlayerShip.m | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/Core/Scripting/OOJSPlayerShip.m b/src/Core/Scripting/OOJSPlayerShip.m
index 3a35a37..c1ba4c4 100644
--- a/src/Core/Scripting/OOJSPlayerShip.m
+++ b/src/Core/Scripting/OOJSPlayerShip.m
@@ -162,7 +162,7 @@ static JSPropertySpec sPlayerShipProperties[] =
 	// JS name							ID											flags
 	{ "aftShield",						kPlayerShip_aftShield,						OOJS_PROP_READWRITE_CB },
 	{ "aftShieldRechargeRate",			kPlayerShip_aftShieldRechargeRate,			OOJS_PROP_READWRITE_CB },
-	{ "compassMode",					kPlayerShip_compassMode,					OOJS_PROP_READONLY_CB },
+	{ "compassMode",					kPlayerShip_compassMode,					OOJS_PROP_READWRITE_CB },
 	{ "compassTarget",					kPlayerShip_compassTarget,					OOJS_PROP_READONLY_CB },
 	{ "compassType",					kPlayerShip_compassType,					OOJS_PROP_READWRITE_CB },
 	{ "currentWeapon",					kPlayerShip_currentWeapon,					OOJS_PROP_READWRITE_CB },
@@ -602,6 +602,16 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro
 			}
 			break;
 			
+		case kPlayerShip_compassMode:
+			sValue = OOStringFromJSValue(context, *value);
+			if(sValue != nil)
+			{
+				OOCompassMode mode=OOCompassModeFromJSValue(context, *value);
+				[player setCompassMode:mode];
+				[player validateCompassTarget];
+				return YES;
+			}
+			break;
 		case kPlayerShip_compassType:
 			sValue = OOStringFromJSValue(context, *value);
 			if (sValue != nil)
-- 
1.8.3.msysgit.0


Top
   
PostPosted: Sun Mar 26, 2017 3:51 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral

Joined: Wed Feb 28, 2007 7:54 am
Posts: 4857
Looks OK and I think we can roll it. The only thing is, be aware that the compass code is very sensitive due to the way the modes have been programmed and switching modes manually may lead to unpredictable results sometimes. Not saying that it will certainly happen, but let's keep it in mind in case any compass bugs come up.

It should also be noted that this patch allows mode changes without considering whether the player has the advanced compass installed or not. Any mode other than COMPASS_MODE_BASIC is effectively awarding an advanced compass for free, so scripters using this should be careful.


Top
   
PostPosted: Sun Mar 26, 2017 5:09 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 21, 2013 12:26 pm
Posts: 410
Quote:
It should also be noted that this patch allows mode changes without considering whether the player has the advanced compass installed or not. Any mode other than COMPASS_MODE_BASIC is effectively awarding an advanced compass for free, so scripters using this should be careful.
On one hand I think it's more efficient if we test for the ASC ourselves, but on the other hand not testing for it may open more possibilities. What do you think? I can republish a fixed version.


Top
   
PostPosted: Sun Mar 26, 2017 5:40 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral

Joined: Wed Feb 28, 2007 7:54 am
Posts: 4857
I'd leave it for the scripts to test. More possibilities is good. :-)


Top
   
PostPosted: Sat Apr 15, 2017 9:25 am 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 21, 2013 12:26 pm
Posts: 410
My ASC got damaged in a fight; I lost the ASC labels and mode symbol but I was still able to switch targets. My script is very basic (if target lock, force ASC to target mode). Unfortunately I repaired it without thinking so I don't know what happens when you relaunch. I'm sure if it qualifies as a bug.


Top
   
PostPosted: Sat Apr 15, 2017 9:33 am 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral

Joined: Wed Feb 28, 2007 7:54 am
Posts: 4857
Anything other than COMPASS_MODE_BASIC is equivalent to an advanced compass. If your scrpit changes it to target mode based only on existing target lock, without first checking its damage status, then you are basically re-awarding it. That's why extra care is required when manually adjusting the compass.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited