Example #1
0
 private bool check_resourceTank(resData resDat)
 {
     foreach (KeyValuePair <string, PartResource> pair in getVesselResources(this.TargetShipSelected))
     {
         if (pair.Key == resDat.resourceName)
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
        private void createTank(resData resDat, float tanksize)
        {
            Part CargoBayPart = findCargoBay();

            if (CargoBayPart != null)
            {
                ConfigNode newRes = new ConfigNode("RESOURCE");
                newRes.AddValue("name", resDat.resourceName);
                newRes.AddValue("amount", 0F);
                newRes.AddValue("maxAmount", tanksize / resDat.PartResource.info.density);

                CargoBayPart.Resources.Add(newRes);
                //this.STCB.useCargoSpace(tanksize);

                float power = tanksize * PT2.L2_usage;
                this.PowSys.draw(PT2.takerName, power);
            }
        }
Example #3
0
        private resData getResourcesInfo(Vessel vesselToSearch, string ResourceToSearch)
        {
            resData tempDat = new resData();

            tempDat.resourceName = ResourceToSearch;
            foreach (Part p in vesselToSearch.Parts)
            {
                PartResourceList pRL = p.Resources;
                foreach (PartResource pr in pRL)
                {
                    if (pr.resourceName == tempDat.resourceName)
                    {
                        tempDat.PartResource    = pr;
                        tempDat.totalAmount    += pr.amount;
                        tempDat.totalWeight    += pr.amount * pr.info.density;
                        tempDat.totalFreeSpace += pr.maxAmount - pr.amount;
                    }
                }
            }
            return(tempDat);
        }
Example #4
0
        private void GUI_transfer_gui()
        {
            resData      resDat  = getResourcesInfo(this.SourceShipSelected, ResourceToMoveSelected);
            resData      resDat2 = getResourcesInfo(this.TargetShipSelected, ResourceToMoveSelected);
            PartResource CargoBayPartResourceRef = findCargoBay_partResource(this.TargetShipSelected, ResourceToMoveSelected);

            GUILayout.BeginVertical();

            GUILayout.Label("Source Ship Data:");

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Amount pesent: " + Math.Round(resDat.totalAmount, 2));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Free Capacity: " + Math.Round(resDat.totalFreeSpace, 2));
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.BeginVertical(scrollview_style2, GUILayout.Width(280));
            FTscrollPosition1 = GUILayout.BeginScrollView(FTscrollPosition1);
            foreach (Part p in this.SourceShipSelected.Parts)
            {
                PartResourceList pRL = p.Resources;
                foreach (PartResource pr in pRL)
                {
                    if (pr.resourceName == resDat.resourceName)
                    {
                        GUILayout.Label(pr.part.partInfo.title + " (" + Math.Round(pr.amount, 2) + ")");
                    }
                }
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Drain");
            GUILayout.FlexibleSpace();
            GUILayout.Label("Fill");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.RepeatButton("-100"))
            {
                //tranfer_resource(pr, CargoBayPartResourceRef,100);
                tranfer_resource_shipwide(this.SourceShipSelected, this.TargetShipSelected, ResourceToMoveSelected, 100);
            }
            if (GUILayout.RepeatButton("-10"))
            {
                //tranfer_resource(pr, CargoBayPartResourceRef, 10);
                tranfer_resource_shipwide(this.SourceShipSelected, this.TargetShipSelected, ResourceToMoveSelected, 10);
            }
            if (GUILayout.RepeatButton("-1"))
            {
                //tranfer_resource(pr, CargoBayPartResourceRef, 1);
                tranfer_resource_shipwide(this.SourceShipSelected, this.TargetShipSelected, ResourceToMoveSelected, 1);
            }
            if (GUILayout.RepeatButton("+1"))
            {
                //tranfer_resource(CargoBayPartResourceRef, pr, 1);
                tranfer_resource_shipwide(this.TargetShipSelected, this.SourceShipSelected, ResourceToMoveSelected, 1);
            }
            if (GUILayout.RepeatButton("+10"))
            {
                //tranfer_resource(CargoBayPartResourceRef, pr, 10);
                tranfer_resource_shipwide(this.TargetShipSelected, this.SourceShipSelected, ResourceToMoveSelected, 10);
            }
            if (GUILayout.RepeatButton("+100"))
            {
                //tranfer_resource(CargoBayPartResourceRef, pr, 100);
                tranfer_resource_shipwide(this.TargetShipSelected, this.SourceShipSelected, ResourceToMoveSelected, 100);
            }
            GUILayout.EndHorizontal();
        }
Example #5
0
        private void GUI_transfer_options()
        {
            if (tanksize == 0f)
            {
                tanksize = 10f;
            }


            resData resDat  = getResourcesInfo(this.SourceShipSelected, ResourceToMoveSelected);
            resData resDat2 = getResourcesInfo(this.TargetShipSelected, ResourceToMoveSelected);


            bool  tank_present = check_resourceTank(resDat);
            float freeCB       = this.STCB.getFreeCargoSpace();


            if (tank_present && resDat2.totalFreeSpace > 0)
            {
                GUILayout.Label("Own Ship Data: ");

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Resource Tank available: " + tank_present);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Amount present: " + resDat2.totalAmount);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Free Capacity: " + Math.Round(resDat2.totalFreeSpace, 2));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Free Cargo Space: " + freeCB + "t");
                GUILayout.EndHorizontal();


                GUI_transfer_gui();
            }
            else
            {
                if (tank_present && resDat2.totalFreeSpace <= 0)
                {
                    GUILayout.BeginVertical();
                    GUILayout.Label("Capt'n, this Tank is overfilled!");
                    GUILayout.Label("The ventile is completely sealed.");
                    GUILayout.Label("We can force the ventile open!");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    GUILayout.Label("Aye");
                    GUILayout.Label("But this will destroy some of the resource?");
                    GUILayout.Label("How Much you ask.");
                    GUILayout.Label("Well - how should I know in advance?");
                    GUILayout.Label("I can only do my best now - can I?");
                    if (GUILayout.Button("Unlock the ventile for " + resDat.resourceName + " in the CargoBay"))
                    {
                        resDat2.PartResource.amount = resDat2.PartResource.amount - rnd.Next(1, 15);
                    }
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    GUILayout.Label("Yes - if we have enough cargobay, we can");
                    GUILayout.Label("make it bigger without loss.");
                    GUILayout.Label("You should talk to the fuel tank manager.");
                    if (GUILayout.Button("Ask the fuel tank manager"))
                    {
                        GUISelection = "FuelTanksMain";
                    }
                    GUILayout.EndVertical();
                }
                else
                {
                    GUILayout.BeginVertical();
                    GUILayout.Label("Capt'n, she doesn't have");
                    GUILayout.Label("this type of storage capacity!");
                    GUILayout.Label("Shall we rig someth'n up in ye CargoBay?");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    GUILayout.Label("Aye - just select the tanksize and hit the button to confirm the order.");
                    GUILayout.Label("Ye CargoBay has currently " + freeCB + "t free");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    GUILayout.Label("Make it big enough, if you overfill the tank,");
                    GUILayout.Label("it might lock down the ventile!");
                    GUILayout.EndVertical();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("min");
                    GUILayout.Label("current");
                    GUILayout.Label("max");
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(Math.Round(resDat.PartResource.amount / resDat.PartResource.info.density, 2).ToString());
                    tanksize = float.Parse(GUILayout.TextField(tanksize.ToString(), 25));
                    GUILayout.Label(Math.Round(freeCB, 2).ToString());
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();


                    if (GUILayout.Button("Create a " + tanksize + "t Tank for " + resDat.resourceName + " in the CargoBay"))
                    {
                        float clamped = Mathf.Clamp(tanksize, 0f, freeCB);
                        createTank(resDat, clamped);
                        tanksize = 0f;
                    }
                    GUILayout.EndHorizontal();
                }
            }
        }