public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
 {
     var ore = Stored;
     Player.TakeOre(ore);
     Player = newOwner.PlayerActor.Trait<PlayerResources>();
     Player.GiveOre(ore);
 }
Exemplo n.º 2
0
 public OreRefinery(Actor self, OreRefineryInfo info)
 {
     this.self = self;
     Info = info;
     PlayerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
     currentDisplayTick = Info.TickRate;
 }
Exemplo n.º 3
0
        public void Tick(PlayerResources pr)
        {
            if (Done)
            {
                if (OnComplete != null) OnComplete();
                return;
            }

            if (Paused) return;

            if (pm.PowerState != PowerState.Normal)
            {
                if (--slowdown <= 0)
                    slowdown = Queue.Info.LowPowerSlowdown;
                else
                    return;
            }

            var costThisFrame = RemainingCost / RemainingTime;
            if (costThisFrame != 0 && !pr.TakeCash(costThisFrame)) return;
            RemainingCost -= costThisFrame;
            RemainingTime -= 1;
            if (RemainingTime > 0) return;

            Done = true;
        }
Exemplo n.º 4
0
        void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
        {
            if (Info.UseFuelReserve)
                fueltank = newOwner.PlayerActor.Trait<Fueltank>();

            resources = newOwner.PlayerActor.TraitOrDefault<PlayerResources>();
        }
Exemplo n.º 5
0
 public Sell(Actor self)
 {
     health = self.TraitOrDefault<Health>();
     sellableInfo = self.Info.TraitInfo<SellableInfo>();
     playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
     IsInterruptible = false;
 }
Exemplo n.º 6
0
 public OreRefinery(Actor self, OreRefineryInfo info)
 {
     this.self = self;
     Info = info;
     PlayerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
     PlayerPower = self.Owner.PlayerActor.Trait<PowerManager>();
 }
Exemplo n.º 7
0
 public OreRefinery(Actor self, OreRefineryInfo info)
 {
     this.self = self;
     Info = info;
     Player = self.Owner.PlayerActor.Trait<PlayerResources> ();
     LinkedHarv = new List<Actor> ();
 }
Exemplo n.º 8
0
		public BaseBuilder(HackyAI ai, string category, Player p, PowerManager pm, PlayerResources pr)
		{
			this.ai = ai;
			world = p.World;
			player = p;
			playerPower = pm;
			playerResources = pr;
			this.category = category;
		}
Exemplo n.º 9
0
        public FuelGenerator(Actor self, FuelGeneratorInfo info)
        {
            Info = info;

            var source = info.UseFuelReserve ? self.Owner.PlayerActor : self;
            fueltank = source.Trait<Fueltank>();
            resources = self.Owner.PlayerActor.TraitOrDefault<PlayerResources>();
            ticks = info.Interval;
        }
Exemplo n.º 10
0
		public BaseBuilder(HackyAI ai, string category, Player p, PowerManager pm, PlayerResources pr)
		{
			this.ai = ai;
			world = p.World;
			player = p;
			playerPower = pm;
			playerResources = pr;
			this.category = category;
			failRetryTicks = ai.Info.StructureProductionResumeDelay;
		}
Exemplo n.º 11
0
        public IngameCashCounterLogic(Widget widget, World world)
        {
            var cash = widget.Get<LabelWithTooltipWidget>("CASH");

            this.world = world;
            player = world.LocalPlayer;
            playerResources = player.PlayerActor.Trait<PlayerResources>();
            displayResources = playerResources.Cash + playerResources.Resources;
            cashLabel = cash.Text;
            displayLabel = cashLabel.F(displayResources);

            cash.GetText = () => displayLabel;
            cash.GetTooltipText = () => "Silo Usage: {0}/{1}".F(playerResources.Resources, playerResources.ResourceCapacity);
        }
Exemplo n.º 12
0
        public RenderBuildingRefinery(ActorInitializer init, RenderBuildingInfo info)
            : base(init, info)
        {
            playerResources = init.self.Owner.PlayerActor.Trait<PlayerResources>();

            lights = new Animation(GetImage(init.self));
            lights.PlayFetchIndex("lights",
                () => playerResources.OreCapacity != 0
                    ? (59 * playerResources.Ore) / (10 * playerResources.OreCapacity)
                    : 0);

            var offset = new float2(-32,-21);
            anims.Add("lights", new AnimationWithOffset( lights, wr => offset, () => !buildComplete )
                { ZOffset = 24 });
        }
Exemplo n.º 13
0
        public void Activate(Player p)
        {
            this.p = p;
            this.world = p.World;
            GameStarted = true;

            random = new XRandom((int)p.PlayerActor.ActorID);

            SpecialPowers = p.PlayerActor.Trait<SupportPowerManager>();
            Power = p.PlayerActor.Trait<PowerManager>();
            Resources = p.PlayerActor.Trait<PlayerResources>();

            squadmanager = new SquadManager(this);

            // Initialize builders
            Builders = new List<IAIBuilder>() { new BaseBuilder(this), new DefenseBuilder(this),
                new InfantryBuilder(this), new VehicleBuilder(this),
                new AircraftBuilder(this), new ShipBuilder(this) };

            // Have the bot cheat, gets free 500 000 credits at the start of the match
            Resources.GiveCash(500000);
        }
Exemplo n.º 14
0
 public MoneyBinWidget(World world)
 {
     this.world = world;
     playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
 }
Exemplo n.º 15
0
 public RenderBuildingSilo( ActorInitializer init, RenderBuildingSiloInfo info )
     : base(init, info)
 {
     playerResources = init.self.Owner.PlayerActor.Trait<PlayerResources>();
 }
Exemplo n.º 16
0
        public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
        {
            PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
            playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
            ClearQueue();

            // Produceable contains the tech from the original owner - this is desired so we don't clear it.
            Produceable = InitTech(self.Owner.PlayerActor);

            // Force a third(!) tech tree update to ensure that prerequisites are correct.
            // The first two updates are triggered by adding/removing the actor when
            // changing ownership, *before* the new techtree watchers have been set up.
            // This is crap.
            self.Owner.PlayerActor.Trait<TechTree>().Update();
        }
Exemplo n.º 17
0
 public SiloBarWidget( [ObjectCreator.Param] World world )
 {
     pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
     tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
         Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
 }
Exemplo n.º 18
0
        public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
        {
            PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
            PlayerResources = newOwner.PlayerActor.Trait<PlayerResources>();
            Queue.Clear();

            // Produceable contains the tech from the original owner - this is desired so we don't clear it.
            Produceable = InitTech(self.Owner.PlayerActor);
        }
Exemplo n.º 19
0
        public ProductionQueue( Actor self, Actor playerActor, ProductionQueueInfo info )
        {
            this.self = self;
            this.Info = info;
            playerResources = playerActor.Trait<PlayerResources>();
            PlayerPower = playerActor.Trait<PowerManager>();

            Race = self.Owner.Country;
            Produceable = InitTech(playerActor);
        }
Exemplo n.º 20
0
 public SiloBarWidget(World world)
 {
     pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
     tooltipContainer = Lazy.New(() =>
         Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
 }
Exemplo n.º 21
0
 public DebugResourceOreCapacity(Actor self)
 {
     pr = self.Trait <PlayerResources>();
 }
Exemplo n.º 22
0
		public StoresResources(Actor self, StoresResourcesInfo info)
		{
			player = self.Owner.PlayerActor.Trait<PlayerResources>();
			this.info = info;
		}
Exemplo n.º 23
0
		public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
		{
			player = newOwner.PlayerActor.Trait<PlayerResources>();
		}
Exemplo n.º 24
0
		// Called by the host's player creation code
		public void Activate(Player p)
		{
			Player = p;
			enabled = true;
			playerPower = p.PlayerActor.Trait<PowerManager>();
			supportPowerMngr = p.PlayerActor.Trait<SupportPowerManager>();
			playerResource = p.PlayerActor.Trait<PlayerResources>();

			foreach (var building in Info.BuildingQueues)
				builders.Add(new BaseBuilder(this, building, p, playerPower, playerResource));
			foreach (var defense in Info.DefenseQueues)
				builders.Add(new BaseBuilder(this, defense, p, playerPower, playerResource));

			Random = new MersenneTwister((int)p.PlayerActor.ActorID);

			// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
			var smallFractionOfRushInterval = Info.RushInterval / 20;
			rushTicks = Random.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);

			// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
			assignRolesTicks = Random.Next(0, Info.AssignRolesInterval);
			attackForceTicks = Random.Next(0, Info.AttackForceInterval);
			minAttackForceDelayTicks = Random.Next(0, Info.MinimumAttackForceDelay);

			resourceTypeIndices = new BitArray(World.TileSet.TerrainInfo.Length); // Big enough
			foreach (var t in Map.Rules.Actors["world"].TraitInfos<ResourceTypeInfo>())
				resourceTypeIndices.Set(World.TileSet.GetTerrainIndex(t.TerrainType), true);
		}
Exemplo n.º 25
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.Country.Race;
            Enabled = !info.Race.Any() || info.Race.Contains(Race);

            CacheProduceables(playerActor);
        }
Exemplo n.º 26
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.Country.Race;
                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();
        }
Exemplo n.º 27
0
        public void 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>();
        }
Exemplo n.º 28
0
 public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
 {
     playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
 }
Exemplo n.º 29
0
 public DebugResourceCash(Actor self)
 {
     pr = self.Trait <PlayerResources>();
 }
Exemplo n.º 30
0
 public StoresOre(Actor self, StoresOreInfo info)
 {
     Player = self.Owner.PlayerActor.Trait<PlayerResources>();
     Info = info;
 }
Exemplo n.º 31
0
        public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
        {
            // Steal any docked harv too
            if (dockedHarv != null)
                dockedHarv.ChangeOwner(newOwner);

            // Unlink any non-docked harvs
            foreach (var harv in GetLinkedHarvesters())
                if (harv.Actor.Owner == oldOwner)
                    harv.Trait.UnlinkProc(harv.Actor, self);

            PlayerResources = newOwner.PlayerActor.Trait<PlayerResources>();
        }
Exemplo n.º 32
0
        public ProductionQueue( Actor self, Actor playerActor, ProductionQueueInfo info )
        {
            this.self = self;
            this.Info = info;
            PlayerResources = playerActor.Trait<PlayerResources>();
            PlayerPower = playerActor.Trait<PowerManager>();

            var ttc = playerActor.Trait<TechTree>();

            foreach (var a in AllBuildables(Info.Type))
            {
                var bi = a.Traits.Get<BuildableInfo>();
                // Can our race build this by satisfying normal prereqs?
                var buildable = bi.Owner.Contains(self.Owner.Country.Race);
                Produceable.Add( a, new ProductionState(){ Visible = buildable && !bi.Hidden } );
                if (buildable)
                    ttc.Add( a.Name, a.Traits.Get<BuildableInfo>().Prerequisites.ToList(), this );
            }
        }