From 36e064d1ee4aa244154b44588fe7d4340234abc8 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 3 Jan 2011 15:34:28 +0000 Subject: [PATCH] Minor cleanup: - changed strings returned by the new playerWillSaveGame event for consistency with the other Oolite specific strings: 'autoSave' is now 'AUTO_SAVE', etc... - tidier / simpler to read fuel calculation code, made fuel price slightly more variable... - rewrote a very misleading (wrong as per r3972) comment. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3973 127b21dd-08f5-0310-b4b7-95ae10353056 --- Resources/Config/logcontrol.plist | 2 +- src/Core/Entities/PlayerEntity.m | 8 +++----- src/Core/Entities/PlayerEntityLoadSave.m | 10 +++++----- src/Core/Entities/ShipEntity.m | 24 +++++------------------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/Resources/Config/logcontrol.plist b/Resources/Config/logcontrol.plist index 9b7f1b2d..58ceaf5f 100644 --- a/Resources/Config/logcontrol.plist +++ b/Resources/Config/logcontrol.plist @@ -297,7 +297,7 @@ script.javaScript.stackTrace.timeLimit = yes; // ...for time limiter script.javaScript.stackTrace.warning = inherit; // ...for warnings - script.javaScript.warning.uselessExpr = no; // A bug in SpiderMonkey causes this warning to be raised when "use strict" is seen in pedantic mode, even though "use strict" is respected. https://bugzilla.mozilla.org/show_bug.cgi?id=559402 + script.javaScript.warning.uselessExpr = yes; // A bug in SpiderMonkey causes this warning to be raised when "use strict" is seen in pedantic mode, even though "use strict" is respected. https://bugzilla.mozilla.org/show_bug.cgi?id=559402 script.load = no; script.load.badName = $scriptError; diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 60c08369..4b6d70c2 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -4462,16 +4462,14 @@ static bool minShieldLevelPercentageInitialised = false; [self suppressTargetLost]; // No target lost messages when dead. [self setStatus:STATUS_DEAD]; [self playGameOver]; - - // Let event scripts check for specific equipment on board when the player dies. + + // Let event scripts know the player died. if (whom == nil) whom = (id)[NSNull null]; [self doScriptEvent:@"shipDied" withArguments:[NSArray arrayWithObjects:whom, why, nil]]; [self setStatus:STATUS_DEAD]; // set dead again in case a script managed to revive the player. - // Then remove the equipment. This should avoid accidental scooping / equipment damage when dead. - [self removeAllEquipment]; + [self removeAllEquipment]; // No scooping / equipment damage when dead. [self loseTargetStatus]; [self showGameOver]; - } diff --git a/src/Core/Entities/PlayerEntityLoadSave.m b/src/Core/Entities/PlayerEntityLoadSave.m index 7e619dda..b7d0239e 100644 --- a/src/Core/Entities/PlayerEntityLoadSave.m +++ b/src/Core/Entities/PlayerEntityLoadSave.m @@ -3,7 +3,7 @@ PlayerEntityLoadSave.m Oolite - Copyright (C) 2004-2010 Giles C Williams and contributors + Copyright (C) 2004-2011 Giles C Williams and contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -142,7 +142,7 @@ static uint16_t PersonalityForCommanderDict(NSDictionary *dict); tmp_name = player_name; tmp_path = save_path; - [self doScriptEvent:@"playerWillSaveGame" withArgument:@"autoSave"]; + [self doScriptEvent:@"playerWillSaveGame" withArgument:@"AUTO_SAVE"]; NSString *saveName = player_name; if (![player_name hasSuffix:DESC(@"autosave-commander-suffix")]) @@ -182,7 +182,7 @@ static uint16_t PersonalityForCommanderDict(NSDictionary *dict); format:@"ERROR no file name returned by [[gameView gameController] playerFileToLoad]"]; } - [self doScriptEvent:@"playerWillSaveGame" withArgument:@"quickSave"]; + [self doScriptEvent:@"playerWillSaveGame" withArgument:@"QUICK_SAVE"]; [self writePlayerToPath:path]; [[UNIVERSE gameView] supressKeysUntilKeyUp]; @@ -581,7 +581,7 @@ static uint16_t PersonalityForCommanderDict(NSDictionary *dict); NSArray* path_components = [[sp filename] pathComponents]; NSString* new_name = [[path_components objectAtIndex:[path_components count]-1] stringByDeletingPathExtension]; - [self doScriptEvent:@"playerWillSaveGame" withArgument:@"standardSave"]; + [self doScriptEvent:@"playerWillSaveGame" withArgument:@"STANDARD_SAVE"]; [player_name release]; player_name = [new_name copy]; @@ -636,7 +636,7 @@ static uint16_t PersonalityForCommanderDict(NSDictionary *dict); NSString* dir = [[UNIVERSE gameController] playerFileDirectory]; NSString *savePath = [dir stringByAppendingPathComponent:[cdrName stringByAppendingPathExtension:@"oolite-save"]]; - [self doScriptEvent:@"playerWillSaveGame" withArgument:@"standardSave"]; + [self doScriptEvent:@"playerWillSaveGame" withArgument:@"STANDARD_SAVE"]; [player_name release]; player_name = [cdrName copy]; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 315a604c..167e8594 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -100,27 +100,13 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change #if MASS_DEPENDENT_FUEL_PRICES static GLfloat calcFuelChargeRate (GLfloat my_mass, GLfloat base_mass) { + static const GLfloat massCharge = 0.65; // the closer to 1 this number is, the more the fuel price changes from ship to ship. + static const GLfloat baseCharge = 1.0 - massCharge; // proportion of price that doesn't change with ship's mass. + // if anything is wrong, default to cobra3 value. - if (my_mass == 0.0 || base_mass == 0.0) return 1.0; + if (my_mass <= 0.0 || base_mass <= 0.0) return 1.0; - GLfloat x = my_mass / base_mass; - - static const GLfloat b = 0.6; - static const GLfloat c = 0.4; - -/* - static const GLfloat a = 0.0; - static const GLfloat n = 1.0; - - // axⁿ+bx+c, where x is mass(player)/mass(base) - // result is normalised so that player==base gives 1.0 - // base is normally the default player ship - - GLfloat result = (a * powf (x, n) + b * x + c) / (a + b + c); -*/ - - // given the const values above, we can use a simpler alternative to get the same result: - GLfloat result = b * x + c; + GLfloat result = (massCharge * my_mass / base_mass) + baseCharge; // round the result to the second decimal digit. return (roundf ((float) (result * 100.0)) / 100.0);