public override void OnUpdate() { //If there are overrideEvents and we haven't initially processed them do so now (should only run ONCE) if (overrideEvents && !overrideEventsProcessed) { try { foreach (PartModule pm in part.Modules) //should be a shorter way to do this, but a foreach cycle works { if (pm.moduleName == overrideModuleName) { overrideEventList = pm.Events; if (overrideEventNameOpen != "" && !overrideEventList.Contains(overrideEventNameOpen)) { overrideEventNameOpen = ""; overrideEvents = false; } if (overrideEventNameClose != "" && !overrideEventList.Contains(overrideEventNameClose)) { overrideEventNameClose = ""; overrideEvents = false; } break; } } } catch (Exception) { //throw; } overrideEventsProcessed = true; } //If there are disableEvents and we haven't initially processed them do so now (should only run ONCE) if (disableEvents && !disableEventsProcessed) { try { foreach (PartModule pm in part.Modules) //should be a shorter way to do this, but a foreach cycle works { if (pm.moduleName == disableModuleName) { disableEventList = pm.Events; if (disableEventName != "" && !disableEventList.Contains(disableEventName)) { disableEventName = ""; disableEvents = false; } break; } } } catch (Exception) { //throw; } disableEventsProcessed = true; } //Once-OFF if camera active on startup/loading open the camera (moved from OnStart to allow for disable and override events if (activeonStartup) { eventOpenCamera(); activeonStartup = false; } //If there are overrideEvents or disableEvents process them on every OnUpdate in case their partmodule is resetting them. if (overrideEvents || disableEvents) { processOverrideDisableEvents(!Active); } Events["eventReviewScience"].active = _scienceData.Count > 0; if (vessel.targetObject != _lastTarget && vessel.targetObject != null) { targettingMode = TargettingMode.Planet; selectedTargetIndex = -1; _lastTarget = vessel.targetObject; } //if (vessel.targetObject != null) //{ // Utilities.Log_Debug("Vessel target=" + vessel.targetObject.GetTransform().position); //} //if (!_inEditor && _camera.Enabled && windowState != WindowSate.Hidden && vessel.isActiveVessel) //{ //if (_camera.Enabled && f++ % frameLimit == 0) //_camera.draw(); //} }
private void TargettingGalWindow(int windowID) { GUILayout.BeginVertical(); GalscrollViewVector = GUILayout.BeginScrollView(GalscrollViewVector, GUILayout.Height(300),GUILayout.Width(GUI_WIDTH_SMALL)); filterContractTargets = GUILayout.Toggle(filterContractTargets,new GUIContent("Show only contract targets","If selected only targets that are the subject of a current contract will be shown")); //RSTUtils.Utilities.Log_Debug(String.Format(" - TargettingWindow - TSTGalaxies.Galaxies.Count = {0}", TSTGalaxies.Galaxies.Count)); var newTarget = 0; if (RBWrapper.APIRBReady && RBWrapper.RBactualAPI.enabled) { newTarget = TSTGalaxies.Galaxies. FindIndex( g => TSTProgressTracker.HasTelescopeCompleted(g) || (ContractSystem.Instance && ContractSystem.Instance.GetCurrentActiveContracts<TSTTelescopeContract>().Any(t => t.target.name == g.name)) ? GUILayout.Button(g.theName) : (filterContractTargets ? false : (TSTMstStgs.Instance.RBCelestialBodies[TSTGalaxies.CBGalaxies.Find(x => x.theName == g.theName)].isResearched ? GUILayout.Button(g.theName): false))); } else { newTarget = TSTGalaxies.Galaxies. FindIndex( g => TSTProgressTracker.HasTelescopeCompleted(g) || (ContractSystem.Instance && ContractSystem.Instance.GetCurrentActiveContracts<TSTTelescopeContract>().Any(t => t.target.name == g.name)) ? GUILayout.Button(g.theName) : (filterContractTargets ? false : GUILayout.Button(g.theName))); } //RSTUtils.Utilities.Log_Debug(String.Format(" - TargettingWindow - newTarget = {0}", newTarget)); if (newTarget != -1 && newTarget != selectedTargetIndex) { vessel.targetObject = null; FlightGlobals.fetch.SetVesselTarget(null); targettingMode = TargettingMode.Galaxy; selectedTargetIndex = newTarget; galaxyTarget = TSTGalaxies.Galaxies[selectedTargetIndex]; FlightGlobals.fetch.SetVesselTarget(galaxyTarget); Utilities.Log_Debug("Targetting: {0} : {1},layer= {2},scaledpos= {3}", newTarget.ToString(), galaxyTarget.name, galaxyTarget.gameObject.layer.ToString(), galaxyTarget.scaledPosition.ToString()); Utilities.Log_Debug("pos= {0}", galaxyTarget.position.ToString()); ScreenMessages.PostScreenMessage("Target: " + galaxyTarget.theName, 5f, ScreenMessageStyle.UPPER_CENTER); } GUILayout.EndScrollView(); GUILayout.Space(10); showGalTargetsWindow = !GUILayout.Button(new GUIContent("Hide", "Hide this Window")); GUILayout.EndVertical(); if (TSTMstStgs.Instance.TSTsettings.Tooltips) Utilities.SetTooltipText(); GUI.DragWindow(); }
/// <summary> /// Adjust position possibilies based on the fact that a ship was sunk /// </summary> /// <param name="size">size of ship</param> void Sink(Ship ship) { // Remove this ship type from ship position consideration for (var i = 0; i < AdaptivePlayer.Width; ++i) { for (var j = 0; j < AdaptivePlayer.Width; ++j) { if (_score[i, j].Score > 0) _score[i, j].Sink(ship.Size); } } _sunkSpots += ship.Size; // We sunk a ship, go back to search mode if we don't have any pending hit boats if (_sunkSpots == _hits.Count) { _sunkSpots = 0; List<Position> adjacent = new List<Position>(); // We can now adjust scores for these hits foreach (Position p in _hits) { AdjustScore(p); if (!_assumeAdjacent) { AdjustNotAdjacentScore(p); adjacent.AddRange(AdjacentPositions(p)); } } if (!_assumeAdjacent) { adjacent = adjacent.Except(_hits).Distinct().ToList(); foreach (Position p in adjacent) { AdjustNotAdjacentScore(p); } } _hits.Clear(); _targettingMode = TargettingMode.Search; } else { // We found two ships that are adjacent _assumeAdjacent = true; // Let's see if we can remove some hits from further consideration List<Ship> possibleLayouts = new List<Ship>(); if ((_destroySearchOrientation & Orientation.Horizontal) == Orientation.Horizontal) { Ship layout = ship.Clone() as Ship; layout.Orientation = Orientation.Horizontal; // Let's see if we can find the end points of the ship var possibilities = _hits.Where(p => p.Row == _lastShot.Row && Math.Abs(p.Column - _lastShot.Column) < ship.Size); if (possibilities.Count() == ship.Size) { layout.Position = possibilities.Min(); if (!layout.Positions.Except(_hits).Any()) { // If all positions in the layout are contained in hits possibleLayouts.Add(layout); } } } if ((_destroySearchOrientation & Orientation.Vertical) == Orientation.Vertical) { Ship layout = ship.Clone() as Ship; layout.Orientation = Orientation.Vertical; // Let's see if we can find the end points of the ship var possibilities = _hits.Where(p => p.Column == _lastShot.Column && Math.Abs(p.Row - _lastShot.Row) < ship.Size); if (possibilities.Count() == ship.Size) { layout.Position = possibilities.Min(); if (!layout.Positions.Except(_hits).Any()) { // If all positions in the layout are contained in hits possibleLayouts.Add(layout); } } } if (possibleLayouts.Count == 1) { // Remove these positions from consideration _hits = _hits.Except(possibleLayouts[0].Positions).ToList(); _sunkSpots -= ship.Size; foreach (Position p in possibleLayouts[0].Positions) AdjustScore(p); } } // Reset our destroy orientation pattern _destroySearchOrientation = Orientation.Horizontal | Orientation.Vertical; }
private void TargettingBodWindow(int windowID) { GUILayout.BeginVertical(); BodscrollViewVector = GUILayout.BeginScrollView(BodscrollViewVector, GUILayout.Height(300), GUILayout.Width(GUI_WIDTH_SMALL)); filterContractTargets = GUILayout.Toggle(filterContractTargets, new GUIContent("Show only contract targets", "If selected only targets that are the subject of a current contract will be shown")); //RSTUtils.Utilities.Log_Debug(String.Format(" - TargettingWindow - TSTBodies.Count = {0}", FlightGlobals.Bodies.Count)); var newTarget = 0; if ( TSTMstStgs.Instance.isRBloaded && RBWrapper.RBactualAPI.enabled) { //var filterRBTargets = isRBactive; newTarget = FlightGlobals.Bodies. FindIndex( g => g.Radius > 100 && (TSTProgressTracker.HasTelescopeCompleted(g) || (ContractSystem.Instance && ContractSystem.Instance.GetCurrentActiveContracts<TSTTelescopeContract>().Any(t => t.target.name == g.name))) ? GUILayout.Button(g.theName) : (filterContractTargets ? false : (TSTMstStgs.Instance.RBCelestialBodies[g].isResearched ? g.Radius > 100 ? GUILayout.Button(g.theName) : false : false))); } else { newTarget = FlightGlobals.Bodies. FindIndex( g => g.Radius > 100 && (TSTProgressTracker.HasTelescopeCompleted(g) || (ContractSystem.Instance && ContractSystem.Instance.GetCurrentActiveContracts<TSTTelescopeContract>() .Any(t => t.target.name == g.name))) ? GUILayout.Button(g.theName) : (filterContractTargets ? false : g.Radius > 100 ? GUILayout.Button(g.theName) : false)); } //RSTUtils.Utilities.Log_Debug(String.Format(" - TargettingWindow - newTarget = {0}", newTarget)); if (newTarget != -1 && newTarget != selectedTargetIndex) { vessel.targetObject = null; FlightGlobals.fetch.SetVesselTarget(null); targettingMode = TargettingMode.Planet; selectedTargetIndex = newTarget; bodyTarget = FlightGlobals.Bodies[selectedTargetIndex]; if (FlightGlobals.ActiveVessel.mainBody.name == bodyTarget.name) { Utilities.Log_Debug("Cannot Target: {0} : {1} in it's SOI", newTarget.ToString(), bodyTarget.name); ScreenMessages.PostScreenMessage("Cannot Target " + bodyTarget.theName + " as in it's SOI", 5f, ScreenMessageStyle.UPPER_CENTER); } else { FlightGlobals.fetch.SetVesselTarget(bodyTarget); Utilities.Log_Debug("Targetting: {0} : {1}", newTarget.ToString(), bodyTarget.name); Utilities.Log_Debug("Targetting: {0} : {1}, layer= {2}", newTarget.ToString(), bodyTarget.name, bodyTarget.gameObject.layer.ToString()); Utilities.Log_Debug("pos=" + bodyTarget.position); ScreenMessages.PostScreenMessage("Target: " + bodyTarget.theName, 5f, ScreenMessageStyle.UPPER_CENTER); } } GUILayout.EndScrollView(); GUILayout.Space(10); showBodTargetsWindow = !GUILayout.Button(new GUIContent("Hide", "Hide this Window")); GUILayout.EndVertical(); if (TSTMstStgs.Instance.TSTsettings.Tooltips) Utilities.SetTooltipText(); GUI.DragWindow(); }
/// <summary> /// Register last fire as a hit /// </summary> public void Hit() { // List of hits in the current sinking process _hits.Add(_lastShot); // Full list of hits _allHits.Add(_lastShot); // Clear out the score for the last shot _score[_lastShot.Row, _lastShot.Column].Clear(); _notAdjacentScore[_lastShot.Row, _lastShot.Column].Clear(); // Determine the new total of remaining positions DetermineRemainingPositions(); // If we're not already in destroy mode, set it and allow the algorithm to choose best choice among horizontal and vertical directions if (_targettingMode != TargettingMode.Destroy) { _destroySearchOrientation = Orientation.Horizontal | Orientation.Vertical; _targettingMode = TargettingMode.Destroy; } else { // We're already in destroy mode, try to determine the orientation of the ship if (_hits.Count > 1) { if (_hits[_hits.Count - 1].Row == _hits[_hits.Count - 2].Row) _destroySearchOrientation = Orientation.Horizontal; else if (_hits[_hits.Count - 1].Column == _hits[_hits.Count - 2].Column) _destroySearchOrientation = Orientation.Vertical; } } }