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; } } }