- hopefully last tweak to the way available cargo is computed...

- tidied up some warnings, and added a test condition against changing cargo values when Special Cargo is in use.
- corrected a silly mistake in the manifest commodity setter.


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2641 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2009-10-06 16:12:50 +00:00
parent 4009e2259a
commit a7c2cd2578
10 changed files with 78 additions and 16 deletions

View File

@ -5,7 +5,7 @@
<key>default</key>
<array>
<array>
<string>Food</string>
<string>Foiotrrod</string>
<integer>0</integer>
<integer>0</integer>
<integer>19</integer>

View File

@ -270,6 +270,8 @@ typedef enum
double last_fps_check_time;
NSString *planetSearchString;
NSString *missionShipModel;
NSString *missionBackgroundFile;
OOMatrix playerRotMatrix;

View File

@ -93,6 +93,7 @@ static NSString * const kOOLogBuyMountedFailed = @"equip.buy.mounted.failed";
static PlayerEntity *sSharedPlayer = nil;
@interface PlayerEntity (OOPrivate)
- (void) setExtraEquipmentFromFlags;
@ -4611,7 +4612,7 @@ static PlayerEntity *sSharedPlayer = nil;
NSMutableDictionary *commodity = [NSMutableDictionary dictionaryWithCapacity:4];
NSString *symName = [[shipCommodityData oo_arrayAtIndex:i] oo_stringAtIndex:MARKET_NAME] ;
// commodity, quantity - keep consistency between .manifest and .contracts
[commodity setObject:[symName lowercaseString] forKey:@"commodity"];
[commodity setObject:CommodityTypeToString(i) forKey:@"commodity"];
[commodity setObject:[NSNumber numberWithUnsignedInt:in_hold[i]] forKey:@"quantity"];
[commodity setObject:CommodityDisplayNameForSymbolicName(symName) forKey:@"commodityName"];
[commodity setObject:DisplayStringForMassUnitForCommodity(i)forKey:@"unit"];
@ -5993,6 +5994,7 @@ static NSString *last_outfitting_key=nil;
{
OOCargoQuantity amount = [[shipCommodityData oo_arrayAtIndex:type] oo_intAtIndex:MARKET_QUANTITY];
OOMassUnit unit = [UNIVERSE unitsForCommodity:type];
if (unit == UNITS_TONS && [self status] != STATUS_DOCKED)
{
int i;
@ -6016,8 +6018,10 @@ static NSString *last_outfitting_key=nil;
- (OOCargoQuantity) setCargoQuantityForType:(OOCommodityType)type amount:(OOCargoQuantity)amount
{
OOCargoQuantity oldAmount = [self cargoQuantityForType:type];
OOMassUnit unit = [UNIVERSE unitsForCommodity:type];
if([self specialCargo] && unit == UNITS_TONS) return 0; // don't do anything if we've got a special cargo...
OOCargoQuantity oldAmount = [self cargoQuantityForType:type];
OOCargoQuantity available = [self availableCargoSpace];
BOOL inPods = (unit == UNITS_TONS && [self status] != STATUS_DOCKED);
@ -6030,14 +6034,14 @@ static NSString *last_outfitting_key=nil;
// eg: with maxCargo 2 & gold 1499kg, you can still add 1 ton alloy.
else if (unit == UNITS_KILOGRAMS && amount > oldAmount)
{
while (oldAmount >= 1000) available++;
available += oldAmount / 1000;
if (oldAmount % 1000 >= 500) available++;
if (available * 1000 < amount) amount = available * 1000;
if (amount < oldAmount) amount = oldAmount;
}
else if (unit == UNITS_GRAMS && amount > oldAmount)
{
while (oldAmount >= 1000000) available++;
available += oldAmount / 1000000;
if (oldAmount % 1000000 >= 500000) available++;
if (available * 1000000 < amount) amount = available * 1000000;
if (amount < oldAmount) amount = oldAmount;

View File

@ -212,6 +212,8 @@ typedef enum
- (void) showShipModel: (NSString *)shipKey;
- (void) setMissionMusic: (NSString *)value;
- (void) setMissionImage: (NSString *)value;
- (NSString *) getMissionShipModel;
- (NSString *) getMissionImage;
- (void) setFuelLeak: (NSString *)value;
- (NSNumber *)fuelLeakRate_number;

View File

@ -2039,19 +2039,24 @@ static int scriptRandomSeed = -1; // ensure proper random function
}
-(NSString *) getMissionShipModel
{
return missionShipModel;
}
- (void) showShipModel:(NSString *)shipKey
{
ShipEntity *ship;
if (!dockedStation) return;
missionShipModel = nil;
[UNIVERSE removeDemoShips]; // get rid of any pre-existing models on display
if ([shipKey isEqualToString:@"none"] || [shipKey length] == 0) return;
[[PlayerEntity sharedPlayer] setShowDemoShips: YES];
Quaternion q2 = { (GLfloat)0.707, (GLfloat)0.707, (GLfloat)0.0, (GLfloat)0.0};
missionShipModel = [NSString stringWithString:shipKey];
ship = [UNIVERSE newShipWithRole: shipKey]; // retain count = 1
if (ship)
{
@ -2082,13 +2087,21 @@ static int scriptRandomSeed = -1; // ensure proper random function
}
- (NSString *) getMissionImage
{
return missionBackgroundFile;
}
- (void) setMissionImage:(NSString *)value
{
missionBackgroundFile = nil;
[missionBackgroundTexture release];
missionBackgroundTexture = nil;
if ([value length] != 0 && ![[value lowercaseString] isEqual:@"none"])
{
missionBackgroundFile = [NSString stringWithString: value];
missionBackgroundTexture = [OOTexture textureWithName:value inFolder:@"Images"];
[missionBackgroundTexture retain];
}

View File

@ -4555,7 +4555,11 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
quantity = [commodityInfo oo_intAtIndex:MARKET_QUANTITY];
// manifest contains entries for all 17 commodities, whether their quantity is 0 or more.
commodityUnits = [UNIVERSE unitsForCommodity:i];
if (commodityUnits != UNITS_TONS) quantity /= (commodityUnits == UNITS_KILOGRAMS) ? 1000 : 1000000; // Kilos : grams
if (commodityUnits != UNITS_TONS)
{
if (commodityUnits == UNITS_KILOGRAMS) quantity = (quantity + 500) / 1000;
else quantity = (quantity + 500000) / 1000000; // grams
}
cargoQtyOnBoard += quantity;
}
cargoQtyOnBoard += [[self cargo] count];

View File

@ -401,9 +401,15 @@ NSString *CommodityTypeToString(OOCommodityType commodity) // returns the commod
case COMMODITY_ALIEN_ITEMS: return @"alien items";
/*
// normalised commodity identifiers, for post MNSR
case COMMODITY_LIQUOR_WINES: return @"liquor_wines";
case COMMODITY_GEM_STONES: return @"gem_stones";
case COMMODITY_ALIEN_ITEMS: return @"alien_items";
//case COMMODITY_LIQUOR_WINES: return @"liquor_wines";
//case COMMODITY_GEM_STONES: return @"gem_stones";
//case COMMODITY_ALIEN_ITEMS: return @"alien_items";
CO_CASE(LIQUOR_WINES);
CO_CASE(GEM_STONES);
CO_CASE(ALIEN_ITEMS);
*/
CO_CASE(FOOD);
CO_CASE(TEXTILES);

View File

@ -314,6 +314,11 @@ static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsval name
if (!JSVAL_IS_INT(name)) return YES;
//if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
if ([entity specialCargo])
{
OOReportJSWarning(context, @"PlayerShip.manifest['foo'] - cannot modify cargo when Special Cargo is in use.");
return YES;
}
switch (JSVAL_TO_INT(name))
{

View File

@ -65,7 +65,9 @@ static JSClass sMissionClass =
enum
{
// Property IDs
kMission_choice, // selected option, string, read-only.
kMission_choice, // selected option, string, read/write.
kMission_background, // mission background image, string, read/write.
kMission_shipModel, // mission ship model role, string, read/write.
};
@ -73,6 +75,9 @@ static JSPropertySpec sMissionProperties[] =
{
// JS name ID flags
{ "choice", kMission_choice, JSPROP_PERMANENT | JSPROP_ENUMERATE },
//{ "backgroundImage", kMission_background, JSPROP_PERMANENT | JSPROP_ENUMERATE },
//{ "shipModel", kMission_shipModel, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ 0 }
};
@ -118,6 +123,16 @@ static JSBool MissionGetProperty(JSContext *context, JSObject *this, jsval name,
if (result == nil) result = [NSNull null];
break;
case kMission_background:
result = [player getMissionImage];
if (result == nil) result = [NSNull null];
break;
case kMission_shipModel:
result = [player getMissionShipModel];
if (result == nil) result = [NSNull null];
break;
default:
OOReportJSBadPropertySelector(context, @"Mission", JSVAL_TO_INT(name));
return NO;
@ -142,6 +157,16 @@ static JSBool MissionSetProperty(JSContext *context, JSObject *this, jsval name,
if (*value == JSVAL_VOID || *value == JSVAL_NULL) [player resetMissionChoice];
else [player setMissionChoice:[NSString stringWithJavaScriptValue:*value inContext:context]];
break;
case kMission_background:
// If value can't be converted to a string -- this will clear the background image.
[player setMissionImage:JSValToNSString(context,*value)];
break;
case kMission_shipModel:
// If value can't be converted to a string -- this will clear the ship model.
[player showShipModel:JSValToNSString(context, *value)];
break;
default:
OOReportJSBadPropertySelector(context, @"Mission", JSVAL_TO_INT(name));
@ -169,7 +194,7 @@ static JSBool MissionShowMissionScreen(JSContext *context, JSObject *obj, uintN
static JSBool MissionShowShipModel(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
PlayerEntity *player = OOPlayerForScripting();
//OOReportJSWarning(context, @"The function Mission.showShipModel is deprecated and will be removed in a future version of Oolite.");
// If argv[0] can't be converted to a string -- e.g., null or undefined -- this will clear the ship model.
[player showShipModel:JSValToNSString(context,argv[0])];
@ -235,6 +260,7 @@ static JSBool MissionSetBackgroundImage(JSContext *context, JSObject *this, uint
PlayerEntity *player = OOPlayerForScripting();
NSString *key = nil;
//OOReportJSWarning(context, @"The function Mission.setBackgroundImage is deprecated and will be removed in a future version of Oolite.");
if (argc >= 1) key = JSValToNSString(context,argv[0]);
[player setMissionImage:key];

View File

@ -531,7 +531,7 @@ static JSBool PlayerShipAwardCargo(JSContext *context, JSObject *this, uintN arg
OOReportJSErrorForCaller(context, @"PlayerShip", @"awardCargo", @"Cannot award %u units of cargo \"%@\" at this time (use canAwardCargo() to avoid this error).", amount, typeString);
return NO;
}
OOReportJSWarning(context, @"Player.ship.awardCargo('foo',bar) is deprecated and will be removed in a future version of Oolite. Use player.ship.manifest['foo'] = bar instead.");
OOReportJSWarning(context, @"PlayerShip.awardCargo('foo',bar) is deprecated and will be removed in a future version of Oolite. Use .manifest['foo'] = bar; instead.");
[player awardCargoType:type amount:amount];
return YES;
}
@ -566,7 +566,7 @@ static JSBool PlayerShipCanAwardCargo(JSContext *context, JSObject *this, uintN
OOReportJSErrorForCaller(context, @"PlayerShip", @"canAwardCargo", @"Cargo quantity (%i) is negative.", amount);
return NO;
}
OOReportJSWarning(context, @"Player.ship.canAwardCargo() is deprecated and will be removed in a future version of Oolite.");
OOReportJSWarning(context, @"PlayerShip.canAwardCargo() is deprecated and will be removed in a future version of Oolite.");
*outResult = BOOLToJSVal([player canAwardCargoType:type amount:amount]);
return YES;
}