Fixed a bug whereby sometimes equipment would not be added to the arsenal during initialization, due to the canAddEquipment check being performed on a partially complete only equipment list.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1733 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
26584c1f33
commit
1b8301ffc8
@ -5702,6 +5702,7 @@ static int last_outfitting_index;
|
||||
{
|
||||
NSDictionary *dict = nil;
|
||||
NSEnumerator *eqEnum = nil;
|
||||
NSEnumerator *eqEnum2 = nil;
|
||||
NSString *eqDesc = nil;
|
||||
|
||||
if ([equipment isKindOfClass:[NSDictionary class]])
|
||||
@ -5722,6 +5723,7 @@ static int last_outfitting_index;
|
||||
return;
|
||||
}
|
||||
|
||||
eqEnum2 = eqEnum;
|
||||
while ((eqDesc = [eqEnum nextObject]))
|
||||
{
|
||||
/* Bug workaround: extra_equipment should never contain EQ_TRUMBLE,
|
||||
@ -5742,7 +5744,21 @@ static int last_outfitting_index;
|
||||
// Traditional form is a dictionary of booleans; we only accept those where the value is true.
|
||||
if (dict != nil && ![dict boolForKey:eqDesc]) continue;
|
||||
|
||||
[self addEquipmentItem:eqDesc];
|
||||
// We need to add the entire collection without validation first and then remove the items that are
|
||||
// not compliant (like items that do not satisfy the requiresEquipment criterion). This is to avoid
|
||||
// unintentionally excluding valid equipment, just because the required equipment existed but had
|
||||
// not been yet added to the equipment list at the time of the canAddEquipment validation check.
|
||||
// Nikos, 20080817.
|
||||
[self addEquipmentItem:eqDesc withValidation:NO];
|
||||
}
|
||||
|
||||
// Now remove items that should not be in the equipment list.
|
||||
while (eqDesc = [eqEnum2 nextObject])
|
||||
{
|
||||
if (![self canAddEquipment:eqDesc])
|
||||
{
|
||||
[self removeEquipmentItem:eqDesc];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,6 +365,7 @@ MA 02110-1301, USA.
|
||||
- (BOOL) hasAllEquipment:(id)equipmentKeys; // As above, but requires _all_ equipment in collection.
|
||||
- (BOOL) canAddEquipment:(NSString *)equipmentKey; // Test ability to add equipment, taking equipment-specific constriants into account.
|
||||
- (void) addEquipmentItem:(NSString *)equipmentKey;
|
||||
- (void) addEquipmentItem:(NSString *)equipmentKey withValidation:(BOOL)validateAddition;
|
||||
/* NOTE: for legacy reasons, canAddEquipment: returns YES if given a missile
|
||||
or mine type, but addEquipmentItem: does nothing in those cases. This
|
||||
should probably be cleaned up by making addEquipmentItem: mount stores.
|
||||
|
@ -1763,10 +1763,16 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
|
||||
|
||||
|
||||
- (void) addEquipmentItem:(NSString *)equipmentKey
|
||||
{
|
||||
[self addEquipmentItem:equipmentKey withValidation:YES];
|
||||
}
|
||||
|
||||
|
||||
- (void) addEquipmentItem:(NSString *)equipmentKey withValidation:(BOOL)validateAddition
|
||||
{
|
||||
OOEquipmentType *eqType = nil;
|
||||
|
||||
if (![self canAddEquipment:equipmentKey]) return;
|
||||
if (validateAddition == YES && ![self canAddEquipment:equipmentKey]) return;
|
||||
eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentKey];
|
||||
|
||||
// FIXME: deal with special handling of missiles and mines.
|
||||
|
Loading…
x
Reference in New Issue
Block a user