Пример #1
0
 protected override void Load(StackReader reader, Map map)
 {
     foreach (var stack in reader)
     {
         var type    = stack.PopEnum <VehicleType>();
         var routeId = stack.PopId();
         if (routeId == Guid.Empty)
         {
             map.AddAvailableVehicle(type);
             continue;
         }
         var routeIdx = stack.PopInt();
         var frontPos = stack.PopFloat();
         var route    = map.GetRoute(routeId);
         if (route == null)
         {
             Error($"Vehicle route {routeId} not found");
             continue;
         }
         var vehicle = Vehicle.Create(type, route);
         vehicle.SetPosition(routeIdx, frontPos);
         if (vehicle is Hauler h)
         {
             h.Carrying = stack.PopInt();
             route.AddHauler(h);
         }
     }
 }
Пример #2
0
 protected override void Load(StackReader reader, Map map)
 {
     while (reader.TryGetStack(out var stack))
     {
         var pos      = stack.PopIntVector();
         var type     = stack.PopEnum <BuildingType>();
         var building = Building.Create(map, type, pos);
         if (building is Workshop w)
         {
             w.Recipe = Recipes.GetRecipe(stack.PopString());
         }
         if (building.Output is DirectProducer p)
         {
             p.SetBuffer(stack.PopInt());
         }
         if (building.Input is DirectConsumer c)
         {
             while (stack.HasItem())
             {
                 var item   = stack.PopEnum <Item>();
                 int amount = stack.PopInt();
                 c.GetBuffer(item).Buffer = amount;
             }
         }
         map.AddBuilding(building, pos);
     }
 }
Пример #3
0
        protected override void Load(StackReader reader, Map map)
        {
            while (reader.TryGetStack(out var stack))
            {
                var route = new Route(map);
                var id    = stack.PopId();
                var dests = stack.PopInt();

                route.SetId(id);

                for (int i = 0; i < dests; i++)
                {
                    var(pos, type, item) = (stack.PopIntVector(), stack.PopEnum <Route.ActionType>(), stack.PopEnum <Item>());
                    var node = map.GetNode(pos);
                    if (node == null)
                    {
                        throw new NullReferenceException($"Node {pos} on map is null or does not exist");
                    }
                    route.AddDestination(node, type, item);
                }
                var path = new List <VehicleNode>();
                while (stack.HasItem())
                {
                    var pos  = stack.PopIntVector();
                    var node = map.GetNode(pos);
                    if (node == null)
                    {
                        throw new NullReferenceException($"Node {pos} on map is null or does not exist");
                    }
                    path.Add(node);
                }
                route.SetPath(path);
                map.AddRoute(route);
            }
        }
Пример #4
0
 protected override void Load(StackReader reader, Map map)
 {
     foreach (var stack in reader)
     {
         var item   = stack.PopEnum <Item>();
         var amount = stack.PopInt();
         map.SetResourceAmount(item, amount);
     }
 }
Пример #5
0
 protected override void Load(StackReader reader, Map map)
 {
     while (reader.TryGetStack(out var stack))
     {
         var source = stack.PopIntVector();
         var dest   = stack.PopIntVector();
         var type   = stack.PopEnum <PathType>();
         map.BuildPath(type, source, dest);
     }
 }
Пример #6
0
 public Enumerator(StackReader reader)
 {
     Current = default(StackEntry);
     _reader = reader;
 }
Пример #7
0
 protected abstract void Load(StackReader reader, Map map);
Пример #8
0
 public void Load(Stream stream, Map map)
 {
     using (var reader = new StackReader(stream)) { Load(reader, map); }
 }