Second parameter to ship.dumpCargo(amount, type)

Preferred cargo type of first pod to be dumped
This commit is contained in:
cim 2015-04-02 13:46:33 +01:00
parent 2ad8320098
commit 2092e0f766
4 changed files with 39 additions and 8 deletions

View File

@ -146,6 +146,7 @@ Methods:
* ship.adjustCargo(commodity,amount)
* ship.removeCollisionException(ship)
* ship.hasEquipmentProviding(eq)
* ship.dumpCargo(amount, preferredtype) second parameter
* player.ship.equipmentStatus(eqKey,true) second parameter
* SystemInfo.setInterstellarProperty(g,s1,s2,l,k,v,[m])

View File

@ -1122,7 +1122,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
- (BOOL) launchCascadeMine;
- (ShipEntity *) launchEscapeCapsule;
- (OOCommodityType) dumpCargo;
- (ShipEntity *) dumpCargoItem;
- (ShipEntity *) dumpCargoItem:(OOCommodityType)preferred;
- (OOCargoType) dumpItem: (ShipEntity*) jetto;
- (void) manageCollisions;

View File

@ -12341,7 +12341,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
// This is a documented AI method; do not change semantics. (Note: AIs don't have access to the return value.)
- (OOCommodityType) dumpCargo
{
ShipEntity *jetto = [self dumpCargoItem];
ShipEntity *jetto = [self dumpCargoItem:nil];
if (jetto != nil)
{
return [jetto commodityType];
@ -12353,17 +12353,40 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
}
- (ShipEntity *) dumpCargoItem
- (ShipEntity *) dumpCargoItem:(OOCommodityType)preferred
{
ShipEntity *jetto = nil;
NSUInteger i = 0;
if (([cargo count] > 0)&&([UNIVERSE getTime] - cargo_dump_time > 0.5)) // space them 0.5s or 10m apart
{
jetto = [[[cargo objectAtIndex:0] retain] autorelease];
if (preferred == nil)
{
jetto = [[[cargo objectAtIndex:0] retain] autorelease];
}
else
{
BOOL found = NO;
for (i=0;i<[cargo count];i++)
{
if ([[[cargo objectAtIndex:i] commodityType] isEqualToString:preferred])
{
jetto = [[[cargo objectAtIndex:i] retain] autorelease];
found = YES;
break;
}
}
if (found == NO)
{
// dump anything
jetto = [[[cargo objectAtIndex:0] retain] autorelease];
i = 0;
}
}
if (jetto != nil)
{
[self dumpItem:jetto]; // CLASS_CARGO, STATUS_IN_FLIGHT, AI state GLOBAL
[cargo removeObjectAtIndex:0];
[cargo removeObjectAtIndex:i];
[self broadcastAIMessage:@"CARGO_DUMPED"]; // goes only to 16 nearby ships in range, but that should be enough.
unsigned i;
// only send script event to powered entities

View File

@ -2200,7 +2200,8 @@ static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
OOJS_NATIVE_ENTER(context)
ShipEntity *thisEnt = nil;
OOCommodityType pref = nil;
GET_THIS_SHIP(thisEnt);
if (EXPECT_NOT([thisEnt isPlayer] && [(PlayerEntity *)thisEnt isDocked]))
@ -2208,6 +2209,12 @@ static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
OOJSReportWarningForCaller(context, @"PlayerShip", @"dumpCargo", @"Can't dump cargo while docked, ignoring.");
OOJS_RETURN_NULL;
}
if (argc > 1)
{
pref = OOStringFromJSValue(context, OOJS_ARGV[1]);
}
// NPCs can queue multiple items to dump
if (!EXPECT_NOT([thisEnt isPlayer]))
{
@ -2216,7 +2223,7 @@ static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
if (argc > 0) gotCount = JS_ValueToInt32(context, OOJS_ARGV[0], &count);
if (EXPECT_NOT(!gotCount || count < 1 || count > 64))
{
OOJSReportBadArguments(context, @"Ship", @"dumpCargo", MIN(argc, 1U), OOJS_ARGV, nil, @"optional quantity (1 to 64)");
OOJSReportBadArguments(context, @"Ship", @"dumpCargo", MIN(argc, 1U), OOJS_ARGV, nil, @"optional quantity (1 to 64), optional preferred commodity");
return NO;
}
@ -2226,7 +2233,7 @@ static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
}
}
OOJS_RETURN_OBJECT([thisEnt dumpCargoItem]);
OOJS_RETURN_OBJECT([thisEnt dumpCargoItem:pref]);
OOJS_NATIVE_EXIT
}