Exemplo n.º 1
0
            public override bool construct()
            {
                int cfgIndex = ConnectorName != "" ? 3 : 2;

                Func <string, ThrusterType> getThrusterType = (type) =>
                {
                    // select thruster type
                    switch (type)
                    {
                    case "atmos":
                        return(ThrusterType.Atmos);

                    case "ion":
                        return(ThrusterType.Ion);

                    case "hydrogen":
                        return(ThrusterType.Hydrogen);
                    }

                    return(0);
                };

                Func <string, ThrusterDirection> getThrusterDirection = (direction) =>
                {
                    // select direction filter
                    switch (direction)
                    {
                    case "lift":
                        return(ThrusterDirection.Lift);

                    case "lower":
                        return(ThrusterDirection.Lower);

                    case "left":
                        return(ThrusterDirection.Left);

                    case "right":
                        return(ThrusterDirection.Right);

                    case "accelerate":
                        return(ThrusterDirection.Accelerate);

                    case "break":
                        return(ThrusterDirection.Break);
                    }

                    return(0);
                };

                if (constructionStage_ == 0)
                {
                    if (ReferenceGrid == null)
                    {
                        constructionStage_ = 1;
                        return(true);
                    }

                    // search for ship controller
                    referenceControllerName_ = Options[cfgIndex];
                    referenceController_     = null;

                    App.GridTerminalSystem.GetBlocksOfType <IMyShipController>(null, (scblock) =>
                    {
                        IMyShipController controller = scblock as IMyShipController;
                        if (controller != null && controller.IsSameConstructAs(ReferenceGrid))
                        {
                            if (!controller.ControlThrusters)
                            {
                                return(false);
                            }

                            if (referenceController_ == null)
                            {
                                referenceController_ = controller;
                            }
                            else if (controller.CustomName == referenceControllerName_)
                            {
                                referenceController_ = controller;
                            }
                            else if (controller.IsMainCockpit)
                            {
                                referenceController_ = controller;
                            }
                            else if (controller.IsUnderControl)
                            {
                                referenceController_ = controller;
                            }
                        }

                        return(false);
                    });

                    if (referenceController_ == null)
                    {
                        log(Console.LogType.Error, "No reference controller");
                    }
                    else
                    {
                        referenceController_.Orientation.GetMatrix(out referenceControllerMatrix_);
                        referenceControllerMatrix_ = Matrix.Invert(referenceControllerMatrix_);
                    }

                    constructionStage_ = 1;
                }
                else if (constructionStage_ == 1)
                {
                    // step through filter
                    for (; cfgIndex < Options.Count; ++cfgIndex)
                    {
                        thrusterType_      |= getThrusterType(Options[cfgIndex].ToLower());
                        thrusterDirection_ |= getThrusterDirection(Options[cfgIndex].ToLower());
                    }

                    thrusterType_      = thrusterType_ == 0 ? ThrusterType.All : thrusterType_;
                    thrusterDirection_ = thrusterDirection_ == 0 ? ThrusterDirection.All : thrusterDirection_;

                    return(base.construct());
                }

                return(true);
            }