Second parameter to ship.dumpCargo(amount, type)
Preferred cargo type of first pod to be dumped
This commit is contained in:
parent
2ad8320098
commit
2092e0f766
@ -146,6 +146,7 @@ Methods:
|
|||||||
* ship.adjustCargo(commodity,amount)
|
* ship.adjustCargo(commodity,amount)
|
||||||
* ship.removeCollisionException(ship)
|
* ship.removeCollisionException(ship)
|
||||||
* ship.hasEquipmentProviding(eq)
|
* ship.hasEquipmentProviding(eq)
|
||||||
|
* ship.dumpCargo(amount, preferredtype) second parameter
|
||||||
* player.ship.equipmentStatus(eqKey,true) second parameter
|
* player.ship.equipmentStatus(eqKey,true) second parameter
|
||||||
* SystemInfo.setInterstellarProperty(g,s1,s2,l,k,v,[m])
|
* SystemInfo.setInterstellarProperty(g,s1,s2,l,k,v,[m])
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
|||||||
- (BOOL) launchCascadeMine;
|
- (BOOL) launchCascadeMine;
|
||||||
- (ShipEntity *) launchEscapeCapsule;
|
- (ShipEntity *) launchEscapeCapsule;
|
||||||
- (OOCommodityType) dumpCargo;
|
- (OOCommodityType) dumpCargo;
|
||||||
- (ShipEntity *) dumpCargoItem;
|
- (ShipEntity *) dumpCargoItem:(OOCommodityType)preferred;
|
||||||
- (OOCargoType) dumpItem: (ShipEntity*) jetto;
|
- (OOCargoType) dumpItem: (ShipEntity*) jetto;
|
||||||
|
|
||||||
- (void) manageCollisions;
|
- (void) manageCollisions;
|
||||||
|
@ -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.)
|
// This is a documented AI method; do not change semantics. (Note: AIs don't have access to the return value.)
|
||||||
- (OOCommodityType) dumpCargo
|
- (OOCommodityType) dumpCargo
|
||||||
{
|
{
|
||||||
ShipEntity *jetto = [self dumpCargoItem];
|
ShipEntity *jetto = [self dumpCargoItem:nil];
|
||||||
if (jetto != nil)
|
if (jetto != nil)
|
||||||
{
|
{
|
||||||
return [jetto commodityType];
|
return [jetto commodityType];
|
||||||
@ -12353,17 +12353,40 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (ShipEntity *) dumpCargoItem
|
- (ShipEntity *) dumpCargoItem:(OOCommodityType)preferred
|
||||||
{
|
{
|
||||||
ShipEntity *jetto = nil;
|
ShipEntity *jetto = nil;
|
||||||
|
NSUInteger i = 0;
|
||||||
|
|
||||||
if (([cargo count] > 0)&&([UNIVERSE getTime] - cargo_dump_time > 0.5)) // space them 0.5s or 10m apart
|
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)
|
if (jetto != nil)
|
||||||
{
|
{
|
||||||
[self dumpItem:jetto]; // CLASS_CARGO, STATUS_IN_FLIGHT, AI state GLOBAL
|
[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.
|
[self broadcastAIMessage:@"CARGO_DUMPED"]; // goes only to 16 nearby ships in range, but that should be enough.
|
||||||
unsigned i;
|
unsigned i;
|
||||||
// only send script event to powered entities
|
// only send script event to powered entities
|
||||||
|
@ -2200,7 +2200,8 @@ static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
|
|||||||
OOJS_NATIVE_ENTER(context)
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
ShipEntity *thisEnt = nil;
|
ShipEntity *thisEnt = nil;
|
||||||
|
OOCommodityType pref = nil;
|
||||||
|
|
||||||
GET_THIS_SHIP(thisEnt);
|
GET_THIS_SHIP(thisEnt);
|
||||||
|
|
||||||
if (EXPECT_NOT([thisEnt isPlayer] && [(PlayerEntity *)thisEnt isDocked]))
|
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.");
|
OOJSReportWarningForCaller(context, @"PlayerShip", @"dumpCargo", @"Can't dump cargo while docked, ignoring.");
|
||||||
OOJS_RETURN_NULL;
|
OOJS_RETURN_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
pref = OOStringFromJSValue(context, OOJS_ARGV[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// NPCs can queue multiple items to dump
|
// NPCs can queue multiple items to dump
|
||||||
if (!EXPECT_NOT([thisEnt isPlayer]))
|
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 (argc > 0) gotCount = JS_ValueToInt32(context, OOJS_ARGV[0], &count);
|
||||||
if (EXPECT_NOT(!gotCount || count < 1 || count > 64))
|
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;
|
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
|
OOJS_NATIVE_EXIT
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user