[RELEASE] Towbar OXP v0.101

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

I got the following exception when accidentally launching a tug drone while targeting a hostile ship.
Exception: TypeError: this.$TugDrone_Sound is null
Active script: tugdrone 0.9
tugdrone.js, line 62:
this.$TugDrone_Sound.play();

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

Re: [RELEASE] Towbar OXP v0.101

Post by phkb »

v0.103 fixes the issue with the tug drone sound.

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

I scooped a 2t "more-cargo2" role cargopod, and got the following error:
Exception: Error: Cannot set property cargo of instance of Manifest to invalid value NaN.
Active script: more-in-one 1.0
more-in-one.js, line 21:
player.ship.manifest[this.$cargoname] += t;
> player.ship.manifest["alloys"] // the script defines this.$cargoname = "alloys";
0

> player.ship.cargoSpaceAvailable
2
I didn't know to check the $cargo property on the pod's script before scooping it, unfortunately.

I also noticed that, even if the script got past there, line 25 of the script would have accessed a nonexistent property displayName (at least non-existent where I am right now):
cdname = system.mainStation.market[this.$cargoname].displayName;
> system.mainStation.market["alloys"]
{
quantity_random: "0.53",
capacity: 127,
key: "alloys",
trumble_opinion: "0",
quantity: 37,
quantity_average: "29",
classes: ["oolite-business", "oolite-shipyard", "oolite-metals", "oolite-salvage"],
price_random: "0.16",
quantity_unit: "0",
price_economic: "0.03",
peak_export: "0",
name: "[commodity-name alloys]",
legality_import: "0",
market_script: "smugglers_illegalmarket.js",
sort_order: "1000",
peak_import: "7",
legality_export: "0",
quantity_economic: "0.12",
price_average: "388",
price: 350
}

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

I got the following error when I started towing a derelict ship spawned by Galcop Missions at an unknown beacon.
Exception: ReferenceError: ship is not defined
Active script: towbar 0.103
towbar.js, line 795:
+" to neutralize a "+t+" in "+ws.$Towbar_Name( ship ), 10);
I think the "ship" variable on that line should be "ws.$TowbarShip" instead.

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

There is a bug when salvaging derelicts in a RH (or anywere with limited market capacity):

Code: Select all

12:36:09.032 [script.javaScript.exception.ooliteDefined]: ***** JavaScript exception (escortdeck 1.11): Error: Station.setMarketQuantity: Invalid arguments ("computers", 13) -- expected Quantity must be between 0 and the station market capacity.
12:36:09.032 [script.javaScript.exception.ooliteDefined]:       AddOns/towbar-0.103.mod.oxz/Scripts/towbar.js, line 1320.
I run a modified version of towbar, so the line number doesn't match the vanilla code, but it's in $Towbar_Payout:

Code: Select all

       //cargo and valuables
        var msg2 = "\n";//skip the line if no cargo
        var cargo = r.$Towbar_Cargo( ship );
        r.$TowbarLostCargo[id] = 100000; //more than any ship can carry including bases to flag it is empty
        var cr1 = 0;
        var cr2 = 0;
        var ccr = 0;
        if( player.ship.docked ) {
            var mc = worldScripts["mo-commodity_markets"]; //different buy and sell prices
            if( cargo.t > 0 ) { //can be negative if lost many cargo container durig towing
                var pr = station.market[cargo.name].price;
                if(mc && mc.$priceFactor) {
                    var id = mc.$commodities.indexOf(cargo.name);
                    if( id > -1 ) pr /= mc.$priceFactor[id]; //2-5% less
                }
                if( r.$TowbarDebug && mc ) log("Towbar", "id:"+id+" pr:"+pr+" mcpf:"+mc.$priceFactor);
                var sq = station.market[cargo.name].quantity;
                var q = cargo.t;
                if( q + sq > 127 ) q = 127 - sq;
                cr1 = Math.round( q * pr / 10 ); //cargo cost
//////////// Here
                station.setMarketQuantity(cargo.name, Math.min(127, station.market[cargo.name].quantity + q));
///////////
                if( !r.$TowbarLimit127t && cargo.t > q ) {
                    cr1 += Math.round((cargo.t-q) * pr / 20 ); //half cost
                } else cargo.t = q; //remains discarded
                cr += cr1;
            }
I couldn't find anyway for a script to retrieve the station market capacity for a given commodity to fix it

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

Isn’t there a capacity property on the market commodity entry?

station.market[cargo.name].capacity

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

Milo wrote:
Tue Jun 30, 2020 5:20 pm
Isn’t there a capacity property on the market commodity entry?

station.market[cargo.name].capacity
I only looked at the wiki... I will try to access the station.market[<commodity>] object with the debug console and see if there's a capacity property

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

In 1.81 or later the format of this object's properties changes to the following, and the number of properties on the object reflects the contents of trade-goods.plist rather than commodities.plist

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

Milo wrote:
Tue Jun 30, 2020 10:59 pm
In 1.81 or later the format of this object's properties changes to the following, and the number of properties on the object reflects the contents of trade-goods.plist rather than commodities.plist
You are right, the object has more properties than the wiki listed in the examples.

I will have something for phkb to apply in one or two days (gotta test it! :lol: )

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

Towbar version 0.103. In more-in-one.js, these two lines need to be changed because they can encounter undefined properties (the market might not have the commodity, and since 1.81, I think .displayName is no longer a property of market commodity entries, replaced by .name, which can include [ ] bracket expressions). I think the global method displayNameForCommodity can be used here instead. I replaced this:

Code: Select all

			var cdname = this.$cargoname;
				if(system && system.mainStation && system.mainStation.market)
				cdname = system.mainStation.market[this.$cargoname].displayName;
with this:

Code: Select all

			cdname = displayNameForCommodity(this.$cargoname);
In towbar.js:

1. line 651 should check if( p.injectorsEngaged ) instead of checking speed
2. line 795 should replace ship with ws.$TowbarShip (I reported this in an earlier post)
3. lines 1300 and 1316, 'quantity' property should be changed to 'capacity' (since 1.81 - dybal reported this earlier)
4. lines 1343-46, 1373-76, 1878 and 1939 can use displayNameForCommodity and remove system market displayName checks

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

Milo wrote:
Fri Jul 03, 2020 2:03 am
1. line 651 should check if( p.injectorsEngaged ) instead of checking speed
The way it is it can deal with speeds between maxSpeed and Injector Speed, like those from Q-Charger OXP
Milo wrote:
Fri Jul 03, 2020 2:03 am
3. lines 1300 and 1316, 'quantity' property should be changed to 'capacity' (since 1.81 - dybal reported this earlier)
I sent a fix for this one to phkb (did I get it right this time? :lol: ) by PM

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

The previous code did not handle the possibility of injector speed being higher than x7.

I checked Q-Charger's script, and it doesn't modify speed. It works by setting the ship's velocity to thrustVector multiplied by maxSpeed, four times per second. Multiplying a vector by a scalar is equivalent to lengthening the vector by that amount, so it's essentially making the ship travel twice as fast (although not quite, because any velocity above thrustVector is treated as inertial velocity, and the game reduces inertial velocity continuously, at the same rate as the ship's thrust ... @ line 6750 in ShipEntity.m).

I'm okay with Towbar instability being unaffected by Q-Charger.

We could revise line 651 like this to handle the possibility of other OXPs that increase speed above maxSpeed:

if ( !p.torusEngaged && p.speed > p.maxSpeed ) //injectors or other speed increases count 1-7 times more (note: Q-Charger increases velocity without increasing speed, so it has no effect on towbar stability)

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

Milo wrote:
Fri Jul 03, 2020 8:18 pm
The previous code did not handle the possibility of injector speed being higher than x7.

I checked Q-Charger's script, and it doesn't modify speed. It works by setting the ship's velocity to thrustVector multiplied by maxSpeed, four times per second. Multiplying a vector by a scalar is equivalent to lengthening the vector by that amount, so it's essentially making the ship travel twice as fast (although not quite, because any velocity above thrustVector is treated as inertial velocity, and the game reduces inertial velocity continuously, at the same rate as the ship's thrust ... @ line 6750 in ShipEntity.m).

I'm okay with Towbar instability being unaffected by Q-Charger.

We could revise line 651 like this to handle the possibility of other OXPs that increase speed above maxSpeed:

if ( !p.torusEngaged && p.speed > p.maxSpeed ) //injectors or other speed increases count 1-7 times more (note: Q-Charger increases velocity without increasing speed, so it has no effect on towbar stability)
Nobody modifies speed directly, it's read-only, but the increase in thrustVector increases speed indirectly - I didn't check the core game code, but I ran a trace in a timer that printed speed, maxspeed, etc., into Latest.log when I was investigating a strange behaviour in Torus speed (namely, it stayed constant at 32x maxSpeed, when it should vary with the distance to planetary bodies), and speed increased beyond maxSpeed when using Q-Charger, even if it wasn't modified directly.

User avatar
Milo
Deadly
Deadly
Posts: 185
Joined: Mon Sep 17, 2018 5:01 pm

Re: [RELEASE] Towbar OXP v0.101

Post by Milo »

Oh, I didn't know it was read-only, and I thought that velocity was derived from speed not vice versa. I guess the code I suggested will still work but it will include Q-Charger too:

Code: Select all

					if( p.speed == 0 ) r.$TowbarPitchC += ato/2; //stopped ship count half
					else if ( p.speed > p.maxSpeed && !p.torusEngaged ) //injectors or other speed increases (e.g., Q-Charger) count more (as much as at any non-zero speed, multiplied by how many times faster than maxSpeed the ship is traveling)
						r.$TowbarPitchC += ato * p.speed/p.maxSpeed;
					else r.$TowbarPitchC += ato; // non-zero speed under maxSpeed, or when using torus, count normal
As for the Torus speed, did you figure out what was causing that? If not, I have a suspect - telescope markers. Torus speed is increased only when distance to nearest entity that has collision enabled exceeds 4x scanner range (and remains a function of that range, so if they stay just past 4x your torus speed will stay close to the minimum), and telescope markers are ships that aren't wreckage or STATUS_DEAD or STATUS_COCKPIT_DISPLAY or STATUS_BEING_SCOOPED, so they have collision enabled.

dybal
Deadly
Deadly
Posts: 144
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

Re: [RELEASE] Towbar OXP v0.101

Post by dybal »

Milo wrote:
Fri Jul 03, 2020 11:37 pm
As for the Torus speed, did you figure out what was causing that? If not, I have a suspect - telescope markers. Torus speed is increased only when distance to nearest entity that has collision enabled exceeds 4x scanner range (and remains a function of that range, so if they stay just past 4x your torus speed will stay close to the minimum), and telescope markers are ships that aren't wreckage or STATUS_DEAD or STATUS_COCKPIT_DISPLAY or STATUS_BEING_SCOOPED, so they have collision enabled.
I isolated it to Telescope, but in some tests with telescope only Torus speed did increase, so I put it in hold (too many itches to scratch... :lol: )

Later I made the same guess you have, that the markers at the scanner border might be the culprit, and the cases when it didn't happen were when I was heading away "into the deep" - no marker in my way.

Post Reply