Ejemplo n.º 1
0
        public TDGunboat(ActorInitializer init, TDGunboatInfo info)
        {
            Info = info;
            self = init.Self;

            var locationInit = init.GetOrDefault <LocationInit>();

            if (locationInit != null)
            {
                SetPosition(self, locationInit.Value);
            }

            var centerPositionInit = init.GetOrDefault <CenterPositionInit>();

            if (centerPositionInit != null)
            {
                SetPosition(self, centerPositionInit.Value);
            }

            Facing = init.GetValue <FacingInit, WAngle>(Info.GetInitialFacing());

            // Prevent mappers from setting bogus facings
            if (Facing != Left && Facing != Right)
            {
                Facing = Facing.Angle > 511 ? Right : Left;
            }
        }
Ejemplo n.º 2
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>);
        }
Ejemplo n.º 3
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var dynamicFacingInit = init.GetOrDefault <DynamicFacingInit>();
            var bodyFacing        = dynamicFacingInit != null?dynamicFacingInit.Value() : init.GetValue <FacingInit, int>(0);

            facing = WAngle.FromFacing(Turreted.TurretFacingFromInit(init, info, 0)());

            // Calculate final position
            var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // Facing rotation
            rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed / 1024);

            var anim = new Animation(init.World, rs.GetImage(self), () => facing);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }
Ejemplo n.º 4
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var dynamicFacingInit = init.GetOrDefault <DynamicFacingInit>();
            var bodyFacing        = dynamicFacingInit != null?dynamicFacingInit.Value() : init.GetValue <FacingInit, WAngle>(WAngle.Zero);

            facing = TurretedInfo.WorldFacingFromInit(init, info, WAngle.Zero)();

            // Calculate final position
            var throwRotation = WRot.FromYaw(new WAngle(Game.CosmeticRandom.Next(1024)));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromYaw(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // WAngle requires positive inputs, so track the speed and direction separately
            var rotationSpeed = WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed.Angle / 1024;

            direction = rotationSpeed < 0 ? -1 : 1;
            rotation  = new WAngle(Math.Abs(rotationSpeed));

            var anim = new Animation(init.World, rs.GetImage(self), () => facing);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }
Ejemplo n.º 5
0
        public ConyardChronoReturn(ActorInitializer init, ConyardChronoReturnInfo info)
        {
            this.info = info;
            self      = init.Self;

            health = self.Trait <Health>();

            wsb     = self.TraitsImplementing <WithSpriteBody>().Single(w => w.Info.Name == info.Body);
            faction = init.GetValue <FactionInit, string>(self.Owner.Faction.InternalName);

            var returnInit = init.GetOrDefault <ChronoshiftReturnInit>();

            if (returnInit != null)
            {
                returnTicks = returnInit.Ticks;
                duration    = returnInit.Duration;
                origin      = returnInit.Origin;

                // Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
                if (returnInit.Chronosphere != null)
                {
                    init.World.AddFrameEndTask(w => chronosphere = returnInit.Chronosphere.Actor(init.World).Value);
                }
            }
        }
Ejemplo n.º 6
0
        public SSCrate(ActorInitializer init, SSCrateInfo info)
        {
            self      = init.Self;
            this.info = info;

            var spawnerInit = init.GetOrDefault <CrateSpawnerTraitInit>(info);

            if (spawnerInit != null)
            {
                spawner = spawnerInit.Value;
            }

            var locationInit = init.GetOrDefault <LocationInit>(info);

            if (locationInit != null)
            {
                SetPosition(self, locationInit.Value);
            }
        }
Ejemplo n.º 7
0
        public LineBuild(ActorInitializer init, LineBuildInfo info)
        {
            this.info = info;
            var lineBuildParentInit = init.GetOrDefault <LineBuildParentInit>();

            if (lineBuildParentInit != null)
            {
                parentNodes = lineBuildParentInit.ActorValue(init.World);
            }
        }
Ejemplo n.º 8
0
        public Mobile(ActorInitializer init, MobileInfo info)
            : base(info)
        {
            self = init.Self;

            speedModifiers = Exts.Lazy(() => self.TraitsImplementing <ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));

            ToSubCell = FromSubCell = info.LocomotorInfo.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;

            var subCellInit = init.GetOrDefault <SubCellInit>();

            if (subCellInit != null)
            {
                FromSubCell = ToSubCell = subCellInit.Value;

                returnToCellOnCreationRecalculateSubCell = false;
            }

            var locationInit = init.GetOrDefault <LocationInit>();

            if (locationInit != null)
            {
                fromCell = toCell = locationInit.Value;
                SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
            }

            Facing = oldFacing = WAngle.FromFacing(init.GetValue <FacingInit, int>(info.InitialFacing));

            // Sets the initial visual position
            // Unit will move into the cell grid (defined by LocationInit) as its initial activity
            var centerPositionInit = init.GetOrDefault <CenterPositionInit>();

            if (centerPositionInit != null)
            {
                oldPos = centerPositionInit.Value;
                SetVisualPosition(self, oldPos);
                returnToCellOnCreation = true;
            }

            creationActivityDelay = init.GetValue <CreationActivityDelayInit, int>(0);
        }
Ejemplo n.º 9
0
        public Crate(ActorInitializer init, CrateInfo info)
        {
            self      = init.Self;
            this.info = info;

            var locationInit = init.GetOrDefault <LocationInit>();

            if (locationInit != null)
            {
                SetPosition(self, locationInit.Value);
            }
        }
Ejemplo n.º 10
0
        public Teleporter(ActorInitializer init, TeleporterInfo info)
        {
            self      = init.Self;
            this.info = info;

            var locationInit = init.GetOrDefault <LocationInit>(info);

            if (locationInit != null)
            {
                SetPosition(self, locationInit.Value);
            }
        }
Ejemplo n.º 11
0
        public ProductionFromMapEdge(ActorInitializer init, ProductionInfo info)
            : base(init, info)
        {
            domainIndex = init.Self.World.WorldActor.Trait <DomainIndex>();

            var spawnLocationInit = init.GetOrDefault <ProductionSpawnLocationInit>(info);

            if (spawnLocationInit != null)
            {
                spawnLocation = spawnLocationInit.Value;
            }
        }
Ejemplo n.º 12
0
        public ScriptTags(ActorInitializer init, ScriptTagsInfo info)
        {
            var scriptTagsInit = init.GetOrDefault <ScriptTagsInit>(info);

            if (scriptTagsInit != null)
            {
                foreach (var tag in scriptTagsInit.Value)
                {
                    tags.Add(tag);
                }
            }
        }
Ejemplo n.º 13
0
        public Flag(ActorInitializer init, FlagInfo info)
        {
            self      = init.Self;
            this.info = info;

            spawner = self.World.WorldActor.Trait <SpawnSSUnit>();
            var locationInit = init.GetOrDefault <LocationInit>(info);

            if (locationInit != null)
            {
                SetPosition(self, locationInit.Value);
            }
        }
Ejemplo n.º 14
0
        public Health(ActorInitializer init, HealthInfo info)
        {
            Info  = info;
            MaxHP = hp = info.HP > 0 ? info.HP : 1;

            // Cast to long to avoid overflow when multiplying by the health
            var healthInit = init.GetOrDefault <HealthInit>();

            if (healthInit != null)
            {
                hp = (int)(healthInit.Value * (long)MaxHP / 100);
            }

            DisplayHP = hp;
        }
        public WithConstructionBeamOverlay(ActorInitializer init, WithConstructionBeamOverlayInfo info)
            : base(info)
        {
            this.info = info;

            var skipMakeAnimsInit = init.GetOrDefault <SkipMakeAnimsInit>(info);

            if (skipMakeAnimsInit != null)
            {
                return;
            }

            renderSprites = init.Self.Trait <RenderSprites>();

            overlay = new Animation(init.World, renderSprites.GetImage(init.Self));
            anim    = new AnimationWithOffset(overlay, null, () => IsTraitDisabled);
            renderSprites.Add(anim, info.Palette, info.IsPlayerPalette);
        }
Ejemplo n.º 16
0
        public Chronoshiftable(ActorInitializer init, ChronoshiftableInfo info)
            : base(info)
        {
            self = init.Self;

            var returnInit = init.GetOrDefault <ChronoshiftReturnInit>();

            if (returnInit != null)
            {
                ReturnTicks = returnInit.Ticks;
                duration    = returnInit.Duration;
                Origin      = returnInit.Origin;

                // Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
                if (returnInit.Chronosphere != null)
                {
                    init.World.AddFrameEndTask(w => chronosphere = returnInit.Chronosphere.Actor(init.World).Value);
                }
            }
        }
Ejemplo n.º 17
0
        public WithConstructionOverlay(ActorInitializer init, WithConstructionOverlayInfo info)
            : base(info)
        {
            var skipMakeAnimsInit = init.GetOrDefault <SkipMakeAnimsInit>(info);

            if (skipMakeAnimsInit != null)
            {
                return;
            }

            var rs   = init.Self.Trait <RenderSprites>();
            var body = init.Self.Trait <BodyOrientation>();

            var overlay = new Animation(init.World, rs.GetImage(init.Self));
            var anim    = new AnimationWithOffset(overlay,
                                                  () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(init.Self, init.Self.Orientation))),
                                                  () => IsTraitDisabled);

            // Remove the animation once it is complete
            overlay.PlayThen(info.Sequence, () => init.World.AddFrameEndTask(w => rs.Remove(anim)));

            rs.Add(anim, info.Palette);
        }