private IEnumerator initializeGrid()
 {
     grid = new MechGrid(gridWidth, gridHeight);
     for (int i = 0; i < blocks.Length; i++) {
         // set blocks to initial positions
         Vector3 startPos = blocks[i].transform.position;
         Vector3 endPos = blockPositions[setNum][i].toVector3XZ();
         if (startPos != endPos)
             yield return StartCoroutine(blocks[i].MoveWithinTime(endPos, 0.2f));
     //			blocks[i].transform.position = blockPositions[setNum][i].toVector3XZ();
         // convert world position to grid indices
         Vector2 p = fromWorldToGrid(blocks[i].transform.position.toVector2XZ());
         int row = (int) p.x;
         int col = (int) p.y;
         grid.placeBlock(row, col);
     }
 }
Esempio n. 2
0
    public static void HandleMechGridAdd(Vector3 mappos, socket tsock, socketIG result)
    {
        List<int> foundgrid = new List<int>();

        if (mechgrids.Count > 0)
        {
            for (int kg = 0; kg < mechgrids.Count; kg++)
            {
                foreach (socketIG asock in mechgrids[kg].thelist)
                {
                    bool thebool = asock.location == mappos + new Vector3(01, 0, 0) || asock.location == mappos + new Vector3(0, 01, 0) || asock.location == mappos + new Vector3(0, 0, 01) || asock.location == mappos + new Vector3(-1, 0, 0) || asock.location == mappos + new Vector3(0, -1, 0) || asock.location == mappos + new Vector3(0, 0, -1);

                    if (thebool)
                    {
                        foundgrid.Add(kg);
                        break;
                    }
                }
            }
        }


        if (foundgrid.Count == 0)
        {
            MechGrid thegrid = new MechGrid(result);
            mechgrids.Add(thegrid);
            thegrid.refreshoncreate();
            parcellist = new List<parcel>();
        }

        if (foundgrid.Count == 1)
        {
            mechgrids[foundgrid[0]].thelist.Add(result);
            mechgrids[foundgrid[0]].refreshoncreate();
            parcellist = new List<parcel>();
        }

        if (foundgrid.Count > 1)
        {
            List<socketIG> alist = new List<socketIG>();
            for (int k = 0; k < foundgrid.Count; k++)
            {
                for (int k2 = 0; k2 < mechgrids[foundgrid[k]].thelist.Count; k2++)
                {
                    alist.Add(mechgrids[foundgrid[k]].thelist[k2]);
                }
            }
            alist.Add(result);

            for (int k = mechgrids.Count - 1; k >= 0; k--)
            {
                bool isequal = false;
                foreach (int anint in foundgrid)
                {
                    if (k == anint)
                    {
                        isequal = true;
                    }
                }
                if (isequal)
                {
                    mechgrids.RemoveAt(k);
                }
            }

            mechgrids.Add(new MechGrid(alist));
            mechgrids[mechgrids.Count - 1].refreshoncreate();
        }
    }