New ship.setBounty(amount,reason) function to give custom reasons to shipBountyChanged for better inter-OXP communication.
Also fix some bugs with the shipBountyChanged event git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4923 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
c5bf077d42
commit
3303c7a248
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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])
|
||||
|
@ -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];
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user