Added script events for planet and station proximity events. Fast PowerPC square root approximation is now actually used. Redefined nil and Nil to be type-pedantic under Cocoa (as they are under GNUstep). Waved a rubber chicken to appease the compiler.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1401 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
c5b9b92365
commit
4b3a74e847
@ -237,6 +237,7 @@
|
||||
1A2319B80B9D031D00EF0852 /* warning.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A40B9D031D00EF0852 /* warning.ogg */; };
|
||||
1A2319B90B9D031D00EF0852 /* witchabort.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A50B9D031D00EF0852 /* witchabort.ogg */; };
|
||||
1A231A180B9D8B1B00EF0852 /* OOCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A231A160B9D8B1B00EF0852 /* OOCacheManager.h */; };
|
||||
1A2324FC0D6ED7C2003578B6 /* OOJSClock.h in Copy Debug OXP */ = {isa = PBXBuildFile; fileRef = 1A6B25EC0C9C2745000717CF /* OOJSClock.h */; };
|
||||
1A26D0AC0BCF9CF80073F257 /* PlayerEntityLegacyScriptEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0880BCF9CF70073F257 /* PlayerEntityLegacyScriptEngine.m */; };
|
||||
1A26D0AD0BCF9CF80073F257 /* ShipEntityAI.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0890BCF9CF70073F257 /* ShipEntityAI.m */; };
|
||||
1A26D0AE0BCF9CF80073F257 /* ShipEntityAI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A26D08A0BCF9CF70073F257 /* ShipEntityAI.h */; };
|
||||
@ -975,6 +976,7 @@
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
1AD267650C83058C00B4BFD1 /* Debug.oxp in Copy Debug OXP */,
|
||||
1A2324FC0D6ED7C2003578B6 /* OOJSClock.h in Copy Debug OXP */,
|
||||
);
|
||||
name = "Copy Debug OXP";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -326,16 +326,16 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
|
||||
|
||||
NSBitmapImageRep* bitmapRep =
|
||||
[[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes: nil // --> let the class allocate it
|
||||
initWithBitmapDataPlanes:NULL // --> let the class allocate it
|
||||
pixelsWide: w
|
||||
pixelsHigh: h
|
||||
bitsPerSample: 8 // each component is 8 bits (1 byte)
|
||||
samplesPerPixel: 3 // number of components (R, G, B)
|
||||
hasAlpha: NO // no transparency
|
||||
isPlanar: NO // data integrated into single plane
|
||||
bitsPerSample: 8 // each component is 8 bits (1 byte)
|
||||
samplesPerPixel: 3 // number of components (R, G, B)
|
||||
hasAlpha: NO // no transparency
|
||||
isPlanar: NO // data integrated into single plane
|
||||
colorSpaceName: NSDeviceRGBColorSpace
|
||||
bytesPerRow: 3*w // can no longer let the class figure it out
|
||||
bitsPerPixel: 24 // can no longer let the class figure it out
|
||||
bytesPerRow: 3*w // can no longer let the class figure it out
|
||||
bitsPerPixel: 24 // can no longer let the class figure it out
|
||||
];
|
||||
|
||||
unsigned char *pixels = [bitmapRep bitmapData];
|
||||
|
@ -186,7 +186,7 @@ enum
|
||||
if (OK)
|
||||
{
|
||||
context = calloc(1, sizeof *context);
|
||||
if (nil != context)
|
||||
if (context != NULL)
|
||||
{
|
||||
*outContext = (OOCASoundRenderContext)context;
|
||||
context->loop = inLoop;
|
||||
|
@ -127,7 +127,7 @@ static NSString *GetAppName(void);
|
||||
static BOOL sInited = NO;
|
||||
static BOOL sWriteToStderr = YES;
|
||||
static OOAsyncLogger *sLogger = nil;
|
||||
static LogCStringFunctionProc sDefaultLogCStringFunction = nil;
|
||||
static LogCStringFunctionProc sDefaultLogCStringFunction = NULL;
|
||||
static NSString *sLogFileName = @"Latest.log";
|
||||
|
||||
|
||||
@ -462,7 +462,7 @@ enum
|
||||
*/
|
||||
static void LoadLogCStringFunctions(void)
|
||||
{
|
||||
CFBundleRef foundationBundle = nil;
|
||||
CFBundleRef foundationBundle = NULL;
|
||||
LogCStringFunctionGetterProc getter = NULL;
|
||||
LogCStringFunctionSetterProc setter = NULL;
|
||||
|
||||
|
@ -1006,21 +1006,21 @@ static GLfloat texture_uv_array[10400 * 2];
|
||||
|
||||
- (NSString*) descriptionComponents
|
||||
{
|
||||
NSString* type_string;
|
||||
NSString *typeString;
|
||||
switch (planet_type)
|
||||
{
|
||||
case PLANET_TYPE_MINIATURE:
|
||||
type_string = @"PLANET_TYPE_MINIATURE"; break;
|
||||
typeString = @"PLANET_TYPE_MINIATURE"; break;
|
||||
case PLANET_TYPE_SUN:
|
||||
type_string = @"PLANET_TYPE_SUN"; break;
|
||||
typeString = @"PLANET_TYPE_SUN"; break;
|
||||
case PLANET_TYPE_GREEN:
|
||||
type_string = @"PLANET_TYPE_GREEN"; break;
|
||||
typeString = @"PLANET_TYPE_GREEN"; break;
|
||||
case PLANET_TYPE_ATMOSPHERE:
|
||||
type_string = @"PLANET_TYPE_ATMOSPHERE"; break;
|
||||
typeString = @"PLANET_TYPE_ATMOSPHERE"; break;
|
||||
default :
|
||||
type_string = @"UNKNOWN";
|
||||
typeString = @"UNKNOWN";
|
||||
}
|
||||
return [NSString stringWithFormat:@"%@ type: %@ radius: %.3fkm", [super descriptionComponents], type_string, 0.001 * [self radius]];
|
||||
return [NSString stringWithFormat:@"ID: %u position: %@ %@ type: %@ radius: %.3fkm", [self universalID], VectorDescription([self position]), typeString, 0.001 * [self radius]];
|
||||
}
|
||||
|
||||
|
||||
|
@ -2589,6 +2589,7 @@ static BOOL toggling_music;
|
||||
station = dockedStation; // leaveDock will clear dockedStation.
|
||||
[self leaveDock:dockedStation];
|
||||
[UNIVERSE setDisplayCursor:NO];
|
||||
suppressAegisMessages = YES;
|
||||
if ([self checkForAegis] != AEGIS_NONE)
|
||||
{
|
||||
[self setCompassMode:COMPASS_MODE_STATION];
|
||||
@ -2597,6 +2598,7 @@ static BOOL toggling_music;
|
||||
{
|
||||
[self setCompassMode:COMPASS_MODE_PLANET];
|
||||
}
|
||||
suppressAegisMessages = NO;
|
||||
[self doScriptEvent:@"shipWillLaunchFromStation" withArgument:station];
|
||||
[self playBreakPattern];
|
||||
}
|
||||
|
@ -157,12 +157,12 @@ MA 02110-1301, USA.
|
||||
is_hulk: 1, // This is used to distinguish abandoned ships from cargo
|
||||
trackCloseContacts: 1,
|
||||
|
||||
// check for landing on planet
|
||||
isNearPlanetSurface: 1,
|
||||
isNearPlanetSurface: 1, // check for landing on planet
|
||||
isFrangible: 1, // frangible => subentities can be damaged individually
|
||||
cloaking_device_active: 1, // cloaking_device
|
||||
canFragment: 1, // Can it break into wreckage?
|
||||
suppressExplosion: 1, // Avoid exploding on death (script hook)
|
||||
suppressAegisMessages: 1, // No script/AI messages sent by -checkForAegis
|
||||
|
||||
// scripting
|
||||
haveExecutedSpawnAction: 1,
|
||||
|
@ -1043,10 +1043,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
|
||||
|
||||
- (Triangle) absoluteIJKForSubentity
|
||||
{
|
||||
Triangle result;
|
||||
result.v[0] = kBasisXVector;
|
||||
result.v[1] = kBasisYVector;
|
||||
result.v[2] = kBasisZVector;
|
||||
Triangle result = {{ kBasisXVector, kBasisYVector, kBasisZVector, kZeroVector }};
|
||||
Entity *last = nil;
|
||||
Entity *father = self;
|
||||
OOMatrix r_mat;
|
||||
@ -3094,6 +3091,22 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
|
||||
}
|
||||
|
||||
|
||||
- (void) transitionToAegisNone
|
||||
{
|
||||
if (!suppressAegisMessages && aegis_status != AEGIS_NONE)
|
||||
{
|
||||
if (aegis_status == AEGIS_IN_DOCKING_RANGE)
|
||||
{
|
||||
[self doScriptEvent:@"shipExitedStationAegis"];
|
||||
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
|
||||
}
|
||||
[self doScriptEvent:@"shipExitedPlanetaryVicinity"];
|
||||
[shipAI message:@"AEGIS_NONE"];
|
||||
}
|
||||
aegis_status = AEGIS_NONE;
|
||||
}
|
||||
|
||||
|
||||
- (OOAegisStatus) checkForAegis
|
||||
{
|
||||
PlanetEntity* the_planet = [UNIVERSE planet];
|
||||
@ -3101,57 +3114,89 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
|
||||
if (!the_planet)
|
||||
{
|
||||
if (aegis_status != AEGIS_NONE)
|
||||
[shipAI message:@"AEGIS_NONE"];
|
||||
{
|
||||
// Planet disappeared!
|
||||
[self transitionToAegisNone];
|
||||
}
|
||||
return AEGIS_NONE;
|
||||
}
|
||||
|
||||
// check planet
|
||||
Vector p1 = the_planet->position;
|
||||
double cr = the_planet->collision_radius;
|
||||
double cr2 = cr * cr;
|
||||
OOAegisStatus result = AEGIS_NONE;
|
||||
p1.x -= position.x; p1.y -= position.y; p1.z -= position.z;
|
||||
double d2 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z;
|
||||
float cr = [the_planet collisionRadius];
|
||||
float cr2 = cr * cr;
|
||||
OOAegisStatus result = AEGIS_NONE;
|
||||
float d2;
|
||||
|
||||
d2 = magnitude2(vector_subtract([the_planet position], [self position]));
|
||||
|
||||
// check if nearing surface
|
||||
// FIXME: need script and probably AI notification for all planets, not just main.
|
||||
BOOL wasNearPlanetSurface = isNearPlanetSurface;
|
||||
isNearPlanetSurface = (d2 - cr2 < 250000+1000*cr); //less than 500m from the surface: (a+b)*(a+b) = a*a+b*b +2*a*b
|
||||
if ((!wasNearPlanetSurface)&&(isNearPlanetSurface))
|
||||
[shipAI reactToMessage:@"APPROACHING_SURFACE"];
|
||||
if ((wasNearPlanetSurface)&&(!isNearPlanetSurface))
|
||||
[shipAI reactToMessage:@"LEAVING_SURFACE"];
|
||||
//
|
||||
d2 -= cr2 * 9.0; // to 3x radius of planet
|
||||
if (d2 < 0.0)
|
||||
if (!suppressAegisMessages)
|
||||
{
|
||||
if (!wasNearPlanetSurface && isNearPlanetSurface)
|
||||
{
|
||||
[self doScriptEvent:@"shipApproachingPlanetSurface" withArgument:the_planet];
|
||||
[shipAI reactToMessage:@"APPROACHING_SURFACE"];
|
||||
}
|
||||
if (wasNearPlanetSurface && !isNearPlanetSurface)
|
||||
{
|
||||
[self doScriptEvent:@"shipLeavingPlanetSurface" withArgument:the_planet];
|
||||
[shipAI reactToMessage:@"LEAVING_SURFACE"];
|
||||
}
|
||||
}
|
||||
|
||||
if (d2 < cr2 * 9.0) // to 3x radius of planet
|
||||
{
|
||||
result = AEGIS_CLOSE_TO_PLANET;
|
||||
}
|
||||
|
||||
// check station
|
||||
StationEntity* the_station = [UNIVERSE station];
|
||||
StationEntity *the_station = [UNIVERSE station];
|
||||
if (!the_station)
|
||||
{
|
||||
if (aegis_status != AEGIS_NONE)
|
||||
[shipAI message:@"AEGIS_NONE"];
|
||||
{
|
||||
// Station disappeared!
|
||||
[self transitionToAegisNone];
|
||||
}
|
||||
return AEGIS_NONE;
|
||||
}
|
||||
p1 = the_station->position;
|
||||
p1.x -= position.x; p1.y -= position.y; p1.z -= position.z;
|
||||
d2 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z - SCANNER_MAX_RANGE2*4.0; // double scanner range
|
||||
if (d2 < 0.0)
|
||||
result = AEGIS_IN_DOCKING_RANGE;
|
||||
|
||||
// ai messages on change in status
|
||||
// approaching..
|
||||
if ((aegis_status == AEGIS_NONE)&&(result == AEGIS_CLOSE_TO_PLANET))
|
||||
[shipAI message:@"AEGIS_CLOSE_TO_PLANET"];
|
||||
if (((aegis_status == AEGIS_CLOSE_TO_PLANET)||(aegis_status == AEGIS_NONE))&&(result == AEGIS_IN_DOCKING_RANGE))
|
||||
[shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
|
||||
// leaving..
|
||||
if ((aegis_status == AEGIS_IN_DOCKING_RANGE)&&(result == AEGIS_CLOSE_TO_PLANET))
|
||||
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
|
||||
if ((aegis_status != AEGIS_NONE)&&(result == AEGIS_NONE))
|
||||
[shipAI message:@"AEGIS_NONE"];
|
||||
d2 = magnitude2(vector_subtract([the_station position], [self position]));
|
||||
if (d2 < SCANNER_MAX_RANGE2 * 4.0) // double scanner range
|
||||
{
|
||||
result = AEGIS_IN_DOCKING_RANGE;
|
||||
}
|
||||
|
||||
if (!suppressAegisMessages)
|
||||
{
|
||||
// script/AI messages on change in status
|
||||
// approaching..
|
||||
if ((aegis_status == AEGIS_NONE)&&(result == AEGIS_CLOSE_TO_PLANET))
|
||||
{
|
||||
[self doScriptEvent:@"shipEnteredPlanetaryVicinity" withArgument:the_planet];
|
||||
[shipAI message:@"AEGIS_CLOSE_TO_PLANET"];
|
||||
}
|
||||
if (((aegis_status == AEGIS_CLOSE_TO_PLANET)||(aegis_status == AEGIS_NONE))&&(result == AEGIS_IN_DOCKING_RANGE))
|
||||
{
|
||||
[self doScriptEvent:@"shipEnteredStationAegis" withArgument:the_station];
|
||||
[shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
|
||||
}
|
||||
// leaving..
|
||||
if ((aegis_status == AEGIS_IN_DOCKING_RANGE)&&(result == AEGIS_CLOSE_TO_PLANET))
|
||||
{
|
||||
[self doScriptEvent:@"shipExitedStationAegis"];
|
||||
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
|
||||
}
|
||||
if ((aegis_status != AEGIS_NONE)&&(result == AEGIS_NONE))
|
||||
{
|
||||
[self transitionToAegisNone];
|
||||
}
|
||||
}
|
||||
|
||||
aegis_status = result; // put this here
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,16 @@ MA 02110-1301, USA.
|
||||
#ifdef OOLITE_SDL_MAC
|
||||
#define OOLITE_SDL 1
|
||||
#endif
|
||||
|
||||
/* Enforce type-clean use of nil and Nil under OS X. (They are untyped in
|
||||
Cocoa, apparently for compatibility with legacy Mac OS code, but typed in
|
||||
GNUstep.)
|
||||
*/
|
||||
#undef nil
|
||||
#define nil ((id)0)
|
||||
#undef Nil
|
||||
#define Nil ((Class)nil)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -176,6 +176,8 @@ OOINLINE float OOFastInvSqrtf(float x)
|
||||
x = *(float*)&i;
|
||||
x = x * (1.5f - xhalf * x * x);
|
||||
return x;
|
||||
#elif OO_PPC
|
||||
return OOInvSqrtf(x);
|
||||
#else
|
||||
return OOReciprocalEstimate(sqrt(x));
|
||||
#endif
|
||||
|
@ -204,7 +204,7 @@ static NSString *GetCPUDescription(void)
|
||||
|
||||
static NSString *GetSysCtlString(const char *name)
|
||||
{
|
||||
char *buffer = nil;
|
||||
char *buffer = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
// Get size
|
||||
|
@ -204,7 +204,7 @@ OOINLINE GLfloat magnitude(Vector vec)
|
||||
|
||||
OOINLINE GLfloat fast_magnitude(Vector vec)
|
||||
{
|
||||
#if FASTINVSQRT_ENABLED
|
||||
#if FASTINVSQRT_ENABLED || OO_PPC
|
||||
GLfloat mag2 = magnitude2(vec);
|
||||
return mag2 * OOFastInvSqrtf(mag2); /* x = sqrt(x) * sqrt(x); x * 1/sqrt(x) = (sqrt(x) * sqrt(x))/sqrt(x) = sqrt(x). */
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user