Inheritance: MonoBehaviour
Ejemplo n.º 1
0
        public tile getTileFromMercator(mercator me, int z)
        {
            px   px   = convert_mercator_to_px(me.me_x, me.me_y, z);
            tile Tile = convert_px_to_tile(px.px_x, px.px_y, z);

            return(Tile);
        }
Ejemplo n.º 2
0
 bool depthSearch(int depth)
 {
     if (outOfBounds())
     {
         return(false);
     }
     checkedTiles.Add(cursor);
     if (placedTiles[cursor.x, cursor.y] != null)
     {
         return(false);
     }
     if (depth > 0)
     {
         tile current = cursor;
         for (int i = 0; i < 6; i++)
         {
             cursor = current;
             MoveCursor(i);
             if (checkedTiles.Contains(cursor))
             {
                 continue;
             }
             bool b = depthSearch(depth - 1);
             if (b)
             {
                 return(b);
             }
         }
         return(false);
     }
     return(true);
 }
    public bool isInBoundsByAxis(ref Vector3 position, List <bool> travableTiles)
    {
        if (position.x < minX)
        {
            return(false);
        }
        if (position.x > maxX)
        {
            return(false);
        }
        if (position.z < minZ)
        {
            return(false);
        }
        if (position.z > maxZ)
        {
            return(false);
        }

        //checks if the type of the tile at index is true from the object's travableTile list
        //it finds the tile at the position, gets the tType and cast it as int to see if true in list
        tile atTile = getToTileByPosition(position);

        if (travableTiles[(int)atTile.tType])
        {
            position = atTile.pos;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 4
0
 public void addinstance()
 {
     tile[]  tiles  = new tile[64];
     piece[] pieces = new piece[32];
     for (int i = 0; i < 64; i++)
     {
         GameObject x = chessboard.GetComponent <chessboard> ().tiles [i];
         tiles [i].a   = x;
         tiles [i].top = x.GetComponent <tileprops> ().top;
     }
     for (int i = 0; i < 32; i++)
     {
         GameObject x = chessboard.GetComponent <chessboard> ().pieces [i];
         pieces [i].a = x;
         if (x != null)
         {
             pieces [i].tile      = x.GetComponent <chesspiece> ().tile;
             pieces [i].tem       = x.transform.position;
             pieces [i].row       = x.GetComponent <chesspiece> ().row;
             pieces [i].col       = x.GetComponent <chesspiece> ().col;
             pieces [i].movecount = x.GetComponent <chesspiece> ().movecount;
             pieces [i].ptype     = x.GetComponent <chesspiece> ().ptype;
             pieces [i].pcolor    = x.GetComponent <chesspiece> ().pcolour;
             pieces [i].wkilled   = x.GetComponent <chesspiece> ().tile.GetComponent <tileprops> ().killmove;
             if (pieces [i].wkilled == true)
             {
                 Debug.Log("As");
             }
         }
     }
     boardinstances.Add(tiles);
     pieceinstance.Add(pieces);
     movecount++;
 }
Ejemplo n.º 5
0
 public void addTile(int x, int y, bool enemy)
 {
     tile newTile = new tile();
       newTile.tilePosition = new Vector3(x * 1.05f, (-y + (x % 2) * .5f) * 1.12f, 0);
       newTile.battle = enemy;
       generatedMap.Add(newTile.tilePosition, newTile);
 }
Ejemplo n.º 6
0
    }    // call this in editor time after everything is done... and calculated;

    public void loadValues()
    {
        tiles = new tile[(width * overSampling), (height * overSampling)];
        tile[] temp = new tile[tilesStorage.Count];
        tilesStorage.CopyTo(temp);
        foreach (tile t in temp)
        {
            tiles[t.x, t.z] = t;
            //Debug.Log("While Copy t.type is"+t.type+"   and tiles.type is"+tiles[t.x, t.z].type);
        }

        /*
         * for (int x = 0; x < tiles.GetLength(0); x++) {
         *      for (int z = 0; z < tiles.GetLength(1); z++) {
         *
         *              tiles[x,z] = tilesStorage[x+z*width];
         *      }
         *
         * }*/

        //for (int x = 0; x < tiles.GetLength(0); x++) {
        //		for (int z = 0; z < tiles.GetLength(1); z++) {
        //			Debug.Log(tiles[x,z].type);
        //		}

        //	}
    }    //call this in run time to load the data into the tiles agains
Ejemplo n.º 7
0
 void SetupBlankBoard(int cols, int rows)
 {
     owner        = new int[cols, rows];
     tile_type    = new type[cols, rows];
     remaining    = new int[cols, rows];
     defense_type = new type[cols, rows];
     defense      = new int[cols, rows];
     tiles        = new tile[cols, rows];
     for (int x = 0; x != cols; ++x)
     {
         for (int y = 0; y != rows; ++y)
         {
             owner[x, y]        = -1;
             defense_type[x, y] = tile_type[x, y] = type.Empty;
             remaining[x, y]    = 0;
             defense[x, y]      = 0;
             tile nt = Instantiate <tile>(tilePrefab);
             //nt.GetComponent<Transform>().position = new Vector3((float)x, (float)y, 0f);
             nt.GetComponent <Transform>().position = new Vector3((float)x, (float)y + 10.0f + 10.0f * Random.value, 0f);
             nt.GetComponent <Rigidbody>().velocity = new Vector3(0f, -20.0f, 0f);
             nt.col      = x;
             nt.row      = y;
             nt.owner    = -1;
             tiles[x, y] = nt;
         }
     }
 }
Ejemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        instance = this;

        Vector3 spawnPosition = startPoint.position;

        for (int i = 0; i < tilesToPreSpawn; i++)
        {
            spawnPosition -= tilePrefab.startPoint.localPosition;
            tile spawnedTile = Instantiate(tilePrefab, spawnPosition, Quaternion.identity) as tile;
            // if(tilesWithNoObstaclesTmp > 0)
            // {
            //     spawnedTile.DeactivateAllObstacles();
            //     tilesWithNoObstaclesTmp--;
            // }
            // else
            // {
            spawnedTile.ActivateRandomObstacle();
            // }

            spawnPosition = spawnedTile.endPoint.position;
            spawnedTile.transform.SetParent(transform);
            spawnedTiles.Add(spawnedTile);
        }
    }
Ejemplo n.º 9
0
    public void init()
    {
        if (!finishTile)
        {
            finishTile = Instantiate(finishPrefab);
        }

        foreach (GameObject c in checkpoints)
        {
            Destroy(c);
        }
        checkpoints.Clear();


        loadTiles();
        //CreateGrid();
        gridCollision();
        if (grid[cursor.x, cursor.y].magnitude < 0)
        {
            do
            {
                cursor = new tile(Random.Range(0, gridSize), Random.Range(0, gridSize));
            }while(grid[cursor.x, cursor.y].magnitude < 0);
        }

        for (int i = 0; i < 5; i++)
        {
            AutoTile();
            tileHistory[i].GetComponent <trackTile>().fadeStart = false;
        }
        cullTrack = gameManager.self.gameType == gameManager.gameTypes.TRACKCULLING;
    }
Ejemplo n.º 10
0
    public void FindSelectableTiles()
    {
        ComputeAdjacencyLists(JumpHeight, null);
        GetCurrentTile();
        Queue <tile> process = new Queue <tile>();

        process.Enqueue(currentTile);
        currentTile.visited = true;


        while (process.Count > 0)
        {
            tile t = process.Dequeue();
            selectableTiles.Add(t);
            t.selectable = true;
            if (t.distance < move)
            {
                foreach (tile tile in t.adjacencyList)
                {
                    if (!tile.visited)
                    {
                        tile.parent   = t;
                        tile.visited  = true;
                        tile.distance = 1 + t.distance;
                        process.Enqueue(tile);
                    }
                }
            }
        }
    }
Ejemplo n.º 11
0
 public void add_tile(tile t)
 {
     if (t != null)
     {
         tiles.Add(t);
     }
 }
Ejemplo n.º 12
0
    public List <tile> GetNeighbor(tile cur)
    {
        List <tile> p   = new List <tile>();
        Vector2     pos = cur.getPos();
        int         x   = Mathf.RoundToInt(pos.x);
        int         y   = Mathf.RoundToInt(pos.y);

        if (y + 1 <= fieldHeight)
        {
            p.Add(tileField[(y + 1) * fieldWidth + x]);
        }
        if (y - 1 >= 0)
        {
            p.Add(tileField[(y - 1) * fieldWidth + x]);
        }
        if (x + 1 <= fieldWidth)
        {
            p.Add(tileField[y * fieldWidth + (x + 1)]);
        }
        if (x - 1 >= 0)
        {
            p.Add(tileField[y * fieldWidth + (x - 1)]);
        }

        return(p);
    }
Ejemplo n.º 13
0
    bool MoveStack(Vector2 pos)
    {
        // check in bounds
        if (!CheckInBounds(pos))
        {
            return(false);
        }
        else
        {
            tile targetTile = null;

            // find tile in pos
            foreach (tile t in tileList)
            {
                if (t.tilePos == pos)
                {
                    targetTile = t;

                    // highlight tile
                    selectedTileTransform = (Transform)Instantiate(highlightTile, new Vector3(pos.x * tileSize, pos.y * tileSize, 0), Quaternion.identity);
                    selectedTile          = t;
                    break;
                }
            }

            // are there more than one tokens on the stack
            if (targetTile.tokens.Count < 1)
            {
                return(false);
            }
        }
        return(true);
    }
Ejemplo n.º 14
0
    bool noOneCloseEnough(int x, int y)
    {
        bool isOK = true;

        for (int i = x - 2; i <= x + 2; i++)
        {
            for (int j = y - 2; j <= y + 2; j++)
            {
                if ((x >= 0) && (x < WIDTH) && (y >= 0) && (y < HEIGHT))
                {
                    tile t = getTileXY(i, j);
                    if ((t.whichType == tileTypes.ROAD) && (t.tStates != tileStates.FREE))
                    {
                        isOK = false;
                        break;
                    }
                }
            }
            if (isOK == false)
            {
                break;
            }
        }

        return(isOK);
    }
Ejemplo n.º 15
0
    tile[,] tiles; //2D array representation of all tile sin the world

    /**
     * Called on start, sets up the world making a size x size grid of water tiles
     * No PCG here, always runs teh same
     */
    void Start()
    {
        tiles = new tile[size, size];
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                tiles[i, j] = new tile(Enums.TileID.sea, i, j);
            }
        }

        BuildContinent();
        BuildContinent2();
        for (int i = 0; i < montNumRanges; i++)
        {
            BuildMountains();
        }

        SmoothContinent();

        for (int i = 0; i < riverNum; i++)
        {
            SpawnRiver();
        }
        setTundra();
        setIce();
        Camera.GetComponent <CameraScript>().setup(size);
        SetCoasts();
        GenerateWorld();
    }
        static Tuple <tile, float, int, Vector3[]> getClosestTile(List <tile> tiles, Vector3 mousePos)
        {
            tile closest = null;

            Vector3[] closestEdgeVec = new Vector3[2];
            int       closestEdge    = 0;
            float     minDist        = Mathf.Infinity;

            foreach (tile t in tiles)
            {
                float dist = Vector2.Distance(t.centre, mousePos);
                if (dist < minDist)
                {
                    closest = t;
                    minDist = dist;
                }
            }

            float minDistToEdge = Mathf.Infinity;

            for (int i = 0; i < closest.edges.Count; ++i)
            {
                float distToEdge = Vector2.Distance(helperFunctionsClass.edgeCentre(closest.edges[i]), mousePos);

                if (distToEdge < minDistToEdge)
                {
                    minDistToEdge  = distToEdge;
                    closestEdgeVec = closest.edges[i];
                    closestEdge    = i + 1;
                }
            }

            return(new Tuple <tile, float, int, Vector3[]>(closest, minDist, closestEdge, closestEdgeVec));
        }
Ejemplo n.º 17
0
    //
    //  read_file - pre-condition : filename exists and is in the correct format.
    //              post-condition: breakout data structures are initialised and
    //                              if successful level is returned else 0 is returned.
    //

    private int read_file(string filename, int level)
    {
        int          row = 0;
        FileInfo     f   = new FileInfo(filename);
        StreamReader r   = f.OpenText();
        string       line;

        do
        {
            line = r.ReadLine();
            process_line(line, row);
            row++;
        } while (line != null);

        while (row < max_row)
        {
            for (int col = 0; col < max_col; col++)
            {
                grid[row, col] = new tile();
            }

            row++;
        }
        return(level);
    }
Ejemplo n.º 18
0
 // checsks if child is on the same team
 // add tile to needy neighbor list
 // updates totalt percent need
 //checks if most needy tile
 void howNeedy(tile tempTile, tile currentTile, List <tile> needyNeighbors, List <float> needs, ref float totalPercentNeed,
               ref float mostNeedy)
 {
     if (tempTile.tileType == currentTile.tileType &&
         tempTile.currentEnergy < currentTile.currentEnergy && tempTile.currentEnergy < tempTile.maxEnergy)
     {
         // add tile to list of needy neighbros
         needyNeighbors.Add(tempTile);
         //calculate %need
         float tempP = (tempTile.maxEnergy - tempTile.currentEnergy) /
                       tempTile.maxEnergy;
         ///add to list of needs
         needs.Add(tempP);
         // add to total percent need
         totalPercentNeed += tempP;
         //Debug.Log ("total Percent need : " + totalPercentNeed);
         // check if most need tile
         if (tempP > mostNeedy)
         {
             mostNeedy = tempP;
             //mostNeedyTile = needs.Count - 1;
         }
     }
     return;
 }
Ejemplo n.º 19
0
    //find a singular zone; subfunction of zone
    void find_zone(int y, int x, Zone z)
    {
        tile t = maze [y, x];

        if (!t.get_touch())
        {
            t.set_zone(z);
            Debug.Log(t.get_zone().get_id());
            t.touch(true);
            z.add_tile(t);

            if (t.get_northwall() == tile.Wall.none)
            {
                find_zone(y - 1, x, z);
            }
            if (t.get_westwall() == tile.Wall.none)
            {
                find_zone(y, x - 1, z);
            }
            if (t.get_eastwall() == tile.Wall.none)
            {
                find_zone(y, x + 1, z);
            }
            if (t.get_southwall() == tile.Wall.none)
            {
                find_zone(y + 1, x, z);
            }
        }
    }
Ejemplo n.º 20
0
 public solver(field field, tile start, tile end)
 {
     this.field = field;
     this.start = start;
     this.end   = end;
     visited    = new List <tile>();
 }
Ejemplo n.º 21
0
    public Vector3 checkToRun(float range)
    {
        foreach (unfreindlyScript enemy in unFriendlyList)
        {
            Vector3 dist = new Vector3(duckTransform.position.x - enemy.unitTransform.position.x, 0, duckTransform.position.z - enemy.unitTransform.position.z);
            if (dist.magnitude < range)
            {
                playerActionSys.isHoldingDuck = false;
                //find a tile to move to
                tile atTile = tilingSys.getToTileByPosition(duckTransform.position);

                for (int row = -1; row < 2; row++)
                {
                    for (int col = -1; col < 2; col++)
                    {
                        tile adjTile = tilingSys.getTilebyIndex((int)atTile.index2.x + col, (int)atTile.index2.y + row);
                        if (duckBehaviourSys.traverseData.traversePossibilities[(int)adjTile.tType] && adjTile.walkable && !(col == 0 && row == 0))
                        {
                            return(adjTile.pos + new Vector3(0, 1, 0));
                        }
                    }
                }
                return(playerTransform.position);
            }
        }

        return(Vector3.zero);
    }
Ejemplo n.º 22
0
    bool PlaceToken(Vector2 pos)
    {
        // find right tile
        tile targetTile = null;

        foreach (tile t in tileList)
        {
            if (t.tilePos == pos)
            {
                targetTile = t;
                break;
            }
        }

        // check if legal to place
        if (targetTile.stack < 4)
        {
            int       yOffset     = -3 + targetTile.stack * 2;
            Transform tokenObject = (Transform)Instantiate(discs[player - 1], new Vector3(pos.x * tileSize, pos.y * tileSize + yOffset, 0), Quaternion.identity);
            token     tok         = new token();
            tok.tokenObject = tokenObject;
            tok.ownerPlayer = player;
            tok.tokenObject.transform.FindChild("sprite").GetComponent <SpriteRenderer>().sortingOrder = targetTile.stack;

            targetTile.tokens.Add(tok);
            targetTile.stack += 1;
            return(true);
        }
        return(false);
    }
Ejemplo n.º 23
0
    private void UpdateMaterials(tile t, shadowMapRenderer r)
    {
        foreach (GameObject o in t.Objs)
        {
            MeshRenderer renderer = o.GetComponent <Renderer>() as MeshRenderer;
            if (renderer)
            {
                Material[] materials = renderer.sharedMaterials;
                foreach (Material mat in materials)
                {
                    if (mat.HasProperty("_ShadowMap"))
                    {
                        //Debug.Log(mrenderer.ReflectionTexture);
                        mat.SetTexture("_ShadowMap", r.shadowMap);
                    }
                    Matrix4x4 shadowMatrix = r.shadowCamera.projectionMatrix;

                    if (SystemInfo.usesReversedZBuffer)
                    {
                        shadowMatrix [2, 0] = -shadowMatrix [2, 0];
                        shadowMatrix [2, 1] = -shadowMatrix [2, 1];
                        shadowMatrix [2, 2] = -shadowMatrix [2, 2];
                        shadowMatrix [2, 3] = -shadowMatrix [2, 3];
                    }
                    shadowMatrix *= r.shadowCamera.worldToCameraMatrix;
                    mat.SetMatrix("_shadowMatrix", shadowMatrix);
                }
            }
        }
    }
Ejemplo n.º 24
0
    void initialize()
    {
        Light l = GetComponent <Light> ();

        if (!l)
        {
            return;
        }
        if (l.type != LightType.Directional)
        {
            return;
        }


        _tiles             = new List <tile> ();
        _renderers         = new List <shadowMapRenderer> ();
        _curTilesRenderers = new Dictionary <int, int> ();


        Bounds bb = GetBoundingBoxofSelectedObjects();

        _numX = Mathf.CeilToInt(bb.extents.x * 2 / tileSize.x);
        _numY = Mathf.CeilToInt(bb.extents.z * 2 / tileSize.y);

        _startX = (float)(bb.center.x - tileSize.x * 0.5 * _numX);
        _startY = (float)(bb.center.z - tileSize.y * 0.5 * _numY);

        _height = (float)bb.center.y;
        //initialize tiles
        for (int j = 0; j < _numY; ++j)
        {
            for (int i = 0; i < _numX; ++i)
            {
                float   posX = (float)(_startX + tileSize.x * 0.5 * (i + 1));
                float   posY = (float)(_startY + tileSize.y * 0.5 * (j + 1));
                Vector2 pos  = new Vector2(posX, posY);
                tile    t    = new tile(pos, tileSize);
                _tiles.Add(t);
            }
        }
        //initialize tiles objects list
        MeshRenderer[] renderers = FindObjectsOfType(typeof(MeshRenderer)) as MeshRenderer[];
        for (int i = 0; i < renderers.Length; ++i)
        {
            if (m_ShadowLayers == (m_ShadowLayers | 1 << renderers[i].gameObject.layer))
            {
                Bounds  b     = renderers[i].bounds;
                Vector2 opos  = new Vector2(b.center.x, b.center.z);
                Vector2 osize = new Vector2(b.extents.x * 2, b.extents.z * 2);
                foreach (tile it in _tiles)
                {
                    if (it.Contain(opos, osize))
                    {
                        it.Objs.Add(renderers [i].gameObject);
                    }
                }
            }
        }
    }
Ejemplo n.º 25
0
        public tile convert_bingTile_to_baidu(int x, int y, int z)
        {
            var  quadkey = tileToQuadkey(x, y, z);
            var  merca   = BingTest(quadkey);
            tile tie     = getTileFromMercator(merca, z);

            return(tie);
        }
Ejemplo n.º 26
0
 public void ComputeAdjacencyLists(float jumpHeight, tile target)
 {
     foreach (GameObject tile in tiles)
     {
         tile t = tile.GetComponent <tile>();
         t.FindNeighbors(JumpHeight, target);
     }
 }
Ejemplo n.º 27
0
 void OnTriggerEnter(Collider collider)
 {
     if (collider.CompareTag("tile"))
     {
         _cursorTile.position = collider.transform.position;
         _previousTile        = collider.gameObject.GetComponent <tile>();
     }
 }
Ejemplo n.º 28
0
 public static bool isWithinMiningRange(tile Tile)
 {
     if (Vector2.Distance(Tile.currentRectangle.Location.ToVector2(), gameWorld.myCharacter.currentRectangle.Location.ToVector2()) < miningRange)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 29
0
 public void FindNeighbors(float jumpHeight, tile target)
 {
     Reset();
     CheckTile(Vector3.forward, jumpHeight, target);
     CheckTile(-Vector3.forward, jumpHeight, target);
     CheckTile(Vector3.right, jumpHeight, target);
     CheckTile(-Vector3.right, jumpHeight, target);
 }
Ejemplo n.º 30
0
        public tile getTile(double lng, double lat, int z)
        {
            mercator point = convert_coord_to_mercator(lng, lat);
            px       px    = convert_mercator_to_px(point.me_x, point.me_y, z);
            tile     Tile  = convert_px_to_tile(px.px_x, px.px_y, z);

            return(Tile);
        }
Ejemplo n.º 31
0
 public void updateAdjacentTiles(tile t)     // update adjacent tiles AND this tile
 {
     t.update();
     t.getAdjacent(1, 0).update();
     t.getAdjacent(-1, 0).update();
     t.getAdjacent(0, 1).update();
     t.getAdjacent(0, -1).update();
 }
Ejemplo n.º 32
0
        private Dictionary<string, tile> GetTileMap(string tmfile, string widfile)
        {
            string tSep = Properties.Settings.Default.TilemapSep;
            bool oldmap = false;
            int oldlen = 0;

            List<int> widths = GetWidths(widfile);

            Dictionary<string, tile> tm = new Dictionary<string, tile>();
            if (File.Exists(tmfile))
            {
                using (StreamReader sr = new StreamReader(tmfile))
                {
                    int row = 0;
                    while (!sr.EndOfStream)
                    {
                        string l = sr.ReadLine();
                        //detect if the seperator exists...
                        if (l.Contains(tSep))
                        {//get the new tilemap format
                            string[] lA = l.Split(new string[] {tSep}, StringSplitOptions.None);
                            for (int col = 0; col < lA.Length; col++)
                            {
                                tile t = new tile();
                                t.col = col;
                                t.row = row;
                                t.width = GetWid(widths, col, row);
                                if (!tm.ContainsKey(lA[col]))
                                {
                                    tm.Add(lA[col], t);
                                }
                            }
                        }
                        else
                        {//old tilemap
                            if (oldlen == 0)
                            {
                                oldmap = true;
                                oldlen = l.Length;
                            }
                            for (int col = 0; col < l.Length; col++)
                            {
                                tile t = new tile();
                                t.col = col;
                                t.row = row;
                                if (!tm.ContainsKey(l[col].ToString()))
                                {
                                    tm.Add(l[col].ToString(), t);
                                }
                                else
                                {
                                    int cinc = 0;
                                    string chk = l[col].ToString();
                                    while (tm.ContainsKey(chk))
                                    {
                                        cinc++;
                                        chk = l[col].ToString() + cinc;
                                    }
                                    tm.Add(chk, t);
                                }
                            }
                        }
                        row++;
                    }
                }
            }
            if (oldmap)
            {//save in the new format... Will only need this once.
                using (StreamWriter sw = new StreamWriter(tmfile, false))
                {
                    int pos = 0;
                    foreach (KeyValuePair<string, tile> t in tm)
                    {
                        if (pos == oldlen-1)
                        {
                            sw.WriteLine(t.Key);
                            pos = -1;
                        }
                        else
                        {
                            sw.Write(t.Key + tSep);
                        }
                        pos++;
                    }
                }
            }
            return tm;
        }
Ejemplo n.º 33
0
 void RemoveBenefitsOfOldType(tile _tile)
 {
     if (tileToConvert.thisTileType == tile.tileType.structure_mining)
     {
         countMining -= 1;
         mineTiles.Remove(_tile);
         UpdateMinableTilesList();
     }
     else if (tileToConvert.thisTileType == tile.tileType.structure_factory) { countFactory -= 1; RecalculateCosts(); }
     else if (tileToConvert.thisTileType == tile.tileType.structure_mill) { countMill -= 1; RecalculateCosts(); }
     else if (tileToConvert.thisTileType == tile.tileType.structure_residence) { countResidence -= 1; }
     else if (tileToConvert.thisTileType == tile.tileType.structure_community) { countCommunity -= 1; }
     else if (tileToConvert.thisTileType == tile.tileType.structure_gemMount) { inventoryGems -= 1; }
     else if (tileToConvert.thisTileType == tile.tileType.structure_sonar || tileToConvert.thisTileType == tile.tileType.structure_sonar_positive) { sonarList.Remove(_tile); }
 }
    // This will be changed since we won't be satisfied with just a hexagon in the future
    // But the formula for locating tiles is useful!
    void generateHexMap(int size)
    {
        board = new tile[size * 2-1, size * 2-1];
        for (int i=0; i<size * 2-1; i++) {
            for (int j=0; j<size * 2-1; j++) {
                board[i,j]=new tile();
            }
        }
        Transform boardHolder = new GameObject ("Board").transform;
        Vector3 pieceposition;
        for(int i=1;i<size*2;i++){
            for(int j=1;j<2*size-Mathf.Abs(size-i);j++){

                //crazy math formulas for the actuall positions, don't delve in if you value your life!
                pieceposition= new Vector3 (tileSize*(Mathf.Abs(size-i)*0.5f+j-size),tileSize*ratio*(i-size),0f);
                GameObject instance = Instantiate(gameTile,pieceposition,Quaternion.identity) as GameObject;
                inputTile tileInfo = instance.GetComponent<inputTile>();

                //the same craziness here
                tileInfo.tilePosition=new Vector2(j-0.5f*(size+i-Mathf.Abs(i-size)),i-size);
                instance.transform.SetParent (boardHolder);
            }
        }
    }
Ejemplo n.º 35
0
 // look above and find the top of the current stack of blocks (the first non-empty block)
 tile FindTileAtTop(tile _tile)
 {
     tile _result = _tile.myNeighborUp;
     while (_result.myNeighborUp.thisTileType != tile.tileType.empty)
     {
         _result = _result.myNeighborUp;
     }
     return _result;
 }
Ejemplo n.º 36
0
 // set neighbors for a tile in all directions
 void FindTileNeighbors(tile t)
 {
     foreach (tile t2 in allTiles)
     {
         if (t.thisTileY + 1 == t2.thisTileY && t.thisTileX == t2.thisTileX) { t.myNeighborUp = t2; }
         else if (t.thisTileY - 1 == t2.thisTileY && t.thisTileX == t2.thisTileX) { t.myNeighborDown = t2; }
         else if (t.thisTileX + 1 == t2.thisTileX && t.thisTileY == t2.thisTileY) { t.myNeighborRight = t2; }
         else if (t.thisTileX - 1 == t2.thisTileX && t.thisTileY == t2.thisTileY) { t.myNeighborLeft = t2; }
     }
 }
Ejemplo n.º 37
0
 // Default implementation
 int FindBaseStrength(tile _tile)
 {
     return FindBaseStrength(_tile, null, -99);	// "-99" is the signal for "null" in this case
 }
Ejemplo n.º 38
0
 // Default implementation
 int FindBaseStrength(tile _tile, tile _tileToRemove)
 {
     return FindBaseStrength(_tile, _tileToRemove, -99);	// "-99" is the signal for "null" in this case
 }
Ejemplo n.º 39
0
    // Show contextual options for clicked tile
    void ContextOptions(tile _tile)
    {
        decisionPossibilities = new List<string>();

        // add options available for all (or most) structure types
        decisionPossibilities.Add (decisionTextCancel);
        decisionPossibilities.Add (decisionTextDestroy);
        decisionPossibilities.Add (decisionTextRevert);

        // add re-enforcement options for all structure types
        if (_tile.levelOfReenforcement == 0)
        {
            decisionPossibilities.Add (decisionTextReenforce);
        }
        else if (_tile.levelOfReenforcement == 1)
        {
            decisionPossibilities.Add (decisionTextUnReenforce);
            decisionPossibilities.Add (decisionTextReenforce2);
        }
        else if (_tile.levelOfReenforcement == 2)
        {
            decisionPossibilities.Add (decisionTextUnReenforce);
        }

        // add options to specific structure types
        if (_tile.thisTileType == tile.tileType.structure)					// if this is an empty structure
        {
            decisionPossibilities.Add (decisionTextResidence);					// to add Residence
            decisionPossibilities.Add (decisionTextMining);						// to add Mining
            if (inventoryGems > 0) { decisionPossibilities.Add (decisionTextMountGem); }			// to add a Gem Mount (if you have any gems)
            decisionPossibilities.Remove (decisionTextRevert);					// remove "revert" for this one (since it wouldn't do anything)
        }

        else if (_tile.thisTileType == tile.tileType.structure_residence)	// if this is a residence
        {
            decisionPossibilities.Add (decisionTextCommunity);					// convert to community center
        }
        else if (_tile.thisTileType == tile.tileType.structure_mining)		// if this is a mining structure
        {
            decisionPossibilities.Add (decisionTextFactory);
            decisionPossibilities.Add (decisionTextMill);
        }
        else if (_tile.thisTileType == tile.tileType.structure_mill)		// if this is a mill
        {
        }
        else if (_tile.thisTileType == tile.tileType.structure_factory)		// if this is a factory
        {
            decisionPossibilities.Add(decisionTextSonar);
        }
        else if (_tile.thisTileType == tile.tileType.structure_community)	// if this is a community
        {
        }
        else if (_tile.thisTileType == tile.tileType.structure_gemMount)	// if this is a gem mount
        {
        }
        else if (_tile.thisTileType == tile.tileType.structure_sonar || _tile.thisTileType == tile.tileType.structure_sonar_positive)	// if this is a sonar
        {
        }
        else if (_tile.thisTileType == tile.tileType.dirt)					// if this is dirt
        {
            decisionPossibilities.Remove (decisionTextDestroy);
            decisionPossibilities.Remove (decisionTextRevert);
        }
        else if (_tile.thisTileType == tile.tileType.rock)					// if this is rock
        {
            decisionPossibilities.Remove (decisionTextDestroy);
            decisionPossibilities.Remove (decisionTextRevert);
        }

        // Re-arrange options (make sure cancel is last, at least)
        if (decisionPossibilities.Contains(decisionTextCancel))
        {
            decisionPossibilities.Remove(decisionTextCancel);
            decisionPossibilities.Add(decisionTextCancel);
        }

        makingDecision = true;
        isMenuOpen = true;
        tileToConvert = _tile;
    }
Ejemplo n.º 40
0
    // look below the structure and find the strength of the supporting tiles
    int FindBaseStrength(tile _tile, tile _tileToRemove, int _valueToReplace)
    {
        int _result = 0;
        tile _tileInQuestion = _tile.myNeighborDown;					// Start looking down at blocks
        while (_tileInQuestion.thisTileType != tile.tileType.empty)		// Until you hit an empty block
        {
            if (_tileInQuestion == _tileToRemove && _valueToReplace == -99) { break; }		// If you find the optional "tileToRemove", then stop there and consider that you've reached the bottom
            else if (_tileInQuestion == _tileToRemove) { _result += _valueToReplace; }		// If you find the optional "tileToRemove" and you have a "valueToReplace", use that value in its place
            else if (_tileInQuestion.thisTileType == tile.tileType.dirt)		// If it's dirt, add the strength of dirt
            {
                _result += strengthOfDirt;
            }
            else if (_tileInQuestion.thisTileType == tile.tileType.rock)	// If it's rock, add the strength of rock
            {
                _result += strengthOfRock;
            }
            else if (_tileInQuestion.structureTypesNonLoadBearing.Contains(_tileInQuestion.thisTileType))	// If it's a non-load bearing structure, add that strength
            {
                _result += strengthOfStructures;
            }
            else if (_tileInQuestion.thisTileType == tile.tileType.bedrock)						// If you hit "bedrock", then you're good for sure, just return positive
            {
                return 9999;
            }

            if (_tileInQuestion == _tileToRemove)		// if this is the structure being removed/replaced, don't add in its re-enforcement
            {
            }
            else if (_tileInQuestion.levelOfReenforcement == 1 )			// if the structure is re-enforced, add that strength in
            {
                _result += strengthOfStructures_reenforced;
            }
            else if (_tileInQuestion.levelOfReenforcement == 2)		// if the structure is double re-enforced, add that strength in
            {
                _result += strengthOfStructures_reenforced_2;
            }

            if (_tileInQuestion.myNeighborDown != null)						// As long as there's a block below, move on to the next one to repeat the loop
            {
                _tileInQuestion = _tileInQuestion.myNeighborDown;
            }
            else { break; }
            if (_result < buildingMaxPressure) { return -1; }	// If at any point you reach more than the "buildingMaxPressure", fail
        }
        return _result;
    }
Ejemplo n.º 41
0
    // Convert structure based on context option chosen
    void ContextOptionChoice(tile _tile, string choice)
    {
        if (choice == decisionTextCancel) { return; }				// If you chose cancel, then don't do anything
        else
        {

            // check if action is possible (unless you're just re-enforcing or un-re-enforcing)
            if (choice == decisionTextReenforce || choice == decisionTextReenforce2 || choice == decisionTextUnReenforce) { }
            else if (tileToConvert.thisTileType == tile.tileType.structure_residence)
            {
                if (!VerifyMeetPrereqs(0,0,0,-1,0) && choice != decisionTextCommunity) { CannotPerformAction("Cannot remove residence - there won't be enough for the workplaces\n(remove mines, or build another residence somewhere else)"); return; }
            }
            else if (tileToConvert.thisTileType == tile.tileType.structure_community)
            {
                if (!VerifyMeetPrereqs(0,0,0,0,-1)) { CannotPerformAction("Cannot remove community - there won't be enough for the residences\n(you need a community to sustain every " + ResidencesPerCommunity + " residences)"); return; }
            }
            else if (choice == decisionTextMining)
            {
                if (!VerifyMeetPrereqs(1,0,0,0,0)) { CannotPerformAction("Cannot build mine - not enough residences\n(1 residence sustains " + MinesPerResidence + " mine(s).)"); return; }
            }
            else if (choice == decisionTextResidence)
            {
                if (!VerifyMeetPrereqs(0,0,0,1,0)) { CannotPerformAction("Cannot build residence - not enough communities\n(you need a community to sustain every " + ResidencesPerCommunity + " residences)"); return; }
            }

            // Check costs and other requirements and perform type change
            if (choice == decisionTextDestroy)
            {
                if (!_tile.structureTypes.Contains(_tile.myNeighborUp.thisTileType))		// if the block above me is not a structure
                {
                    if (FindBaseStrength(FindTileAtTop(_tile), _tile) >= 0)					// make sure it's not structurally necessary before destroying it
                    {
                        RemoveBenefitsOfOldType(_tile);
                        _tile.ChangeTileType(tile.tileType.empty);			// set to empty
                        inventoryDirt -= costToDestroyStructure;							// pay resources
                    }
                    else { CannotPerformAction("Cannot destroy structure - structures rely on this block"); }
                }
                else { CannotPerformAction("Cannot destroy structure - structures rely on this block"); }
            }
            else if (choice == decisionTextRevert)											// revert to empty
            {
                RemoveBenefitsOfOldType(_tile);
                _tile.ChangeTileType (tile.tileType.structure);			// set to empty
                inventoryDirt -= costToRemodel;											// pay resources
            }
            else if (choice == decisionTextReenforce && inventoryDirt - costOfStructure_reenforced >= 0)					// re-enforce structure 1
            {
                _tile.prop_levelOfReenforcement++;
                inventoryDirt -= costOfStructure_reenforced;
            }
            else if (choice == decisionTextReenforce2 && inventoryDirt - costOfStructure_reenforced_2 >= 0)					// re-enforce structure 2
            {
                _tile.prop_levelOfReenforcement++;
                inventoryDirt -= costOfStructure_reenforced_2;
            }
            else if (choice == decisionTextUnReenforce)					// un-re-enforce structure
            {
                // find the strength it will be set back to
                int _tempStrength = 0;
                if (tileToConvert.structureTypes.Contains(tileToConvert.thisTileType)) { _tempStrength = strengthOfStructures; }
                else if (tileToConvert.thisTileType == tile.tileType.dirt) { _tempStrength = strengthOfDirt; }
                else if (tileToConvert.thisTileType == tile.tileType.rock || tileToConvert.thisTileType == tile.tileType.rockWithGem) { _tempStrength = strengthOfRock; }

                if (FindBaseStrength(FindTileAtTop(_tile), _tile, _tempStrength) >= 0			// make sure the structure doesn't rely on it
                         || tileToConvert.myNeighborUp.thisTileType == tile.tileType.empty)		// or if it's the top structure
                {
                    _tile.prop_levelOfReenforcement = 0;
                    inventoryDirt += costOfStructure_unReenforce;
                }
                else { CannotPerformAction("Cannot un-reenforce structure - structures rely on this block's re-enforcement"); }
            }
            else if (choice == decisionTextResidence && inventoryDirt - costOfStructure_residence >= 0)						// change to residence
            { RemoveBenefitsOfOldType(_tile); _tile.ChangeTileType (tile.tileType.structure_residence); inventoryDirt -= costOfStructure_residence; countResidence++; }
            else if (choice == decisionTextMining && inventoryDirt - costOfStructure_mining >= 0)							// change to mining
            {
                RemoveBenefitsOfOldType(_tile);
                _tile.ChangeTileType (tile.tileType.structure_mining);
                inventoryDirt -= costOfStructure_mining;
                countMining++;
                mineTiles.Add(_tile);
                UpdateMinableTilesList();
            }
            else if (choice == decisionTextFactory && inventoryDirt - costOfStructure_factory >= 0)							// change to factory
            { RemoveBenefitsOfOldType(_tile); _tile.ChangeTileType (tile.tileType.structure_factory); inventoryDirt -= costOfStructure_factory; countFactory++; RecalculateCosts(); }
            else if (choice == decisionTextMill && inventoryDirt - costOfStructure_mill >= 0)								// change to mill
            { RemoveBenefitsOfOldType(_tile); _tile.ChangeTileType (tile.tileType.structure_mill); inventoryDirt -= costOfStructure_mill; countMill++; RecalculateCosts(); }
            else if (choice == decisionTextCommunity && inventoryDirt - costOfStructure_community >= 0)						// change to community center
            { RemoveBenefitsOfOldType(_tile); _tile.ChangeTileType (tile.tileType.structure_community); inventoryDirt -= costOfStructure_community; countCommunity++; }
            else if (choice == decisionTextSonar && inventoryDirt - costOfStructure_sonar >= 0)								// change to sonar
            {
                RemoveBenefitsOfOldType(_tile);
                inventoryDirt -= costOfStructure_sonar;
                sonarList.Add(_tile);														// Add to sonar list
                UpdateAllSonar();
                RecalculateCosts();
            }
            else if (choice == decisionTextMountGem)																		// change to gem mount
            {
                if (inventoryGems > 0)												// make sure you have a gem
                {
                    if (_tile.myNeighborUp.thisTileType == tile.tileType.empty)		// make sure there's no structure above
                    {
                        if (_tile.thisTileY >= gemHeightRequirement)				// make sure the gem is being mounted high enough
                        {
                            RemoveBenefitsOfOldType(_tile);
                            _tile.ChangeTileType (tile.tileType.structure_gemMount);
                            inventoryGems--;
                            countGemMount++;
                            inventoryDirt += prizeDirtForMountingGem;
                        }
                        else { CannotPerformAction("Cannot mount Gem here - Gem must be mounted at least " + gemHeightRequirement + " above ground level"); }
                    }
                    else { CannotPerformAction("Cannot mount Gem here - Gem must be mounted on the top of a structure"); }
                }
                else { CannotPerformAction("Cannot mount Gem - You don't have any Gems"); }
            }
            else { CannotPerformAction("Not enough resources\n(Resources can be gained by mining or destroying other structures)"); }
        }
    }
Ejemplo n.º 42
0
 /// <summary>
 /// returnerar den index som den givna tilen existerar i
 /// </summary>
 /// <param name="inTile"></param>
 /// <returns></returns>
 public int FindIndex_AtTile(tile inTile)
 {
     for (int i = 0; i < tileList.Count; i++)
     {
         if (tileList[i] == inTile)
         {
             return i;
         }
     }
     return -1;
 }
Ejemplo n.º 43
0
 public bool Tile_IsAdjacentTo(tile tile1, tile tile2)
 {
     int[] temp = new int[3];
     temp = tile1.XYZLibraryCoordinates();
     temp[0]++;
     temp[1]++;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     temp = tile1.XYZLibraryCoordinates();
     temp[1]++;
     temp[2]++;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     temp = tile1.XYZLibraryCoordinates();
     temp[2]++;
     temp[0]--;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     temp = tile1.XYZLibraryCoordinates();
     temp[0]--;
     temp[1]--;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     temp = tile1.XYZLibraryCoordinates();
     temp[1]--;
     temp[2]--;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     temp = tile1.XYZLibraryCoordinates();
     temp[2]--;
     temp[0]++;
     //temp[2];
     if (temp[0] == tile2.XYZLibraryCoordinates()[0] &&
         temp[1] == tile2.XYZLibraryCoordinates()[1] &&
         temp[2] == tile2.XYZLibraryCoordinates()[2])
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 44
0
        /// <summary>
        /// </summary>
        /// <param name="tileIndex"></param>
        /// <param name="unitID"></param>
        /// <param name="postiveORnegative"></param>
        /// <param name="XYZ"></param>
        public void MoveUnit(int unitID, tile tileAt, tile tileTo, unitLib uLib)
        {
            if (tileAt.unitExists(unitID) && Tile_IsAdjacentTo(tileAt, tileTo) && uLib.unitList[uLib.FindIndexOfUnit_AtUnitID(unitID)].CurrentMovePoints > 0)
            {
                tileAt.removeUnit(unitID);
                tileTo.addUnit(unitID);

                uLib.unitList[uLib.FindIndexOfUnit_AtUnitID(unitID)].CurrentMovePoints--;
            }
        }
Ejemplo n.º 45
0
 //finding the closest point
 //interate throught all points
 //if a point is closer store
 //loop
 //once you have gone through all of the points
 //the last stored point is the closest
 float checkDistance(tile target, tile source)
 {
     return Mathf.Pow(target.x - source.x, 2) + Mathf.Pow(target.y - source.y, 2);
 }
Ejemplo n.º 46
0
 tile getRandomCoord()
 {
     tile coordinate = new tile (PseudoRng.Next (0, sizeX),PseudoRng.Next(0, sizeY));
     return coordinate;
 }
Ejemplo n.º 47
0
 void storeTiles()
 {
     mapData = new tile[sizeX, sizeY];
     for(int y = 0; y < sizeY; y++)
     {
         for(int x = 0; x < sizeX; x++)
         {
             foreach(tile tile in myTiles)
             {
                 if(tile.x == x && tile.y == y)
                 {
                     mapData[x,y]= tile;
                     tile.tileContents = tileState.crossroad;
                     break; //stops the loop because we fount the element
                 }
             }
             if(mapData[x,y] == null)
             {
                 mapData[x,y] = new tile(x,y);
             }
         }
     }
 }