Ejemplo n.º 1
0
    void DigCorridors(MapSection s)
    {
        int ox = (int)s.m_position.x;
        int oy = (int)s.m_position.y;
        int mx = (int)s.GetMidpoint().x;
        int my = (int)s.GetMidpoint().y;
        int sx = (int)s.m_size.x;
        int sy = (int)s.m_size.y;

        for (int y = oy; y < oy + sy; y++)
        {
            for (int x = ox; x < ox + sx; x++)
            {
                if (s.m_corridors.north && x == mx && y >= my)
                {
                    m_terrain_map[x, y] = ".";
                }
                if (s.m_corridors.south && x == mx && y <= my)
                {
                    m_terrain_map[x, y] = ".";
                }
                if (s.m_corridors.east && y == my && x >= mx)
                {
                    m_terrain_map[x, y] = ".";
                }
                if (s.m_corridors.west && y == my && x <= mx)
                {
                    m_terrain_map[x, y] = ".";
                }
            }
        }
    }
Ejemplo n.º 2
0
    void DigRoom(MapSection s)
    {
        if (s.m_room == null)
        {
            return;
        }

        int ox = (int)s.m_position.x;
        int oy = (int)s.m_position.y;
        int mx = (int)s.GetMidpoint().x;
        int my = (int)s.GetMidpoint().y;
        int sx = (int)s.m_size.x;
        int sy = (int)s.m_size.y;

        for (int y = oy; y < oy + sy; y++)
        {
            for (int x = ox; x < ox + sx; x++)
            {
                if (Mathf.Abs(x - mx) < s.m_room.m_size && Mathf.Abs(y - my) < s.m_room.m_size)
                {
                    m_terrain_map[x, y] = ".";
                }
            }
        }
    }
Ejemplo n.º 3
0
    Vector3 GetRandomSquareInSection(MapSection sec)
    {
        Vector3 rnd_pos = new Vector3(sec.GetMidpoint().x, 0, sec.GetMidpoint().y);

        if (sec.m_room != null)
        {
            float rnd_x = sec.GetMidpoint().x + Random.Range(-sec.m_room.m_size, sec.m_room.m_size);
            float rnd_y = sec.GetMidpoint().y + Random.Range(-sec.m_room.m_size, sec.m_room.m_size);
            rnd_pos = new Vector3(rnd_x, 0, rnd_y);
        }
        return(rnd_pos);
    }
Ejemplo n.º 4
0
    void PlaceEnemy(MapSection s)
    {
        if (s.m_room == null)
        {
            return;
        }
        if (s.m_room.m_type == RoomType.ENTRANCE)
        {
            return;
        }

        float rnd_x = Mathf.Floor(s.GetMidpoint().x + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size;
        float rnd_y = Mathf.Floor(s.GetMidpoint().y + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size;

        Vector3 pos = new Vector3(rnd_x, 0, rnd_y);

        Instantiate(GetRandomSpawn(), pos, Quaternion.identity);
    }
Ejemplo n.º 5
0
    void PlaceRandomFeature(MapSection s)
    {
        if (s.m_room == null)
        {
            return;
        }
        if (m_map_features.Length == 0)
        {
            return;
        }

        float rnd_x = Mathf.Floor(s.GetMidpoint().x + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size;
        float rnd_y = Mathf.Floor(s.GetMidpoint().y + Random.Range(1 - s.m_room.m_size, s.m_room.m_size - 1)) * m_map_square_size;

        Vector3    pos         = new Vector3(rnd_x, 0, rnd_y);
        GameObject rnd_feature = m_map_features[Random.Range(0, m_map_features.Length)];

        Instantiate(rnd_feature, pos, Quaternion.identity);
    }
Ejemplo n.º 6
0
    public Vector3 GetAdjacentRoomPosition(Vector3 position)
    {
        //Vector2 pos = new Vector2(Mathf.FloorToInt(position.x/m_map_square_size),Mathf.FloorToInt(position.z/m_map_square_size));
        //MapSection current_section = GetSectionAtCoords(pos);
        MapSection current_section = GetSectionAtPosition(position);

        List <MapSection> rnd_sections = new List <MapSection>();
        Vector3           section_pos;

        if (current_section.m_corridors.east)
        {
            section_pos = new Vector3(current_section.GetMidpoint().x + m_section_size.x, current_section.GetMidpoint().y);
            rnd_sections.Add(GetSectionAtCoords(section_pos));
        }
        if (current_section.m_corridors.west)
        {
            section_pos = new Vector3(current_section.GetMidpoint().x - m_section_size.x, current_section.GetMidpoint().y);
            rnd_sections.Add(GetSectionAtCoords(section_pos));
        }
        if (current_section.m_corridors.north)
        {
            section_pos = new Vector3(current_section.GetMidpoint().x, current_section.GetMidpoint().y + m_section_size.y);
            rnd_sections.Add(GetSectionAtCoords(section_pos));
        }
        if (current_section.m_corridors.south)
        {
            section_pos = new Vector3(current_section.GetMidpoint().x, current_section.GetMidpoint().y - m_section_size.y);
            rnd_sections.Add(GetSectionAtCoords(section_pos));
        }
        //rnd_sections.Shuffle();

        MapSection rnd_sec = rnd_sections[Random.Range(0, rnd_sections.Count - 1)];

        if (rnd_sections.Count == 0)
        {
            return(Vector3.zero);
        }

        return(new Vector3(rnd_sec.GetMidpoint().x *m_map_square_size, 0, rnd_sec.GetMidpoint().y *m_map_square_size));
    }
Ejemplo n.º 7
0
    void AIWander()
    {
        //Clear target if it has been reached.
        if (m_has_wander_target)
        {
            if (Vector3.Distance(transform.position, m_wander_target) < 1)
            {
                m_has_wander_target = false;
                return;
            }
        }

        //Move towards target.
        if (m_has_wander_target)
        {
            Vector3 dir   = m_wander_target - transform.position;
            Vector2 dir2d = new Vector3(dir.x, dir.z);
            m_entity.m_mobile.Move(m_entity.m_move_speed * m_wander_speed_mod, dir2d);
            return;
        }

        //Get a new target.
        MapSection current_section = Game.map.GetSectionAtPosition(transform.position);

        if (current_section.m_room == null)
        {
            return;
        }

        Vector2 rnd_tile = new Vector2(
            current_section.GetMidpoint().x + Random.Range(-current_section.m_room.m_size + 1, current_section.m_room.m_size),
            current_section.GetMidpoint().y + Random.Range(-current_section.m_room.m_size + 1, current_section.m_room.m_size)
            );
        Vector3 rnd_position = new Vector3(rnd_tile.x * Game.map.GetMapSquareSize(), 0, rnd_tile.y * Game.map.GetMapSquareSize());

        m_wander_target     = rnd_position;
        m_has_wander_target = true;
    }
Ejemplo n.º 8
0
    void SetupRandomExit(MapSection s)
    {
        m_corridor_count++;

        if (s.m_room != null && s.m_room.m_type == RoomType.EXIT)
        {
            m_exit_path_found = true;
            //If you've made enough corridors, already, back out...
            if (m_corridor_count > m_min_corridors)
            {
                return;
            }
        }

        List <string> exits = new List <string>();

        if (s.GetMidpoint().x - s.m_size.x > 0)
        {
            exits.Add("west");
        }
        if (s.GetMidpoint().x + s.m_size.x < m_map_size.x)
        {
            exits.Add("east");
        }
        if (s.GetMidpoint().y - s.m_size.y > 0)
        {
            exits.Add("south");
        }
        if (s.GetMidpoint().y + s.m_size.y < m_map_size.y)
        {
            exits.Add("north");
        }
        exits.Shuffle();

        MapSection next_section;

        foreach (string e in exits)
        {
            if (e == "north" &&
                GetSectionAtCoords(s.GetMidpoint() + Vector2.up * s.m_size.y) != null &&
                GetSectionAtCoords(s.GetMidpoint() + Vector2.up * s.m_size.y).m_corridors.south == false)
            {
                next_section = GetSectionAtCoords(s.GetMidpoint() + Vector2.up * s.m_size.y);
                if (next_section == null)
                {
                    continue;
                }

                s.m_corridors.north            = true;
                next_section.m_corridors.south = true;
                SetupRandomExit(next_section);
            }
            else if (e == "south" &&
                     GetSectionAtCoords(s.GetMidpoint() - Vector2.up * s.m_size.y) != null &&
                     GetSectionAtCoords(s.GetMidpoint() - Vector2.up * s.m_size.y).m_corridors.north == false)
            {
                next_section = GetSectionAtCoords(s.GetMidpoint() - Vector2.up * s.m_size.y);
                if (next_section == null)
                {
                    continue;
                }

                s.m_corridors.south            = true;
                next_section.m_corridors.north = true;
                SetupRandomExit(next_section);
            }
            else if (e == "east" &&
                     GetSectionAtCoords(s.GetMidpoint() + Vector2.right * s.m_size.x) != null &&
                     GetSectionAtCoords(s.GetMidpoint() + Vector2.right * s.m_size.x).m_corridors.west == false)
            {
                next_section = GetSectionAtCoords(s.GetMidpoint() + Vector2.right * s.m_size.x);
                if (next_section == null)
                {
                    continue;
                }

                s.m_corridors.east            = true;
                next_section.m_corridors.west = true;
                SetupRandomExit(next_section);
            }
            else if (e == "west" &&
                     GetSectionAtCoords(s.GetMidpoint() - Vector2.right * s.m_size.x) != null &&
                     GetSectionAtCoords(s.GetMidpoint() - Vector2.right * s.m_size.x).m_corridors.east == false)
            {
                next_section = GetSectionAtCoords(s.GetMidpoint() - Vector2.right * s.m_size.x);
                if (next_section == null)
                {
                    continue;
                }

                s.m_corridors.west            = true;
                next_section.m_corridors.east = true;
                SetupRandomExit(next_section);
            }

            if (m_exit_path_found == true && m_corridor_count > m_min_corridors)
            {
                break;
            }
        }
    }