requires_equipment, requires_any_equipment and incompatible_with_equipment restrictions now work for weapons.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2218 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2009-06-21 13:27:07 +00:00
parent 106fbe6ea6
commit 0285f07250
2 changed files with 32 additions and 17 deletions

View File

@ -368,8 +368,9 @@ MA 02110-1301, USA.
// Equipment
- (BOOL) hasEquipmentItem:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons; // This can take a string or an set or array of strings. If a collection, returns YES if ship has _any_ of the specified equipment. If includeWeapons is NO, missiles and primary weapons are not checked.
- (BOOL) hasEquipmentItem:(id)equipmentKeys; // Short for hasEquipmentItem:foo includeWeapons:NO
- (BOOL) hasAllEquipment:(id)equipmentKeys; // Like hasEquipmentItem:, but requires _all_ equipment in collection.
- (BOOL) canAddEquipment:(NSString *)equipmentKey; // Test ability to add equipment, taking equipment-specific constriants into account.
- (BOOL) hasAllEquipment:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons; // Like hasEquipmentItem:includeWeapons:, but requires _all_ elements in collection.
- (BOOL) hasAllEquipment:(id)equipmentKeys; // Short for hasAllEquipment:foo includeWeapons:NO
- (BOOL) canAddEquipment:(NSString *)equipmentKey; // Test ability to add equipment, taking equipment-specific constriants into account.
- (BOOL) equipmentValidToAdd:(NSString *)equipmentKey; // Actual test if equipment satisfies validation criteria.
- (void) addEquipmentItem:(NSString *)equipmentKey;
- (void) addEquipmentItem:(NSString *)equipmentKey withValidation:(BOOL)validateAddition;

View File

@ -1774,6 +1774,23 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
// Equipment
- (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeWeapons:(BOOL)includeWeapons
{
if ([self hasOneEquipmentItem:itemKey includeMissiles:includeWeapons]) return YES;
if (includeWeapons)
{
// Check for primary weapon
OOWeaponType weaponType = EquipmentStringToWeaponTypeStrict(itemKey);
if (weaponType != WEAPON_NONE)
{
if ([self hasPrimaryWeapon:weaponType]) return YES;
}
}
return NO;
}
- (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeMissiles:(BOOL)includeMissiles
{
if ([_equipment containsObject:itemKey]) return YES;
@ -1829,16 +1846,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
for (keyEnum = [equipmentKeys objectEnumerator]; (key = [keyEnum nextObject]); )
{
if ([self hasOneEquipmentItem:key includeMissiles:includeWeapons]) return YES;
if (includeWeapons)
{
// Check for primary weapon
OOWeaponType weaponType = EquipmentStringToWeaponTypeStrict(key);
if (weaponType != WEAPON_NONE)
{
if ([self hasPrimaryWeapon:weaponType]) return YES;
}
}
if ([self hasOneEquipmentItem:key includeWeapons:includeWeapons]) return YES;
}
return NO;
@ -1851,7 +1859,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
- (BOOL) hasAllEquipment:(id)equipmentKeys
- (BOOL) hasAllEquipment:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons
{
NSEnumerator *keyEnum = nil;
id key = nil;
@ -1864,13 +1872,19 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
for (keyEnum = [equipmentKeys objectEnumerator]; (key = [keyEnum nextObject]); )
{
if (![_equipment containsObject:key]) return NO;
if (![self hasOneEquipmentItem:key includeWeapons:includeWeapons]) return NO;
}
return YES;
}
- (BOOL) hasAllEquipment:(id)equipmentKeys
{
return [self hasAllEquipment:equipmentKeys includeWeapons:NO];
}
- (BOOL) canAddEquipment:(NSString *)equipmentKey
{
if ([equipmentKey hasSuffix:@"_DAMAGED"])
@ -1902,9 +1916,9 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
if ([eqType requiresEmptyPylon] && [self missileCount] >= [self missileCapacity]) return NO;
if ([eqType requiresMountedPylon] && [self missileCount] == 0) return NO;
if ([self availableCargoSpace] < [eqType requiredCargoSpace]) return NO;
if ([eqType requiresEquipment] != nil && ![self hasAllEquipment:[eqType requiresEquipment]]) return NO;
if ([eqType requiresAnyEquipment] != nil && ![self hasEquipmentItem:[eqType requiresAnyEquipment]]) return NO;
if ([eqType incompatibleEquipment] != nil && [self hasEquipmentItem:[eqType incompatibleEquipment]]) return NO;
if ([eqType requiresEquipment] != nil && ![self hasAllEquipment:[eqType requiresEquipment] includeWeapons:YES]) return NO;
if ([eqType requiresAnyEquipment] != nil && ![self hasEquipmentItem:[eqType requiresAnyEquipment] includeWeapons:YES]) return NO;
if ([eqType incompatibleEquipment] != nil && [self hasEquipmentItem:[eqType incompatibleEquipment] includeWeapons:YES]) return NO;
if ([eqType requiresCleanLegalRecord] && [self legalStatus] != 0) return NO;
if ([eqType requiresNonCleanLegalRecord] && [self legalStatus] == 0) return NO;
if ([eqType requiresFreePassengerBerth] && [self passengerCount] >= [self passengerCapacity]) return NO;