/// <summary> /// Inserts a StaticEntity to the Map and the appropriate List, if possible. /// </summary> /// <param name="e">The StaticEntity to insert</param> /// <param name="x">The X-coordinate of the intended origin Cell</param> /// <param name="y">The Y-coordinate of the intended origin Cell</param> /// <returns>True if insertion was successful, false otherwise</returns> public bool insert(StaticEntity e, int x, int y) { bool worked = map.insert(e, x, y); if (worked) { switch (e.type) { case StaticEntity.Type.Object: objects.Add((ObjectEntity)e); break; case StaticEntity.Type.Resource: resources.Add((ResourceEntity)e); break; case StaticEntity.Type.Building: buildings.Add((Building)e); break; } } return worked; }
/// <summary> /// This method will find the cell closest to 'unit' that 'entity' is currently occupying. /// </summary> /// <param name="unit"></param> /// <param name="entity"></param> /// <returns></returns> public static Cell findClosestCell(Unit unit, StaticEntity se, GameWorld gw) { Cell cell = null; float dis = 10000; short xC = se.orginCell.Xcoord; short yC = se.orginCell.Ycoord; short width = se.width; short height = se.height; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j) <= dis) { cell = gw.map.getCell(xC + i, xC + j); dis = EntityLocController.findDistance(unit.x, unit.y, xC + i, yC + j); } } } return cell; }
/// <summary> /// Adds a static entity to the game. /// </summary> /// <param name="entity">The StaticEntity being added.</param> /// <param name="x">X-Coord of the desired "orgin Cell" of the static entity.</param> /// <param name="y">Y-Coord of the desired "orgin Cell" of the static entity.</param> /// <returns>true if the entity is added successfully, false otherwise.</returns> public bool addEntity(StaticEntity entity, short x, short y) { return locController.addEntity(entity, x, y); }
/// <summary> /// Removes a StaticEntity from the Map /// </summary> /// <param name="e">The StaticEntity to remove</param> public void remove(StaticEntity e) { int x = e.orginCell.Xcoord; int y = e.orginCell.Ycoord; int h = e.height; int w = e.width; for (int j = y; j < y + h; j++) { for (int i = x; i < x + w; i++) { cells[i, j].entity = null; } } }
/// <summary> /// Inserts a StaticEntity to the Map, if possible /// </summary> /// <param name="e">The StaticEntity to add</param> /// <param name="c">The intended origin Cell</param> /// <returns>True if insertion was successful, false if not</returns> public bool insert(StaticEntity e, Cell c) { return insert(e, c.Xcoord, c.Ycoord); }
/* * public functions */ /// <summary> /// Inserts a StaticEntity to the Map, if possible /// </summary> /// <param name="e">The StaticEntity to add</param> /// <param name="x">The X-coordinate of the intended origin Cell</param> /// <param name="y">The Y-coordinate of the intended origin Cell</param> /// <returns>True if insertion was successful, false if not</returns> public bool insert(StaticEntity e, int x, int y) { // check to see if we can actually insert the entity here; if not, return false if (x < 0 || x + e.width > this.width) return false; if (y < 0 || y + e.height > this.height) return false; for (int j = 0; j < this.height; j++) { for (int i = 0; i < this.width; i++) { if (!cells[i, j].isValid) return false; } } // set the appropriate Cell StaticEntity pointers to the given StaticEntity for (int j = 0; j < e.height; j++) { for (int i = 0; i < e.width; i++) { cells[i, j].entity = e; } } // set the given StaticEntity's origin Cell to the given (x, y) coordinate and return true e.setOrginCell(cells[x, y]); return true; }
/// <summary> /// Removes a StaticEntity from the Map and the appropriate List. /// </summary> /// <param name="e">The StaticEntity to remove</param> public void remove(StaticEntity e) { map.remove(e); switch (e.getEntityType()) { case Entity.EntityType.Object: objects.Remove((ObjectEntity)e); break; case Entity.EntityType.Resource: resources.Remove((ResourceEntity)e); break; case Entity.EntityType.Building: buildings.Remove((Building)e); break; } }
/// <summary> /// Copy constructor /// </summary> /// <param name="c">The Cell to copy</param> public Cell(Cell c) { this.entity = c.entity; this.isValid = c.isValid; }
/// <summary> /// Includes a validity parameter /// </summary> /// <param name="isValid">Validity parameter</param> public Cell(bool isValid) { this.isValid = isValid; this.entity = null; }
/* * constructors */ /// <summary> /// Blank constructor /// </summary> public Cell() { this.isValid = true; this.entity = null; }