public void InitializeFromSave()
 {
     if (this.InstalledModuleUID != "Dummy" && this.InstalledModuleUID != null)
     {
         this.module = ResourceManager.GetModule(this.InstalledModuleUID);
         this.module.installedSlot = this;
         this.module.SetParent(this.Parent);
         this.module.facing = this.facing;
         this.module.InitializeFromSave(this.Position);
     }
 }
        public override void HandleInput(InputState input)
        {
            this.CategoryList.HandleInput(input);
            this.CarrierOnlyBox.HandleInput(input);

            if (this.ActiveModule != null && (this.ActiveModule.InstalledWeapon != null && this.ActiveModule.ModuleType != ShipModuleType.Turret || this.ActiveModule.XSIZE != this.ActiveModule.YSIZE))
            {
                if (input.Left)
                    this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Left);
                if (input.Right)
                    this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Right);
                if (input.Down)
                    this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Rear);
                if (input.Up)
                    this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Normal);
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.Y) && !input.LastKeyboardState.IsKeyDown(Keys.Y) && !GlobalStats.TakingInput)
            {
                AudioManager.PlayCue("echo_affirm");
                this.ExitScreen();
            }
            if (this.close.HandleInput(input))
                this.ExitScreen();
            else if (input.CurrentKeyboardState.IsKeyDown(Keys.Z) && input.LastKeyboardState.IsKeyUp(Keys.Z) && input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl))
            {
                if (this.DesignStack.Count <= 0)
                    return;
                ShipModule shipModule = this.ActiveModule;
                DesignAction designAction = this.DesignStack.Pop();
                SlotStruct slot1 = new SlotStruct();
                foreach (SlotStruct slot2 in this.Slots)
                {
                    if (slot2.pq == designAction.clickedSS.pq)
                    {
                        this.ClearSlotNoStack(slot2);
                        slot1 = slot2;
                        slot1.facing = designAction.clickedSS.facing;
                    }
                    foreach (SlotStruct slotStruct in designAction.AlteredSlots)
                    {
                        if (slot2.pq == slotStruct.pq)
                        {
                            this.ClearSlotNoStack(slot2);
                            break;
                        }
                    }
                }
                if (designAction.clickedSS.ModuleUID != null)
                {
                    this.ActiveModule = ResourceManager.GetModule(designAction.clickedSS.ModuleUID);
                    this.ResetModuleState();
                    this.InstallModuleNoStack(slot1);
                }
                foreach (SlotStruct slotStruct in designAction.AlteredSlots)
                {
                    foreach (SlotStruct slot2 in this.Slots)
                    {
                        if (slot2.pq == slotStruct.pq && slotStruct.ModuleUID != null)
                        {
                            this.ActiveModule = ResourceManager.GetModule(slotStruct.ModuleUID);
                            this.ResetModuleState();
                            this.InstallModuleNoStack(slot2);
                            slot2.facing = slotStruct.facing;
                            slot2.ModuleUID = slotStruct.ModuleUID;
                        }
                    }
                }
                this.ActiveModule = shipModule;
                this.ResetModuleState();
            }
            else
            {
                if (!HelperFunctions.CheckIntersection(this.ModuleSelectionMenu.Menu, input.CursorPosition) && !HelperFunctions.CheckIntersection(this.HullSelectionRect, input.CursorPosition) && !HelperFunctions.CheckIntersection(this.ChooseFighterSub.Menu, input.CursorPosition))
                {
                    if (input.ScrollOut)
                    {
                        this.TransitionZoom -= 0.1f;
                        if ((double)this.TransitionZoom < 0.300000011920929)
                            this.TransitionZoom = 0.3f;
                        if ((double)this.TransitionZoom > 2.65000009536743)
                            this.TransitionZoom = 2.65f;
                    }
                    if (input.ScrollIn)
                    {
                        this.TransitionZoom += 0.1f;
                        if ((double)this.TransitionZoom < 0.300000011920929)
                            this.TransitionZoom = 0.3f;
                        if ((double)this.TransitionZoom > 2.65000009536743)
                            this.TransitionZoom = 2.65f;
                    }
                }
                if (input.CurrentKeyboardState.IsKeyDown(Keys.OemTilde))
                    input.LastKeyboardState.IsKeyUp(Keys.OemTilde);
                if (this.Debug)
                {
                    if (input.CurrentKeyboardState.IsKeyDown(Keys.Enter) && input.LastKeyboardState.IsKeyUp(Keys.Enter))
                    {
                        foreach (ModuleSlotData moduleSlotData in this.ActiveHull.ModuleSlotList)
                            moduleSlotData.InstalledModuleUID = (string)null;
                        new XmlSerializer(typeof(ShipData)).Serialize((TextWriter)new StreamWriter("Content/Hulls/" + this.ActiveHull.ShipStyle + "/" + this.ActiveHull.Name + ".xml"), (object)this.ActiveHull);
                    }
                    if (input.Right)
                        ++this.operation;
                    if (this.operation > (ShipDesignScreen.SlotModOperation)6)
                        this.operation = ShipDesignScreen.SlotModOperation.Delete;
                }
                this.HoveredModule = (ShipModule)null;
                this.mouseStateCurrent = Mouse.GetState();
                Vector2 vector2 = new Vector2((float)this.mouseStateCurrent.X, (float)this.mouseStateCurrent.Y);
                this.selector = (Selector)null;
                this.EmpireUI.HandleInput(input, (GameScreen)this);
                this.activeModSubMenu.HandleInputNoReset((object)this);
                this.hullSL.HandleInput(input);
                for (int index = this.hullSL.indexAtTop; index < this.hullSL.Copied.Count && index < this.hullSL.indexAtTop + this.hullSL.entriesToDisplay; ++index)
                {
                    ScrollList.Entry e = this.hullSL.Copied[index];
                    if (e.item is ModuleHeader)
                    {
                        if ((e.item as ModuleHeader).HandleInput(input, e))
                            return;
                    }
                    else if (HelperFunctions.CheckIntersection(e.clickRect, vector2))
                    {
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        e.clickRectHover = 1;
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        if (input.InGameSelect)
                        {
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                            if (!this.ShipSaved && !this.CheckDesign())
                            {
                                MessageBoxScreen messageBoxScreen = new MessageBoxScreen(Localizer.Token(2121), "Save", "No");
                                messageBoxScreen.Accepted += new EventHandler<EventArgs>(this.SaveWIPThenChangeHull);
                                messageBoxScreen.Cancelled += new EventHandler<EventArgs>(this.JustChangeHull);
                                this.changeto = e.item as ShipData;
                                this.ScreenManager.AddScreen((GameScreen)messageBoxScreen);
                                return;
                            }
                            else
                            {
                                this.ChangeHull(e.item as ShipData);
                                return;
                            }
                        }
                    }
                    else
                        e.clickRectHover = 0;
                }
                this.modSel.HandleInput((object)this);
                if (this.ActiveModule != null)
                {
                    if (this.ActiveModule.ModuleType == ShipModuleType.Hangar && !this.ActiveModule.IsTroopBay && !this.ActiveModule.IsSupplyBay)
                    {
                        this.UpdateHangarOptions(this.ActiveModule);
                        this.ChooseFighterSL.HandleInput(input);
                        for (int index = this.ChooseFighterSL.indexAtTop; index < this.ChooseFighterSL.Copied.Count && index < this.ChooseFighterSL.indexAtTop + this.ChooseFighterSL.entriesToDisplay; ++index)
                        {
                            ScrollList.Entry entry = this.ChooseFighterSL.Copied[index];
                            if (HelperFunctions.CheckIntersection(entry.clickRect, vector2))
                            {
                                this.selector = new Selector(this.ScreenManager, entry.clickRect);
                                entry.clickRectHover = 1;
                                this.selector = new Selector(this.ScreenManager, entry.clickRect);
                                if (input.InGameSelect)
                                {
                                    this.ActiveModule.hangarShipUID = (entry.item as Ship).Name;
                                    this.HangarShipUIDLast = (entry.item as Ship).Name;
                                    AudioManager.PlayCue("sd_ui_accept_alt3");
                                    return;
                                }
                            }
                        }
                    }
                }
                else if (this.HighlightedModule != null && this.HighlightedModule.ModuleType == ShipModuleType.Hangar && (!this.HighlightedModule.IsTroopBay && !this.HighlightedModule.IsSupplyBay))
                {
                    this.ChooseFighterSL.HandleInput(input);
                    for (int index = this.ChooseFighterSL.indexAtTop; index < this.ChooseFighterSL.Copied.Count && index < this.ChooseFighterSL.indexAtTop + this.ChooseFighterSL.entriesToDisplay; ++index)
                    {
                        ScrollList.Entry entry = this.ChooseFighterSL.Copied[index];
                        if (HelperFunctions.CheckIntersection(entry.clickRect, vector2))
                        {
                            this.selector = new Selector(this.ScreenManager, entry.clickRect);
                            entry.clickRectHover = 1;
                            this.selector = new Selector(this.ScreenManager, entry.clickRect);
                            if (input.InGameSelect)
                            {
                                this.HighlightedModule.hangarShipUID = (entry.item as Ship).Name;
                                this.HangarShipUIDLast = (entry.item as Ship).Name;
                                AudioManager.PlayCue("sd_ui_accept_alt3");
                                return;
                            }
                        }
                    }
                }
                for (int index = this.weaponSL.indexAtTop; index < this.weaponSL.Copied.Count && index < this.weaponSL.indexAtTop + this.weaponSL.entriesToDisplay; ++index)
                {
                    ScrollList.Entry e = this.weaponSL.Copied[index];
                    if (e.item is ModuleHeader)
                    {
                        if ((e.item as ModuleHeader).HandleInput(input, e))
                            return;
                    }
                    else if (HelperFunctions.CheckIntersection(e.clickRect, vector2))
                    {
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        e.clickRectHover = 1;
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        if (input.InGameSelect)
                        {
                            this.SetActiveModule(ResourceManager.GetModule((e.item as ShipModule).UID));
                            this.ResetModuleState();
                            return;
                        }
                    }
                    else
                        e.clickRectHover = 0;
                }
                this.weaponSL.HandleInput(input);
                if (HelperFunctions.CheckIntersection(this.HullSelectionRect, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed || HelperFunctions.CheckIntersection(this.modSel.Menu, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed || HelperFunctions.CheckIntersection(this.activeModSubMenu.Menu, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed)
                    return;
                if (HelperFunctions.CheckIntersection(this.modSel.Menu, vector2))
                {
                    if (this.mouseStateCurrent.ScrollWheelValue > this.mouseStatePrevious.ScrollWheelValue && this.weaponSL.indexAtTop > 0)
                        --this.weaponSL.indexAtTop;
                    if (this.mouseStateCurrent.ScrollWheelValue < this.mouseStatePrevious.ScrollWheelValue && this.weaponSL.indexAtTop + this.weaponSL.entriesToDisplay < this.weaponSL.Entries.Count)
                        ++this.weaponSL.indexAtTop;
                }
                if (HelperFunctions.CheckIntersection(this.ArcsButton.R, input.CursorPosition))
                    ToolTip.CreateTooltip(134, this.ScreenManager);
                if (this.ArcsButton.HandleInput(input))
                {
                    this.ArcsButton.ToggleOn = !this.ArcsButton.ToggleOn;
                    this.ShowAllArcs = this.ArcsButton.ToggleOn;
                }
                if (input.Tab)
                {
                    this.ShowAllArcs = !this.ShowAllArcs;
                    this.ArcsButton.ToggleOn = this.ShowAllArcs;
                }
                if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released)
                {
                    this.StartDragPos = input.CursorPosition;
                    this.cameraVelocity.X = 0.0f;
                    this.cameraVelocity.Y = 0.0f;
                }
                if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Pressed)
                {
                    float num1 = input.CursorPosition.X - this.StartDragPos.X;
                    float num2 = input.CursorPosition.Y - this.StartDragPos.Y;
                    this.camera._pos += new Vector2(-num1, -num2);
                    this.StartDragPos = input.CursorPosition;
                    this.cameraPosition.X += -num1;
                    this.cameraPosition.Y += -num2;
                }
                else
                {
                    this.cameraVelocity.X = 0.0f;
                    this.cameraVelocity.Y = 0.0f;
                }
                this.cameraVelocity.X = MathHelper.Clamp(this.cameraVelocity.X, -10f, 10f);
                this.cameraVelocity.Y = MathHelper.Clamp(this.cameraVelocity.Y, -10f, 10f);
                if (input.Escaped)
                    this.ExitScreen();
                if (this.ToggleOverlay)
                {
                    foreach (SlotStruct slotStruct in this.Slots)
                    {
                        Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)slotStruct.pq.enclosingRect.X, (float)slotStruct.pq.enclosingRect.Y));
                        if (HelperFunctions.CheckIntersection(new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom)), vector2))
                        {
                            if (slotStruct.isDummy && slotStruct.parent.module != null)
                                this.HoveredModule = slotStruct.parent.module;
                            else if (slotStruct.module != null)
                                this.HoveredModule = slotStruct.module;
                            if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released)
                            {
                                AudioManager.GetCue("simple_beep").Play();
                                if (this.Debug)
                                {
                                    this.DebugAlterSlot(slotStruct.slotReference.Position, this.operation);
                                    return;
                                }
                                else if (slotStruct.isDummy && slotStruct.parent.module != null)
                                    this.HighlightedModule = slotStruct.parent.module;
                                else if (slotStruct.module != null)
                                    this.HighlightedModule = slotStruct.module;
                            }
                        }
                    }
                }
                if (HelperFunctions.CheckIntersection(this.upArrow, vector2) && this.mouseStateCurrent.LeftButton == ButtonState.Released && (this.mouseStatePrevious.LeftButton == ButtonState.Pressed && this.scrollPosition > 0))
                {
                    --this.scrollPosition;
                    AudioManager.GetCue("blip_click").Play();
                    foreach (ModuleButton moduleButton in this.ModuleButtons)
                        moduleButton.moduleRect.Y += 128;
                }
                if (HelperFunctions.CheckIntersection(this.downArrow, vector2) && this.mouseStateCurrent.LeftButton == ButtonState.Released && this.mouseStatePrevious.LeftButton == ButtonState.Pressed)
                {
                    ++this.scrollPosition;
                    AudioManager.GetCue("blip_click").Play();
                    foreach (ModuleButton moduleButton in this.ModuleButtons)
                        moduleButton.moduleRect.Y -= 128;
                }
                if (HelperFunctions.CheckIntersection(this.ModuleSelectionArea, vector2))
                {
                    if (input.ScrollIn && this.scrollPosition > 0)
                    {
                        --this.scrollPosition;
                        AudioManager.GetCue("blip_click").Play();
                        foreach (ModuleButton moduleButton in this.ModuleButtons)
                            moduleButton.moduleRect.Y += 128;
                    }
                    if (input.ScrollOut)
                    {
                        ++this.scrollPosition;
                        AudioManager.GetCue("blip_click").Play();
                        foreach (ModuleButton moduleButton in this.ModuleButtons)
                            moduleButton.moduleRect.Y -= 128;
                    }
                }
                if (this.mouseStateCurrent.RightButton == ButtonState.Released && this.mouseStatePrevious.RightButton == ButtonState.Pressed)
                {
                    //this should actually clear slots
                    this.ActiveModule = (ShipModule)null;
                    foreach (SlotStruct parent in this.Slots)
                    {
                        parent.ShowInvalid = false;
                        parent.ShowValid = false;
                        Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)parent.pq.enclosingRect.X, (float)parent.pq.enclosingRect.Y));
                        Rectangle rect = new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom));
                        if ((parent.module != null || parent.isDummy) && HelperFunctions.CheckIntersection(rect, vector2)) //if clicked at this slot
                        {
                            DesignAction designAction = new DesignAction();
                            designAction.clickedSS = new SlotStruct();
                            designAction.clickedSS.pq = parent.isDummy ? parent.parent.pq : parent.pq;
                            designAction.clickedSS.Restrictions = parent.Restrictions;
                            designAction.clickedSS.facing = parent.module != null ? parent.module.facing : 0.0f;
                            designAction.clickedSS.ModuleUID = parent.isDummy ? parent.parent.ModuleUID : parent.ModuleUID;
                            designAction.clickedSS.module = parent.module;
                            designAction.clickedSS.slotReference = parent.isDummy ? parent.parent.slotReference : parent.slotReference;
                            this.DesignStack.Push(designAction);
                            AudioManager.GetCue("sub_bass_whoosh").Play();
                            if (parent.isDummy)
                                this.ClearParentSlot(parent.parent);
                            else
                                this.ClearParentSlot(parent);
                            this.RecalculatePower();
                        }
                    }
                }
                foreach (ModuleButton moduleButton in this.ModuleButtons)
                {
                    if (HelperFunctions.CheckIntersection(this.ModuleSelectionArea, new Vector2((float)(moduleButton.moduleRect.X + 30), (float)(moduleButton.moduleRect.Y + 30))))
                    {
                        if (HelperFunctions.CheckIntersection(moduleButton.moduleRect, vector2))
                        {
                            if (input.InGameSelect)
                                this.SetActiveModule(ResourceManager.GetModule(moduleButton.ModuleUID));
                            moduleButton.isHighlighted = true;
                        }
                        else
                            moduleButton.isHighlighted = false;
                    }
                }
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && this.ActiveModule != null)
                {
                    foreach (SlotStruct slot in this.Slots)
                    {
                        Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)slot.pq.enclosingRect.X, (float)slot.pq.enclosingRect.Y));
                        if (HelperFunctions.CheckIntersection(new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom)), vector2))
                        {
                            AudioManager.GetCue("sub_bass_mouseover").Play();
                            this.InstallModule(slot);
                        }
                    }
                }
                else if (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed)
                    this.HoldTimer -= .01666f;
                else
                    this.HoldTimer = 0.50f;

                foreach (SlotStruct slotStruct in this.Slots)
                {
                    if (slotStruct.ModuleUID != null && this.HighlightedModule != null && (slotStruct.module == this.HighlightedModule && (double)slotStruct.module.FieldOfFire != 0.0) && slotStruct.module.ModuleType == ShipModuleType.Turret)
                    {
                        float num1 = slotStruct.module.FieldOfFire / 2f;
                        Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)(slotStruct.pq.enclosingRect.X + 16 * (int)slotStruct.module.XSIZE / 2), (float)(slotStruct.pq.enclosingRect.Y + 16 * (int)slotStruct.module.YSIZE / 2)));
                        float num2 = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2));
                        float num3 = this.HighlightedModule.facing;
                        float num4 = Math.Abs(num2 - num3);
                        if ((double)num4 > (double)num1)
                        {
                            if ((double)num2 > 180.0)
                                num2 = (float)(-1.0 * (360.0 - (double)num2));
                            if ((double)num3 > 180.0)
                                num3 = (float)(-1.0 * (360.0 - (double)num3));
                            num4 = Math.Abs(num2 - num3);
                        }

                        if (GlobalStats.AltArcControl)
                        {
                            //The Doctor: ALT (either) + LEFT CLICK to pick and move arcs. This way, it's impossible to accidentally pick the wrong arc, while it's just as responsive and smooth as the original method when you are trying to.
                            if ((double)num4 < (double)num1 && (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed && ((input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt) || input.LastKeyboardState.IsKeyDown(Keys.LeftAlt)) || (input.CurrentKeyboardState.IsKeyDown(Keys.RightAlt) || input.LastKeyboardState.IsKeyDown(Keys.RightAlt)))))
                            {

                                this.HighlightedModule.facing = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2));
                            }
                        }
                        else
                        {
                            //Delay method
                            if ((double)num4 < (double)num1 && (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed && this.HoldTimer < 0))
                            {
                                this.HighlightedModule.facing = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2));
                            }

                        }

                    }
                }
                foreach (UIButton uiButton in this.Buttons)
                {
                    if (HelperFunctions.CheckIntersection(uiButton.Rect, vector2))
                    {
                        uiButton.State = UIButton.PressState.Hover;
                        if (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed)
                            uiButton.State = UIButton.PressState.Pressed;
                        if (this.mouseStateCurrent.LeftButton == ButtonState.Released && this.mouseStatePrevious.LeftButton == ButtonState.Pressed)
                        {
                            switch (uiButton.Launches)
                            {
                                case "Toggle Overlay":
                                    AudioManager.PlayCue("blip_click");
                                    this.ToggleOverlay = !this.ToggleOverlay;
                                    continue;
                                case "Save As...":
                                    if (this.CheckDesign())
                                    {
                                        this.ScreenManager.AddScreen((GameScreen)new DesignManager(this, this.ActiveHull.Name));
                                        continue;
                                    }
                                    else
                                    {
                                        AudioManager.PlayCue("UI_Misc20");
                                        this.ScreenManager.AddScreen((GameScreen)new MessageBoxScreen(Localizer.Token(2049)));
                                        continue;
                                    }
                                case "Load":
                                    this.ScreenManager.AddScreen((GameScreen)new LoadDesigns(this));
                                    continue;
                                default:
                                    continue;
                            }
                        }
                    }
                    else
                        uiButton.State = UIButton.PressState.Normal;
                }
                if (this.ActiveHull != null)
                {
                    foreach (ToggleButton toggleButton in this.CombatStatusButtons)
                    {
                        if (HelperFunctions.CheckIntersection(toggleButton.r, input.CursorPosition))
                        {
                            if (toggleButton.HasToolTip)
                                ToolTip.CreateTooltip(toggleButton.WhichToolTip, this.ScreenManager);
                            if (input.InGameSelect)
                            {
                                AudioManager.PlayCue("sd_ui_accept_alt3");
                                switch (toggleButton.Action)
                                {
                                    case "attack":
                                        this.CombatState = CombatState.AttackRuns;
                                        break;
                                    case "arty":
                                        this.CombatState = CombatState.Artillery;
                                        break;
                                    case "hold":
                                        this.CombatState = CombatState.HoldPosition;
                                        break;
                                    case "orbit_left":
                                        this.CombatState = CombatState.OrbitLeft;
                                        break;
                                    case "broadside_left":
                                        this.CombatState = CombatState.BroadsideLeft;
                                        break;
                                    case "orbit_right":
                                        this.CombatState = CombatState.OrbitRight;
                                        break;
                                    case "broadside_right":
                                        this.CombatState = CombatState.BroadsideRight;
                                        break;
                                    case "evade":
                                        this.CombatState = CombatState.Evade;
                                        break;
                                }
                            }
                        }
                        else
                            toggleButton.Hover = false;
                        switch (toggleButton.Action)
                        {
                            case "attack":
                                toggleButton.Active = this.CombatState == CombatState.AttackRuns;
                                continue;
                            case "arty":
                                toggleButton.Active = this.CombatState == CombatState.Artillery;
                                continue;
                            case "hold":
                                toggleButton.Active = this.CombatState == CombatState.HoldPosition;
                                continue;
                            case "orbit_left":
                                toggleButton.Active = this.CombatState == CombatState.OrbitLeft;
                                continue;
                            case "broadside_left":
                                toggleButton.Active = this.CombatState == CombatState.BroadsideLeft;
                                continue;
                            case "orbit_right":
                                toggleButton.Active = this.CombatState == CombatState.OrbitRight;
                                continue;
                            case "broadside_right":
                                toggleButton.Active = this.CombatState == CombatState.BroadsideRight;
                                continue;
                            case "evade":
                                toggleButton.Active = this.CombatState == CombatState.Evade;
                                continue;
                            default:
                                continue;
                        }
                    }
                }
                this.mouseStatePrevious = this.mouseStateCurrent;
                base.HandleInput(input);
            }
        }
 /// <summary>
 /// Seperate module intialization for ships loaded from save games. 
 /// </summary>
 /// <param name="pos"></param>
 public void InitializeFromSave(Vector2 pos)
 {
     DebugInfoScreen.ModulesCreated = DebugInfoScreen.ModulesCreated + 1;
     this.XMLPosition = pos;
     this.radius = 8f;
     base.Position = pos;
     base.Dimensions = new Vector2(16f, 16f);
     Vector2 RelativeShipCenter = new Vector2(512f, 512f);
     this.moduleCenter.X = base.Position.X + 256f;
     this.moduleCenter.Y = base.Position.Y + 256f;
     this.distanceToParentCenter = (float)Math.Sqrt((double)((this.moduleCenter.X - RelativeShipCenter.X) * (this.moduleCenter.X - RelativeShipCenter.X) + (this.moduleCenter.Y - RelativeShipCenter.Y) * (this.moduleCenter.Y - RelativeShipCenter.Y)));
     float scaleFactor = 1f;
     ShipModule shipModule = this;
     shipModule.distanceToParentCenter = shipModule.distanceToParentCenter * scaleFactor;
     this.offsetAngle = (float)Math.Abs(base.findAngleToTarget(RelativeShipCenter, this.moduleCenter));
     this.offsetAngleRadians = MathHelper.ToRadians(this.offsetAngle);
     this.SetInitialPosition();
     this.SetAttributesByType();
     //if (this.Parent != null && this.Parent.loyalty != null)
     //{
     //    //bool flag = false;
     //    //if (this.HealthMax == base.Health)
     //    //    flag = true;
     //    this.HealthMax = this.HealthMax + this.HealthMax * this.Parent.loyalty.data.Traits.ModHpModifier;
     //    base.Health = base.Health + base.Health * this.Parent.loyalty.data.Traits.ModHpModifier;
     //    this.Health = base.Health;
     //    //if (flag)
     //    //    this.Health = this.HealthMax;
     //}
     if (!this.isDummy && (this.installedSlot.state == ShipDesignScreen.ActiveModuleState.Left || this.installedSlot.state == ShipDesignScreen.ActiveModuleState.Right))
     {
         byte xsize = this.YSIZE;
         byte ysize = this.XSIZE;
         this.XSIZE = xsize;
         this.YSIZE = ysize;
     }
     if (this.XSIZE > 1)
     {
         for (int xs = this.XSIZE; xs > 1; xs--)
         {
             ShipModule dummy = new ShipModule()
             {
                 XMLPosition = this.XMLPosition
             };
             dummy.XMLPosition.X = dummy.XMLPosition.X + (float)(16 * (xs - 1));
             dummy.isDummy = true;
             dummy.ParentOfDummy = this;
             dummy.Mass = 0f;
             dummy.Parent = this.Parent;
             dummy.Health = base.Health;
             dummy.HealthMax = this.HealthMax;
             dummy.ModuleType = ShipModuleType.Dummy;
             dummy.Initialize();
             this.LinkedModulesList.Add(dummy);
             if (this.YSIZE > 1)
             {
                 for (int ys = this.YSIZE; ys > 1; ys--)
                 {
                     dummy = new ShipModule()
                     {
                         ParentOfDummy = this,
                         XMLPosition = this.XMLPosition
                     };
                     dummy.XMLPosition.X = dummy.XMLPosition.X + (float)(16 * (xs - 1));
                     dummy.XMLPosition.Y = dummy.XMLPosition.Y + (float)(16 * (ys - 1));
                     dummy.isDummy = true;
                     dummy.Mass = 0f;
                     dummy.Health = base.Health;
                     dummy.HealthMax = this.HealthMax;
                     dummy.ModuleType = ShipModuleType.Dummy;
                     dummy.Parent = this.Parent;
                     dummy.Initialize();
                     this.LinkedModulesList.Add(dummy);
                 }
             }
         }
     }
     if (this.YSIZE > 1)
     {
         for (int ys = this.YSIZE; ys > 1; ys--)
         {
             ShipModule dummy = new ShipModule()
             {
                 XMLPosition = this.XMLPosition
             };
             dummy.XMLPosition.Y = dummy.XMLPosition.Y + (float)(16 * (ys - 1));
             dummy.isDummy = true;
             dummy.ParentOfDummy = this;
             dummy.Mass = 0f;
             dummy.Parent = this.Parent;
             dummy.Health = base.Health;
             dummy.HealthMax = this.HealthMax;
             dummy.ModuleType = ShipModuleType.Dummy;
             dummy.Initialize();
             this.LinkedModulesList.Add(dummy);
         }
     }
     if (!this.isDummy)
     {
         foreach (ShipModule module in this.LinkedModulesList)
         {
             module.Parent = this.Parent;
             module.system = this.Parent.GetSystem();
             module.Dimensions = base.Dimensions;
             module.IconTexturePath = this.IconTexturePath;
             foreach (ModuleSlot slot in this.Parent.ModuleSlotList)
             {
                 if (slot.Position != module.XMLPosition)
                 {
                     continue;
                 }
                 slot.module = module;
                 break;
             }
             module.Initialize(module.XMLPosition);
         }
     }
     base.Initialize();
 }
 public void InitializeForLoad()
 {
     this.module = ResourceManager.ShipModulesDict[this.InstalledModuleUID];
 }
 private void SetupSlots()
 {
     this.Slots.Clear();
     foreach (ModuleSlotData slot in this.ActiveHull.ModuleSlotList)
     {
         SlotStruct ss = new SlotStruct();
         PrimitiveQuad pq = new PrimitiveQuad(slot.Position.X + this.offset.X - 8f, slot.Position.Y + this.offset.Y - 8f, 16f, 16f);
         ss.pq = pq;
         ss.Restrictions = slot.Restrictions;
         ss.facing = slot.facing;
         ss.ModuleUID = slot.InstalledModuleUID;
         ss.state = slot.state;
         ss.slotReference = slot;
         ss.SlotOptions = slot.SlotOptions;
         this.Slots.Add(ss);
     }
     foreach (SlotStruct slot in this.Slots)
     {
         if (slot.ModuleUID == null)
         {
             continue;
         }
         this.ActiveModule = Ship_Game.ResourceManager.GetModule(slot.ModuleUID);
         this.ChangeModuleState(slot.state);
         this.InstallModuleFromLoad(slot);
         if (slot.module == null || slot.module.ModuleType != ShipModuleType.Hangar)
         {
             continue;
         }
         slot.module.hangarShipUID = slot.SlotOptions;
     }
     this.ActiveModule = null;
     this.ActiveModState = ShipDesignScreen.ActiveModuleState.Normal;
 }
        public void BeamRecreate(Vector2 srcCenter, int Thickness, Ship Owner, GameplayObject target)
        {
            this.ArmorDamageBonus = 0f;
            this.ArmorPiercing = 0;
            this.BeamOffsetAngle = 0f;
            this.BeamZ = 0f;
            this.Center = Vector2.Zero;
            this.collidedThisFrame = false ;
            this.damageAmount = 0;
            this.damageRadius = 0;
            this.DamageToggleOn = false;
            this.displacement = 1f;
            this.duration = 0;
            this.Duration = 2f;
            this.explodes = false;
            this.firstRun = true;
            this.owner = null;
            this.hitLast = null;
            this.HitModule = null;
            this.IgnoresShields = false;
            this.infinite = false;
            this.isInDeepSpace = false;
            this.LastDamagedBy = null;
            this.loyalty = null;

            this.SetSystem(null);
            this.thickness = 0;
            this.weapon = null;
            this.weaponEffect = "";
            this.WeaponEffectType = "";
            this.WeaponType = "";
            this.ShieldDamageBonus = 0;
            this.RotationRadsPerSecond = 0;

            this.Target = target;
            this.owner = Owner;
            Vector2 TargetPosition = Vector2.Normalize(target.Center);
            if (Owner.InFrustum)
            {
                this.DamageToggleSound = AudioManager.GetCue("sd_shield_static_1");
            }
            if (this.owner.isInDeepSpace || this.owner.GetSystem() == null)
            {
                UniverseScreen.DeepSpaceManager.BeamList.Add(this);
            }
            else
            {
                this.system = this.owner.GetSystem();
                this.system.spatialManager.BeamList.Add(this);
            }
            this.Source = srcCenter;
            this.BeamOffsetAngle = Owner.Rotation - MathHelper.ToRadians(HelperFunctions.findAngleToTarget(srcCenter, TargetPosition));
            this.Destination = HelperFunctions.findPointFromAngleAndDistanceUsingRadians(srcCenter, Owner.Rotation + this.BeamOffsetAngle, this.range);
            this.ActualHitDestination = this.Destination;
            //this.Vertices = new VertexPositionNormalTexture[4];
            //this.Indexes = new int[6];
            this.BeamZ = RandomMath2.RandomBetween(-1f, 1f);
            Vector3[] points = HelperFunctions.BeamPoints(srcCenter, TargetPosition, (float)Thickness, new Vector2[4], 0, this.BeamZ);
            this.UpperLeft = points[0];
            this.UpperRight = points[1];
            this.LowerLeft = points[2];
            this.LowerRight = points[3];
            this.FillVertices();
            this.Active = true;
        }
 private void DoOrdinanceTransporterLogic(ShipModule module)
 {
     foreach (Ship ship in module.GetParent().loyalty.GetShips().Where(ship => Vector2.Distance(this.Owner.Center, ship.Center) <= module.TransporterRange + 500f && ship.Ordinance < ship.OrdinanceMax && !ship.hasOrdnanceTransporter).OrderBy(ship => ship.Ordinance).ToList())
     {
         if (ship != null)
         {
             module.TransporterTimer = module.TransporterTimerConstant;
             float TransferAmount = 0f;
             //check how much can be taken
             if (module.TransporterOrdnance > module.GetParent().Ordinance)
                 TransferAmount = module.GetParent().Ordinance;
             else
                 TransferAmount = module.TransporterOrdnance;
             //check how much can be given
             if (TransferAmount > ship.OrdinanceMax - ship.Ordinance)
                 TransferAmount = ship.OrdinanceMax - ship.Ordinance;
             //Transfer
             ship.Ordinance += TransferAmount;
             module.GetParent().Ordinance -= TransferAmount;
             module.GetParent().PowerCurrent -= module.TransporterPower * (TransferAmount / module.TransporterOrdnance);
             if(this.Owner.InFrustum && ResourceManager.SoundEffectDict.ContainsKey("transporter"))
             {
                 GameplayObject.audioListener.Position = ShipModule.universeScreen.camPos;
                 AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict["transporter"], GameplayObject.audioListener, module.GetParent().emitter, 0.5f);
             }
             return;
         }
     }
 }
 private void InstallModuleNoStack(SlotStruct slot)
 {
     //System.Diagnostics.Debug.Assert(false);
     //looks like this function is not actually used, see if anyone manages to trigger this
     int num = 0;    //check for sufficient slots
     for (int index1 = 0; index1 < (int)this.ActiveModule.YSIZE; ++index1)
     {
         for (int index2 = 0; index2 < (int)this.ActiveModule.XSIZE; ++index2)
         {
             foreach (SlotStruct slotStruct in this.Slots)
             {   //checks if this slot is within xsize and ysize
                 if (slotStruct.pq.Y == slot.pq.Y + 16 * index1 && slotStruct.pq.X == slot.pq.X + 16 * index2)
                 {
                     if(slotStruct.module == null && slotStruct.parent == null){   //make sure they are actually empty!
                         ++num;
                     }
                 }
             }
         }
     }
     if (num == (int)this.ActiveModule.XSIZE * (int)this.ActiveModule.YSIZE)
     {   //set module to this slot
         this.ClearSlotNoStack(slot);
         this.ClearDestinationSlotsNoStack(slot);
         slot.ModuleUID = this.ActiveModule.UID;
         slot.module = this.ActiveModule;
         slot.module.SetAttributesNoParent();
         slot.state = this.ActiveModState;
         slot.module.hangarShipUID = this.ActiveModule.hangarShipUID;
         slot.module.facing = this.ActiveModule.facing;
         slot.tex = ResourceManager.TextureDict[ResourceManager.ShipModulesDict[this.ActiveModule.UID].IconTexturePath];
         //set other slots occupied by the module to use this slot as parent
         for (int index1 = 0; index1 < (int)this.ActiveModule.YSIZE; ++index1)
         {
             for (int index2 = 0; index2 < (int)this.ActiveModule.XSIZE; ++index2)
             {
                 if (!(index2 == 0 && index1 == 0))  //if not the parent slot
                 {
                     foreach (SlotStruct slotStruct in this.Slots)
                     {
                         if (slotStruct.pq.Y == slot.pq.Y + 16 * index1 && slotStruct.pq.X == slot.pq.X + 16 * index2)
                         {
                             slot.facing = 0.0f;
                             slotStruct.facing = 0.0f;
                             slotStruct.ModuleUID = (string)null;
                             slotStruct.isDummy = true;
                             slotStruct.tex = (Texture2D)null;
                             slotStruct.module = (ShipModule)null;
                             slotStruct.parent = slot;
                         }
                     }
                 }
             }
         }
         this.RecalculatePower();
         this.ShipSaved = false;
         if (this.ActiveModule.ModuleType != ShipModuleType.Hangar)
         {
             this.ActiveModule = Ship_Game.ResourceManager.GetModule(this.ActiveModule.UID);
         }
         //grabs a fresh copy of the same module type to cursor
         this.ChangeModuleState(this.ActiveModState);
         //set rotation for new module at cursor
     }
     else
         this.PlayNegativeSound();
 }
 //Modified by McShooterz: not used before, changed to be used for exploding modules
 public void ExplodeAtModule(GameplayObject source, ShipModule HitModule, float damageAmount, float damageRadius)
 {
     if ((double)damageRadius <= 0.0 || HitModule.GetParent().dying || !HitModule.GetParent().Active)
         return;
     BatchRemovalCollection<ExplosionRay> removalCollection = new BatchRemovalCollection<ExplosionRay>();
     int num1 = 15;
     float num2 = (float)(360 / num1);
     for (int index = 0; index < num1; ++index)
         removalCollection.Add(new ExplosionRay()
         {
             Direction = HelperFunctions.findPointFromAngleAndDistance(Vector2.Zero, num2 * (float)index, 1f),
             Damage = damageAmount / (float)num1
         });
     List<ShipModule> list = new List<ShipModule>();
     list.Add(HitModule);
     foreach (ModuleSlot ModuleSlot in HitModule.GetParent().ModuleSlotList.Where(moduleSlot => Vector2.Distance(HitModule.Center, moduleSlot.module.Center) <= damageRadius).OrderBy(moduleSlot => Vector2.Distance(HitModule.Center, moduleSlot.module.Center)))
     {
         list.Add(ModuleSlot.module);
     }
     int num3 = 0;
     while ((double)num3 < (double)damageRadius)
     {
         foreach (ExplosionRay explosionRay in (List<ExplosionRay>)removalCollection)
         {
             if ((double)explosionRay.Damage > 0.0)
             {
                 foreach (ShipModule shipModule in list)
                 {
                     if (shipModule.Active && (double)shipModule.Health > 0.0)
                     {
                         Vector2 vector2_1 = HitModule.Center + explosionRay.Direction * (float)num3;
                         Vector2 vector2_2 = shipModule.Center - vector2_1;
                         if ((double)Vector2.Distance(vector2_1, shipModule.Center) <= 8.0 && (double)explosionRay.Damage > 0.0)
                         {
                             float health = shipModule.Health;
                             shipModule.Damage(source, explosionRay.Damage);
                             explosionRay.Damage -= health;
                         }
                     }
                 }
             }
         }
         num3 += 8;
     }
 }
 private void DoAssaultTransporterLogic(ShipModule module)
 {
     foreach (ArtificialIntelligence.ShipWeight ship in this.NearbyShips.Where(Ship => Ship.ship.loyalty != null && Ship.ship.loyalty != this.Owner.loyalty && Ship.ship.shield_power <= 0 && Vector2.Distance(this.Owner.Center, Ship.ship.Center) <= module.TransporterRange + 500f).OrderBy(Ship => Vector2.Distance(this.Owner.Center, Ship.ship.Center)))
     {
         if (ship != null)
         {
             byte TroopCount = 0;
             bool Transported = false;
             for (byte i = 0; i < this.Owner.TroopList.Count(); i++)
             {
                 if (this.Owner.TroopList[i] == null)
                     continue;
                 if (this.Owner.TroopList[i].GetOwner() == this.Owner.loyalty)
                 {
                     ship.ship.TroopList.Add(this.Owner.TroopList[i]);
                     this.Owner.TroopList.Remove(this.Owner.TroopList[i]);
                     TroopCount++;
                     Transported = true;
                 }
                 if (TroopCount == module.TransporterTroopAssault)
                     break;
             }
             if (Transported)
             {
                 module.TransporterTimer = module.TransporterTimerConstant;
                 if (this.Owner.InFrustum && ResourceManager.SoundEffectDict.ContainsKey("transporter"))
                 {
                     GameplayObject.audioListener.Position = ShipModule.universeScreen.camPos;
                     AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict["transporter"], GameplayObject.audioListener, module.GetParent().emitter, 0.5f);
                 }
                 return;
             }
         }
     }
 }
 public static void AddExplosion(Vector3 Position, float radius, float intensity, float duration, ShipModule mod)
 {
     if (radius == 0f)
     {
         radius = 1f;
     }
     Explosion newExp = new Explosion()
     {
         duration = 2.25f,
         pos = Position
     };
     if (ExplosionManager.universeScreen.viewState == UniverseScreen.UnivScreenState.ShipView)
     {
         newExp.light = new PointLight();
         newExp.Radius = radius;
         newExp.light.World = Matrix.Identity * Matrix.CreateTranslation(Position);
         newExp.light.Position = Position;
         newExp.light.Radius = radius;
         newExp.light.ObjectType = ObjectType.Dynamic;
         newExp.light.DiffuseColor = new Vector3(0.9f, 0.8f, 0.7f);
         newExp.light.Intensity = intensity;
         newExp.light.Enabled = true;
         lock (GlobalStats.ObjectManagerLocker)
         {
             ExplosionManager.universeScreen.ScreenManager.inter.LightManager.Submit(newExp.light);
         }
     }
     switch ((int)RandomMath2.RandomBetween(0f, 2f))
     {
         case 0:
         {
             newExp.AnimationTexture = "sd_explosion_12a_cc/sd_explosion_12a_cc_00000";
             newExp.AnimationBasePath = "sd_explosion_12a_cc/sd_explosion_12a_cc_";
             break;
         }
         case 1:
         {
             newExp.AnimationTexture = "sd_explosion_14a_cc/sd_explosion_14a_cc_00000";
             newExp.AnimationBasePath = "sd_explosion_14a_cc/sd_explosion_14a_cc_";
             break;
         }
         case 2:
         {
             newExp.AnimationTexture = "sd_explosion_07a_cc/sd_explosion_07a_cc_00000";
             newExp.AnimationBasePath = "sd_explosion_07a_cc/sd_explosion_07a_cc_00000";
             break;
         }
     }
     lock (GlobalStats.ExplosionLocker)
     {
         ExplosionManager.ExplosionList.Add(newExp);
     }
 }
 public void SetActiveModule(ShipModule mod)
 {
     AudioManager.GetCue("smallservo").Play();
     this.ActiveModule = mod;
 }
 public override void HandleInput(InputState input)
 {
     if (!base.IsActive)
     {
         return;
     }
     if (this.LoadModelButton.HandleInput(input))
     {
         base.ScreenManager.AddScreen(new LoadModelScreen(this));
     }
     if (input.Escaped)
     {
         this.ActiveModule = null;
         this.ExitScreen();
     }
     if (this.ShipNameBox.HandlingInput)
     {
         this.ShipNameBox.HandleTextInput(ref this.HullName, input);
         this.ShipNameBox.Text = this.HullName;
     }
     if (!HelperFunctions.CheckIntersection(this.ShipNameBox.ClickableArea, input.CursorPosition))
     {
         this.ShipNameBox.Hover = false;
         if (input.InGameSelect)
         {
             this.ShipNameBox.HandlingInput = false;
         }
     }
     else
     {
         this.ShipNameBox.Hover = true;
         if (input.InGameSelect)
         {
             this.ShipNameBox.HandlingInput = true;
         }
     }
     foreach (ToggleButton button in this.DesignStateButtons)
     {
         if (!HelperFunctions.CheckIntersection(button.r, input.CursorPosition))
         {
             button.Hover = false;
         }
         else
         {
             if (!button.Hover)
             {
                 AudioManager.PlayCue("sd_ui_mouseover");
             }
             button.Hover = true;
             if (button.HasToolTip)
             {
                 ToolTip.CreateTooltip(button.WhichToolTip, base.ScreenManager);
             }
             if (input.InGameSelect)
             {
                 AudioManager.PlayCue("sd_ui_accept_alt3");
                 this.SetRestrictionFromText(button.Action);
             }
         }
         if (this.GetRestrictionFromText(button.Action) != this.DesignState)
         {
             button.Active = false;
         }
         else
         {
             button.Active = true;
         }
     }
     if (input.C)
     {
         this.MarkThruster();
     }
     if (this.SaveHullButton.HandleInput(input))
     {
         this.SaveShipData("New Ship");
     }
     if (input.ScrollIn)
     {
         ShipToolScreen shipToolScreen = this;
         shipToolScreen.tscale = shipToolScreen.tscale + 1f;
     }
     if (input.ScrollOut)
     {
         ShipToolScreen shipToolScreen1 = this;
         shipToolScreen1.tscale = shipToolScreen1.tscale - 1f;
     }
     if (input.Right)
     {
         this.heat = 1f;
     }
     if (input.Left)
     {
         this.heat = 0.01f;
     }
     if (input.Up)
     {
         this.applyThruster = true;
     }
     if (input.Down)
     {
         this.applyThruster = false;
     }
     if (input.YButtonDown || input.Right)
     {
         this.NextDesignState();
     }
     if (input.BButtonDown)
     {
         this.ExitScreen();
     }
 }
        public void SetActiveModule(ShipModule mod)
        {
            AudioManager.GetCue("smallservo").Play();
            mod.SetAttributesNoParent();
            this.ActiveModule = mod;
            this.ResetModuleState();
            foreach (SlotStruct s in this.Slots)
            {
                s.ShowInvalid = false;
                s.ShowValid = false;
                if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.I && (s.Restrictions == Restrictions.I || s.Restrictions == Restrictions.IO))
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.IO && (s.Restrictions == Restrictions.I || s.Restrictions == Restrictions.IO || s.Restrictions == Restrictions.O))
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.IE && (s.Restrictions == Restrictions.I || s.Restrictions == Restrictions.E))
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.OE && (s.Restrictions == Restrictions.O || s.Restrictions == Restrictions.E))
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.O && (s.Restrictions == Restrictions.O || s.Restrictions == Restrictions.IO))
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions == Restrictions.E && s.Restrictions == Restrictions.E)
                {
                    s.ShowValid = true;
                }
                else if (Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].Restrictions != Restrictions.IOE || s.Restrictions != Restrictions.I && s.Restrictions != Restrictions.IO && s.Restrictions != Restrictions.O && s.Restrictions != Restrictions.E)
                {
                    s.ShowInvalid = true;
                }

                else
                {
                    s.ShowValid = true;
                }
            }
            if (this.ActiveModule.ModuleType == ShipModuleType.Hangar)
            {
                this.ChooseFighterSL.Entries.Clear();
                this.ChooseFighterSL.Copied.Clear();
                foreach (string shipname in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).ShipsWeCanBuild)
                {
                    if (!this.ActiveModule.PermittedHangarRoles.Contains(Ship_Game.ResourceManager.ShipsDict[shipname].Role) || Ship_Game.ResourceManager.ShipsDict[shipname].Size >= this.ActiveModule.MaximumHangarShipSize)
                    {
                        continue;
                    }
                    this.ChooseFighterSL.AddItem(Ship_Game.ResourceManager.ShipsDict[shipname]);
                }
                if (this.HangarShipUIDLast != "Undefined" && this.ActiveModule.PermittedHangarRoles.Contains(Ship_Game.ResourceManager.ShipsDict[HangarShipUIDLast].Role) && this.ActiveModule.MaximumHangarShipSize >= Ship_Game.ResourceManager.ShipsDict[HangarShipUIDLast].Size)
                {
                    this.ActiveModule.hangarShipUID = this.HangarShipUIDLast;
                }
                else if (this.ChooseFighterSL.Entries.Count > 0)
                {
                    this.ActiveModule.hangarShipUID = (this.ChooseFighterSL.Entries[0].item as Ship).Name;
                }
            }
            this.HighlightedModule = null;
            this.HoveredModule = null;
            this.ResetModuleState();
        }
        public static ShipModule GetModule(string uid)
        {
            ShipModule module = new ShipModule()
            {
                BombType = Ship_Game.ResourceManager.ShipModulesDict[uid].BombType,
                HealPerTurn = Ship_Game.ResourceManager.ShipModulesDict[uid].HealPerTurn,
                BonusRepairRate = Ship_Game.ResourceManager.ShipModulesDict[uid].BonusRepairRate,
                Cargo_Capacity = Ship_Game.ResourceManager.ShipModulesDict[uid].Cargo_Capacity,
                Cost = Ship_Game.ResourceManager.ShipModulesDict[uid].Cost,
                DescriptionIndex = Ship_Game.ResourceManager.ShipModulesDict[uid].DescriptionIndex,
                ECM = Ship_Game.ResourceManager.ShipModulesDict[uid].ECM,
                EMP_Protection = Ship_Game.ResourceManager.ShipModulesDict[uid].EMP_Protection,
                explodes = Ship_Game.ResourceManager.ShipModulesDict[uid].explodes,
                FieldOfFire = Ship_Game.ResourceManager.ShipModulesDict[uid].FieldOfFire,
                hangarShipUID = Ship_Game.ResourceManager.ShipModulesDict[uid].hangarShipUID,
                hangarTimer = Ship_Game.ResourceManager.ShipModulesDict[uid].hangarTimer,
                hangarTimerConstant = Ship_Game.ResourceManager.ShipModulesDict[uid].hangarTimerConstant,
                Health = Ship_Game.ResourceManager.ShipModulesDict[uid].HealthMax,
                IsSupplyBay = Ship_Game.ResourceManager.ShipModulesDict[uid].IsSupplyBay,
                HealthMax = Ship_Game.ResourceManager.ShipModulesDict[uid].HealthMax,
                isWeapon = Ship_Game.ResourceManager.ShipModulesDict[uid].isWeapon,
                IsTroopBay = Ship_Game.ResourceManager.ShipModulesDict[uid].IsTroopBay,
                Mass = Ship_Game.ResourceManager.ShipModulesDict[uid].Mass,
                MechanicalBoardingDefense = Ship_Game.ResourceManager.ShipModulesDict[uid].MechanicalBoardingDefense,
                ModuleType = Ship_Game.ResourceManager.ShipModulesDict[uid].ModuleType,
                NameIndex = Ship_Game.ResourceManager.ShipModulesDict[uid].NameIndex,
                numberOfColonists = Ship_Game.ResourceManager.ShipModulesDict[uid].numberOfColonists,
                numberOfEquipment = Ship_Game.ResourceManager.ShipModulesDict[uid].numberOfEquipment,
                numberOfFood = Ship_Game.ResourceManager.ShipModulesDict[uid].numberOfFood,
                OrdinanceCapacity = Ship_Game.ResourceManager.ShipModulesDict[uid].OrdinanceCapacity,
                OrdnanceAddedPerSecond = Ship_Game.ResourceManager.ShipModulesDict[uid].OrdnanceAddedPerSecond,
                PowerDraw = Ship_Game.ResourceManager.ShipModulesDict[uid].PowerDraw,
                PowerFlowMax = Ship_Game.ResourceManager.ShipModulesDict[uid].PowerFlowMax,
                PowerRadius = Ship_Game.ResourceManager.ShipModulesDict[uid].PowerRadius,
                PowerStoreMax = Ship_Game.ResourceManager.ShipModulesDict[uid].PowerStoreMax,
                SensorRange = Ship_Game.ResourceManager.ShipModulesDict[uid].SensorRange,
                shield_power = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_power_max,
                shield_power_max = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_power_max,
                shield_radius = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_radius,
                shield_recharge_delay = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_recharge_delay,
                shield_recharge_rate = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_recharge_rate,
                TechLevel = Ship_Game.ResourceManager.ShipModulesDict[uid].TechLevel,
                thrust = Ship_Game.ResourceManager.ShipModulesDict[uid].thrust,
                TroopBoardingDefense = Ship_Game.ResourceManager.ShipModulesDict[uid].TroopBoardingDefense,
                TroopCapacity = Ship_Game.ResourceManager.ShipModulesDict[uid].TroopCapacity,
                TroopsSupplied = Ship_Game.ResourceManager.ShipModulesDict[uid].TroopsSupplied,
                UID = Ship_Game.ResourceManager.ShipModulesDict[uid].UID,
                WarpThrust = Ship_Game.ResourceManager.ShipModulesDict[uid].WarpThrust,
                XSIZE = Ship_Game.ResourceManager.ShipModulesDict[uid].XSIZE,
                YSIZE = Ship_Game.ResourceManager.ShipModulesDict[uid].YSIZE,
                InhibitionRadius = Ship_Game.ResourceManager.ShipModulesDict[uid].InhibitionRadius,
                FightersOnly = Ship_Game.ResourceManager.ShipModulesDict[uid].FightersOnly,
                DroneModule = Ship_Game.ResourceManager.ShipModulesDict[uid].DroneModule,
                FighterModule = Ship_Game.ResourceManager.ShipModulesDict[uid].FighterModule,
                CorvetteModule = Ship_Game.ResourceManager.ShipModulesDict[uid].CorvetteModule,
                FrigateModule = Ship_Game.ResourceManager.ShipModulesDict[uid].FrigateModule,
                DestroyerModule = Ship_Game.ResourceManager.ShipModulesDict[uid].DestroyerModule,
                CruiserModule = Ship_Game.ResourceManager.ShipModulesDict[uid].CruiserModule,
                CarrierModule = Ship_Game.ResourceManager.ShipModulesDict[uid].CarrierModule,
                CapitalModule = Ship_Game.ResourceManager.ShipModulesDict[uid].CapitalModule,
                FreighterModule = Ship_Game.ResourceManager.ShipModulesDict[uid].FreighterModule,
                PlatformModule = Ship_Game.ResourceManager.ShipModulesDict[uid].PlatformModule,
                StationModule = Ship_Game.ResourceManager.ShipModulesDict[uid].StationModule,
                TurnThrust = Ship_Game.ResourceManager.ShipModulesDict[uid].TurnThrust,
                DeployBuildingOnColonize = Ship_Game.ResourceManager.ShipModulesDict[uid].DeployBuildingOnColonize,
                PermittedHangarRoles = Ship_Game.ResourceManager.ShipModulesDict[uid].PermittedHangarRoles,
                MaximumHangarShipSize = Ship_Game.ResourceManager.ShipModulesDict[uid].MaximumHangarShipSize,
                IsRepairModule = Ship_Game.ResourceManager.ShipModulesDict[uid].IsRepairModule,
                MountLeft = Ship_Game.ResourceManager.ShipModulesDict[uid].MountLeft,
                MountRight = Ship_Game.ResourceManager.ShipModulesDict[uid].MountRight,
                MountRear = Ship_Game.ResourceManager.ShipModulesDict[uid].MountRear,
                WarpMassCapacity = Ship_Game.ResourceManager.ShipModulesDict[uid].WarpMassCapacity,
                PowerDrawAtWarp = Ship_Game.ResourceManager.ShipModulesDict[uid].PowerDrawAtWarp,
                FTLSpeed = Ship_Game.ResourceManager.ShipModulesDict[uid].FTLSpeed,
                ResourceStored = Ship_Game.ResourceManager.ShipModulesDict[uid].ResourceStored,
                ResourceRequired = Ship_Game.ResourceManager.ShipModulesDict[uid].ResourceRequired,
                ResourcePerSecond = Ship_Game.ResourceManager.ShipModulesDict[uid].ResourcePerSecond,
                ResourcePerSecondWarp = Ship_Game.ResourceManager.ShipModulesDict[uid].ResourcePerSecondWarp,
                ResourceStorageAmount = Ship_Game.ResourceManager.ShipModulesDict[uid].ResourceStorageAmount,
                IsCommandModule = Ship_Game.ResourceManager.ShipModulesDict[uid].IsCommandModule,
                shield_recharge_combat_rate = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_recharge_combat_rate,
                FTLSpoolTime = Ship_Game.ResourceManager.ShipModulesDict[uid].FTLSpoolTime,
                shieldsOff = Ship_Game.ResourceManager.ShipModulesDict[uid].shieldsOff,
                SensorBonus = Ship_Game.ResourceManager.ShipModulesDict[uid].SensorBonus,
                TransporterOrdnance = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterOrdnance,
                TransporterPower = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterPower,
                TransporterRange = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterRange,
                TransporterTimerConstant = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterTimerConstant,
                TransporterTroopLanding = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterTroopLanding,
                TransporterTroopAssault = Ship_Game.ResourceManager.ShipModulesDict[uid].TransporterTroopAssault,
                KineticResist = Ship_Game.ResourceManager.ShipModulesDict[uid].KineticResist,
                EnergyResist = Ship_Game.ResourceManager.ShipModulesDict[uid].EnergyResist,
                GuidedResist = Ship_Game.ResourceManager.ShipModulesDict[uid].GuidedResist,
                MissileResist = Ship_Game.ResourceManager.ShipModulesDict[uid].MissileResist,
                HybridResist = Ship_Game.ResourceManager.ShipModulesDict[uid].HybridResist,
                BeamResist = Ship_Game.ResourceManager.ShipModulesDict[uid].BeamResist,
                ExplosiveResist = Ship_Game.ResourceManager.ShipModulesDict[uid].ExplosiveResist,
                InterceptResist = Ship_Game.ResourceManager.ShipModulesDict[uid].InterceptResist,
                RailgunResist = Ship_Game.ResourceManager.ShipModulesDict[uid].RailgunResist,
                SpaceBombResist = Ship_Game.ResourceManager.ShipModulesDict[uid].SpaceBombResist,
                BombResist = Ship_Game.ResourceManager.ShipModulesDict[uid].BombResist,
                BioWeaponResist = Ship_Game.ResourceManager.ShipModulesDict[uid].BioWeaponResist,
                DroneResist = Ship_Game.ResourceManager.ShipModulesDict[uid].DroneResist,
                WarpResist = Ship_Game.ResourceManager.ShipModulesDict[uid].WarpResist,
                TorpedoResist = Ship_Game.ResourceManager.ShipModulesDict[uid].TorpedoResist,
                CannonResist = Ship_Game.ResourceManager.ShipModulesDict[uid].CannonResist,
                SubspaceResist = Ship_Game.ResourceManager.ShipModulesDict[uid].SubspaceResist,
                PDResist = Ship_Game.ResourceManager.ShipModulesDict[uid].PDResist,
                FlakResist = Ship_Game.ResourceManager.ShipModulesDict[uid].FlakResist,
                APResist = Ship_Game.ResourceManager.ShipModulesDict[uid].APResist,
                DamageThreshold = Ship_Game.ResourceManager.ShipModulesDict[uid].DamageThreshold,
                shield_threshold = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_threshold,
                shield_energy_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_energy_resist,
                shield_kinetic_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_kinetic_resist,
                shield_explosive_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_explosive_resist,
                shield_flak_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_flak_resist,
                shield_hybrid_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_hybrid_resist,
                shield_missile_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_missile_resist,
                shield_railgun_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_railgun_resist,
                shield_subspace_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_subspace_resist,
                shield_warp_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_warp_resist,
                shield_beam_resist = Ship_Game.ResourceManager.ShipModulesDict[uid].shield_beam_resist,
                IndirectPower = Ship_Game.ResourceManager.ShipModulesDict[uid].IndirectPower,
                isPowerArmour = Ship_Game.ResourceManager.ShipModulesDict[uid].isPowerArmour,
                isBulkhead = Ship_Game.ResourceManager.ShipModulesDict[uid].isBulkhead

            };

            #region TargetWeight
            module.TargetValue += module.ModuleType == ShipModuleType.Armor ? -1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Bomb ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Command ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Countermeasure ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Drone ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Engine ? 2 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.FuelCell ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Hangar ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.MainGun ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.MissileLauncher ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Ordnance ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.PowerPlant ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Sensors ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Shield ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Spacebomb ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Special ? 1 : 0;
            module.TargetValue += module.ModuleType == ShipModuleType.Turret ? 1 : 0;
            module.TargetValue += module.explodes ? 2 : 0;
            module.TargetValue += module.isWeapon ? 1 : 0;

            #endregion
            return module;
        }
 public void UpdateHangarOptions(ShipModule mod)
 {
     if (mod.ModuleType == ShipModuleType.Hangar)
     {
         this.ChooseFighterSL.Entries.Clear();
         this.ChooseFighterSL.Copied.Clear();
         foreach (string shipname in EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).ShipsWeCanBuild)
         {
             if (!mod.PermittedHangarRoles.Contains(Ship_Game.ResourceManager.ShipsDict[shipname].Role) || Ship_Game.ResourceManager.ShipsDict[shipname].Size >= mod.MaximumHangarShipSize)
             {
                 continue;
             }
             this.ChooseFighterSL.AddItem(Ship_Game.ResourceManager.ShipsDict[shipname]);
         }
     }
 }
 public Weapon(Ship owner, ShipModule moduleAttachedTo)
 {
     this.owner = owner;
     this.moduleAttachedTo = moduleAttachedTo;
 }
        private void InstallModuleOrig(SlotStruct slot)
        {
            int num = 0;
            for (int index1 = 0; index1 < (int)this.ActiveModule.YSIZE; ++index1)
            {
                for (int index2 = 0; index2 < (int)this.ActiveModule.XSIZE; ++index2)
                {
                    foreach (SlotStruct slotStruct in this.Slots)
                    {
                        if (slotStruct.pq.Y == slot.pq.Y + 16 * index1 && slotStruct.pq.X == slot.pq.X + 16 * index2 && slotStruct.ShowValid)
                        {
                            if (slotStruct.module == null && slotStruct.parent == null)
                            {   //make sure they are actually empty!
                                ++num;
                            }
                        }

                    }
                }
            }
            if (num == (int)this.ActiveModule.XSIZE * (int)this.ActiveModule.YSIZE)
            {
                DesignAction designAction = new DesignAction();
                designAction.clickedSS = new SlotStruct();
                designAction.clickedSS.pq = slot.pq;
                designAction.clickedSS.Restrictions = slot.Restrictions;
                designAction.clickedSS.facing = slot.module != null ? slot.module.facing : 0.0f;
                designAction.clickedSS.ModuleUID = slot.ModuleUID;
                designAction.clickedSS.module = slot.module;
                designAction.clickedSS.tex = slot.tex;
                designAction.clickedSS.slotReference = slot.slotReference;
                designAction.clickedSS.state = slot.state;
                this.DesignStack.Push(designAction);
                this.ClearSlot(slot);
                this.ClearDestinationSlots(slot);
                slot.ModuleUID = this.ActiveModule.UID;
                slot.module = this.ActiveModule;
                slot.module.SetAttributesNoParent();
                slot.state = this.ActiveModState;
                slot.module.facing = this.ActiveModule.facing;
                slot.tex = ResourceManager.TextureDict[ResourceManager.ShipModulesDict[this.ActiveModule.UID].IconTexturePath];
                for (int index1 = 0; index1 < (int)this.ActiveModule.YSIZE; ++index1)
                {
                    for (int index2 = 0; index2 < (int)this.ActiveModule.XSIZE; ++index2)
                    {
                        if (!(index2 == 0 & index1 == 0))
                        {
                            foreach (SlotStruct slotStruct in this.Slots)
                            {
                                if (slotStruct.pq.Y == slot.pq.Y + 16 * index1 && slotStruct.pq.X == slot.pq.X + 16 * index2)
                                {
                                    slot.facing = 0.0f;
                                    slotStruct.facing = 0.0f;
                                    slotStruct.ModuleUID = (string)null;
                                    slotStruct.isDummy = true;
                                    slotStruct.tex = (Texture2D)null;
                                    slotStruct.module = (ShipModule)null;
                                    slotStruct.parent = slot;
                                }
                            }
                        }
                    }
                }
                this.RecalculatePower();
                this.ShipSaved = false;
                if (this.ActiveModule.ModuleType != ShipModuleType.Hangar)
                {
                    this.ActiveModule = Ship_Game.ResourceManager.GetModule(this.ActiveModule.UID);
                }
                this.ChangeModuleState(this.ActiveModState);
            }
            else
                this.PlayNegativeSound();
        }
 public Projectile(Ship owner, Vector2 direction, ShipModule moduleAttachedTo)
 {
     this.loyalty = owner.loyalty;
     this.owner = owner;
     if (!owner.isInDeepSpace)
     {
         this.system = owner.GetSystem();
     }
     else
     {
         this.isInDeepSpace = true;
     }
     base.Position = moduleAttachedTo.Center;
     this.moduleAttachedTo = moduleAttachedTo;
     this.Center = moduleAttachedTo.Center;
     this.emitter.Position = new Vector3(moduleAttachedTo.Center, 0f);
 }
 //Added by McShooterz: module repair priority list
 public static int ModulePriority(ShipModule ShipModule)
 {
     if (ShipModule.ModuleType == ShipModuleType.Command)
         return 0;
     if (ShipModule.ModuleType == ShipModuleType.PowerPlant)
         return 1;
     if (ShipModule.ModuleType == ShipModuleType.PowerConduit)
         return 2;
     if (ShipModule.ModuleType == ShipModuleType.Engine)
         return 3;
     if (ShipModule.ModuleType == ShipModuleType.Shield)
         return 4;
     if (ShipModule.ModuleType == ShipModuleType.Armor)
         return 6;
     return 5;
 }
 public target(ShipModule module, int weight)
 {
     this.module = module;
     this.weight = weight;
 }