Oolite
Loading...
Searching...
No Matches
Entity.m
Go to the documentation of this file.
1/*
2
3Entity.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "Entity.h"
27#import "PlayerEntity.h"
28#import "OOPlanetEntity.h"
29
30#import "OOMaths.h"
31#import "Universe.h"
32#import "GameController.h"
33#import "ResourceManager.h"
34#import "OOConstToString.h"
35
36#import "CollisionRegion.h"
37
39#import "OODebugFlags.h"
41
42#ifndef NDEBUG
43uint32_t gLiveEntityCount = 0;
45#endif
46
47
48#ifndef NDEBUG
49static NSString * const kOOLogEntityAddToList = @"entity.linkedList.add";
50static NSString * const kOOLogEntityAddToListError = @"entity.linkedList.add.error";
51static NSString * const kOOLogEntityRemoveFromList = @"entity.linkedList.remove";
52static NSString * const kOOLogEntityRemoveFromListError = @"entity.linkedList.remove.error";
53static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.error";
54#endif
55static NSString * const kOOLogEntityVerificationError = @"entity.linkedList.verify.error";
56
57
58
59@interface Entity (OOPrivate)
60
61- (BOOL) checkLinkedLists;
62
63@end
64
65
66@implementation Entity
67
68- (id) init
69{
70 self = [super init];
71 if (EXPECT_NOT(self == nil)) return nil;
72
73 _sessionID = [UNIVERSE sessionID];
74
75 orientation = kIdentityQuaternion;
76 rotMatrix = kIdentityMatrix;
77 position = kZeroHPVector;
78
79 no_draw_distance = 100000.0; // 10 km
80
81 collidingEntities = [[NSMutableArray alloc] init];
82
83 scanClass = CLASS_NOT_SET;
84 [self setStatus:STATUS_COCKPIT_DISPLAY];
85
86 spawnTime = [UNIVERSE getTime];
87
88 isSunlit = YES;
89
90 atmosphereFogging = [[OOColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0] retain];
91
92#ifndef NDEBUG
94 gTotalEntityMemory += [self oo_objectSize];
95#endif
96
97 lastDrawCounter = 0;
98 return self;
99}
100
101
102- (void) dealloc
103{
104 [UNIVERSE ensureEntityReallyRemoved:self];
105 DESTROY(collidingEntities);
106 DESTROY(collisionRegion);
107 [self deleteJSSelf];
108 [self setOwner:nil];
109 [atmosphereFogging release];
110
111#ifndef NDEBUG
113 gTotalEntityMemory -= [self oo_objectSize];
114#endif
115
116 [super dealloc];
117}
118
119
120- (NSString *)descriptionComponents
121{
122 return [NSString stringWithFormat:@"position: %@ scanClass: %@ status: %@", HPVectorDescription([self position]), OOStringFromScanClass([self scanClass]), OOStringFromEntityStatus([self status])];
123}
124
125
126- (NSUInteger) sessionID
127{
128 return _sessionID;
129}
130
131
132- (BOOL)isShip
133{
134 return isShip;
135}
136
137
138- (BOOL)isDock
139{
140 return NO;
141}
142
143
144- (BOOL)isStation
145{
146 return isStation;
147}
148
149
150- (BOOL)isSubEntity
151{
152 return isSubEntity;
153}
154
155
156- (BOOL)isPlayer
157{
158 return isPlayer;
159}
160
161
162- (BOOL)isPlanet
163{
164 return NO;
165}
166
167
168- (BOOL)isSun
169{
170 return NO;
171}
172
173
174- (BOOL) isSunlit
175{
176 return isSunlit;
177}
178
179
180- (BOOL) isStellarObject
181{
182 return [self isPlanet] || [self isSun];
183}
184
185
186- (BOOL)isSky
187{
188 return NO;
189}
190
191- (BOOL)isWormhole
192{
193 return isWormhole;
194}
195
196
197- (BOOL) isEffect
198{
199 return NO;
200}
201
202
203- (BOOL) isVisualEffect
204{
205 return NO;
206}
207
208
209- (BOOL) isWaypoint
210{
211 return NO;
212}
213
214
215- (BOOL) validForAddToUniverse
216{
217 NSUInteger mySessionID = [self sessionID];
218 NSUInteger currentSessionID = [UNIVERSE sessionID];
219 if (EXPECT_NOT(mySessionID != currentSessionID))
220 {
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);
222 return NO;
223 }
224
225 return YES;
226}
227
228
229- (void) addToLinkedLists
230{
231#ifndef NDEBUG
233 OOLog(kOOLogEntityAddToList, @"DEBUG adding entity %@ to linked lists", self);
234#endif
235 //
236 // insert at the start
237 if (UNIVERSE)
238 {
239 x_previous = nil; x_next = UNIVERSE->x_list_start;
240 // move UP the list
241 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
242 {
243 x_previous = x_next;
244 x_next = x_next->x_next;
245 }
246 if (x_next) x_next->x_previous = self;
247 if (x_previous) x_previous->x_next = self;
248 else UNIVERSE->x_list_start = self;
249
250 y_previous = nil; y_next = UNIVERSE->y_list_start;
251 // move UP the list
252 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
253 {
254 y_previous = y_next;
255 y_next = y_next->y_next;
256 }
257 if (y_next) y_next->y_previous = self;
258 if (y_previous) y_previous->y_next = self;
259 else UNIVERSE->y_list_start = self;
260
261 z_previous = nil; z_next = UNIVERSE->z_list_start;
262 // move UP the list
263 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
264 {
265 z_previous = z_next;
266 z_next = z_next->z_next;
267 }
268 if (z_next) z_next->z_previous = self;
269 if (z_previous) z_previous->z_next = self;
270 else UNIVERSE->z_list_start = self;
271
272 }
273
274#ifndef NDEBUG
276 {
277 if (![self checkLinkedLists])
278 {
279 OOLog(kOOLogEntityAddToListError, @"DEBUG LINKED LISTS - problem encountered while adding %@ to linked lists", self);
280 [UNIVERSE debugDumpEntities];
281 }
282 }
283#endif
284}
285
286
287- (void) removeFromLinkedLists
288{
289#ifndef NDEBUG
291 OOLog(kOOLogEntityRemoveFromList, @"DEBUG removing entity %@ from linked lists", self);
292#endif
293
294 if ((x_next == nil)&&(x_previous == nil)) // removed already!
295 return;
296
297 // make sure the starting point is still correct
298 if (UNIVERSE)
299 {
300 if ((UNIVERSE->x_list_start == self)&&(x_next))
301 UNIVERSE->x_list_start = x_next;
302 if ((UNIVERSE->y_list_start == self)&&(y_next))
303 UNIVERSE->y_list_start = y_next;
304 if ((UNIVERSE->z_list_start == self)&&(z_next))
305 UNIVERSE->z_list_start = z_next;
306 }
307 //
308 if (x_previous) x_previous->x_next = x_next;
309 if (x_next) x_next->x_previous = x_previous;
310 //
311 if (y_previous) y_previous->y_next = y_next;
312 if (y_next) y_next->y_previous = y_previous;
313 //
314 if (z_previous) z_previous->z_next = z_next;
315 if (z_next) z_next->z_previous = z_previous;
316 //
317 x_previous = nil; x_next = nil;
318 y_previous = nil; y_next = nil;
319 z_previous = nil; z_next = nil;
320
321#ifndef NDEBUG
323 {
324 if (![self checkLinkedLists])
325 {
326 OOLog(kOOLogEntityRemoveFromListError, @"DEBUG LINKED LISTS - problem encountered while removing %@ from linked lists", self);
327 [UNIVERSE debugDumpEntities];
328 }
329 }
330#endif
331}
332
333
334- (BOOL) checkLinkedLists
335{
336 // DEBUG check for loops
337 if (UNIVERSE->n_entities > 0)
338 {
339 int n;
340 Entity *check, *last;
341 //
342 last = nil;
343 //
344 n = UNIVERSE->n_entities;
345 check = UNIVERSE->x_list_start;
346 while ((n--)&&(check))
347 {
348 last = check;
349 check = check->x_next;
350 }
351 if ((check)||(n > 0))
352 {
353 OOLog(kOOLogEntityVerificationError, @"Broken x_next %@ list (%d) ***", UNIVERSE->x_list_start, n);
354 return NO;
355 }
356 //
357 n = UNIVERSE->n_entities;
358 check = last;
359 while ((n--)&&(check)) check = check->x_previous;
360 if ((check)||(n > 0))
361 {
362 OOLog(kOOLogEntityVerificationError, @"Broken x_previous %@ list (%d) ***", UNIVERSE->x_list_start, n);
363 return NO;
364 }
365 //
366 n = UNIVERSE->n_entities;
367 check = UNIVERSE->y_list_start;
368 while ((n--)&&(check))
369 {
370 last = check;
371 check = check->y_next;
372 }
373 if ((check)||(n > 0))
374 {
375 OOLog(kOOLogEntityVerificationError, @"Broken y_next %@ list (%d) ***", UNIVERSE->y_list_start, n);
376 return NO;
377 }
378 //
379 n = UNIVERSE->n_entities;
380 check = last;
381 while ((n--)&&(check)) check = check->y_previous;
382 if ((check)||(n > 0))
383 {
384 OOLog(kOOLogEntityVerificationError, @"Broken y_previous %@ list (%d) ***", UNIVERSE->y_list_start, n);
385 return NO;
386 }
387 //
388 n = UNIVERSE->n_entities;
389 check = UNIVERSE->z_list_start;
390 while ((n--)&&(check))
391 {
392 last = check;
393 check = check->z_next;
394 }
395 if ((check)||(n > 0))
396 {
397 OOLog(kOOLogEntityVerificationError, @"Broken z_next %@ list (%d) ***", UNIVERSE->z_list_start, n);
398 return NO;
399 }
400 //
401 n = UNIVERSE->n_entities;
402 check = last;
403 while ((n--)&&(check)) check = check->z_previous;
404 if ((check)||(n > 0))
405 {
406 OOLog(kOOLogEntityVerificationError, @"Broken z_previous %@ list (%d) ***", UNIVERSE->z_list_start, n);
407 return NO;
408 }
409 }
410 return YES;
411}
412
413
414- (void) updateLinkedLists
415{
416 if (!UNIVERSE)
417 return; // not in the UNIVERSE - don't do this!
418 if ((x_next == nil)&&(x_previous == nil))
419 return; // not in the lists - don't do this!
420
421#ifndef NDEBUG
423 {
424 if (![self checkLinkedLists])
425 {
426 OOLog(kOOLogEntityVerificationError, @"DEBUG LINKED LISTS problem encountered before updating linked lists for %@", self);
427 [UNIVERSE debugDumpEntities];
428 }
429 }
430#endif
431
432 // update position in linked list for position.x
433 // take self out of list..
434 if (x_previous) x_previous->x_next = x_next;
435 if (x_next) x_next->x_previous = x_previous;
436 // sink DOWN the list
437 while ((x_previous)&&(x_previous->position.x - x_previous->collision_radius > position.x - collision_radius))
438 {
439 x_next = x_previous;
440 x_previous = x_previous->x_previous;
441 }
442 // bubble UP the list
443 while ((x_next)&&(x_next->position.x - x_next->collision_radius < position.x - collision_radius))
444 {
445 x_previous = x_next;
446 x_next = x_next->x_next;
447 }
448 if (x_next) // insert self into the list before x_next..
449 x_next->x_previous = self;
450 if (x_previous) // insert self into the list after x_previous..
451 x_previous->x_next = self;
452 if ((x_previous == nil)&&(UNIVERSE)) // if we're the first then tell the UNIVERSE!
453 UNIVERSE->x_list_start = self;
454
455 // update position in linked list for position.y
456 // take self out of list..
457 if (y_previous) y_previous->y_next = y_next;
458 if (y_next) y_next->y_previous = y_previous;
459 // sink DOWN the list
460 while ((y_previous)&&(y_previous->position.y - y_previous->collision_radius > position.y - collision_radius))
461 {
462 y_next = y_previous;
463 y_previous = y_previous->y_previous;
464 }
465 // bubble UP the list
466 while ((y_next)&&(y_next->position.y - y_next->collision_radius < position.y - collision_radius))
467 {
468 y_previous = y_next;
469 y_next = y_next->y_next;
470 }
471 if (y_next) // insert self into the list before y_next..
472 y_next->y_previous = self;
473 if (y_previous) // insert self into the list after y_previous..
474 y_previous->y_next = self;
475 if ((y_previous == nil)&&(UNIVERSE)) // if we're the first then tell the UNIVERSE!
476 UNIVERSE->y_list_start = self;
477
478 // update position in linked list for position.z
479 // take self out of list..
480 if (z_previous) z_previous->z_next = z_next;
481 if (z_next) z_next->z_previous = z_previous;
482 // sink DOWN the list
483 while ((z_previous)&&(z_previous->position.z - z_previous->collision_radius > position.z - collision_radius))
484 {
485 z_next = z_previous;
486 z_previous = z_previous->z_previous;
487 }
488 // bubble UP the list
489 while ((z_next)&&(z_next->position.z - z_next->collision_radius < position.z - collision_radius))
490 {
491 z_previous = z_next;
492 z_next = z_next->z_next;
493 }
494 if (z_next) // insert self into the list before z_next..
495 z_next->z_previous = self;
496 if (z_previous) // insert self into the list after z_previous..
497 z_previous->z_next = self;
498 if ((z_previous == nil)&&(UNIVERSE)) // if we're the first then tell the UNIVERSE!
499 UNIVERSE->z_list_start = self;
500
501 // done
502#ifndef NDEBUG
504 {
505 if (![self checkLinkedLists])
506 {
507 OOLog(kOOLogEntityUpdateError, @"DEBUG LINKED LISTS problem encountered after updating linked lists for %@", self);
508 [UNIVERSE debugDumpEntities];
509 }
510 }
511#endif
512}
513
514
515- (void) wasAddedToUniverse
516{
517 // Do nothing
518}
519
520
521- (void) wasRemovedFromUniverse
522{
523 // Do nothing
524}
525
526
527- (void) warnAboutHostiles
528{
529 // do nothing for now, this can be expanded in sub classes
530 OOLog(@"general.error.subclassResponsibility.Entity-warnAboutHostiles", @"%@", @"***** Entity does nothing in warnAboutHostiles");
531}
532
533
534- (CollisionRegion*) collisionRegion
535{
536 return collisionRegion;
537}
538
539
540- (void) setCollisionRegion: (CollisionRegion*) region
541{
542 if (collisionRegion) [collisionRegion release];
543 collisionRegion = [region retain];
544}
545
546
547- (void) setUniversalID:(OOUniversalID)uid
548{
549 universalID = uid;
550}
551
552
553- (OOUniversalID) universalID
554{
555 return universalID;
556}
557
558
559- (BOOL) throwingSparks
560{
561 return throw_sparks;
562}
563
564
565- (void) setThrowSparks:(BOOL) value
566{
567 throw_sparks = value;
568}
569
570
571- (void) throwSparks
572{
573 // do nothing for now
574}
575
576
577- (void) setOwner:(Entity *)ent
578{
579 [_owner release];
580 _owner = [ent weakRetain];
581}
582
583
584- (id) owner
585{
586 return [_owner weakRefUnderlyingObject];
587}
588
589
590- (ShipEntity *)parentEntity
591{
592 id owner = [self owner];
593 if ([owner isShipWithSubEntityShip:self]) return owner;
594 return nil;
595}
596
597
598- (id<OOWeakReferenceSupport>) superShaderBindingTarget
599{
600 return [self parentEntity];
601}
602
603
604- (ShipEntity *) rootShipEntity
605{
606 ShipEntity *parent = [self parentEntity];
607 if (parent != nil) return [parent rootShipEntity];
608 if ([self isShip]) return (ShipEntity *)self;
609 return nil;
610}
611
612
613- (HPVector) position
614{
615 return position;
616}
617
618- (Vector) cameraRelativePosition
619{
620 return cameraRelativePosition;
621}
622
623- (GLfloat) cameraRangeFront
624{
625 return magnitude(cameraRelativePosition) - [self frustumRadius];
626}
627
628- (GLfloat) cameraRangeBack
629{
630 return magnitude(cameraRelativePosition) + [self frustumRadius];
631}
632
633
634
635// Exposed to uniform bindings.
636// so needs to remain at OpenGL precision levels
637- (Vector) relativePosition
638{
639 return HPVectorToVector(HPvector_subtract([self position], [PLAYER position]));
640}
641
642- (Vector) vectorTo:(Entity *)entity
643{
644 return HPVectorToVector(HPvector_subtract([entity position], [self position]));
645}
646
647
648- (void) setPosition:(HPVector) posn
649{
650 position = posn;
651 [self updateCameraRelativePosition];
652}
653
654
655- (void) setPositionX:(OOHPScalar)x y:(OOHPScalar)y z:(OOHPScalar)z
656{
657 position.x = x;
658 position.y = y;
659 position.z = z;
660 [self updateCameraRelativePosition];
661}
662
663
664- (void) updateCameraRelativePosition
665{
666 cameraRelativePosition = HPVectorToVector(HPvector_subtract([self absolutePositionForSubentity],[PLAYER viewpointPosition]));
667}
668
669
670- (HPVector) absolutePositionForSubentity
671{
672 return [self absolutePositionForSubentityOffset:kZeroHPVector];
673}
674
675
676- (HPVector) absolutePositionForSubentityOffset:(HPVector) offset
677{
678 HPVector abspos = HPvector_add(position, OOHPVectorMultiplyMatrix(offset, rotMatrix));
679 Entity *last = nil;
680 Entity *father = [self parentEntity];
681
682 while (father != nil && father != last)
683 {
684 abspos = HPvector_add(OOHPVectorMultiplyMatrix(abspos, [father drawRotationMatrix]), [father position]);
685 last = father;
686 if (![last isSubEntity]) break;
687 father = [father owner];
688 }
689 return abspos;
690}
691
692
693- (double) zeroDistance
694{
695 return zero_distance;
696}
697
698
699- (double) camZeroDistance
700{
701 return cam_zero_distance;
702}
703
704
705- (NSComparisonResult) compareZeroDistance:(Entity *)otherEntity
706{
707 if ((otherEntity)&&(zero_distance > otherEntity->zero_distance))
708 return NSOrderedAscending;
709 else
710 return NSOrderedDescending;
711}
712
713
714- (BoundingBox) boundingBox
715{
716 return boundingBox;
717}
718
719
720- (GLfloat) mass
721{
722 return mass;
723}
724
725
726- (void) setOrientation:(Quaternion) quat
727{
728 orientation = quat;
729 [self orientationChanged];
730}
731
732
733- (Quaternion) orientation
734{
735 return orientation;
736}
737
738
739- (Quaternion) normalOrientation
740{
741 return [self orientation];
742}
743
744
745- (void) setNormalOrientation:(Quaternion) quat
746{
747 [self setOrientation:quat];
748}
749
750
751- (void) orientationChanged
752{
753 quaternion_normalize(&orientation);
754 rotMatrix = OOMatrixForQuaternionRotation(orientation);
755}
756
757
758- (void) setVelocity:(Vector) vel
759{
760 velocity = vel;
761}
762
763
764- (Vector) velocity
765{
766 return velocity;
767}
768
769
770- (double) speed
771{
772 return magnitude([self velocity]);
773}
774
775
776- (GLfloat) distanceTravelled
777{
778 return distanceTravelled;
779}
780
781
782- (void) setDistanceTravelled: (GLfloat) value
783{
784 distanceTravelled = value;
785}
786
787
788- (void) setStatus:(OOEntityStatus) stat
789{
790 _status = stat;
791}
792
793
794- (OOEntityStatus) status
795{
796 return _status;
797}
798
799
800- (void) setScanClass:(OOScanClass)sClass
801{
802 scanClass = sClass;
803}
804
805
806- (OOScanClass) scanClass
807{
808 return scanClass;
809}
810
811
812- (void) setEnergy:(GLfloat) amount
813{
814 energy = amount;
815}
816
817
818- (GLfloat) energy
819{
820 return energy;
821}
822
823
824- (void) setMaxEnergy:(GLfloat)amount
825{
826 maxEnergy = amount;
827}
828
829
830- (GLfloat) maxEnergy
831{
832 return maxEnergy;
833}
834
835
836- (void) applyRoll:(GLfloat) roll andClimb:(GLfloat) climb
837{
838 if ((roll == 0.0)&&(climb == 0.0)&&(!hasRotated))
839 return;
840
841 if (roll)
842 quaternion_rotate_about_z(&orientation, -roll);
843 if (climb)
844 quaternion_rotate_about_x(&orientation, -climb);
845
846 [self orientationChanged];
847}
848
849
850- (void) applyRoll:(GLfloat) roll climb:(GLfloat) climb andYaw:(GLfloat) yaw
851{
852 if ((roll == 0.0)&&(climb == 0.0)&&(yaw == 0.0)&&(!hasRotated))
853 return;
854
855 if (roll)
856 quaternion_rotate_about_z(&orientation, -roll);
857 if (climb)
858 quaternion_rotate_about_x(&orientation, -climb);
859 if (yaw)
860 quaternion_rotate_about_y(&orientation, -yaw);
861
862 [self orientationChanged];
863}
864
865
866- (void) moveForward:(double)amount
867{
868 HPVector forward = HPvector_multiply_scalar(HPvector_forward_from_quaternion(orientation), amount);
869 position = HPvector_add(position, forward);
870 distanceTravelled += amount;
871}
872
873
874- (OOMatrix) rotationMatrix
875{
876 return rotMatrix;
877}
878
879
880- (OOMatrix) drawRotationMatrix
881{
882 return rotMatrix;
883}
884
885
886- (OOMatrix) transformationMatrix
887{
888 OOMatrix result = rotMatrix;
889 return OOMatrixHPTranslate(result, position);
890}
891
892
893- (OOMatrix) drawTransformationMatrix
894{
895 OOMatrix result = rotMatrix;
896 return OOMatrixHPTranslate(result, position);
897}
898
899
900- (BOOL) canCollide
901{
902 return YES;
903}
904
905
906- (GLfloat) collisionRadius
907{
908 return collision_radius;
909}
910
911
912- (GLfloat) frustumRadius
913{
914 return collision_radius;
915}
916
917
918- (void) setCollisionRadius:(GLfloat) amount
919{
920 collision_radius = amount;
921}
922
923
924- (NSMutableArray *) collisionArray
925{
926 return collidingEntities;
927}
928
929
930- (void) update:(OOTimeDelta)delta_t
931{
932 if (_status != STATUS_COCKPIT_DISPLAY)
933 {
934 if ([self isSubEntity])
935 {
936 zero_distance = [[self owner] zeroDistance];
937 cam_zero_distance = [[self owner] camZeroDistance];
938 [self updateCameraRelativePosition];
939 }
940 else
941 {
942 zero_distance = HPdistance2(PLAYER->position, position);
943 cam_zero_distance = HPdistance2([PLAYER viewpointPosition], position);
944 [self updateCameraRelativePosition];
945 }
946 }
947 else
948 {
949 zero_distance = HPmagnitude2(position);
950 cam_zero_distance = zero_distance;
951 cameraRelativePosition = HPVectorToVector(position);
952 }
953
954 if ([self status] != STATUS_COCKPIT_DISPLAY)
955 {
956 [self applyVelocity:delta_t];
957 }
958
959 hasMoved = !HPvector_equal(position, lastPosition);
960 hasRotated = !quaternion_equal(orientation, lastOrientation);
961 lastPosition = position;
962 lastOrientation = orientation;
963}
964
965
966- (void) applyVelocity:(OOTimeDelta)delta_t
967{
968 position = HPvector_add(position, HPvector_multiply_scalar(vectorToHPVector(velocity), delta_t));
969}
970
971
972- (BOOL) checkCloseCollisionWith:(Entity *)other
973{
974 return other != nil;
975}
976
977
978- (double)findCollisionRadius
979{
981 return 0;
982}
983
984
985- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
986{
988}
989
990
991- (void) takeEnergyDamage:(double) amount from:(Entity *) ent becauseOf:(Entity *) other weaponIdentifier:(NSString *)weaponIdentifier
992{
993
994}
995
996
997- (void)dumpState
998{
999 if (OOLogWillDisplayMessagesInClass(@"dumpState"))
1000 {
1001 OOLog(@"dumpState", @"State for %@:", self);
1003 OOLogIndent();
1004 @try
1005 {
1006 [self dumpSelfState];
1007 }
1008 @catch (id exception) {}
1010 }
1011}
1012
1013
1014- (void)dumpSelfState
1015{
1016 NSMutableArray *flags = nil;
1017 NSString *flagsString = nil;
1018 id owner = [self owner];
1019
1020 if (owner == self) owner = @"self";
1021 else if (owner == nil) owner = @"none";
1022
1023 OOLog(@"dumpState.entity", @"Universal ID: %u", universalID);
1024 OOLog(@"dumpState.entity", @"Scan class: %@", OOStringFromScanClass(scanClass));
1025 OOLog(@"dumpState.entity", @"Status: %@", OOStringFromEntityStatus([self status]));
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);
1032
1033 flags = [NSMutableArray array];
1034 #define ADD_FLAG_IF_SET(x) if (x) { [flags addObject:@#x]; }
1035 ADD_FLAG_IF_SET(isShip);
1036 ADD_FLAG_IF_SET(isStation);
1037 ADD_FLAG_IF_SET(isPlayer);
1038 ADD_FLAG_IF_SET(isWormhole);
1039 ADD_FLAG_IF_SET(isSubEntity);
1040 ADD_FLAG_IF_SET(hasMoved);
1041 ADD_FLAG_IF_SET(hasRotated);
1042 ADD_FLAG_IF_SET(isSunlit);
1043 ADD_FLAG_IF_SET(throw_sparks);
1044 flagsString = [flags count] ? [flags componentsJoinedByString:@", "] : (NSString *)@"none";
1045 OOLog(@"dumpState.entity", @"Flags: %@", flagsString);
1046 OOLog(@"dumpState.entity", @"Collision Test Filter: %u", collisionTestFilter);
1047
1048}
1049
1050
1051- (void)subEntityReallyDied:(ShipEntity *)sub
1052{
1053 OOLog(@"entity.bug", @"%s called for non-ship entity %p by %p", __PRETTY_FUNCTION__, self, sub);
1054}
1055
1056
1057- (NSUInteger) lastDrawCounter
1058{
1059 return lastDrawCounter;
1060}
1061
1062
1063- (void) setLastDrawCounter: (NSUInteger) drawCounter
1064{
1065 lastDrawCounter = drawCounter;
1066 return;
1067}
1068
1069
1070// For shader bindings.
1071- (GLfloat)universalTime
1072{
1073 return [UNIVERSE getTime];
1074}
1075
1076
1077- (GLfloat)spawnTime
1078{
1079 return spawnTime;
1080}
1081
1082
1083- (GLfloat)timeElapsedSinceSpawn
1084{
1085 return [UNIVERSE getTime] - spawnTime;
1086}
1087
1088
1089- (void) setAtmosphereFogging: (OOColor *)fogging
1090{
1091 [atmosphereFogging release];
1092 atmosphereFogging = [fogging retain];
1093}
1094
1095- (OOColor *) fogUniform
1096{
1097 return [[atmosphereFogging retain] autorelease];
1098}
1099
1100#ifndef NDEBUG
1101- (NSString *) descriptionForObjDumpBasic
1102{
1103 NSString *result = [self descriptionComponents];
1104 if (result != nil) result = [NSString stringWithFormat:@"%@ %@", NSStringFromClass([self class]), result];
1105 else result = [self description];
1106
1107 return result;
1108}
1109
1110
1111- (NSString *) descriptionForObjDump
1112{
1113 NSString *result = [self descriptionForObjDumpBasic];
1114
1115 result = [result stringByAppendingFormat:@" range: %g (visible: %@)", HPdistance([self position], [PLAYER position]), [self isVisible] ? @"yes" : @"no"];
1116
1117 return result;
1118}
1119
1120
1121- (NSSet *) allTextures
1122{
1123 return nil;
1124}
1125#endif
1126
1127
1128- (BOOL) isVisible
1129{
1130 return cam_zero_distance <= ABSOLUTE_NO_DRAW_DISTANCE2;
1131}
1132
1133
1134- (BOOL) isInSpace
1135{
1136 switch ([self status])
1137 {
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:
1144 case STATUS_EFFECT:
1145 case STATUS_ACTIVE:
1146 return YES;
1147 default:
1148 return NO;
1149 }
1150}
1151
1152
1153- (BOOL) isImmuneToBreakPatternHide
1154{
1155 return isImmuneToBreakPatternHide;
1156}
1157
1158@end
NSUInteger gDebugFlags
Definition main.m:7
OOEntityStatus
Definition Entity.h:60
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
OOScanClass
Definition Entity.h:71
#define ABSOLUTE_NO_DRAW_DISTANCE2
Definition Entity.h:47
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
uint32_t gLiveEntityCount
Definition Entity.m:43
#define ADD_FLAG_IF_SET(x)
size_t gTotalEntityMemory
Definition Entity.m:44
static NSString *const kOOLogEntityRemoveFromList
Definition Entity.m:51
static NSString *const kOOLogEntityRemoveFromListError
Definition Entity.m:52
static NSString *const kOOLogEntityVerificationError
Definition Entity.m:55
static NSString *const kOOLogEntityUpdateError
Definition Entity.m:53
static NSString *const kOOLogEntityAddToList
Definition Entity.m:49
static NSString *const kOOLogEntityAddToListError
Definition Entity.m:50
#define DESTROY(x)
Definition OOCocoa.h:75
uint32_t gLiveEntityCount
Definition Entity.m:43
size_t gTotalEntityMemory
Definition Entity.m:44
@ DEBUG_LINKED_LISTS
Definition OODebugFlags.h:5
#define EXPECT_NOT(x)
const HPVector kZeroHPVector
Definition OOHPVector.m:28
void OOLogPushIndent(void)
Definition OOLogging.m:316
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
void OOLogPopIndent(void)
Definition OOLogging.m:340
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:144
#define OOLogGenericSubclassResponsibility()
Definition OOLogging.h:129
#define OOLog(class, format,...)
Definition OOLogging.h:88
void OOLogIndent(void)
Definition OOLogging.m:366
double OOHPScalar
Definition OOMaths.h:69
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m)
Definition OOMatrix.m:145
const OOMatrix kIdentityMatrix
Definition OOMatrix.m:31
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
Definition OOMatrix.m:65
return self
return nil
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)
float y
float x
uint16_t OOUniversalID
Definition OOTypes.h:189
double OOTimeDelta
Definition OOTypes.h:224
#define PLAYER
#define UNIVERSE
Definition Universe.h:842
BOOL checkLinkedLists()
Definition Entity.m:334
Entity * z_next
Definition Entity.h:122
Entity * z_previous
Definition Entity.h:122
GLfloat zero_distance
Definition Entity.h:108
Entity * x_previous
Definition Entity.h:120
ShipEntity * rootShipEntity()
Definition Entity.m:604
Entity * x_next
Definition Entity.h:120
void setStatus:(OOEntityStatus stat)
Definition Entity.m:788
id owner()
Definition Entity.m:584
Entity * y_next
Definition Entity.h:121
Entity * y_previous
Definition Entity.h:121
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:95
voidpf uLong offset
Definition ioapi.h:140