Beispiel #1
0
    public override WorldObject CreateWorldObject(Transform transform = null)
    {
        GenerationRandom genRan = new GenerationRandom(WorldPosition.GetHashCode() * 13);
        int count = genRan.RandomInt(2, 5);

        WorldObject r1 = null;

        for (int i = 0; i < count; i++)
        {
            Vector3 pos   = genRan.RandomVector3(-MaxSize, MaxSize, (i) * 0.1f, (i) * 0.2f + 0.1f, -MaxSize, MaxSize) / 100f;
            float   rSize = genRan.Random(0.5f, 1.5f);
            Rock    r     = new Rock(WorldPosition, pos, rSize);

            if (i == 0)
            {
                r1 = r.CreateWorldObject(transform);
            }
            else
            {
                WorldObject rn = r.CreateWorldObject(r1.transform);
                rn.transform.localPosition = pos;
            }
        }
        return(r1);
    }
    private static void PlaceOutsideObjects(GenerationRandom genRan, Blacksmith smith, BuildingVoxels vox, Vec2i outMin, Vec2i outMax)
    {
        List <WorldObjectData> toPlace = new List <WorldObjectData>(new WorldObjectData[] { new Anvil(), new Anvil() });
        bool isFinished = false;

        while (!isFinished)
        {
            WorldObjectData toPlaceCur = toPlace[0];
            toPlace.RemoveAt(0);
            Vector3 pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
            toPlaceCur.SetPosition(pos);
            while (!BuildingGenerator.AddObject(smith, vox, toPlaceCur))
            {
                pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
                toPlaceCur.SetPosition(pos);
            }
            if (toPlace.Count == 0)
            {
                isFinished = true;
            }
        }
    }
    public override void Generate(GenerationRandom ran)
    {
        GenRan = ran;
        BuildWallAndEntrance();
        GenerateSubworldCave(new Vec2i(TileSize.x - 10, TileSize.z - 10));
        DEBUG = false;
        EntityFaction bandits = new EntityFaction("Bandits");

        for (int i = 0; i < 10; i++)
        {
            Vector3 pos    = GenRan.RandomVector3(Boundry + 2, Mathf.Min(TileSize.x, TileSize.z) - Boundry - 2);
            Bandit  bandit = new Bandit();
            bandit.SetEntityFaction(bandits);
            bandit.MoveEntity(pos);
            AddEntity(bandit);
        }
    }
Beispiel #4
0
    public override void OnObjectLoad(WorldObject obj)
    {
        Mesh  mesh        = obj.GetComponent <MeshFilter>().mesh;
        float distort_amp = 2;
        float sin_freq    = Mathf.PI * 2;
        float total_scale = 1;

        Vector3[] verticies = mesh.vertices;

        Vector3 seed_delta = new Vector3(WorldPosition.x + ObjectDeltaPosition.x * 17f, ObjectDeltaPosition.y * 2f, WorldPosition.z + ObjectDeltaPosition.z * 27f);
        Vector3 scale      = genRan.RandomVector3(0.2f, 0.5f) * RockSize;

        scale.y *= 0.8f; //Bias to flatter canopies
        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            float perlin = genRan.PerlinNoise3D(verticies[i] + seed_delta, 512f);
            float dist_f = 1 + distort_amp * perlin;
            verticies[i].Scale(scale * dist_f);
        }
        mesh.vertices = verticies;
        mesh.RecalculateNormals();
    }
    private List <CaveRoom> GenerateRooms(int roomCount = 4)
    {
        List <CaveRoom> rooms = new List <CaveRoom>();

        for (int i = 0; i < roomCount; i++)
        {
            Vector3 size    = GenRan.RandomVector3(8, 32, 3, 7, 8, 32);
            Vec3i   roomPos = GenRan.RandomVec3i((int)size.x + 1, (int)(TileSize.x - size.x - 1), (int)size.y + 1, (int)(World.ChunkHeight - size.y - 1),
                                                 (int)size.z + 1, (int)(TileSize.z - size.z - 1));
            Debug.Log(roomPos + "_" + size);
            rooms.Add(new CaveRoom(roomPos, size, new Vec3i(0, 0, 0), new Vec3i(0, 0, 0)));
            List <Vec3i> vs = rooms[rooms.Count - 1].AllPointsInside();
            Debug.Log(vs.Count + " nodes total");
            foreach (Vec3i v in vs)
            {
                //if(InBounds(v))
                ClearVoxelNode(v.x, v.y, v.z);
                Densities[v.x, v.y, v.z] = 0;
            }
        }
        return(rooms);
    }