diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 727d88a2..782c24bb 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -4510,6 +4510,13 @@ static GLfloat sBaseMass = 0.0; - (void) setBounty:(OOCreditsQuantity)amount withReason:(OOLegalStatusReason)reason +{ + NSString* nReason = OOStringFromLegalStatusReason(reason); + [self setBounty:amount withReasonAsString:nReason]; +} + + +- (void) setBounty:(OOCreditsQuantity)amount withReasonAsString:(NSString *)reason { JSContext *context = OOJSAcquireContext(); @@ -4517,15 +4524,13 @@ static GLfloat sBaseMass = 0.0; int amountVal2 = (int)amount-(int)legalStatus; JS_NewNumberValue(context, amountVal2, &amountVal); - legalStatus = amount; // can't set the new bounty until the size of the change is known - jsval reasonVal = OOJSValueFromLegalStatusReason(context, reason); + jsval reasonVal = OOJSValueFromNativeObject(context,reason); ShipScriptEvent(context, self, "shipBountyChanged", amountVal, reasonVal); OOJSRelinquishContext(context); - } @@ -4554,7 +4559,7 @@ static GLfloat sBaseMass = 0.0; JSContext *context = OOJSAcquireContext(); jsval amountVal = JSVAL_VOID; - int amountVal2 = (legalStatus | offence_value) - offence_value; + int amountVal2 = (legalStatus | offence_value) - legalStatus; JS_NewNumberValue(context, amountVal2, &amountVal); legalStatus |= offence_value; // can't set the new bounty until the size of the change is known diff --git a/src/Core/Entities/ShipEntity.h b/src/Core/Entities/ShipEntity.h index 93086b81..992e09b0 100644 --- a/src/Core/Entities/ShipEntity.h +++ b/src/Core/Entities/ShipEntity.h @@ -729,6 +729,7 @@ typedef enum */ - (void) setBounty:(OOCreditsQuantity) amount; - (void) setBounty:(OOCreditsQuantity) amount withReason:(OOLegalStatusReason)reason; +- (void) setBounty:(OOCreditsQuantity) amount withReasonAsString:(NSString *)reason; - (OOCreditsQuantity) bounty; - (int) legalStatus; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 23f62eca..c7c5bbae 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -5662,7 +5662,20 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context) { if ([self isSubEntity]) { - [[self parentEntity] setBounty:amount]; + [[self parentEntity] setBounty:amount withReason:reason]; + } + else + { + NSString* nReason = OOStringFromLegalStatusReason(reason); + [self setBounty:amount withReasonAsString:nReason]; + } +} + +- (void) setBounty:(OOCreditsQuantity) amount withReasonAsString:(NSString*)reason +{ + if ([self isSubEntity]) + { + [[self parentEntity] setBounty:amount withReasonAsString:reason]; } else { @@ -5673,7 +5686,7 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context) bounty = amount; // can't set the new bounty until the size of the change is known - jsval reasonVal = OOJSValueFromLegalStatusReason(context, reason); + jsval reasonVal = OOJSValueFromNativeObject(context,reason); ShipScriptEvent(context, self, "shipBountyChanged", amountVal, reasonVal); @@ -5683,6 +5696,7 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context) } + - (OOCreditsQuantity) bounty { if ([self isSubEntity]) diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index f0e35f36..b82b615f 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -1621,7 +1621,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl if (trader) { - [ship setBounty:0]; + [ship setBounty:0 withReason:kOOLegalStatusReasonSetup]; [ship setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL]; if (sunskimmer) { @@ -1773,9 +1773,9 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl [police_ship addTarget:[UNIVERSE entityForUniversalID:police_target]]; if ([police_ship scanClass] == CLASS_NOT_SET) [police_ship setScanClass: CLASS_POLICE]; + [police_ship setBounty:0 withReason:kOOLegalStatusReasonSetup]; if ([police_ship heatInsulation] < [self heatInsulation]) [police_ship setHeatInsulation:[self heatInsulation]]; - [police_ship setBounty:0]; [police_ship switchAITo:@"policeInterceptAI.plist"]; [self addShipToLaunchQueue:police_ship :YES]; defenders_launched++; @@ -2011,7 +2011,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl if ([pirate_ship heatInsulation] < [self heatInsulation]) [pirate_ship setHeatInsulation:[self heatInsulation]]; //**Lazygun** added 30 Nov 04 to put a bounty on those pirates' heads. - [pirate_ship setBounty: 10 + floor(randf() * 20)]; // modified for variety + [pirate_ship setBounty: 10 + floor(randf() * 20) withReason:kOOLegalStatusReasonSetup]; // modified for variety [self addShipToLaunchQueue:pirate_ship :NO]; [pirate_ship autorelease]; @@ -2114,7 +2114,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl if ([patrol_ship heatInsulation] < [self heatInsulation]) [patrol_ship setHeatInsulation:[self heatInsulation]]; [patrol_ship setPrimaryRole:@"police"]; - [patrol_ship setBounty:0]; + [patrol_ship setBounty:0 withReason:kOOLegalStatusReasonSetup]; [patrol_ship setGroup:[self stationGroup]]; // who's your Daddy [patrol_ship switchAITo:@"planetPatrolAI.plist"]; [self addShipToLaunchQueue:patrol_ship :NO]; diff --git a/src/Core/Scripting/OOJSShip.m b/src/Core/Scripting/OOJSShip.m index 57d9ff58..3a08e7ea 100644 --- a/src/Core/Scripting/OOJSShip.m +++ b/src/Core/Scripting/OOJSShip.m @@ -77,6 +77,7 @@ static JSBool ShipEquipmentStatus(JSContext *context, uintN argc, jsval *vp); static JSBool ShipSetEquipmentStatus(JSContext *context, uintN argc, jsval *vp); static JSBool ShipSelectNewMissile(JSContext *context, uintN argc, jsval *vp); static JSBool ShipFireMissile(JSContext *context, uintN argc, jsval *vp); +static JSBool ShipSetBounty(JSContext *context, uintN argc, jsval *vp); static JSBool ShipSetCargo(JSContext *context, uintN argc, jsval *vp); static JSBool ShipSetMaterials(JSContext *context, uintN argc, jsval *vp); static JSBool ShipSetShaders(JSContext *context, uintN argc, jsval *vp); @@ -316,6 +317,7 @@ static JSFunctionSpec sShipMethods[] = { "selectNewMissile", ShipSelectNewMissile, 0 }, { "sendAIMessage", ShipSendAIMessage, 1 }, { "setAI", ShipSetAI, 1 }, + { "setBounty", ShipSetBounty, 2 }, { "setCargo", ShipSetCargo, 1 }, { "setEquipmentStatus", ShipSetEquipmentStatus, 2 }, { "setMaterials", ShipSetMaterials, 1 }, @@ -2028,6 +2030,34 @@ static JSBool ShipFireMissile(JSContext *context, uintN argc, jsval *vp) OOJS_NATIVE_EXIT } +// setBounty(amount, reason) +static JSBool ShipSetBounty(JSContext *context, uintN argc, jsval *vp) +{ + OOJS_NATIVE_ENTER(context) + + ShipEntity *thisEnt = nil; + NSString *reason = nil; + int32 newbounty = 0; + BOOL gotBounty = YES; + + GET_THIS_SHIP(thisEnt); + + if (argc > 0) gotBounty = JS_ValueToInt32(context, OOJS_ARGV[0], &newbounty); + if (argc > 1) reason = OOStringFromJSValue(context, OOJS_ARGV[1]); + if (EXPECT_NOT(reason == nil || !gotBounty || newbounty < 0)) + { + OOJSReportBadArguments(context, @"Ship", @"setBounty", argc, OOJS_ARGV, nil, @"new bounty and reason"); + return NO; + } + + [thisEnt setBounty:(OOCreditsQuantity)newbounty withReasonAsString:reason]; + + return YES; + + OOJS_NATIVE_EXIT +} + + // setCargo(cargoType : String [, number : count]) static JSBool ShipSetCargo(JSContext *context, uintN argc, jsval *vp) {