示例#1
0
 private void Compress()
 {
     if (MBToolbox.AmountAvailable("ElectricCharge", base.part) < this.EcPerSec)
     {
         if (this.isBusy)
         {
             ScreenMessages.PostScreenMessage("Not enough electric charge! Nowadays nothing works without elctricity!", 2f, ScreenMessageStyle.UPPER_CENTER);
         }
         this.isBusy = false;
     }
     else if (MBToolbox.AmountAvailable("Dirt", base.part) < (double)(this.dirtPerBlock / 100f))
     {
         if (this.isBusy)
         {
             ScreenMessages.PostScreenMessage("Not enough dirt! What do you want?", 2f, ScreenMessageStyle.UPPER_CENTER);
         }
         this.isBusy = false;
     }
     else
     {
         this.isBusy = true;
         MBToolbox.RequestResource("ElectricCharge", this.EcPerSec * (double)TimeWarp.deltaTime, base.part);
         MBToolbox.RequestResource("Dirt", (double)(this.dirtPerBlock / this.reqSec * TimeWarp.deltaTime), base.part);
         this.dtime += TimeWarp.deltaTime;
     }
 }
        public void fuel()
        {
            Vessel v = FlightGlobals.ActiveVessel;

            foreach (PartResource r in v.rootPart.Resources)
            {
                foreach (PartResource rt in base.part.Resources)
                {
                    if (r.resourceName.Equals(rt.resourceName))
                    {
                        MBToolbox.magicResourceTransfer(r.resourceName, r.maxAmount, r.part, rt.part);
                    }
                }
            }
        }
示例#3
0
        public override void OnUpdate()
        {
            if (this.isRunning)
            {
                if (base.vessel.situation != Vessel.Situations.LANDED && base.vessel.situation != Vessel.Situations.PRELAUNCH && !this.HasSurfaceConatct(this.impactTrans))
                {
                    ScreenMessages.PostScreenMessage("You are not landed!", 5f, ScreenMessageStyle.UPPER_CENTER);
                    this.isRunning = false;
                    this.stat      = "Not landed";
                    this.RetractAnim();
                }
                else if (MBToolbox.AmountAvailable(this.input, base.part) < (double)(this.inPerSec * TimeWarp.deltaTime))
                {
                    ScreenMessages.PostScreenMessage("Not enough" + this.input, 5f, ScreenMessageStyle.UPPER_CENTER);
                    this.isRunning = false;
                    this.stat      = "Not enough " + this.input;
                    this.RetractAnim();
                }
                else if (base.vessel.srfSpeed > (double)this.maxSpeed)
                {
                    ScreenMessages.PostScreenMessage("Too fast!", 5f, ScreenMessageStyle.UPPER_CENTER);
                    this.isRunning = false;
                    this.stat      = "Too fast!";
                }
                else
                {
                    MBToolbox.RequestResource(this.input, (double)(this.inPerSec * TimeWarp.deltaTime), base.part);
                    double free = MBToolbox.FreeSpaceAvailable(this.resource, base.part);
                    double d    = (double)(this.unitPerSec * TimeWarp.deltaTime / this.maxSpeed) * base.vessel.srfSpeed;
                    this.rat = MBToolbox.AddResource(this.resource, d, base.part);
                    Debug.Log("Free space available: " + free.ToString());
                    Debug.Log("d: " + d.ToString());
                    Debug.Log("rat: " + rat.ToString());
                    double free2 = MBToolbox.FreeSpaceAvailable(this.resource, base.part);

                    if (free == 0)
                    {
                        ScreenMessages.PostScreenMessage("Not enough space for the resources!", 5f, ScreenMessageStyle.UPPER_CENTER);
                        this.isRunning = false;
                        this.stat      = "Not enough free space";
                        this.RetractAnim();
                    }
                }
            }
        }
示例#4
0
        private void EndCompress()
        {
            Part prefab = this.queue[this.queue.Count - 1].apart.partPrefab;

            this.dtime  = 0f;
            this.isBusy = false;
            this.queue.RemoveAt(this.queue.Count - 1);
            System.Collections.Generic.List <ModuleKISInventory> invs = MBToolbox.GetInventories(base.vessel);
            if (invs.Count == 0)
            {
                ScreenMessages.PostScreenMessage("No inventories found!", 2f, ScreenMessageStyle.UPPER_CENTER);
            }
            else
            {
                foreach (ModuleKISInventory inv in invs)
                {
                    if (inv.part.name == base.part.name)
                    {
                        if (inv.isFull() || inv.GetContentVolume() + 1000f > inv.maxVolume)
                        {
                            break;
                        }
                        inv.AddItem(prefab, 1f, -1);
                        return;
                    }
                }
                foreach (ModuleKISInventory inv2 in invs)
                {
                    if (!inv2.isFull() || inv2.GetContentVolume() + 1000f <= inv2.maxVolume)
                    {
                        inv2.AddItem(prefab, 1f, -1);
                        return;
                    }
                }
                ScreenMessages.PostScreenMessage("No free inventories found!", 2f, ScreenMessageStyle.UPPER_CENTER);
            }
        }
示例#5
0
 private bool HasSurfaceConatct(Transform trans)
 {
     Debug.Log("[STB]: " + MBToolbox.GetSurfaceAlt(trans.position));
     return(MBToolbox.GetSurfaceAlt(trans.position) <= 0.1);
 }
示例#6
0
        private void InstallMode(ModuleSTPModularCorridor.ModeConfig m, bool isLoading = false)
        {
            ConfigNode conf      = m.config;
            int        idx       = m.path.LastIndexOf('/');
            string     modelPath = m.path.Substring(0, idx) + "/" + conf.GetValue("model");

            Debug.Log("[STB]: Loading: " + conf.GetValue("modeName") + " mode.");
            ConfigNode[] array = m.inRes;
            for (int j = 0; j < array.Length; j++)
            {
                ConfigNode i = array[j];
                if (MBToolbox.AmountAvailable(i.GetValue("name"), FlightGlobals.ActiveVessel.rootPart) < System.Convert.ToDouble(i.GetValue("amount")))
                {
                    ScreenMessages.PostScreenMessage("Not enough " + i.GetValue("name"), 5f);
                    return;
                }
                MBToolbox.RequestResource(i.GetValue("name"), System.Convert.ToDouble(i.GetValue("amount")), FlightGlobals.ActiveVessel.rootPart);
            }
            if (this.installedModule.hasInit() && !isLoading)
            {
                Debug.Log("[STB]: Reseting modules...");
                if (this.installedModule.moduleconfs.Length != 0)
                {
                    System.Collections.Generic.List <PartModule> pmToRemoveList = new System.Collections.Generic.List <PartModule>();
                    using (var enumerator = base.part.Modules.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            PartModule pm = (PartModule)enumerator.Current;
                            array = this.installedModule.moduleconfs;
                            for (int j = 0; j < array.Length; j++)
                            {
                                ConfigNode i = array[j];
                                if (i.GetValue("name") == pm.moduleName)
                                {
                                    pmToRemoveList.Add(pm);
                                }
                            }
                        }
                    }
                    foreach (PartModule pm in pmToRemoveList)
                    {
                        base.part.RemoveModule(pm);
                        Debug.Log("[STB]: Removing: " + pm.moduleName + " module.");
                    }
                }
                Debug.Log("[STB]: Reseting resources...");
                foreach (PartResource r in base.part.Resources)
                {
                    array = this.installedModule.resconfs;
                    for (int j = 0; j < array.Length; j++)
                    {
                        ConfigNode i = array[j];
                        if (i.GetValue("name") == r.resourceName)
                        {
                            ConfigNode node = i.CreateCopy();
                            node.SetValue("name", r.resourceName, false);
                            node.SetValue("amount", "0", false);
                            node.SetValue("maxAmount", "0", false);
                            base.part.SetResource(node);
                            Debug.Log("[STB]: Reseting " + r.resourceName);
                        }
                    }
                }
                Debug.Log("[STB]: Reseting model...");
                if (this.currModel != null)
                {
                    this.currModel.SetActive(false);
                }
            }
            if (m.isDepsOk)
            {
                Debug.Log("[STB]: Adding modules...");
                array = m.moduleconfs;
                for (int j = 0; j < array.Length; j++)
                {
                    ConfigNode i  = array[j];
                    PartModule pm = base.part.AddModule(i.GetValue("name"));
                    pm.OnAwake();
                    pm.OnInitialize();
                    pm.Load(i);
                    pm.OnStart(PartModule.StartState.Landed);
                    Debug.Log(i.GetValue("name") + " is being added from: " + i.name);
                }
            }
            if (!isLoading)
            {
                Debug.Log("[STB]: Adding resources...");
                array = m.resconfs;
                for (int j = 0; j < array.Length; j++)
                {
                    ConfigNode i = array[j];
                    if (i.GetValue("amount") != "0")
                    {
                        i.SetValue("amount", "0", false);
                    }
                    base.part.SetResource(i);
                    Debug.Log(i.GetValue("name") + " " + i.name + " is being added");
                }
            }
            Debug.Log("[STB]: Adding model...");
            if (GameDatabase.Instance.ExistsModel(modelPath))
            {
                GameObject go = GameDatabase.Instance.GetModel(modelPath);
                go.SetActive(true);
                go.layer = 15;
                go.name  = conf.GetValue("modeName") + go.GetInstanceID();
                go.transform.position = base.part.partTransform.position;
                go.transform.rotation = base.part.partTransform.rotation;
                go.transform.parent   = base.part.partTransform;
                this.currModel        = go;
            }
            else
            {
                Debug.Log("[STB] says: " + modelPath + " is not found!");
            }
            this.installedModule = m;
            this.currModeName    = conf.GetValue("modeName");
            Debug.Log("[STB]: Installing done!");
        }
示例#7
0
 public static double magicResourceTransfer(string resName, double amount, Part from, Part to)
 {
     return(MBToolbox.AddResource(resName, MBToolbox.RequestResource(resName, amount, from), to));
 }