|
|
|
@ -40,11 +40,12 @@
|
|
|
|
|
#include "tracerestrict.h"
|
|
|
|
|
#include "train.h"
|
|
|
|
|
#include "date_func.h"
|
|
|
|
|
#include "3rdparty/nlohmann/json.hpp"
|
|
|
|
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
|
|
|
|
|
#include "3rdparty/robin_hood/robin_hood.h"
|
|
|
|
|
|
|
|
|
|
#include <3rdparty/nlohmann/json.hpp>
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
|
|
|
|
/* DestinationID must be at least as large as every these below, because it can
|
|
|
|
@ -269,6 +270,41 @@ void Order::MakeLabel(OrderLabelSubType subtype)
|
|
|
|
|
this->flags = subtype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Order::ToJSONString() const
|
|
|
|
|
{
|
|
|
|
|
std::string out;
|
|
|
|
|
nlohmann::json json;
|
|
|
|
|
json["packed-data"] = this->Pack();
|
|
|
|
|
|
|
|
|
|
json["destination-id"] = this->GetDestination();
|
|
|
|
|
|
|
|
|
|
if(this->extra.get() != nullptr){
|
|
|
|
|
auto& extraJson = json["extra"];
|
|
|
|
|
|
|
|
|
|
extraJson["cargo-type-flags"] = this->extra.get()->cargo_type_flags;
|
|
|
|
|
extraJson["colour"] = this->extra.get()->colour;
|
|
|
|
|
extraJson["dispatch-index"] = this->extra.get()->dispatch_index;
|
|
|
|
|
extraJson["xdata"] = this->extra.get()->xdata;
|
|
|
|
|
extraJson["xdata2"] = this->extra.get()->xdata2;
|
|
|
|
|
extraJson["xflags"] = this->extra.get()->xflags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
json["refit-cargo"] = this->GetRefitCargo();
|
|
|
|
|
json["wait-time"] = this->GetWaitTime();
|
|
|
|
|
json["travel-time"] = this->GetTravelTime();
|
|
|
|
|
json["max-speed"] = this->GetMaxSpeed();
|
|
|
|
|
|
|
|
|
|
out = json.dump();
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Order Order::FromJSONString(std::string)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Order newOrder;
|
|
|
|
|
return newOrder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make this depot/station order also a refit order.
|
|
|
|
|
* @param cargo the cargo type to change to.
|
|
|
|
@ -824,6 +860,97 @@ void OrderList::MoveOrder(int from, int to)
|
|
|
|
|
this->ReindexOrderList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string OrderList::ToJSONString()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
nlohmann::json json;
|
|
|
|
|
auto& SD_data = this->GetScheduledDispatchScheduleSet();
|
|
|
|
|
|
|
|
|
|
auto& headJson = json["head"];
|
|
|
|
|
for (unsigned int i = 0; auto &SD : SD_data) {
|
|
|
|
|
|
|
|
|
|
auto &SDJson = headJson["scheduled-dispatch"][i++];
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; auto &SD_slot : SD.GetScheduledDispatch()) {
|
|
|
|
|
auto& slotsJson = SDJson["slots"][i++];
|
|
|
|
|
slotsJson["offset"] = SD_slot.offset;
|
|
|
|
|
slotsJson["flags"] = SD_slot.flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDJson["name"] = SD.ScheduleName();
|
|
|
|
|
SDJson["start-tick"] = SD.GetScheduledDispatchStartTick().value;
|
|
|
|
|
SDJson["duration"] = SD.GetScheduledDispatchDuration();
|
|
|
|
|
SDJson["max-delay"] = SD.GetScheduledDispatchDelay();
|
|
|
|
|
SDJson["flags"] = SD.GetScheduledDispatchFlags();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Order* o = this->GetFirstOrder();
|
|
|
|
|
|
|
|
|
|
if (o != nullptr) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
do {
|
|
|
|
|
json["orders"][i++] = nlohmann::json::parse(o->ToJSONString());
|
|
|
|
|
} while ((o = this->GetNext(o)) != this->GetFirstOrder());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << json.dump();
|
|
|
|
|
return json.dump();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OrderList OrderList::FromJSONString(std::string json_str)
|
|
|
|
|
{
|
|
|
|
|
OrderList list;
|
|
|
|
|
nlohmann::json json = nlohmann::json::parse(json_str);
|
|
|
|
|
|
|
|
|
|
if (json.contains("head")){
|
|
|
|
|
auto &headJson = json.at("head");
|
|
|
|
|
if (headJson.contains("scheduled-dispatch")) {
|
|
|
|
|
auto &SDJson = headJson.at("scheduled-dispatch");
|
|
|
|
|
if (SDJson.is_array()) {
|
|
|
|
|
for (nlohmann::json::iterator it = SDJson.begin(); it != SDJson.end(); ++it) {
|
|
|
|
|
if (it.value().contains("slots")) {
|
|
|
|
|
|
|
|
|
|
auto &slotsJson = it.value().at("slots");;
|
|
|
|
|
DispatchSchedule dispatchSchedule;
|
|
|
|
|
|
|
|
|
|
if (slotsJson.is_array()) {
|
|
|
|
|
for (nlohmann::json::iterator it = slotsJson.begin(); it != slotsJson.end(); ++it) {
|
|
|
|
|
|
|
|
|
|
DispatchSlot newDispatchSlot;
|
|
|
|
|
|
|
|
|
|
newDispatchSlot.offset = it.value().at("offset").template get<uint32_t>();
|
|
|
|
|
newDispatchSlot.flags = it.value().at("flags").template get<uint16_t>();
|
|
|
|
|
|
|
|
|
|
dispatchSchedule.GetScheduledDispatchMutable().push_back(newDispatchSlot);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispatchSchedule.ScheduleName() = it.value().at("name").template get<std::string>();
|
|
|
|
|
dispatchSchedule.SetScheduledDispatchStartTick(it.value().at("start-tick").template get<uint32_t>());
|
|
|
|
|
dispatchSchedule.SetScheduledDispatchDuration(it.value().at("duration").template get<uint32_t>());
|
|
|
|
|
dispatchSchedule.SetScheduledDispatchDelay(it.value().at("max-delay").template get<uint32_t>());
|
|
|
|
|
dispatchSchedule.SetScheduledDispatchFlags(it.value().at("flags").template get<uint8_t>());
|
|
|
|
|
|
|
|
|
|
list.dispatch_schedules.push_back(dispatchSchedule);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (json.contains("orders")) {
|
|
|
|
|
|
|
|
|
|
/*Where do orders get allocated?*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the vehicle from the shared order list.
|
|
|
|
|
* @note This is supposed to be called when the vehicle is still in the chain
|
|
|
|
|