Separate some docking control into separate DockEntity in preparation for allowing multiple docks per station.
Known regression: stations without docks (but with port_dimensions/radius) can no longer dock ships. Doesn't actually work yet with multiple docks per station (everything will be directed through the first dock, though player may be able to dock at others) but first dock should be working as before. DockEntity.* files will need adding to Xcode project before Mac compile works. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5058 127b21dd-08f5-0310-b4b7-95ae10353056master
parent
e3525a2a1e
commit
1c8a27357a
|
@ -150,6 +150,7 @@ OOLITE_DEBUG_FILES = \
|
|||
OOTCPStreamDecoderAbstractionLayer.m
|
||||
|
||||
OOLITE_ENTITY_FILES = \
|
||||
DockEntity.m \
|
||||
DustEntity.m \
|
||||
Entity.m \
|
||||
OOEntityWithDrawable.m \
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
|
||||
DockEntity.h
|
||||
|
||||
ShipEntity subclass representing a dock entity
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2012 Giles C Williams and contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#import "ShipEntity.h"
|
||||
#import "StationEntity.h"
|
||||
#import "Universe.h"
|
||||
#import "legacy_random.h"
|
||||
|
||||
|
||||
@interface DockEntity: ShipEntity
|
||||
{
|
||||
|
||||
NSMutableDictionary *shipsOnApproach;
|
||||
NSMutableArray *launchQueue;
|
||||
double last_launch_time;
|
||||
double approach_spacing;
|
||||
|
||||
ShipEntity *id_lock[MAX_DOCKING_STAGES]; // OOWeakReferences to a ShipEntity
|
||||
|
||||
Vector port_dimensions;
|
||||
double port_corridor; // corridor length inside station.
|
||||
|
||||
unsigned no_docking_while_launching: 1;
|
||||
|
||||
}
|
||||
|
||||
- (void) clearIdLocks:(ShipEntity *)ship;
|
||||
- (void) abortAllDockings;
|
||||
- (unsigned) sanityCheckShipsOnApproach;
|
||||
- (void) autoDockShipsOnApproach;
|
||||
- (void) autoDockShipsInQueue:(NSMutableDictionary *)queue;
|
||||
- (NSDictionary *) dockingInstructionsForShip:(ShipEntity *) ship;
|
||||
- (NSString*) canAcceptShipForDocking:(ShipEntity *) ship;
|
||||
- (BOOL) isOffCentre;
|
||||
- (void) addShipToShipsOnApproach:(ShipEntity *) ship;
|
||||
- (void) abortDockingForShip:(ShipEntity *) ship;
|
||||
- (Vector) portUpVectorForShipsBoundingBox:(BoundingBox) bb;
|
||||
- (void) pullInShipIfPermitted:(ShipEntity *)ship;
|
||||
- (unsigned) countShipsInLaunchQueueWithPrimaryRole:(NSString *)role;
|
||||
- (void) launchShip:(ShipEntity *) ship;
|
||||
- (void) addShipToLaunchQueue:(ShipEntity *) ship :(BOOL) priority;
|
||||
- (BOOL) fitsInDock:(ShipEntity *) ship;
|
||||
- (BOOL) dockingCorridorIsEmpty;
|
||||
- (void) clearDockingCorridor;
|
||||
- (BOOL) shipIsInDockingCorridor:(ShipEntity *)ship;
|
||||
- (Vector) portUpVectorForShipsBoundingBox:(BoundingBox) bb;
|
||||
- (void) clear;
|
||||
- (void) noteDockingForShip:(ShipEntity *) ship;
|
||||
- (void)setDimensionsAndCorridor;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -158,6 +158,7 @@ enum OOScanClass
|
|||
- (OOUInteger) sessionID;
|
||||
|
||||
- (BOOL) isShip;
|
||||
- (BOOL) isDock;
|
||||
- (BOOL) isStation;
|
||||
- (BOOL) isSubEntity;
|
||||
- (BOOL) isPlayer;
|
||||
|
|
|
@ -131,6 +131,12 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
|||
}
|
||||
|
||||
|
||||
- (BOOL)isDock
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isStation
|
||||
{
|
||||
return isStation;
|
||||
|
|
|
@ -60,6 +60,7 @@ MA 02110-1301, USA.
|
|||
|
||||
#import "OOParticleSystem.h"
|
||||
#import "StationEntity.h"
|
||||
#import "DockEntity.h"
|
||||
#import "OOSunEntity.h"
|
||||
#import "OOPlanetEntity.h"
|
||||
#import "PlayerEntity.h"
|
||||
|
@ -790,16 +791,23 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
|
|||
subentKey = [subentDict oo_stringForKey:@"subentity_key"];
|
||||
if (subentKey == nil) return NO;
|
||||
|
||||
subentity = [UNIVERSE newShipWithName:subentKey];
|
||||
if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"])
|
||||
{
|
||||
subentity = [UNIVERSE newDockWithName:subentKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
subentity = [UNIVERSE newShipWithName:subentKey];
|
||||
}
|
||||
if (subentity == nil) return NO;
|
||||
|
||||
subPosition = [subentDict oo_vectorForKey:@"position"];
|
||||
subOrientation = [subentDict oo_quaternionForKey:@"orientation"];
|
||||
|
||||
if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"])
|
||||
/* if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"])
|
||||
{
|
||||
[(StationEntity *)self setDockingPortModel:subentity :subPosition :subOrientation];
|
||||
}
|
||||
} */
|
||||
|
||||
[subentity setPosition:subPosition];
|
||||
[subentity setOrientation:subOrientation];
|
||||
|
@ -830,6 +838,11 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
|
|||
bounding_box_add_vector(&totalBoundingBox, sebb.min);
|
||||
}
|
||||
|
||||
if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"])
|
||||
{
|
||||
[(DockEntity *)subentity setDimensionsAndCorridor];
|
||||
}
|
||||
|
||||
[subentity release];
|
||||
|
||||
return YES;
|
||||
|
|
|
@ -102,7 +102,9 @@ typedef enum
|
|||
allowsAutoDocking: 1;
|
||||
}
|
||||
|
||||
- (void) setDockingPortModel:(ShipEntity*) dock_model :(Vector) dock_pos :(Quaternion) dock_q;
|
||||
- (NSEnumerator *)dockSubEntityEnumerator;
|
||||
|
||||
// - (void) setDockingPortModel:(ShipEntity*) dock_model :(Vector) dock_pos :(Quaternion) dock_q;
|
||||
|
||||
- (NSMutableArray *) localMarket;
|
||||
- (void) setLocalMarket:(NSArray *) some_market;
|
||||
|
@ -139,12 +141,10 @@ typedef enum
|
|||
|
||||
- (void) autoDockShipsOnApproach;
|
||||
|
||||
- (NSDictionary *) dockingInstructionsForShip:(ShipEntity *) ship;
|
||||
- (void) addShipToShipsOnApproach:(ShipEntity *) ship;
|
||||
|
||||
- (Vector) portUpVector;
|
||||
- (Vector) portUpVectorForShipsBoundingBox:(BoundingBox) bb;
|
||||
|
||||
- (NSDictionary *) dockingInstructionsForShip:(ShipEntity *) ship;
|
||||
|
||||
- (BOOL) shipIsInDockingCorridor:(ShipEntity*) ship;
|
||||
|
||||
- (BOOL) dockingCorridorIsEmpty;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@ MA 02110-1301, USA.
|
|||
|
||||
@class GameController, CollisionRegion, MyOpenGLView, GuiDisplayGen,
|
||||
Entity, ShipEntity, StationEntity, OOPlanetEntity, OOSunEntity,
|
||||
PlayerEntity, OORoleSet, WormholeEntity;
|
||||
PlayerEntity, OORoleSet, WormholeEntity, DockEntity;
|
||||
|
||||
|
||||
typedef BOOL (*EntityFilterPredicate)(Entity *entity, void *parameter);
|
||||
|
@ -407,6 +407,7 @@ typedef uint8_t OOEconomyID; // 0..7
|
|||
- (NSString *) randomShipKeyForRoleRespectingConditions:(NSString *)role;
|
||||
- (ShipEntity *) newShipWithRole:(NSString *)role OO_RETURNS_RETAINED; // Selects ship using role weights, applies auto_ai, respects conditions
|
||||
- (ShipEntity *) newShipWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions
|
||||
- (DockEntity *) newDockWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions
|
||||
- (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy OO_RETURNS_RETAINED; // If usePlayerProxy, non-carriers are instantiated as ProxyPlayerEntity.
|
||||
|
||||
- (Class) shipClassForShipDictionary:(NSDictionary *)dict;
|
||||
|
|
|
@ -59,6 +59,7 @@ MA 02110-1301, USA.
|
|||
#import "PlayerEntityContracts.h"
|
||||
#import "PlayerEntityScriptMethods.h"
|
||||
#import "StationEntity.h"
|
||||
#import "DockEntity.h"
|
||||
#import "SkyEntity.h"
|
||||
#import "DustEntity.h"
|
||||
#import "OOPlanetEntity.h"
|
||||
|
@ -2691,6 +2692,42 @@ static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
|
|||
}
|
||||
|
||||
|
||||
- (DockEntity *) newDockWithName:(NSString *)shipKey
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
NSDictionary *shipDict = nil;
|
||||
DockEntity *ship = nil;
|
||||
|
||||
shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
|
||||
if (shipDict == nil) return nil;
|
||||
|
||||
volatile Class shipClass = [DockEntity class];
|
||||
|
||||
NS_DURING
|
||||
ship = [[shipClass alloc] initWithKey:shipKey definition:shipDict];
|
||||
NS_HANDLER
|
||||
[ship release];
|
||||
ship = nil;
|
||||
|
||||
if ([[localException name] isEqual:OOLITE_EXCEPTION_DATA_NOT_FOUND])
|
||||
{
|
||||
OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [Universe newDockWithName: %@ ] *****", [localException reason], shipKey);
|
||||
}
|
||||
else [localException raise];
|
||||
NS_ENDHANDLER
|
||||
|
||||
// Set primary role to same as ship name, if ship name is also a role.
|
||||
// Otherwise, if caller doesn't set a role, one will be selected randomly.
|
||||
if ([ship hasRole:shipKey]) [ship setPrimaryRole:shipKey];
|
||||
|
||||
// MKW 20090327 - retain count is actually 2!
|
||||
return ship; // retain count = 1
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
|
||||
- (ShipEntity *) newShipWithName:(NSString *)shipKey
|
||||
{
|
||||
return [self newShipWithName:shipKey usePlayerProxy:NO];
|
||||
|
@ -2716,6 +2753,7 @@ static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
|
|||
isStation = [dict oo_boolForKey:@"isCarrier" defaultValue:isStation];
|
||||
isStation = [dict oo_boolForKey:@"is_carrier" defaultValue:isStation];
|
||||
|
||||
|
||||
return isStation ? [StationEntity class] : [ShipEntity class];
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
|
|
Loading…
Reference in New Issue