public void HandleDetectionBy(Player detectingPlayer, IUnitCmd_Ltd cmdItem, RangeCategory sensorRange) { if (!_item.IsOperational) { D.Error("{0} should not be detected by {1} when dead!", _item.DebugName, cmdItem.DebugName); } //D.Log(ShowDebugLog, "{0}.HandleDetectionBy called. Detecting Cmd: {1}, SensorRange: {2}.", DebugName, cmdItem.DebugName, sensorRange.GetValueName()); IDictionary<RangeCategory, IList<IUnitCmd_Ltd>> rangeLookup; if (!_detectionLookup.TryGetValue(detectingPlayer, out rangeLookup)) { Profiler.BeginSample("Proper Dictionary allocation", (_item as Component).gameObject); rangeLookup = new Dictionary<RangeCategory, IList<IUnitCmd_Ltd>>(3, RangeCategoryEqualityComparer.Default); // OPTIMIZE check size Profiler.EndSample(); _detectionLookup.Add(detectingPlayer, rangeLookup); } IList<IUnitCmd_Ltd> cmds; if (!rangeLookup.TryGetValue(sensorRange, out cmds)) { Profiler.BeginSample("Proper List allocation", (_item as Component).gameObject); cmds = new List<IUnitCmd_Ltd>(); Profiler.EndSample(); rangeLookup.Add(sensorRange, cmds); } D.Assert(!cmds.Contains(cmdItem), cmdItem.DebugName); cmds.Add(cmdItem); // The following returns can not move earlier in method as detection state must be kept current to support Reset if (_debugControls.IsAllIntelCoverageComprehensive) { // Should already be set to comprehensive during game startup __ValidatePlayerIntelCoverageOfItemIsComprehensive(detectingPlayer); // Note: this debug setting DOES NOT pre-populate all player's knowledge if (_item.Owner.IsRelationshipWith(detectingPlayer, DiplomaticRelationship.Alliance, DiplomaticRelationship.Self)) { // even with DebugSettings all coverage comprehensive, still no reason to update if Alliance or Self __ValidatePlayerIntelCoverageOfItemIsComprehensive(detectingPlayer); // UNCLEAR why called again? __ValidatePlayerKnowledgeOfItem(detectingPlayer); return; } UpdatePlayerKnowledge(detectingPlayer); return; // continuing could regress coverage on items that allow it } if (_item.Owner.IsRelationshipWith(detectingPlayer, DiplomaticRelationship.Alliance, DiplomaticRelationship.Self)) { // Should already be set to comprehensive when became self or alliance took place __ValidatePlayerIntelCoverageOfItemIsComprehensive(detectingPlayer); __ValidatePlayerKnowledgeOfItem(detectingPlayer); return; // continuing could regress coverage on items that allow it } Profiler.BeginSample("AssignDetectingPlayerIntelCoverage", (_item as Component).gameObject); AssignDetectingPlayerIntelCoverage(detectingPlayer); Profiler.EndSample(); Profiler.BeginSample("UpdatePlayerKnowledge", (_item as Component).gameObject); UpdatePlayerKnowledge(detectingPlayer); Profiler.EndSample(); }
public void HandleDetectionLostBy(Player detectingPlayer, IUnitCmd_Ltd cmdItem, RangeCategory sensorRangeCat) { _detectionHandler.HandleDetectionLostBy(detectingPlayer, cmdItem, sensorRangeCat); }
private void RemoveCommand(IUnitCmd_Ltd command) { var isRemoved = _commands.Remove(command); isRemoved = isRemoved & _items.Remove(command); D.Assert(isRemoved); //D.Log("{0} has removed Command {1}.", DebugName, command.DebugName); IStarbaseCmd_Ltd sbCmd = command as IStarbaseCmd_Ltd; if (sbCmd != null) { var sbSectorID = sbCmd.SectorID; IList<IStarbaseCmd_Ltd> sbCmds = _starbasesLookupBySectorID[sbSectorID]; isRemoved = sbCmds.Remove(sbCmd); D.Assert(isRemoved); if (sbCmds.Count == Constants.Zero) { _starbasesLookupBySectorID.Remove(sbSectorID); } } else { ISettlementCmd_Ltd settlement = command as ISettlementCmd_Ltd; if (settlement != null) { var sSectorID = settlement.SectorID; isRemoved = _settlementLookupBySectorID.Remove(sSectorID); D.Assert(isRemoved); } } }
private void AddCommand(IUnitCmd_Ltd command) { var isAdded = _commands.Add(command); isAdded = isAdded & _items.Add(command); D.Assert(isAdded); // Cmd cannot already be present. If adding due to a change in an element's IsHQ state, then previous HQElement removed Cmd before this Add //D.Log("{0} has added Command {1}.", DebugName, command.DebugName); IStarbaseCmd_Ltd sbCmd = command as IStarbaseCmd_Ltd; if (sbCmd != null) { var sbSectorID = sbCmd.SectorID; IList<IStarbaseCmd_Ltd> sbCmds; if (!_starbasesLookupBySectorID.TryGetValue(sbSectorID, out sbCmds)) { sbCmds = new List<IStarbaseCmd_Ltd>(2); _starbasesLookupBySectorID.Add(sbSectorID, sbCmds); } D.Assert(!sbCmds.Contains(sbCmd)); sbCmds.Add(sbCmd); } else { ISettlementCmd_Ltd settlementCmd = command as ISettlementCmd_Ltd; if (settlementCmd != null) { var sSectorID = settlementCmd.SectorID; //if (_settlementLookupBySectorID.ContainsKey(sSectorID)) { // D.Error("{0}.AddCmd({1}) found {2} already occupied by {3}.", DebugName, command.DebugName, sSectorID, _settlementLookupBySectorID[sSectorID].DebugName); //} _settlementLookupBySectorID.Add(sSectorID, settlementCmd); } } }
private bool TryFindPrimaryUserCommand(IntVector3 userHomeSectorID, out IUnitCmd_Ltd primaryUserCmd) { var userKnowledge = _gameMgr.UserAIManager.Knowledge; bool isCmdFound = false; primaryUserCmd = null; ISettlementCmd_Ltd userHomeSettlement; if (userKnowledge.TryGetSettlement(userHomeSectorID, out userHomeSettlement)) { D.AssertEqual(_gameMgr.UserPlayer, (userHomeSettlement as ISettlementCmd).Owner); primaryUserCmd = userHomeSettlement; isCmdFound = true; } else { IEnumerable<IFleetCmd_Ltd> userHomeSectorFleets; if (userKnowledge.TryGetFleets(userHomeSectorID, out userHomeSectorFleets)) { var myHomeSectorFleets = from fleet in userHomeSectorFleets let myFleet = fleet as IFleetCmd where myFleet.Owner == _gameMgr.UserPlayer select fleet; if (myHomeSectorFleets.Any()) { isCmdFound = true; primaryUserCmd = myHomeSectorFleets.First(); } } } return isCmdFound; }
public AUnitCmdReport(AUnitCmdData data, Player player, IUnitCmd_Ltd item) : base(data, player, item) { }
public void HandleDetectionLostBy(Player detectingPlayer, IUnitCmd_Ltd cmdItem, RangeCategory sensorRange) { D.AssertNotDefault((int)sensorRange); if (!_item.IsOperational) { // 7.20.16 detected items no longer notified of lost detection when they die D.Error("{0} should not be notified by {1} of detection lost when dead!", DebugName, cmdItem.DebugName); } //D.Log(ShowDebugLog, "{0}.HandleDetectionLostBy called. Detecting Cmd: {1}, SensorRange: {2}.", DebugName, cmdItem.DebugName, sensorRange.GetValueName()); IDictionary<RangeCategory, IList<IUnitCmd_Ltd>> rangeLookup; if (!_detectionLookup.TryGetValue(detectingPlayer, out rangeLookup)) { D.Error("{0} found no Sensor Range lookup. Detecting Cmd: {1}.", DebugName, cmdItem.DebugName); return; } IList<IUnitCmd_Ltd> cmds; if (!rangeLookup.TryGetValue(sensorRange, out cmds)) { D.Error("{0} found no List of Commands. Detecting Cmd: {1}, SensorRange: {2}.", DebugName, cmdItem.DebugName, sensorRange.GetValueName()); return; } bool isRemoved = cmds.Remove(cmdItem); D.Assert(isRemoved, cmdItem.DebugName); if (cmds.Count == Constants.Zero) { rangeLookup.Remove(sensorRange); if (rangeLookup.Count == Constants.Zero) { _detectionLookup.Remove(detectingPlayer); } } // The following returns can not move earlier in method as detection state must be kept current to support Reset if (_debugControls.IsAllIntelCoverageComprehensive) { // Should already be set to comprehensive during game startup __ValidatePlayerIntelCoverageOfItemIsComprehensive(detectingPlayer); __ValidatePlayerKnowledgeOfItem(detectingPlayer); // must have already detected item to have lost it return; // continuing could regress coverage on items that allow it } if (_item.Owner.IsRelationshipWith(detectingPlayer, DiplomaticRelationship.Alliance, DiplomaticRelationship.Self)) { // Should already be set to comprehensive when became self or alliance took place __ValidatePlayerIntelCoverageOfItemIsComprehensive(detectingPlayer); __ValidatePlayerKnowledgeOfItem(detectingPlayer); return; // continuing could regress coverage on items that allow it } AssignDetectingPlayerIntelCoverage(detectingPlayer); UpdatePlayerKnowledge(detectingPlayer); }