Beispiel #1
0
        public Cargo(ActorInitializer init, CargoInfo info)
        {
            self             = init.Self;
            Info             = info;
            checkTerrainType = info.UnloadTerrainTypes.Count > 0;

            currentAdjacentCells = new CachedTransform <CPos, IEnumerable <CPos> >(loc =>
            {
                return(Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => loc != c));
            });

            var runtimeCargoInit = init.GetOrDefault <RuntimeCargoInit>(info);
            var cargoInit        = init.GetOrDefault <CargoInit>(info);

            if (runtimeCargoInit != null)
            {
                cargo       = runtimeCargoInit.Value.ToList();
                totalWeight = cargo.Sum(c => GetWeight(c));
            }
            else if (cargoInit != null)
            {
                foreach (var u in cargoInit.Value)
                {
                    var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
                                                      new TypeDictionary {
                        new OwnerInit(self.Owner)
                    });

                    cargo.Add(unit);
                }

                totalWeight = cargo.Sum(c => GetWeight(c));
            }
            else
            {
                foreach (var u in info.InitialUnits)
                {
                    var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
                                                      new TypeDictionary {
                        new OwnerInit(self.Owner)
                    });

                    cargo.Add(unit);
                }

                totalWeight = cargo.Sum(c => GetWeight(c));
            }

            facing = Exts.Lazy(self.TraitOrDefault <IFacing>);
        }
Beispiel #2
0
        public Cargo(ActorInitializer init, CargoInfo info)
        {
            self             = init.Self;
            Info             = info;
            Unloading        = false;
            checkTerrainType = info.UnloadTerrainTypes.Count > 0;
            upgradeManager   = self.Trait <UpgradeManager>();

            if (init.Contains <RuntimeCargoInit>())
            {
                cargo       = new Stack <Actor>(init.Get <RuntimeCargoInit, Actor[]>());
                totalWeight = cargo.Sum(c => GetWeight(c));
            }
            else if (init.Contains <CargoInit>())
            {
                foreach (var u in init.Get <CargoInit, string[]>())
                {
                    var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
                                                      new TypeDictionary {
                        new OwnerInit(self.Owner)
                    });

                    cargo.Push(unit);
                }

                totalWeight = cargo.Sum(c => GetWeight(c));
            }
            else
            {
                foreach (var u in info.InitialUnits)
                {
                    var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
                                                      new TypeDictionary {
                        new OwnerInit(self.Owner)
                    });

                    cargo.Push(unit);
                }

                totalWeight = cargo.Sum(c => GetWeight(c));
            }

            facing = Exts.Lazy(self.TraitOrDefault <IFacing>);
        }