Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Core/AI.m
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script
NSDictionary *newSM = nil;
NSMutableDictionary *cleanSM = nil;
OOCacheManager *cacheMgr = [OOCacheManager sharedCache];
NSEnumerator *stateEnum = nil;
NSString *stateKey = nil;
NSDictionary *stateHandlers = nil;
NSAutoreleasePool *pool = nil;
Expand Down Expand Up @@ -844,7 +843,7 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script

cleanSM = [NSMutableDictionary dictionaryWithCapacity:[newSM count]];

for (stateEnum = [newSM keyEnumerator]; (stateKey = [stateEnum nextObject]); )
foreachkey (stateKey, newSM)
{
stateHandlers = [newSM objectForKey:stateKey];
if (![stateHandlers isKindOfClass:[NSDictionary class]])
Expand Down Expand Up @@ -887,13 +886,12 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script

- (NSDictionary *) cleanHandlers:(NSDictionary *)handlers forState:(NSString *)stateKey stateMachine:(NSString *)smName
{
NSEnumerator *handlerEnum = nil;
NSString *handlerKey = nil;
NSArray *handlerActions = nil;
NSMutableDictionary *result = nil;

result = [NSMutableDictionary dictionaryWithCapacity:[handlers count]];
for (handlerEnum = [handlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); )
foreachkey (handlerKey, handlers)
{
handlerActions = [handlers objectForKey:handlerKey];
if (![handlerActions isKindOfClass:[NSArray class]])
Expand All @@ -913,7 +911,6 @@ - (NSDictionary *) cleanHandlers:(NSDictionary *)handlers forState:(NSString *)s

- (NSArray *) cleanActions:(NSArray *)actions forHandler:(NSString *)handlerKey state:(NSString *)stateKey stateMachine:(NSString *)smName
{
NSEnumerator *actionEnum = nil;
NSString *action = nil;
NSRange spaceRange;
NSString *selector = nil;
Expand All @@ -936,7 +933,7 @@ - (NSArray *) cleanActions:(NSArray *)actions forHandler:(NSString *)handlerKey
}

result = [NSMutableArray arrayWithCapacity:[actions count]];
for (actionEnum = [actions objectEnumerator]; (action = [actionEnum nextObject]); )
foreach (action, actions)
{
if (![action isKindOfClass:[NSString class]])
{
Expand Down
12 changes: 4 additions & 8 deletions src/Core/AIGraphViz.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN
"\tnode [shape=box height=0.2 width=3.5 fontname=Helvetica color=\"#808080\"]\n\t\n"
"\tspecial_start [shape=ellipse color=\"#0000C0\" label=\"Start\"]\n\tspecial_start -> %@ [lhead=\"cluster_GLOBAL\" color=\"#0000A0\"]\n", EscapedGraphVizString(smName), HandlerToken(@"GLOBAL", @"ENTER", handlerKeys, uniqueSet)];

NSEnumerator *stateKeyEnum = [stateMachine keyEnumerator];
NSString *stateKey = nil;

NSMutableSet *specialNodes = [NSMutableSet set];

while ((stateKey = [stateKeyEnum nextObject]))
foreachkey (stateKey, stateMachine)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[graphViz appendFormat:@"\t\n\tsubgraph cluster_%@\n\t{\n\t\tlabel=\"%@\"\n", stateKey, EscapedGraphVizString(stateKey)];

NSDictionary *state = [stateMachine oo_dictionaryForKey:stateKey];
NSEnumerator *handlerKeyEnum = [state keyEnumerator];
NSString *handlerKey = nil;
while ((handlerKey = [handlerKeyEnum nextObject]))
foreachkey (handlerKey, state)
{
[graphViz appendFormat:@"\t\t%@ [label=\"%@\"]\n", HandlerToken(stateKey, handlerKey, handlerKeys, uniqueSet), EscapedGraphVizString(handlerKey)];
}
Expand All @@ -78,8 +76,7 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN
[graphViz appendString:@"\t}\n"];

// Go through each handler looking for interesting methods.
handlerKeyEnum = [state keyEnumerator];
while ((handlerKey = [handlerKeyEnum nextObject]))
foreachkey (handlerKey, state)
{
NSArray *handlerCommands = [state oo_arrayForKey:handlerKey];
NSUInteger commandIter, commandCount = [handlerCommands count];
Expand All @@ -98,9 +95,8 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN
{
[graphViz appendString:@"\t\n"];

NSEnumerator *specialEnum = [specialNodes objectEnumerator];
NSString *special = nil;
while ((special = [specialEnum nextObject]))
foreach (special, specialNodes)
{
[graphViz appendString:special];
}
Expand Down
21 changes: 8 additions & 13 deletions src/Core/Debug/OODebugMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ - (void) dumpEntity:(id)entity withState:(EntityDumpState *)state parentVisible:
OOLogIndent();
if ([entity isShip])
{
NSEnumerator *subEnum = nil;
id subentity = nil;
for (subEnum = [entity subEntityEnumerator]; (subentity = [subEnum nextObject]); )
foreach (subentity, [entity subEntityEnumerator])
{
[self dumpEntity:subentity withState:state parentVisible:visible];
}
Expand Down Expand Up @@ -494,9 +493,8 @@ - (void) dumpEntity:(id)entity withState:(EntityDumpState *)state parentVisible:
}
if ([entity isWormhole])
{
NSEnumerator *shipEnum = nil;
NSDictionary *shipInfo = nil;
for (shipEnum = [[entity shipsInTransit] objectEnumerator]; (shipInfo = [shipEnum nextObject]); )
foreach (shipInfo, [entity shipsInTransit])
{
ShipEntity *ship = [shipInfo objectForKey:@"ship"];
[self dumpEntity:ship withState:state parentVisible:NO];
Expand All @@ -516,8 +514,7 @@ - (void) dumpMemoryStatistics
NSMutableDictionary *textureRefCounts = [NSMutableDictionary dictionaryWithCapacity:[allTextures count]];

OOTexture *tex = nil;
NSEnumerator *texEnum = nil;
for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); )
foreach (tex, allTextures)
{
// We subtract one because allTextures retains the textures.
[textureRefCounts setObject:[NSNumber numberWithUnsignedInteger:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]];
Expand All @@ -537,12 +534,11 @@ - (void) dumpMemoryStatistics
};

id entity = nil;
NSEnumerator *entityEnum = nil;
for (entityEnum = [entities objectEnumerator]; (entity = [entityEnum nextObject]); )
foreach (entity, entities)
{
[self dumpEntity:entity withState:&entityDumpState parentVisible:YES];
}
for (entityEnum = [[PLAYER scannedWormholes] objectEnumerator]; (entity = [entityEnum nextObject]); )
foreach (entity, [PLAYER scannedWormholes])
{
[self dumpEntity:entity withState:&entityDumpState parentVisible:YES];
}
Expand All @@ -560,7 +556,7 @@ - (void) dumpMemoryStatistics
*/
NSMutableArray *textures = [[[OOTexture cachedTexturesByAge] mutableCopy] autorelease];

for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); )
foreach (tex, allTextures)
{
if ([textures indexOfObject:tex] == NSNotFound)
{
Expand All @@ -575,7 +571,7 @@ - (void) dumpMemoryStatistics
[self writeMemStat:@"Textures:"];
OOLogIndent();

for (texEnum = [textures objectEnumerator]; (tex = [texEnum nextObject]); )
foreach (tex, textures)
{
size_t objSize = [tex oo_objectSize];
size_t dataSize = [tex dataSize];
Expand Down Expand Up @@ -828,12 +824,11 @@ - (NSArray *)loadSourceFile:(NSString *)filePath
- (NSMutableDictionary *)normalizeConfigDictionary:(NSDictionary *)dictionary
{
NSMutableDictionary *result = nil;
NSEnumerator *keyEnum = nil;
NSString *key = nil;
id value = nil;

result = [NSMutableDictionary dictionaryWithCapacity:[dictionary count]];
for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); )
foreachkey (key, dictionary)
{
value = [dictionary objectForKey:key];
value = [self normalizeConfigValue:value forKey:key];
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Debug/OODebugTCPConsoleClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ - (void) handleNoteConfigurationChangePacket:(NSDictionary *)packet
configuration = [packet oo_dictionaryForKey:kOOTCPConfiguration];
if (configuration != nil)
{
for (keyEnum = [configuration keyEnumerator]; (key = [keyEnum nextObject]); )
foreachkey (key, configuration)
{
value = [configuration objectForKey:key];
[_monitor setConfigurationValue:value forKey:key];
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Entities/OOFlasherEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ - (void) setUpColors:(NSArray *)colorSpecifiers
{
NSMutableArray *colors = [NSMutableArray arrayWithCapacity:[colorSpecifiers count]];
id specifier = nil;
NSEnumerator *specEnum = [colorSpecifiers objectEnumerator];
while ((specifier = [specEnum nextObject]))
foreach (specifier, colorSpecifiers)
{
[colors addObject:[OOColor colorWithDescription:specifier saturationFactor:0.75f]];
}
Expand Down
26 changes: 9 additions & 17 deletions src/Core/Entities/PlayerEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,8 @@ - (NSDictionary *) commanderDataDictionary

// wormhole information
NSMutableArray *wormholeDicts = [NSMutableArray arrayWithCapacity:[scannedWormholes count]];
NSEnumerator *wormholes = [scannedWormholes objectEnumerator];
WormholeEntity *wh = nil;
foreach(wh, wormholes)
foreach (wh, scannedWormholes)
{
[wormholeDicts addObject:[wh getDict]];
}
Expand Down Expand Up @@ -1519,11 +1518,10 @@ energy bomb (900 credits). This must be done after missiles are
// wormholes
NSArray * whArray;
whArray = [dict objectForKey:@"wormholes"];
NSEnumerator * whDicts = [whArray objectEnumerator];
NSDictionary * whCurrDict;
[scannedWormholes release];
scannedWormholes = [[NSMutableArray alloc] initWithCapacity:[whArray count]];
while ((whCurrDict = [whDicts nextObject]) != nil)
foreach (whCurrDict, whArray)
{
WormholeEntity * wh = [[WormholeEntity alloc] initWithDict:whCurrDict];
[scannedWormholes addObject:wh];
Expand Down Expand Up @@ -7729,12 +7727,11 @@ - (NSArray *) cargoList
{
NSMutableArray *manifest = [NSMutableArray array];
NSArray *list = [self cargoListForScripting];
NSEnumerator *cargoEnum = nil;
NSDictionary *commodity;

if (specialCargo) [manifest addObject:specialCargo];

for (cargoEnum = [list objectEnumerator]; (commodity = [cargoEnum nextObject]); )
foreach (commodity, list)
{
NSInteger quantity = [commodity oo_integerForKey:@"quantity"];
NSString *units = [commodity oo_stringForKey:@"unit"];
Expand Down Expand Up @@ -8083,10 +8080,9 @@ - (NSDictionary *) markedDestinations
[self prepareMarkedDestination:destinations:marker];
}

NSEnumerator *keyEnum = nil;
NSString *key = nil;

for (keyEnum = [missionDestinations keyEnumerator]; (key = [keyEnum nextObject]); )
foreachkey (key, missionDestinations)
{
marker = [missionDestinations objectForKey:key];
[self prepareMarkedDestination:destinations:marker];
Expand Down Expand Up @@ -11897,10 +11893,9 @@ - (void) doWorldScriptEvent:(jsid)message inContext:(JSContext *)context withArg
{
NSParameterAssert(context != NULL && JS_IsInRequest(context));

NSEnumerator *scriptEnum = nil;
OOScript *theScript = nil;

for (scriptEnum = [worldScripts objectEnumerator]; (theScript = [scriptEnum nextObject]); )
foreach (theScript, [worldScripts allValues])
{
OOJSStartTimeLimiterWithTimeLimit(limit);
[theScript callMethod:message inContext:context withArguments:argv count:argc result:NULL];
Expand Down Expand Up @@ -12142,9 +12137,8 @@ - (void)addScannedWormhole:(WormholeEntity*)whole
assert(whole != nil);

// Only add if we don't have it already!
NSEnumerator *wormholes = [scannedWormholes objectEnumerator];
WormholeEntity *wh = nil;
while ((wh = [wormholes nextObject]))
foreach (wh, scannedWormholes)
{
if (wh == whole) return;
}
Expand All @@ -12165,10 +12159,9 @@ - (void)updateWormholes
double now = [self clockTimeAdjusted];

NSMutableArray * savedWormholes = [[NSMutableArray alloc] initWithCapacity:[scannedWormholes count]];
NSEnumerator * wormholes = [scannedWormholes objectEnumerator];
WormholeEntity *wh;

while ((wh = (WormholeEntity*)[wormholes nextObject]))
foreach (wh, scannedWormholes)
{
// TODO: Start drawing wormhole exit a few seconds before the first
// ship is disgorged.
Expand Down Expand Up @@ -12200,7 +12193,6 @@ - (NSArray *) scannedWormholes

- (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(NSArray *)legacy
{
NSEnumerator *keyEnum = nil;
NSString *key = nil;
id value = nil;

Expand All @@ -12209,7 +12201,7 @@ - (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(N
[missionDestinations release];
missionDestinations = [[NSMutableDictionary alloc] init];

for (keyEnum = [destinations keyEnumerator]; (key = [keyEnum nextObject]); )
foreachkey (key, destinations)
{
value = [destinations objectForKey:key];
if (value != nil)
Expand All @@ -12227,7 +12219,7 @@ - (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(N
{
OOSystemID dest;
NSNumber *legacyMarker;
for (keyEnum = [legacy objectEnumerator]; (legacyMarker = [keyEnum nextObject]); )
foreach (legacyMarker, legacy)
{
dest = [legacyMarker intValue];
[self addMissionDestinationMarker:[self defaultMarker:dest]];
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Entities/PlayerEntityLegacyScriptEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,12 @@ have been generated by OOSanitizeLegacyScriptConditions() and doesn't
- (NSString *) expandScriptRightHandSide:(NSArray *)rhsComponents
{
NSMutableArray *result = nil;
NSEnumerator *componentEnum = nil;
NSArray *component = nil;
NSString *value = nil;

result = [NSMutableArray arrayWithCapacity:[rhsComponents count]];

for (componentEnum = [rhsComponents objectEnumerator]; (component = [componentEnum nextObject]); )
foreach (component, rhsComponents)
{
/* Each component is a two-element array. The second element is a
string. The first element is a boolean indicating whether the
Expand Down Expand Up @@ -1397,7 +1396,7 @@ - (void) removeAllCargo:(BOOL)forceRemoval

OOLog(kOOLogNoteRemoveAllCargo, @"%@ removeAllCargo", forceRemoval ? @"Forcing" : @"Going to");

foreach(type, [shipCommodityData goods])
foreach (type, [shipCommodityData goods])
{
if ([shipCommodityData massUnitForGood:type] == UNITS_TONS)
{
Expand Down Expand Up @@ -1983,15 +1982,14 @@ - (void) setMissionChoicesDictionary:(NSDictionary *)choicesDict
[UNIVERSE enterGUIViewModeWithMouseInteraction:YES]; // enables mouse selection of the choices list items

OOGUIRow choicesRow = (end_row+1) - [choiceKeys count];
NSEnumerator *choiceEnum = nil;
NSString *choiceKey = nil;
id choiceValue = nil;
NSString *choiceText = nil;

BOOL selectableRowExists = NO;
NSUInteger firstSelectableRow = end_row;

for (choiceEnum = [choiceKeys objectEnumerator]; (choiceKey = [choiceEnum nextObject]); )
foreach (choiceKey, choiceKeys)
{
choiceValue = [choicesDict objectForKey:choiceKey];
OOGUIAlignment alignment = GUI_ALIGN_CENTER;
Expand Down
Loading