public FormCargoSell(int item, int maxAmount, CargoSellOp op, int price)
        {
            InitializeComponent();

            Commander cmdr = game.Commander;
            int       cost = cmdr.PriceCargo[item] / cmdr.Ship.Cargo[item];

            numAmount.Maximum = maxAmount;
            numAmount.Value   = numAmount.Minimum;
            this.Text         = Functions.StringVars(Strings.CargoTitle, Strings.CargoSellOps[(int)op],
                                                     Consts.TradeItems[item].Name);
            lblQuestion.Text = Functions.StringVars(Strings.CargoSellQuestion, Strings.CargoSellOps[(int)op].ToLower());
            lblPaid.Text     = Functions.StringVars(op == CargoSellOp.SellTrader ? Strings.CargoSellPaidTrader :
                                                    Strings.CargoSellPaid, Functions.FormatMoney(cost),
                                                    Functions.Multiples(maxAmount, Strings.CargoUnit));
            lblProfit.Text = Functions.StringVars(Strings.CargoSellProfit, price >= cost ? "profit" : "loss",
                                                  Functions.FormatMoney(price >= cost ? price - cost : cost - price));

            // Override defaults for some ops.
            switch (op)
            {
            case CargoSellOp.Dump:
                lblStatement.Text = Functions.StringVars(Strings.CargoSellStatementDump, Strings.CargoSellOps[(int)op].ToLower(),
                                                         Functions.FormatNumber(maxAmount));
                lblProfit.Text = Functions.StringVars(Strings.CargoSellDumpCost, Functions.FormatMoney(-price));
                break;

            case CargoSellOp.Jettison:
                lblStatement.Text = Functions.StringVars(Strings.CargoSellStatementDump, Strings.CargoSellOps[(int)op].ToLower(),
                                                         Functions.FormatNumber(maxAmount));
                break;

            case CargoSellOp.SellSystem:
                lblStatement.Text = Functions.StringVars(Strings.CargoSellStatement, Functions.FormatNumber(maxAmount),
                                                         Functions.FormatMoney(price));
                break;

            case CargoSellOp.SellTrader:
                lblStatement.Text = Functions.StringVars(Strings.CargoSellStatementTrader, Consts.TradeItems[item].Name,
                                                         Functions.FormatMoney(price));
                break;
            }
        }
		public FormCargoSell(int item, int maxAmount, CargoSellOp op, int price)
		{
			InitializeComponent();

			Commander	cmdr			= game.Commander;
			int				cost			= cmdr.PriceCargo[item] / cmdr.Ship.Cargo[item];

			numAmount.Maximum		= maxAmount;
			numAmount.Value			= numAmount.Minimum;
			this.Text						= Functions.StringVars(Strings.CargoTitle, Strings.CargoSellOps[(int)op],
														Consts.TradeItems[item].Name);
			lblQuestion.Text		= Functions.StringVars(Strings.CargoSellQuestion, Strings.CargoSellOps[(int)op].ToLower());
			lblPaid.Text				= Functions.StringVars(op == CargoSellOp.SellTrader ? Strings.CargoSellPaidTrader :
														Strings.CargoSellPaid, Functions.FormatMoney(cost),
														Functions.Multiples(maxAmount, Strings.CargoUnit));
			lblProfit.Text			= Functions.StringVars(Strings.CargoSellProfit, price >= cost ? "profit" : "loss",
														Functions.FormatMoney(price >= cost ? price - cost : cost - price));

			// Override defaults for some ops.
			switch (op)
			{
				case CargoSellOp.Dump:
					lblStatement.Text	= Functions.StringVars(Strings.CargoSellStatementDump, Strings.CargoSellOps[(int)op].ToLower(),
															Functions.FormatNumber(maxAmount));
					lblProfit.Text		= Functions.StringVars(Strings.CargoSellDumpCost, Functions.FormatMoney(-price));
					break;
				case CargoSellOp.Jettison:
					lblStatement.Text	= Functions.StringVars(Strings.CargoSellStatementDump, Strings.CargoSellOps[(int)op].ToLower(),
															Functions.FormatNumber(maxAmount));
					break;
				case CargoSellOp.SellSystem:
					lblStatement.Text	= Functions.StringVars(Strings.CargoSellStatement, Functions.FormatNumber(maxAmount),
															Functions.FormatMoney(price));
					break;
				case CargoSellOp.SellTrader:
					lblStatement.Text	= Functions.StringVars(Strings.CargoSellStatementTrader, Consts.TradeItems[item].Name,
															Functions.FormatMoney(price));
					break;
			}
		}
Example #3
0
		private void CargoSell(int tradeItem, bool all, IWin32Window owner, CargoSellOp op)
		{
			int qtyInHand = Commander.Ship.Cargo[tradeItem];
			int unitPrice;
			switch (op)
			{
				case CargoSellOp.SellSystem:
					unitPrice = PriceCargoSell[tradeItem];
					break;
				case CargoSellOp.SellTrader:
					TradeItem item = Consts.TradeItems[tradeItem];
					int chance = item.Illegal ? 45 : 10;
					double adj = Functions.GetRandom(100) < chance ? (item.Illegal ? 0.8 : 0.9) : 1.1;
					unitPrice = Math.Min(item.MaxTradePrice, Math.Max(item.MinTradePrice,
						(int)Math.Round(PriceCargoSell[tradeItem] * adj / item.RoundOff) * item.RoundOff));
					break;
				default:
					unitPrice = 0;
					break;
			}

			if (qtyInHand == 0)
				FormAlert.Alert(AlertType.CargoNoneToSell, owner, Strings.CargoSellOps[(int)op]);
			else if (op == CargoSellOp.SellSystem && unitPrice <= 0)
				FormAlert.Alert(AlertType.CargoNotInterested, owner);
			else
			{
				if (op != CargoSellOp.Jettison || LitterWarning ||
					Commander.PoliceRecordScore <= Consts.PoliceRecordScoreDubious ||
					FormAlert.Alert(AlertType.EncounterDumpWarning, owner) == DialogResult.Yes)
				{
					int unitCost = 0;
					int maxAmount = (op == CargoSellOp.SellTrader) ? Math.Min(qtyInHand, Opponent.FreeCargoBays) : qtyInHand;
					if (op == CargoSellOp.Dump)
					{
						unitCost = 5 * ((int)Difficulty + 1);
						maxAmount = Math.Min(maxAmount, Commander.CashToSpend / unitCost);
					}
					int price = unitPrice > 0 ? unitPrice : -unitCost;

					int qty = 0;
					if (all)
						qty = maxAmount;
					else
					{
						FormCargoSell form = new FormCargoSell(tradeItem, maxAmount, op, price);
						if (form.ShowDialog(owner) == DialogResult.OK)
							qty = form.Amount;
					}

					if (qty > 0)
					{
						int totalPrice = qty * price;

						Commander.Ship.Cargo[tradeItem] -= qty;
						Commander.PriceCargo[tradeItem] = (Commander.PriceCargo[tradeItem] * (qtyInHand - qty)) / qtyInHand;
						Commander.Cash += totalPrice;

						if (op == CargoSellOp.Jettison)
						{
							if (Functions.GetRandom(10) < (int)Difficulty + 1)
							{
								if (Commander.PoliceRecordScore > Consts.PoliceRecordScoreDubious)
									Commander.PoliceRecordScore = Consts.PoliceRecordScoreDubious;
								else
									Commander.PoliceRecordScore--;

								NewsAddEvent(NewsEvent.CaughtLittering);
							}
						}
					}
				}
			}
		}