Esempio n. 1
0
        private static PortTownIndividualPacket createNewPortTownAtLocation(SimplifiedLayoutReturnPacket simplifiedLayout, UpscaledLayoutReturnPacket upscaledLayout,
                                                                            byte roomX, byte roomY, float roomWidthHeight, int numOfVertsPerEdge, System.Random random_forThread)
        {
            PortTownIndividualPacket portTownIndividual = new PortTownIndividualPacket();

            portTownIndividual.setPortTownPierCoords_simple(roomX, roomY);

            Vector2 waterPosition = new Vector2((roomX + 0.5f) * roomWidthHeight, (roomY + 0.5f) * -roomWidthHeight);
            Vector2 landPosition  = findPortTownPierLandPoint(simplifiedLayout.getSimplifiedRoomArray()[roomX, roomY], waterPosition, roomWidthHeight, random_forThread);

            portTownIndividual.setPortTownYRotation(Vector2.SignedAngle(waterPosition - landPosition, Vector2.up));

            Vector2 stepAmount = (landPosition - waterPosition).normalized * Constants.shipMoveSpeed;

            do
            {
                waterPosition += stepAmount;
            } while (BoolArrayManager.checkForConflict_V2_noDoors(upscaledLayout.getBoolArray(), waterPosition));

            stepAmount     = stepAmount / Constants.shipMoveSpeed * Constants.portTownDistanceFromLand;
            waterPosition -= stepAmount;

            portTownIndividual.setPortTownPierCoords_upscaled(waterPosition.x, waterPosition.y);

            addHousesAroundPier(portTownIndividual, upscaledLayout.getLandVertexHeights(), random_forThread);

            return(portTownIndividual);
        }
Esempio n. 2
0
        public static PortTownReturnPacket generatePortTownInformation_DemoVer(SimplifiedLayoutReturnPacket simplifiedLayout, UpscaledLayoutReturnPacket upscaledLayout,
                                                                               float roomWidthHeight, int numOfVertsPerEdge)
        {
            PortTownReturnPacket portTownPacket = new PortTownReturnPacket(1);

            PortTownIndividualPacket portTownIndividual = new PortTownIndividualPacket();

            portTownIndividual.setAllData_forDemo();

            portTownPacket.addNewPortTownData(portTownIndividual);

            return(portTownPacket);
        }
Esempio n. 3
0
        private static byte getCornerIndexOffset(PortTownIndividualPacket portTownIndividual)
        {
            switch ((short)Mathf.Abs(portTownIndividual.getPortTownYRotation()))
            {
            case 0:
            case 1:
            case 89:
            case 90:
            case 91:
            case 269:
            case 270:
            case 271:
            case 359:
            case 360:
                return(2);

            default:
                return(0);
            }
        }
Esempio n. 4
0
        private static void addHousesAroundPier(PortTownIndividualPacket portTownIndividual, float[,] heightArray, System.Random random_forThread)
        {
            float townSize = 0.5f + (float)(random_forThread.NextDouble()) * 1.5f;
            float housePlacementDiameter = 40f * townSize;
            byte  maxNumberOfHouses      = (byte)(30 * townSize * townSize * (0.5f + random_forThread.NextDouble()));

            Vector3[] housePositions       = new Vector3[maxNumberOfHouses];
            Vector3[] houseScales          = new Vector3[maxNumberOfHouses];
            float[]   houseRotations       = new float[maxNumberOfHouses];
            byte      firstOpenSlotInArray = 0;

            Vector2 houseCenter = Vector2.zero;
            float   houseHeight;
            float   houseScale_front;
            float   houseScale_side;
            float   houseScale_top;

            byte cornerIndexOffset = getCornerIndexOffset(portTownIndividual);


            for (byte index = 0; index < maxNumberOfHouses; index++)
            {
                do
                {
                    houseCenter.x = (float)(random_forThread.NextDouble() - 0.5);
                    houseCenter.y = (float)(random_forThread.NextDouble() - 0.5);
                } while ((houseCenter.x * houseCenter.x) + (houseCenter.y * houseCenter.y) > 0.25f);

                houseCenter.x = houseCenter.x * housePlacementDiameter + portTownIndividual.getPortTownCoords_upscaled()[0];
                houseCenter.y = houseCenter.y * housePlacementDiameter + portTownIndividual.getPortTownCoords_upscaled()[1];

                houseHeight = getLandHeightAtCoord(houseCenter, heightArray);

                if (checkIfHouseCanBePlacedHere(houseCenter, houseHeight, housePositions, firstOpenSlotInArray))
                {
                    houseHeight = Mathf.Max(getLandHeightAtCoord(houseCenter + Constants.walls_hittestVectors[0 + cornerIndexOffset] * houseSize_boundBox_max, heightArray), houseHeight);
                    houseHeight = Mathf.Max(getLandHeightAtCoord(houseCenter + Constants.walls_hittestVectors[4 + cornerIndexOffset] * houseSize_boundBox_max, heightArray), houseHeight);
                    houseHeight = Mathf.Max(getLandHeightAtCoord(houseCenter + Constants.walls_hittestVectors[8 + cornerIndexOffset] * houseSize_boundBox_max, heightArray), houseHeight);
                    houseHeight = Mathf.Max(getLandHeightAtCoord(houseCenter + Constants.walls_hittestVectors[12 + cornerIndexOffset] * houseSize_boundBox_max, heightArray), houseHeight);

                    housePositions[firstOpenSlotInArray] = new Vector3(houseCenter.x, houseHeight - 0.5f, houseCenter.y);

                    houseScale_front = houseSize_front_min + (float)(random_forThread.NextDouble()) * houseSize_front_max_add;
                    houseScale_side  = houseSize_side_min + (float)(random_forThread.NextDouble()) * houseSize_side_max_add;
                    houseScale_top   = houseSize_top_min + (float)(random_forThread.NextDouble()) * houseSize_top_max_add;

                    if (random_forThread.Next(0, 2) == 0)
                    {
                        houseScales[firstOpenSlotInArray] = new Vector3(houseScale_front, houseScale_top, houseScale_side);
                    }
                    else
                    {
                        houseScales[firstOpenSlotInArray] = new Vector3(houseScale_side, houseScale_top, houseScale_front);
                    }


                    // houseRotations[firstOpenSlotInArray] = portTownIndividual.getPortTownYRotation() + random_forThread.Next(0, 4) * 90f;
                    // houseRotations[firstOpenSlotInArray] = Mathf.Atan((houseCenter.y - portTownIndividual.getPortTownCoords_upscaled()[1]) /
                    //                                                     (houseCenter.x - portTownIndividual.getPortTownCoords_upscaled()[0]))
                    //                                                      * -180f / Mathf.PI + 90f
                    //                                                      + (float)((random_forThread.NextDouble() -0.5)) * 15f;
                    houseRotations[firstOpenSlotInArray] = portTownIndividual.getPortTownYRotation() + random_forThread.Next(0, 4) * 90f
                                                           + (float)((random_forThread.NextDouble() - 0.5)) * 20f;

                    firstOpenSlotInArray++;
                }
            }

            Vector3[] housePositions_actual = new Vector3[firstOpenSlotInArray];
            Vector3[] houseScales_actual    = new Vector3[firstOpenSlotInArray];
            float[]   houseRotations_actual = new float[firstOpenSlotInArray];

            Color32[] roofColors     = new Color32[firstOpenSlotInArray];
            Color32[] wallColors     = new Color32[firstOpenSlotInArray];
            Color32   roofColor_base = generateRandomRoofColor_base(random_forThread);

            for (byte index = 0; index < firstOpenSlotInArray; index++)
            {
                housePositions_actual[index] = housePositions[index];
                houseScales_actual[index]    = houseScales[index];
                houseRotations_actual[index] = houseRotations[index];

                roofColors[index] = generateRandomRoofColor_offset(random_forThread, roofColor_base);
                wallColors[index] = generateRandomWallColor(random_forThread);
            }

            // portTownIndividual.setHouseData(housePositions_actual, houseScales_actual, houseRotations_actual, generateRandomRoofColor(random_forThread));
            portTownIndividual.setHouseData(housePositions_actual, houseScales_actual, houseRotations_actual, roofColors, wallColors);
        }
Esempio n. 5
0
 public void addNewPortTownData(PortTownIndividualPacket portTownData)
 {
     portTownArray[numOfPortTowns_actual] = portTownData;
     numOfPortTowns_actual++;
 }