Exemplo n.º 1
0
    public void Add(RoadComponent road)
    {
        RoadType type = road.GetRoadType();

        if (collection.ContainsKey(type))
        {
            Debug.LogError("RoadCollection:Add: road of this type existed");
            return;
        }
        collection.Add(type, road);
    }
Exemplo n.º 2
0
    public RoadCollection(RoadComponent currentRoad)
    {
        collection         = new Dictionary <RoadType, RoadComponent>();
        placedRoadsByOrder = new List <RoadType>();

        RoadType type = currentRoad.GetRoadType();

        Add(currentRoad);
        SetCurrent(type);
        Place(type);
    }
Exemplo n.º 3
0
    private void Initialize()
    {
        RoadComponent component = transform.GetChild(0).GetComponent <RoadComponent>();

        collection = new RoadCollection(component);

        int count = transform.childCount;

        for (int i = 1; i < count; i++)
        {
            component = transform.GetChild(i).GetComponent <RoadComponent>();
            collection.Add(component);
            collection.Place(component.GetRoadType());
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// place road component of the given type after this road
    /// component
    /// </summary>
    /// <param name="type">type of next road component</param>
    /// <returns>position of place road component</returns>
    public Vector3 Place(RoadType type)
    {
        RoadComponent shouldBePlacedRoad = collection.Get(type);
        RoadComponent currentRoad        = collection.GetCurrentRoadComponent();

        currentRoad.SetActive(false);

        // get last placed road
        RoadComponent lastRoad = collection.GetLastRoadComponent();

        // get position of last placed road
        position = lastRoad.GetPosition();
        // move position forwad for finding position of next road
        position.z += planeWidth;
        shouldBePlacedRoad.SetPosition(position); // place new road after the last road
        collection.Place(type);                   // a new road has been placed
        shouldBePlacedRoad.Place();
        collection.Next();                        // update collection current road to next road
        return(position);
    }
Exemplo n.º 5
0
        private void Entities_EntityAdded(object sender, EntityEventArgs e)
        {
            Point index = e.Entity.Get <PositionComponent>().Index;

            // update the game data
            foreach (Component c in e.Entity.Components.Values.ToList())
            {
                switch (c.GetType().Name)
                {
                case "CitizenComponent":
                    CitizenComponent citizen = (CitizenComponent)c;

                    // fill in the data if it doesn't already exist
                    if (string.IsNullOrWhiteSpace(citizen.Name))
                    {
                        // generate name
                        string[] names = { "Steve", "John", "Bill" };
                        citizen.Name = names[Random.Next(0, names.Length)];
                    }

                    if (string.IsNullOrWhiteSpace(citizen.Surname))
                    {
                        // generate family name
                        string[] names = { "Johnson", "Miller", "Smith" };
                        citizen.Surname = names[Random.Next(0, names.Length)];
                    }

                    if (citizen.Gender == Gender.BOTH)
                    {
                        citizen.Gender = (Gender)Random.Next(1, 3);
                    }

                    if (citizen.Age == 0)
                    {
                        // generate age
                        citizen.Age = Random.Next(14, 46);
                    }

                    if (citizen.Money == 0)
                    {
                        citizen.Money = Random.Next(20, 100);
                    }
                    break;

                case "CollapsibleComponent":
                    CollapsibleComponent collapsible = (CollapsibleComponent)c;

                    if (collapsible.Value == 0)
                    {
                        collapsible.Value = CollapsibleComponent.MAX;
                    }
                    break;

                case "CollisionComponent":
                    CollisionComponent collision = (CollisionComponent)c;

                    foreach (LocationValue lv in collision.Plan)
                    {
                        Point p = new Point(index.X + lv.Offset.X, index.Y + lv.Offset.Y);

                        if (Collisions.Map.ContainsKey(p))
                        {
                            Collisions.Map[p] = (PathTypes)lv.Value;
                        }
                        else
                        {
                            Collisions.Map.Add(p, (PathTypes)lv.Value);
                        }
                    }
                    break;

                case "CollisionMapComponent":
                    Collisions = (CollisionMapComponent)c;
                    break;

                case "FoundationComponent":
                    FoundationComponent floor = (FoundationComponent)c;

                    // update the floor planner
                    foreach (LocationValue lv in floor.Plan)
                    {
                        Point update = new Point(index.X + lv.Offset.X, index.Y + lv.Offset.Y);
                        Foundations.SpaceTaken.Add(update, e.Entity.ID);
                    }
                    break;

                case "FoundationPlannerComponent":
                    Foundations = (FoundationPlannerComponent)c;
                    break;

                case "GameDateComponent":
                    Date = (GameDateComponent)c;
                    break;

                case "IsometricMapComponent":
                    Map = e.Entity.Get <IsometricMapComponent>();

                    if (Map.Terrain == null)
                    {
                        Map.CreateMap(Map.SpriteSheetName, Map.TxWidth, Map.TxHeight, Map.PxTileWidth, Map.PxTileHeight);

                        // replace the map
                        e.Entity.RemoveComponent(e.Entity.Get <IsometricMapComponent>());
                        e.Entity.AddComponent(Map);
                    }
                    break;

                case "PositionComponent":
                    PositionComponent position = (PositionComponent)c;

                    if (!String.IsNullOrWhiteSpace(position.GenerateAt))
                    {
                        int xIndex = -1;
                        int yIndex = -1;

                        switch (position.GenerateAt)
                        {
                        // random
                        case "Edge":
                            int side = Random.Next(4);

                            switch (side)
                            {
                            case 0:
                                // northwest
                                xIndex = 0;
                                yIndex = Random.Next(1, Map.TxHeight);
                                break;

                            case 1:
                                // northeast
                                xIndex = Random.Next(1, Map.TxWidth);
                                yIndex = 0;
                                break;

                            case 2:
                                // southeast
                                xIndex = Map.TxWidth - 1;
                                yIndex = Random.Next(1, Map.TxHeight);
                                break;

                            default:
                                // southwest
                                xIndex = Random.Next(1, Map.TxWidth);
                                yIndex = Map.TxHeight - 1;
                                break;
                            }
                            break;

                        case "NoEdge":
                            xIndex = Random.Next(1, Map.TxWidth - 1);
                            yIndex = Random.Next(1, Map.TxHeight - 1);
                            break;

                        default:
                            xIndex = Random.Next(0, Map.TxWidth);
                            yIndex = Random.Next(0, Map.TxHeight);
                            break;
                        }

                        Vector2 pos = Map.GetPositionFromIndex(xIndex, yIndex);

                        position.X          = pos.X;
                        position.Y          = pos.Y;
                        position.Index      = new Point(xIndex, yIndex);
                        position.GenerateAt = String.Empty;
                        index = position.Index;
                    }
                    break;

                case "RoadComponent":
                    // setup the road component
                    RoadComponent road = (RoadComponent)c;
                    road.BuiltAt = index;

                    // update the planner
                    Roads.AddOrUpdate(this, e.Entity, true);
                    break;

                case "RoadPlannerComponent":
                    Roads = (RoadPlannerComponent)c;
                    break;

                case "SpawnerComponent":
                    break;
                }
            }
        }