43#define OO_WORMHOLE_COLOR_BOOST 25.0
44#define OO_WORMHOLE_COLOR_FVEC4 { 0.067, 0.067, 1.0, 0.25 }
47@interface WormholeEntity (Private)
54static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius,
int step, GLfloat z_distance, GLfloat* col4v1);
56@implementation WormholeEntity (Private)
60 if ((
self = [super
init])) {
63 collision_radius = 0.0;
65 scanClass = CLASS_WORMHOLE;
88 if ((
self = [
self init])) {
93 origin = [
dict oo_intForKey:@"origin_id" defaultValue:0];
96 originCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:origin inGalaxy:[PLAYER galaxyNumber]];
97 destinationCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:destination inGalaxy:[PLAYER galaxyNumber]];
115 _misjump = [
dict oo_boolForKey:@"misjump" defaultValue:NO];
118 NSArray* shipDictsArray = [
dict oo_arrayForKey:@"ships"];
119 NSDictionary* currShipDict =
nil;
120 [shipsInTransit removeAllObjects];
123 foreach (currShipDict, shipDictsArray) {
124 NSDictionary* shipInfo = [
currShipDict oo_dictionaryForKey:@"ship_info"];
125 if (shipInfo !=
nil) {
130 [shipsInTransit addObject:[
NSDictionary dictionaryWithObjectsAndKeys:
135 OOLog(
@"wormhole.load.warning",
@"Wormhole ship \"%@\
" failed to initialize - missing OXP or old-style saved wormhole data.", [shipInfo oo_stringForKey:
@"ship_key"]);
148 if ((
self = [
self init])) {
149 double now = [PLAYER clockTimeAdjusted];
154 origin = [UNIVERSE currentSystemID];
157 destinationCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:destination inGalaxy:[PLAYER galaxyNumber]];
164 if (sun && ([sun willGoNova] || [sun goneNova]) && [ship
mass] > 240000)
204- (void)setMisjumpWithRange:(GLfloat)range
206 if (range <= 0.0 || range >= 1.0) {
238 if (!ship || [ship
status] == STATUS_ENTERING_WITCHSPACE) {
249 double now = [PLAYER clockTimeAdjusted];
267 if (leader && (leader != ship)) {
270 if (leaderShipSpeed < shipSpeed)
271 shipSpeed = leaderShipSpeed;
273 if (shipSpeed <= 0.0f)
275 now += d / shipSpeed;
281 [shipsInTransit addObject:[
NSDictionary dictionaryWithObjectsAndKeys:
283 [
NSNumber numberWithDouble:now + travel_time - arrival_time], @"time",
295 [UNIVERSE addWitchspaceJumpEffectForShip:ship];
302 [UNIVERSE removeEntity:ship];
309 [UNIVERSE carryPlayerOn:(StationEntity*)ship inWormhole:
self];
319 double now = [PLAYER clockTimeAdjusted];
320 NSMutableArray* shipsStillInTransit = [[
NSMutableArray alloc] initWithCapacity:[shipsInTransit count]];
321 BOOL hasShiftedExitPosition = NO;
322 BOOL useExitXYScatter = NO;
324 NSDictionary* shipInfo =
nil;
327 NSString* shipBeacon = [
shipInfo objectForKey:@"shipBeacon"];
329 double time_passed = now - ship_arrival_time;
331 if ([ship
status] == STATUS_DEAD)
334 if (ship_arrival_time > now) {
339 position = [UNIVERSE getWitchspaceExitPosition];
340 GLfloat min_d1 = [UNIVERSE safeWitchspaceExitDistance];
350 if (fabs(d1) < min_d1)
352 d1 += ((d1 > 0.0) ? min_d1 : -min_d1);
366 double offset_x =
randf() * 150.0 - 75.0;
367 double offset_y =
randf() * 150.0 - 75.0;
368 shippos.
x =
position.x + (offset_x * exit_vector_x.
x) + (offset_y * exit_vector_y.
x);
369 shippos.
y =
position.y + (offset_x * exit_vector_x.
y) + (offset_y * exit_vector_y.
y);
370 shippos.
z =
position.z + (offset_x * exit_vector_x.
z) + (offset_y * exit_vector_y.
z);
376 [PLAYER setSpeed:exit_speed];
378 useExitXYScatter = YES;
382 if (shipBeacon !=
nil) {
397 if (time_passed < 2.0) {
405 [UNIVERSE addEntity:ship];
419 hasShiftedExitPosition = YES;
422 }
else if (time_passed > 1)
424 if (hasShiftedExitPosition) {
426 [
ship update:(ship_arrival_time - arrival_time)];
435 [shipsInTransit release];
448- (void)setContainsPlayer:(BOOL)val
484- (void)setExitSpeed:(
double)speed
519- (void)setScannedAt:(
double)p_scanTime
545 [shipsInTransit release];
552 double now = [PLAYER clockTime];
553 return [
NSString stringWithFormat:@"destination: %@ ttl: %.2fs arrival: %@",
554 _misjump ? (NSString*)@"Interstellar Space" : [UNIVERSE getSystemName:destination],
556 ClockToString(arrival_time, false)];
561 if ([ship hasEquipmentItem:
@"EQ_WORMHOLE_SCANNER"]) {
563 return [
NSString stringWithFormat:DESC(@"wormhole-to-@"), [UNIVERSE getSystemName:destination]];
565 return DESC(
@"wormhole-desc");
593- (BOOL)checkCloseCollisionWith:(
Entity*)other
603 assert(player !=
nil);
622 [UNIVERSE removeEntity:
self];
626- (void)drawImmediate:(
bool)immediate translucent:(
bool)translucent
650 OOGL(glDisable(GL_CULL_FACE));
651 OOGL(glEnable(GL_BLEND));
653 OOGL(glColor4fv(color_fv));
658 color_fv[3] = fmin(color_fv[3] * 2.0, 1.0);
661 OOGL(glEnable(GL_CULL_FACE));
662 OOGL(glDisable(GL_BLEND));
669static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius,
int step, GLfloat z_distance, GLfloat* col4v1)
671 if (outer_radius >= z_distance)
675 const GLfloat activityMin = 0.34f;
676 const GLfloat activityLength = 1.0f;
678 GLfloat s0, c0, s1, c1;
683 GLfloat theta, delta, halfStep;
685 r0 = outer_radius * z_distance / sqrt(z_distance * z_distance - outer_radius * outer_radius);
686 r1 = inner_radius * z_distance / sqrt(z_distance * z_distance - inner_radius * inner_radius);
688 delta = step *
M_PI / 180.0f;
689 halfStep = 0.5f * delta;
693 for (i = 0; i < 360; i += step) {
697 q = activityMin + rv0 * activityLength;
699 s0 = r0 * sin(theta);
700 c0 = r0 * cos(theta);
701 glColor4f(col4v1[0] * q, col4v1[1] * q, col4v1[2] * q, col4v1[3] * rv0);
702 glVertex3f(s0, c0, 0.0);
704 s1 = r1 * sin(theta - halfStep) * 0.5 * (1.0 + rv1);
705 c1 = r1 * cos(theta - halfStep) * 0.5 * (1.0 + rv1);
707 glVertex3f(s1, c1, 0.0);
715 q = activityMin + rv0 * activityLength;
719 glColor4f(col4v1[0] * q, col4v1[1] * q, col4v1[2] * q, col4v1[3] * rv0);
720 glVertex3f(s0, c0, 0.0);
722 s1 = r1 * sin(halfStep) * 0.5 * (1.0 + rv1);
723 c1 = r1 * cos(halfStep) * 0.5 * (1.0 + rv1);
725 glVertex3f(s1, c1, 0.0);
733 [
myDict oo_setInteger:origin forKey:@"origin_id"];
734 [
myDict oo_setInteger:destination forKey:@"dest_id"];
735 [
myDict setObject:StringFromPoint(originCoords) forKey:@"origin_coords"];
736 [
myDict setObject:StringFromPoint(destinationCoords) forKey:@"dest_coords"];
739 [
myDict oo_setFloat:(expiry_time) forKey:@"expiry_time"];
740 [
myDict oo_setFloat:(arrival_time) forKey:@"arrival_time"];
741 [
myDict oo_setFloat:(estimated_arrival_time) forKey:@"estimated_arrival_time"];
742 [
myDict oo_setHPVector:position forKey:@"position"];
743 [
myDict oo_setBool:_misjump forKey:@"misjump"];
745 NSMutableArray* shipArray = [
NSMutableArray arrayWithCapacity:[shipsInTransit count]];
746 NSEnumerator* ships = [shipsInTransit objectEnumerator];
747 NSDictionary* currShipDict =
nil;
749 while ((currShipDict = [ships nextObject]) !=
nil) {
753 [
ship savedShipDictionaryWithContext:context], @"ship_info",
756 [
myDict setObject:shipArray forKey:@"ships"];
765 return @"WH_SCANINFO_NONE";
767 return @"WH_SCANINFO_SCANNED";
769 return @"WH_SCANINFO_COLLAPSE_TIME";
771 return @"WH_SCANINFO_ARRIVAL_TIME";
773 return @"WH_SCANINFO_DESTINATION";
775 return @"WH_SCANINFO_SHIP";
777 return @"WH_SCANINFO_UNDEFINED";
794 for (i = 0; i < [shipsInTransit count]; ++i) {
795 NSDictionary* shipDict = [shipsInTransit oo_dictionaryAtIndex:i];
798 OOLog(
@"dumpState.wormholeEntity.ships",
@"Ship %d: %@ mass %.2f arrival time %@", i + 1, ship, [ship
mass],
ClockToString(ship_arrival_time,
false));
#define NO_DRAW_DISTANCE_FACTOR
#define SCANNER_MAX_RANGE
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
#define OOLogERR(class, format,...)
NSString *const kOOLogInconsistentState
#define OOLog(class, format,...)
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
@ OPENGL_STATE_TRANSLUCENT_PASS
#define OOVerifyOpenGLState()
BOOL OOCheckOpenGLErrors(NSString *format,...)
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
#define OOSetOpenGLState(STATE)
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
NSString * ClockToString(double clock, BOOL adjusting)
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
const Vector kBasisZVector
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
#define WORMHOLE_SHRINK_RATE
@ WH_SCANINFO_ARRIVAL_TIME
@ WH_SCANINFO_DESTINATION
@ WH_SCANINFO_COLLAPSE_TIME
#define OO_WORMHOLE_COLOR_FVEC4
#define OO_WORMHOLE_COLOR_BOOST
static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat *col4v1)
void message:(NSString *ms)
void setVelocity:(Vector vel)
void setOrientation:(Quaternion quat)
void update:(OOTimeDelta delta_t)
GLfloat collisionRadius()
GLfloat cam_zero_distance
void setStatus:(OOEntityStatus stat)
void setPosition:(HPVector posn)
double clockTimeAdjusted()
void doScriptEvent:(OOJSPropID message)
void setBounty:withReason:(OOCreditsQuantity amount,[withReason] OOLegalStatusReason reason)
void setStatus:(OOEntityStatus stat)
BOOL witchspaceLeavingEffects()
void setRoll:(double amount)
void setSpeed:(double amount)
void setPitch:(double amount)
void setBeaconCode:(NSString *bcode)
void doScriptEvent:andReactToAIMessage:(OOJSPropID scriptEvent,[andReactToAIMessage] NSString *aiMessage)
void update:(OOTimeDelta delta_t)
float afterburnerFactor()
id shipRestoredFromDictionary:useFallback:context:(NSDictionary *dictionary,[useFallback] BOOL fallback,[context] NSMutableDictionary *context)
WORMHOLE_SCANINFO scanInfo()
double estimatedArrivalTime()
NSPoint originCoordinates()
NSPoint destinationCoords
WORMHOLE_SCANINFO scan_info
double estimated_arrival_time
NSMutableArray * shipsInTransit
NSPoint destinationCoordinates()
NSString * scanInfoString()
NSString * descriptionComponents()
void setExitSpeed:(double speed)
static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat *col4v1)
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC