Esempio n. 1
0
 //private bool isClosed = false;
 private void Close(IMyEntity myEntity)
 {
     //radarCanSee = null;
     CubeBlock = null;
     myBeacon  = null;
     //MyObjectBuilder = null;
     //isClosed = true;
 }
Esempio n. 2
0
		public Beacon(IMyCubeBlock block)
		{
			CubeBlock = block;
			myBeacon = block as Ingame.IMyBeacon;
			myLogger = new Logger("Beacon", CubeBlock);

			myLogger.debugLog("init as beacon: " + CubeBlock.BlockDefinition.SubtypeName, "Init()", Logger.severity.TRACE);
		}
Esempio n. 3
0
 private void UpdateTargetPowerLevel()
 {
     Ingame.IMyBeacon asBeacon = CubeBlock as Ingame.IMyBeacon;
     if (asBeacon != null)
     {
         PowerLevel_Target = asBeacon.Radius;
     }
     else
     {
         Ingame.IMyRadioAntenna asRadio = CubeBlock as Ingame.IMyRadioAntenna;
         if (asRadio != null)
         {
             PowerLevel_Target = asRadio.Radius;
         }
     }
 }
Esempio n. 4
0
        public Beacon(IMyCubeBlock block)
        {
            CubeBlock = block;
            myBeacon  = block as Ingame.IMyBeacon;

            isSmallBlock = block.CubeGrid.GridSizeEnum == MyCubeSize.Small;
            if (Settings.boolSettings[Settings.BoolSetName.bAllowRadar] && CubeBlock.BlockDefinition.SubtypeName.Contains(SubTypeSearchRadar))
            {
                isRadar = true;
                log("init as radar: " + CubeBlock.BlockDefinition.SubtypeName, "Init()", Logger.severity.TRACE);
            }
            else
            {
                log("init as beacon: " + CubeBlock.BlockDefinition.SubtypeName, "Init()", Logger.severity.TRACE);
            }
            //UpdateManager.RegisterForUpdates(100, UpdateAfterSimulation100);

            CubeBlock.OnClosing += Close;
        }
Esempio n. 5
0
        /// <summary>
        /// Group grids in the CP into subfleets
        /// </summary>
        private Dictionary <long, Subfleet> nearbySubfleets()
        {
            var foundSubfleets = new Dictionary <long, Subfleet>();

            log("Grouping nearby grids into Subfleets.", "nearbySubfleets");

            VRageMath.BoundingSphereD bounds           = new VRageMath.BoundingSphereD(Position, (double)Radius);
            List <IMyEntity>          entitiesInBounds = MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);

            foreach (IMyEntity e in entitiesInBounds)
            {
                // Is it a grid?
                IMyCubeGrid grid = e as IMyCubeGrid;
                if (grid == null)
                {
                    continue;
                }

                // does it have a GE?
                GridEnforcer ge = grid.Components.Get <MyGameLogicComponent>() as GridEnforcer;
                if (ge == null)
                {
                    log("Failed to retrieve GridEnforcer for grid " + grid.EntityId,
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                // Is it classified?
                if (ge.Class == HullClass.CLASS.UNCLASSIFIED)
                {
                    continue;
                }


                // There are no hooks to check if someone changed factions,
                // so reevaluate here to make sure info is up to date for fleet groups
                ge.reevaluateOwnership();

                /*
                 * if (ge.Owner.OwnerType == GridOwner.OWNER_TYPE.UNOWNED) {
                 *      log("Grid " + grid.EntityId + " is unowned, skipping",
                 *              "nearbySubfleets");
                 *      continue;
                 * }
                 */

                // We could check here if the grid is supported by its fleet,
                // or more generally if it's violation any rules
                // But we should notify players, b/c that could be confusing

                /*
                 * if (!ge.SupportedByFleet) {
                 *      log("Grid " + grid.DisplayName + " is unsupported by its fleet, skipping.",
                 *              "getRoundWinner");
                 *      continue;
                 * }
                 */

                // Is its Hull Classifier broadcasting far enough?
                HullClassifier classifier = ge.Classifier;
                if (classifier == null)
                {
                    log("Grid has no classifier but was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                IMyCubeBlock fatblock = classifier.FatBlock;
                if (fatblock == null)
                {
                    log("Classifier could not be referenced as fatblock",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                if (!fatblock.IsWorking)
                {
                    log("Classifier not working but grid was classified",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }

                InGame.IMyBeacon       beacon  = fatblock as InGame.IMyBeacon;
                InGame.IMyRadioAntenna antenna = fatblock as InGame.IMyRadioAntenna;
                if (beacon == null && antenna == null)
                {
                    log("Classifier not a beacon or antennae, no broadcast radius",
                        "nearbySubfleets", Logger.severity.ERROR);
                    continue;
                }
                if (beacon != null && beacon.Radius <
                    VRageMath.Vector3.Distance(Position, grid.GetPosition()))
                {
                    log("Classifier range too small, skipping", "nearbySubfleets");
                    // TODO notify pilot
                    continue;
                }
                if (antenna != null && antenna.Radius <
                    VRageMath.Vector3.Distance(Position, grid.GetPosition()))
                {
                    log("Classifier range too small, skipping", "nearbySubfleets");
                    // TODO notify pilot
                    continue;
                }

                // Grid passed all tests!
                long fleetID = ge.Owner.FleetID;
                log("Grid '" + ge.Grid.DisplayName + "'passed all tests, including in fleet " + fleetID, "nearbySubfleets");
                if (!foundSubfleets.ContainsKey(fleetID))
                {
                    foundSubfleets[fleetID] = new Subfleet {
                        ID        = fleetID,
                        Enforcers = new List <GridEnforcer>()
                        {
                            ge
                        },
                        TotalValue = ge.CaptureMultiplier,
                    };
                }
                else
                {
                    foundSubfleets[fleetID].Enforcers.Add(ge);
                    foundSubfleets[fleetID].TotalValue += ge.CaptureMultiplier;
                }
            }

            return(foundSubfleets);
        }
Esempio n. 6
0
 public CR_BeaconBlock(Ingame.IMyBeacon beacon)
 {
     this.m_beacon = beacon;
 }
Esempio n. 7
0
        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);
        }