add tank wagon rail vehicle

Dieser Commit ist enthalten in:
Reinder Feenstra 2023-03-06 23:53:07 +01:00
Ursprung 6e03b67a08
Commit a60b4e2883
10 geänderte Dateien mit 170 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -96,6 +96,8 @@ namespace DisplayName
{
namespace Rail
{
constexpr std::string_view cargoCapacity = "vehicle.rail:cargo_capacity";
constexpr std::string_view cargoLoaded = "vehicle.rail:cargo_loaded";
constexpr std::string_view lob = "vehicle.rail:lob";
constexpr std::string_view speedMax = "vehicle.rail:speed_max";
constexpr std::string_view decoder = "vehicle.rail:decoder";

Datei anzeigen

@ -23,6 +23,7 @@
#include "freightcar.hpp"
#include "../../world/world.hpp"
#include "../../core/attributes.hpp"
#include "../../utils/displayname.hpp"
FreightCar::FreightCar(World& world, std::string_view _id)
: UnpoweredRailVehicle(world, _id)
@ -49,12 +50,14 @@ FreightCar::FreightCar(World& world, std::string_view _id)
{
const bool editable = contains(m_world.state.value(), WorldState::Edit);
Attributes::addDisplayName(cargoLoaded, DisplayName::Vehicle::Rail::cargoLoaded);
Attributes::addMinMax(cargoLoaded, 0., 100., RatioUnit::Percent);
m_interfaceItems.insertBefore(cargoLoaded, totalWeight);
Attributes::addMinMax(cargoWeight, 0., 0., WeightUnit::Ton);
m_interfaceItems.insertBefore(cargoWeight, totalWeight);
Attributes::addDisplayName(cargoCapacity, DisplayName::Vehicle::Rail::cargoCapacity);
Attributes::addEnabled(cargoCapacity, editable);
m_interfaceItems.insertBefore(cargoCapacity, totalWeight);
}

Datei anzeigen

@ -31,5 +31,7 @@ std::shared_ptr<RailVehicle> RailVehicles::create(World& world, std::string_view
return MultipleUnit::create(world, id);
if(classId == FreightCar::classId)
return FreightCar::create(world, id);
if(classId == TankWagon::classId)
return TankWagon::create(world, id);
return std::shared_ptr<RailVehicle>();
}

Datei anzeigen

@ -29,6 +29,7 @@
#include "locomotive.hpp"
#include "multipleunit.hpp"
#include "freightcar.hpp"
#include "tankwagon.hpp"
struct RailVehicles
{
@ -37,7 +38,8 @@ struct RailVehicles
static constexpr auto classList = makeArray(
Locomotive::classId,
MultipleUnit::classId,
FreightCar::classId
FreightCar::classId,
TankWagon::classId
);
static std::shared_ptr<RailVehicle> create(World& world, std::string_view classId, std::string_view id);

Datei anzeigen

@ -0,0 +1,93 @@
/**
* server/src/vehicle/rail/tankwagon.cpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2023 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "tankwagon.hpp"
#include "../../world/world.hpp"
#include "../../core/attributes.hpp"
#include "../../utils/displayname.hpp"
TankWagon::TankWagon(World& world, std::string_view _id)
: UnpoweredRailVehicle(world, _id)
, cargoLoaded{*this, "cargo_loaded", 0, RatioUnit::Percent, PropertyFlags::ReadWrite | PropertyFlags::NoStore,
[this](double value, RatioUnit unit)
{
const double ratio = std::clamp(convertUnit(value, unit, RatioUnit::Ratio), 0., 1.);
cargoVolume.setValue(ratio * cargoCapacity.getValue(cargoVolume.unit()));
}}
, cargoVolume{*this, "cargo_volume", 0, VolumeUnit::CubicMeter, PropertyFlags::ReadWrite | PropertyFlags::StoreState,
[this](double /*value*/, VolumeUnit /*unit*/)
{
updateCargoLoaded();
updateTotalWeight();
}}
, cargoCapacity{*this, "cargo_capacity", 0, VolumeUnit::CubicMeter, PropertyFlags::ReadWrite | PropertyFlags::Store,
[this](double value, VolumeUnit unit)
{
Attributes::setMax(cargoVolume, value, unit);
if(cargoVolume.getValue(unit) > value)
cargoVolume.setValue(convertUnit(value, unit, cargoVolume.unit()));
updateCargoLoaded();
}}
{
const bool editable = contains(m_world.state.value(), WorldState::Edit);
Attributes::addDisplayName(cargoLoaded, DisplayName::Vehicle::Rail::cargoLoaded);
Attributes::addMinMax(cargoLoaded, 0., 100., RatioUnit::Percent);
m_interfaceItems.insertBefore(cargoLoaded, totalWeight);
Attributes::addMinMax(cargoVolume, 0., 0., VolumeUnit::CubicMeter);
m_interfaceItems.insertBefore(cargoVolume, totalWeight);
Attributes::addDisplayName(cargoCapacity, DisplayName::Vehicle::Rail::cargoCapacity);
Attributes::addEnabled(cargoCapacity, editable);
m_interfaceItems.insertBefore(cargoCapacity, totalWeight);
}
double TankWagon::calcTotalWeight(WeightUnit unit) const
{
return RailVehicle::calcTotalWeight(unit) + convertUnit(cargoVolume.getValue(VolumeUnit::CubicMeter) * cargoDensity, WeightUnit::KiloGram, unit);
}
void TankWagon::loaded()
{
UnpoweredRailVehicle::loaded();
updateCargoLoaded();
Attributes::setMax(cargoVolume, cargoCapacity.value(), cargoCapacity.unit());
}
void TankWagon::worldEvent(WorldState state, WorldEvent event)
{
UnpoweredRailVehicle::worldEvent(state, event);
const bool editable = contains(state, WorldState::Edit);
Attributes::setEnabled(cargoCapacity, editable);
}
void TankWagon::updateCargoLoaded()
{
const double capacity = cargoCapacity.getValue(VolumeUnit::CubicMeter);
if(capacity > 0)
cargoLoaded.setValueInternal(convertUnit(cargoVolume.getValue(VolumeUnit::CubicMeter) / capacity, RatioUnit::Ratio, cargoLoaded.unit()));
else
cargoLoaded.setValueInternal(0);
}

Datei anzeigen

@ -0,0 +1,53 @@
/**
* server/src/vehicle/rail/tankwagon.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2023 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TRAINTASTIC_SERVER_VEHICLE_RAIL_TANKWAGON_HPP
#define TRAINTASTIC_SERVER_VEHICLE_RAIL_TANKWAGON_HPP
#include "unpoweredrailvehicle.hpp"
#include "../../core/ratioproperty.hpp"
#include "../../core/volumeproperty.hpp"
class TankWagon : public UnpoweredRailVehicle
{
private:
void updateCargoLoaded();
protected:
void loaded() override;
void worldEvent(WorldState state, WorldEvent event) final;
double calcTotalWeight(WeightUnit unit) const override;
public:
CLASS_ID("vehicle.rail.tank_wagon")
CREATE(TankWagon)
static constexpr double cargoDensity = 1000; //!< in kg/m3 \todo change to property
RatioProperty cargoLoaded;
VolumeProperty cargoVolume;
VolumeProperty cargoCapacity;
TankWagon(World& world, std::string_view _id);
};
#endif

Datei anzeigen

@ -607,10 +607,10 @@ turnout_position:left=Links
turnout_position:right=Recht
turnout_position:straight=Gerade
#vehicle.rail.freight_car:cargo_capacity=Cargo capacity
#vehicle.rail.freight_car:cargo_loaded=Cargo loaded
#vehicle.rail.freight_car:cargo_weight=Cargo weight
#vehicle.rail:cargo_capacity=Cargo capacity
#vehicle.rail:cargo_loaded=Cargo loaded
#vehicle.rail:decoder=Decoder
#vehicle.rail:lob=LOB
vehicle.rail:speed_max=Maximale Geschwindigkeit

Datei anzeigen

@ -72,6 +72,8 @@ class_id:interface.xpressnet=XpressNet
class_id:interface.z21=Z21
class_id:vehicle.rail.freight_car=Freight car
class_id:vehicle.rail.locomotive=Locomotive
class_id:vehicle.rail.multiple_unit=Multiple unit
class_id:vehicle.rail.tank_wagon=Tank wagon
clock:day=Day
clock:debug_log=Debug log
@ -228,6 +230,8 @@ length_unit:m=m
length_unit:mm=mm
length_unit:yd=yd
list.train_vehicle:reverse=Reverse
list:add=Add
list:create=Create
list:delete=Delete
@ -236,8 +240,6 @@ list:move_down=Move down
list:move_up=Move up
list:remove=Remove
list.train_vehicle:reverse=Reverse
lncv_programmer:description=Description
lncv_programmer:lncv_programmer=LNCV programmer
lncv_programmer:module=Module
@ -600,10 +602,12 @@ turnout_position:left=Left
turnout_position:right=Right
turnout_position:straight=Straight
vehicle.rail.freight_car:cargo_capacity=Cargo capacity
vehicle.rail.freight_car:cargo_loaded=Cargo loaded
vehicle.rail.freight_car:cargo_weight=Cargo weight
vehicle.rail.tank_wagon:cargo_volume=Cargo volume
vehicle.rail:cargo_capacity=Cargo capacity
vehicle.rail:cargo_loaded=Cargo loaded
vehicle.rail:decoder=Decoder
vehicle.rail:lob=LOB
vehicle.rail:speed_max=Maximum speed

Datei anzeigen

@ -595,10 +595,10 @@ turnout_position:left=Sinistra
turnout_position:right=Destra
turnout_position:straight=Corretto tracciato
vehicle.rail.freight_car:cargo_capacity=Capacità di carico
vehicle.rail.freight_car:cargo_loaded=Carico presente
vehicle.rail.freight_car:cargo_weight=Peso del carico
vehicle.rail:cargo_capacity=Capacità di carico
vehicle.rail:cargo_loaded=Carico presente
vehicle.rail:decoder=Decoder
vehicle.rail:lob=Lunghezza veicolo
vehicle.rail:speed_max=Velocità massima

Datei anzeigen

@ -593,10 +593,10 @@ turnout_position:left=Links
turnout_position:right=Rechts
turnout_position:straight=Rechtdoor
#vehicle.rail.freight_car:cargo_capacity=Cargo capacity
#vehicle.rail.freight_car:cargo_loaded=Cargo loaded
vehicle.rail.freight_car:cargo_weight=Gewicht lading
#vehicle.rail:cargo_capacity=Cargo capacity
#vehicle.rail:cargo_loaded=Cargo loaded
vehicle.rail:decoder=Decoder
vehicle.rail:lob=LOB
vehicle.rail:speed_max=Maximale snelheid