Beispiel #1
0
 static TileCosts()
 {
     Flat = new TileCosts();
             Flat.costs["Grass"] = 1;
             Flat.costs["Forest"] = 1;
             Flat.costs["Water"] = 1;
             Flat.costs["Mountain"] = 1;
             Flat.costs["Hill"] = 1;
 }
Beispiel #2
0
 public void deselect(int x,int y,int mov,TileCosts costs)
 {
     //deselects all selected (highlighted) tiles.
     List<Tile> tiles = getTilesInMovement(x,y,costs,mov);
     foreach (Tile tile in tiles){
         tile.clearHighlight();
     }
     /*Tile currentTile;
     while(highlighted.Count > 0){
         currentTile = highlighted.First.Value;
         highlighted.RemoveFirst();
         currentTile.clearHighlight();
     }*/
 }
Beispiel #3
0
 //method called by wrapper getTilesInMovement
 private List<Tile> gtim(int x,int y,TileCosts costs, int distance, GameOptions explored,List<Tile> tiles)
 {
     if (distance < 0) return new List<Tile>();
     if (!onMap(x,y)) return new List<Tile>();
     if (tiles.Contains(map[x,y])){
         if (explored.get(x,y) < distance){
             explored.set (x,y,distance);
         }
         else return new List<Tile>();//there was a more efficient route
     }
     else{
         tiles.Add (map[x,y]);
         explored.set(x,y,distance);
     }
     if (onMap(x+1,y))gtim (x+1,y,costs,distance - (int)costs.costs[map[x+1,y].type],explored,tiles);
     if (onMap(x-1,y))gtim (x-1,y,costs,distance - (int)costs.costs[map[x-1,y].type],explored,tiles);
     if (onMap(x,y+1))gtim (x,y+1,costs,distance - (int)costs.costs[map[x,y+1].type],explored,tiles);
     if (onMap(x,y-1))gtim (x,y-1,costs,distance - (int)costs.costs[map[x,y-1].type],explored,tiles);
     return tiles;
 }
Beispiel #4
0
 //returns the remaining movement
 public int searchForTileInRange(int x, int y,Tile tile,int mov, TileCosts costs)
 {
     int final = mov - searchForTile(x,y,tile,0,costs);
     if (final < 0) return 0;
     else return final;
 }
Beispiel #5
0
    //returns the distance to the tile
    public int searchForTile(int x,int y,Tile tile, int mov, TileCosts costs)
    {
        int max = 20;
        //print ("doing " + mov);
        //if (mov < gridDistance(x,tile.x,y,tile.y)) return -100; //failure
        if (mov >= max) return int.MaxValue; //stop looking after some point
        if (tile.Equals(map[x,y])) return mov; //success

        int left,right,up,down,final;
        final = left = right = up = down = int.MaxValue; //high value so it wont be chosen
        if (onMap (x+1,y)) right = gridDistance(x+1,tile.x,y,tile.y) + (int)costs.costs[map[x+1,y].type];
        if (onMap (x-1,y)) left = gridDistance(x-1,tile.x,y,tile.y) + (int)costs.costs[map[x-1,y].type];
        if (onMap (x,y+1)) up = gridDistance(x,tile.x,y+1,tile.y) + (int)costs.costs[map[x,y+1].type];
        if (onMap (x,y-1)) down = gridDistance(x,tile.x,y-1,tile.y) + (int)costs.costs[map[x,y-1].type];

        while(up < int.MaxValue || down < int.MaxValue || left < int.MaxValue || right < int.MaxValue){
            if(up < down && up < right && up < left){
                final = searchForTile(x,y+1,tile,mov + (int)costs.costs[map[x,y+1].type],costs);
                if (final >= max) up = int.MaxValue; //this condition is so it will check the other options if it deadends
                else return final;
            }
            if (down < left && down < right){
                final = searchForTile(x,y-1,tile,mov + (int) costs.costs[map[x,y-1].type],costs);
                if (final >= max) down = int.MaxValue;
                else return final;
            }
            if (left < right){
                final = searchForTile(x-1,y,tile,mov + (int) costs.costs[map[x-1,y].type],costs);
                if (final >= max) left = int.MaxValue;
                else return final;
            }
            if (right < int.MaxValue){
                final = searchForTile(x+1,y,tile,mov + (int) costs.costs[map[x+1,y].type],costs);
                if (final >= max) right = int.MaxValue;
                else return final;
            }
        }
        return final;
    }
Beispiel #6
0
 //unoptimized method to get tiles in a range which excludes tiles from a lower bound.
 //currently excludes the lower radius based on tile distance rather than how much movement it took to get there.
 //I think that's OK?
 public List<Tile> getTilesInRange(int x,int y,TileCosts costs,int lower,int upper)
 {
     List<Tile> tiles = getTilesInMovement(x,y,costs,upper);
     List<Tile> matchedTiles = new List<Tile>();
     foreach(Tile tile in tiles){
         if (gridDistance(tile.x,x,tile.y,y) >= lower){
             matchedTiles.Add(tile);
         }
     }
     return matchedTiles;
 }
Beispiel #7
0
 public List<Tile> getTilesInMovement(int x, int y,TileCosts costs,int distance)
 {
     List<Tile> tiles = new List<Tile>();
     GameOptions options = new GameOptions();
     tiles = gtim (x,y,costs,distance,options,tiles);
     return tiles;
 }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        //these are all 0 by default.
        maxHp += 10;
        hp += 10;
        atk += 7;
        def += 2;
        skl += 6;
        dge += 2;
        lvl += 1;
        exp += 0;
        maxMov += 4;
        mov += 4;
        vis += 5;
        minRnge += 1; //TODO range will probably be moved to an attack skill once skills are added.
        maxRnge += 1;

        controller = Grid.controller;

        moveCosts = new TileCosts();

        if (faction != null && faction.Equals(Grid.turnManager.factions[0])){
            refreshVision();
        }

        actions.Add(new NormalAttack(this));
        actions.Add(new EndTurn(this));
    }
Beispiel #9
0
    /*
    private void findOptionsPartTwo(int x, int y, int move, GameOptions options,int n){ //highlights all tiles that the unit can move to.
        int max = 10;
        print ("depth of : " + n);
        //print (x + ", " + y);
        //print (options.get (x,y));
        if (options.get (x,y) != -1 && options.get (x,y) <= move){
            print ("return point a: " + options.get (x,y));
            return;
        }
        else {
            options.set(x,y,move);
        }
        Tile tile = map[x,y];

        if (x-1 >= 0 && move + (int)TileCosts.Basic.costs[map[x-1,y].type] < max) //check that the next space is in the map and that it does not exceed movement cost.
        {findOptionsPartTwo (x-1,y,move + (int)TileCosts.Basic.costs[map[x-1,y].type], options, n+1);}
        if (x+1 < WIDTH && move + (int)TileCosts.Basic.costs[map[x+1,y].type] < max)
        {findOptionsPartTwo (x+1,y,move + (int)TileCosts.Basic.costs[map[x+1,y].type], options,n+1);}
        if (y-1 >= 0 && move + (int)TileCosts.Basic.costs[map[x,y-1].type] < max)
        {findOptionsPartTwo (x,y-1,move + (int)TileCosts.Basic.costs[map[x,y-1].type], options,n+1);}
        if (y+1 < HEIGHT && move + (int)TileCosts.Basic.costs[map[x,y+1].type] < max)
        {findOptionsPartTwo (x,y+1,move + (int)TileCosts.Basic.costs[map[x,y+1].type], options,n+1);}

        return;
    }
    */
    //method called by wrapper findOptions
    private void fo(int x,int y,TileCosts costs, int distance, GameOptions explored)
    {
        int max = 50;
        if (distance > max) return;
        if (!onMap(x,y)) return;
        if (explored.get (x,y) != -1){ //has been explored.
            if (explored.get(x,y) > distance){
                explored.set (x,y,distance);
            }
            else return;//there was a more efficient route
        }
        else{
            explored.set(x,y,distance);
        }
        if (onMap(x+1,y))fo (x+1,y,costs,distance + (int)costs.costs[map[x+1,y].type],explored);
        if (onMap(x-1,y))fo (x-1,y,costs,distance + (int)costs.costs[map[x-1,y].type],explored);
        if (onMap(x,y+1))fo (x,y+1,costs,distance + (int)costs.costs[map[x,y+1].type],explored);
        if (onMap(x,y-1))fo (x,y-1,costs,distance + (int)costs.costs[map[x,y-1].type],explored);
        return;
    }