From ec727b5dedee70ace0b5547a92870268fb14e3e5 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 9 Dec 2009 19:55:13 +0000 Subject: [PATCH] - fix: awardContract quantities now checked properly git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2866 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Scripting/OOJSShip.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Core/Scripting/OOJSShip.m b/src/Core/Scripting/OOJSShip.m index 196afdaf..87be5689 100644 --- a/src/Core/Scripting/OOJSShip.m +++ b/src/Core/Scripting/OOJSShip.m @@ -1331,6 +1331,7 @@ static JSBool ShipAwardContract(JSContext *context, JSObject *this, uintN argc, ShipEntity *thisEnt = nil; BOOL OK = JSVAL_IS_INT(argv[0]); NSString *key = nil; + int qty = 0; if (!JSShipGetShipEntity(context, this, &thisEnt)) return YES; // stale reference, no-op. @@ -1345,8 +1346,9 @@ static JSBool ShipAwardContract(JSContext *context, JSObject *this, uintN argc, OK = ValidateContracts(context, this, argc, argv, outResult, YES); // always go through validate contracts (cargo) if (!OK) return NO; - unsigned qty = JSVAL_TO_INT(argv[0]); - if (![thisEnt isPlayer] || (qty > [thisEnt availableCargoSpace] || qty < 1)) + qty = JSVAL_TO_INT(argv[0]); + + if (![thisEnt isPlayer] || qty < 1) { OOReportJSWarning(context, @"Ship.%@(): cannot %@.", @"awardContract", @"award contract"); OK = NO; @@ -1367,7 +1369,7 @@ static JSBool ShipAwardContract(JSContext *context, JSObject *this, uintN argc, JS_ValueToNumber(context, argv[4], &eta); JS_ValueToNumber(context, argv[5], &fee); // commodity key is case insensitive. - OK = [(PlayerEntity*)thisEnt awardContract:JSVAL_TO_INT(argv[0]) commodity:key + OK = [(PlayerEntity*)thisEnt awardContract:qty commodity:key start:JSVAL_TO_INT(argv[2]) destination:JSVAL_TO_INT(argv[3]) eta:eta fee:fee]; }