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];
103 [UNIVERSE ensureEntityReallyRemoved:self];
108 [atmosphereFogging release];
119- (NSString *)descriptionComponents
121 return [NSString stringWithFormat:@"position: %@ scanClass: %@ status: %@", HPVectorDescription([
self position]), OOStringFromScanClass([
self scanClass]), OOStringFromEntityStatus([
self status])];
125- (NSUInteger) sessionID
179- (BOOL) isStellarObject
181 return [
self isPlanet] || [
self isSun];
202- (BOOL) isVisualEffect
214- (BOOL) validForAddToUniverse
216 NSUInteger mySessionID = [
self sessionID];
217 NSUInteger currentSessionID = [UNIVERSE sessionID];
218 if (
EXPECT_NOT(mySessionID != currentSessionID))
220 OOLogERR(
@"entity.invalidSession",
@"Entity %@ from session %lu cannot be added to universe in session %lu. This is an internal error, please report it.", [
self shortDescription], mySessionID, currentSessionID);
228- (void) addToLinkedLists
240 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
243 x_next = x_next->x_next;
245 if (x_next) x_next->x_previous =
self;
246 if (x_previous) x_previous->x_next =
self;
251 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
254 y_next = y_next->y_next;
256 if (y_next) y_next->y_previous =
self;
257 if (y_previous) y_previous->y_next =
self;
262 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
265 z_next = z_next->z_next;
267 if (z_next) z_next->z_previous =
self;
268 if (z_previous) z_previous->z_next =
self;
276 if (![
self checkLinkedLists])
279 [UNIVERSE debugDumpEntities];
286- (void) removeFromLinkedLists
293 if ((x_next ==
nil)&&(x_previous ==
nil))
299 if ((
UNIVERSE->x_list_start ==
self)&&(x_next))
301 if ((
UNIVERSE->y_list_start ==
self)&&(y_next))
303 if ((
UNIVERSE->z_list_start ==
self)&&(z_next))
307 if (x_previous) x_previous->x_next = x_next;
308 if (x_next) x_next->x_previous = x_previous;
310 if (y_previous) y_previous->y_next = y_next;
311 if (y_next) y_next->y_previous = y_previous;
313 if (z_previous) z_previous->z_next = z_next;
314 if (z_next) z_next->z_previous = z_previous;
316 x_previous =
nil; x_next =
nil;
317 y_previous =
nil; y_next =
nil;
318 z_previous =
nil; z_next =
nil;
323 if (![
self checkLinkedLists])
326 [UNIVERSE debugDumpEntities];
345 while ((n--)&&(check))
350 if ((check)||(n > 0))
358 while ((n--)&&(check)) check = check->
x_previous;
359 if ((check)||(n > 0))
367 while ((n--)&&(check))
372 if ((check)||(n > 0))
380 while ((n--)&&(check)) check = check->
y_previous;
381 if ((check)||(n > 0))
389 while ((n--)&&(check))
394 if ((check)||(n > 0))
402 while ((n--)&&(check)) check = check->
z_previous;
403 if ((check)||(n > 0))
413- (void) updateLinkedLists
417 if ((x_next ==
nil)&&(x_previous ==
nil))
423 if (![
self checkLinkedLists])
426 [UNIVERSE debugDumpEntities];
433 if (x_previous) x_previous->x_next = x_next;
434 if (x_next) x_next->x_previous = x_previous;
436 while ((x_previous)&&(x_previous->position.x - x_previous->collision_radius > position.x - collision_radius))
439 x_previous = x_previous->x_previous;
442 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
445 x_next = x_next->x_next;
448 x_next->x_previous =
self;
450 x_previous->x_next =
self;
456 if (y_previous) y_previous->y_next = y_next;
457 if (y_next) y_next->y_previous = y_previous;
459 while ((y_previous)&&(y_previous->position.y - y_previous->collision_radius > position.y - collision_radius))
462 y_previous = y_previous->y_previous;
465 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
468 y_next = y_next->y_next;
471 y_next->y_previous =
self;
473 y_previous->y_next =
self;
479 if (z_previous) z_previous->z_next = z_next;
480 if (z_next) z_next->z_previous = z_previous;
482 while ((z_previous)&&(z_previous->position.z - z_previous->collision_radius > position.z - collision_radius))
485 z_previous = z_previous->z_previous;
488 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
491 z_next = z_next->z_next;
494 z_next->z_previous =
self;
496 z_previous->z_next =
self;
504 if (![
self checkLinkedLists])
507 [UNIVERSE debugDumpEntities];
514- (void) wasAddedToUniverse
520- (void) wasRemovedFromUniverse
526- (void) warnAboutHostiles
529 OOLog(
@"general.error.subclassResponsibility.Entity-warnAboutHostiles",
@"%@",
@"***** Entity does nothing in warnAboutHostiles");
535 return collisionRegion;
541 if (collisionRegion) [collisionRegion release];
542 collisionRegion = [region retain];
558- (BOOL) throwingSparks
564- (void) setThrowSparks:(BOOL) value
566 throw_sparks = value;
576- (void) setOwner:(
Entity *)ent
585 return [_owner weakRefUnderlyingObject];
591 id owner = [
self owner];
592 if ([owner isShipWithSubEntityShip:
self])
return owner;
597- (id<OOWeakReferenceSupport>) superShaderBindingTarget
599 return [
self parentEntity];
617- (Vector) cameraRelativePosition
619 return cameraRelativePosition;
622- (GLfloat) cameraRangeFront
624 return magnitude(cameraRelativePosition) - [
self frustumRadius];
627- (GLfloat) cameraRangeBack
629 return magnitude(cameraRelativePosition) + [
self frustumRadius];
636- (Vector) relativePosition
638 return HPVectorToVector(HPvector_subtract([
self position], [
PLAYER position]));
641- (Vector) vectorTo:(
Entity *)entity
643 return HPVectorToVector(HPvector_subtract([entity position], [
self position]));
647- (void) setPosition:(HPVector) posn
650 [
self updateCameraRelativePosition];
659 [
self updateCameraRelativePosition];
663- (void) updateCameraRelativePosition
665 cameraRelativePosition = HPVectorToVector(HPvector_subtract([
self absolutePositionForSubentity],[
PLAYER viewpointPosition]));
669- (HPVector) absolutePositionForSubentity
671 return [
self absolutePositionForSubentityOffset:kZeroHPVector];
675- (HPVector) absolutePositionForSubentityOffset:(HPVector) offset
679 Entity *father = [
self parentEntity];
681 while (father !=
nil && father != last)
685 if (![last isSubEntity])
break;
686 father = [father
owner];
692- (double) zeroDistance
694 return zero_distance;
698- (double) camZeroDistance
700 return cam_zero_distance;
704- (NSComparisonResult) compareZeroDistance:(
Entity *)otherEntity
706 if ((otherEntity)&&(zero_distance > otherEntity->
zero_distance))
707 return NSOrderedAscending;
709 return NSOrderedDescending;
713- (BoundingBox) boundingBox
725- (void) setOrientation:(Quaternion) quat
728 [
self orientationChanged];
732- (Quaternion) orientation
738- (Quaternion) normalOrientation
740 return [
self orientation];
744- (void) setNormalOrientation:(Quaternion) quat
746 [
self setOrientation:quat];
750- (void) orientationChanged
752 quaternion_normalize(&orientation);
757- (void) setVelocity:(Vector) vel
771 return magnitude([
self velocity]);
775- (GLfloat) distanceTravelled
777 return distanceTravelled;
781- (void) setDistanceTravelled: (GLfloat) value
783 distanceTravelled = value;
811- (void) setEnergy:(GLfloat) amount
823- (void) setMaxEnergy:(GLfloat)amount
835- (void) applyRoll:(GLfloat) roll andClimb:(GLfloat) climb
837 if ((roll == 0.0)&&(climb == 0.0)&&(!hasRotated))
845 [
self orientationChanged];
849- (void) applyRoll:(GLfloat) roll climb:(GLfloat) climb andYaw:(GLfloat) yaw
851 if ((roll == 0.0)&&(climb == 0.0)&&(yaw == 0.0)&&(!hasRotated))
861 [
self orientationChanged];
865- (void) moveForward:(
double)amount
868 position = HPvector_add(position, forward);
869 distanceTravelled += amount;
873- (OOMatrix) rotationMatrix
879- (OOMatrix) drawRotationMatrix
885- (OOMatrix) transformationMatrix
887 OOMatrix result = rotMatrix;
888 return OOMatrixHPTranslate(result, position);
892- (OOMatrix) drawTransformationMatrix
894 OOMatrix result = rotMatrix;
895 return OOMatrixHPTranslate(result, position);
905- (GLfloat) collisionRadius
907 return collision_radius;
911- (GLfloat) frustumRadius
913 return collision_radius;
917- (void) setCollisionRadius:(GLfloat) amount
919 collision_radius = amount;
923- (NSMutableArray *) collisionArray
925 return collidingEntities;
931 if (_status != STATUS_COCKPIT_DISPLAY)
933 if ([
self isSubEntity])
935 zero_distance = [[
self owner] zeroDistance];
936 cam_zero_distance = [[
self owner] camZeroDistance];
937 [
self updateCameraRelativePosition];
941 zero_distance = HPdistance2(
PLAYER->position, position);
942 cam_zero_distance = HPdistance2([
PLAYER viewpointPosition], position);
943 [
self updateCameraRelativePosition];
948 zero_distance = HPmagnitude2(position);
949 cam_zero_distance = zero_distance;
950 cameraRelativePosition = HPVectorToVector(position);
953 if ([
self status] != STATUS_COCKPIT_DISPLAY)
955 [
self applyVelocity:delta_t];
958 hasMoved = !HPvector_equal(position, lastPosition);
959 hasRotated = !quaternion_equal(orientation, lastOrientation);
960 lastPosition = position;
961 lastOrientation = orientation;
967 position = HPvector_add(position, HPvector_multiply_scalar(vectorToHPVector(velocity), delta_t));
971- (BOOL) checkCloseCollisionWith:(
Entity *)other
977- (double)findCollisionRadius
984- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
990- (void) takeEnergyDamage:(
double) amount from:(
Entity *) ent becauseOf:(
Entity *) other weaponIdentifier:(NSString *)weaponIdentifier
1000 OOLog(
@"dumpState",
@"State for %@:",
self);
1005 [
self dumpSelfState];
1007 @catch (
id exception) {}
1013- (void)dumpSelfState
1015 NSMutableArray *flags =
nil;
1016 NSString *flagsString =
nil;
1017 id owner = [
self owner];
1019 if (owner ==
self) owner =
@"self";
1020 else if (owner ==
nil) owner =
@"none";
1022 OOLog(
@"dumpState.entity",
@"Universal ID: %u", universalID);
1025 OOLog(
@"dumpState.entity",
@"Position: %@", HPVectorDescription(position));
1026 OOLog(
@"dumpState.entity",
@"Orientation: %@", QuaternionDescription(orientation));
1027 OOLog(
@"dumpState.entity",
@"Distance travelled: %g", distanceTravelled);
1028 OOLog(
@"dumpState.entity",
@"Energy: %g of %g", energy, maxEnergy);
1029 OOLog(
@"dumpState.entity",
@"Mass: %g", mass);
1030 OOLog(
@"dumpState.entity",
@"Owner: %@", owner);
1032 flags = [NSMutableArray array];
1033 #define ADD_FLAG_IF_SET(x) if (x) { [flags addObject:@#x]; }
1043 flagsString = [flags count] ? [flags componentsJoinedByString:@", "] : (NSString *)
@"none";
1044 OOLog(
@"dumpState.entity",
@"Flags: %@", flagsString);
1045 OOLog(
@"dumpState.entity",
@"Collision Test Filter: %u", collisionTestFilter);
1052 OOLog(
@"entity.bug",
@"%s called for non-ship entity %p by %p", __PRETTY_FUNCTION__,
self, sub);
1057- (GLfloat)universalTime
1059 return [UNIVERSE getTime];
1069- (GLfloat)timeElapsedSinceSpawn
1071 return [UNIVERSE getTime] - spawnTime;
1075- (void) setAtmosphereFogging: (
OOColor *)fogging
1077 [atmosphereFogging release];
1078 atmosphereFogging = [fogging retain];
1083 return [[atmosphereFogging retain] autorelease];
1087- (NSString *) descriptionForObjDumpBasic
1089 NSString *result = [
self descriptionComponents];
1090 if (result !=
nil) result = [NSString stringWithFormat:@"%@ %@", NSStringFromClass([
self class]), result];
1091 else result = [
self description];
1097- (NSString *) descriptionForObjDump
1099 NSString *result = [
self descriptionForObjDumpBasic];
1101 result = [result stringByAppendingFormat:@" range: %g (visible: %@)", HPdistance([
self position], [PLAYER position]), [
self isVisible] ? @"yes" : @"no"];
1107- (NSSet *) allTextures
1122 switch ([
self status])
1124 case STATUS_IN_FLIGHT:
1125 case STATUS_DOCKING:
1126 case STATUS_LAUNCHING:
1127 case STATUS_AUTOPILOT_ENGAGED:
1128 case STATUS_WITCHSPACE_COUNTDOWN:
1129 case STATUS_BEING_SCOOPED:
1139- (BOOL) isImmuneToBreakPatternHide
1141 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)