void UpdateRenderedSpriteInner(CPos cell, RendererCellContents content) { if (content.Density > 0) { var clear = FindClearSides(cell, content.Type); if (clear == ClearSides.None) { var maxDensity = ResourceLayer.GetMaxDensity(content.Type); var index = content.Density > maxDensity / 2 ? 1 : 0; UpdateSpriteLayers(cell, content.Sequence, index, content.Palette); } else if (SpriteMap.TryGetValue(clear, out var index)) { UpdateSpriteLayers(cell, content.Sequence, index, content.Palette); } else { throw new InvalidOperationException($"SpriteMap does not contain an index for ClearSides type '{clear}'"); } } else { UpdateSpriteLayers(cell, null, 0, null); } }
public PlaceBuildingOrderGenerator(ProductionQueue queue, string name, WorldRenderer worldRenderer) { var world = queue.Actor.World; this.queue = queue; placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo <PlaceBuildingInfo>(); buildingInfluence = world.WorldActor.Trait <BuildingInfluence>(); resourceLayer = world.WorldActor.TraitOrDefault <ResourceLayer>(); viewport = worldRenderer.Viewport; // Clear selection if using Left-Click Orders if (Game.Settings.Game.UseClassicMouseStyle) { world.Selection.Clear(); } var variants = new List <VariantWrapper>() { new VariantWrapper(worldRenderer, queue, world.Map.Rules.Actors[name]) }; foreach (var v in variants[0].ActorInfo.TraitInfos <PlaceBuildingVariantsInfo>()) { foreach (var a in v.Actors) { variants.Add(new VariantWrapper(worldRenderer, queue, world.Map.Rules.Actors[a])); } } this.variants = variants.ToArray(); }
public static bool CanHarvestAt(this Actor self, CPos pos, ResourceLayer resLayer, HarvesterInfo harvInfo, ResourceClaimLayer territory) { var resType = resLayer.GetResource(pos); if (resType == null) { return(false); } // Can the harvester collect this kind of resource? if (!harvInfo.Resources.Contains(resType.Info.Name)) { return(false); } if (territory != null) { // Another harvester has claimed this resource: ResourceClaim claim; if (territory.IsClaimedByAnyoneElse(self as Actor, pos, out claim)) { return(false); } } return(true); }
public HackyAI(HackyAIInfo info, ActorInitializer init) { Info = info; World = init.World; if (World.Type == WorldType.Editor) { return; } domainIndex = World.WorldActor.Trait <DomainIndex>(); resLayer = World.WorldActor.Trait <ResourceLayer>(); territory = World.WorldActor.TraitOrDefault <ResourceClaimLayer>(); pathfinder = World.WorldActor.Trait <IPathFinder>(); isEnemyUnit = unit => Player.Stances[unit.Owner] == Stance.Enemy && !unit.Info.HasTraitInfo <HuskInfo>() && unit.Info.HasTraitInfo <ITargetableInfo>(); unitCannotBeOrdered = a => a.Owner != Player || a.IsDead || !a.IsInWorld; foreach (var decision in info.PowerDecisions) { powerDecisions.Add(decision.OrderName, decision); } }
public HarvestResource(Actor self) { harv = self.Trait <Harvester>(); harvInfo = self.Info.Traits.Get <HarvesterInfo>(); facing = self.Trait <IFacing>(); territory = self.World.WorldActor.TraitOrDefault <ResourceClaimLayer>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); }
public Freighter(Actor self, FreighterInfo info) { Info = info; Contents = new ReadOnlyDictionary <DrResourceTypeInfo, int>(contents); mobile = self.Trait <Mobile>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); }
protected override void TraitEnabled(Actor self) { pathfinder = world.WorldActor.Trait <IPathFinder>(); domainIndex = world.WorldActor.Trait <DomainIndex>(); resLayer = world.WorldActor.TraitOrDefault <ResourceLayer>(); claimLayer = world.WorldActor.TraitOrDefault <ResourceClaimLayer>(); scanForIdleHarvestersTicks = Info.ScanForIdleHarvestersInterval; }
public AIHarvesterManager(HackyAI ai, Player p) { this.ai = ai; world = p.World; pathfinder = world.WorldActor.Trait <IPathFinder>(); domainIndex = world.WorldActor.Trait <DomainIndex>(); resLayer = world.WorldActor.TraitOrDefault <ResourceLayer>(); claimLayer = world.WorldActor.TraitOrDefault <ResourceClaimLayer>(); }
public HarvestResource(Actor self) { harv = self.Trait <Harvester>(); harvInfo = self.Info.TraitInfo <HarvesterInfo>(); facing = self.Trait <IFacing>(); body = self.Trait <BodyOrientation>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); }
public ViewportControllerWidget(World world, WorldRenderer worldRenderer) { this.world = world; this.worldRenderer = worldRenderer; tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer)); resourceLayer = world.WorldActor.TraitOrDefault <ResourceLayer>(); }
public Sandworm(Actor self, SandwormInfo info) : base(self, info) { WormInfo = info; mobile = self.Trait <Mobile>(); attackTrait = self.Trait <AttackBase>(); //manager = self.World.WorldActor.Trait<ActorSpawnManager>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); }
public FindResources(Actor self) { harv = self.Trait <Harvester>(); harvInfo = self.Info.Traits.Get <HarvesterInfo>(); mobile = self.Trait <Mobile>(); mobileInfo = self.Info.Traits.Get <MobileInfo>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); territory = self.World.WorldActor.TraitOrDefault <ResourceClaimLayer>(); pathFinder = self.World.WorldActor.Trait <IPathFinder>(); }
bool allowKicks = true; // allow kicks? public SlaveMinerHarvester(ActorInitializer init, SlaveMinerHarvesterInfo info) : base(init, info) { self = init.Self; this.info = info; mobile = self.Trait <Mobile>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); kickTicks = info.KickDelay; }
public EatResource(Actor self, CPos targetcell) { harv = self.Trait <Sandworm>(); harvInfo = self.Info.TraitInfo <SandwormInfo>(); facing = self.Trait <IFacing>(); body = self.Trait <BodyOrientation>(); move = self.Trait <IMove>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); this.targetCell = targetcell; }
public HarvestResource(Actor self, CPos targetCell) { harv = self.Trait <Harvester>(); harvInfo = self.Info.TraitInfo <HarvesterInfo>(); facing = self.Trait <IFacing>(); body = self.Trait <BodyOrientation>(); move = self.Trait <IMove>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); resLayer = self.World.WorldActor.Trait <ResourceLayer>(); this.targetCell = targetCell; notifyHarvesterActions = self.TraitsImplementing <INotifyHarvesterAction>().ToArray(); }
protected override void TraitEnabled(Actor self) { pathfinder = world.WorldActor.Trait <IPathFinder>(); domainIndex = world.WorldActor.Trait <DomainIndex>(); resLayer = world.WorldActor.TraitOrDefault <ResourceLayer>(); claimLayer = world.WorldActor.TraitOrDefault <ResourceClaimLayer>(); // Avoid all AIs scanning for idle harvesters on the same tick, randomize their initial scan delay. scanForIdleHarvestersTicks = world.LocalRandom.Next(Info.ScanForIdleHarvestersInterval, Info.ScanForIdleHarvestersInterval * 2); scanForEnoughHarvestersTicks = Info.ProduceHarvestersInterval; }
public PlacesResourcesWhenCreated(Actor self, PlacesResourcesWhenCreatedInfo info) : base(info) { resourceLayer = self.World.WorldActor.Trait <ResourceLayer>(); var resourceTypes = self.World.WorldActor.TraitsImplementing <ResourceType>().ToArray(); resourceType = resourceTypes.FirstOrDefault(a => string.Equals(a.Info.Name, info.ResourceType, StringComparison.InvariantCultureIgnoreCase)); if (resourceType == null) { throw new ArgumentException($"Couldn't find resource type: {info.ResourceType}"); } }
public SeedsResourceCA(Actor self, SeedsResourceCAInfo info) : base(info) { Info = info; resourceType = self.World.WorldActor.TraitsImplementing <ResourceType>() .FirstOrDefault(t => t.Info.Type == info.ResourceType); if (resourceType == null) { throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType)); } resLayer = self.World.WorldActor.Trait <ResourceLayer>(); }
public PreyActivity(Actor self, Actor dockact, bool facingDock, Dock d) { info = self.Info.TraitInfo <AcolytePreyInfo>(); wsb = self.Trait <WithSpriteBody>(); dockactor = dockact; lockfacing = facingDock; playanim = true; _d = d; ticks = self.Info.TraitInfo <AcolytePreyInfo>().leechinterval; resLayer = self.World.WorldActor.Trait <ResourceLayer>(); externalCondition = dockact.TraitsImplementing <ExternalCondition>() .FirstOrDefault(t => t.Info.Condition == self.Info.TraitInfo <AcolytePreyInfo>().GrantsCondition&& t.CanGrantCondition(dockactor, self)); }
public HackyAI(HackyAIInfo info, ActorInitializer init) { Info = info; World = init.World; domainIndex = World.WorldActor.Trait <DomainIndex>(); resLayer = World.WorldActor.TraitOrDefault <ResourceLayer>(); claimLayer = World.WorldActor.TraitOrDefault <ResourceClaimLayer>(); pathfinder = World.WorldActor.Trait <IPathFinder>(); isEnemyUnit = unit => Player.Stances[unit.Owner] == Stance.Enemy && !unit.Info.HasTraitInfo <HuskInfo>() && unit.Info.HasTraitInfo <ITargetableInfo>(); unitCannotBeOrdered = a => a.Owner != Player || a.IsDead || !a.IsInWorld; }
public SpiceBloom(ActorInitializer init, SpiceBloomInfo info) { this.info = info; self = init.Self; resLayer = self.World.WorldActor.Trait <ResourceLayer>(); resType = self.World.WorldActor.TraitsImplementing <ResourceType>().First(t => t.Info.Name == info.ResourceType); var render = self.Trait <RenderSprites>(); anim = new AnimationWithOffset(new Animation(init.Self.World, render.GetImage(self)), null, () => self.IsDead); render.Add(anim); respawnTicks = self.World.SharedRandom.Next(info.RespawnDelay[0], info.RespawnDelay[1]); growTicks = self.World.SharedRandom.Next(info.GrowthDelay[0], info.GrowthDelay[1]); anim.Animation.Play(info.GrowthSequences[0]); }
public PreyActivity(Actor self, Actor dockact, bool facingDock, Dock d) { info = self.Info.TraitInfo <AcolytePreyInfo>(); wsb = self.Trait <WithSpriteBody>(); dockactor = dockact; lockfacing = facingDock; playanim = true; this.d = d; ticks = self.Info.TraitInfo <AcolytePreyInfo>().Leechinterval; resLayer = self.World.WorldActor.Trait <ResourceLayer>(); conditionManager = self.Trait <ConditionManager>(); token = ConditionManager.InvalidConditionToken; condtion = self.Info.TraitInfo <AcolytePreyInfo>().SelfEnabledCondition; resourceTypesPreres = self.Info.TraitInfo <AcolytePreyInfo>().ResourceTypesPreres; resourceExtraTimes = self.Info.TraitInfo <AcolytePreyInfo>().ResourceExtraTimes; }
public SpiceBloom(Actor self, SpiceBloomInfo info) { this.info = info; resLayer = self.World.WorldActor.Trait <ResourceLayer>(); resType = self.World.WorldActor.TraitsImplementing <ResourceType>().First(t => t.Info.Type == info.ResourceType); var rs = self.Trait <RenderSprites>(); body = new Animation(self.World, rs.GetImage(self)); rs.Add(new AnimationWithOffset(body, null, () => self.IsDead)); growTicks = self.World.SharedRandom.Next(info.Lifetime[0], info.Lifetime[1]); body.Play(info.GrowthSequences[0]); spurt = new Animation(self.World, rs.GetImage(self)); rs.Add(new AnimationWithOffset(spurt, null, () => !showSpurt)); spurt.PlayThen(info.SpurtSequence, () => showSpurt = false); }
public AutoDeployMinersBotModule(Actor self, AutoDeployMinersBotModuleInfo info) : base(info) { world = self.World; player = self.Owner; resourceLayer = self.World.WorldActor.Trait <ResourceLayer>(); claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); pathFinder = self.World.WorldActor.Trait <IPathFinder>(); domainIndex = self.World.WorldActor.Trait <DomainIndex>(); var resourceTypes = self.World.WorldActor.TraitsImplementing <ResourceType>().ToArray(); var resourceType = resourceTypes.FirstOrDefault(a => string.Equals(a.Info.Type, info.TargetResourceType, StringComparison.InvariantCultureIgnoreCase)); if (resourceType == null) { throw new ArgumentException($"Couldn't find resource type: {info.TargetResourceType}"); } }
void UpdateRenderedSpriteInner(CPos cell, RendererCellContents content) { var density = content.Density; var renderType = content.Type; if (density > 0 && renderType != null) { // The call chain for this method (that starts with AddDirtyCell()) guarantees // that the new content type would still be suitable for this renderer, // but that is a bit too fragile to rely on in case the code starts changing. if (!Info.RenderTypes.Contains(renderType.Info.Type)) { return; } var clear = FindClearSides(renderType, cell); int index; if (clear == ClearSides.None) { var sprites = Variants[content.Variant]; var frame = density > ResourceLayer.GetMaxResourceDensity(cell) / 2 ? 1 : 0; UpdateSpriteLayers(cell, renderType.Variants.First().Value, sprites[frame], renderType.Palette); } else if (SpriteMap.TryGetValue(clear, out index)) { UpdateSpriteLayers(cell, renderType.Variants.First().Value, index, renderType.Palette); } else { throw new InvalidOperationException("SpriteMap does not contain an index for ClearSides type '{0}'".F(clear)); } } else { UpdateSpriteLayers(cell, null, 0, null); } }
public PoisonedByTiberium(ActorInitializer init, PoisonedByTiberiumInfo info) : base(info) { rl = init.Self.World.WorldActor.Trait <ResourceLayer>(); }
public TransformsNearResources(Actor self, TransformsNearResourcesInfo info) { resourceLayer = self.World.WorldActor.Trait <ResourceLayer>(); delay = Common.Util.RandomDelay(self.World, info.Delay); this.info = info; }
public SpawnerRefineryMaster(ActorInitializer init, SpawnerRefineryMasterInfo info) : base(init, info) { this.info = info; resLayer = init.Self.World.WorldActor.Trait <ResourceLayer>(); transforms = init.Self.Trait <Transforms>(); }
void INotifyCreated.Created(Actor self) { resLayer = self.World.WorldActor.Trait <ResourceLayer>(); }