/// <summary> /// load a cargo based on the cargo ID /// </summary> /// <param name="cargoid"></param> /// <returns></returns> public Traveller.Starship.cargoDesc loadCargo(int cargoid) { Traveller.Starship.cargoDesc cargo = new Starship.cargoDesc(); XDocument xdoc = XDocument.Load(this.filename); //XElement cargoNode = xmlDoc.Root.Elements("Cargo").Elements("lot").Where(r => (int)r.Attribute("cargoID") == cargo.cargoID // & (string)r.Attribute("sold") == "false").FirstOrDefault(); XElement sn = xdoc.Root.Elements("Cargo").Elements("lot").Where(r => (int)r.Attribute("cargoID") == cargoid).FirstOrDefault(); if (sn != null) { cargo.desc = sn.Element("desc").Value; cargo.origCode = sn.Attribute("origCode").Value; cargo.dtons = Convert.ToInt32(sn.Attribute("dTons").Value); cargo.cargoID = cargoid; int.TryParse(sn.Element("purchase").Element("baseprice").Value, out cargo.basecostbuy); int.TryParse(sn.Element("purchase").Element("finalprice").Value, out cargo.purchasePrice); int.TryParse(sn.Element("selling").Element("baseprice").Value, out cargo.basecostsell); int.TryParse(sn.Element("selling").Element("finalprice").Value, out cargo.sellingPrice); } return cargo; }
/// <summary> /// create a cargo based on the CSV line item /// </summary> /// <param name="lot"></param> /// <returns></returns> private Traveller.Starship.cargoDesc MTCreateCargo(string[] lot, List<string> avTable, List<string> expandedGoods) { Traveller.Starship.cargoDesc cargo = new Starship.cargoDesc(); cargo.desc = lot[1]; int.TryParse(lot[2], out cargo.basecostbuy); cargo.basecostsell = cargo.basecostbuy; // determine dTons string[] qty = lot[3].Split(new char[] { 'D', 'd', 'x' }); int dice = Convert.ToInt32(qty[0]); for (int i = 0; i < dice; i++) { cargo.dtons += util.rollDx(6); } int multiplier = Convert.ToInt32(qty[2]); cargo.dtons *= multiplier; cargo.origCode = this.world.TechLevel.ToString() + " - "; // figure out the actual value // 1st, any trade class mods string[] buymods = lot[5].Split(new char[] { ' ' }); int buyMax = 0; int mods = 0; int tmod = 0; // find the largest buy modifier foreach (Traveller.World.stTrade tc in this.world.TradeClass) { cargo.origCode += tc.code + " "; foreach (string bm in buymods) { if (bm.StartsWith(tc.code)) // matching trade code { if (bm[2] == '+') { int.TryParse(bm[3].ToString(), out tmod); if (tmod > buyMax) buyMax = tmod; } } } } mods += buyMax; // if we're using the expanded trade tables, we'll need to replace // the description, base cost & tonnage if (this.useExpandedTradeTables) { List<string> myGoods = new List<string>(); // 1st find the matching cargo foreach (string expanded in expandedGoods) { string[] exp = expanded.Split(new char[] { ',' }); if (exp[0] == lot[0]) { myGoods.Add(expanded); } } // myGoods now has the list of expanded items; roll 2d6 and get the appropriate range // assuming we've actually found anything if (myGoods.Count > 0) { int myroll = util.rollDx(6); myroll += util.rollDx(6); foreach (string exp in myGoods) { string[] good = exp.Split(new char[] { ',' }); int low = 0; int high = 0; int.TryParse(good[1], out low); int.TryParse(good[2], out high); if (myroll >= low & myroll <= high) { cargo.desc = good[3]; // tonnage int baseDie = 0; int mult = 0; int tonnage = 0; string[] sTonnage = good[4].Split(new char[] {'*'}); int.TryParse(sTonnage[0], out baseDie); int.TryParse(sTonnage[1], out mult); for (int i = 0; i < baseDie; i++) { tonnage += util.rollDx(6); } tonnage *= mult; if (tonnage > 0) cargo.dtons = tonnage; // base cost int myBase = cargo.basecostbuy; int.TryParse(good[5], out myBase); if (myBase > 0) cargo.basecostbuy = myBase; break; } } } } // and now roll on our actual value buy table; // this table allows for -1, so -1 = 0 position, 0 = 1 position; so we add 1 to compensate int roll = util.rollDx(6) + util.rollDx(6) + util.rollDx(6) + mods + 1; string[] av = avTable[roll].Split(new char[] { ',' }); cargo.avBuy = Convert.ToDouble(av[1]); cargo.purchasePrice = (int)((double)cargo.basecostbuy * (double)cargo.dtons * cargo.avBuy); // and finalize our origCode cargo.origCode += "Cr" + cargo.basecostbuy.ToString(); return cargo; }
/// <summary> /// T5 trade process /// </summary> private Traveller.Starship.cargoDesc T5Trade() { Traveller.Starship.cargoDesc cargo = new Starship.cargoDesc(); cargo.basecostbuy = 3000; int tcMod = 0; // trade class mod in final price/tonnage // trade code adjustments foreach (Traveller.World.stTrade tc in this.world.TradeClass) { cargo.basecostbuy += tc.buymod; if (tc.buymod != 0) tcMod++; } // TL mod adjustments int TLmod = 100 * util.HexToInt(this.world.TechLevel.ToString()); cargo.basecostbuy += TLmod; // generate our code StringBuilder sCargo = new StringBuilder(world.TechLevel + " -"); foreach (Traveller.World.stTrade tc in this.world.TradeClass) { sCargo.Append(" " + tc.code); } // and the base cost sCargo.Append(" Cr" + cargo.basecostbuy.ToString()); cargo.origCode = sCargo.ToString(); // see if we can find a random cargo based on trade classicification cargo.desc = this.findCargo(world.TradeClass); // and the tonnage: (flux + pop) x (total TCs + 1) / mod = liason cargo.dtons = (util.flux() + util.HexToInt(world.Population.ToString()) * ++tcMod); // and our actual cost cargo.purchasePrice = cargo.basecostbuy * cargo.dtons; cargo.origSEC = world.SEC; return cargo; }
/// <summary> /// Classic Traveller trade - find a cargo /// </summary> private Traveller.Starship.cargoDesc CTTrade() { Traveller.Starship.cargoDesc cargo = new Starship.cargoDesc(); // 1. roll d66 // 1a. modifier on d1: pop >= 9, +1; pop <=5, -1 // 1b (<1 = 1, > 6 = 6) // 2. find cargo // 3. determine quantity // 4. determine base cost int d1 = util.rollDx(6); int d2 = util.rollDx(6); int pop = util.HexToInt(this.world.Population.ToString()); if (pop >= 9) { d1 += 1; if (d1 > 6) d1 = 6; } if (pop <= 5) { d1 -= 1; if (d1 <= 0) d1 = 1; } string d66 = d1.ToString() + d2.ToString(); // find this item in our table string[] cargos = File.ReadAllLines("CTGoods.csv"); List<string> actualValue = util.loadCSV("CTValue.CSV"); foreach (string line in cargos) { string[] lot = line.Split(new char[] { ',' }); if (d66 == lot[0]) // found it! { cargo.desc = lot[1]; // cargo description cargo.basecostbuy = Convert.ToInt32(lot[2]); // base cost before mods cargo.basecostsell = cargo.basecostbuy; // same price point in CT cargo.origCode = this.world.TechLevel.ToString() + " - "; foreach (Traveller.World.stTrade tc in this.world.TradeClass) { cargo.origCode += tc.code + " "; } // now figure the price mods for the roll int mods = 0; string[] tccodes = new string[] { "Ag", "Na", "In", "Ni", "Ri", "Po" }; for (int i = 4; i <= 9; i++) { foreach (Traveller.World.stTrade tc in world.TradeClass) { if (tc.code == tccodes[i - 4]) { int tMod = 0; int.TryParse(lot[i], out tMod); mods += tMod; } } } // roll on the actual value table (-2 for 0=based table) int roll = util.rollDx(6) + util.rollDx(6) + ship.TradeDM - 2; string[] av = actualValue[roll].Split(new char[] { ',' }); cargo.avBuy = Convert.ToDouble(av[1]); cargo.purchasePrice = (int)((double)cargo.basecostbuy * cargo.avBuy); cargo.origCode += " Cr" + cargo.purchasePrice.ToString(); // and out quantity string[] qty = lot[3].Split(new char[] { 'D', 'd', 'x' }); int dice = Convert.ToInt32(qty[0]); for (int i = 0; i < dice; i++) { cargo.dtons += util.rollDx(6); } int multiplier = Convert.ToInt32(qty[2]); cargo.dtons *= multiplier; // and our final purchase price cargo.purchasePrice *= cargo.dtons; break; } } return cargo; }