static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s) { var mobileInfo = producee.Traits.GetOrDefault <MobileInfo>(); return(mobileInfo == null || mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCell, self, true)); }
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.Get <IFacingInfo>(); var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing; var exitLocation = rp.Value != null ? rp.Value.Location : exit; var target = Target.FromCell(self.World, exitLocation); 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) { newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit)); newUnit.QueueActivity(new AttackMove.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); } } }); }
static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s) { var mobileInfo = producee.Traits.GetOrDefault <MobileInfo>(); foreach (var blocker in self.World.ActorMap.GetUnitsAt(self.Location + s.ExitCell)) { // Notify the blocker that he's blocking our move: foreach (var moveBlocked in blocker.TraitsImplementing <INotifyBlockingMove>()) { moveBlocked.OnNotifyBlockingMove(blocker, self); } } return(mobileInfo == null || mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self)); }
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo) { var exit = self.Location + exitinfo.ExitCell; var spawn = self.CenterPosition + exitinfo.SpawnOffset; var to = exit.CenterPosition; var fi = producee.Traits.Get <IFacingInfo>(); var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing; var exitLocation = rp.Value != null ? rp.Value.rallyPoint : exit; var target = Target.FromCell(exitLocation); var nearEnough = rp.Value != null?WRange.FromCells(rp.Value.nearEnough) : WRange.Zero; self.World.AddFrameEndTask(w => { var newUnit = self.World.CreateActor(producee.Name, new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(exit), new CenterPositionInit(spawn), new FacingInit(initialFacing) }); var move = newUnit.TraitOrDefault <IMove>(); if (move != null) { if (exitinfo.MoveIntoWorld) { newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit)); newUnit.QueueActivity(new AttackMove.AttackMoveActivity( newUnit, move.MoveWithinRange(target, nearEnough))); } } newUnit.SetTargetLine(target, Color.Green, false); if (!self.IsDead()) { foreach (var t in self.TraitsImplementing <INotifyProduction>()) { t.UnitProduced(self, newUnit, exit); } } }); }
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo) { var newUnit = self.World.CreateActor(false, producee.Name, new TypeDictionary { new OwnerInit(self.Owner), }); var exit = self.Location + exitinfo.ExitCell; var spawn = self.Trait <IHasLocation>().PxPosition + exitinfo.SpawnOffset; var teleportable = newUnit.Trait <ITeleportable>(); var facing = newUnit.TraitOrDefault <IFacing>(); // Set the physical position of the unit as the exit cell teleportable.SetPosition(newUnit, exit); var to = Util.CenterOfCell(exit); teleportable.AdjustPxPosition(newUnit, spawn); if (facing != null) { facing.Facing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, facing.Facing) : exitinfo.Facing; } self.World.Add(newUnit); var mobile = newUnit.TraitOrDefault <Mobile>(); if (mobile != null) { // Animate the spawn -> exit transition var speed = mobile.MovementSpeedForCell(newUnit, exit); var length = speed > 0 ? (int)((to - spawn).Length * 3 / speed) : 0; newUnit.QueueActivity(new Drag(spawn, to, length)); } var target = MoveToRallyPoint(self, newUnit, exit); newUnit.SetTargetLine(Target.FromCell(target), Color.Green, false); foreach (var t in self.TraitsImplementing <INotifyProduction>()) { t.UnitProduced(self, newUnit, exit); } }
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo) { var exit = self.Location + exitinfo.ExitCellVector; var spawn = self.CenterPosition + exitinfo.SpawnOffsetVector; var to = exit.CenterPosition; var fi = producee.Traits.Get <IFacingInfo>(); var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing; var newUnit = self.World.CreateActor(producee.Name, new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(exit), new FacingInit(initialFacing) }); // TODO: Move this into an *Init // TODO: We should be adjusting the actual position for aircraft, not just visuals. var teleportable = newUnit.Trait <IPositionable>(); teleportable.SetVisualPosition(newUnit, spawn); // TODO: Generalize this for non-mobile (e.g. aircraft) too // Remember to update the Enter activity too var mobile = newUnit.TraitOrDefault <Mobile>(); if (mobile != null) { // Animate the spawn -> exit transition var speed = mobile.MovementSpeedForCell(newUnit, exit); var length = speed > 0 ? (to - spawn).Length / speed : 0; newUnit.QueueActivity(new Drag(spawn, to, length)); } var target = MoveToRallyPoint(self, newUnit, exit); newUnit.SetTargetLine(Target.FromCell(target), Color.Green, false); foreach (var t in self.TraitsImplementing <INotifyProduction>()) { t.UnitProduced(self, newUnit, exit); } }