Fixes to fuel/mass prices:

- always uses the current cobra3 mass as its base mass.
 - no on-the-fly fuel rate recalculations anymore.
 - removed the (already marked for '#fuel charge testing' only) fuel_charge_rate savegame key.
Clean up: an initial setup method inside Universe now has a more meaningful name.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4526 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2011-04-26 10:03:31 +00:00
parent a1b28ecb52
commit b05f83cc8c
3 changed files with 52 additions and 76 deletions

View File

@ -168,6 +168,22 @@ static GLfloat sBaseMass = 0.0;
- (GLfloat) baseMass
{
if (sBaseMass <= 0.0)
{
// First call with initialised mass (in [UNIVERSE setUpInitialUniverse]) is always to the cobra 3, even when starting with a savegame.
if ([self mass] > 0.0) // bootstrap the base mass.
{
// OOLog(@"fuelPrices.debug", @"Setting Cobra3 base mass to: %.2f ", [self mass]);
sBaseMass = [self mass];
}
else
{
// This happened on startup when [UNIVERSE setUpSpace] was called before player init, inside [UNIVERSE setUpInitialUniverse].
// OOLog(@"fuelPrices.debug", @"Player ship not initialised properly yet, using precalculated base mass.");
return 185580.0;
}
}
return sBaseMass;
}
@ -524,7 +540,6 @@ static GLfloat sBaseMass = 0.0;
*/
[result oo_setFloat:credits forKey:@"credits"];
[result oo_setUnsignedInteger:fuel forKey:@"fuel"];
[result oo_setFloat:fuel_charge_rate forKey:@"fuel_charge_rate"]; // ## fuel charge testing
[result oo_setInteger:galaxy_number forKey:@"galaxy_number"];
@ -732,6 +747,7 @@ static GLfloat sBaseMass = 0.0;
NSDictionary *shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:[self shipDataKey]];
if (shipDict == nil) return NO;
if (![self setUpShipFromDictionary:shipDict]) return NO;
//OOLog(@"fuelPrices.debug", @"Bought \"%@\" fuel charge rate: %.2f", [self shipDataKey],fuel_charge_rate);
// ship depreciation
ship_trade_in_factor = [dict oo_intForKey:@"ship_trade_in_factor" defaultValue:95];
@ -854,10 +870,6 @@ static GLfloat sBaseMass = 0.0;
credits = OODeciCreditsFromObject([dict objectForKey:@"credits"]);
fuel = [dict oo_unsignedIntForKey:@"fuel" defaultValue:fuel];
fuel_charge_rate = [UNIVERSE strict]
? 1.0
: [dict oo_floatForKey:@"fuel_charge_rate" defaultValue:fuel_charge_rate]; // ## fuel charge testing
galaxy_number = [dict oo_intForKey:@"galaxy_number"];
forward_weapon_type = [dict oo_intForKey:@"forward_weapon"];
aft_weapon_type = [dict oo_intForKey:@"aft_weapon"];
@ -1307,12 +1319,6 @@ static GLfloat sBaseMass = 0.0;
if (![super setUpFromDictionary:shipDict]) return NO;
// boostrap base mass at program startup!
if (sBaseMass == 0.0 && [[self shipDataKey] isEqualTo:PLAYER_SHIP_DESC])
{
sBaseMass = [self mass];
}
// Player-only settings.
//
// set control factors..

View File

@ -100,15 +100,16 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
#if MASS_DEPENDENT_FUEL_PRICES
static GLfloat calcFuelChargeRate (GLfloat my_mass, GLfloat base_mass)
static GLfloat calcFuelChargeRate (GLfloat myMass)
{
#define kMassCharge 0.65 // the closer to 1 this number is, the more the fuel price changes from ship to ship.
#define kBaseCharge (1.0 - kMassCharge) // proportion of price that doesn't change with ship's mass.
GLfloat baseMass = [PLAYER baseMass];
// if anything is wrong, use 1 (the default charge rate).
if (myMass <= 0.0 || baseMass <=0.0) return 1.0;
// if anything is wrong, default to cobra3 value.
if (my_mass <= 0.0 || base_mass <= 0.0) return 1.0;
GLfloat result = (kMassCharge * my_mass / base_mass) + kBaseCharge;
GLfloat result = (kMassCharge * myMass / baseMass) + kBaseCharge;
// round the result to the second decimal digit.
return (roundf ((float) (result * 100.0)) / 100.0);
@ -348,39 +349,32 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
float density = [shipDict oo_floatForKey:@"density" defaultValue:1.0f];
if (octree) mass = (GLfloat)(density * 20.0 * [octree volume]);
fuel_charge_rate = 1.0; // Standard (& strict play) charge rate.
#if MASS_DEPENDENT_FUEL_PRICES
// set up fuel scooping & charging
if ([UNIVERSE strict])
// Fuel scooping and prices are relative to the mass of the cobra3.
// NB: finally removed the "fuel_charge_rate" test-only key (was never meant for actual use). Kaks 20110425
if (![UNIVERSE strict])
{
fuel_charge_rate = 1.0;
}
else
{
#if 0
// Temporary fix for mass-dependent fuel prices.
// See [ShipEntity fuelChargeRate] for more information.
// - MKW 2011.03.11
GLfloat rate = 1.0;
if (PLAYER != nil)
{
rate = calcFuelChargeRate (mass, [PLAYER baseMass]);
}
fuel_charge_rate = (rate > 0.0) ? rate : 1.0;
GLfloat rate = 1.0;
NSString *shipKey = [self shipDataKey];
rate = [shipDict oo_floatForKey:@"fuel_charge_rate" defaultValue:fuel_charge_rate];
if (rate != fuel_charge_rate)
if (PLAYER != nil &&
![shipKey isEqualTo:PLAYER_SHIP_DESC]) // cobra3 rate is always 1!
{
// clamp the charge rate at no more than three times, and no less than about a third of the calculated value.
if (rate < 0.33 * fuel_charge_rate) fuel_charge_rate *= 0.33;
else if (rate > 3 * fuel_charge_rate) fuel_charge_rate *= 3;
else fuel_charge_rate = rate;
rate = calcFuelChargeRate (mass);
}
#else
fuel_charge_rate = [shipDict oo_floatForKey:@"fuel_charge_rate" defaultValue:1.0f];
#endif
// Make sure that the rate is clamped to between three times and a third of the standard charge rate.
if (rate < 0.33) rate = 0.33;
else if (rate > 3) rate = 3;
//OOLog(@"fuelPrices.debug", @"\"%@\" fuel charge rate: %.2f (mass ratio: %.2f/%.2f)", shipKey, rate, mass, [PLAYER baseMass]);
fuel_charge_rate = rate;
}
#else
fuel_charge_rate = 1.0;
#endif
OOColor *color = [OOColor brightColorWithDescription:[shipDict objectForKey:@"laser_color"]];
@ -4246,7 +4240,6 @@ static GLfloat scripted_color[4] = { 0.0, 0.0, 0.0, 0.0}; // to be defined by s
}
- (BOOL) isJammingScanning
{
return ([self hasMilitaryJammer] && military_jammer_active);
@ -5364,33 +5357,8 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
- (GLfloat) fuelChargeRate
{
#if MASS_DEPENDENT_FUEL_PRICES
// Interim mass-dependent fuel price fix. The current implentation
// in setUpFromDictionary: is no longer working because at player
// ship setup time, it is only partially configured and has no mass.
// - MKW 2011.03.11
GLfloat rate = 1.0f;
if (![UNIVERSE strict] && [self mass] > 0.0)
{
#define kCobra3Mass (185580) // the base mass of a Cobra Mk III
rate = calcFuelChargeRate([self mass], kCobra3Mass);
if (rate <= 0.0f) rate = 1.0f;
#undef kCobra3Mass
// clamp the charge rate at no more than three times, and no less than about a third of the calculated value.
if ((fuel_charge_rate != 1.0f) && (fuel_charge_rate != rate))
{
if (fuel_charge_rate < 0.33f * rate) rate *= 0.33f;
else if (fuel_charge_rate > 3.0f * rate) rate *= 3.0f;
else rate = fuel_charge_rate;
}
}
return rate;
#else
//OOLog(@"fuelPrices.debug", @"querying charge rate: %.2f ", fuel_charge_rate);
return fuel_charge_rate;
#endif
}

View File

@ -186,7 +186,7 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
- (BOOL) doRemoveEntity:(Entity *)entity;
- (void) preloadSounds;
- (void) setUpSettings;
- (void) setUpPlayerSettings;
- (void) setUpInitialUniverse;
- (ShipEntity *) spawnPatrolShipAt:(Vector)launchPos alongRoute:(Vector)v_route withOffset:(double)ship_location;
- (Vector) fractionalPositionFrom:(Vector)point0 to:(Vector)point1 withFraction:(double)routeFraction;
@ -292,6 +292,7 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
[[GameController sharedController] logProgress:DESC(@"loading-ships")];
// Load ship data
[OOShipRegistry sharedRegistry];
entities = [[NSMutableArray arrayWithCapacity:MAX_NUMBER_OF_ENTITIES] retain];
@ -321,7 +322,7 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
[player setStatus:STATUS_START_GAME];
[player setShowDemoShips: YES];
[self setUpPlayerSettings];
[self setUpInitialUniverse];
universeRegion = [[CollisionRegion alloc] initAsUniverse];
entitiesDeadThisUpdate = [[NSMutableSet alloc] init];
@ -8472,7 +8473,7 @@ Entity *gOOJSPlayerIfStale = nil;
demo_ship = nil;
[[gameView gameController] setPlayerFileToLoad:nil]; // reset Quicksave
[self setUpPlayerSettings];
[self setUpInitialUniverse];
autoSaveNow = NO; // don't autosave immediately after loading / restarting game!
[[self station] initialiseLocalMarketWithRandomFactor:[player random_factor]];
@ -8500,8 +8501,7 @@ Entity *gOOJSPlayerIfStale = nil;
}
// FIXME: how is this stuff "player settings"?
- (void) setUpPlayerSettings
- (void) setUpInitialUniverse
{
PlayerEntity* player = PLAYER;
@ -8521,12 +8521,14 @@ Entity *gOOJSPlayerIfStale = nil;
[self setGalaxySeed: [player galaxy_seed] andReinit:YES];
system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed];
OO_DEBUG_POP_PROGRESS();
[self setUpSpace];
OO_DEBUG_PUSH_PROGRESS(@"Player init: setUpShipFromDictionary", __PRETTY_FUNCTION__);
[player setUpShipFromDictionary:[[OOShipRegistry sharedRegistry] shipInfoForKey:[player shipDataKey]]]; // the standard cobra at this point
OO_DEBUG_POP_PROGRESS();
// Player init above finishes initialising all standard player ship properties. Now that the base mass is set, we can run setUpSpace!
[self setUpSpace];
[self setViewDirection:VIEW_GUI_DISPLAY];
[player setPosition:[[self station] position]];
[player setOrientation:kIdentityQuaternion];