Ejemplo n.º 1
0
    private void BuildMapsByIEnum(Vector3 nodeLoc, int j, int _mapType = -1, int _rotation = -1)
    {
        int startGridLocX = (int)nodeLoc.x - (_mapSettings.sizeOfMapPiecesXZ / 2);
        int startGridLocY = (int)nodeLoc.y;
        int startGridLocZ = (int)nodeLoc.z - (_mapSettings.sizeOfMapPiecesXZ / 2);

        Vector3 GridLoc;

        List <int[, ]> layers = new List <int[, ]>();

        int[,] floor;


        bool floorORRoof = (layerCount % 2 == 0) ? true : false; // floors/Vents
        int  mapPieceType;

        if (floorORRoof) // Floor
        {
            mapPieceType = _mapType;
        }
        else // Roof
        {
            mapPieceType = _mapType + 1;
        }

        int mapPiece = Random.Range(1, 4); //Map pieces // 0 = Entrance so dont use here
        int rotation = (_rotation == -1) ? Random.Range(0, 4) : _rotation;

        if (rotation == 4)
        {
            mapPiece = 0; //ConnectorPiece UP not sure if going to work
        }

        layers = GetMapPiece(mapPieceType, mapPiece);
        int rotations = rotation;

        int objectsCountX = startGridLocX;
        int objectsCountY = startGridLocY;
        int objectsCountZ = startGridLocZ;

        for (int y = 0; y < layers.Count; y++)
        {
            objectsCountX = startGridLocX;
            objectsCountZ = startGridLocZ;

            floor = layers[y];

            for (int r = 0; r < rotations; r++)
            {
                floor = TransposeArray(floor, _mapSettings.sizeOfMapPiecesXZ - 1);
            }

            for (int z = 0; z < floor.GetLength(0); z++)
            {
                objectsCountX = startGridLocX;

                for (int x = 0; x < floor.GetLength(1); x++)
                {
                    int cubeType = floor[z, x];
                    GridLoc = new Vector3(objectsCountX, objectsCountY, objectsCountZ);

                    _cubeBuilder.CreateCubeObject(GridLoc, cubeType, rotations, layerCount); // Create the cube

                    objectsCountX += 1;
                }
                objectsCountZ += 1;
            }
            objectsCountY += 1;
        }
    }
Ejemplo n.º 2
0
    private static void BuildMapsByIEnum <T>(T node, Vector3 nodeLoc, int _mapType = -1, int _mapPiece = -1, int _rotation = -1) where T : BaseNode
    {
        int startGridLocX = (int)nodeLoc.x - (MapSettings.sizeOfMapPiecesXZ / 2);
        int startGridLocY = (int)nodeLoc.y;
        int startGridLocZ = (int)nodeLoc.z - (MapSettings.sizeOfMapPiecesXZ / 2);

        Vector3 GridLoc;

        List <int[, ]> layers    = new List <int[, ]>();
        int            rotations = 0;

        int[,] floor;


        bool floorORRoof = (layerCount % 2 == 0) ? true : false; // floors/Vents
        int  mapType;
        int  mapPiece;
        int  rotation;

        if (floorORRoof) // Floor
        {
            mapType = _mapType;
        }
        else // Roof
        {
            mapType = _mapType + 1;
        }

        // PLACING PLAYERS SHIP //////////////////////////////////
        if (node.playerShipMapPART1 || node.playerShipMapPART2)
        {
            if (floorORRoof)
            {
                if (node.playerShipMapPART1)
                {
                    layers = PlayerManager.PlayerShipSmallFloorDataPART1;
                }
                else
                {
                    layers = PlayerManager.PlayerShipSmallFloorDataPART2;
                }
            }
            else
            {
                if (node.playerShipMapPART1)
                {
                    layers = PlayerManager.PlayerShipSmallVentDataPART1;
                }
                else
                {
                    layers = PlayerManager.PlayerShipSmallVentDataPART2;
                }
            }
            rotation = 0;
        }/////////////////////////////////////////////////////////////
        else
        {
            mapPiece = _mapPiece;
            rotation = _rotation;

            if (node.entrance)
            {
                KeyValuePair <int, int> mapAndRot = GetShipEntranceMap(_mapPiece);
                mapPiece = mapAndRot.Key;
                rotation = mapAndRot.Value;
            }

            layers = GetMapPiece(mapType, mapPiece);
        }

        rotations = rotation;
        //node.nodeRotation = rotation;

        int objectsCountX = startGridLocX;
        int objectsCountY = startGridLocY;
        int objectsCountZ = startGridLocZ;

        for (int y = 0; y < layers.Count; y++)
        {
            objectsCountX = startGridLocX;
            objectsCountZ = startGridLocZ;

            floor = layers[y];


            // for an extra layer roof of the vents only appearing if no map piece above vent
            if (!node.entrance)
            {
                if (!floorORRoof && y == (layers.Count - 1) && neighbours[5] != -1)
                {
                    continue; // if so, skip last layer
                }
            }


            for (int r = 0; r < rotations; r++)
            {
                floor = TransposeArray(floor, MapSettings.sizeOfMapPiecesXZ - 1);

                /*
                 * if(floorORRoof) // storing the map data for serilisation and other shit still to work out
                 * { // have to implement this at some stage
                 *  floorDataToReturn.Add(floor);
                 * }
                 * else
                 * {
                 *  ventDataToReturn.Add(floor);
                 * }
                 */
            }

            for (int z = 0; z < floor.GetLength(0); z++)
            {
                objectsCountX = startGridLocX;

                for (int x = 0; x < floor.GetLength(1); x++)
                {
                    GridLoc = new Vector3(objectsCountX, objectsCountY, objectsCountZ);

                    int cubeType = floor[z, x];

                    cubeType = FigureOutDoors(node, _mapType, cubeType, rotations);
                    int nodeLayercount = node.GetComponent <T>().NodeLayerCount + nodeLayerCounter;

                    CubeLocationScript cubeScript = CubeBuilder.CreateCubeObject(GridLoc, cubeType, rotations, nodeLayercount, node.gameObject.transform); // Create the cube

                    // A test to see if cube has panel to try make connecting neighbours easier
                    if (cubeScript && cubeScript.CubeIsPanel)
                    {
                        halfCubesWithPanels.Add(cubeScript);
                    }

                    objectsCountX += 1;
                }
                objectsCountZ += 1;
            }

            if (y % 2 != 0)
            {
                nodeLayerCounter++;
            }
            objectsCountY += 1;
        }
    }
Ejemplo n.º 3
0
    //////////////////////////////////////////////

    public static void BuildMap(MapNode node)
    {
        MapFloorData.Clear(); // storing data for serialzatino
        MapVentData.Clear();

        neighbourVects = node.neighbourVects;

        Vector3Int nodeLoc = node.NodeID;

        int startGridLocX = -(MapSettings.MapNodeCountDistanceXZ / 2 + 1); // local Positions
        int startGridLocY = -(MapSettings.MapNodeCountDistanceY / 2 + 1);
        int startGridLocZ = -(MapSettings.MapNodeCountDistanceXZ / 2 + 1);

        Vector3Int localGridLoc;


        List <int[]> layers = LoadDataFromMapTextDoc(node.NodeMapPiece);

        /*
         * if (node.entrance)
         * {
         *     KeyValuePair<int, int> mapAndRot = GetShipEntranceMap((int)mapPiece);
         *     mapPiece = mapAndRot.Key;
         *     rotation = mapAndRot.Value;
         * }
         */


        int objectsCountX = startGridLocX;
        int objectsCountY = startGridLocY;
        int objectsCountZ = startGridLocZ;

        int cubeCounter = 0;

        for (int y = 0; y < MapSettings.NodeCountOfMapPiecesY; y++)
        {
            objectsCountX = startGridLocX;
            objectsCountZ = startGridLocZ;

            // floor = layers;


            // for an extra layer roof of the vents only appearing if no map piece above vent
            //if (!node.entrance)
            //{
            //    if (y == (layers.Count - 1) && neighbourVects[5] != new Vector3Int(-1, -1, -1))
            //    {
            //        continue; // if so, skip last layer
            //    }
            //}


            for (int z = 0; z < MapSettings.NodeCountOfMapPiecesXZ; z++)
            {
                objectsCountX = startGridLocX;

                for (int x = 0; x < MapSettings.NodeCountOfMapPiecesXZ; x++)
                {
                    localGridLoc = new Vector3Int(objectsCountX, objectsCountY, objectsCountZ);

                    if (layers != null && layers[cubeCounter] != null)
                    {
                        int[] cubeData = layers[cubeCounter];

                        CubeLocationScript cubeScript = CubeBuilder.CreateCubeObject(localGridLoc, cubeData, node.gameObject.transform);  // Create the cube // TIDY THIS UP

                        // A test to see if cube has panel to try make connecting neighbours easier
                        if (cubeScript && cubeScript.CubeIsPanel)
                        {
                            halfCubesWithPanels.Add(cubeScript);
                        }
                    }

                    cubeCounter++;

                    objectsCountX += 1;
                }
                objectsCountZ += 1;
            }
            objectsCountY += 1;
        }
    }