public override void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
        {
            var exit         = CPos.Zero;
            var exitLocation = CPos.Zero;

            var info      = (ProductionParadropInfo)Info;
            var actorType = info.ActorType;

            var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo <AircraftInfo>().CruiseAltitude;

            // Clone the initializer dictionary for the new actor
            var td = new TypeDictionary();

            foreach (var init in inits)
            {
                td.Add(init);
            }

            if (self.OccupiesSpace != null)
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.World.Map.CenterOfCell(exit) + new WVec(WDist.Zero, WDist.Zero, altitude);
                var to    = self.World.Map.CenterOfCell(exit);

                var initialFacing = exitinfo.Facing < 0 ? (to - spawn).Yaw.Facing : exitinfo.Facing;

                exitLocation = rp.Value != null ? rp.Value.Location : exit;

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
                td.Add(new MoveIntoWorldDelayInit(exitinfo.ExitDelay));
            }

            self.World.AddFrameEndTask(w =>
            {
                var newUnit = self.World.CreateActor(producee.Name, td);
                newUnit.Trait <Parachutable>().IgnoreActor = self;

                var move = newUnit.TraitOrDefault <IMove>();
                if (move != null)
                {
                    newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(exitLocation, 1, targetLineColor: Color.OrangeRed)));
                }

                if (!self.IsDead)
                {
                    foreach (var t in self.TraitsImplementing <INotifyProduction>())
                    {
                        t.UnitProduced(self, newUnit, exit);
                    }
                }

                var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                {
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType, td);
                }
            });
        }
Example #2
0
        static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s)
        {
            var mobileInfo = producee.TraitInfoOrDefault <MobileInfo>();

            self.NotifyBlocker(self.Location + s.ExitCell);

            return(mobileInfo == null ||
                   mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, ignoreActor: self));
        }
Example #3
0
        public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
        {
            var exit          = CPos.Zero;
            var exitLocations = new List <CPos>();

            // Clone the initializer dictionary for the new actor
            var td = new TypeDictionary();

            foreach (var init in inits)
            {
                td.Add(init);
            }

            if (exitinfo != null && self.OccupiesSpace != null && producee.HasTraitInfo <IOccupySpaceInfo>())
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.CenterPosition + exitinfo.SpawnOffset;
                var to    = self.World.Map.CenterOfCell(exit);

                var initialFacing = exitinfo.Facing;
                if (exitinfo.Facing < 0)
                {
                    var delta = to - spawn;
                    if (delta.HorizontalLengthSquared == 0)
                    {
                        var fi = producee.TraitInfoOrDefault <IFacingInfo>();
                        initialFacing = fi != null?fi.GetInitialFacing() : 0;
                    }
                    else
                    {
                        initialFacing = delta.Yaw.Facing;
                    }
                }

                exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List <CPos> {
                    exit
                };

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
                if (exitinfo != null)
                {
                    td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
                }
            }

            self.World.AddFrameEndTask(w =>
            {
                var newUnit = self.World.CreateActor(producee.Name, td);

                var move = newUnit.TraitOrDefault <IMove>();
                if (exitinfo != null && move != null)
                {
                    foreach (var cell in exitLocations)
                    {
                        newUnit.QueueActivity(new AttackMoveActivity(newUnit, () => move.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
                    }
                }

                if (!self.IsDead)
                {
                    foreach (var t in self.TraitsImplementing <INotifyProduction>())
                    {
                        t.UnitProduced(self, newUnit, exit);
                    }
                }

                var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                {
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType, td);
                }
            });
        }
        public override void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
        {
            var exit         = CPos.Zero;
            var exitLocation = CPos.Zero;
            var target       = Target.Invalid;

            var info      = (ProductionParadropInfo)Info;
            var actorType = info.ActorType;

            var bi = producee.TraitInfoOrDefault <BuildableInfo>();

            if (bi != null && bi.ForceFaction != null)
            {
                factionVariant = bi.ForceFaction;
            }

            var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo <AircraftInfo>().CruiseAltitude;
            var td       = new TypeDictionary
            {
                new OwnerInit(self.Owner),
            };

            if (self.OccupiesSpace != null)
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.World.Map.CenterOfCell(exit) + new WVec(WDist.Zero, WDist.Zero, altitude);
                var to    = self.World.Map.CenterOfCell(exit);

                var initialFacing = exitinfo.Facing < 0 ? (to - spawn).Yaw.Facing : exitinfo.Facing;

                exitLocation = rp.Value != null ? rp.Value.Location : exit;
                target       = Target.FromCell(self.World, exitLocation);

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
            }

            self.World.AddFrameEndTask(w =>
            {
                if (factionVariant != null)
                {
                    td.Add(new FactionInit(factionVariant));
                }

                var newUnit = self.World.CreateActor(producee.Name, td);

                newUnit.QueueActivity(new Parachute(newUnit, newUnit.CenterPosition, self));
                var move = newUnit.TraitOrDefault <IMove>();
                if (move != null)
                {
                    if (exitinfo.MoveIntoWorld)
                    {
                        if (exitinfo.ExitDelay > 0)
                        {
                            newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));
                        }

                        newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
                        newUnit.QueueActivity(new AttackMoveActivity(newUnit, move.MoveTo(exitLocation, 1)));
                    }
                }

                newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);

                if (!self.IsDead)
                {
                    foreach (var t in self.TraitsImplementing <INotifyProduction>())
                    {
                        t.UnitProduced(self, newUnit, exit);
                    }
                }

                var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                {
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
                }

                foreach (var t in newUnit.TraitsImplementing <INotifyBuildComplete>())
                {
                    t.BuildingComplete(newUnit);
                }
            });
        }
Example #5
0
        public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
        {
            var exit         = CPos.Zero;
            var exitLocation = CPos.Zero;
            var target       = Target.Invalid;

            var bi = producee.TraitInfoOrDefault <BuildableInfo>();

            if (bi != null && bi.ForceFaction != null)
            {
                factionVariant = bi.ForceFaction;
            }

            var td = new TypeDictionary
            {
                new OwnerInit(self.Owner),
            };

            if (self.OccupiesSpace != null)
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.CenterPosition + exitinfo.SpawnOffset;
                var to    = self.World.Map.CenterOfCell(exit);

                var initialFacing = exitinfo.Facing;
                if (exitinfo.Facing < 0)
                {
                    var delta = to - spawn;
                    if (delta.HorizontalLengthSquared == 0)
                    {
                        var fi = producee.TraitInfoOrDefault <IFacingInfo>();
                        initialFacing = fi != null?fi.GetInitialFacing() : 0;
                    }
                    else
                    {
                        initialFacing = delta.Yaw.Facing;
                    }
                }

                exitLocation = rp.Value != null ? rp.Value.Location : exit;
                target       = Target.FromCell(self.World, exitLocation);

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
            }

            self.World.AddFrameEndTask(w =>
            {
                if (factionVariant != null)
                {
                    td.Add(new FactionInit(factionVariant));
                }

                var newUnit = self.World.CreateActor(producee.Name, td);

                var move = newUnit.TraitOrDefault <IMove>();
                if (move != null)
                {
                    if (exitinfo.MoveIntoWorld)
                    {
                        if (exitinfo.ExitDelay > 0)
                        {
                            newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));
                        }

                        newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
                        newUnit.QueueActivity(new AttackMoveActivity(
                                                  newUnit, move.MoveTo(exitLocation, 1)));
                    }
                }

                newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);

                if (!self.IsDead)
                {
                    foreach (var t in self.TraitsImplementing <INotifyProduction>())
                    {
                        t.UnitProduced(self, newUnit, exit);
                    }
                }

                var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                {
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
                }

                foreach (var t in newUnit.TraitsImplementing <INotifyBuildComplete>())
                {
                    t.BuildingComplete(newUnit);
                }
            });
        }
Example #6
0
        public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string raceVariant)
        {
            var exit  = self.Location + exitinfo.ExitCell;
            var spawn = self.CenterPosition + exitinfo.SpawnOffset;
            var to    = self.World.Map.CenterOfCell(exit);

            var fi            = producee.Traits.GetOrDefault <IFacingInfo>();
            var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi == null ? 0 : fi.GetInitialFacing()) : exitinfo.Facing;

            var exitLocation = rp.Value != null ? rp.Value.Location : exit;
            var target       = Target.FromCell(self.World, exitLocation);

            var bi = producee.Traits.GetOrDefault <BuildableInfo>();

            if (bi != null && bi.ForceRace != null)
            {
                raceVariant = bi.ForceRace;
            }

            self.World.AddFrameEndTask(w =>
            {
                var td = new TypeDictionary
                {
                    new OwnerInit(self.Owner),
                    new LocationInit(exit),
                    new CenterPositionInit(spawn),
                    new FacingInit(initialFacing)
                };

                if (raceVariant != null)
                {
                    td.Add(new RaceInit(raceVariant));
                }

                var newUnit = self.World.CreateActor(producee.Name, td);

                var move = newUnit.TraitOrDefault <IMove>();
                if (move != null)
                {
                    if (exitinfo.MoveIntoWorld)
                    {
                        if (exitinfo.ExitDelay > 0)
                        {
                            newUnit.QueueActivity(new Wait(exitinfo.ExitDelay));
                        }

                        newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
                        newUnit.QueueActivity(new AttackMoveActivity(
                                                  newUnit, move.MoveTo(exitLocation, 1)));
                    }
                }

                newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);

                if (!self.IsDead)
                {
                    foreach (var t in self.TraitsImplementing <INotifyProduction>())
                    {
                        t.UnitProduced(self, newUnit, exit);
                    }
                }

                var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                {
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
                }

                if (bi != null && bi.InitialActivity != null)
                {
                    newUnit.QueueActivity(Game.CreateObject <Activity>(bi.InitialActivity));
                }

                foreach (var t in newUnit.TraitsImplementing <INotifyBuildComplete>())
                {
                    t.BuildingComplete(newUnit);
                }
            });
        }
Example #7
0
        public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
        {
            var exit          = CPos.Zero;
            var exitLocations = new List <CPos>();

            // Clone the initializer dictionary for the new actor
            var td = new TypeDictionary();

            foreach (var init in inits)
            {
                td.Add(init);
            }

            if (exitinfo != null && self.OccupiesSpace != null && producee.HasTraitInfo <IOccupySpaceInfo>())
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.CenterPosition + exitinfo.SpawnOffset;
                var to    = self.World.Map.CenterOfCell(exit);

                WAngle initialFacing;
                if (!exitinfo.Facing.HasValue)
                {
                    var delta = to - spawn;
                    if (delta.HorizontalLengthSquared == 0)
                    {
                        var fi = producee.TraitInfoOrDefault <IFacingInfo>();
                        initialFacing = fi != null?fi.GetInitialFacing() : WAngle.Zero;
                    }
                    else
                    {
                        initialFacing = delta.Yaw;
                    }
                }
                else
                {
                    initialFacing = exitinfo.Facing.Value;
                }

                exitLocations = rp != null && rp.Path.Count > 0 ? rp.Path : new List <CPos> {
                    exit
                };

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
                if (exitinfo != null)
                {
                    td.Add(new CreationActivityDelayInit(exitinfo.ExitDelay));
                }
            }

            self.World.AddFrameEndTask(w =>
            {
                // Here we check if production should go into the cargo of a passenger and if so, if cargo trait exists and if there is space to do so
                if (info.ProduceIntoCargoOfCargo && self.TraitOrDefault <Cargo>() != null && self.TraitOrDefault <Cargo>().Passengers.Any(p => p.TraitOrDefault <Cargo>().HasSpace(producee.TraitInfo <PassengerInfo>().Weight)))
                {
                    var newUnit = self.World.CreateActor(false, producee.Name, td);

                    foreach (var p in self.TraitOrDefault <Cargo>().Passengers)
                    {
                        if (p.TraitOrDefault <Cargo>().HasSpace(producee.TraitInfo <PassengerInfo>().Weight))
                        {
                            p.TraitOrDefault <Cargo>().Load(p, newUnit);

                            if (!self.IsDead)
                            {
                                foreach (var t in self.TraitsImplementing <INotifyProduction>())
                                {
                                    t.UnitProduced(self, newUnit, exit);
                                }
                            }

                            var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                            foreach (var notify in notifyOthers)
                            {
                                notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType, td);
                            }

                            break;
                        }
                    }
                }
                // Here we check if production should go into the cargo of the producer and if so, if cargo trait exists and if there is space to do so
                else if (info.ProduceIntoCargo && self.TraitOrDefault <Cargo>() != null && self.TraitOrDefault <Cargo>().HasSpace(producee.TraitInfo <PassengerInfo>().Weight))
                {
                    var newUnit = self.World.CreateActor(false, producee.Name, td);

                    self.TraitOrDefault <Cargo>().Load(self, newUnit);

                    if (!self.IsDead)
                    {
                        foreach (var t in self.TraitsImplementing <INotifyProduction>())
                        {
                            t.UnitProduced(self, newUnit, exit);
                        }
                    }

                    var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                    foreach (var notify in notifyOthers)
                    {
                        notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType, td);
                    }
                }
                // this is actually the good old production
                else
                {
                    var newUnit = self.World.CreateActor(producee.Name, td);

                    var move = newUnit.TraitOrDefault <IMove>();
                    if (exitinfo != null && move != null)
                    {
                        foreach (var cell in exitLocations)
                        {
                            newUnit.QueueActivity(new AttackMoveActivity(newUnit,
                                                                         () => move.MoveTo(cell, 1, evaluateNearestMovableCell: true,
                                                                                           targetLineColor: Color.OrangeRed)));
                        }
                    }

                    if (!self.IsDead)
                    {
                        foreach (var t in self.TraitsImplementing <INotifyProduction>())
                        {
                            t.UnitProduced(self, newUnit, exit);
                        }
                    }

                    var notifyOthers = self.World.ActorsWithTrait <INotifyOtherProduction>();
                    foreach (var notify in notifyOthers)
                    {
                        notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit, productionType, td);
                    }
                }
            });
        }