Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Freeze:Equipment Price & like Ship Price Calculations 1.75.3

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Freeze:Equipment Price & like Ship Price Calculations 1.75.3

Post by Frame »

during my testing, in order to test Equipment fast and being a skint ;-)
i set some equipment to cost 0 credits.. on Oolite 1.75.3

I set a single ship to be able to have this Equipment, called the constrictor X, now renamed ConstrictorBugHUNTER

I did it like this...

equipment.plist

Code: Select all

(
	(
		2, 9, "BUG HUNT EQUIPMENT",
		"EQ_FRAME_BUG_HUNT",
		"Bug hunt equipment",
		{
			available_to_all = true;
		}
	)
)
shipyard.plist

Code: Select all

{
	"CONSTRICTOR-BUG-Player" =
	{
		chance = 1.0;
		"optional_equipment" =
		(
			"EQ_ECM",
			"EQ_FUEL_SCOOPS",
			"EQ_ESCAPE_POD",
			"EQ_ENERGY_BOMB",
			"EQ_ENERGY_UNIT",
			"EQ_NAVAL_ENERGY_UNIT",
			"EQ_DOCK_COMP",
			"EQ_WEAPON_PULSE_LASER",
			"EQ_WEAPON_BEAM_LASER",
			"EQ_WEAPON_MINING_LASER",
			"EQ_WEAPON_MILITARY_LASER",
			"EQ_FUEL_INJECTION",
			"EQ_SCANNER_SHOW_MISSILE_TARGET",
			"EQ_MULTI_TARGET",
			"EQ_GAL_DRIVE",
			"EQ_FRAME_BUG_HUNT"
		);
		price = 0;
		"standard_equipment" =
		{
			extras =
			(
                "EQ_SCANNER_SHOW_MISSILE_TARGET",
                "EQ_MULTI_TARGET"
			);
			"forward_weapon_type" = "EQ_WEAPON_PULSE_LASER";
			missiles = 1;
		};
		techlevel = 2;
		"weapon_facings" = 1;
	};
}
and finally

shipdata.plist

Code: Select all

{
	"CONSTRICTOR-BUG-Player" =
	{
		aft_eject_position = "0.0 5.5 -19.0";
		bounty = 250;
		cargo_type = "CARGO_NOT_CARGO";
		energy_recharge_rate = 5;
		exhaust = ("0.0 0.0 -30.0 6.0 6.0 6.0");
		forward_weapon_type = "WEAPON_MILITARY_LASER";
		fuel = 70;
		has_ecm = yes;
		hyperspace_motor_spin_time = 5;
		has_escape_pod = yes;
		has_fuel_injection = yes;
		likely_cargo = 3;
		max_cargo = 20;
		max_energy = 450;
		max_flight_pitch = 1.75;
		max_flight_roll = 2.5;
		max_flight_speed = 650;
		missile_launch_position = "0.0 -5.5 16.0";
		missiles = 4;
		model = "constrictor_redux.dat";
		materials =
		{
			constrictor_redux.png = { shininess = 20; };
		};
		name = "ConstrictorBUGHunter";
		roles = "player";
		thrust = 50;
		weapon_position_forward = "0.0 0.0 27.5";
		custom_views =
		(
			{
				view_description = "Rear View";
				view_orientation = "1.0 0.0 0.0 0.0";
				view_position = "0.0 30.0 -200.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Rear Right View";
				view_orientation = "0.9239 0.0 0.3827 0.0";
				view_position = "2000.42 30.0 -2000.42";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Right View";
				view_orientation = "0.7071 0.0 0.7071 0.0";
				view_position = "200.0 30.0 0.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front Right View";
				view_orientation = "0.3827 0.0 0.9239 0.0";
				view_position = "2000.42 30.0 2000.42";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front View";
				view_orientation = "0.0 0.0 1.0 0.0";
				view_position = "0.0 30.0 200.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front Left View";
				view_orientation = "0.3827 0.0 -0.9239 0.0";
				view_position = "-2000.42 30.0 2000.42";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Left View";
				view_orientation = "0.7071 0.0 -0.7071 0.0";
				view_position = "-200.0 30.0 0.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Rear Left View";
				view_orientation = "0.9239 0.0 -0.3827 0.0";
				view_position = "-2000.42 30.0 -2000.42";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Top View";
				view_orientation = "-0.7071 0.7071 0.0 0.0";
				view_position = "0.0 200.0 -15.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Bottom View";
				view_orientation = "0.0 0.0 0.7071 0.7071";
				view_position = "0.0 -200.0 -15.0";
				weapon_facing = "FORWARD";
			}
		);
	};
}
This will Freeze Oolite on My machine which is Windows Vista Ultimate(updated).

Notice the price of the Equipment, its "9", or 0.9 credits in Oolite..
Notice that it is also in optional_equipment..

so in order to trigger the freeze I'm referring too, the price of the equipment must be less than 10, and I presume it must be in the Equipment list for one of the following ships on the but new ship(shipyard), page. I had this in optional_equipment for my special ship and therefore had a reproducible freeze of Oolite..

A not completely but nearly similar test case OXP can be found here..

http://www.box.com/s/jvir61xeycb7cl3nak52

I'm in time restraints so i do not have time to log in at the bug tracking feature tracker and add it there..

Cheers Frame....
Bounty Scanner
Number 935
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by Eric Walch »

Frame wrote:
during my testing, in order to test Equipment fast and being a skint ;-)
i set some equipment to cost 0 credits.. on Oolite 1.75.3
I could reproduce the freeze for a Jameson. But i don't think it is dependent on the equipment value. With a cost of 1000 credits I still had a freeze. Than giving the ship itself a value > 0 also gave a freeze.

Than I started with your oxp renamed to "~YourName" so that it was listed as first in my list and the problems were over. They stayed over when putting the values back to zero. So it must be an oxp conflict. But I don'r see why because all your names for the keys should be unique.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6572
Joined: Wed Feb 28, 2007 7:54 am

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by another_commander »

Bug confirmed. The cause is the price of the equipment being less than 10Cr and the offending code is line 7518 of Universe.m, method -shipsForSaleForSystem:

Code: Select all

if (eqPrice > 0)   // <----------------- This is line 7518
					{
						if ([equipmentKey hasPrefix:@"EQ_WEAPON"])
						{
							OOWeaponType new_weapon = OOWeaponTypeFromEquipmentIdentifierSloppy(equipmentKey);
							//fit best weapon forward
							if ([......rest of code]
eqPrice is an unsigned long long number and any equipment value less than 10 will result in it being truncated to 0 near the start of the -shipsForSaleForSystem: method, where a division by 10 is performed on the actual price. As a result, the code below line 7518 will not be run and, since we are in a while loop that goes on until certain conditions have been met, we are effectively looping forever.

The proposed solution is to change the initial price condition to

Code: Select all

if (eqPrice >= 0)
This will take into account also equipment values less than 10 and in my first tests seems to allow the game to carry on running.

I have not been able to cause a freeze as Eric mentioned above, by changing the ship price to be bigger than 0.
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by Micha »

Why exactly are we storing the prices in decicredits, but then working in credits (ie, the div-by-10)?

Why not just keep working in decicredits (or even centi/millicredits if additional accuracy is required) and avoid the rounding issue?
Of course, we'd still need to deal with any 0Cr items in some way so this fix is still needed.

EDIT: Actually, your proposed fix will break equipment tech levels:

Code: Select all

// Higher tech items are rarer!
if (randf() * (eqTechLevel - techlevel) < 1.0)
{
	// All included equip has a 10% discount.
	eqPrice *= (tech_price_boost + eqTechLevel - techlevel) * 90 / 100;
}
else 
	eqPrice = 0;	// Bar this upgrade.
So I re-iterate: Let's just work in decicredits, or even centicredits, and do any rounding right at the end.
The glass is twice as big as it needs to be.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6572
Joined: Wed Feb 28, 2007 7:54 am

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by another_commander »

Micha wrote:
Why exactly are we storing the prices in decicredits, but then working in credits (ie, the div-by-10)?

Why not just keep working in decicredits (or even centi/millicredits if additional accuracy is required) and avoid the rounding issue?
I think you have a fair point there. But I feel the potential to overlook something while trying to correct this is reasonably high. Just to be on the safe side, I would rather leave it with the trivial fix for now and correct it properly as you propose after MNSR. Just my opinion, though.

Edit: Just saw your edit. Let's go for decicredits calculations.
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by Micha »

another_commander wrote:
Edit: Just saw your edit. Let's go for decicredits calculations.
Just had a more detailed look through the routine; seems that 0-price equipment is not the issue; rather, that Frame was setting equipment to 0-price (which would normally disable it) but then also made it a required item.

Even decicredit calculations won't fix Frame's particular situation since he set the price to 0. Using 0.1 wouldn't work either since we apply a 10% discount to equipment prices when pre-fitted (making it 0.09, ie, 0).

So the fix is to
1) remove any equipment items which ends up with a 0-price from the list of available equipment, just as is done with other invalid equipment. If the chance is 1, we can then log it as an OXP bug.

2) Not use a 0-price as the flag and use a separate variable to flag invalid equipment (probably the best option).
The glass is twice as big as it needs to be.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by Eric Walch »

another_commander wrote:
I have not been able to cause a freeze as Eric mentioned above, by changing the ship price to be bigger than 0.
I now also cant reproduce the freeze when setting the name back to the old one. Even not with 0 credits. But that is probably because he now does not try to generate that ship anymore.

Maybe I had problems with flushing the cache? I have had it once before. I have the setting of always flushing the cache, but a few months back I had a situation that none of my oxp changes was recognised. The log always wrote that it had flushed the cache but it hadn't happened, how hard I tried. Using the shift key in addition didn't help either. Only running an older Oolite version in between (That also forces a cache rebuild) made that my oxp changes were recognised. I never had it after that, but there also must be a bug lurking somewhere. I never investigated further.
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Re: Freeze:Equipment Price & like Ship Price Calculations 1.

Post by Micha »

Fixed in r4657.
The glass is twice as big as it needs to be.
Post Reply