20#define CPPHTTPLIB_NO_EXCEPTIONS
23using json = nlohmann::json;
47 auto identity = state.world.nation_get_identity_from_identity_holder(n);
48 auto color = state.world.national_identity_get_color(identity);
76 j[
"secondary_nation"] =
format_nation(state, fid.get_secondary_nation());
77 j[
"associated_tag"] =
format_nation(state, fid.get_associated_tag());
79 j[
"ticking_warscore"] = fid.get_ticking_war_score();
109 auto dt = state.current_date.to_ymd(state.start_date);
112 j[
"month"] = dt.month;
114 j[
"date"] = std::to_string(dt.day) +
"." + std::to_string(dt.month) +
"." + std::to_string(dt.year);
121 json jlist = json::array();
123 for(
auto nation : state.world.in_nation) {
129 auto national_bank = state.world.nation_get_national_bank(nation);
134 j[
"population"] = population;
135 j[
"nation_ppp_gdp"] = nation_ppp_gdp_text;
136 j[
"nation_ppp_gdp_per_capita"] = nation_ppp_gdp_per_capita_text;
137 j[
"nation_sol"] = nation_sol_text;
139 j[
"national_bank"] = national_bank;
140 j[
"state_debt"] = state_debt;
150 json jlist = json::array();
152 for(
auto commodity : state.world.in_commodity) {
153 auto id = commodity.id.index();
160 j[
"name"] = commodity_name;
163 json jplist = json::array();
164 for(
auto n : state.world.in_nation)
165 if(n.get_owned_province_count() != 0) {
169 if(jel[
"supply"] > 0.0f) {
173 j[
"producers"] = jplist;
176 json jblist = json::array();
177 for(
auto n : state.world.in_nation)
178 if(n.get_owned_province_count() != 0) {
182 if(jel[
"demand"] > 0.0f) {
187 j[
"consumers"] = jblist;
197 json jlist = json::array();
199 for(
auto cid : state.world.in_commodity) {
200 state.world.for_each_trade_route([&](dcon::trade_route_id trade_route) {
201 auto current_volume = state.world.trade_route_get_volume(trade_route, cid);
204 ? state.world.trade_route_get_connected_markets(trade_route, 0)
205 : state.world.trade_route_get_connected_markets(trade_route, 1);
207 current_volume <= 0.f
208 ? state.world.trade_route_get_connected_markets(trade_route, 0)
209 : state.world.trade_route_get_connected_markets(trade_route, 1);
211 auto s_origin = state.world.market_get_zone_from_local_market(origin);
212 auto s_target = state.world.market_get_zone_from_local_market(target);
214 auto p_origin = state.world.state_instance_get_capital(s_origin);
215 auto p_target = state.world.state_instance_get_capital(s_target);
217 auto sat = state.world.market_get_direct_demand_satisfaction(origin, cid);
219 auto absolute_volume = std::abs(current_volume);
220 auto factual_volume = sat * absolute_volume;
222 if(absolute_volume <= 0) {
226 bool is_sea = state.world.trade_route_get_distance(trade_route) == state.world.trade_route_get_sea_distance(trade_route);
232 j[
"commodity_id"] = cid.id.
value;
233 j[
"commodity"] = commodity_name;
235 j[
"origin_market_id"] = origin.value;
236 j[
"target_market_id"] = target.value;
238 j[
"origin_state_id"] = s_origin.value;
239 j[
"target_state_id"] = s_target.value;
241 j[
"origin_province_id"] = p_origin.id.value;
242 j[
"target_province_id"] = p_target.id.value;
247 auto origin_country = state.world.province_get_nation_from_province_ownership(p_origin);
248 auto target_country = state.world.province_get_nation_from_province_ownership(p_target);
250 j[
"origin_country_id"] = origin_country.value;
251 j[
"target_country_id"] = target_country.value;
259 j[
"is_sea"] = is_sea;
268 json jlist = json::array();
270 for(
auto prov : state.world.in_province) {
271 auto id = prov.id.index();
275 auto owner = state.world.province_get_nation_from_province_ownership(prov.id);
276 auto prov_population = state.world.province_get_demographics(prov.id,
demographics::total);
278 float num_capitalist = state.world.province_get_demographics(
283 float num_aristocrat = state.world.province_get_demographics(
288 auto rgo = state.world.province_get_rgo(prov);
293 j[
"name"] = province_name;
295 j[
"population"][
"total"] = prov_population;
296 j[
"population"][
"capitalist"] = num_capitalist;
297 j[
"population"][
"aristocrat"] = num_aristocrat;
308 json jlist = json::array();
310 for(
auto war : state.world.in_war) {
311 auto id = war.id.index();
317 j[
"is_great"] = war.get_is_great();
318 j[
"is_crisis"] = war.get_is_crisis_war();
319 j[
"attacker_battle_score"] = war.get_attacker_battle_score();
320 j[
"defender_battle_score"] = war.get_defender_battle_score();
321 j[
"primary_attacker"] =
format_nation(state, war.get_primary_attacker());
322 j[
"primary_defender"] =
format_nation(state, war.get_primary_defender());
326 json jalist = json::array();
327 json jdlist = json::array();
328 std::vector<dcon::nation_id> attackers;
330 for(
auto wp : state.world.war_get_war_participant(war)) {
331 if(wp.get_is_attacker()) {
333 attackers.push_back(wp.get_nation());
339 j[
"attackers"] = jalist;
340 j[
"defenders"] = jdlist;
342 json jawgslist = json::array();
343 json jdwgslist = json::array();
345 for(
auto el : war.get_wargoals_attached()) {
346 auto wg = el.get_wargoal();
347 if(std::find(attackers.begin(), attackers.end(), wg.get_added_by()) != attackers.end()) {
355 j[
"attacker_wargoals"] = jawgslist;
356 j[
"defender_wargoals"] = jdwgslist;
370 j[
"primary_attacker"] =
format_nation(state, state.primary_crisis_attacker);
371 j[
"primary_defender"] =
format_nation(state, state.primary_crisis_defender);
373 if(state.crisis_state_instance) {
374 auto fid =
dcon::fatten(state.world, state.crisis_state_instance);
375 auto defid = fid.get_definition();
379 j[
"temperature"] = state.crisis_temperature;
381 json jalist = json::array();
382 json jdlist = json::array();
384 for(
auto cp : state.crisis_participants) {
385 if(cp.supports_attacker) {
387 }
else if (!cp.merely_interested) {
392 j[
"attackers"] = jalist;
393 j[
"defenders"] = jdlist;
395 json jawgslist = json::array();
396 json jdwgslist = json::array();
398 for(
auto awg : state.crisis_attacker_wargoals) {
401 for(
auto dwg : state.crisis_attacker_wargoals) {
405 j[
"attacker_wargoals"] = jawgslist;
406 j[
"defender_wargoals"] = jdwgslist;
411 svr.
listen(
"0.0.0.0", 1234);
namespace for Niels Lohmann
void push_back(basic_json &&val)
add an object to an array
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
bool listen(const std::string &host, int port, int socket_flags=0)
Server & Get(const std::string &pattern, Handler handler)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float calculate_nation_sol(sys::state &state, dcon::nation_id nation_id)
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
float supply(sys::state &state, dcon::market_id s, dcon::commodity_id c)
float demand(sys::state &state, dcon::market_id s, dcon::commodity_id c)
float gdp_adjusted(sys::state &state, dcon::market_id n)
float get_debt(sys::state &state, dcon::nation_id n)
int32_t int_red_from_int(uint32_t v)
int32_t int_blue_from_int(uint32_t v)
int32_t int_green_from_int(uint32_t v)
std::string format_float(float num, size_t digits)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
json format_color(sys::state &state, uint32_t c)
void init(sys::state &state) noexcept
json format_wargoal(sys::state &state, dcon::wargoal_id wid)
json format_nation(sys::state &state, dcon::nation_id n)
void set_content(const char *s, size_t n, const std::string &content_type)
dcon::nation_id target_nation
dcon::nation_id secondary_nation
dcon::national_identity_id wg_tag
dcon::state_definition_id state
Holds important data about the game world, state, and other data regarding windowing,...