Beispiel #1
0
        public void clearResources(ref xPipeLine pipeModule)
        {

          //  pipeModule.part.Resources.list.Clear();
            string recipeOutputs = "";
            
            pipeModule.RecipeOutputs = recipeOutputs;
            pipeModule.reloadRecipe();
           

        }
Beispiel #2
0
        public void getNetworkResources(pipelineShip p, ref xPipeLine pipeModule, double dt)
        {
            Dictionary<string, double> supply = new Dictionary<string, double>();
            Dictionary<string, double> demand = new Dictionary<string, double>();
            Dictionary<string, double> capacity = new Dictionary<string, double>();
           // pipeModule.contributors = new Dictionary<string, Dictionary<string, double>>();

            foreach(pipelineShip px in Networks[p.networkID])
           {
               if (px.id == p.id) continue;
                foreach(string k in px.resourceSupply.Keys)
                {
                    if (k == "pipeNetwork")
                        continue;
                    if (supply.ContainsKey(k))
                    {
                        double capacityScalar = Math.Min(px.resourceCapacity[k], dt) / dt;
                        supply[k] += px.resourceSupply[k] * capacityScalar;
                        demand[k] += px.resourceDemand[k];
                        
                    }
                    else
                    {
                        double capacityScalar = Math.Min(px.resourceCapacity[k], dt) / dt;
                        supply[k] = px.resourceSupply[k] * capacityScalar;
                        demand[k] = px.resourceDemand[k];
                         
                    }
                  

                }
                
              

           }
            //pipeModule.part.Resources.list.Clear();
            //foreach (string k in amounts.Keys)
            //{
            //    ConfigNode resourceNode = new ConfigNode("RESOURCE");

            //    resourceNode.AddValue("name", k);
            //    resourceNode.AddValue("amount", amounts[k].ToString());
            //    resourceNode.AddValue("maxAmount", maximums[k].ToString());
            //    print("try to add resource...");
            //    try
            //    {
            //        var resource = pipeModule.part.AddResource(resourceNode);

            //        print("resource defined " + resource.info.name + " " + resource.amount.ToString() + " " + resource.maxAmount.ToString());
            //    }
            //    catch { }

            //}

           print("part has resources " + pipeModule.part.Resources.Count.ToString());
           foreach (var res in pipeModule.part.Resources.list)
               print("resource " + res.info.name + " " + res.amount.ToString() + " " + res.maxAmount.ToString());

           string recipeOutputs = "";
           foreach (string k in demand.Keys)
           {
               
               recipeOutputs += k + "," + ( (supply[k] - demand[k])).ToString() + ",true;";
           }
            recipeOutputs = recipeOutputs.TrimEnd(';');
            print("recipe outputs = " + recipeOutputs);

            pipeModule.RecipeOutputs = recipeOutputs;
            pipeModule.reloadRecipe();
            print("adjusting mass... resource mass = " + pipeModule.part.GetResourceMass().ToString());
           
            print("part mass..." + pipeModule.part.mass.ToString());

            p.needsResourceUpdate = false;
        }