Example #1
0
        void ProcessResource(RMResourceSet vr, string res, BuildResourceSet rd, bool xfer)
        {
            var amount = vr.ResourceAmount(res);
            var mass   = amount * ELRecipeDatabase.ResourceDensity(res);

            ProcessIngredient(new Ingredient(res, mass), rd, xfer);
        }
Example #2
0
 void onVesselWasModified(Vessel v)
 {
     if (v == recycler.vessel)
     {
         recycler_resources = new RMResourceSet(recycler.vessel, recycle_parts);
     }
 }
Example #3
0
 public void Start(Collider field)
 {
     RecycleField = field;
     GameEvents.onVesselWasModified.Add(onVesselWasModified);
     recycler_resources = new RMResourceSet(recycler.vessel, recycle_parts);
     fsm.StartFSM(start_state);
 }
        void ProcessResources(RMResourceSet resources, BuildResourceSet report_resources, BuildResourceSet required_resources = null)
        {
            var reslist = resources.resources.Keys.ToList();

            foreach (string res in reslist)
            {
                double amount = resources.ResourceAmount(res);
                var    recipe = ELRecipeDatabase.ResourceRecipe(res);

                if (recipe != null)
                {
                    double density = ELRecipeDatabase.ResourceDensity(res);
                    double mass    = amount * density;
                    recipe = recipe.Bake(mass);
                    foreach (var ingredient in recipe.ingredients)
                    {
                        var br     = new BuildResource(ingredient);
                        var resset = report_resources;
                        if (required_resources != null)
                        {
                            resset = required_resources;
                        }
                        resset.Add(br);
                    }
                }
                else
                {
                    var br = new BuildResource(res, amount);
                    report_resources.Add(br);
                }
            }
        }
        public void RemoveSet(RMResourceSet set)
        {
            sets.Remove(set);
            var remove_list = new List <string> ();

            foreach (var resinfo in resources)
            {
                string         resource     = resinfo.Key;
                RMResourceInfo resourceInfo = resinfo.Value;
                for (int i = resourceInfo.containers.Count - 1; i >= 0; i--)
                {
                    var container = resourceInfo.containers[i] as ResourceSetContainer;
                    if (container != null && container.set == set)
                    {
                        resourceInfo.containers.Remove(container);
                    }
                }
                if (resourceInfo.containers.Count == 0)
                {
                    remove_list.Add(resource);
                }
            }
            foreach (string resource in remove_list)
            {
                resources.Remove(resource);
            }
        }
        void ProcessParts(Part part, RMResourceSet set)
        {
            var cp = ConnectedParts(part);

            if (part.parent != null && cp.Has(part.parent))
            {
                //Debug.LogFormat("[RMResourceSet] ProcessParts: parent {0}", part.parent);
                set = AddModule(cp.Name(part.parent));
            }

            set.AddPart(part);

            for (int i = part.children.Count; i-- > 0;)
            {
                var child = part.children[i];
                if (cp.Has(child))
                {
                    //Debug.LogFormat("[RMResourceSet] ProcessParts: child {0}", child);
                    ProcessParts(child, AddModule(cp.Name(child)));
                }
                else
                {
                    ProcessParts(child, set);
                }
            }
        }
Example #7
0
 public void Start(Collider field)
 {
     workNet      = recycler.vessel.FindVesselModuleImplementing <ELVesselWorkNet> ();
     RecycleField = field;
     GameEvents.onVesselWasModified.Add(onVesselWasModified);
     recycler_resources = new RMResourceSet(recycler.vessel, recycle_parts);
     fsm.StartFSM(start_state);
 }
        RMResourceSet AddModule(string name)
        {
            var set = new RMResourceSet();

            set.name = name;
            moduleSets.Add(set);
            return(set);
        }
Example #9
0
 void AddSet(Dictionary <string, RMResourceSet> dict, RMResourceSet set, string res)
 {
     if (!dict.ContainsKey(res))
     {
         dict[res]          = new RMResourceSet();
         dict[res].balanced = true;
     }
     dict[res].AddSet(set);
 }
 internal void SetupCraftResources(Vessel vsl)
 {
     craftResources = new RMResourceSet(vsl);
     foreach (var br in buildCost.optional)
     {
         var amount = craftResources.ResourceAmount(br.name);
         craftResources.TransferResource(br.name, -amount);
     }
 }
Example #11
0
        void FlowState(RMResourceSet set, string res)
        {
            bool curFlow = set.GetFlowState(res);
            bool newFlow = GUILayout.Toggle(curFlow, "");

            if (newFlow != curFlow)
            {
                set.SetFlowState(res, newFlow);
            }
        }
Example #12
0
        void RemoveSet(Dictionary <string, RMResourceSet> dict, RMResourceSet set, string res)
        {
            var s = dict[res];

            s.RemoveSet(set);
            if (s.resources.Count < 1)
            {
                dict.Remove(res);
            }
        }
 void onVesselWasModified(Vessel v)
 {
     if (v == builder.vessel)
     {
         padResources = new RMResourceSet(builder.vessel);
         if (craftRoot != null && craftRoot.vessel != builder.vessel)
         {
             CleaupAfterRelease();
         }
     }
 }
Example #14
0
        void ModuleResourceLine(int ind, RMResourceSet set, string res,
                                bool highlight)
        {
            double amount    = set.ResourceAmount(res);
            double maxAmount = set.ResourceCapacity(res);

            GUILayout.BeginHorizontal();
            GUILayout.Space(40);
            GUILayout.Label(set.name, ELStyles.label);
            GUILayout.FlexibleSpace();
            string amountFmt    = "F0";
            string maxAmountFmt = "F0";

            if (amount < 100)
            {
                amountFmt = "F2";
            }
            if (maxAmount < 100)
            {
                maxAmountFmt = "F2";
            }
            GUILayout.Label(amount.ToString(amountFmt), ELStyles.label);
            GUILayout.Label("/", ELStyles.label);
            GUILayout.Label(maxAmount.ToString(maxAmountFmt), ELStyles.label);
            TransferState(ind, set, res);
            FlowState(set, res);
            GUILayout.EndHorizontal();

            if (setSelected != null &&
                Event.current.type == EventType.Repaint)
            {
                var rect = GUILayoutUtility.GetLastRect();
                if (highlight && rect.Contains(Event.current.mousePosition))
                {
                    if (!setSelected[ind])
                    {
                        setSelected[ind] = true;
                        HighlightSet(set, res, true);
                    }
                }
                else
                {
                    if (setSelected[ind])
                    {
                        setSelected[ind] = false;
                        HighlightSet(set, res, false);
                    }
                }
            }
        }
        public CostReport getBuildCost(ConfigNode craft)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct();

            if (!ship.LoadShip(craft))
            {
                return(null);
            }
            if (!ship.shipPartsUnlocked)
            {
                lockedParts = true;
            }
            GameObject ro          = ship.parts[0].localRoot.gameObject;
            Vessel     craftVessel = ro.AddComponent <Vessel>();

            craftVessel.vesselName = "EL craftVessel - " + craft.GetValue("ship");
            craftVessel.Initialize(true);
            foreach (Part part in craftVessel.parts)
            {
                part.ModulesOnStart();
            }
            if (ELSettings.B9Wings_Present)
            {
                if (!InitializeB9Wings(craftVessel) &&
                    ELSettings.FAR_Present)
                {
                    InitializeFARSurfaces(craftVessel);
                }
            }
            else if (ELSettings.FAR_Present)
            {
                InitializeFARSurfaces(craftVessel);
            }

            // needed for displaying optional resources during the planning
            // stage.
            craftResources = new RMResourceSet(craftVessel);

            BuildCost resources = new BuildCost();

            foreach (Part p in craftVessel.parts)
            {
                resources.addPart(p);
            }
            craftVessel.Die();

            return(resources.cost);
        }
 public void AddSet(RMResourceSet set)
 {
     sets.Add(set);
     foreach (var resource in set.resources.Keys)
     {
         RMResourceInfo resourceInfo;
         if (!resources.ContainsKey(resource))
         {
             resourceInfo        = new RMResourceInfo();
             resources[resource] = resourceInfo;
         }
         resourceInfo = resources[resource];
         resourceInfo.containers.Add(new ResourceSetContainer(resource, set));
     }
 }
        // The dictionary is indexed by part id (flight or craft) such that
        // the symmetry set can be found by the id of any part within the set.
        // However, the sets consist of only those parts that hold resources.
        void FindSymmetrySets(IEnumerable <Part> parts)
        {
            visitedParts.Clear();
            var dict = new Dictionary <uint, RMResourceSet> ();
            var sets = new List <RMResourceSet> ();

            foreach (Part p in parts)
            {
                if (excludeParts.Contains(p))
                {
                    continue;
                }
                uint id = GetID(p);
                //Debug.LogFormat ("{0} {1} {2}", i, p.name, p.symmetryCounterparts.Count);
                if (p.Resources.Count < 1)
                {
                    // no resources, so no point worrying about symmetry
                    continue;
                }
                if (p.symmetryCounterparts.Count < 1)
                {
                    // not part of a symmetry set
                    continue;
                }
                if (visitedParts.Contains(id))
                {
                    // already added this part
                    continue;
                }
                visitedParts.Add(id);
                RMResourceSet symmetrySet = new RMResourceSet();
                symmetrySet.balanced = true;
                symmetrySet.name     = "sym " + id.ToString();
                symmetrySet.AddPart(p);
                dict[id] = symmetrySet;
                sets.Add(symmetrySet);
                for (int j = 0; j < p.symmetryCounterparts.Count; j++)
                {
                    Part s = p.symmetryCounterparts[j];
                    id = GetID(s);
                    visitedParts.Add(id);
                    symmetrySet.AddPart(s);
                    dict[id] = symmetrySet;
                }
            }
            symmetryDict = dict;
            symmetrySets = sets;
        }
        void FinalizeResourceSets()
        {
            visitedParts.Clear();
            resourceSets = new List <RMResourceSet> ();
            masterSet    = new RMResourceSet();
            RMResourceSet set = null;

            foreach (var m in moduleSets)
            {
                if (set == null)
                {
                    set      = new RMResourceSet();
                    set.name = m.name;
                }
                foreach (var p in m.parts)
                {
                    uint id = GetID(p);
                    if (visitedParts.Contains(id))
                    {
                        continue;
                    }
                    if (p.symmetryCounterparts.Count > 0 &&
                        symmetryDict.ContainsKey(id))
                    {
                        RMResourceSet sym = symmetryDict[id];
                        foreach (var s in sym.parts)
                        {
                            uint sid = GetID(s);
                            visitedParts.Add(sid);
                        }
                        set.AddSet(sym);
                        masterSet.AddSet(sym);
                    }
                    else
                    {
                        visitedParts.Contains(id);
                        set.AddPart(p);
                        masterSet.AddPart(p);
                    }
                }
                if (set.parts.Count > 0 || set.sets.Count > 0)
                {
                    resourceSets.Add(set);
                    set = null;
                }
            }
        }
        internal void FindVesselResources()
        {
            padResources = new RMResourceSet(builder.vessel);
            var craft_parts = CraftParts();

            if (craft_parts.Count > 0)
            {
                craftResources = new RMResourceSet();
            }
            foreach (var part in craft_parts)
            {
                padResources.RemovePart(part);
                craftResources.AddPart(part);
            }
            if (craftResources == null && craftConfig != null)
            {
                getBuildCost(craftConfig);
            }
        }
Example #20
0
        void TransferState(int ind, RMResourceSet set, string res)
        {
            XferState old = XferState.Hold;

            if (xferState != null)
            {
                old = xferState[ind];
            }
            ToggleXferState(ind, XferState.Hold, "Hold");
            ToggleXferState(ind, XferState.In, "In");
            ToggleXferState(ind, XferState.Out, "Out");
            GUILayout.Space(40);
            if (xferState != null && xferState[ind] != old)
            {
                if (old == XferState.In)
                {
                    RemoveSet(dstSets, set, res);
                }
                else if (old == XferState.Out)
                {
                    RemoveSet(srcSets, set, res);
                }
                if (xferState[ind] == XferState.In)
                {
                    AddSet(dstSets, set, res);
                }
                else if (xferState[ind] == XferState.Out)
                {
                    AddSet(srcSets, set, res);
                }
                canTransfer = false;
                foreach (string r in dstSets.Keys)
                {
                    if (srcSets.ContainsKey(r))
                    {
                        canTransfer = true;
                        break;
                    }
                }
            }
        }
Example #21
0
        void HighlightSet(RMResourceSet set, string res, bool on)
        {
            RMResourceInfo info;

            if (set.resources.TryGetValue(res, out info))
            {
                for (int i = 0; i < info.containers.Count; i++)
                {
                    var c = info.containers[i];
                    if (c is PartResourceContainer)
                    {
                        HighlightPart(c.part, on);
                    }
                    else if (c is ResourceSetContainer)
                    {
                        var sc = c as ResourceSetContainer;
                        HighlightSet(sc.set, res, on);
                    }
                }
            }
        }
 public BuildCost()
 {
     resources    = new RMResourceSet();
     container    = new RMResourceSet();
     hullResoures = new RMResourceSet();
 }