Fixed damaged equipment handling.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1692 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2008-07-13 13:18:03 +00:00
parent fb3b2b7ebe
commit 51748cae1c
6 changed files with 42 additions and 16 deletions

View File

@ -583,7 +583,7 @@ waitingForStickCallback: 1;
- (void) docked;
- (void) setGuiToStatusScreen;
- (NSArray *) equipmentList;
- (NSArray *) equipmentList; // Each entry is an array with a string followed by a boolean indicating availability (NO = damaged).
- (NSArray *) cargoList;
- (void) setGuiToSystemDataScreen;
- (NSArray *) markedDestinations;

View File

@ -3996,31 +3996,45 @@ double scoopSoundPlayTime = 0.0;
NSMutableArray *quip = [NSMutableArray arrayWithCapacity:[eqTypes count]];
NSEnumerator *eqTypeEnum = nil;
OOEquipmentType *eqType = nil;
NSString *desc = nil;
for (eqTypeEnum = [eqTypes objectEnumerator]; (eqType = [eqTypeEnum nextObject]); )
{
if ([self hasEquipmentItem:[eqType identifier]])
{
[quip addObject:[eqType name]];
[quip addObject:[NSArray arrayWithObjects:[eqType name], [NSNumber numberWithBool:YES], nil]];
}
else if (![UNIVERSE strict])
{
// Check for damaged version
if ([self hasEquipmentItem:[[eqType identifier] stringByAppendingString:@"_DAMAGED"]])
{
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-@-not-available"), [eqType name]]];
desc = [NSString stringWithFormat:DESC(@"equipment-@-not-available"), [eqType name]];
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:NO], nil]];
}
}
}
if (forward_weapon > WEAPON_NONE)
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-fwd-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:forward_weapon]]];
{
desc = [NSString stringWithFormat:DESC(@"equipment-fwd-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:forward_weapon]];
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
}
if (aft_weapon > WEAPON_NONE)
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-aft-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:aft_weapon]]];
{
desc = [NSString stringWithFormat:DESC(@"equipment-aft-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:aft_weapon]];
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
}
if (starboard_weapon > WEAPON_NONE)
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-stb-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:starboard_weapon]]];
{
desc = [NSString stringWithFormat:DESC(@"equipment-stb-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:starboard_weapon]];
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
}
if (port_weapon > WEAPON_NONE)
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-port-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:port_weapon]]];
{
desc = [NSString stringWithFormat:DESC(@"equipment-port-weapon-@"),[UNIVERSE descriptionForArrayKey:@"weapon_name" index:port_weapon]];
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
}
if (max_passengers > 0)
{
@ -4028,14 +4042,15 @@ double scoopSoundPlayTime = 0.0;
// may have quite different ways of phrasing the two.
if (max_passengers > 1)
{
[quip addObject:[NSString stringWithFormat:DESC(@"equipment-multiple-pass-berth-@"), max_passengers]];
desc = [NSString stringWithFormat:DESC(@"equipment-multiple-pass-berth-@"), max_passengers];
}
else
{
[quip addObject:DESC(@"equipment-single-pass-berth-@")];
desc = DESC(@"equipment-single-pass-berth-@");
}
[quip addObject:[NSArray arrayWithObjects:desc, [NSNumber numberWithBool:YES], nil]];
}
return quip;
}

View File

@ -1240,7 +1240,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
OOLog(kOOLogSyntaxAwardEquipment, @"SCRIPT ERROR in %@ ***** CANNOT award undamaged weapon:'%@'. Damaged weapons can be awarded instead.", CurrentScriptDesc(), equipString);
return;
}
if ([equipString hasSuffix:@"_DAMAGED"] && [self hasEquipmentItem:[equipString substringToIndex:[equipString length]-8]])
if ([equipString hasSuffix:@"_DAMAGED"] && [self hasEquipmentItem:[equipString substringToIndex:[equipString length] - [@"_DAMAGED" length]]])
{
OOLog(kOOLogSyntaxAwardEquipment, @"SCRIPT ERROR in %@ ***** CANNOT award damaged equipment:'%@'. Undamaged version already equipped.", CurrentScriptDesc(), equipString);
}

View File

@ -1683,6 +1683,11 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
OOEquipmentType *eqType = nil;
if ([equipmentKey hasSuffix:@"_DAMAGED"])
{
equipmentKey = [equipmentKey substringToIndex:[equipmentKey length] - [@"_DAMAGED" length]];
}
eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentKey];
if (eqType == nil) return NO;

View File

@ -762,18 +762,22 @@ OOINLINE BOOL RowInRange(OOGUIRow row, NSRange range)
for (i=0; i < equipment_list_items_count; i++)
{
// Damaged items in the equipment list appear in orange color.
BOOL is_eqpt_damaged = [[eqptList objectAtIndex:i] hasSuffix:DESC(@"equipment-not-available")];
if (is_eqpt_damaged == YES) glColor4f (1.0f, 0.5f, 0.0f, 1.0f);
NSArray *info = [eqptList objectAtIndex:i];
NSString *name = [info stringAtIndex:0];
BOOL damaged = ![info boolAtIndex:1];
if (damaged) glColor4f (1.0f, 0.5f, 0.0f, 1.0f);
if (i < eqpt_items_per_column)
{
drawString ([eqptList objectAtIndex:i], -220, 40 - (15 * i), z, NSMakeSize(15,15));
drawString (name, -220, 40 - (15 * i), z, NSMakeSize(15, 15));
}
else
{
drawString ([eqptList objectAtIndex:i], 50, 40 - (15 * (i - eqpt_items_per_column)), z, NSMakeSize(15,15));
drawString (name, 50, 40 - (15 * (i - eqpt_items_per_column)), z, NSMakeSize(15, 15));
}
glColor4f (1.0f, 1.0f, 0.0f, 1.0f); // Reset text color to yellow.
if (damaged) glColor4f (1.0f, 1.0f, 0.0f, 1.0f); // Reset text color to yellow.
}
}

View File

@ -7233,6 +7233,8 @@ double estimatedTimeForJourney(double distance, int hops)
if (passenger_berths == 0)
{
// This will be needed to construct the description for passenger berths.
// Note: use of lowercaseString is bad from an i18n perspective,
// but the string is never actually shown anyway...
passengerBerthLongDesc = [NSString stringWithFormat:@"%@", [eqLongDesc lowercaseString]];
}
passenger_berths++;