Esempio n. 1
0
        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("[RMResourceManager] ProcessParts: parent {0}", part.parent);
                set = AddModule(cp.Name(part.parent), GetID(part.parent));
            }

            set.AddPart(part);

            for (int i = part.children.Count; i-- > 0;)
            {
                var child = part.children[i];
                if (excludeParts.Contains(child))
                {
                    continue;
                }
                if (cp.Has(child))
                {
                    //Debug.LogFormat("[RMResourceManager] ProcessParts: child {0}", child);
                    ProcessParts(child, AddModule(cp.Name(child), GetID(child)));
                }
                else
                {
                    ProcessParts(child, set);
                }
            }
        }
        RMResourceSet AddModule(string name, uint id)
        {
            var set = new RMResourceSet();

            set.name = name;
            set.id   = id;
            moduleSets.Add(set);
            return(set);
        }
Esempio n. 4
0
 void AddSet(XferSet xferSet, RMResourceSet set, string resourceName)
 {
     if (!xferSet.ContainsKey(resourceName))
     {
         xferSet[resourceName]          = new RMResourceSet();
         xferSet[resourceName].balanced = true;
     }
     xferSet[resourceName].AddSet(set);
 }
 // Returns the amount of resource not transfered (0 = all has been
 // transfered).
 public double Transfer(double amount, bool balanced = true)
 {
     if (balanced)
     {
         return(RMResourceSet.BalancedTransfer(this, amount));
     }
     else
     {
         return(RMResourceSet.UnbalancedTransfer(this, amount));
     }
 }
Esempio n. 6
0
 void RemoveSet(XferSet xferSet, RMResourceSet set, string resourceName)
 {
     if (xferSet.ContainsKey(resourceName))
     {
         var s = xferSet[resourceName];
         s.RemoveSet(set);
         if (s.resources.Count < 1)
         {
             xferSet.Remove(resourceName);
         }
     }
 }
Esempio n. 7
0
 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));
     }
 }
        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;
                    set.id   = m.id;
                }
                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;
                }
            }
        }
        // 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}", id, 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;
        }
 public void MoveSet(XferState from, XferState to, RMResourceSet set,
                     string resourceName)
 {
     if (from == XferState.In)
     {
         xferControl.RemoveDestination(set, resourceName);
     }
     else if (from == XferState.Out)
     {
         xferControl.RemoveSource(set, resourceName);
     }
     if (to == XferState.In)
     {
         xferControl.AddDestination(set, resourceName);
     }
     else if (to == XferState.Out)
     {
         xferControl.AddSource(set, resourceName);
     }
     xferControl.CheckTransfer();
 }
Esempio n. 11
0
 public void RemoveSource(RMResourceSet set, string resourceName)
 {
     Debug.Log($"[ResourceXferControl] RemoveSource {set.name} {resourceName}");
     RemoveSet(srcSets, set, resourceName);
 }
Esempio n. 12
0
 public void RemoveDestination(RMResourceSet set, string resourceName)
 {
     Debug.Log($"[ResourceXferControl] RemoveDestination {set.name} {resourceName}");
     RemoveSet(dstSets, set, resourceName);
 }