public static Ship CreateShipForBattleMode(string key, Empire Owner, Vector2 p)
 {
     Ship newShip = new Ship()
     {
         Role = Ship_Game.ResourceManager.ShipsDict[key].Role,
         Name = Ship_Game.ResourceManager.ShipsDict[key].Name,
         BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength,
         BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp
     };
     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
         };
         newShip.SetSO(newSO);
     }
     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);
     }
     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.state = slot.state;
         newSlot.InstalledModuleUID = slot.InstalledModuleUID;
         newShip.ModuleSlotList.AddLast(newSlot);
     }
     newShip.Position = p;
     newShip.loyalty = Owner;
     newShip.Initialize();
     newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
     newShip.isInDeepSpace = true;
     Owner.AddShip(newShip);
     return newShip;
 }
 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;
 }
        //Added by McShooterz: for refit to keep name
        public static Ship CreateShipAt(string key, Empire Owner, Planet p, bool DoOrbit, string RefitName, byte RefitLevel)
        {
            Ship newShip;
            //if (universeScreen.MasterShipList.pendingRemovals.TryPop(out newShip))
            //{
            //    newShip.ShipRecreate();
            //    newShip.Role = Ship_Game.ResourceManager.ShipsDict[key].Role;
            //    newShip.Name = Ship_Game.ResourceManager.ShipsDict[key].Name;
            //    newShip.BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength;
            //    newShip.BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp;
            //}
            //else
            newShip = new Ship()
            {
                Role = Ship_Game.ResourceManager.ShipsDict[key].Role,
                Name = Ship_Game.ResourceManager.ShipsDict[key].Name,
                BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength,
                BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp

            };
            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
                };
                newShip.SetSO(newSO);
            }
            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);
            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.state = slot.state;
                newSlot.InstalledModuleUID = slot.InstalledModuleUID;
                newShip.ModuleSlotList.AddLast(newSlot);
            }
            newShip.Position = p.Position;
            newShip.loyalty = Owner;

            newShip.Initialize();
            //Added by McShooterz: add automatic ship naming
            newShip.VanityName = RefitName;
            newShip.Level = RefitLevel;
            newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
            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();
            }
            if (newShip.Role == "fighter")
            {
                Ship level = newShip;
                level.Level += Owner.data.BonusFighterLevels;
            }
            Owner.AddShip(newShip);
            newShip.GetAI().State = AIState.AwaitingOrders;
            return newShip;
        }
 public static Ship CreateShipAtPointNow(string key, Empire Owner, Vector2 p)
 {
     Ship newShip = new Ship();
     if (!Ship_Game.ResourceManager.ShipsDict.ContainsKey(key))
     {
         return null;
     }
     newShip.Role = Ship_Game.ResourceManager.ShipsDict[key].Role;
     newShip.Name = Ship_Game.ResourceManager.ShipsDict[key].Name;
     newShip.BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength;
     newShip.BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp;
     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
         };
         newShip.SetSO(newSO);
     }
     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);
     if (newShip.Role == "fighter" && Owner.data != null)
     {
         Ship level = newShip;
         level.Level = level.Level + Owner.data.BonusFighterLevels;
     }
     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.state = slot.state;
         newSlot.InstalledModuleUID = slot.InstalledModuleUID;
         newShip.ModuleSlotList.AddLast(newSlot);
     }
     newShip.Position = p;
     newShip.loyalty = Owner;
     newShip.Initialize();
     //Added by McShooterz: add automatic ship naming
     if (GlobalStats.ActiveMod != null && Ship_Game.ResourceManager.ShipNames.CheckForName(Owner.data.Traits.ShipType, newShip.Role))
         newShip.VanityName = Ship_Game.ResourceManager.ShipNames.GetName(Owner.data.Traits.ShipType, newShip.Role);
     newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
     lock (GlobalStats.ObjectManagerLocker)
     {
         Ship_Game.ResourceManager.universeScreen.ScreenManager.inter.ObjectManager.Submit(newShip.GetSO());
     }
     newShip.isInDeepSpace = true;
     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();
     }
     Owner.AddShip(newShip);
     return newShip;
 }
        public static Ship GetShip(string key)
        {
            Ship newShip = new Ship()
            {
                Role = Ship_Game.ResourceManager.ShipsDict[key].Role,
                BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength,
                BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp
            };
            newShip.LoadContent(GetContentManager());
            newShip.Name = Ship_Game.ResourceManager.ShipsDict[key].Name;
            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
                };
                newShip.SetSO(newSO);
            }
            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);
            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.state = slot.state;
                newSlot.InstalledModuleUID = slot.InstalledModuleUID;
                newShip.ModuleSlotList.AddLast(newSlot);
            }

            return newShip;
        }
 public static Ship GetPlayerShip(string key)
 {
     Ship newShip = new Ship()
     {
         PlayerShip = true,
         Role = Ship_Game.ResourceManager.ShipsDict[key].Role
     };
     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
         };
         newShip.SetSO(newSO);
     }
     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);
     foreach (Thruster t in Ship_Game.ResourceManager.ShipsDict[key].GetTList())
     {
         Thruster thr = new Thruster()
         {
             Parent = newShip,
             XMLPos = t.XMLPos,
             tscale = t.tscale
         };
         newShip.GetTList().Add(thr);
     }
     if (newShip.FirstNode == null)
     {
         (new ShipModuleNode()).Next = new ShipModuleNode();
     }
     foreach (ModuleSlot slot in Ship_Game.ResourceManager.ShipsDict[key].ModuleSlotList)
     {
         ModuleSlot newSlot = new ModuleSlot()
         {
             Restrictions = slot.Restrictions,
             Position = slot.Position,
             facing = slot.facing,
             InstalledModuleUID = slot.InstalledModuleUID
         };
         newShip.ModuleSlotList.AddLast(newSlot);
     }
     return newShip;
 }
 public static LinkedList<ModuleSlot> LoadSlotDataListToSlotList(List<ModuleSlotData> dataList, Ship parent)
 {
     LinkedList<ModuleSlot> linkedList = new LinkedList<ModuleSlot>();
     foreach (ModuleSlotData moduleSlotData in dataList)
     {
         ModuleSlot moduleSlot = new ModuleSlot();
         moduleSlot.ModuleHealth = moduleSlotData.Health;
         moduleSlot.Shield_Power = moduleSlotData.Shield_Power;
         moduleSlot.Position = moduleSlotData.Position;
         moduleSlot.facing = moduleSlotData.facing;
         moduleSlot.state = moduleSlotData.state;
         moduleSlot.Restrictions = moduleSlotData.Restrictions;
         moduleSlot.InstalledModuleUID = moduleSlotData.InstalledModuleUID;
         moduleSlot.HangarshipGuid = moduleSlotData.HangarshipGuid;
         if (moduleSlotData.SlotOptions != null)
             moduleSlot.SlotOptions = moduleSlotData.SlotOptions;
         linkedList.AddLast(moduleSlot);
     }
     return linkedList;
 }
 private string GetConduitGraphic(ModuleSlot ss, Ship ship)
 {
     bool flag1 = false;
     bool flag2 = false;
     bool flag3 = false;
     bool flag4 = false;
     int num1 = 0;
     foreach (ModuleSlot moduleSlot in ship.ModuleSlotList)
     {
         if (moduleSlot.module != null && moduleSlot.module.ModuleType == ShipModuleType.PowerConduit && moduleSlot != ss)
         {
             int num2 = (int)Math.Abs(moduleSlot.module.XMLPosition.X - ss.module.XMLPosition.X) / 16;
             int num3 = (int)Math.Abs(moduleSlot.module.XMLPosition.Y - ss.module.XMLPosition.Y) / 16;
             if (num2 == 1 && num3 == 0)
             {
                 if ((double)moduleSlot.module.XMLPosition.X > (double)ss.module.XMLPosition.X)
                     flag1 = true;
                 else
                     flag2 = true;
             }
             if (num3 == 1 && num2 == 0)
             {
                 if ((double)moduleSlot.module.XMLPosition.Y > (double)ss.module.XMLPosition.Y)
                     flag4 = true;
                 else
                     flag3 = true;
             }
         }
     }
     if (flag2)
         ++num1;
     if (flag1)
         ++num1;
     if (flag3)
         ++num1;
     if (flag4)
         ++num1;
     if (num1 <= 1)
     {
         if (flag3)
             return "Conduits/conduit_powerpoint_down";
         if (flag4)
             return "Conduits/conduit_powerpoint_up";
         if (flag2)
             return "Conduits/conduit_powerpoint_right";
         return flag1 ? "Conduits/conduit_powerpoint_left" : "Conduits/conduit_intersection";
     }
     else
     {
         if (num1 == 3)
         {
             if (flag3 && flag4 && flag2)
                 return "Conduits/conduit_tsection_left";
             if (flag3 && flag4 && flag1)
                 return "Conduits/conduit_tsection_right";
             if (flag2 && flag1 && flag4)
                 return "Conduits/conduit_tsection_down";
             if (flag2 && flag1 && flag3)
                 return "Conduits/conduit_tsection_up";
         }
         else
         {
             if (num1 == 4)
                 return "Conduits/conduit_intersection";
             if (num1 == 2)
             {
                 if (flag2 && flag3)
                     return "Conduits/conduit_corner_BR";
                 if (flag2 && flag4)
                     return "Conduits/conduit_corner_TR";
                 if (flag1 && flag3)
                     return "Conduits/conduit_corner_BL";
                 if (flag1 && flag4)
                     return "Conduits/conduit_corner_TL";
                 if (flag3 && flag4)
                     return "Conduits/conduit_straight_vertical";
                 if (flag2 && flag1)
                     return "Conduits/conduit_straight_horizontal";
             }
         }
         return "";
     }
 }
 private void CheckAndPowerConduit(ModuleSlot slot)
 {
     if (!slot.module.Active)
         return;
     slot.module.Powered = true;
     slot.CheckedConduits = true;
     foreach (ModuleSlot slot1 in this.ModuleSlotList)
     {
         if (slot1 != slot && (int)Math.Abs(slot.Position.X - slot1.Position.X) / 16 + (int)Math.Abs(slot.Position.Y - slot1.Position.Y) / 16 == 1 && (slot1.module != null && slot1.module.ModuleType == ShipModuleType.PowerConduit) && (slot1.module.ModuleType == ShipModuleType.PowerConduit && !slot1.CheckedConduits))
             this.CheckAndPowerConduit(slot1);
     }
 }