The idea of this thread is to achieve concensus on an OO structure for the MapSquare class. F_Smith, can you post the variables for your existing class here also?
Here is what I currently have in the MapSquare classes for the demo 4 + code. Because I was initially trying to be frugal with memory storage for each MapSquare there was a hierarchy of three types of MapSquare classes. The lowest is BaseMapSquare which can handle things like sea squares that don't require all the information that is required for land. Next highest is MapSquare which holds all the info necessary for a land square. The highest is PopSquare which is a MapSquare with population in it.
Given what I've learned from F. Smith, it is probably foolish to have these three different levels of MapSquare. I will just put them one after the other, and the sum of all three is my guess the starting proposal for the new MapSquare class.
The entire map is held in a class called TheMap which is simply a 2D array of BaseMapSquare. I strongly urge that we keep this structure intact, since substantial amounts of the existing code for AI, movement, and map graphics, relies on this 2d array being there.
If you don't want to look at my abbreviated version, the complete Javadoc and source code are available in the thread Javadoc Documentation for current source / + current source code
This stuff is not all self-explanatory. There's some things that relate to the AI, such as having different worlds (to test out strategies in a world that is divorced from the game world). If you are really having a hard time figuring out what something is, post a question and I'll try to answer it quickly.
Also, where possible, I think we should keep the current variable names and structures unless there are big problems with them. Every change will potentially involve a lot of work. Please don't suggest a change unless you think the existing version is so bad that it will cause significant future problems.
Here is what I currently have in the MapSquare classes for the demo 4 + code. Because I was initially trying to be frugal with memory storage for each MapSquare there was a hierarchy of three types of MapSquare classes. The lowest is BaseMapSquare which can handle things like sea squares that don't require all the information that is required for land. Next highest is MapSquare which holds all the info necessary for a land square. The highest is PopSquare which is a MapSquare with population in it.
Given what I've learned from F. Smith, it is probably foolish to have these three different levels of MapSquare. I will just put them one after the other, and the sum of all three is my guess the starting proposal for the new MapSquare class.
The entire map is held in a class called TheMap which is simply a 2D array of BaseMapSquare. I strongly urge that we keep this structure intact, since substantial amounts of the existing code for AI, movement, and map graphics, relies on this 2d array being there.
If you don't want to look at my abbreviated version, the complete Javadoc and source code are available in the thread Javadoc Documentation for current source / + current source code
This stuff is not all self-explanatory. There's some things that relate to the AI, such as having different worlds (to test out strategies in a world that is divorced from the game world). If you are really having a hard time figuring out what something is, post a question and I'll try to answer it quickly.
Also, where possible, I think we should keep the current variable names and structures unless there are big problems with them. Every change will potentially involve a lot of work. Please don't suggest a change unless you think the existing version is so bad that it will cause significant future problems.
Code:
/** BaseMapSquare is an individual square of the map and its characteristics. * BaseMapSquare provides routines used by all MapSquare classes, stores information about: * 1) Generic Terrain Types and Specific Value for This Square, * 2) Square Location, X and Y, * 3) Military TFs present..., * 4) Whether the Square Is Selected or Not, an Aid for the User Interface, * 5) Special resources are implemented at this level (eventually) to handle fishing..., * * BaseMapSquare fully represents a sea or lake Square. For a land square it is extended to * MapSquare if unpopulated, and PopSquare if populated. * * Copyright 1999, the Clash of Civilizations Development Group * * @author Mark Everson * @version 0.3, Date: January 12 2000 */ public class BaseMapSquare extends SerialCloneable implements Cloneable { // Which world is the square in? Defaults to 0, the main game world // Rather than have a whole new set of constructors for different worlds, when the World() // constructor is called it will paste in the correct value. private byte worldIndex = 0; /** Describing whether a square is coastal, inland, etc */ private byte positionType = 0; /** Describes land squares around a littoral water square; so far just use 4 bits for adjacent land to the North (1), East (2), South (4), and West (8); so a one-square lake = 15*/ private byte oceanType = 0; protected byte terrain = OFF_MAP; // one of the terrain types, e.g. MapSquare.WATER private byte siteType = 0;// index pointing to position in econSitesArray that holds site information // Right now there is only one siteType for each terrain type, but I'm setting it up more // generally for future use private byte mapTile = 0; // map Tile numbers - not used currently protected int xLoc, yLoc; // absolute x and y coords of the square. private TF[] TFsHere; // the TFs know what civ they're from by TF.itsCiv private byte numTFsHere = 0; /** Is combat possible here this turn; used for assigning support forces to friendly TFs */ private boolean potentialCombat = false; /** Attacker for combat that will take place this turn, loaded in isTherePotentialCombatThisTurn()*/ private Civ attackerCiv; /** Defender for combat that will take place this turn, loaded in isTherePotentialCombatThisTurn() */ private Civ defenderCiv; private boolean selected; // for use in selecting squares on the map for various functions private boolean isTarget; // a second type of selection, currently not used ************************************************** /** MapSquare * PopSquare at bottom of file extends MapSquare to cover populated squares that * don't belong to a civ * An individual land square of the map and its characteristics * * Copyright 1999, the Clash of Civilizations Development Group * * @Author Unknown * @Version 0.3 Date January 12 2000 */ public class MapSquare extends BaseMapSquare implements Cloneable { /** 1 in a bit means there's a river, all rivers flow to center of Sq * N edge is 8x bit rotating clockwise (NESW) to * W edge is 1x bit - River N&E -> riverPos = 12; */ private byte riverPos = 0; /** [0] is N and it goes cw ([1] = NE etc...) * just because roadTo[x] is true doesn't mean there's a useable road * must check roadCondition[] value to determine existence and * quality */ private boolean[] roadTo; /** None = 0, is for planned or destroyed roads */ private byte[] roadCondition; /** MapSquare() constructor */ public MapSquare(){ // [0] is N and it goes cw ([1] = NE etc...) roadTo = new boolean[8] ; // None = 0, is for planned or destroyed roads // might have info, like the tiling used to display // the road in future implementations roadCondition = new byte[8] ; } Copy /** PopSquare // * PopSquare extends MapSquare to cover populated squares * * Copyright 1999, the Clash of Civilizations Development Group * * @Author Unknown * @Version 0.3 Date January 12 2000 */ public class PopSquare extends MapSquare implements Cloneable { /** the Province the square is associated with, if any */ private Province prov; /** city indicates whether the square is urban or not */ private boolean city = false; /** used in multi-square province (MSP) bookkeeping, has to * do with how developed this square is with respect to the average for the MSP * no [0] similar to sector numbers [1] is diff for Farm, [5] is for Merch... */ private float[] capDifference = null; /** Contains the population of the square population, 1 = 1000 people */ private float pop; /* The defensive military capability of the inhabitants of the square */ private float milPower = 0; /** Culture covers tech and society aspects of populated squares there can be up to three cultures per popSquare */ private Culture cultures[]; /** culturepct that don't belong to a civ, culturePct keeps track of percent * of population in each of three cultures if sum over culturePct less than 100 * the rest of the pop is a mixture of other cultures too small to keep track of */ private byte culturePct[]; /** nomad is the pop primarily nomadic or agricultural */ private boolean nomad = false; /** frontline is used if sq is part of a prov to determine if * this square is directly exposed to potential hostilities */ private boolean frontLine = false; /** number of foreign squares adjacent * Specifically, number of adjacent land squares not controlled directly by us */ private byte numForeignSqs = -1; ******************************************************************* And here is TheMap... /** * TheMap Holds a map (2D array of type BaseMapSquare) of the world for a particular World. * It functions mostly as just a container for map[][] after initialization which it handles. * Right now initialization is by reading in a world map from a save file format and performing * some modifications to the initial information. For now there is no way to replace a square * with a different type directly, you're stuck with the map as it is. * * Date: 10/4/1999, Copyright 1999, the Clash of Civilizations Development Group * * @author Mark Everson * @Version 0.3 Date January 12 2000 */ public class TheMap{ /** which world this is associated with */ private int worldNumber; /** the detailed map */ private BaseMapSquare[][] map = new BaseMapSquare[mapLengthX][mapLengthY]; // eventually earth map will be absorbed by this map /** makes an off-map square for various uses */ private static PopSquare zipMapSquare; /** position of upper left of map in earthMap, right now set so play occurs on Europe */ private static Point smallMap00_Position_OnWorldMap;// /** squares in map x dir */ private static final int mapLengthX = 70; // /** squares in map y dir */ private static final int mapLengthY = 150; /** Map of Earth size 320x200 from an old game project called Antiquity */ private static short[][] earthMap = new short[320][200]; private static short[][] earthMapRotated = new short[1000][700]; private InputStream in; /*FileInputStream*/
Comment