Beispiel #1
0
    /*
     *  Function: getTileSubdivisionBoundaries
     *
     *  Parameters: GTile:<tile>, TileSubdivisions:<subdivision>
     *
     *  Returns: Vector2[2]
     *
     *  -Returns a two-element array containing Vector2s to represent the position boundary points of <tile>s <subdivision>
     *
     *  Tiles are subdivided as follows:
     *          +---+---+
     *          |[0]|[1]|
     *          +---+---+
     *          |[2]|[3]|
     *          +---+---+
     *  where:
     *      subdivision [0] = TileSubdivisions.TopLeft
     *      subdivision [1] = TileSubdivisions.TopRight
     *      subdivision [2] = TileSubdivisions.BottomLeft
     *      subdivision [3] = TileSubdivisions.BottomRight
     *
     *  Then the returned array contains the position of the 2 points that delimitate <tile>s <subdivision>, as follows:
     *      <returned>[0] = Top-Left point
     *      <returned>[1] = Bottom-Right point
     *
     */
    public Vector2[] getTileSubdivisionBoundaries(GTile tile, TileSubdivisions subdivision)
    {
        Vector2 tile_origin = tile.getOrigin();

        Vector2[] boundaries = new Vector2[2] {
            Vector2.zero, Vector2.zero
        };

        switch (subdivision)
        {
        case TileSubdivisions.TopLeft:
            boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + GameController.DataSettings.tile_width / 2);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width);
            break;

        case TileSubdivisions.TopRight:
            boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width);
            break;

        case TileSubdivisions.BottomLeft:
            boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + 0);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2);
            break;

        case TileSubdivisions.BottomRight:
            boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + 0);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width / 2);
            break;
        }

        return(boundaries);
    }
Beispiel #2
0
 public Vector2 getCenter(TileSubdivisions subdivision, Vector2 offset)
 {
     if (Mathf.Abs (offset.x) <= GameController.DataSettings.tile_width / 4 && Mathf.Abs (offset.y) <= GameController.DataSettings.tile_width / 4) {
         Vector2 center = getCenter (subdivision);
         return new Vector2 (center.x + offset.x, center.y + offset.y);
     }
     return getCenter (subdivision);
 }
Beispiel #3
0
 public Vector2 getCenter(TileSubdivisions subdivision, Vector2 offset)
 {
     if (Mathf.Abs(offset.x) <= GameController.DataSettings.tile_width / 4 && Mathf.Abs(offset.y) <= GameController.DataSettings.tile_width / 4)
     {
         Vector2 center = getCenter(subdivision);
         return(new Vector2(center.x + offset.x, center.y + offset.y));
     }
     return(getCenter(subdivision));
 }
Beispiel #4
0
 public bool pointBelongsToTileSubdivision(Vector2 point, GTile tile, TileSubdivisions subdivision)
 {
     if (pointBelongsToTile(point, tile))
     {
         Vector2[] boundaries = getTileSubdivisionBoundaries(tile, subdivision);
         if (point.x > boundaries[0].x && point.x <boundaries[1].x && point.y> boundaries[0].y && point.y < boundaries[1].y)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
 public bool containsStructures(TileSubdivisions subdivision)
 {
     List<GStructure> contained_structures = Contained_Objects.structures.all.getDataList () as List<GStructure>;
     for (int i = 0; i < contained_structures.Count; ++i) {
         if(GameData.GData.pointBelongsToTileSubdivision(contained_structures[i].getPosition(), this, subdivision)) {
             return true;
         }
         if((int)contained_structures[i].dimensions.size >= (int) StructureSizes.Medium) {
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
    public bool isBlocked(TileSubdivisions subdivision)
    {
        List <GStructure> contained_structures = Contained_Objects.structures.all.getDataList() as List <GStructure>;

        for (int i = 0; i < contained_structures.Count; ++i)
        {
            if (contained_structures[i].properties.is_blocking)
            {
                // check if blocking item is inside subdivision
                if (GameData.GData.getSubdivisionFromPoint(contained_structures[i].getPosition()) == subdivision)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Beispiel #7
0
    public bool containsStructures(TileSubdivisions subdivision)
    {
        List <GStructure> contained_structures = Contained_Objects.structures.all.getDataList() as List <GStructure>;

        for (int i = 0; i < contained_structures.Count; ++i)
        {
            if (GameData.GData.pointBelongsToTileSubdivision(contained_structures[i].getPosition(), this, subdivision))
            {
                return(true);
            }
            if ((int)contained_structures[i].dimensions.size >= (int)StructureSizes.Medium)
            {
                return(true);
            }
        }
        return(false);
    }
Beispiel #8
0
 /*
  *	Sets the position of this GStructure to tile with indexes <tile_index>, at the specified <subdivision>, offset by <offset>
  *  The GStructure must be of size small.
  */
 public void setPosition(Vector2 tile_index, TileSubdivisions subdivision, Vector2 offset)
 {
     if (dimensions.size == StructureSizes.Small)
     {
         removeFromTile();
         if (placeAtPoint(GameData.GData.getTile(tile_index).getCenter(subdivision, offset)))
         {
             addToTile(GameData.GData.getTile(tile_index));
             reflist_index.subdivision = subdivision;
         }
         else
         {
             Debug.LogError("Failed to place GStructure at " + GameData.GData.getTile(tile_index).getCenter(offset));
         }
     }
     else
     {
         Debug.LogError("GStructure must be of size small.");
     }
 }
Beispiel #9
0
 /*
  *	Sets the position of this GStructure to the center of <tile>, at the specified <subdivision>
  */
 public void setPosition(GTile tile, TileSubdivisions subdivision)
 {
     if (dimensions.size == StructureSizes.Small)
     {
         removeFromTile();
         if (placeAtPoint(tile.getCenter(subdivision)))
         {
             addToTile(tile);
             reflist_index.subdivision = subdivision;
         }
         else
         {
             Debug.LogError("Failed to place GStructure at " + tile.getCenter());
         }
     }
     else
     {
         Debug.LogError("GStructure must be of size small.");
     }
 }
Beispiel #10
0
 public bool isBlocked(TileSubdivisions subdivision)
 {
     List<GStructure> contained_structures = Contained_Objects.structures.all.getDataList () as List<GStructure>;
     for (int i = 0; i < contained_structures.Count; ++i) {
         if(contained_structures[i].properties.is_blocking) {
             // check if blocking item is inside subdivision
             if(GameData.GData.getSubdivisionFromPoint(contained_structures[i].getPosition()) == subdivision) {
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #11
0
 /*
  *	Sets the position of this GStructure to the center of <tile>, at the specified <subdivision>
  */
 public void setPosition(GTile tile, TileSubdivisions subdivision)
 {
     if (dimensions.size == StructureSizes.Small) {
         removeFromTile ();
         if (placeAtPoint (tile.getCenter (subdivision))) {
             addToTile (tile);
             reflist_index.subdivision = subdivision;
         } else {
             Debug.LogError ("Failed to place GStructure at " + tile.getCenter ());
         }
     } else {
         Debug.LogError ("GStructure must be of size small.");
     }
 }
Beispiel #12
0
 /*
  *	Sets the position of this GStructure to tile with indexes <tile_index>, at the specified <subdivision>, offset by <offset>
  *  The GStructure must be of size small.
  */
 public void setPosition(Vector2 tile_index, TileSubdivisions subdivision, Vector2 offset)
 {
     if (dimensions.size == StructureSizes.Small) {
         removeFromTile ();
         if (placeAtPoint (GameData.GData.getTile (tile_index).getCenter (subdivision, offset))) {
             addToTile (GameData.GData.getTile (tile_index));
             reflist_index.subdivision = subdivision;
         } else {
             Debug.LogError ("Failed to place GStructure at " + GameData.GData.getTile (tile_index).getCenter (offset));
         }
     } else {
         Debug.LogError ("GStructure must be of size small.");
     }
 }
Beispiel #13
0
 public bool pointBelongsToTileSubdivision(Vector2 point, GTile tile, TileSubdivisions subdivision)
 {
     if (pointBelongsToTile (point, tile)) {
         Vector2[] boundaries = getTileSubdivisionBoundaries(tile, subdivision);
         if(point.x > boundaries[0].x && point.x < boundaries[1].x && point.y > boundaries[0].y && point.y < boundaries[1].y) {
             return true;
         }
     }
     return false;
 }
Beispiel #14
0
 public Vector2 getCenter(TileSubdivisions subdivision)
 {
     Vector2[] boundaries = GameData.GData.getTileSubdivisionBoundaries(this, subdivision);
     return(new Vector2(boundaries[0].x + Mathf.Abs(boundaries[1].x - boundaries[0].x) / 2, boundaries[0].y + Mathf.Abs(boundaries[1].y - boundaries[0].y) / 2));
 }
Beispiel #15
0
 public Vector2 tileIndexesToWorldPoint(Vector2 tile_indexes, TileSubdivisions subdivision)
 {
     Vector2[] boundaries = getTileSubdivisionBoundaries (getTile(tile_indexes), subdivision);
     return boundaries [0];
 }
Beispiel #16
0
 public Vector2 getCenter(TileSubdivisions subdivision)
 {
     Vector2[] boundaries = GameData.GData.getTileSubdivisionBoundaries (this, subdivision);
     return new Vector2 (boundaries[0].x + Mathf.Abs(boundaries[1].x - boundaries[0].x)/2, boundaries[0].y + Mathf.Abs(boundaries[1].y - boundaries[0].y)/2);
 }
Beispiel #17
0
 public Vector2 tileIndexesToWorldPoint(Vector2 tile_indexes, TileSubdivisions subdivision)
 {
     Vector2[] boundaries = getTileSubdivisionBoundaries(getTile(tile_indexes), subdivision);
     return(boundaries [0]);
 }
Beispiel #18
0
    /*
     *  Function: getTileSubdivisionBoundaries
     *
     *  Parameters: GTile:<tile>, TileSubdivisions:<subdivision>
     *
     * 	Returns: Vector2[2]
     *
     * 	-Returns a two-element array containing Vector2s to represent the position boundary points of <tile>s <subdivision>
     *
     *  Tiles are subdivided as follows:
     * 			+---+---+
     * 			|[0]|[1]|
     * 			+---+---+
     * 			|[2]|[3]|
     * 			+---+---+
     * 	where:
     * 		subdivision [0] = TileSubdivisions.TopLeft
     * 		subdivision [1] = TileSubdivisions.TopRight
     * 		subdivision [2] = TileSubdivisions.BottomLeft
     * 		subdivision [3] = TileSubdivisions.BottomRight
     *
     * 	Then the returned array contains the position of the 2 points that delimitate <tile>s <subdivision>, as follows:
     * 		<returned>[0] = Top-Left point
     * 		<returned>[1] = Bottom-Right point
     *
     */
    public Vector2[] getTileSubdivisionBoundaries(GTile tile, TileSubdivisions subdivision)
    {
        Vector2 tile_origin = tile.getOrigin();
        Vector2[] boundaries = new Vector2[2] { Vector2.zero, Vector2.zero };

        switch (subdivision) {
        case TileSubdivisions.TopLeft:
            boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + GameController.DataSettings.tile_width / 2);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width);
            break;
        case TileSubdivisions.TopRight:
            boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width);
            break;
        case TileSubdivisions.BottomLeft:
            boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + 0);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2);
            break;
        case TileSubdivisions.BottomRight:
            boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + 0);
            boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width / 2);
            break;
        }

        return boundaries;
    }