public void AddOrUpdate(GameWorld world, Entity e, bool recursion = false) { RoadComponent road = e.Get <RoadComponent>(); string value = "dirt-road-" + GetRoadValue(world.Map, road.BuiltAt); // set the value of built into the roadPlanner if (!Built.ContainsKey(road.BuiltAt)) { Built.Add(road.BuiltAt, value); } else { Built[road.BuiltAt] = value; } if (road.Updateable) { DrawableComponent drawable = e.Get <DrawableComponent>(); foreach (GameDrawable sprite in drawable.Drawables["Foundation"].ToList()) { if (sprite.PrototypeID.Contains("road")) { // remove old road drawables drawable.Drawables["Foundation"].Remove(sprite); } } road.RoadType = Built[road.BuiltAt]; drawable.Add("Foundation", (GameDrawable)world.Prototypes[road.RoadType]); } if (recursion) { UpdateNeighbors(world, e); } }
private void UpdateNeighbors(GameWorld world, Entity e) { RoadComponent road = e.Get <RoadComponent>(); Point location = new Point(road.BuiltAt.X - 1, road.BuiltAt.Y); // update the neighbors to account for this one if (world.Map.IsValidIndex(location) && IsRoadAt(location)) { AddOrUpdate(world, GetRoadAtOffset(world, e, -1, 0)); } location = new Point(road.BuiltAt.X, road.BuiltAt.Y - 1); if (world.Map.IsValidIndex(location) && IsRoadAt(location)) { AddOrUpdate(world, GetRoadAtOffset(world, e, 0, -1)); } location = new Point(road.BuiltAt.X + 1, road.BuiltAt.Y); if (world.Map.IsValidIndex(location) && IsRoadAt(location)) { AddOrUpdate(world, GetRoadAtOffset(world, e, 1, 0)); } location = new Point(road.BuiltAt.X, road.BuiltAt.Y + 1); if (world.Map.IsValidIndex(location) && IsRoadAt(location)) { AddOrUpdate(world, GetRoadAtOffset(world, e, 0, 1)); } }
private Entity GetRoadAtOffset(GameWorld world, Entity e, int x, int y) { RoadComponent road = e.Get <RoadComponent>(); Point p = new Point(road.BuiltAt.X + x, road.BuiltAt.Y + y); uint id = world.Foundations.SpaceTaken[p]; return(world.Entities.Get(id)); }