예제 #1
0
        private void Date_Changed(GameDateComponent sender)
        {
            foreach (Entity e in collapsibles)
            {
                CollapsibleComponent c = e.Get <CollapsibleComponent>();

                c.Value--;

                // TODO: collapse the entity if the value is below 0
            }
        }
        public override void Update(double dt)
        {
            _updateCountdown -= dt;

            if (_updateCountdown <= 0)
            {
                _updateCountdown += _updateRate;

                if (_dateEntity != null)
                {
                    GameDateComponent date = _dateEntity.Get <GameDateComponent>();
                    date.Time++;
                }
            }
        }
예제 #3
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;
                }
            }
        }
        private void Date_TimeChanged(GameDateComponent sender)
        {
            long elapsed = World.Date.MinutesElapsed(lastUpdate);

            lastUpdate = World.Date.Time;

            List <Entity> producers = World.Entities.FindAll(delegate(Entity e) { return(e.HasComponent <ProductionComponent>()); });

            foreach (Entity e in producers)
            {
                ProductionComponent p = e.Get <ProductionComponent>();

                if (string.IsNullOrWhiteSpace(p.Recipe))
                {
                    continue;
                }

                // determines how much work is done
                // TODO: check for divide by zero?
                float workerPercentage = (float)p.Employees.Length / (float)p.MaxEmployees;

                p.WorkDone += (elapsed * workerPercentage);

                Recipe r = (Recipe)World.Prototypes[p.Recipe];
                if (p.WorkDone >= r.Stages[p.CurrentStage].WorkRequired)
                {
                    // TODO: check the inputs and modify or elminate the output based on the amount of inputs present
                    // store output in the inventory
                    Inventory   inventory = e.Get <Inventory>();
                    RecipeStage stage     = r.Stages[p.CurrentStage];

                    foreach (RecipeOutput output in stage.Outputs)
                    {
                        inventory.Add(output.Item, output.AmountProduced);
                        // make sure the newly produced item is marked as output
                        inventory.Items[output.Item].Output = true;
                    }

                    // go to next stage in the recipe
                    p.CurrentStage++;
                    if (p.CurrentStage >= r.Stages.Count)
                    {
                        p.CurrentStage = 0;
                    }

                    // reset the work done
                    p.WorkDone = 0;

                    // update the drawables
                    DrawableComponent drawable = e.Get <DrawableComponent>();
                    stage = r.Stages[p.CurrentStage];

                    // remove
                    foreach (string str in stage.RemoveFromDrawableComponent)
                    {
                        drawable.RemoveByPrototypeID(str);
                    }

                    // add
                    foreach (string str in stage.AddToDrawableComponent)
                    {
                        GameDrawable igd = (GameDrawable)World.Prototypes[str];

                        drawable.Add(igd.Layer, igd);
                    }
                }
            }
        }
예제 #5
0
 private void Date_TimeChanged(GameDateComponent sender)
 {
     date.Text = GetTimeText();
 }