protected override float ResourcesMass(bool maxAmount = true)
        {
            var mass = 0f;

            if (current_resource != null)
            {
                mass = (float)current_resource.maxAmount * current_resource.info.density;
            }
            else
            {
                if (tank_type == null && !init_tank_type())
                {
                    return(0);
                }
                resource_info = tank_type[CurrentResource];
                if (resource_info == null)
                {
                    return(0);
                }
                mass = MaxResourceInVolume * resource_info.Resource.density;
            }
            return(maxAmount? mass : mass *InitialAmount);
        }
        protected override float ResourcesCost(bool maxAmount = true)
        {
            var cost = 0f;

            if (current_resource != null)
            {
                cost = (float)current_resource.maxAmount * current_resource.info.unitCost;
            }
            else
            {
                if (tank_type == null && !init_tank_type())
                {
                    return(0);
                }
                resource_info = tank_type[CurrentResource];
                if (resource_info == null)
                {
                    return(0);
                }
                cost = MaxResourceInVolume * resource_info.Resource.unitCost;
            }
            return(maxAmount? cost : cost *InitialAmount);
        }
Example #3
0
 public override void Load(ConfigNode node)
 {
     base.Load(node);
     Resources = TankResource.ParseResourcesToSortedList(PossibleResources);
 }
        bool init_resource()
        {
            if (current_resource != null)
            {
                CurrentResource = current_resource.resourceName;
                return(false);
            }
            if (tank_type == null)
            {
                return(false);
            }
            //check if this is tank initialization or switching
            var initializing = previous_resource == string.Empty;

            previous_resource = CurrentResource;
            //check if the resource is in use by another tank
            if (resource_in_use(CurrentResource))
            {
                Utils.Message(6, "A part cannot have more than one resource of any type");
                #if DEBUG
                this.Log("this tank: {}\nothers: {}", CurrentResource,
                         other_tanks.Select(t => t.GetInstanceID() + ": " + t.CurrentResource));
                #endif
                return(false);
            }
            //get definition of the next not-managed resource
            resource_info = tank_type[CurrentResource];
            var maxAmount = MaxResourceInVolume;
            //if there is such resource already, just plug it in
            var part_res = part.Resources[resource_info.Name];
            if (part_res != null)
            {
                current_resource = part_res;
                //do not change resource amount/maxAmount in flight, unless we have none
                if (HighLogic.LoadedSceneIsEditor || current_resource.amount.Equals(0))
                {
                    current_resource.maxAmount = maxAmount;
                    if (current_resource.amount > current_resource.maxAmount)
                    {
                        current_resource.amount = current_resource.maxAmount;
                    }
                }
            }
            else //create the new resource
            {
                var node = new ConfigNode("RESOURCE");
                node.AddValue("name", resource_info.Name);
                node.AddValue("amount", initializing? maxAmount * InitialAmount : 0);
                node.AddValue("maxAmount", maxAmount);
                current_resource = part.Resources.Add(node);
            }
            current_resource_name = Utils.ParseCamelCase(CurrentResource);
            if (boiloff != null)
            {
                boiloff.SetResource(current_resource);
            }
            if (part.Events != null)
            {
                part.SendEvent("resource_changed");
            }
            return(true);
        }