* tentatively added new shipRemoved(Bool removeDeathActions) event.

* refactored initWithGameView and reinitAndShowDemo

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2341 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2009-08-30 22:20:46 +00:00
parent 9a25bab0d2
commit b62fd002fe
2 changed files with 148 additions and 198 deletions

View File

@ -962,16 +962,23 @@ static JSBool ShipExplode(JSContext *context, JSObject *this, uintN argc, jsval
static JSBool ShipRemove(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) static JSBool ShipRemove(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
{ {
ShipEntity *thisEnt = nil; ShipEntity *thisEnt = nil;
JSBool noDeathActions = NO; JSBool removeDeathActions = NO;
if (!JSShipGetShipEntity(context, this, &thisEnt) ) return YES; // stale reference, no-op. if (!JSShipGetShipEntity(context, this, &thisEnt) ) return YES; // stale reference, no-op.
if ([thisEnt isPlayer]) return NO;
if (EXPECT_NOT(!JS_ValueToBoolean(context, argv[0], &noDeathActions))) if ( argc > 0 && EXPECT_NOT(!JS_ValueToBoolean(context, argv[0], &removeDeathActions)))
{ {
OOReportJSBadArguments(context, @"Ship", @"remove", argc, argv, nil, @"boolean"); OOReportJSBadArguments(context, @"Ship", @"remove", argc, argv, nil, @"boolean");
return NO; return NO;
} }
if (noDeathActions && ![thisEnt isPlayer]) [thisEnt removeScript]; [thisEnt doScriptEvent:@"shipRemoved" withArgument:[NSNumber numberWithBool:removeDeathActions]];
if (removeDeathActions)
{
//OOReportJSWarning(context, @"Ship.remove(): all death actions will now be removed from %@", thisEnt);
[thisEnt removeScript];
}
return RemoveOrExplodeShip(context, this, argc, argv, outResult, NO); return RemoveOrExplodeShip(context, this, argc, argv, outResult, NO);
} }

View File

@ -126,6 +126,8 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
- (BOOL)doRemoveEntity:(Entity *)entity; - (BOOL)doRemoveEntity:(Entity *)entity;
- (void) preloadSounds; - (void) preloadSounds;
- (void) initSettings;
- (void) initPlayerSettings;
#if SUPPORT_GRAPHVIZ_OUT #if SUPPORT_GRAPHVIZ_OUT
- (void) dumpDebugGraphViz; - (void) dumpDebugGraphViz;
@ -205,62 +207,11 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
// Load ship data // Load ship data
[OOShipRegistry sharedRegistry]; [OOShipRegistry sharedRegistry];
next_universal_id = 100; // start arbitrarily above zero
entities = [[NSMutableArray arrayWithCapacity:MAX_NUMBER_OF_ENTITIES] retain]; entities = [[NSMutableArray arrayWithCapacity:MAX_NUMBER_OF_ENTITIES] retain];
sun_center_position[0] = 4000000.0;
sun_center_position[1] = 0.0;
sun_center_position[2] = 0.0;
sun_center_position[3] = 1.0;
// this MUST have the default no. of rows else the GUI_ROW macros in PlayerEntity.h need modification // this MUST have the default no. of rows else the GUI_ROW macros in PlayerEntity.h need modification
gui = [[GuiDisplayGen alloc] init]; // alloc retains gui = [[GuiDisplayGen alloc] init]; // alloc retains
comm_log_gui = [[GuiDisplayGen alloc] init]; // alloc retains
message_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(480, 160)
columns:1
rows:9
rowHeight:19
rowStart:20
title:nil];
[message_gui setCurrentRow:8];
[message_gui setCharacterSize:NSMakeSize(16,20)]; // slightly narrower characters
[message_gui setDrawPosition: make_vector(0.0, -40.0, 640.0)];
[message_gui setAlpha:1.0];
comm_log_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(360, 120)
columns:1
rows:10
rowHeight:12
rowStart:12
title:nil];
[comm_log_gui setCurrentRow:9];
[comm_log_gui setBackgroundColor:[OOColor colorWithCalibratedRed:0.0 green:0.05 blue:0.45 alpha:0.5]];
[comm_log_gui setTextColor:[OOColor whiteColor]];
[comm_log_gui setAlpha:0.0];
[comm_log_gui printLongText:DESC(@"communications-log-string") align:GUI_ALIGN_CENTER color:[OOColor yellowColor] fadeTime:0 key:nil addToArray:nil];
[comm_log_gui setDrawPosition: make_vector(0.0, 180.0, 640.0)];
commodityLists = [(NSDictionary *)[ResourceManager dictionaryFromFilesNamed:@"commodities.plist" inFolder:@"Config" andMerge:YES] retain];
commodityData = [[NSArray arrayWithArray:[commodityLists arrayForKey:@"default"]] retain];
illegal_goods = [[ResourceManager dictionaryFromFilesNamed:@"illegal_goods.plist" inFolder:@"Config" andMerge:YES] retain];
characters = [[ResourceManager dictionaryFromFilesNamed:@"characters.plist" inFolder:@"Config" andMerge:YES] retain];
customsounds = [[ResourceManager dictionaryFromFilesNamed:@"customsounds.plist" inFolder:@"Config" andMerge:YES] retain];
[self preloadSounds];
planetInfo = [[ResourceManager dictionaryFromFilesNamed:@"planetinfo.plist" inFolder:@"Config" mergeMode:MERGE_SMART cache:YES] retain];
pirateVictimRoles = [[NSSet alloc] initWithArray:[ResourceManager arrayFromFilesNamed:@"pirate-victim-roles.plist" inFolder:@"Config" andMerge:YES]];
autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
equipmentData = [[ResourceManager arrayFromFilesNamed:@"equipment.plist" inFolder:@"Config" andMerge:YES] retain];
[OOEquipmentType loadEquipment];
localPlanetInfoOverrides = [[NSMutableDictionary alloc] initWithCapacity:8]; localPlanetInfoOverrides = [[NSMutableDictionary alloc] initWithCapacity:8];
@ -268,42 +219,20 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
demo_ships = [[OOShipRegistry sharedRegistry] demoShipKeys]; demo_ships = [[OOShipRegistry sharedRegistry] demoShipKeys];
time_acceleration_factor = TIME_ACCELERATION_FACTOR_DEFAULT; [self initSettings];
player = [[PlayerEntity alloc] init]; // alloc retains! player = [[PlayerEntity alloc] init]; // alloc retains!
[self addEntity:player]; [self addEntity:player];
[player release];
player->x_next = nil; player->x_previous = nil; x_list_start = player;
player->y_next = nil; player->y_previous = nil; y_list_start = player;
player->z_next = nil; player->z_previous = nil; z_list_start = player;
[player setUpShipFromDictionary:[[OOShipRegistry sharedRegistry] shipInfoForKey:[player ship_desc]]]; // ship desc is the standard cobra at this point
[player setStatus:STATUS_START_GAME]; [player setStatus:STATUS_START_GAME];
[player setShowDemoShips: YES]; [player setShowDemoShips: YES];
[self setGalaxy_seed: [player galaxy_seed] andReinit:YES];
system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed];
activeWormholes = [[NSMutableArray arrayWithCapacity:16] retain];
characterPool = [[NSMutableArray arrayWithCapacity:256] retain];
[[GameController sharedController] logProgress:DESC(@"populating-space")]; [[GameController sharedController] logProgress:DESC(@"populating-space")];
[self setUpSpace]; [self initPlayerSettings];
if (cachedStation) [player setPosition:cachedStation->position];
[self setViewDirection:VIEW_GUI_DISPLAY];
universeRegion = [[CollisionRegion alloc] initAsUniverse]; universeRegion = [[CollisionRegion alloc] initAsUniverse];
entitiesDeadThisUpdate = [[NSMutableArray alloc] init]; entitiesDeadThisUpdate = [[NSMutableArray alloc] init];
framesDoneThisUpdate = 0; framesDoneThisUpdate = 0;
OOInitDebugSupport(); OOInitDebugSupport();
@ -311,6 +240,7 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
[[GameController sharedController] logProgress:DESC(@"running-scripts")]; [[GameController sharedController] logProgress:DESC(@"running-scripts")];
[player completeInitialSetUp]; [player completeInitialSetUp];
[player release];
#ifndef NDEBUG #ifndef NDEBUG
[self runLocalizationTools]; [self runLocalizationTools];
@ -414,12 +344,10 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
- (void) reinitAndShowDemo:(BOOL)showDemo - (void) reinitAndShowDemo:(BOOL)showDemo
{ {
PlayerEntity* player = [[PlayerEntity sharedPlayer] retain];
Quaternion q0 = kIdentityQuaternion;
int i;
BOOL delayedReset=NO; BOOL delayedReset=NO;
no_update = YES; no_update = YES;
PlayerEntity* player = [[PlayerEntity sharedPlayer] retain];
[self removeAllEntitiesExceptPlayer:NO]; [self removeAllEntitiesExceptPlayer:NO];
@ -439,91 +367,6 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
speechArray = [[ResourceManager arrayFromFilesNamed:@"speech_pronunciation_guide.plist" inFolder:@"Config" andMerge:YES] retain]; speechArray = [[ResourceManager arrayFromFilesNamed:@"speech_pronunciation_guide.plist" inFolder:@"Config" andMerge:YES] retain];
#endif #endif
firstBeacon = NO_TARGET;
lastBeacon = NO_TARGET;
next_universal_id = 100; // start arbitrarily above zero
for (i = 0; i < MAX_ENTITY_UID; i++)
entity_for_uid[i] = nil;
sun_center_position[0] = 4000000.0;
sun_center_position[1] = 0.0;
sun_center_position[2] = 0.0;
sun_center_position[3] = 1.0;
[gui autorelease];
gui = [[GuiDisplayGen alloc] init];
[message_gui autorelease];
message_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(480, 160)
columns:1
rows:9
rowHeight:19
rowStart:20
title:nil];
[message_gui setCurrentRow:8];
[message_gui setCharacterSize:NSMakeSize(16,20)]; // slightly narrower characters
[message_gui setDrawPosition: make_vector(0.0, -40.0, 640.0)];
[message_gui setAlpha:1.0];
[comm_log_gui autorelease];
comm_log_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(360, 120)
columns:1
rows:10
rowHeight:12
rowStart:12
title:nil];
[comm_log_gui setCurrentRow:9];
[comm_log_gui setBackgroundColor:[OOColor colorWithCalibratedRed:0.0 green:0.05 blue:0.45 alpha:0.5]];
[comm_log_gui setTextColor:[OOColor whiteColor]];
[comm_log_gui setAlpha:0.0];
[comm_log_gui printLongText:DESC(@"communications-log-string") align:GUI_ALIGN_CENTER color:[OOColor yellowColor] fadeTime:0 key:nil addToArray:nil];
[comm_log_gui setDrawPosition: make_vector(0.0, 180.0, 640.0)];
time_delta = 0.0;
time_acceleration_factor = TIME_ACCELERATION_FACTOR_DEFAULT;
universal_time = 0.0;
messageRepeatTime = 0.0;
[commodityLists autorelease];
commodityLists = [[ResourceManager dictionaryFromFilesNamed:@"commodities.plist" inFolder:@"Config" andMerge:YES] retain];
[commodityData autorelease];
commodityData = [[NSArray arrayWithArray:[commodityLists arrayForKey:@"default"]] retain];
[illegal_goods autorelease];
illegal_goods = [[ResourceManager dictionaryFromFilesNamed:@"illegal_goods.plist" inFolder:@"Config" andMerge:YES] retain];
[descriptions autorelease];
descriptions = [[ResourceManager dictionaryFromFilesNamed:@"descriptions.plist" inFolder:@"Config" andMerge:YES] retain];
[characters autorelease];
characters = [[ResourceManager dictionaryFromFilesNamed:@"characters.plist" inFolder:@"Config" andMerge:YES] retain];
[customsounds autorelease];
customsounds = [[ResourceManager dictionaryFromFilesNamed:@"customsounds.plist" inFolder:@"Config" andMerge:YES] retain];
[planetInfo autorelease];
planetInfo = [[ResourceManager dictionaryFromFilesNamed:@"planetinfo.plist" inFolder:@"Config" mergeMode:MERGE_SMART cache:YES] retain];
[pirateVictimRoles autorelease];
pirateVictimRoles = [[NSSet alloc] initWithArray:[ResourceManager arrayFromFilesNamed:@"pirate-victim-roles.plist" inFolder:@"Config" andMerge:YES]];
//[autoAIMap autorelease]; // Having this line in causes a crash when switching from normal to strict and then back to normal.
autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
[equipmentData autorelease];
equipmentData = [[ResourceManager arrayFromFilesNamed:@"equipment.plist" inFolder:@"Config" andMerge:YES] retain];
if (strict && ([equipmentData count] > NUMBER_OF_STRICT_EQUIPMENT_ITEMS))
{
NSArray* strict_equipment = [equipmentData subarrayWithRange:NSMakeRange(0, NUMBER_OF_STRICT_EQUIPMENT_ITEMS)]; // alloc retains
[equipmentData autorelease];
equipmentData = [strict_equipment retain];
}
[OOEquipmentType loadEquipment];
if(showDemo) if(showDemo)
{ {
[demo_ships release]; [demo_ships release];
@ -537,6 +380,8 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
cachedPlanet = nil; cachedPlanet = nil;
cachedStation = nil; cachedStation = nil;
[self initSettings];
if (player == nil) if (player == nil)
player = [[PlayerEntity alloc] init]; player = [[PlayerEntity alloc] init];
else else
@ -545,32 +390,16 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
delayedReset=YES; delayedReset=YES;
} }
[self addEntity:player]; [self addEntity:player];
demo_ship = nil;
[[gameView gameController] setPlayerFileToLoad:nil]; // reset Quicksave [[gameView gameController] setPlayerFileToLoad:nil]; // reset Quicksave
[player setUpShipFromDictionary:[[OOShipRegistry sharedRegistry] shipInfoForKey:[player ship_desc]]]; // ship desc is the standard cobra at this point
if (activeWormholes) [self initPlayerSettings];
[activeWormholes autorelease];
activeWormholes = [[NSMutableArray arrayWithCapacity:16] retain];
[characterPool removeAllObjects]; [player setOrientation:kIdentityQuaternion];
// these lines are needed here to reset systeminfo and long range chart properly
[localPlanetInfoOverrides removeAllObjects];
[self setGalaxy_seed: [player galaxy_seed] andReinit:YES];
system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed];
[self setUpSpace];
[[self station] initialiseLocalMarketWithSeed:system_seed andRandomFactor:[player random_factor]]; [[self station] initialiseLocalMarketWithSeed:system_seed andRandomFactor:[player random_factor]];
[player setDockedAtMainStation]; [player setDockedAtMainStation];
demo_ship = nil;
[self setViewDirection:VIEW_GUI_DISPLAY];
[player setPosition:kZeroVector];
[player setOrientation:q0];
if(showDemo) if(showDemo)
{ {
[player setGuiToIntroFirstGo:NO]; [player setGuiToIntroFirstGo:NO];
@ -8275,6 +8104,120 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context)
@implementation Universe (OOPrivate) @implementation Universe (OOPrivate)
- (void) initSettings
{
int i;
firstBeacon = NO_TARGET;
lastBeacon = NO_TARGET;
next_universal_id = 100; // start arbitrarily above zero
for (i = 0; i < MAX_ENTITY_UID; i++)
entity_for_uid[i] = nil;
sun_center_position[0] = 4000000.0;
sun_center_position[1] = 0.0;
sun_center_position[2] = 0.0;
sun_center_position[3] = 1.0;
[gui autorelease];
gui = [[GuiDisplayGen alloc] init];
[message_gui autorelease];
message_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(480, 160)
columns:1
rows:9
rowHeight:19
rowStart:20
title:nil];
[message_gui setCurrentRow:8];
[message_gui setCharacterSize:NSMakeSize(16,20)]; // slightly narrower characters
[message_gui setDrawPosition: make_vector(0.0, -40.0, 640.0)];
[message_gui setAlpha:1.0];
[comm_log_gui autorelease];
comm_log_gui = [[GuiDisplayGen alloc]
initWithPixelSize:NSMakeSize(360, 120)
columns:1
rows:10
rowHeight:12
rowStart:12
title:nil];
[comm_log_gui setCurrentRow:9];
[comm_log_gui setBackgroundColor:[OOColor colorWithCalibratedRed:0.0 green:0.05 blue:0.45 alpha:0.5]];
[comm_log_gui setTextColor:[OOColor whiteColor]];
[comm_log_gui setAlpha:0.0];
[comm_log_gui printLongText:DESC(@"communications-log-string") align:GUI_ALIGN_CENTER color:[OOColor yellowColor] fadeTime:0 key:nil addToArray:nil];
[comm_log_gui setDrawPosition: make_vector(0.0, 180.0, 640.0)];
time_delta = 0.0;
time_acceleration_factor = TIME_ACCELERATION_FACTOR_DEFAULT;
universal_time = 0.0;
messageRepeatTime = 0.0;
[commodityLists autorelease];
commodityLists = [[ResourceManager dictionaryFromFilesNamed:@"commodities.plist" inFolder:@"Config" andMerge:YES] retain];
[commodityData autorelease];
commodityData = [[NSArray arrayWithArray:[commodityLists arrayForKey:@"default"]] retain];
[illegal_goods autorelease];
illegal_goods = [[ResourceManager dictionaryFromFilesNamed:@"illegal_goods.plist" inFolder:@"Config" andMerge:YES] retain];
[descriptions autorelease];
descriptions = [[ResourceManager dictionaryFromFilesNamed:@"descriptions.plist" inFolder:@"Config" andMerge:YES] retain];
[characters autorelease];
characters = [[ResourceManager dictionaryFromFilesNamed:@"characters.plist" inFolder:@"Config" andMerge:YES] retain];
[customsounds autorelease];
customsounds = [[ResourceManager dictionaryFromFilesNamed:@"customsounds.plist" inFolder:@"Config" andMerge:YES] retain];
[planetInfo autorelease];
planetInfo = [[ResourceManager dictionaryFromFilesNamed:@"planetinfo.plist" inFolder:@"Config" mergeMode:MERGE_SMART cache:YES] retain];
[pirateVictimRoles autorelease];
pirateVictimRoles = [[NSSet alloc] initWithArray:[ResourceManager arrayFromFilesNamed:@"pirate-victim-roles.plist" inFolder:@"Config" andMerge:YES]];
// [autoAIMap autorelease]; // Having this line in causes a crash when switching from normal to strict and then back to normal.
autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
[equipmentData autorelease];
equipmentData = [[ResourceManager arrayFromFilesNamed:@"equipment.plist" inFolder:@"Config" andMerge:YES] retain];
if (strict && ([equipmentData count] > NUMBER_OF_STRICT_EQUIPMENT_ITEMS))
{
NSArray* strict_equipment = [equipmentData subarrayWithRange:NSMakeRange(0, NUMBER_OF_STRICT_EQUIPMENT_ITEMS)]; // alloc retains
[equipmentData autorelease];
equipmentData = [strict_equipment retain];
}
[OOEquipmentType loadEquipment];
}
- (void) initPlayerSettings
{
PlayerEntity* player = [PlayerEntity sharedPlayer];
[player setUpShipFromDictionary:[[OOShipRegistry sharedRegistry] shipInfoForKey:[player ship_desc]]]; // ship desc is the standard cobra at this point
if (activeWormholes) [activeWormholes autorelease];
activeWormholes = [[NSMutableArray arrayWithCapacity:16] retain];
if (characterPool) [characterPool autorelease];
characterPool = [[NSMutableArray arrayWithCapacity:256] retain];
// these lines are needed here to reset systeminfo and long range chart properly
[localPlanetInfoOverrides removeAllObjects];
[self setGalaxy_seed: [player galaxy_seed] andReinit:YES];
system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed];
[self setUpSpace];
[self setViewDirection:VIEW_GUI_DISPLAY];
[player setPosition:[[self station] position]];
}
- (BOOL)doRemoveEntity:(Entity *)entity - (BOOL)doRemoveEntity:(Entity *)entity
{ {
// remove reference to entity in linked lists // remove reference to entity in linked lists