* OXP related compass behaviour update:

- if compass is not visible, compass mode changes are disabled.
- compassTargetChanged now fires when compass display switches from visible to invisible during in-system flight - target is null, signifying the compass is being turned off.
- compassTargetChanged now fires also after willEnterWitchspace, with target undefined, meaning the compass lost its target.
- compassTargetChanged should now fire after a witchjump to a new system, under all circumstances.

* escape_pod_role property added to shipdata, to be used in preference to escape_pod_model
- yet some more, mostly whitespaces, cleanup...


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5359 127b21dd-08f5-0310-b4b7-95ae10353056
master
Marc 2012-09-23 16:27:37 +00:00
parent 97b2ee5e27
commit 53b1c1407d
9 changed files with 143 additions and 58 deletions

View File

@ -270,6 +270,7 @@
"missile_launch_position",
"missile_load_time",
"missile_role",
"escape_pod_role",
"escape_pod_model",
"aft_eject_position",
"auto_ai",

View File

@ -105,7 +105,8 @@
missile_launch_position = "vector";
missile_load_time = "positiveFloat";
missile_role = "$shipRole";
escape_pod_model = "$shipRole";
escape_pod_role = "$shipRole"; // new, improved (1.77)
escape_pod_model = "$shipRole"; // old, deprecated
aft_eject_position = "vector";
auto_ai = "boolean";
script = "$scriptFileName";

View File

@ -139,6 +139,8 @@ static GLfloat sBaseMass = 0.0;
- (double) hyperspaceJumpDistance;
- (OOFuelQuantity) fuelRequiredForJump;
- (void) noteCompassLostTarget;
@end
@ -2158,11 +2160,9 @@ static GLfloat sBaseMass = 0.0;
[[UNIVERSE planet] update: 2.34375 * market_rnd]; // from 0..10 minutes
[[UNIVERSE station] update: 2.34375 * market_rnd]; // from 0..10 minutes
}
[self addTarget:[UNIVERSE entityForUniversalID:_dockTarget]]; // main station in the original system, unless overridden.
[UNIVERSE setBlockJSPlayerShipProps:NO]; // re-enable player.ship!
Entity *dockTargetEntity = [UNIVERSE entityForUniversalID:_dockTarget];
if ([dockTargetEntity isStation]) // also fails if _dockTarget is NO_TARGET
Entity *dockTargetEntity = [UNIVERSE entityForUniversalID:_dockTarget]; // main station in the original system, unless overridden.
if ([dockTargetEntity isStation]) // fails if _dockTarget is NO_TARGET
{
[doppelganger becomeExplosion]; // blow up the doppelganger
// restore player ship
@ -2174,7 +2174,7 @@ static GLfloat sBaseMass = 0.0;
[player_ship release]; // we only wanted it for its polygons!
}
[UNIVERSE setViewDirection:VIEW_FORWARD];
[UNIVERSE setBlockJSPlayerShipProps:NO]; // re-enable player.ship!
[self enterDock:(StationEntity *)dockTargetEntity];
}
else // no dock target? dock target is not a station? game over!
@ -2688,9 +2688,18 @@ static GLfloat sBaseMass = 0.0;
// announce arrival
if ([UNIVERSE planet])
{
[UNIVERSE addMessage:[NSString stringWithFormat:@" %@. ",[UNIVERSE getSystemName:system_seed]] forCount:3.0];
// and reset the compass
if ([self hasEquipmentItem:@"EQ_ADVANCED_COMPASS"])
compassMode = COMPASS_MODE_PLANET;
else
compassMode = COMPASS_MODE_BASIC;
}
else
{
if ([UNIVERSE inInterstellarSpace]) [UNIVERSE addMessage:DESC(@"witch-engine-malfunction") forCount:3.0]; // if sun gone nova, print nothing
}
[self setStatus:STATUS_IN_FLIGHT];
@ -3155,7 +3164,8 @@ static GLfloat sBaseMass = 0.0;
- (BOOL) switchHudTo:(NSString *)hudFileName
{
NSDictionary *hudDict = nil;
BOOL theHudIsHidden = NO;
BOOL wasHidden = NO;
BOOL wasCompassActive = YES;
double scannerZoom = 1.0;
if (!hudFileName) return NO;
@ -3177,7 +3187,9 @@ static GLfloat sBaseMass = 0.0;
if (hud != nil)
{
theHudIsHidden = [hud isHidden];
// remember these values
wasHidden = [hud isHidden];
wasCompassActive = [hud isCompassActive];
scannerZoom = [hud scannerZoom];
}
@ -3187,9 +3199,11 @@ static GLfloat sBaseMass = 0.0;
[hud setHidden:YES]; // hide the hud while rebuilding it.
DESTROY(hud);
hud = [[HeadUpDisplay alloc] initWithDictionary:hudDict inFile:hudFileName];
[hud setScannerZoom:scannerZoom];
[hud resetGuis:hudDict];
[hud setHidden:theHudIsHidden]; // now show it, or reset it to what it was before.
// reset zoom & hidden to what they were before the swich
[hud setScannerZoom:scannerZoom];
[hud setCompassActive:wasCompassActive];
[hud setHidden:wasHidden];
}
return YES;
@ -3565,6 +3579,7 @@ static GLfloat sBaseMass = 0.0;
switch (compassMode)
{
case COMPASS_MODE_INACTIVE:
case COMPASS_MODE_BASIC:
case COMPASS_MODE_PLANET:
beacon = [UNIVERSE lastBeacon];
@ -3633,6 +3648,7 @@ static GLfloat sBaseMass = 0.0;
switch (compassMode)
{
case COMPASS_MODE_INACTIVE:
case COMPASS_MODE_BASIC:
case COMPASS_MODE_PLANET:
aegis = [self checkForAegis];
@ -5206,12 +5222,6 @@ static GLfloat sBaseMass = 0.0;
scanner_zoom_rate = 0.0f;
[UNIVERSE setDisplayText:NO];
//reset the compass
if ([self hasEquipmentItem:@"EQ_ADVANCED_COMPASS"])
compassMode = COMPASS_MODE_PLANET;
else
compassMode = COMPASS_MODE_BASIC;
if ( ![self wormhole] && !galactic_witchjump) // galactic hyperspace does not generate a wormhole
{
OOLog(kOOLogInconsistentState, @"Internal Error : Player entering witchspace with no wormhole.");
@ -5333,6 +5343,21 @@ static GLfloat sBaseMass = 0.0;
}
- (void) noteCompassLostTarget
{
if ([[self hud] isCompassActive])
{
// "the compass, it says we're lost!" :)
JSContext *context = OOJSAcquireContext();
jsval jsmode = OOJSValueFromCompassMode(context, [self compassMode]);
ShipScriptEvent(context, self, "compassTargetChanged", JSVAL_VOID, jsmode);
OOJSRelinquishContext(context);
[[self hud] setCompassActive:NO]; // ensure a target change when returning to normal space.
}
}
- (void) enterGalacticWitchspace
{
if (![self witchJumpChecklist:true])
@ -5340,6 +5365,7 @@ static GLfloat sBaseMass = 0.0;
[self setStatus:STATUS_ENTERING_WITCHSPACE];
ShipScriptEventNoCx(self, "shipWillEnterWitchspace", OOJSSTR("galactic jump"));
[self noteCompassLostTarget];
[self witchStart];
@ -5444,12 +5470,12 @@ static GLfloat sBaseMass = 0.0;
BOOL malfunc = ((ranrot_rand() & 0xff) > malfunc_chance);
// 75% of the time a malfunction means a misjump
BOOL misjump = [self scriptedMisjump] || ((flightPitch == max_flight_pitch) || (malfunc && (randf() > 0.75)));
BOOL misjump = [self scriptedMisjump] || (flightPitch == max_flight_pitch) || (malfunc && (randf() > 0.75));
if (malfunc && !misjump)
{
// some malfunctions will start fuel leaks, some will result in no witchjump at all.
if ([self takeInternalDamage]) // Depending on ship type and loaded cargo, will this return 20 - 50% true.
if ([self takeInternalDamage]) // Depending on ship type and loaded cargo, this will be true for 20 - 50% of the time.
{
[self playWitchjumpFailure];
[self setStatus:STATUS_IN_FLIGHT];
@ -5461,19 +5487,20 @@ static GLfloat sBaseMass = 0.0;
[self setFuelLeak:[NSString stringWithFormat:@"%f", (randf() + randf()) * 5.0]];
}
}
// From this point forward we are -definitely- witchjumping
// burn the full fuel amount to create the wormhole
fuel -= [self fuelRequiredForJump];
// NEW: Create the players' wormhole
// Create the players' wormhole
wormhole = [[WormholeEntity alloc] initWormholeTo:target_system_seed fromShip:self];
[UNIVERSE addEntity:wormhole]; // New new: Add new wormhole to Universe to let other ships target it. Required for ships following the player.
[UNIVERSE addEntity:wormhole]; // Add new wormhole to Universe to let other ships target it. Required for ships following the player.
[self addScannedWormhole:wormhole];
[self setStatus:STATUS_ENTERING_WITCHSPACE];
ShipScriptEventNoCx(self, "shipWillEnterWitchspace", OOJSSTR("standard jump"));
[self noteCompassLostTarget];
if ([self scriptedMisjump]) misjump = YES; // a script could just have changed this to true;
[self witchJumpTo:target_system_seed misjump:misjump];
}

View File

@ -262,7 +262,7 @@ static NSTimeInterval time_last_frame;
LOAD_KEY_SETTING(key_hud_toggle, 'o' );
LOAD_KEY_SETTING(key_comms_log, '`' );
LOAD_KEY_SETTING(key_prev_compass_mode, '|' );
LOAD_KEY_SETTING(key_prev_compass_mode, '|' );
LOAD_KEY_SETTING(key_next_compass_mode, '\\' );
LOAD_KEY_SETTING(key_cloaking_device, '0' );
@ -2813,27 +2813,30 @@ static NSTimeInterval time_last_frame;
scanner_zoom_rate = SCANNER_ZOOM_RATE_DOWN;
}
// Compass mode '|'
if ([gameView isDown:key_prev_compass_mode]) // look for the '|' key
if (EXPECT([[self hud] isCompassActive])) // only switch compass modes if there is a compass
{
if ((!prev_compass_mode_pressed)&&(compassMode != COMPASS_MODE_BASIC))
[self setPrevCompassMode];
prev_compass_mode_pressed = YES;
}
else
{
prev_compass_mode_pressed = NO;
}
// Compass mode '\'
if ([gameView isDown:key_next_compass_mode]) // look for the '\' key
{
if ((!next_compass_mode_pressed)&&(compassMode != COMPASS_MODE_BASIC))
[self setNextCompassMode];
next_compass_mode_pressed = YES;
}
else
{
next_compass_mode_pressed = NO;
// Compass mode '|'
if ([gameView isDown:key_prev_compass_mode]) // look for the '|' key
{
if ((!prev_compass_mode_pressed)&&(compassMode != COMPASS_MODE_BASIC))
[self setPrevCompassMode];
prev_compass_mode_pressed = YES;
}
else
{
prev_compass_mode_pressed = NO;
}
// Compass mode '\'
if ([gameView isDown:key_next_compass_mode]) // look for the '\' key
{
if ((!next_compass_mode_pressed)&&(compassMode != COMPASS_MODE_BASIC))
[self setNextCompassMode];
next_compass_mode_pressed = YES;
}
else
{
next_compass_mode_pressed = NO;
}
}
// show comms log '`'

View File

@ -1862,11 +1862,16 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
ShipEntity *pod = nil;
pod = [UNIVERSE newShipWithRole:[shipinfoDictionary oo_stringForKey:@"escape_pod_model" defaultValue:@"escape-capsule"]];
pod = [UNIVERSE newShipWithRole:[shipinfoDictionary oo_stringForKey:@"escape_pod_role"]]; // or nil
if (!pod)
{
pod = [UNIVERSE newShipWithRole:@"escape-capsule"];
OOLog(@"shipEntity.noEscapePod", @"Ship %@ has no correct escape_pod_model defined. Now using default capsule.", self);
// _role not defined? it might have _model defined;
pod = [UNIVERSE newShipWithRole:[shipinfoDictionary oo_stringForKey:@"escape_pod_model" defaultValue:@"escape-capsule"]];
if (!pod)
{
pod = [UNIVERSE newShipWithRole:@"escape-capsule"];
OOLog(@"shipEntity.noEscapePod", @"Ship %@ has no correct escape_pod_role defined. Now using default capsule.", self);
}
}
if (pod)

View File

@ -238,6 +238,7 @@ MA 02110-1301, USA.
GLfloat _crosshairScale;
GLfloat _crosshairWidth;
NSString *crosshairDefinition;
BOOL _compassActive;
}
@ -261,6 +262,8 @@ MA 02110-1301, USA.
- (BOOL) isHidden;
- (void) setHidden:(BOOL)newValue;
- (BOOL) isCompassActive;
- (void) setCompassActive:(BOOL)newValue;
- (BOOL) isUpdating;
- (void) setDeferredHudName:(NSString *)newDeferredHudName;

View File

@ -152,6 +152,7 @@ enum
- (void) checkMassLock;
- (BOOL) checkEntityForMassLock:(Entity *)ent withScanClass:(int)scanClass;
- (BOOL) checkPlayerInFlight;
- (BOOL) checkPlayerInSystemFlight;
@end
@ -169,7 +170,8 @@ static const GLfloat black_color[4] = {0.0, 0.0, 0.0, 1.0};
static const GLfloat lightgray_color[4] = {0.25, 0.25, 0.25, 1.0};
static float sGlyphWidths[256];
static BOOL scannerUpdated;
static BOOL _scannerUpdated;
static BOOL _compassUpdated;
static BOOL hostiles;
@ -196,6 +198,7 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
- (id) initWithDictionary:(NSDictionary *)hudinfo inFile:(NSString *)hudFileName
{
unsigned i;
BOOL isCompassToBeDrawn = NO;
BOOL areTrumblesToBeDrawn = NO;
self = [super init];
@ -217,6 +220,7 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
{
NSDictionary *dial_info = [dials oo_dictionaryAtIndex:i];
if (!areTrumblesToBeDrawn && [[dial_info oo_stringForKey:SELECTOR_KEY] isEqualToString:@"drawTrumbles:"]) areTrumblesToBeDrawn = YES;
if (!isCompassToBeDrawn && [[dial_info oo_stringForKey:SELECTOR_KEY] isEqualToString:@"drawCompass:"]) isCompassToBeDrawn = YES;
[self addDial:dial_info];
}
@ -225,7 +229,8 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
NSDictionary *trumble_dial_info = [NSDictionary dictionaryWithObjectsAndKeys: @"drawTrumbles:", SELECTOR_KEY, nil];
[self addDial:trumble_dial_info];
}
_compassActive = isCompassToBeDrawn;
NSArray *legends = [hudinfo oo_arrayForKey:LEGENDS_KEY];
for (i = 0; i < [legends count]; i++)
@ -499,6 +504,18 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
}
- (BOOL) isCompassActive
{
return _compassActive;
}
- (void) setCompassActive:(BOOL)newValue
{
_compassActive = !!newValue;
}
- (BOOL) isUpdating
{
return hudUpdating;
@ -673,7 +690,8 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
{
z1 = [[UNIVERSE gameView] display_z];
// reset drawScanner flag.
scannerUpdated = NO;
_scannerUpdated = NO;
_compassUpdated = NO;
// tight loop, we assume dialArray doesn't change in mid-draw.
for (_idx = [dialArray count] - 1; _idx >= 0; _idx--)
@ -682,9 +700,16 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
[self drawHUDItem:[_arrayAtIdx oo_dictionaryAtIndex:WIDGET_INFO]];
}
if (EXPECT_NOT(!_compassUpdated && _compassActive && [self checkPlayerInSystemFlight])) // compass gone / broken / disabled ?
{
// trigger the targetChanged event with whom == null
_compassActive = NO;
[PLAYER doScriptEvent:OOJSID("compassTargetChanged") withArguments:[NSArray arrayWithObjects:[NSNull null], OOStringFromCompassMode([PLAYER compassMode]), nil]];
}
// We always need to check the mass lock status. It's normally checked inside drawScanner,
// but if drawScanner wasn't called, we can check mass lock explicitly.
if (!scannerUpdated) [self checkMassLock];
if (!_scannerUpdated) [self checkMassLock];
}
@ -841,8 +866,9 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
NSString *equipment = [info oo_stringForKey:EQUIPMENT_REQUIRED_KEY];
if (EXPECT_NOT(equipment != nil && ![PLAYER hasEquipmentItem:equipment]))
{
return;
}
// use the selector value stored during init.
[self performSelector:[(NSValue *)[_arrayAtIdx objectAtIndex:WIDGET_SELECTOR] pointerValue] withObject:info];
CheckOpenGLErrors(@"HeadUpDisplay after drawHUDItem %@", info);
@ -857,6 +883,17 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
}
- (BOOL) checkPlayerInSystemFlight
{
OOSunEntity *the_sun = [UNIVERSE sun];
OOPlanetEntity *the_planet = [UNIVERSE planet];
return [self checkPlayerInFlight] // be in the right mode
&& the_sun && the_planet // and be in a system
&& ![the_sun goneNova];
}
- (void) checkMassLock
{
if ([self checkPlayerInFlight])
@ -962,7 +999,7 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
- (void) drawScanner:(NSDictionary *)info
{
if (scannerUpdated) return; // there's never the need to draw the scanner twice per frame!
if (_scannerUpdated) return; // there's never the need to draw the scanner twice per frame!
int i, x, y;
NSSize siz;
@ -1236,7 +1273,7 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
[my_entities[i] release]; // released
}
scannerUpdated = YES;
_scannerUpdated = YES;
}
@ -1345,8 +1382,10 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
switch ([PLAYER compassMode])
{
case COMPASS_MODE_INACTIVE:
break;
case COMPASS_MODE_BASIC:
aegis = [PLAYER checkForAegis];
if ((aegis == AEGIS_CLOSE_TO_MAIN_PLANET || aegis == AEGIS_IN_DOCKING_RANGE) && the_station)
{
@ -1385,8 +1424,9 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
reference = the_planet;
}
if (reference != [PLAYER compassTarget])
if (EXPECT_NOT(!_compassActive || reference != [PLAYER compassTarget]))
{
_compassActive = YES;
[PLAYER setCompassTarget:reference];
[PLAYER doScriptEvent:OOJSID("compassTargetChanged") withArguments:[NSArray arrayWithObjects:reference, OOStringFromCompassMode([PLAYER compassMode]), nil]];
}
@ -1406,6 +1446,9 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
OOGL(GLScaledLineWidth(2.0));
switch ([PLAYER compassMode])
{
case COMPASS_MODE_INACTIVE:
break;
case COMPASS_MODE_BASIC:
[self drawCompassPlanetBlipAt:relativePosition Size:siz Alpha:alpha];
break;
@ -1431,6 +1474,7 @@ static void prefetchData(NSDictionary *info, struct CachedInfo *data)
[[beacon beaconDrawable] oo_drawHUDBeaconIconAt:NSMakePoint(x, y) size:siz alpha:alpha z:z1];
break;
}
_compassUpdated = YES;
}
}

View File

@ -1,4 +1,5 @@
// NOTE: numerical values are available to shaders.
ENTRY(COMPASS_MODE_INACTIVE, -1)
ENTRY(COMPASS_MODE_BASIC, 0)
ENTRY(COMPASS_MODE_PLANET, 1)
ENTRY(COMPASS_MODE_STATION, 3)

View File

@ -9,7 +9,7 @@ ENTRY(CLASS_ROCK, 7)
ENTRY(CLASS_MINE, 8)
ENTRY(CLASS_THARGOID, 9)
ENTRY(CLASS_BUOY, 10)
ENTRY(CLASS_VISUAL_EFFECT, 11)
ENTRY(CLASS_VISUAL_EFFECT, 11)
ENTRY(CLASS_WORMHOLE, 444)
ENTRY(CLASS_PLAYER, 100)
ENTRY(CLASS_POLICE, 999)