Beispiel #1
0
        void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
        {
            // Unlink any harvesters
            foreach (var harv in GetLinkedHarvesters())
            {
                harv.Trait.UnlinkProc(harv.Actor, self);
            }

            playerResources = newOwner.PlayerActor.Trait <PlayerResources>();
        }
 protected override void Created(Actor self)
 {
     // Special case handling is required for the Player actor.
     // Created is called before Player.PlayerActor is assigned,
     // so we must query player traits from self, which refers
     // for bot modules always to the Player actor.
     playerPower             = self.TraitOrDefault <PowerManager>();
     playerResources         = self.Trait <PlayerResources>();
     positionsUpdatedModules = self.TraitsImplementing <IBotPositionsUpdated>().ToArray();
 }
Beispiel #3
0
        void INotifyCreated.Created(Actor self)
        {
            playerPower     = self.Owner.PlayerActor.TraitOrDefault <PowerManager>();
            playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();
            developerMode   = self.Owner.PlayerActor.Trait <DeveloperMode>();
            techTree        = self.Owner.PlayerActor.Trait <TechTree>();

            productionTraits = self.TraitsImplementing <Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
            CacheProducibles(self.Owner.PlayerActor);
        }
 public SupportPowerBotModule(Actor self, SupportPowerBotModuleInfo info)
     : base(info)
 {
     world  = self.World;
     player = self.Owner;
     self.World.AddFrameEndTask(w =>
     {
         playerResource = player.PlayerActor.Trait <PlayerResources>();
     });
 }
Beispiel #5
0
        public void Tick(PlayerResources pr)
        {
            if (!Started)
            {
                var time = Queue.GetBuildTime(ai, bi);
                if (time > 0)
                {
                    RemainingTime = TotalTime = time;
                }

                Started = true;
            }

            if (Done)
            {
                OnComplete?.Invoke();

                return;
            }

            if (Paused)
            {
                return;
            }

            if (pm != null && pm.PowerState != PowerState.Normal)
            {
                Slowdown -= 100;
                if (Slowdown < 0)
                {
                    Slowdown = Queue.Info.LowPowerModifier + Slowdown;
                }
                else
                {
                    return;
                }
            }

            var expectedRemainingCost = RemainingTime == 1 ? 0 : TotalCost * RemainingTime / Math.Max(1, TotalTime);
            var costThisFrame         = RemainingCost - expectedRemainingCost;

            if (costThisFrame != 0 && !pr.TakeCash(costThisFrame, true))
            {
                return;
            }

            RemainingCost -= costThisFrame;
            RemainingTime -= 1;
            if (RemainingTime > 0)
            {
                return;
            }

            Done = true;
        }
Beispiel #6
0
        void INotifyCreated.Created(Actor self)
        {
            // Special case handling is required for the Player actor.
            // Created is called before Player.PlayerActor is assigned,
            // so we must query other player traits from self, knowing that
            // it refers to the same actor as self.Owner.PlayerActor
            var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;

            playerResources  = playerActor.Trait <PlayerResources>();
            conditionManager = self.TraitOrDefault <ConditionManager>();
        }
Beispiel #7
0
 public BaseBuilderQueueManager(BaseBuilderBotModule baseBuilder, string category, Player p, PowerManager pm,
                                PlayerResources pr, BitArray resourceTypeIndices)
 {
     this.baseBuilder         = baseBuilder;
     world                    = p.World;
     player                   = p;
     playerPower              = pm;
     playerResources          = pr;
     this.category            = category;
     failRetryTicks           = baseBuilder.Info.StructureProductionResumeDelay;
     minimumExcessPower       = baseBuilder.Info.MinimumExcessPower;
     this.resourceTypeIndices = resourceTypeIndices;
 }
Beispiel #8
0
        public ProductionQueue(ActorInitializer init, Actor playerActor, ProductionQueueInfo info)
        {
            self            = init.Self;
            Info            = info;
            playerResources = playerActor.Trait <PlayerResources>();
            playerPower     = playerActor.Trait <PowerManager>();
            developerMode   = playerActor.Trait <DeveloperMode>();

            Race    = init.Contains <RaceInit>() ? init.Get <RaceInit, string>() : self.Owner.Faction.InternalName;
            Enabled = !info.Race.Any() || info.Race.Contains(Race);

            CacheProduceables(playerActor);
        }
Beispiel #9
0
        public ProductionQueue(ActorInitializer init, Actor playerActor, ProductionQueueInfo info)
        {
            self            = init.Self;
            Info            = info;
            playerResources = playerActor.Trait <PlayerResources>();
            developerMode   = playerActor.Trait <DeveloperMode>();

            Faction        = init.Contains <FactionInit>() ? init.Get <FactionInit, string>() : self.Owner.Faction.InternalName;
            IsValidFaction = !info.Factions.Any() || info.Factions.Contains(Faction);
            Enabled        = IsValidFaction;

            CacheProducibles(playerActor);
            allProducibles       = producible.Where(a => a.Value.Buildable || a.Value.Visible).Select(a => a.Key);
            buildableProducibles = producible.Where(a => a.Value.Buildable).Select(a => a.Key);
        }
Beispiel #10
0
        public WithResources(Actor self, WithResourcesInfo info)
        {
            this.info       = info;
            rs              = self.Trait <RenderSimple>();
            playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();

            var a = new Animation(self.World, rs.GetImage(self));

            a.PlayFetchIndex(info.Sequence, () =>
                             playerResources.ResourceCapacity != 0 ?
                             ((10 * a.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) :
                             0);

            anim = new AnimationWithOffset(a, null, () => !buildComplete, 1024);
            rs.Add(anim);
        }
Beispiel #11
0
        void INotifyCreated.Created(Actor self)
        {
            // Special case handling is required for the Player actor.
            // Created is called before Player.PlayerActor is assigned,
            // so we must query other player traits from self, knowing that
            // it refers to the same actor as self.Owner.PlayerActor
            var playerActor = self.Info.Name == "player" ? self : self.Owner.PlayerActor;

            playerPower     = playerActor.TraitOrDefault <PowerManager>();
            playerResources = playerActor.Trait <PlayerResources>();
            developerMode   = playerActor.Trait <DeveloperMode>();
            techTree        = playerActor.Trait <TechTree>();

            productionTraits = self.TraitsImplementing <Production>().Where(p => p.Info.Produces.Contains(Info.Type)).ToArray();
            CacheProducibles(playerActor);
        }
 public BaseBuilderQueueManager(BaseBuilderBotModule baseBuilder, string category, Player p, PowerManager pm,
                                PlayerResources pr, IResourceLayer rl)
 {
     this.baseBuilder   = baseBuilder;
     world              = p.World;
     player             = p;
     playerPower        = pm;
     playerResources    = pr;
     resourceLayer      = rl;
     this.category      = category;
     failRetryTicks     = baseBuilder.Info.StructureProductionResumeDelay;
     minimumExcessPower = baseBuilder.Info.MinimumExcessPower;
     if (!baseBuilder.Info.NavalProductionTypes.Any())
     {
         waterState = WaterCheck.DontCheck;
     }
 }
Beispiel #13
0
        public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
        {
            ClearQueue();

            playerPower     = newOwner.PlayerActor.Trait <PowerManager>();
            playerResources = newOwner.PlayerActor.Trait <PlayerResources>();
            developerMode   = newOwner.PlayerActor.Trait <DeveloperMode>();

            if (!Info.Sticky)
            {
                Race    = self.Owner.Faction.InternalName;
                Enabled = !Info.Race.Any() || Info.Race.Contains(Race);
            }

            // Regenerate the produceables and tech tree state
            oldOwner.PlayerActor.Trait <TechTree>().Remove(this);
            CacheProduceables(newOwner.PlayerActor);
            newOwner.PlayerActor.Trait <TechTree>().Update();
        }
Beispiel #14
0
        void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
        {
            ClearQueue();

            playerPower     = newOwner.PlayerActor.Trait <PowerManager>();
            playerResources = newOwner.PlayerActor.Trait <PlayerResources>();
            developerMode   = newOwner.PlayerActor.Trait <DeveloperMode>();

            if (!Info.Sticky)
            {
                Faction        = self.Owner.Faction.InternalName;
                IsValidFaction = !Info.Factions.Any() || Info.Factions.Contains(Faction);
            }

            // Regenerate the producibles and tech tree state
            oldOwner.PlayerActor.Trait <TechTree>().Remove(this);
            CacheProducibles(newOwner.PlayerActor);
            newOwner.PlayerActor.Trait <TechTree>().Update();
        }
        protected override void TraitEnabled(Actor self)
        {
            playerPower             = player.PlayerActor.TraitOrDefault <PowerManager>();
            playerResources         = player.PlayerActor.Trait <PlayerResources>();
            positionsUpdatedModules = player.PlayerActor.TraitsImplementing <IBotPositionsUpdated>().ToArray();

            var tileset = world.Map.Rules.TileSet;

            resourceTypeIndices = new BitArray(tileset.TerrainInfo.Length);             // Big enough
            foreach (var t in world.Map.Rules.Actors["world"].TraitInfos <ResourceTypeInfo>())
            {
                resourceTypeIndices.Set(tileset.GetTerrainIndex(t.TerrainType), true);
            }

            foreach (var building in Info.BuildingQueues)
            {
                builders.Add(new BaseBuilderQueueManager(this, building, player, playerPower, playerResources, resourceTypeIndices));
            }
            foreach (var defense in Info.DefenseQueues)
            {
                builders.Add(new BaseBuilderQueueManager(this, defense, player, playerPower, playerResources, resourceTypeIndices));
            }
        }
 public override void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
 {
     playerResources = newOwner.PlayerActor.Trait <PlayerResources>();
     base.OnOwnerChanged(self, oldOwner, newOwner);
 }
Beispiel #17
0
 void INotifyCreated.Created(Actor self)
 {
     playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();
 }
Beispiel #18
0
 void INotifyCreated.Created(Actor self)
 {
     resources  = self.TraitOrDefault <PlayerResources>();
     experience = self.TraitOrDefault <PlayerExperience>();
 }
 public ResourceStorageWarning(Actor self, ResourceStorageWarningInfo info)
 {
     this.info = info;
     resources = self.Trait <PlayerResources>();
 }
Beispiel #20
0
 void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
 {
     player = newOwner.PlayerActor.Trait <PlayerResources>();
 }
Beispiel #21
0
 public StoresResources(Actor self, StoresResourcesInfo info)
 {
     this.info = info;
     player    = self.Owner.PlayerActor.Trait <PlayerResources>();
 }
Beispiel #22
0
 public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
 {
     player = newOwner.PlayerActor.Trait <PlayerResources>();
 }
Beispiel #23
0
 public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info)
 {
     this.info       = info;
     wsb             = init.Self.Trait <WithSpriteBody>();
     playerResources = init.Self.Owner.PlayerActor.Trait <PlayerResources>();
 }
 protected override void Created(Actor self)
 {
     playerPower             = self.Owner.PlayerActor.TraitOrDefault <PowerManager>();
     playerResources         = self.Owner.PlayerActor.Trait <PlayerResources>();
     positionsUpdatedModules = self.Owner.PlayerActor.TraitsImplementing <IBotPositionsUpdated>().ToArray();
 }
Beispiel #25
0
        protected override void Created(Actor self)
        {
            resources = self.Owner.PlayerActor.Trait <PlayerResources>();

            base.Created(self);
        }
 public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info)
     : base(init, info)
 {
     this.info       = info;
     playerResources = init.Self.Owner.PlayerActor.Trait <PlayerResources>();
 }