- Laser setting API now takes any valid equipmentInfoExpression

- Laser setting API now works fore and aft for NPCs


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4883 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Chris Morris 2012-04-25 19:03:08 +00:00
parent ad4e2394f1
commit be5d0e26a8
3 changed files with 53 additions and 6 deletions

View File

@ -516,6 +516,7 @@ typedef enum
- (BOOL) hasEquipmentItem:(id)equipmentKeys; // Short for hasEquipmentItem:foo includeWeapons:NO whileLoading:NO
- (BOOL) hasAllEquipment:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading; // Like hasEquipmentItem:includeWeapons:, but requires _all_ elements in collection.
- (BOOL) hasAllEquipment:(id)equipmentKeys; // Short for hasAllEquipment:foo includeWeapons:NO
- (BOOL) setWeaponMount:(int)facing toWeapon:(NSString *)eqKey;
- (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.
- (BOOL) equipmentValidToAdd:(NSString *)equipmentKey whileLoading:(BOOL)loading;

View File

@ -2525,6 +2525,32 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
- (BOOL) setWeaponMount:(int)facing toWeapon:(NSString *)eqKey
{
// sets WEAPON_NONE if not recognised
int chosen_weapon = OOWeaponTypeFromEquipmentIdentifierStrict(eqKey);
switch (facing)
{
case WEAPON_FACING_FORWARD :
forward_weapon_type = chosen_weapon;
break;
case WEAPON_FACING_AFT :
aft_weapon_type = chosen_weapon;
break;
/* // not for now
case WEAPON_FACING_PORT :
port_weapon_type = chosen_weapon;
break;
case WEAPON_FACING_STARBOARD :
starboard_weapon_type = chosen_weapon;
break; */
}
return YES;
}
- (BOOL) addEquipmentItem:(NSString *)equipmentKey
{
return [self addEquipmentItem:equipmentKey withValidation:YES];

View File

@ -691,6 +691,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsid propID, J
Vector vValue;
OOShipGroup *group = nil;
OOColor *colorForScript = nil;
BOOL exists;
if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
if (OOIsStaleEntity(entity)) return YES;
@ -950,20 +951,39 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsid propID, J
}
break;
// TO DO: make these work for NPC ships too
case kShip_aftWeapon:
case kShip_forwardWeapon:
case kShip_portWeapon:
case kShip_starboardWeapon:
if (EXPECT_NOT(![entity isPlayer])) goto npcReadOnly;
sValue = OOStringFromJSValue(context,*value);
case kShip_aftWeapon:
case kShip_forwardWeapon:
sValue = JSValueToEquipmentKeyRelaxed(context, *value, &exists);
if (sValue == nil)
{
sValue = @"EQ_WEAPON_NONE";
}
switch (JSID_TO_INT(propID))
{
case kShip_aftWeapon:
[PLAYER setWeaponMount:WEAPON_FACING_AFT toWeapon:sValue];
if ([entity isPlayer])
{
[PLAYER setWeaponMount:WEAPON_FACING_AFT toWeapon:sValue];
}
else
{
[entity setWeaponMount:WEAPON_FACING_AFT toWeapon:sValue];
}
break;
case kShip_forwardWeapon:
[PLAYER setWeaponMount:WEAPON_FACING_FORWARD toWeapon:sValue];
if ([entity isPlayer])
{
[PLAYER setWeaponMount:WEAPON_FACING_FORWARD toWeapon:sValue];
}
else
{
[entity setWeaponMount:WEAPON_FACING_FORWARD toWeapon:sValue];
}
break;
case kShip_portWeapon:
[PLAYER setWeaponMount:WEAPON_FACING_PORT toWeapon:sValue];