public Goal(Troop toCopy, Empire Owner, Planet p)
 {
     this.GoalName = "Build Troop";
     this.type = GoalType.DeepSpaceConstruction;
     this.PlanetBuildingAt = p;
     this.ToBuildUID = toCopy.Name;
     this.empire = Owner;
     this.type = GoalType.BuildTroop;
 }
        private void RunGroundPlanner()
        {
            float totalideal = 0;
            float totalwanted = 0;
            Troop troop;
            Troop LowCosttroop = new Troop();
            Troop highCosttroop = new Troop();
            foreach (KeyValuePair<String, Troop> troops in ResourceManager.TroopsDict.OrderBy(cost => cost.Value.Cost))
            {
                if (!this.empire.WeCanBuildTroop(troops.Key))
                    continue;
                if (troops.Value.Cost > highCosttroop.Cost)
                    highCosttroop = troops.Value;
                if (LowCosttroop.Cost == 0)
                    LowCosttroop = troops.Value;
                else if (troops.Value.Cost < LowCosttroop.Cost)
                    LowCosttroop = troops.Value;
            }

            troop = highCosttroop;

            foreach (SolarSystem system in this.empire.GetOwnedSystems())
            {

                SystemCommander defenseSystem = this.DefensiveCoordinator.DefenseDict[system];
                //int planetcount = system.PlanetList.Where(planet => planet.Owner == empire).Count();
                //planetcount = planetcount == 0 ? 1 : planetcount;

                if (defenseSystem.TroopStrengthNeeded <= 0)
                {
                    continue;
                }
                totalwanted += defenseSystem.TroopStrengthNeeded;// >0 ?defenseSystem.TroopStrengthNeeded : 1;
                totalideal += defenseSystem.IdealTroopStr;// >0 ? defenseSystem.IdealTroopStr : 1;
            }
            if (totalwanted / totalideal > .5f)
            {
                troop = LowCosttroop;
            }
            if (totalwanted / totalideal <= .1f)
                return;
            Planet targetBuild = this.empire.GetPlanets()
                .Where(planet => planet.AllowInfantry
                    && planet.GetMaxProductionPotential() > 2
                    && (planet.ProductionHere) -(planet.ConstructionQueue.Where(goal => goal.Goal != null
                        && goal.Goal.type == GoalType.BuildTroop).Sum(cost => cost.Cost)) > 0//10 turns to build curremt troops in queue

                        )
                        .OrderBy(noshipyard => !noshipyard.HasShipyard)
                        .ThenByDescending(build => build.GrossProductionPerTurn).FirstOrDefault();
            if (targetBuild == null)
                return;

            Goal g = new Goal(troop, this.empire, targetBuild);
            this.Goals.Add(g);
        }
 public void LaunchBoardingPartyORIG(Troop troop)
 {
     if (this.IsTroopBay && this.Powered)
     {
         if (this.hangarShip != null)
         {
             this.hangarShip.DoEscort(this.Parent);
             return;
         }
         if (this.hangarTimer <= 0f && this.hangarShip == null)
         {
             this.hangarShip = Ship_Game.ResourceManager.CreateTroopShipAtPoint(this.Parent.loyalty.data.StartingScout, this.Parent.loyalty, this.Center, troop);
             this.hangarShip.VanityName = "Assault Ship";
             this.hangarShip.Mothership = this.Parent;
             this.hangarShip.DoEscort(this.Parent);
             this.hangarShip.Velocity = (((this.Parent.GetSystem() != null ? this.Parent.GetSystem().RNG : Ship.universeScreen.DeepSpaceRNG)).RandomDirection() * this.hangarShip.speed) + this.Parent.Velocity;
             if (this.hangarShip.Velocity.Length() > this.hangarShip.velocityMaximum)
             {
                 this.hangarShip.Velocity = Vector2.Normalize(this.hangarShip.Velocity) * this.hangarShip.speed;
             }
             this.installedSlot.HangarshipGuid = this.hangarShip.guid;
             this.hangarTimer = this.hangarTimerConstant;
         }
     }
 }
 //added by gremlin boarding parties
 public void LaunchBoardingParty(Troop troop)
 {
     if (this.IsTroopBay && this.Powered)
     {
         if (this.hangarShip != null)
         {
             //this.hangarShip.GetAI().State == AIState.AssaultPlanet || this.hangarShip.GetAI().State == AIState.Boarding ||
             if (this.hangarShip.GetAI().State == AIState.ReturnToHangar || this.hangarShip.GetAI().EscortTarget != null || this.hangarShip.GetAI().OrbitTarget != null) return;
             this.hangarShip.DoEscort(this.Parent);
             return;
         }
         if (this.hangarTimer <= 0f && this.hangarShip == null)
         {
             this.hangarShip = ResourceManager.CreateTroopShipAtPoint(this.Parent.loyalty.data.StartingScout, this.Parent.loyalty, this.Center, troop);
             this.hangarShip.VanityName = "Assault Ship";
             this.hangarShip.Mothership = this.Parent;
             this.hangarShip.DoEscort(this.Parent);
             this.hangarShip.Velocity = (((this.Parent.GetSystem() != null ? this.Parent.GetSystem().RNG : Ship.universeScreen.DeepSpaceRNG)).RandomDirection() * this.hangarShip.speed) + this.Parent.Velocity;
             if (this.hangarShip.Velocity.Length() > this.hangarShip.velocityMaximum)
             {
                 this.hangarShip.Velocity = Vector2.Normalize(this.hangarShip.Velocity) * this.hangarShip.speed;
             }
             this.installedSlot.HangarshipGuid = this.hangarShip.guid;
             this.hangarTimer = this.hangarTimerConstant;
             //if (this.Parent.GetAI().Target != null && this.Parent.GetAI().Target is Ship && (this.Parent.GetAI().Target as Ship).loyalty != this.Parent.loyalty)
             //{
             //    this.hangarShip.GetAI().OrderTroopToBoardShip(this.Parent.GetAI().Target as Ship);
             //}
         }
     }
 }
 public bool AssignTroopToTile(Troop t)
 {
     List<PlanetGridSquare> list = new List<PlanetGridSquare>();
     foreach (PlanetGridSquare planetGridSquare in this.TilesList)
     {
         if (planetGridSquare.TroopsHere.Count < planetGridSquare.number_allowed_troops && (planetGridSquare.building == null || planetGridSquare.building != null && planetGridSquare.building.CombatStrength == 0))
             list.Add(planetGridSquare);
     }
     if (list.Count > 0)
     {
         int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count);
         PlanetGridSquare planetGridSquare = list[index];
         foreach (PlanetGridSquare eventLocation in this.TilesList)
         {
             if (eventLocation == planetGridSquare)
             {
                 eventLocation.TroopsHere.Add(t);
                 this.TroopsHere.Add(t);
                 t.SetPlanet(this);
                 if (eventLocation.building == null || string.IsNullOrEmpty(eventLocation.building.EventTriggerUID) || (eventLocation.TroopsHere.Count <= 0 || eventLocation.TroopsHere[0].GetOwner().isFaction))
                     return true;
                 ResourceManager.EventsDict[eventLocation.building.EventTriggerUID].TriggerPlanetEvent(this, eventLocation.TroopsHere[0].GetOwner(), eventLocation, EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty), Planet.universeScreen);
             }
         }
     }
     return false;
 }
        public bool AssignTroopToNearestAvailableTile(Troop t, PlanetGridSquare tile)
        {
            List<PlanetGridSquare> list = new List<PlanetGridSquare>();
            foreach (PlanetGridSquare planetGridSquare in this.TilesList)
            {
                if (planetGridSquare.TroopsHere.Count < planetGridSquare.number_allowed_troops && (planetGridSquare.building == null || planetGridSquare.building != null && planetGridSquare.building.CombatStrength == 0) && (Math.Abs(tile.x - planetGridSquare.x) <= 1 && Math.Abs(tile.y - planetGridSquare.y) <= 1))
                    list.Add(planetGridSquare);
            }
            if (list.Count > 0)
            {
                int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count);
                PlanetGridSquare planetGridSquare1 = list[index];
                foreach (PlanetGridSquare planetGridSquare2 in this.TilesList)
                {
                    if (planetGridSquare2 == planetGridSquare1)
                    {
                        planetGridSquare2.TroopsHere.Add(t);
                        this.TroopsHere.Add(t);
                        t.SetPlanet(this);
                        return true;

                    }
                }
            }
            return false;
        }
 public static Ship CreateTroopShipAtPoint(string key, Empire Owner, Vector2 point, Troop troop)
 {
     Ship newShip = new Ship()
     {
         Role = "troop",
         Name = key,
         VanityName = troop.Name
     };
     newShip.LoadContent(GetContentManager());
     SceneObject newSO = new SceneObject();
     if (!Ship_Game.ResourceManager.ShipsDict[key].GetShipData().Animated)
     {
         newSO = new SceneObject(Ship_Game.ResourceManager.GetModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath).Meshes[0])
         {
             ObjectType = ObjectType.Dynamic
         };
     }
     else
     {
         SkinnedModel model = Ship_Game.ResourceManager.GetSkinnedModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath);
         newSO = new SceneObject(model.Model);
         newShip.SetAnimationController(new AnimationController(model.SkeletonBones), model);
     }
     newSO.ObjectType = ObjectType.Dynamic;
     newShip.SetSO(newSO);
     newShip.Position = point;
     foreach (Thruster t in Ship_Game.ResourceManager.ShipsDict[key].GetTList())
     {
         Thruster thr = new Thruster()
         {
             Parent = newShip,
             tscale = t.tscale,
             XMLPos = t.XMLPos
         };
         newShip.GetTList().Add(thr);
     }
     foreach (ModuleSlot slot in Ship_Game.ResourceManager.ShipsDict[key].ModuleSlotList)
     {
         ModuleSlot newSlot = new ModuleSlot();
         newSlot.SetParent(newShip);
         newSlot.SlotOptions = slot.SlotOptions;
         newSlot.Restrictions = slot.Restrictions;
         newSlot.Position = slot.Position;
         newSlot.facing = slot.facing;
         newSlot.InstalledModuleUID = slot.InstalledModuleUID;
         newShip.ModuleSlotList.AddLast(newSlot);
     }
     newShip.loyalty = Owner;
     newShip.Initialize();
     newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
     newShip.VanityName = troop.Name;
     lock (GlobalStats.ObjectManagerLocker)
     {
         Ship_Game.ResourceManager.universeScreen.ScreenManager.inter.ObjectManager.Submit(newShip.GetSO());
     }
     foreach (Thruster t in newShip.GetTList())
     {
         t.load_and_assign_effects(Ship_Game.ResourceManager.universeScreen.ScreenManager.Content, "Effects/ThrustCylinderB", "Effects/NoiseVolume", Ship_Game.ResourceManager.universeScreen.ThrusterEffect);
         t.InitializeForViewing();
     }
     newShip.TroopList.Add(Ship_Game.ResourceManager.CopyTroop(troop));
     Owner.AddShip(newShip);
     return newShip;
 }
        public static Troop CreateTroop(Troop t, Empire Owner)
        {
            Troop troop = new Troop()
            {
                Class = t.Class,
                Cost = t.Cost,
                Name = t.Name,
                Description = t.Description,
                HardAttack = t.HardAttack,
                Initiative = t.Initiative,
                SoftAttack = t.SoftAttack,
                Strength = t.Strength,
                StrengthMax = t.StrengthMax > 0 ? t.StrengthMax : t.Strength,
                Icon = t.Icon,
                BoardingStrength = t.BoardingStrength
            };

            if (Owner != null)
            {
                Troop strength = troop;
                strength.Strength = strength.Strength + (int)(Owner.data.Traits.GroundCombatModifier * (float)troop.Strength);
            }
            troop.TargetType = t.TargetType;
            troop.TexturePath = t.TexturePath;
            troop.Range = t.Range;
            troop.Experience = t.Experience;
            troop.SetOwner(Owner);
            troop.animated = t.animated;
            troop.idle_path = t.idle_path;
            troop.idle_x_offset = t.idle_x_offset;
            troop.idle_y_offset = t.idle_y_offset;
            troop.num_attack_frames = t.num_attack_frames;
            troop.num_idle_frames = t.num_idle_frames;
            troop.attack_width = t.attack_width;
            troop.attack_path = t.attack_path;
            troop.WhichFrame = (int)RandomMath.RandomBetween(1f, (float)(t.num_idle_frames - 1));
            troop.first_frame = t.first_frame;
            troop.sound_attack = t.sound_attack;
            troop.MovementCue = t.MovementCue;
            troop.MoveTimerBase = t.MoveTimerBase;
            troop.AttackTimerBase = t.AttackTimerBase;
            troop.Level = t.Level;
            troop.Kills = t.Kills;
            return troop;
        }
 public static Troop CopyTroop(Troop t)
 {
     Troop troop = new Troop()
     {
         Class = t.Class,
         Cost = t.Cost,
         Name = t.Name
     };
     troop.SetOwner(t.GetOwner());
     troop.Range = t.Range;
     troop.Description = t.Description;
     troop.HardAttack = t.HardAttack;
     troop.Initiative = t.Initiative;
     troop.SoftAttack = t.SoftAttack;
     troop.Strength = t.Strength;
     troop.StrengthMax = t.StrengthMax;
     troop.TargetType = t.TargetType;
     troop.TexturePath = t.TexturePath;
     troop.Experience = t.Experience;
     troop.Icon = t.Icon;
     troop.animated = t.animated;
     troop.idle_path = t.idle_path;
     troop.idle_x_offset = t.idle_x_offset;
     troop.idle_y_offset = t.idle_y_offset;
     troop.num_attack_frames = t.num_attack_frames;
     troop.num_idle_frames = t.num_idle_frames;
     troop.attack_width = t.attack_width;
     troop.attack_path = t.attack_path;
     troop.WhichFrame = (int)RandomMath.RandomBetween(1f, (float)(t.num_idle_frames - 1));
     troop.first_frame = t.first_frame;
     troop.MovementCue = t.MovementCue;
     troop.sound_attack = t.sound_attack;
     troop.MoveTimerBase = t.MoveTimerBase;
     troop.AttackTimerBase = t.AttackTimerBase;
     troop.Level = t.Level;
     troop.Kills = t.Kills;
     troop.BoardingStrength = t.BoardingStrength;
     return troop;
 }