public void LargeSetOfContainers_ShouldBeDividedWithinLimits() { // Arrange CargoShip ship = new CargoShip(4, 3, 4000); List <Container> containers = new List <Container>() { new Container(225, ContainerType.Normal), new Container(50, ContainerType.Normal), new Container(150, ContainerType.Coolable), new Container(100, ContainerType.Normal), new Container(100, ContainerType.Normal), new Container(175, ContainerType.Valuable), new Container(150, ContainerType.Normal), new Container(100, ContainerType.ValuableAndCoolable), new Container(100, ContainerType.Normal), new Container(100, ContainerType.Valuable), new Container(100, ContainerType.Normal), new Container(375, ContainerType.Normal), new Container(50, ContainerType.Valuable), new Container(100, ContainerType.Coolable), new Container(150, ContainerType.ValuableAndCoolable), new Container(100, ContainerType.Normal), new Container(250, ContainerType.Normal), new Container(300, ContainerType.Valuable), new Container(100, ContainerType.Normal), new Container(275, ContainerType.Coolable) }; // Act ship.Divide(containers); double leftWeightRatio = ship.GetLeftWeightRatio(); // Assert Assert.AreEqual(0.5d, leftWeightRatio, 0.2d); }
private void Btn_Algorithm_Click(object sender, EventArgs e) { if (Lbx_CargoShips.SelectedIndex != -1) { double totalWeightContainers = _dock.AllContainers.Sum(item => item.Weight); if (totalWeightContainers >= _cargoShip.MaximumCarryWeight / 2) { _cargoShip = Lbx_CargoShips.SelectedItem as CargoShip; _dock.ActivateAlgorithm(_cargoShip); UpdateCargoShipStats(); CalcProcentWeightFilled(); RefreshListsCargoShip(); RefreshAllContainers(); ShowStackInfo(); } else { MessageBox.Show("Not Enough weight in Containers, or CargoShip to Big for the load!" + Environment.NewLine + "Total weight Containers: " + totalWeightContainers + " Needed: " + _cargoShip.MaximumCarryWeight / 2); } } else { MessageBox.Show("Select a CargoShip!"); } }
void OnEntitySpawned(BaseEntity Entity) { if (!initialized) { return; } if (Entity == null) { return; } if (Entity is CargoShip) { CargoShip cargoShip = (CargoShip)Entity; if (!IsInLivableArea(cargoShip.transform.position)) { Log($"CargoShip spawned out liveable area", logType: LogType.WARNING); Log($"{cargoShip.transform.position.x}|{cargoShip.transform.position.y}|{cargoShip.transform.position.z}", logType: LogType.WARNING); timer.Once(1f, () => { cargoShip.Kill(); }); Vector3 newPostition = GetFixedPosition(cargoShip.transform.position); timer.Once(2f, () => { SpawnCargoShip(newPostition); }); } else { Log($"CargoShip spawned in liveable area properly", logType: LogType.INFO); Log($"{cargoShip.transform.position.x}|{cargoShip.transform.position.y}|{cargoShip.transform.position.z}", logType: LogType.INFO); } } }
public void TestSpaceshipTaxCalculatorCalculateMethodForCargoShip() { Spaceship cargoShip = new CargoShip(yearOfPurchase: 2332, milesTraveled: 344789); taxCalculator = new SpaceshipTax(cargoShip); Assert.AreEqual(expected: 326768.00, taxCalculator.Calculate(yearOfCalculation: 2369)); }
private void btnResult_Click(object sender, EventArgs e) { //Запись имени кораблей из текстбокса string Name1 = txtName1.Text; string Name2 = txtName2.Text; //Запись грузоподъемности из текстбокса int Weight1 = Convert.ToInt32(txtWeight1.Text); int Weight2 = Convert.ToInt32(txtWeight2.Text); //Конструктор CargoShip cs1 = new CargoShip(Name1, Weight1); CargoShip cs2 = new CargoShip(Name2, Weight2); //Показ информации о кораблях MessageBox.Show(cs1.ShowInfo()); MessageBox.Show(cs2.ShowInfo()); //Сравнение кораблей int comprez = cs1.CompareTo(cs2); if (comprez == -1) { MessageBox.Show("Грузоподъемность первого корабля больше второго"); } if (comprez == 1) { MessageBox.Show("Грузоподъемность второго корабля больше первого"); } if (comprez == 0) { MessageBox.Show("Грузоподъемность равная"); } }
public void TestVehicleConstructorWithInvalidMiles() { yearOfPurchase = 2000; milesTraveled = -2; Spaceship cargoShip; Assert.Throws <ArgumentException>(() => cargoShip = new CargoShip(yearOfPurchase, milesTraveled)); }
void LogCurrentPosition(CargoShip cargoShip) { if (cargoShip == null || cargoShip.IsDestroyed) { return; } Log($"Current position: {cargoShip.transform.position.x}|{cargoShip.transform.position.y}|{cargoShip.transform.position.z} ", logType: LogType.INFO); }
public static CargoShipDto Create(CargoShip cargoShip) { return(new CargoShipDto { GoodType = cargoShip.GoodType, Capacity = cargoShip.Capacity, GoodCount = cargoShip.GoodCount, }); }
public void TestVehicleConstructorWIthCorrectInput() { yearOfPurchase = 2022; milesTraveled = 2000; Spaceship cargoShip = new CargoShip(yearOfPurchase, milesTraveled); Assert.AreEqual(cargoShip.MilesTraveled, milesTraveled); Assert.AreEqual(cargoShip.YearOfPurchase, yearOfPurchase); }
private void Btn_AddCargoShip_Click(object sender, EventArgs e) { CargoShip cargoShip = new CargoShip((int)Nud_CargoShipWidth.Value, (int)Nud_CargoShipLength.Value); _dock.CargoShips.Add(cargoShip); Lbx_CargoShips.Items.Add(cargoShip); RefreshListsCargoShip(); Lbx_CargoShips.SetSelected(Lbx_CargoShips.Items.Count - 1, true); ShowStackInfo(); }
static void Main(string[] args) { Console.WriteLine("(this is one row on the ship)"); Console.WriteLine("stacked, values, here"); Console.WriteLine("each, one, is, a, column"); Console.WriteLine("bottom, to, top"); Console.WriteLine(); List <Container> containers = new List <Container>() { new Container(346, ContainerType.Normal), new Container(873, ContainerType.Normal), new Container(182, ContainerType.Normal), new Container(784, ContainerType.Normal), new Container(505, ContainerType.Normal), new Container(133, ContainerType.Normal), new Container(126, ContainerType.Coolable), new Container(173, ContainerType.Coolable), new Container(284, ContainerType.Valuable), new Container(183, ContainerType.Valuable), new Container(177, ContainerType.Valuable), new Container(185, ContainerType.Valuable), new Container(137, ContainerType.Valuable), new Container(190, ContainerType.ValuableAndCoolable), new Container(168, ContainerType.Valuable), new Container(302, ContainerType.ValuableAndCoolable), new Container(547, ContainerType.Normal), new Container(284, ContainerType.Normal), new Container(273, ContainerType.Normal), new Container(941, ContainerType.Normal), new Container(725, ContainerType.Normal), new Container(825, ContainerType.Normal), new Container(477, ContainerType.Coolable), new Container(168, ContainerType.Coolable), new Container(294, ContainerType.Valuable), new Container(624, ContainerType.Valuable), new Container(157, ContainerType.Valuable), new Container(345, ContainerType.ValuableAndCoolable) }; CargoShip ship = new CargoShip(5, 7, containers.Sum(c => c.Weight)); try { ContainerRow[] rows = ship.Divide(containers); for (int i = 0; i < rows.Length; i++) { Console.WriteLine($"----------- {i}:"); Console.Write(rows[i].ToString()); } Console.WriteLine("\n\n" + GetTotalWeightString(rows)); } catch (Exception e) { Console.WriteLine(e.Message); } }
private bool CanShowPanel(CargoShip cargo) { object result = Interface.Call("MagicPanelCanShow", Name, cargo); if (result is bool) { return((bool)result); } return(true); }
public void HasCargoShipHaveEnoughWeightToPreventCapsizing() { // Arange CargoShip cargoShip = new CargoShip(3, 1); double totalWeightContainers = _dock.AllContainers.Sum(item => item.Weight); // Act bool cargoHasEnoughWeight = totalWeightContainers >= cargoShip.MaximumCarryWeight / 2; // Assert Assert.IsTrue(cargoHasEnoughWeight); }
public void CargoShipContents_TooMuchWeight() { // Arrange CargoShip ship = new CargoShip(1, 1, 100); List <Container> containers = new List <Container>() { new Container(1000, ContainerType.Normal) }; // Act, Assert Assert.ThrowsException <Exception>(() => ship.Divide(containers)); }
public void CargoShipContents_UnbalancedWeight() { // Arrange CargoShip ship = new CargoShip(1, 1, 200); List <Container> containers = new List <Container>() { new Container(75, ContainerType.Normal), new Container(25, ContainerType.Normal) }; // Act, Assert Assert.ThrowsException <Exception>(() => ship.Divide(containers)); }
public void ValuableContainer_ShouldThrow_BecauseNotEnoughSpace() { // Arrange CargoShip ship = new CargoShip(3, 1, 100); Container valuableContainer = new Container(30, ContainerType.Valuable); List <Container> containers = new List <Container>() { valuableContainer, valuableContainer, valuableContainer }; // Act, Assert Assert.ThrowsException <Exception>(() => ship.Divide(containers)); }
private void OnEntitySpawned(CargoShip ship) { NextTick(() => { if (!CanShowPanel(ship)) { return; } _activeCargoShips.Add(ship); CheckCargoShip(); }); }
public void ValuableContainer_ShouldDivide_BecauseCoolableMayBeStacked() { // Arrange CargoShip ship = new CargoShip(3, 1, 100); Container coolableContainer = new Container(30, ContainerType.Coolable); List <Container> containers = new List <Container>() { coolableContainer, coolableContainer, coolableContainer }; // Act ContainerRow[] rows = ship.Divide(containers); // Assert Assert.IsTrue(rows[0].GetTotalContainers() == 3); }
public void CoolableContainer_ShouldBeInFront() { // Arrange CargoShip ship = new CargoShip(3, 1, 100); Container coolableContainer = new Container(30, ContainerType.Coolable); Container normalContainer = new Container(30, ContainerType.Normal); List <Container> containers = new List <Container>() { normalContainer, normalContainer, coolableContainer }; // Act ContainerRow[] rows = ship.Divide(containers); // Assert Assert.IsTrue(rows[0][0][0].Type == ContainerType.Coolable); }
void OnEntitySpawned(CargoShip ship) { if (!configData.alerts.cargoShip) { return; } NextTick(() => { if (ship == null) { return; } SendMsg(Lang("CargoShip", null, GetLocation(ship.transform.position, null, null))); }); }
public void SmallSetOfContainers_ShouldBeDividedWithinLimits() { // Arrange CargoShip ship = new CargoShip(2, 2, 120); List <Container> containers = new List <Container>() { new Container(30, ContainerType.Normal), new Container(30, ContainerType.Normal), new Container(30, ContainerType.Normal), new Container(30, ContainerType.Normal) }; // Act ship.Divide(containers); double leftWeightRatio = ship.GetLeftWeightRatio(); // Assert Assert.AreEqual(0.5d, leftWeightRatio, 0.2d); }
private void RefreshListsCargoShip() { Lbx_StackContainers.Items.Clear(); if (Lbx_CargoShips.SelectedIndex != -1) { if (DGV_Stacks.DataSource != null) { DGV_Stacks.DataSource = null; } _cargoShip = Lbx_CargoShips.SelectedItem as CargoShip; DataTable dt = new DataTable(); DGV_Stacks.DataSource = dt; for (int j = 0; j < _cargoShip.Width; j++) { dt.Columns.Add("Column: " + j); } int counter = 0; for (int currentRow = 0; currentRow < _cargoShip.Length; currentRow++) { DataRow dr = dt.NewRow(); for (int currentColumn = 0; currentColumn < _cargoShip.Width; currentColumn++) { int amountContainers = 0; if (_cargoShip.Stacks[counter].Containers != null) { amountContainers = _cargoShip.Stacks[counter].Containers.Count; } int stackId = _cargoShip.Stacks[counter].StackID; Stack stock = _cargoShip.FindStackWithId(stackId); stock.CalcStackWeight(); Lbl_StackWeight.Text = "Stack Weight: " + stock.StackWeight; dr[currentColumn] = stackId + "; Cont:" + amountContainers + " Cool:" + stock.HasCooling; counter++; } dt.Rows.Add(dr); } } }
public void CountStacksEqualCargoShipMeasures() { // Arange CargoShip cargoShip = new CargoShip(3, 1); List <Stack> stacks = new List <Stack>() { new Stack(0, 0, BalansPosition.Left), new Stack(0, 1, BalansPosition.Middle), new Stack(0, 2, BalansPosition.Right) }; cargoShip.Stacks = stacks; int cargoShipStacks = cargoShip.Width * cargoShip.Length; //cargoShip.WeightLeftSide; int innerStacks = cargoShip.Stacks.Count; //cargoShip.WeightRightSide; // Act bool amountStacksMatch = cargoShipStacks == innerStacks; // Assert Assert.IsTrue(amountStacksMatch); }
public void IsCargoShipWeightDistributionBalanced() { // Arange CargoShip cargoShip = new CargoShip(3, 1); int leftWeight = 100; //cargoShip.WeightLeftSide; int rightWeight = 110; //cargoShip.WeightRightSide; bool isBallenced; // Act int difference = cargoShip.ProcentDifferenceSides(leftWeight, rightWeight); if (difference > 20 || difference < -20) { isBallenced = false; } else { isBallenced = true; } // Assert Assert.IsTrue(isBallenced); }
void OnEntitySpawned(CargoShip ship) { if (!configData.Alerts.CargoShip) { return; } if (ship == null) { return; } var pos = ship.transform.position; string msg = Lang("CargoShip", null, GetLocation(pos, null, null)); Server.Broadcast(msg); if (configData.Misc.LogToConsole) { Puts(msg); } if (configData.Misc.LogToFile) { LogToFile("log", $"[{DateTime.Now.ToString("HH:mm:ss")}] {msg}", this); } }
void OnEntitySpawned(CargoShip ship) { if (ship == null) { return; } // disable egress timer.In(5f, () => { ship.CancelInvoke(new Action(ship.StartEgress)); }); // start egress when safe timer.In((CargoShip.event_duration_minutes * 60f), () => { checker?.Destroy(); checker = timer.Every(1f, () => { if (safePos(ship.transform.position)) { ship.Invoke(new Action(ship.StartEgress), 1f); checker?.Destroy(); } }); }); }
private void Btn_AddContainerToStack_Click(object sender, EventArgs e) { if (Lbx_CargoShips.SelectedIndex != -1 && Lbx_Containers.SelectedIndex != -1) { Lbx_StackContainers.Items.Clear(); int stackId = Convert.ToInt32(DGV_Stacks.CurrentCell.Value.ToString().Split(';')[0]); _cargoShip = Lbx_CargoShips.SelectedItem as CargoShip; Stack selectedStack = _cargoShip.FindStackWithId(stackId); Container selectedContainer = Lbx_Containers.SelectedItem as Container; if (selectedStack.CanContainerBeAddedToStack()) { selectedStack.AddContainer(selectedContainer); } else { MessageBox.Show("Can't add the container to this stack"); } foreach (var conto in selectedStack.Containers) { Lbx_StackContainers.Items.Add(conto); } _dock.AllContainers.Remove(Lbx_Containers.SelectedItems[0] as Container); Lbx_Containers.Items.Remove(Lbx_Containers.SelectedItems[0]); UpdateCargoShipStats(); RefreshListsCargoShip(); ShowStackInfo(); } else { MessageBox.Show("Select a CargoShip and a Container!"); } }
private void CheckPlayerCanLoadToShip(IPlayer player, IReadOnlyCollection <IGood> goods, CargoShip cargoShip) { var goodType = goods.First().Type; if (!cargoShip.CanBeLoaded(goodType)) { throw new GameException($"{goodType} cannot be loaded to ship with capacity {cargoShip.Capacity}"); } var typedShip = GetCargoShipWithGoodTypeOrDefault(goodType); if (typedShip != null && typedShip != cargoShip) { throw new GameException( $"{goodType} barrels already loaded to ship with capacity {typedShip.Capacity}"); } if (typedShip == null && goods.Count > cargoShip.Capacity && Game.CargoShips.Exists(ship => ship.Capacity > cargoShip.Capacity && ship.CanBeLoaded(goodType))) { throw new GameException($"{goodType} must be loaded to a ship with more capacity"); } }
private void OnEntitySpawned(CargoShip entity) { HandleEntity(entity); }
async Task FillPorts(GalaxyManager galaxyManager, LocalIDManager galaxyIDManager, CargoSynchronizer cargoSynchronizer) { var ports = galaxyManager.GetAllAreas().Where(a => a.AreaType == AreaTypes.Port); CargoTransaction lastTransaction = null; foreach (var p in ports) { var port = p as Port; foreach (var s in _config.PortConfig.StatefulCargoCounts) { StatefulCargo sc; for (int i = 0; i < s.Value; i++)//Yes, this loop is lazy, but it's 11:30PM... { //TODO: make a StatefulCargoFactory switch (s.Key) { case StatefulCargoTypes.Barge: { sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Barge]); break; } case StatefulCargoTypes.BattleCruiser: { sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.BattleCruiser]); break; } case StatefulCargoTypes.Penguin: { sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Penguin]); break; } case StatefulCargoTypes.Reaper: { sc = new CargoShip(galaxyIDManager.PopFreeID(), 666, ShipStats[ShipTypes.Reaper]); break; } case StatefulCargoTypes.LaserTurret: { sc = new CargoLaserTurret(galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats()); break; } default: { sc = new StatefulCargo(galaxyIDManager.PopFreeID(), s.Key); break; } } CargoTransaction tr = new TransactionAddStatefulCargo(port, sc, true); cargoSynchronizer.RequestTransaction(tr); lastTransaction = tr; } } foreach (var s in _config.PortConfig.StatelessCargoCounts) { var tr = new TransactionAddStatelessCargo(port, s.Key, s.Value, true); cargoSynchronizer.RequestTransaction(tr); lastTransaction = tr; } foreach (var s in _config.PortConfig.ModuleCounts) { Module m = ModuleFactory.CreateModule(s.Key, galaxyIDManager.PopFreeID(), 1); var tr = new TransactionAddStatefulCargo(port, m, true); cargoSynchronizer.RequestTransaction(tr); lastTransaction = tr; } } if (lastTransaction != null) { await lastTransaction.ResultTask; } }