Ejemplo n.º 1
0
        public FormCargoBuy(int item, int maxAmount, CargoBuyOp op)
        {
            InitializeComponent();

            Commander cmdr = game.Commander;

            numAmount.Maximum = maxAmount;
            numAmount.Value   = numAmount.Minimum;
            this.Text         = Functions.StringVars(Strings.CargoTitle, Strings.CargoBuyOps[(int)op],
                                                     Consts.TradeItems[item].Name);
            lblQuestion.Text = Functions.StringVars(Strings.CargoBuyQuestion, Strings.CargoBuyOps[(int)op].ToLower());

            switch (op)
            {
            case CargoBuyOp.BuySystem:
                lblStatement.Text = Functions.StringVars(Strings.CargoBuyStatement,
                                                         Functions.FormatMoney(game.PriceCargoBuy[item]),
                                                         Functions.FormatNumber(maxAmount));

                this.Height = btnOk.Top + btnOk.Height + 34;
                break;

            case CargoBuyOp.BuyTrader:
                int afford = Math.Min(game.Commander.Cash / game.PriceCargoBuy[item],
                                      game.Commander.Ship.FreeCargoBays);
                if (afford < maxAmount)
                {
                    numAmount.Maximum = afford;
                }

                lblStatement.Text = Functions.StringVars(Strings.CargoBuyStatementTrader, Consts.TradeItems[item].Name,
                                                         Functions.FormatMoney(game.PriceCargoBuy[item]));
                lblAvailable.Text = Functions.StringVars(Strings.CargoBuyAvailable,
                                                         Functions.Multiples(game.Opponent.Cargo[item], Strings.CargoUnit));
                lblAfford.Text = Functions.StringVars(Strings.CargoBuyAfford, Functions.Multiples(afford,
                                                                                                  Strings.CargoUnit));

                lblAvailable.Visible = true;
                lblAfford.Visible    = true;

                btnOk.Top       += 26;
                btnAll.Top      += 26;
                btnNone.Top     += 26;
                lblQuestion.Top += 26;
                numAmount.Top   += 26;

                break;

            case CargoBuyOp.Plunder:
                lblStatement.Text = Functions.StringVars(Strings.CargoBuyStatementSteal,
                                                         Functions.FormatNumber(game.Opponent.Cargo[item]));

                this.Height = btnOk.Top + btnOk.Height + 34;
                break;
            }
        }
Ejemplo n.º 2
0
		public FormCargoBuy(int item, int maxAmount, CargoBuyOp op)
		{
			InitializeComponent();

			Commander	cmdr						= game.Commander;
			numAmount.Maximum					= maxAmount;
			numAmount.Value						= numAmount.Minimum;
			this.Text									= Functions.StringVars(Strings.CargoTitle, Strings.CargoBuyOps[(int)op],
																	Consts.TradeItems[item].Name);
			lblQuestion.Text					= Functions.StringVars(Strings.CargoBuyQuestion, Strings.CargoBuyOps[(int)op].ToLower());

			switch (op)
			{
				case CargoBuyOp.BuySystem:
					lblStatement.Text			= Functions.StringVars(Strings.CargoBuyStatement,
																	Functions.FormatMoney(game.PriceCargoBuy[item]),
																	Functions.FormatNumber(maxAmount));

					this.Height						= btnOk.Top + btnOk.Height + 34;
					break;
				case CargoBuyOp.BuyTrader:
					int afford						= Math.Min(game.Commander.Cash / game.PriceCargoBuy[item],
																	game.Commander.Ship.FreeCargoBays);
					if (afford < maxAmount)
						numAmount.Maximum	= afford;

					lblStatement.Text			= Functions.StringVars(Strings.CargoBuyStatementTrader, Consts.TradeItems[item].Name,
																	Functions.FormatMoney(game.PriceCargoBuy[item]));
					lblAvailable.Text			= Functions.StringVars(Strings.CargoBuyAvailable,
																	Functions.Multiples(game.Opponent.Cargo[item], Strings.CargoUnit));
					lblAfford.Text				= Functions.StringVars(Strings.CargoBuyAfford, Functions.Multiples(afford,
																	Strings.CargoUnit));

					lblAvailable.Visible	= true;
					lblAfford.Visible			= true;

					btnOk.Top							+= 26;
					btnAll.Top						+= 26;
					btnNone.Top						+= 26;
					lblQuestion.Top				+= 26;
					numAmount.Top					+= 26;

					break;
				case CargoBuyOp.Plunder:
					lblStatement.Text			= Functions.StringVars(Strings.CargoBuyStatementSteal,
																	Functions.FormatNumber(game.Opponent.Cargo[item]));

					this.Height						= btnOk.Top + btnOk.Height + 34;
					break;
			}
		}
Ejemplo n.º 3
0
		private void CargoBuy(int tradeItem, bool max, IWin32Window owner, CargoBuyOp op)
		{
			int freeBays = Commander.Ship.FreeCargoBays;
			int[] items = null;
			int unitPrice = 0;
			int cashToSpend = Commander.Cash;

			switch (op)
			{
				case CargoBuyOp.BuySystem:
					freeBays = Math.Max(0, Commander.Ship.FreeCargoBays - Options.LeaveEmpty);
					items = Commander.CurrentSystem.TradeItems;
					unitPrice = PriceCargoBuy[tradeItem];
					cashToSpend = Commander.CashToSpend;
					break;
				case CargoBuyOp.BuyTrader:
					items = Opponent.Cargo;
					TradeItem item = Consts.TradeItems[tradeItem];
					int chance = item.Illegal ? 45 : 10;
					double adj = Functions.GetRandom(100) < chance ? 1.1 : (item.Illegal ? 0.8 : 0.9);
					unitPrice = Math.Min(item.MaxTradePrice, Math.Max(item.MinTradePrice,
						(int)Math.Round(PriceCargoBuy[tradeItem] * adj / item.RoundOff) * item.RoundOff));
					break;
				case CargoBuyOp.Plunder:
					items = Opponent.Cargo;
					break;
			}

			if (op == CargoBuyOp.BuySystem && Commander.Debt > Consts.DebtTooLarge)
				FormAlert.Alert(AlertType.DebtTooLargeTrade, owner);
			else if (op == CargoBuyOp.BuySystem && (items[tradeItem] <= 0 || unitPrice <= 0))
				FormAlert.Alert(AlertType.CargoNoneAvailable, owner);
			else if (freeBays == 0)
				FormAlert.Alert(AlertType.CargoNoEmptyBays, owner);
			else if (op != CargoBuyOp.Plunder && cashToSpend < unitPrice)
				FormAlert.Alert(AlertType.CargoIf, owner);
			else
			{
				int qty = 0;
				int maxAmount = Math.Min(freeBays, items[tradeItem]);
				if (op == CargoBuyOp.BuySystem)
					maxAmount = Math.Min(maxAmount, Commander.CashToSpend / unitPrice);

				if (max)
					qty = maxAmount;
				else
				{
					FormCargoBuy form = new FormCargoBuy(tradeItem, maxAmount, op);
					if (form.ShowDialog(owner) == DialogResult.OK)
						qty = form.Amount;
				}

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

					Commander.Ship.Cargo[tradeItem] += qty;
					items[tradeItem] -= qty;
					Commander.Cash -= totalPrice;
					Commander.PriceCargo[tradeItem] += totalPrice;
				}
			}
		}