Ejemplo n.º 1
0
        // make sure values has name lower case.
        public void Update(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, List <Tuple <string, int> > values, int cnum = 0)
        {
            var curlist = items.GetLastValues((x) => x.Details.Category == cat && x.Counts[cnum] > 0); // find all of this cat with a count >0

            var varray = new int[MaterialCommodityMicroResource.NoCounts];                             // all set to zero
            var vsets  = new bool[MaterialCommodityMicroResource.NoCounts];                            // all set to false, change

            vsets[cnum] = true;                                                                        // set the cnum to set.

            foreach (var v in values)
            {
                varray[cnum] = v.Item2;                         // set cnum value
                Change(utc, cat, v.Item1, varray, vsets, 0);    // set entry
            }

            foreach (var c in curlist)
            {
                if (values.Find(x => x.Item1.Equals(c.Details.FDName, StringComparison.InvariantCultureIgnoreCase)) == null) // if not in updated list
                {
                    var mc = new MaterialCommodityMicroResource(c);                                                          // clone it
                    mc.Counts[cnum] = 0;                                                                                     // zero cnum
                    items.Add(c.Details.FDName.ToLowerInvariant(), mc);
                    System.Diagnostics.Debug.WriteLine("{0} Found {1} not in update list, zeroing", utc, mc.Details.FDName);
                }
            }
        }
Ejemplo n.º 2
0
 public MaterialCommodityMicroResource(MaterialCommodityMicroResource c)
 {
     Counts = new int[NoCounts];
     Array.Copy(c.Counts, Counts, NoCounts);
     Price        = c.Price;
     this.Details = c.Details;       // can copy this, its fixed
 }
Ejemplo n.º 3
0
        //always changes entry 0
        public void Craft(DateTime utc, string fdname, int num)
        {
            MaterialCommodityMicroResource mc = items.GetLast(fdname.ToLowerInvariant());      // find last entry, may return null if none stored

            if (mc != null)
            {
                mc           = new MaterialCommodityMicroResource(mc); // new clone of
                mc.Counts[0] = Math.Max(mc.Counts[0] - num, 0);
                items[mc.Details.FDName.ToLowerInvariant()] = mc;
                //System.Diagnostics.Debug.WriteLine("MCMRLIST {0} Craft {1} {2}", utc.ToString(), mc.Details.FDName, num);
            }
        }
        // return shopping list/count given receipe list, list of current materials.

        static public List <Tuple <MaterialCommodityMicroResource, int> > GetShoppingList(List <Tuple <Recipes.Recipe, int> > wantedrecipes, List <MaterialCommodityMicroResource> list)
        {
            var shoppingList = new List <Tuple <MaterialCommodityMicroResource, int> >();
            var totals       = TotalList(list);

            foreach (Tuple <Recipes.Recipe, int> want in wantedrecipes)
            {
                Recipes.Recipe r      = want.Item1;
                int            wanted = want.Item2;

                for (int i = 0; i < r.Ingredients.Length; i++)
                {
                    string ingredient = r.Ingredients[i].Shortname;

                    int mi = list.FindIndex(x => x.Details.Shortname.Equals(ingredient));                                                                                          // see if we have any in list

                    MaterialCommodityMicroResource matc = mi != -1 ? list[mi] : new MaterialCommodityMicroResource(MaterialCommodityMicroResourceType.GetByShortName(ingredient)); // if not there, make one
                    if (mi == -1)                                                                                                                                                  // if not there, make an empty total entry
                    {
                        totals[matc.Details.FDName] = 0;
                    }

                    int got  = totals[matc.Details.FDName];     // what we have left from totals
                    int need = r.Amount[i] * wanted;
                    int left = got - need;

                    if (left < 0)                                                                                                                                           // if not enough
                    {
                        int shopentry = shoppingList.FindIndex(x => x.Item1.Details.Shortname.Equals(ingredient));                                                          // have we already got it in the shopping list

                        if (shopentry >= 0)                                                                                                                                 // found, update list with new wanted total
                        {
                            shoppingList[shopentry] = new Tuple <MaterialCommodityMicroResource, int>(shoppingList[shopentry].Item1, shoppingList[shopentry].Item2 - left); // need this more
                        }
                        else
                        {
                            shoppingList.Add(new Tuple <MaterialCommodityMicroResource, int>(matc, -left));  // a new shop entry with this many needed
                        }

                        totals[matc.Details.FDName] = 0;            // clear count
                    }
                    else
                    {
                        totals[matc.Details.FDName] -= need;        // decrement total
                    }
                }
            }

            shoppingList.Sort(delegate(Tuple <MaterialCommodityMicroResource, int> left, Tuple <MaterialCommodityMicroResource, int> right) { return(left.Item1.Details.Name.CompareTo(right.Item1.Details.Name)); });

            return(shoppingList);
        }
Ejemplo n.º 5
0
 public void Clear(int cnum, params MaterialCommodityMicroResourceType.CatType[] cats)
 {
     foreach (var cat in cats)                                                                   // meow
     {
         var list = items.GetLastValues((x) => x.Details.Category == cat && x.Counts[cnum] > 0); // find all of this cat with a count >0
         foreach (var e in list)
         {
             var mc = new MaterialCommodityMicroResource(e);     // clone it
             mc.Counts[cnum] = 0;
             items[e.Details.FDName.ToLowerInvariant()] = mc;    // and add to end of list
         }
     }
 }
Ejemplo n.º 6
0
        // counts/set array can be of length 1 to maximum number of counts
        // to set a value, set count/set=1 for that entry
        // to change a value, set count/set = 0 for that entry
        // to leave a value, set count=0,set=0 for that entry
        // set means set to value, else add to value
        public bool Change(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, string fdname, int[] counts, bool[] set, long price)
        {
            fdname = fdname.ToLowerInvariant();

            MaterialCommodityMicroResource mc = items.GetLast(fdname);                                                   // find last entry, may return null if none stored

            if (mc == null)                                                                                              // not stored, make new
            {
                MaterialCommodityMicroResourceType mcdb = MaterialCommodityMicroResourceType.EnsurePresent(cat, fdname); // get a MCDB of this
                mc = new MaterialCommodityMicroResource(mcdb);
            }
            else
            {
                mc = new MaterialCommodityMicroResource(mc);                // copy constructor, new copy of it
            }

            double costprev  = mc.Counts[0] * mc.Price;
            double costofnew = counts[0] * price;
            bool   changed   = false;

            for (int i = 0; i < counts.Length; i++)
            {
                int newcount = set[i] ? counts[i] : Math.Max(mc.Counts[i] + counts[i], 0);       // don't let it go below zero if changing
                if (newcount != mc.Counts[i])
                {
                    changed = true;
                    //  System.Diagnostics.Debug.WriteLine("MCMRLIST {0} Gen {1} Changed {2}:{3} Entry {4} {5} -> {6} {7}", utc.ToString(), items.Generation, mc.Details.Category, mc.Details.FDName, i, mc.Counts[i], newcount, mc.Counts[i]<newcount ? "+++" : "---");
                    //   System.Diagnostics.Debug.WriteLine(Environment.StackTrace);
                    mc.Counts[i] = newcount;
                }
            }

            if (changed)                                                    // only store back a new entry if material change to counts
            {
                if (mc.Counts[0] > 0 && counts[0] > 0)                      // if bought (defensive with mc.counts)
                {
                    mc.Price = (costprev + costofnew) / mc.Counts[0];       // price is now a combination of the current cost and the new cost. in case we buy in tranches
                }
                items[fdname] = mc;                                         // and set fdname to mc - this allows for any repeat adds due to frontier data repeating stuff in things like cargo
            }
            else
            {
                // System.Diagnostics.Debug.WriteLine("{0} Not changed {1} {2}", utc.ToString(), mc.Details.FDName, mc.Count);
            }

            return(changed);
        }
Ejemplo n.º 7
0
        // ensure a category has the same values as in values, for cnum entry.
        // All others in the same cat not mentioned in values go to zero
        // make sure values has name lower case.

        public int Update(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, List <Tuple <string, int> > values, int cnum = 0)
        {
            var curlist = items.GetLastValues((x) => x.Details.Category == cat && x.Counts[cnum] > 0); // find all of this cat with a count >0

            var varray = new int[MaterialCommodityMicroResource.NoCounts];                             // all set to zero
            var vsets  = new bool[MaterialCommodityMicroResource.NoCounts];                            // all set to false, change, with 0 in the varray, no therefore no change

            vsets[cnum] = true;                                                                        // but set the cnum to set

            int changed = 0;

            //System.Diagnostics.Debug.WriteLine("Perform update for " + cat.ToString());
            foreach (var v in values)
            {
                varray[cnum] = v.Item2;                          // set cnum value
                if (Change(utc, cat, v.Item1, varray, vsets, 0)) // set entry
                {
                    //System.Diagnostics.Debug.WriteLine("MCMRLIST {0} updated {1} {2} to {3} (entry {4})", utc.ToString(), cat, v.Item1, v.Item2 , cnum);
                    changed++;                                 // indicated changed
                }
            }

            foreach (var c in curlist)                                                                                       //go thru the non zero list of cat
            {
                if (values.Find(x => x.Item1.Equals(c.Details.FDName, StringComparison.InvariantCultureIgnoreCase)) == null) // if not in updated list
                {
                    var mc = new MaterialCommodityMicroResource(c);                                                          // clone it
                    mc.Counts[cnum] = 0;                                                                                     // zero cnum
                    items[c.Details.FDName.ToLowerInvariant()] = mc;
                    //System.Diagnostics.Debug.WriteLine("MCMRLIST {0} Found {1}:{2} not in update list, zeroing", utc.ToString(), mc.Details.Category, mc.Details.FDName);
                    changed++;
                }
            }

            if (changed > 0)
            {
                System.Diagnostics.Debug.WriteLine("MCMRLIST {0} {1} fixed {2}", utc.ToString(), cat, changed);
            }

            return(changed);
        }
Ejemplo n.º 8
0
        // counts/set array can be of length 1 to maximum number of counts
        // to set a value, set count/set=1 for that entry
        // to change a value, set count/set = 0 for that entry
        // to leave a value, set count=0,set=0 for that entry
        // set means set to value, else add to value
        public void Change(DateTime utc, MaterialCommodityMicroResourceType.CatType cat, string fdname, int[] counts, bool[] set, long price)
        {
            fdname = fdname.ToLowerInvariant();

            MaterialCommodityMicroResource mc = items.GetLast(fdname);                                                   // find last entry, may return null if none stored

            if (mc == null)                                                                                              // not stored, make new
            {
                MaterialCommodityMicroResourceType mcdb = MaterialCommodityMicroResourceType.EnsurePresent(cat, fdname); // get a MCDB of this
                mc = new MaterialCommodityMicroResource(mcdb);
            }
            else
            {
                mc = new MaterialCommodityMicroResource(mc);                // copy constructor, new copy of it
            }

            double costprev  = mc.Counts[0] * mc.Price;
            double costofnew = counts[0] * price;
            bool   changed   = false;

            for (int i = 0; i < counts.Length; i++)
            {
                int newcount = set[i] ? counts[i] : Math.Max(mc.Counts[i] + counts[i], 0); // don't let it go below zero if changing
                changed     |= newcount != mc.Counts[i];                                   // have we changed? we are trying to minimise deltas to the gen dictionary, so don't add if nothing changed
                mc.Counts[i] = newcount;
            }

            if (changed)                                              // only store back a new entry if material change to counts
            {
                if (mc.Counts[0] > 0 && counts[0] > 0)                // if bought (defensive with mc.counts)
                {
                    mc.Price = (costprev + costofnew) / mc.Counts[0]; // price is now a combination of the current cost and the new cost. in case we buy in tranches
                }
                items.Add(fdname, mc);                                // and add a new fresh mc to the dictionary
                // System.Diagnostics.Debug.WriteLine("{0} Changed {1} {2} {3}", utc, items.Generation, mc.Details.FDName, mc.Count);
            }
            else
            {
                // System.Diagnostics.Debug.WriteLine("{0} Not changed {1} {2}", utc, mc.Details.FDName, mc.Count);
            }
        }
        // curmats may be null
        Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, List <MaterialCommodityMicroResource> historicmats, List <MaterialCommodityMicroResource> curmats,
                                  Point matpos, Size matsize)
        {
            Point startpos  = matpos;
            Point maximum   = matpos;
            int   noperline = 0;

            string matclicktext = sn.DisplayMaterials(2, historicmats, curmats);

            foreach (KeyValuePair <string, double> sd in sn.Materials)
            {
                string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, historicmats, curmats);

                Color  fillc = Color.Yellow;
                string abv   = sd.Key.Substring(0, 1);

                MaterialCommodityMicroResourceType mc = MaterialCommodityMicroResourceType.GetByFDName(sd.Key);

                if (mc != null)
                {
                    abv   = mc.Shortname;
                    fillc = mc.Colour;
                    //System.Diagnostics.Debug.WriteLine("Colour {0} {1}", fillc.ToString(), fillc.GetBrightness());

                    if (HideFullMaterials)                 // check full
                    {
                        int?limit = mc.MaterialLimit();
                        MaterialCommodityMicroResource matnow = curmats?.Find(x => x.Details == mc);  // allow curmats = null

                        // debug if (matnow != null && mc.shortname == "Fe")  matnow.count = 10000;

                        if (matnow != null && limit != null && matnow.Count >= limit)        // and limit
                        {
                            continue;
                        }
                    }

                    if (ShowOnlyMaterialsRare && mc.IsCommonMaterial)
                    {
                        continue;
                    }
                }

                System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap();
                colormap.OldColor = Color.White;    // this is the marker colour to replace
                colormap.NewColor = fillc;

                Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)BaseUtils.Icons.IconSet.GetIcon("Controls.Scan.Bodies.Material"), new System.Drawing.Imaging.ColorMap[] { colormap });

                BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, Font, fillc.GetBrightness() > 0.4f ?  Color.Black : Color.White);

                ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement(
                    new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, tooltip + "\n\n" + "All " + matclicktext, tooltip);

                pc.Add(ie);

                maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height));

                if (++noperline == 4)
                {
                    matpos    = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy);
                    noperline = 0;
                }
                else
                {
                    matpos.X += matsize.Width + materiallinespacerxy;
                }
            }

            return(maximum);
        }