示例#1
0
        //NO INPUT (FS)
        public Program()
        {
            antenna = GridTerminalSystem.GetBlockWithName(ANTENNA_NAME) as IMyRadioAntenna;
            if (antenna != null)
            {
                output = GridTerminalSystem.GetBlockWithName(OUTPUT_NAME);
                try
                {
                    IMyTextPanel textPanel = output as IMyTextPanel;
                    textPanel.WritePublicText("");
                    outputIsTextPanel = true;
                }
                catch (Exception)
                {
                    outputIsTextPanel = false;
                }
                //TODO assign antenna to pb in script (even possible?)
                isWorking = true;
                antenna.SetValueFloat("Radius", RANGE);
                switch (ACCEPT_MESSAGE)
                {
                case 0:
                    antenna.IgnoreOtherBroadcast  = false;
                    antenna.IgnoreAlliedBroadcast = false;
                    break;

                case 1:
                    antenna.IgnoreOtherBroadcast  = true;
                    antenna.IgnoreAlliedBroadcast = false;
                    break;

                case 2:
                    antenna.IgnoreOtherBroadcast  = true;
                    antenna.IgnoreAlliedBroadcast = true;
                    break;

                default:
                    antenna.IgnoreOtherBroadcast  = true;
                    antenna.IgnoreAlliedBroadcast = false;
                    break;
                }
                if (ALWAYS_ON)
                {
                    antenna.SetValue("EnableBroadCast", true);
                }
                else
                {
                    antenna.SetValue("EnableBroadCast", false);
                }
            }
            else
            {
                Echo("Antenna could not be found");
                isWorking = false;
                return;
            }
            if (CHAT_MODE)
            {
                chathandler = new ChatHandler(this, CHAT_NAME);
            }
            if (OWN_NAME == "")
            {
                OWN_NAME = Me.CubeGrid.CustomName;
            }
            OWN_NAME      = OWN_NAME + "/" + Me.EntityId % 10000;
            comHandler    = new ComModule(this, antenna, OWN_NAME, ALWAYS_ON);
            Me.CustomName = "PB-COM-" + OWN_NAME;
            Me.CustomData = "";
        }
示例#2
0
        public Drone(IMyEntity ent, BroadcastingTypes broadcasting)
        {
            var    ship = (IMyCubeGrid)ent;
            double maxEngagementRange = ConquestMod.MaxEngagementRange;

            broadcastingType = broadcasting;

            Ship = ship;
            var lstSlimBlock = new List <IMySlimBlock>();

            GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship);

            //If it has any type of cockipt
            ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyShipController);
            FindWeapons();
            SetupActions();



            //If no cockpit the ship is either no ship or is broken.
            if (lstSlimBlock.Count != 0)
            {
                //Make the controls be the cockpit
                ShipControls = lstSlimBlock[0].FatBlock as IMyControllableEntity;

                _ownerId = ((Sandbox.ModAPI.IMyTerminalBlock)ShipControls).OwnerId;


                #region Activate Beacons && Antennas


                //Maximise radius on antennas and beacons.
                lstSlimBlock.Clear();
                ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyRadioAntenna);
                foreach (var block in lstSlimBlock)
                {
                    IMyRadioAntenna antenna =
                        (IMyRadioAntenna)block.FatBlock;
                    if (antenna != null)
                    {
                        //antenna.GetActionWithName("SetCustomName").Apply(antenna, new ListReader<TerminalActionParameter>(new List<TerminalActionParameter>() { TerminalActionParameter.Get("Combat Drone " + _manualGats.Count) }));
                        antenna.SetValueFloat("Radius", 10000);//antenna.GetMaximum<float>("Radius"));
                        _blockOn.Apply(antenna);
                    }
                }

                lstSlimBlock = new List <IMySlimBlock>();
                ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is IMyBeacon);
                foreach (var block in lstSlimBlock)
                {
                    IMyBeacon beacon = (IMyBeacon)block.FatBlock;
                    if (beacon != null)
                    {
                        beacon.SetValueFloat("Radius", 10000);//beacon.GetMaximum<float>("Radius"));
                        _blockOn.Apply(beacon);
                    }
                }

                #endregion

                //SetWeaponPower(true);
                //AmmoManager.ReloadReactors(_allReactors);
                //AmmoManager.ReloadGuns(_manualGats);
                ship.GetBlocks(lstSlimBlock, x => x is IMyEntity);

                List <IMyTerminalBlock> massBlocks =
                    new List <IMyTerminalBlock>();

                GridTerminalSystem.GetBlocksOfType <IMyVirtualMass>(massBlocks);

                List <IMyTerminalBlock> allTerminalBlocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(allTerminalBlocks);
                HealthBlockBase = allTerminalBlocks.Count;


                if (ShipControls != null)
                {
                    navigation = new DroneNavigation(ship, ShipControls, _nearbyFloatingObjects, maxEngagementRange);
                }
            }
            Ship.OnBlockAdded += RecalcMaxHp;
            myNumber           = numDrones;
            numDrones++;
        }