Beispiel #1
0
        /// <summary>
        /// <para>Search for a grid.</para>
        /// The search happens when the action is executed.
        /// When action is executed, an error may occur and instructionErrorIndex will be updated.
        /// </summary>
        private bool getAction_gridDest(out Action execute, string instruction)
        {
            myLogger.debugLog("entered getAction_gridDest(out Action execute, string " + instruction + ")", "getAction_gridDest()");
            //string searchName = owner.CNS.tempBlockName;
            //myLogger.debugLog("searchName = " + searchName + ", owner.CNS.tempBlockName = " + owner.CNS.tempBlockName, "getAction_gridDest()");
            //owner.CNS.tempBlockName = null;
            int myInstructionIndex = currentInstruction;

            execute = () =>
            {
                IMyCubeBlock blockBestMatch;
                LastSeen     gridBestMatch;
                myLogger.debugLog("calling lastSeenFriendly with (" + instruction + ", " + owner.CNS.tempBlockName + ")", "getAction_gridDest()");
                if (owner.myTargeter.lastSeenFriendly(instruction, out gridBestMatch, out blockBestMatch, owner.CNS.tempBlockName))
                {
                    Base6Directions.Direction?landDir = null;
                    if ((blockBestMatch != null && owner.CNS.landLocalBlock != null && owner.CNS.landDirection == null) &&
                        !Lander.landingDirection(blockBestMatch, out landDir))
                    {
                        log("could not get landing direction from block: " + owner.CNS.landLocalBlock.DefinitionDisplayNameText, "getAction_gridDest()", Logger.severity.INFO);
                        instructionErrorIndex_add(myInstructionIndex);
                        return;
                    }

                    if (landDir != null)                     // got a landing direction
                    {
                        owner.CNS.landDirection = landDir;
                        myLogger.debugLog("got landing direction of " + landDir + " from " + owner.CNS.landLocalBlock.DefinitionDisplayNameText, "getAction_gridDest()");
                        log("set land offset to " + owner.CNS.landOffset, "getAction_gridDest()", Logger.severity.TRACE);
                    }
                    else                     // no landing direction
                    {
                        if (blockBestMatch != null)
                        {
                            myLogger.debugLog("setting centreDestination to " + gridBestMatch.Entity.getBestName() + ", " + blockBestMatch.DisplayNameText + " seen by " + owner.currentRCblock.getNameOnly(), "getAction_gridDest()");
                        }
                        else
                        {
                            myLogger.debugLog("setting centreDestination to " + gridBestMatch.Entity.getBestName() + " seen by " + owner.currentRCblock.getNameOnly(), "getAction_gridDest()");
                        }
                    }

                    owner.CNS.setDestination(gridBestMatch, blockBestMatch, owner.currentRCblock);
                    return;
                }
                // did not find grid
                log("did not find a friendly grid", "getAction_gridDest()", Logger.severity.TRACE);
                instructionErrorIndex_add(myInstructionIndex);
            };

            return(true);
        }