예제 #1
0
 public PartKit(
     string name,
     float mass,
     float cost,
     float assembly_fraction,
     float additional_work,
     bool assembled
 )
 {
     Name = name;
     craftID = 0;
     PseudoPart = true;
     Mass.Add(assembly_fraction, mass);
     Cost.Add(assembly_fraction, cost);
     Complexity = assembly_fraction;
     var assembly_mass = mass * assembly_fraction;
     var assembly_work = additional_work * assembly_fraction;
     Assembly.TotalWork = total_work(Assembly, assembly_mass) + assembly_work;
     Construction.TotalWork = total_work(Construction, mass - assembly_mass)
                              + additional_work
                              - assembly_work;
     update_total_work();
     if(assembled)
         SetStageComplete(ASSEMBLY, true);
 }
예제 #2
0
 public void ComputeCost()
 {
     cost = new Cost();
     foreach (var c in data.cost)
     {
         cost.Add(c);
     }
 }
        public void TestAddingZeroIsZero()
        {
            Cost none = new Cost();
            none.Add(new Cost());

            var a = new Cost();
            var b = new Cost();
            Assert.IsTrue(a.Equals(b));
            Assert.AreEqual(0, new Cost().GetLoDSum());
        }
예제 #4
0
        public PartKit(Part part, bool assembled = true)
        {
            Name                = part.partInfo.title;
            craftID             = part.craftID;
            PseudoPart          = false;
            part.needPrefabMass = true;
            part.UpdateMass();
            var   kit_container = part.Modules.GetModule <DeployableKitContainer>();
            var   dry_cost = Mathf.Max(part.DryCost(), 0);
            float kit_mass, kit_cost;

            Mass.Add(1, part.mass);
            Cost.Add(1, dry_cost);
            if (kit_container != null)
            {
                var kit = kit_container.kit;
                kit_mass               = kit.MassAtStage(ASSEMBLY);
                kit_cost               = kit.CostAtStage(ASSEMBLY);
                Complexity             = 0;
                Assembly.TotalWork     = kit.TotalWorkInStage(ASSEMBLY);
                Construction.TotalWork = total_work(Construction, part.mass - kit_mass);
            }
            else
            {
                Complexity =
                    Mathf.Clamp01(1
                                  - 1
                                  / ((dry_cost / part.mass
                                      + GLB.IgnoreModules.SizeOfDifference(part.Modules) * 1000)
                                     * GLB.ComplexityFactor
                                     + 1));
                var structure_mass = part.mass * Mathf.Clamp01(1 - Complexity);
                var structure_cost =
                    Mathf.Min(
                        structure_mass
                        / GLB.ConstructionResource.def.density
                        * GLB.ConstructionResource.def.unitCost,
                        dry_cost * 0.9f);
                kit_mass               = part.mass - structure_mass;
                kit_cost               = dry_cost - structure_cost;
                Assembly.TotalWork     = total_work(Assembly, kit_mass);
                Construction.TotalWork = total_work(Construction, structure_mass);
            }
            update_total_work();
            var frac = (float)(Assembly.TotalWork / TotalWork);

            Mass.Add(frac, kit_mass);
            Cost.Add(frac, kit_cost);
            if (assembled || frac.Equals(0))
            {
                SetStageComplete(ASSEMBLY, true);
            }
        }
        public void Add(Costs cost, double price)
        {
            var cos = Cost.Keys.FirstOrDefault(f => f.Name.Equals(cost.Name));

            if (cos == null)
            {
                Cost.Add(cost, price);
            }
            else
            {
                Cost[cos] += price;
            }
        }
예제 #6
0
        public bool AddCostData(Cost cost)
        {
            if (cost == null)
            {
                return(false);
            }
            if (cost.PaidPatientCopay == 0 && cost.PaidPatientCoinsurance == 0 && cost.PaidPatientDeductible == 0 &&
                cost.PaidByPayer == 0 && cost.TotalPaid == 0)
            {
                return(false);
            }

            Cost.Add(cost);
            return(true);
        }
예제 #7
0
 //deprecated config conversion
 public override void Load(ConfigNode node)
 {
     base.Load(node);
     if (!Construction.Valid)
     {
         CurrentIndex = -1;
     }
     else if (node.HasValue("Completeness"))
     {
         CurrentIndex       = CONSTRUCTION;
         Assembly.TotalWork = Assembly.WorkDone = Construction.TotalWork;
         update_total_work();
         float v;
         var   frac = (float)(Assembly.TotalWork / TotalWork);
         var   val  = node.GetValue("Title");
         if (!string.IsNullOrEmpty(val))
         {
             Name = val;
         }
         val = node.GetValue("PartMass");
         if (float.TryParse(val, out v))
         {
             Mass.Add(1, v);
         }
         val = node.GetValue("PartCost");
         if (float.TryParse(val, out v))
         {
             Cost.Add(1, v);
         }
         val = node.GetValue("KitMass");
         if (float.TryParse(val, out v))
         {
             Mass.Add(frac, v);
         }
         val = node.GetValue("KitCost");
         if (float.TryParse(val, out v))
         {
             Cost.Add(frac, v);
         }
         frac = (float)get_fraction();
         Mass.Update(frac);
         Cost.Update(frac);
     }
 }
예제 #8
0
        public PartKit(Part part, bool assembled = true)
        {
            Name       = part.partInfo.title;
            craftID    = part.craftID;
            PseudoPart = false;
            var is_DIY_Kit = part.Modules.Contains <DeployableKitContainer>();
            var dry_cost   = Mathf.Max(part.DryCost(), 0);

            Mass.Add(1, part.mass);
            Cost.Add(1, dry_cost);
            if (is_DIY_Kit)
            {
                Complexity             = 1;
                Assembly.TotalWork     = total_work(Assembly, part.mass);
                Construction.TotalWork = 0;
                update_total_work();
                if (assembled)
                {
                    SetComplete(assembled);
                }
            }
            else
            {
                Complexity = Mathf.Clamp01(1 - 1 / ((dry_cost / part.mass + GLB.IgnoreModules.SizeOfDifference(part.Modules) * 1000) * GLB.ComplexityFactor + 1));
                var structure_mass = part.mass * Mathf.Clamp01(1 - Complexity);
                var structure_cost = Mathf.Min(structure_mass / GLB.ConstructionResource.def.density * GLB.ConstructionResource.def.unitCost, dry_cost * 0.9f);
                var kit_mass       = part.mass - structure_mass;
                var kit_cost       = dry_cost - structure_cost;
                Construction.TotalWork = total_work(Construction, structure_mass);
                Assembly.TotalWork     = total_work(Assembly, kit_mass);
                update_total_work();
                var frac = (float)(Assembly.TotalWork / TotalWork);
                //Utils.Log("{}: C {}, frac {}, kit_mass {}, kit_cost {}",
                //Complexity, Name, frac, kit_mass, kit_cost);//debug
                Mass.Add(frac, kit_mass);
                Cost.Add(frac, kit_cost);
                SetStageComplete(ASSEMBLY, assembled);
            }
        }
예제 #9
0
 public PartKit(string name, float mass, float cost, bool assembled)
 {
     Name       = name;
     craftID    = 0;
     PseudoPart = true;
     Mass.Add(1, mass);
     Cost.Add(1, cost);
     if (assembled)
     {
         Complexity             = 0;
         Construction.TotalWork = total_work(Construction, mass);
         Assembly.TotalWork     = 0;
         update_total_work();
         SetStageComplete(ASSEMBLY, true);
     }
     else
     {
         Complexity             = 1;
         Assembly.TotalWork     = total_work(Assembly, mass);
         Construction.TotalWork = 0;
         update_total_work();
     }
 }
 public override void link(Cost directCost, Cost dependantCost)
 {
     directCost.Add(getCost());
 }
예제 #11
0
 public void AccumulateCost(Cost cost)
 {
     currentCost = currentCost.Add(cost);
 }