public WithIdleOverlay(Actor self, WithIdleOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); buildComplete = !self.Info.HasTraitInfo <BuildingInfo>(); // always render instantly for units overlay = new Animation(self.World, rs.GetImage(self)); if (info.StartSequence != null) { overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.StartSequence), () => overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence))); } else { overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence)); } var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => IsTraitDisabled || !buildComplete, () => (info.PauseOnLowPower && self.IsDisabled()) || !buildComplete, p => WithTurret.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithParachute(Actor self, WithParachuteInfo info) : base(info) { this.info = info; if (info.ShadowImage != null) { shadow = new Animation(self.World, info.ShadowImage); shadow.PlayRepeating(info.ShadowSequence); } if (info.Image == null) { return; } // For this, info.Image must not be null var overlay = new Animation(self.World, info.Image); var body = self.Trait <BodyOrientation>(); anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => IsTraitDisabled && !renderProlonged, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); var rs = self.Trait <RenderSprites>(); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public Altar(Actor self, AltarInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); var overlay1 = new Animation(self.World, rs.GetImage(self)); var overlay2 = new Animation(self.World, rs.GetImage(self)); overlay1.PlayRepeating(RenderSprites.NormalizeSequence(overlay1, self.GetDamageState(), Info.Sequence1)); overlay2.PlayRepeating(RenderSprites.NormalizeSequence(overlay2, self.GetDamageState(), Info.Sequence2)); var anim1 = new AnimationWithOffset(overlay1, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => IsTraitDisabled || summonTicker == 0, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); var anim2 = new AnimationWithOffset(overlay2, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => IsTraitDisabled || summonTicker == 0, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim1); rs.Add(anim2); }
public WithTilesetBody(Actor self, WithTilesetBodyInfo info) { var rs = self.Trait <RenderSprites>(); var bi = self.Info.TraitInfo <BuildingInfo>(); var cols = bi.Dimensions.X; var rows = bi.Dimensions.Y; for (var index = 0; index < (cols * rows); index++) { if (info.SkipFrames == null || !info.SkipFrames.Contains(index)) { var y = index / cols; var x = index % cols; var anim = new Animation(self.World, rs.GetImage(self)); var cellOffset = new WVec(x * 1024 - 512, y * 1024 - 512, 0); var frameIndex = index; anim.PlayFetchIndex(info.Sequence, () => frameIndex); anim.IsDecoration = true; var awo = new AnimationWithOffset(anim, () => cellOffset, null, 0); rs.Add(awo, info.Palette); } } }
public WithIdleOverlayOnGround(Actor self, WithIdleOverlayOnGroundInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); var image = !string.IsNullOrEmpty(info.Image) ? info.Image : rs.GetImage(self); buildComplete = !self.Info.HasTraitInfo <BuildingInfo>(); // always render instantly for units overlay = new Animation(self.World, image, () => IsTraitPaused || !buildComplete); if (info.StartSequence != null) { overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.StartSequence), () => overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence))); } else { overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence)); } var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))) - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition)), () => IsTraitDisabled || !buildComplete, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public Sacrificer(ActorInitializer init, SacrificerInfo info) : base(init, info) { this.info = info; var renderSprites = init.Self.Trait <RenderSprites>(); var body = init.Self.Trait <BodyOrientation>(); if (info.SequenceEnter != null) { var animation = new Animation(init.Self.World, renderSprites.GetImage(init.Self)); animation.PlayRepeating(RenderSprites.NormalizeSequence(animation, init.Self.GetDamageState(), info.SequenceEnter)); var animationWithOffset = new AnimationWithOffset(animation, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(init.Self, init.Self.Orientation))), () => IsTraitDisabled || sacrificeTicker == 0, p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1)); renderSprites.Add(animationWithOffset); } if (info.SequenceSummon != null) { var animation = new Animation(init.Self.World, renderSprites.GetImage(init.Self)); animation.PlayRepeating(RenderSprites.NormalizeSequence(animation, init.Self.GetDamageState(), info.SequenceSummon)); var animationWithOffset = new AnimationWithOffset(animation, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(init.Self, init.Self.Orientation))), () => IsTraitDisabled || summonTicker == 0, p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1)); renderSprites.Add(animationWithOffset); } }
public void AddedToWorld(Actor self) { var width = bi.Dimensions.X; var bibOffset = bi.Dimensions.Y - 1; var centerOffset = FootprintUtils.CenterOffset(bi); var location = self.Location; var rows = info.HasMinibib ? 1 : 2; for (var i = 0; i < rows * width; i++) { var index = i; var anim = new Animation(self.World, rs.GetImage(self)); var cellOffset = new CVec(i % width, i / width + bibOffset); // Some mods may define terrain-specific bibs var terrain = self.World.GetTerrainType(location + cellOffset); var testSequence = info.Sequence + "-" + terrain; var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; anim.PlayFetchIndex(sequence, () => index); anim.IsDecoration = true; // Z-order is one set to the top of the footprint var offset = cellOffset.ToWVec() - centerOffset; var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512)); rs.Add("bib_{0}".F(i), awo, info.Palette); } }
public override void DoAttack(Actor self, Target target, IEnumerable <Armament> armaments = null) { if (!CanAttack(self, target)) { return; } var pos = self.CenterPosition; var targetedPosition = GetTargetPosition(pos, target); var targetYaw = (targetedPosition - pos).Yaw; foreach (var a in Armaments) { if (a.IsTraitDisabled) { continue; } var port = SelectFirePort(self, targetYaw); if (port == null) { return; } var muzzleFacing = targetYaw.Angle / 4; paxFacing[a.Actor].Facing = muzzleFacing; paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port)); var barrel = a.CheckFire(a.Actor, facing, target); if (barrel == null) { continue; } if (a.Info.MuzzleSequence != null) { // Muzzle facing is fixed once the firing starts var muzzleAnim = new Animation(self.World, paxRender[a.Actor].GetImage(a.Actor), () => muzzleFacing); var sequence = a.Info.MuzzleSequence; if (a.Info.MuzzleSplitFacings > 0) { sequence += Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString(); } var muzzleFlash = new AnimationWithOffset(muzzleAnim, () => PortOffset(self, port), () => false, p => RenderUtils.ZOffsetFromCenter(self, p, 1024)); muzzles.Add(muzzleFlash); muzzleAnim.PlayThen(sequence, () => muzzles.Remove(muzzleFlash)); } foreach (var npa in self.TraitsImplementing <INotifyAttack>()) { npa.Attacking(self, target, a, barrel); } } }
void INotifyAddedToWorld.AddedToWorld(Actor self) { var rows = info.HasMinibib ? 1 : 2; var width = bi.Dimensions.X; var bibOffset = bi.Dimensions.Y - rows; var centerOffset = bi.CenterOffset(self.World); var location = self.Location; var map = self.World.Map; for (var i = 0; i < rows * width; i++) { var index = i; var anim = new Animation(self.World, rs.GetImage(self)); var cellOffset = new CVec(i % width, i / width + bibOffset); var cell = location + cellOffset; // Some mods may define terrain-specific bibs var terrain = map.GetTerrainInfo(cell).Type; var testSequence = info.Sequence + "-" + terrain; var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; anim.PlayFetchIndex(sequence, () => index); anim.IsDecoration = true; // Z-order is one set to the top of the footprint var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset; var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512)); anims.Add(awo); rs.Add(awo, info.Palette); } }
public WithIdleOverlayOnGround(Actor self, WithIdleOverlayOnGroundInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); var image = info.Image ?? rs.GetImage(self); overlay = new Animation(self.World, image, () => IsTraitPaused) { IsDecoration = info.IsDecoration }; if (info.StartSequence != null) { overlay.PlayThen(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.StartSequence), () => overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence))); } else { overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence)); } var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self.Orientation))) - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition)), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public TechBunker(ActorInitializer init, TechBunkerInfo info) { this.info = info; wsb = init.Self.Trait <WithSpriteBody>(); timer = 0; state = TechBunkerState.ClosedLocked; var rs = init.Self.Trait <RenderSprites>(); if (info.SequenceLocked != null) { var overlay = new Animation(init.World, rs.GetImage(init.Self), () => state != TechBunkerState.ClosedLocked); overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, init.Self.GetDamageState(), info.SequenceLocked)); var anim = new AnimationWithOffset(overlay, () => WVec.Zero, () => state != TechBunkerState.ClosedLocked, p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1)); rs.Add(anim); } if (info.SequenceUnlocked != null) { var overlay = new Animation(init.World, rs.GetImage(init.Self), () => state != TechBunkerState.ClosedUnlocked); overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, init.Self.GetDamageState(), info.SequenceUnlocked)); var anim = new AnimationWithOffset(overlay, () => WVec.Zero, () => state != TechBunkerState.ClosedUnlocked, p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1)); rs.Add(anim); } }
public Researchable(ActorInitializer init, ResearchableInfo info) : base(info) { this.info = info; self = init.Self; Level = info.Level; var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); var hidden = new Func <bool>(() => ResearchedBy == null || !self.Owner.IsAlliedWith(self.World.LocalPlayer)); overlay = new Animation(self.World, "indicators", hidden); overlay.PlayRepeating(info.Sequence + 0); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld( new WVec(info.Offset.Y * -32, info.Offset.X * -32, 0).Rotate(body.QuantizeOrientation(self, self.Orientation))), hidden, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim); while (overlay.HasSequence(info.Sequence + researchSteps)) { researchSteps++; } }
private void AddAnimation(Actor self, string sequence, Func <bool> hideWhen) { if (sequence == null) { return; } var rs = self.Trait <RenderSprites>(); var overlay = new Animation(self.World, rs.GetImage(self), hideWhen); overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), sequence)); var anim = new AnimationWithOffset(overlay, () => { var currentSequence = wsb.DefaultAnimation.CurrentSequence as OffsetsSpriteSequence; var sprite = wsb.DefaultAnimation.Image; if (currentSequence == null || !currentSequence.EmbeddedOffsets.ContainsKey(sprite) || currentSequence.EmbeddedOffsets[sprite] == null) { return(WVec.Zero); } var point = currentSequence.EmbeddedOffsets[sprite].FirstOrDefault(p => p.Id == 0); return(point != null ? new WVec(point.X * 32, point.Y * 32, 0) : WVec.Zero); }, hideWhen, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim); }
public void Add(AnimationWithOffset anim, string palette = null, bool isPlayerPalette = false) { // Use defaults if (palette == null) { palette = Info.Palette ?? Info.PlayerPalette; isPlayerPalette = Info.Palette == null; } anims.Add(new AnimationWrapper(anim, palette, isPlayerPalette)); }
public WithTeleportEnergyOverlay(ActorInitializer init, WithTeleportEnergyOverlayInfo info) { this.info = info; renderSprites = init.Self.Trait <RenderSprites>(); overlay = new Animation(init.World, info.Image ?? renderSprites.GetImage(init.Self)); var body = init.Self.Trait <BodyOrientation>(); animation = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(init.Self, init.Self.Orientation))), () => false); }
public WithMakeOverlay(Actor self, WithMakeOverlayInfo info) { this.info = info; var rs = self.Trait <RenderSprites>(); var overlay = new Animation(self.World, rs.GetImage(self)); overlay.Play(info.Sequence); anim = new AnimationWithOffset(overlay, null, () => !visible); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info) : base(init, info) { roof = new Animation(GetImage(init.self)); var offset = new AnimationWithOffset(roof) { ZOffset = 24 }; offset.DisableFunc = () => !buildComplete; anims.Add("roof", offset); }
public WithInfantryBodyDisguisedUpdate(ActorInitializer init, WithInfantryBodyDisguisedUpdateInfo info) : base(info) { var rs = init.Self.Trait <RenderSprites>(); DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), RenderSprites.MakeFacingFunc(init.Self)); Animwo = new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled); rs.Add(Animwo); PlayStandAnimation(init.Self); state = AnimationState.Waiting; move = init.Self.Trait <IMove>(); }
public WithCrumbleOverlay(ActorInitializer init, WithCrumbleOverlayInfo info) : base(info) { this.info = info; if (init.Contains <SkipMakeAnimsInit>(info)) { return; } renderSprites = init.Self.Trait <RenderSprites>(); overlay = new Animation(init.World, renderSprites.GetImage(init.Self)); animation = new AnimationWithOffset(overlay, null, () => IsTraitDisabled); }
public WithExitOverlay(Actor self, WithExitOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); overlay = new Animation(self.World, rs.GetImage(self)); overlay.PlayRepeating(info.Sequence); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !enable); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); overlay = new Animation(self.World, rs.GetImage(self)); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !visible || IsTraitDisabled); overlay.PlayThen(info.Sequence, () => visible = false); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithDockingOverlay(Actor self, WithDockingOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); var overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused); overlay.Play(info.Sequence); WithOffset = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !Visible || IsTraitDisabled); rs.Add(WithOffset, info.Palette, info.IsPlayerPalette); }
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <IBodyOrientation>(); buildComplete = !self.HasTrait <Building>(); // always render instantly for units overlay = new Animation(self.World, rs.GetImage(self)); overlay.PlayRepeating(info.Sequence); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !IsProducing || !buildComplete); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); buildComplete = !self.Info.HasTraitInfo <BuildingInfo>(); // always render instantly for units overlay = new Animation(self.World, rs.GetImage(self)); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !visible || !buildComplete); overlay.PlayThen(info.Sequence, () => visible = false); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
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); }
public WithSupportPowerActivationOverlay(Actor self, WithSupportPowerActivationOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); overlay = new Animation(self.World, rs.GetImage(self)); overlay.PlayThen(info.Sequence, () => visible = false); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => IsTraitDisabled || !visible, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithResourceCollectorOverlay(Actor self, WithResourceCollectorOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var resourceCollector = self.Trait <ResourceCollector>(); overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused); overlay.PlayFetchIndex(info.Sequence, () => resourceCollector.Resources != 0 ? (10 * overlay.CurrentSequence.Length - 1) * resourceCollector.Resources / (10 * resourceCollector.Info.Capacity) : 0); var anim = new AnimationWithOffset(overlay, null, () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithCrumbleOverlay(ActorInitializer init, WithCrumbleOverlayInfo info) { if (init.Contains <SkipMakeAnimsInit>()) { return; } var rs = init.Self.Trait <RenderSprites>(); var overlay = new Animation(init.World, rs.GetImage(init.Self)); var anim = new AnimationWithOffset(overlay, null, () => !buildComplete); // Remove the animation once it is complete overlay.PlayThen(info.Sequence, () => init.World.AddFrameEndTask(w => rs.Remove(anim))); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithRepairOverlay(Actor self, WithRepairOverlayInfo info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <IBodyOrientation>(); buildComplete = !self.HasTrait <Building>(); // always render instantly for units overlay = new Animation(self.World, rs.GetImage(self)); overlay.Play(info.Sequence); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !buildComplete, () => info.PauseOnLowPower && self.IsDisabled(), p => WithTurret.ZOffsetFromCenter(self, p, 1)); rs.Add(anim, info.Palette, info.IsPlayerPalette); }
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info) : base(info) { var rs = self.Trait <RenderSprites>(); var body = self.Trait <BodyOrientation>(); productionInfos = self.Info.TraitInfos <ProductionInfo>().ToArray(); overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused); overlay.PlayRepeating(info.Sequence); var anim = new AnimationWithOffset(overlay, () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => !IsProducing || IsTraitDisabled); rs.Add(anim, info.Palette, info.IsPlayerPalette); }