Ejemplo n.º 1
0
        public TurretBaseEntity(CubeGridEntity parent, MyObjectBuilder_TurretBase definition)
            : base(parent, definition)
        {
            m_inventory = new InventoryEntity(definition.Inventory);

            m_shootingRange  = definition.Range;
            m_searchingRange = m_shootingRange + 100;

            m_targetMeteors  = definition.TargetMeteors;
            m_targetMissiles = definition.TargetMissiles;
        }
Ejemplo n.º 2
0
        public TurretBaseEntity(CubeGridEntity parent, MyObjectBuilder_TurretBase definition, Object backingObject)
            : base(parent, definition, backingObject)
        {
            m_turretNetworkManager = new TurretNetworkManager(this, GetNetworkManager( ));
            m_inventory            = new InventoryEntity(definition.Inventory, GetTurretInventory( ));

            m_shootingRange  = definition.Range;
            m_searchingRange = m_shootingRange + 100;

            m_targetMeteors  = definition.TargetMeteors;
            m_targetMissiles = definition.TargetMissiles;
        }
Ejemplo n.º 3
0
        public void UpdateAfterSimulation()
        {
            if (myCubeBlock == null)
            {
                return;
            }

            //if (needToRelease)
            //	lock_notMyUpdate.ReleaseExclusive();
            //needToRelease = false;

            try
            {
                if (!myCubeBlock.IsWorking || myCubeBlock.Closed)
                {
                    return;
                }

                if (updateCount % 100 == 0)                 // every 100 updates
                {
                    if (updateCount == 1000)
                    {
                        myLogger.debugLog("update 1000", "UpdateAfterSimulation()");
                        reset();
                        return;
                    }

                    controlEnabled = myCubeBlock.DisplayNameText.Contains("[") && myCubeBlock.DisplayNameText.Contains("]");

                    TurretBase_CustomNameChanged(null);

                    if (myAntenna == null || myAntenna.CubeBlock == null || !myAntenna.CubeBlock.canSendTo(myCubeBlock, true))
                    {
                        //myLogger.debugLog("searching for attached antenna", "UpdateAfterSimulation10()");

                        myAntenna = null;
                        foreach (Receiver antenna in RadioAntenna.registry)
                        {
                            if (antenna.CubeBlock.canSendTo(myCubeBlock, true))
                            {
                                myLogger.debugLog("found attached antenna: " + antenna.CubeBlock.DisplayNameText, "UpdateAfterSimulation10()", Logger.severity.INFO);
                                myAntenna = antenna;
                                break;
                            }
                        }
                        if (myAntenna == null)
                        {
                            foreach (Receiver antenna in LaserAntenna.registry)
                            {
                                if (antenna.CubeBlock.canSendTo(myCubeBlock, true))
                                {
                                    myLogger.debugLog("found attached antenna: " + antenna.CubeBlock.DisplayNameText, "UpdateAfterSimulation10()", Logger.severity.INFO);
                                    myAntenna = antenna;
                                    break;
                                }
                            }
                        }
                        //if (myAntenna == null)
                        //myLogger.debugLog("did not find attached antenna", "UpdateAfterSimulation10()");
                    }

                    MyObjectBuilder_TurretBase builder = myCubeBlock.getSlimObjectBuilder() as MyObjectBuilder_TurretBase;
                    targetMissiles   = builder.TargetMissiles;
                    targetMeteors    = MeteorsEnabled && builder.TargetMeteors;
                    targetCharacters = builder.TargetCharacters;
                    targetMoving     = builder.TargetMoving;
                    targetLargeGrids = builder.TargetLargeGrids;
                    targetSmallGrids = builder.TargetSmallGrids;
                    targetStations   = builder.TargetStations;

                    if (possibleTargets())
                    {
                        if (CurrentState == State.NO_POSSIBLE)
                        {
                            myLogger.debugLog("now possible to target", "UpdateAfterSimulation()");
                            CurrentState = State.OFF;
                        }
                    }
                    else
                    if (CurrentState != State.NO_POSSIBLE)
                    {
                        myLogger.debugLog("no longer possible to target", "UpdateAfterSimulation()");
                        setNoTarget();
                        CurrentState = State.NO_POSSIBLE;
                    }
                }                 // end if (updateCount % 100 == 0)

                if (CurrentState == State.NO_POSSIBLE)
                {
                    return;
                }

                if (!controlEnabled)
                {
                    if (CurrentState != State.OFF)
                    {
                        CurrentState = State.OFF;
                        //myTurretBase.TrackTarget(null);
                        myTurretBase.ResetTargetingToDefault();
                    }
                    return;
                }

                if (CurrentState == State.OFF)
                {
                    if (defaultTargetingAcquiredTarget)
                    {
                        setNoTarget();
                    }
                    else
                    {
                        CurrentState = State.WAIT_DTAT;
                    }
                }

                // Wait for default targeting to acquire a target.
                if (CurrentState == State.WAIT_DTAT)
                {
                    if (updateCount % 10 == 0)
                    {
                        turretPosition = myCubeBlock.GetPosition();
                        MyObjectBuilder_TurretBase builder = myCubeBlock.getSlimObjectBuilder() as MyObjectBuilder_TurretBase;
                        IMyEntity target;
                        if (MyAPIGateway.Entities.TryGetEntityById(builder.Target, out target))
                        {
                            if ((target is IMyCubeBlock || target is IMyMeteor) &&
                                canLase(target))
                            {
                                defaultTargetingAcquiredTarget = true;
                                setNoTarget();
                                myLogger.debugLog("default targeting acquired a target: " + target.getBestName(), "UpdateAfterSimulation()", Logger.severity.DEBUG);
                            }
                        }
                    }
                    return;
                }

                // start thread
                if (!queued && updateCount % 10 == 0)
                {
                    queued = true;
                    TurretThread.EnqueueAction(Update);
                }
            }
            catch (Exception e) { myLogger.log("Exception: " + e, "UpdateAfterSimulation10()", Logger.severity.ERROR); }
            finally
            {
                updateCount++;
                //needToRelease = true;
                //lock_notMyUpdate.AcquireExclusive();
            }
        }