public void UpdateAfterSimulation100() { //if (!IsInitialized) return; if (CubeBlock == null || CubeBlock.Closed || CubeBlock.CubeGrid == null) { return; } try { if (!myBeacon.IsWorking) { if (isRadar && powerLevel > 0) { powerLevel += powerDecrease; } return; } // send beacon self to radio antenna LinkedList <RadioAntenna> canSeeMe = new LinkedList <RadioAntenna>(); // friend and foe alike float radiusSquared = myBeacon.Radius * myBeacon.Radius; foreach (RadioAntenna ant in RadioAntenna.registry) { if (CubeBlock.canSendTo(ant.CubeBlock, false, radiusSquared, true)) { canSeeMe.AddLast(ant); } } LastSeen self = new LastSeen(CubeBlock.CubeGrid, isRadar); foreach (RadioAntenna ant in canSeeMe) { ant.receive(self); } //log("beacon made self known to "+canSeeMe.Count+" antennas", "UpdateAfterSimulation100()", Logger.severity.TRACE); if (!isRadar) { return; } // Radar float Radius = myBeacon.Radius; // cap small radar if (isSmallBlock) { if (Radius > maxRadiusSmallRadar) { myLogger.debugLog("Reduce radius from " + Radius + " to " + maxRadiusSmallRadar, "UpdateAfterSimulation100()"); myBeacon.SetValueFloat("Radius", maxRadiusSmallRadar); Radius = maxRadiusSmallRadar; } } // adjust power level if (powerLevel < 0) { powerLevel = 0; } powerLevel += powerIncrease; if (powerLevel > Radius) { powerLevel = Radius; } myLogger.debugLog("Radius = " + Radius + ", power level = " + powerLevel, "UpdateAfterSimulation100()"); // figure out what radar sees LinkedList <LastSeen> radarSees = new LinkedList <LastSeen>(); HashSet <IMyEntity> allGrids = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities_Safe(allGrids, (entity) => { return(entity is IMyCubeGrid); }); foreach (IMyEntity ent in allGrids) //if (ent is IMyCubeGrid || ent is IMyCharacter) { // get detection distance float volume = ent.LocalAABB.Volume(); float power = (volume + radarPower_A) / (volume + radarPower_B) / radarPower_C * powerLevel; if (!CubeBlock.canSendTo(ent, false, power)) // not in range { continue; } //log("radar found a grid: " + (ent as IMyCubeGrid).DisplayName, "UpdateAfterSimulation100()", Logger.severity.TRACE); // report to attached antennas and remotes LastSeen seen = new LastSeen(ent, false, new RadarInfo(volume)); radarSees.AddLast(seen); //foreach (RadioAntenna ant in RadioAntenna.registry) // if (CubeBlock.canSendTo(ant.CubeBlock, true)) // ant.receive(seen); //foreach (RemoteControl rem in RemoteControl.registry.Values) // if (CubeBlock.canSendTo(rem.CubeBlock, true)) // rem.receive(seen); } Receiver.sendToAttached(CubeBlock, radarSees); } catch (Exception e) { alwaysLog("Exception: " + e, "UpdateAfterSimulation100()", Logger.severity.ERROR); } }
private void UpdatePowerLevel() { if (this.CubeBlock == null) { Log.DebugLog("not updating power levels, not a block"); return; } UpdateTargetPowerLevel(); if (PowerLevel_Current == PowerLevel_Target) { return; } Log.DebugLog("current power level: " + PowerLevel_Current + ", target power level: " + PowerLevel_Target, Logger.severity.TRACE); // cap power level { if (PowerLevel_Target > myDefinition.MaxPowerLevel) { PowerLevel_Target = myDefinition.MaxPowerLevel; if (MyAPIGateway.Multiplayer.IsServer) { IMyTerminalBlock TermBlock = this.TermBlock; IMyCubeBlock CubeBlock = this.CubeBlock; MyAPIGateway.Utilities.TryInvokeOnGameThread(() => { Log.DebugLog("Reducing target power from " + PowerLevel_Target + " to " + myDefinition.MaxPowerLevel, Logger.severity.INFO); // turn down slider Ingame.IMyBeacon asBeacon = CubeBlock as Ingame.IMyBeacon; if (asBeacon != null) { asBeacon.SetValueFloat("Radius", PowerLevel_Target); } else { Ingame.IMyRadioAntenna asRadio = CubeBlock as Ingame.IMyRadioAntenna; if (asRadio != null) { asRadio.SetValueFloat("Radius", PowerLevel_Target); } } UpdatePowerConsumption(); }); } else { MyAPIGateway.Utilities.InvokeOnGameThread(UpdatePowerConsumption); } } } // adjust current power level if (PowerLevel_Current < 0) { PowerLevel_Current = 0; } PowerLevel_Current += myDefinition.PowerIncrease; if (PowerLevel_Current > PowerLevel_Target) { PowerLevel_Current = PowerLevel_Target; } MyAPIGateway.Utilities.InvokeOnGameThread(UpdatePowerConsumption); Log.DebugLog("PowerLevel_Target: " + PowerLevel_Target + ", PowerLevel_Current: " + PowerLevel_Current, Logger.severity.TRACE); }