59@interface Entity (OOPrivate)
73 _sessionID = [UNIVERSE sessionID];
79 no_draw_distance = 100000.0;
81 collidingEntities = [[NSMutableArray alloc] init];
83 scanClass = CLASS_NOT_SET;
86 spawnTime = [UNIVERSE getTime];
104 [UNIVERSE ensureEntityReallyRemoved:self];
109 [atmosphereFogging release];
120- (NSString *)descriptionComponents
122 return [NSString stringWithFormat:@"position: %@ scanClass: %@ status: %@", HPVectorDescription([
self position]), OOStringFromScanClass([
self scanClass]), OOStringFromEntityStatus([
self status])];
126- (NSUInteger) sessionID
180- (BOOL) isStellarObject
182 return [
self isPlanet] || [
self isSun];
203- (BOOL) isVisualEffect
215- (BOOL) validForAddToUniverse
217 NSUInteger mySessionID = [
self sessionID];
218 NSUInteger currentSessionID = [UNIVERSE sessionID];
219 if (
EXPECT_NOT(mySessionID != currentSessionID))
221 OOLogERR(
@"entity.invalidSession",
@"Entity %@ from session %llu cannot be added to universe in session %llu. This is an internal error, please report it.", [
self shortDescription], mySessionID, currentSessionID);
229- (void) addToLinkedLists
241 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
244 x_next = x_next->x_next;
246 if (x_next) x_next->x_previous =
self;
247 if (x_previous) x_previous->x_next =
self;
252 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
255 y_next = y_next->y_next;
257 if (y_next) y_next->y_previous =
self;
258 if (y_previous) y_previous->y_next =
self;
263 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
266 z_next = z_next->z_next;
268 if (z_next) z_next->z_previous =
self;
269 if (z_previous) z_previous->z_next =
self;
277 if (![
self checkLinkedLists])
280 [UNIVERSE debugDumpEntities];
287- (void) removeFromLinkedLists
294 if ((x_next ==
nil)&&(x_previous ==
nil))
300 if ((
UNIVERSE->x_list_start ==
self)&&(x_next))
302 if ((
UNIVERSE->y_list_start ==
self)&&(y_next))
304 if ((
UNIVERSE->z_list_start ==
self)&&(z_next))
308 if (x_previous) x_previous->x_next = x_next;
309 if (x_next) x_next->x_previous = x_previous;
311 if (y_previous) y_previous->y_next = y_next;
312 if (y_next) y_next->y_previous = y_previous;
314 if (z_previous) z_previous->z_next = z_next;
315 if (z_next) z_next->z_previous = z_previous;
317 x_previous =
nil; x_next =
nil;
318 y_previous =
nil; y_next =
nil;
319 z_previous =
nil; z_next =
nil;
324 if (![
self checkLinkedLists])
327 [UNIVERSE debugDumpEntities];
346 while ((n--)&&(check))
351 if ((check)||(n > 0))
359 while ((n--)&&(check)) check = check->
x_previous;
360 if ((check)||(n > 0))
368 while ((n--)&&(check))
373 if ((check)||(n > 0))
381 while ((n--)&&(check)) check = check->
y_previous;
382 if ((check)||(n > 0))
390 while ((n--)&&(check))
395 if ((check)||(n > 0))
403 while ((n--)&&(check)) check = check->
z_previous;
404 if ((check)||(n > 0))
414- (void) updateLinkedLists
418 if ((x_next ==
nil)&&(x_previous ==
nil))
424 if (![
self checkLinkedLists])
427 [UNIVERSE debugDumpEntities];
434 if (x_previous) x_previous->x_next = x_next;
435 if (x_next) x_next->x_previous = x_previous;
437 while ((x_previous)&&(x_previous->position.x - x_previous->collision_radius > position.x - collision_radius))
440 x_previous = x_previous->x_previous;
443 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
446 x_next = x_next->x_next;
449 x_next->x_previous =
self;
451 x_previous->x_next =
self;
457 if (y_previous) y_previous->y_next = y_next;
458 if (y_next) y_next->y_previous = y_previous;
460 while ((y_previous)&&(y_previous->position.y - y_previous->collision_radius > position.y - collision_radius))
463 y_previous = y_previous->y_previous;
466 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
469 y_next = y_next->y_next;
472 y_next->y_previous =
self;
474 y_previous->y_next =
self;
480 if (z_previous) z_previous->z_next = z_next;
481 if (z_next) z_next->z_previous = z_previous;
483 while ((z_previous)&&(z_previous->position.z - z_previous->collision_radius > position.z - collision_radius))
486 z_previous = z_previous->z_previous;
489 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
492 z_next = z_next->z_next;
495 z_next->z_previous =
self;
497 z_previous->z_next =
self;
505 if (![
self checkLinkedLists])
508 [UNIVERSE debugDumpEntities];
515- (void) wasAddedToUniverse
521- (void) wasRemovedFromUniverse
527- (void) warnAboutHostiles
530 OOLog(
@"general.error.subclassResponsibility.Entity-warnAboutHostiles",
@"%@",
@"***** Entity does nothing in warnAboutHostiles");
536 return collisionRegion;
542 if (collisionRegion) [collisionRegion release];
543 collisionRegion = [region retain];
559- (BOOL) throwingSparks
565- (void) setThrowSparks:(BOOL) value
567 throw_sparks = value;
577- (void) setOwner:(
Entity *)ent
586 return [_owner weakRefUnderlyingObject];
592 id owner = [
self owner];
593 if ([owner isShipWithSubEntityShip:
self]) return owner;
598- (id<OOWeakReferenceSupport>) superShaderBindingTarget
600 return [
self parentEntity];
618- (Vector) cameraRelativePosition
620 return cameraRelativePosition;
623- (GLfloat) cameraRangeFront
625 return magnitude(cameraRelativePosition) - [
self frustumRadius];
628- (GLfloat) cameraRangeBack
630 return magnitude(cameraRelativePosition) + [
self frustumRadius];
637- (Vector) relativePosition
639 return HPVectorToVector(HPvector_subtract([
self position], [
PLAYER position]));
642- (Vector) vectorTo:(
Entity *)entity
644 return HPVectorToVector(HPvector_subtract([entity position], [
self position]));
648- (void) setPosition:(HPVector) posn
651 [
self updateCameraRelativePosition];
660 [
self updateCameraRelativePosition];
664- (void) updateCameraRelativePosition
666 cameraRelativePosition = HPVectorToVector(HPvector_subtract([
self absolutePositionForSubentity],[
PLAYER viewpointPosition]));
670- (HPVector) absolutePositionForSubentity
672 return [
self absolutePositionForSubentityOffset:kZeroHPVector];
676- (HPVector) absolutePositionForSubentityOffset:(HPVector) offset
680 Entity *father = [
self parentEntity];
682 while (father !=
nil && father != last)
686 if (![last isSubEntity])
break;
687 father = [father
owner];
693- (double) zeroDistance
695 return zero_distance;
699- (double) camZeroDistance
701 return cam_zero_distance;
705- (NSComparisonResult) compareZeroDistance:(
Entity *)otherEntity
707 if ((otherEntity)&&(zero_distance > otherEntity->
zero_distance))
708 return NSOrderedAscending;
710 return NSOrderedDescending;
714- (BoundingBox) boundingBox
726- (void) setOrientation:(Quaternion) quat
729 [
self orientationChanged];
733- (Quaternion) orientation
739- (Quaternion) normalOrientation
741 return [
self orientation];
745- (void) setNormalOrientation:(Quaternion) quat
747 [
self setOrientation:quat];
751- (void) orientationChanged
753 quaternion_normalize(&orientation);
758- (void) setVelocity:(Vector) vel
772 return magnitude([
self velocity]);
776- (GLfloat) distanceTravelled
778 return distanceTravelled;
782- (void) setDistanceTravelled: (GLfloat) value
784 distanceTravelled = value;
812- (void) setEnergy:(GLfloat) amount
824- (void) setMaxEnergy:(GLfloat)amount
836- (void) applyRoll:(GLfloat) roll andClimb:(GLfloat) climb
838 if ((roll == 0.0)&&(climb == 0.0)&&(!hasRotated))
846 [
self orientationChanged];
850- (void) applyRoll:(GLfloat) roll climb:(GLfloat) climb andYaw:(GLfloat) yaw
852 if ((roll == 0.0)&&(climb == 0.0)&&(yaw == 0.0)&&(!hasRotated))
862 [
self orientationChanged];
866- (void) moveForward:(
double)amount
869 position = HPvector_add(position, forward);
870 distanceTravelled += amount;
874- (OOMatrix) rotationMatrix
880- (OOMatrix) drawRotationMatrix
886- (OOMatrix) transformationMatrix
888 OOMatrix result = rotMatrix;
889 return OOMatrixHPTranslate(result, position);
893- (OOMatrix) drawTransformationMatrix
895 OOMatrix result = rotMatrix;
896 return OOMatrixHPTranslate(result, position);
906- (GLfloat) collisionRadius
908 return collision_radius;
912- (GLfloat) frustumRadius
914 return collision_radius;
918- (void) setCollisionRadius:(GLfloat) amount
920 collision_radius = amount;
924- (NSMutableArray *) collisionArray
926 return collidingEntities;
932 if (_status != STATUS_COCKPIT_DISPLAY)
934 if ([
self isSubEntity])
936 zero_distance = [[
self owner] zeroDistance];
937 cam_zero_distance = [[
self owner] camZeroDistance];
938 [
self updateCameraRelativePosition];
942 zero_distance = HPdistance2(
PLAYER->position, position);
943 cam_zero_distance = HPdistance2([
PLAYER viewpointPosition], position);
944 [
self updateCameraRelativePosition];
949 zero_distance = HPmagnitude2(position);
950 cam_zero_distance = zero_distance;
951 cameraRelativePosition = HPVectorToVector(position);
954 if ([
self status] != STATUS_COCKPIT_DISPLAY)
956 [
self applyVelocity:delta_t];
959 hasMoved = !HPvector_equal(position, lastPosition);
960 hasRotated = !quaternion_equal(orientation, lastOrientation);
961 lastPosition = position;
962 lastOrientation = orientation;
968 position = HPvector_add(position, HPvector_multiply_scalar(vectorToHPVector(velocity), delta_t));
972- (BOOL) checkCloseCollisionWith:(
Entity *)other
978- (double)findCollisionRadius
985- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
991- (void) takeEnergyDamage:(
double) amount from:(
Entity *) ent becauseOf:(
Entity *) other weaponIdentifier:(NSString *)weaponIdentifier
1001 OOLog(
@"dumpState",
@"State for %@:",
self);
1006 [
self dumpSelfState];
1008 @catch (
id exception) {}
1014- (void)dumpSelfState
1016 NSMutableArray *flags =
nil;
1017 NSString *flagsString =
nil;
1018 id owner = [
self owner];
1020 if (owner ==
self) owner =
@"self";
1021 else if (owner ==
nil) owner =
@"none";
1023 OOLog(
@"dumpState.entity",
@"Universal ID: %u", universalID);
1026 OOLog(
@"dumpState.entity",
@"Position: %@", HPVectorDescription(position));
1027 OOLog(
@"dumpState.entity",
@"Orientation: %@", QuaternionDescription(orientation));
1028 OOLog(
@"dumpState.entity",
@"Distance travelled: %g", distanceTravelled);
1029 OOLog(
@"dumpState.entity",
@"Energy: %g of %g", energy, maxEnergy);
1030 OOLog(
@"dumpState.entity",
@"Mass: %g", mass);
1031 OOLog(
@"dumpState.entity",
@"Owner: %@", owner);
1033 flags = [NSMutableArray array];
1034 #define ADD_FLAG_IF_SET(x) if (x) { [flags addObject:@#x]; }
1044 flagsString = [flags count] ? [flags componentsJoinedByString:@", "] : (NSString *)
@"none";
1045 OOLog(
@"dumpState.entity",
@"Flags: %@", flagsString);
1046 OOLog(
@"dumpState.entity",
@"Collision Test Filter: %u", collisionTestFilter);
1053 OOLog(
@"entity.bug",
@"%s called for non-ship entity %p by %p", __PRETTY_FUNCTION__,
self, sub);
1057- (NSUInteger) lastDrawCounter
1059 return lastDrawCounter;
1063- (void) setLastDrawCounter: (NSUInteger) drawCounter
1065 lastDrawCounter = drawCounter;
1071- (GLfloat)universalTime
1073 return [UNIVERSE getTime];
1083- (GLfloat)timeElapsedSinceSpawn
1085 return [UNIVERSE getTime] - spawnTime;
1089- (void) setAtmosphereFogging: (
OOColor *)fogging
1091 [atmosphereFogging release];
1092 atmosphereFogging = [fogging retain];
1097 return [[atmosphereFogging retain] autorelease];
1101- (NSString *) descriptionForObjDumpBasic
1103 NSString *result = [
self descriptionComponents];
1104 if (result !=
nil) result = [NSString stringWithFormat:@"%@ %@", NSStringFromClass([
self class]), result];
1105 else result = [
self description];
1111- (NSString *) descriptionForObjDump
1113 NSString *result = [
self descriptionForObjDumpBasic];
1115 result = [result stringByAppendingFormat:@" range: %g (visible: %@)", HPdistance([
self position], [PLAYER position]), [
self isVisible] ? @"yes" : @"no"];
1121- (NSSet *) allTextures
1136 switch ([
self status])
1138 case STATUS_IN_FLIGHT:
1139 case STATUS_DOCKING:
1140 case STATUS_LAUNCHING:
1141 case STATUS_AUTOPILOT_ENGAGED:
1142 case STATUS_WITCHSPACE_COUNTDOWN:
1143 case STATUS_BEING_SCOOPED:
1153- (BOOL) isImmuneToBreakPatternHide
1155 return isImmuneToBreakPatternHide;
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
#define ABSOLUTE_NO_DRAW_DISTANCE2
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
uint32_t gLiveEntityCount
#define ADD_FLAG_IF_SET(x)
size_t gTotalEntityMemory
static NSString *const kOOLogEntityRemoveFromList
static NSString *const kOOLogEntityRemoveFromListError
static NSString *const kOOLogEntityVerificationError
static NSString *const kOOLogEntityUpdateError
static NSString *const kOOLogEntityAddToList
static NSString *const kOOLogEntityAddToListError
uint32_t gLiveEntityCount
size_t gTotalEntityMemory
const HPVector kZeroHPVector
void OOLogPushIndent(void)
#define OOLogERR(class, format,...)
void OOLogPopIndent(void)
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
#define OOLogGenericSubclassResponsibility()
#define OOLog(class, format,...)
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m)
const OOMatrix kIdentityMatrix
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
void quaternion_rotate_about_x(Quaternion *quat, OOScalar angle)
HPVector HPvector_forward_from_quaternion(Quaternion quat)
void quaternion_rotate_about_z(Quaternion *quat, OOScalar angle)
const Quaternion kIdentityQuaternion
void quaternion_rotate_about_y(Quaternion *quat, OOScalar angle)
ShipEntity * rootShipEntity()
void setStatus:(OOEntityStatus stat)
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)