Page 1 of 2

Equipment-overrides :-/

Posted: Sun Nov 26, 2023 3:28 pm
by Killer Wolf
Struggling w/ this [and everything else, lol].

wiki says its entries override the normal equipment plist, so i've taken the stock equipment plist, renamed it and tweaked prices. docked at my station, nothing. log says
"[plist.wrongType]: Property list is wrong type - expected NSDictionary, got GSArray."
which i seems to be due to this plist, though it doesn't say specifically ~ when i changed something i got a different error then got the error back when i reverted. Not sure why i'd get it when i copied the stock plist though, wiki doesn't seem to suggest i need other entries?

tried docking at the main station in case there was some quirk w/ my own but it's the same standard list there.

TIA

Re: Equipment-overrides :-/

Posted: Sun Nov 26, 2023 7:34 pm
by phkb
The format of the equipment-overrides.plist is slightly different to the equipment.plist file by necessity. A sample file is shown, where some (but not all) of the core pulse laser properties are being updated:

Code: Select all

{
	"EQ_WEAPON_PULSE_LASER" = {
		techlevel = 7;
		price = 50000;
		short_description = "Laser Pointer";
		long_description = "A simple, all purpose (but weak) laser. Only useful for irritating pirates.";
		available_to_all = YES;
		weapon_info = {
			color = "whiteColor";
		};
	};
}
The biggest difference is that this is a dictionary of dictionaries file (similar to the shipdata-overrides.plist file), where the equipment key is the primary dictionary key. techlevel, price, short and long descriptions are now keys, along with all the other settings.

Re: Equipment-overrides :-/

Posted: Wed Nov 29, 2023 11:20 am
by Killer Wolf
magic, thanks bud :-)

Re: Equipment-overrides :-/

Posted: Fri Dec 01, 2023 4:43 pm
by Killer Wolf
can you not make new equipment and the overrides particular to a single place? i was tweaking my station to have some better prices but it's all displaying in another Coriolis too.

Re: Equipment-overrides :-/

Posted: Fri Dec 01, 2023 9:17 pm
by phkb
Killer Wolf wrote: Fri Dec 01, 2023 4:43 pm
can you not make new equipment and the overrides particular to a single place? i was tweaking my station to have some better prices but it's all displaying in another Coriolis too.
If you add a condition_script to your equipment item (either in equipment.plist, or in equipment-overrides.plist) you can do two things:

1. use the allowAwardEquipment to control the visibility of the item at a station:
For example, this code will only offer the equipment item for sale if the player is docked at a station with a particular data key:

Code: Select all

this.allowAwardEquipment = function (equipment, ship, context) {
	if (context == "scripted") return true; // you should always do this at the top of this function.
	if (equipment == "EQ_MY_EQUIPKEY" && ship.isPlayer) {
		if (player.ship.dockedStation.dataKey == "my_station") {
			return true;
		}
	}
	return false;
}
2. use the updateEquipmentPrice to change the price of an equipment item.
For example, this code will take 50% off the normal price of an item when you're docked at a particular station

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	if (equipment == "EQ_MY_EQUIPKEY") {
		if (player.ship.dockedStation.dataKey == "my_station") {
			newprice = parseInt(newprice * 0.5);
		}
	}
	return newprice;
}
Note: This code is executed before the station's equipmentPriceFactor is applied, so further changes to the price could occur if that value is something other than 1.0.

Hope that helps!

Re: Equipment-overrides :-/

Posted: Sat Dec 02, 2023 11:39 am
by Killer Wolf
thanks agan bud, i'll have a bit experiment :-)

Re: Equipment-overrides :-/

Posted: Wed Dec 06, 2023 4:29 pm
by Killer Wolf
seem to have the new equipment working but my prices are still not playing. in my equipment-overrides i've got entries like

Code: Select all

"EQ_MISSILE" = {
		"condition_script" = "KWiiprices.js";
		};
	
	"EQ_CARGO_BAY" = {
		"condition_script" = "KWiiprices.js";
		};
and as you had above KWiiprices is

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	if (equipment == "EQ_FUEL" || "EQ_MISSILE" || "EQ_CARGO_BAY") {
		if (player.ship.dockedStation.dataKey == "KW_II") {
			newprice = parseInt(newprice * 0.5);
		}
	}
	return newprice;
}
but i'm not getting the recalc :-(
is my if statement wrong?

Re: Equipment-overrides :-/

Posted: Wed Dec 06, 2023 9:03 pm
by phkb
Killer Wolf wrote: Wed Dec 06, 2023 4:29 pm
is my if statement wrong?
Kind of.

There's a couple of ways to handle it. If you just want to apply the same discount to *everything*, you'd be better off setting the equipment_price_factor of the station in your shipdata.plist file.

However, if you only want to discount some selected items, and again use the same discount for all of them, here's some options:

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	if (equipment == "EQ_FUEL" || equipment == "EQ_MISSILE" || equipment == "EQ_CARGO_BAY") {
		if (player.ship.dockedStation.dataKey == "KW_II") {
			newprice = parseInt(newprice * 0.5);
		}
	}
	return newprice;
}
A lot of typing with that one, and it ends up being unreadable once you have a lot of items.
Then there's this:

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	if (["EQ_FUEL", "EQ_MISSILE", "EQ_CARGO_BAY"].indexOf(equipment) >= 0) {
		if (player.ship.dockedStation.dataKey == "KW_II") {
			newprice = parseInt(newprice * 0.5);
		}
	}
	return newprice;
}
We're essentially creating an array and checking the if the equipment item matches one of the elements. If it does, the index will be zero or higher. You just add extra items into the array to expand the list.

Another alternative is:

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	switch (equipment) {
		case "EQ_FUEL":
		case "EQ_MISSILE":
		case "EQ_CARGO_BAY":
			if (player.ship.dockedStation.dataKey == "KW_II") {
				newprice = parseInt(newprice * 0.5);
			}
			break;
	}
	return newprice;
}
Here we're using a switch statement, which is kind of like a structured If statement. What this is making use of is the "fall through" processing that a switch statement has. Basically, we start by telling the switch what we're switching on (ie, the equipment variable). Then we specify each of the cases the switch needs to consider. Normally, you'd have the "break;" command after each case, because switch statements will fall through the cases until it hits one. But in this case, by only having the one "break;" we've essentially created a large OR statement. It reads like this:
If equipment is equal to "EQ_FUEL" OR is equal to "EQ_MISSILE" OR is equal to "EQ_CARGO_BAY", then execute the code following. If equipment is not equal to any of those, then skip everything.

The benefit of this last version is it makes it relatively easy to change your mind about discounts on certain items. For instance, if you decide you want to only have a 25% discount on missiles, you rearrange it like this:

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	switch (equipment) {
		case "EQ_MISSILE":
			if (player.ship.dockedStation.dataKey == "KW_II") {
				newprice = parseInt(newprice * 0.75);
			}
			break;
		case "EQ_FUEL":
		case "EQ_CARGO_BAY":
			if (player.ship.dockedStation.dataKey == "KW_II") {
				newprice = parseInt(newprice * 0.5);
			}
			break;
	}
	return newprice;
}
Of course, you'd end up checking the datakey of the docked station a lot that way. So, one final change I'd make would be to make all that checking unnecessary by doing this:

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	if (player.ship.dockedStation.dataKey != "KW_II") return currentPrice;
	var newprice = currentPrice;
	switch (equipment) {
		case "EQ_MISSILE":
			newprice = parseInt(newprice * 0.75);
			break;
		case "EQ_FUEL":
		case "EQ_CARGO_BAY":
			newprice = parseInt(newprice * 0.5);
			break;
	}
	return newprice;
}
Anyway, hope that helps a bit.

Re: Equipment-overrides :-/

Posted: Thu Dec 07, 2023 3:10 pm
by Killer Wolf
can't get that to work [your last example], do i still leave the overrides plist as it is, w/ the
"EQ_MISSILE" = {
"condition_script" = "KWiiprices.js";
};

"EQ_CARGO_BAY" = {
"condition_script" = "KWiiprices.js";
};

stuff in it?

Re: Equipment-overrides :-/

Posted: Thu Dec 07, 2023 8:45 pm
by phkb
Killer Wolf wrote: Thu Dec 07, 2023 3:10 pm
do i still leave the overrides plist as it is,
Yes, if you want to do anything with the core equipment items, you'll need to use the overrides.plist

Does your full overrides file look like this:

Code: Select all

{
	"EQ_MISSILE" = {
		"condition_script" = "KWiiprices.js";
	};

	"EQ_CARGO_BAY" = {
		"condition_script" = "KWiiprices.js";
	};
}
It needs the curly braces around the entire list, just like a shipdata-overrides.plist.

Re: Equipment-overrides :-/

Posted: Fri Dec 08, 2023 1:53 pm
by Killer Wolf
yeah, EQ_FUEL has the long and short description in it too but aside from that it looks ok, everything compiles and is recognised ok, it's just that, eg, a cargo bay is being offered at C400 when i dock, instead of C200.

script is

Code: Select all

this.updateEquipmentPrice - function (equipment, currentPrice) {
	var newprice = currentPrice;
	switch (equipment) {
		case "EQ_MISSILE":
			if (player.ship.dockedStation.dataKey == "KW_II") {
				newprice = parseInt(newprice * 0.75);
			}
			break;
		case "EQ_FUEL":
		case "EQ_CARGO_BAY":
			if (player.ship.dockedStation.dataKey == "KW_II") {
				newprice = parseInt(newprice * 0.5);
			}
			break;
	}
	return newprice;
}

Re: Equipment-overrides :-/

Posted: Fri Dec 08, 2023 7:44 pm
by phkb

Code: Select all

 this.updateEquipmentPrice - function (equipment, currentPrice) {
Your problem is in this line. That should be an = before “function”, not a -.

Re: Equipment-overrides :-/

Posted: Fri Dec 08, 2023 9:22 pm
by hiran
phkb wrote: Fri Dec 08, 2023 7:44 pm

Code: Select all

 this.updateEquipmentPrice - function (equipment, currentPrice) {
Your problem is in this line. That should be an = before “function”, not a -.
Could a linter spot the evaluation of a value without storing it somewhere?

Re: Equipment-overrides :-/

Posted: Fri Dec 08, 2023 9:57 pm
by phkb
hiran wrote: Fri Dec 08, 2023 9:22 pm
Could a linter spot the evaluation of a value without storing it somewhere?
Not sure. I don’t use a Linter normally (I’m a bit old school that way), so I’m not sure what they’re capable of. I probably should look into using one though.

Re: Equipment-overrides :-/

Posted: Sat Dec 09, 2023 8:55 am
by hiran
phkb wrote: Fri Dec 08, 2023 9:57 pm
hiran wrote: Fri Dec 08, 2023 9:22 pm
Could a linter spot the evaluation of a value without storing it somewhere?
Not sure. I don’t use a Linter normally (I’m a bit old school that way), so I’m not sure what they’re capable of. I probably should look into using one though.
We are talking JavaScript, aren't we? I just googled a bit and found
https://eslint.org/docs/latest/rules/no ... xpressions

It may not spot this situation since the function can have side effects. But then it should spot it since the function call would still not require the minus operation.

We simply need to try this out. Maybe we embed this linter into the Oolite builds to check the resources, and it could also go into the expansion verifier.