This is ODirection.m in view mode; [Download] [Up]
// // $Id: ODirection.m,v 1.1 1997/10/28 05:11:21 nygard Exp $ // // // This file is a part of Empire, a game of exploration and conquest. // Copyright (C) 1996 Steve Nygard // // 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., 675 Mass Ave, Cambridge, MA 02139, USA. // // You may contact the author by: // e-mail: nygard@telusplanet.net // #import "Empire.h" RCSID ("$Id: ODirection.m,v 1.1 1997/10/28 05:11:21 nygard Exp $"); #import "ODirection.h" #import "Unit.h" //====================================================================== // // This instructs the unit to move in a given direction. If it is // blocked, it tries to strip the horizontal component off the // direction and move that way, and then the vertical direction if it // is still blocked, before giving up. // // For example, if it's going northeast and is blocked, it then tries // north. If it is still blocked, it tries moving east. // //====================================================================== #define ODirection_VERSION 1 @implementation ODirection + (void) initialize { if (self == [ODirection class]) { [self setVersion:ODirection_VERSION]; } } //---------------------------------------------------------------------- - initForUnit:(Unit *)aUnit direction:(Direction)dir { [super initForUnit:aUnit]; direction = dir; return self; } //---------------------------------------------------------------------- - (void) dealloc { [super dealloc]; } //---------------------------------------------------------------------- - (NSString *) orderText { return [NSString stringWithFormat:@"Direction %@", EMShortDirectionName (direction)]; } //---------------------------------------------------------------------- - (Direction) nextMove { Direction dir = direction; Direction stripHorizontal[9] = {d_north, d_north, d_north, d_west, d_none, d_east, d_south, d_south, d_south}; Direction stripVertical[9] = {d_west, d_north, d_east, d_west, d_none, d_east, d_west, d_south, d_east}; // Try not to crash fighters. if ([unit unitType] == u_fighter && [unit remainingFuel] == 10) return d_none; if (blockedCount == 1) dir = stripHorizontal[dir]; else if (blockedCount == 2) dir = stripVertical[dir]; return dir; } //---------------------------------------------------------------------- - (BOOL) wasBlocked { blockedCount++; return blockedCount < 3; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.