MCPcopy Create free account
hub / github.com/DFHack/dfhack / GetWorldInfo

Function GetWorldInfo

library/RemoteTools.cpp:376–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376static command_result GetWorldInfo(color_ostream &stream,
377 const EmptyMessage *, GetWorldInfoOut *out)
378{
379 using df::global::plotinfo;
380 using df::global::adventure;
381 using df::global::world;
382
383 if (!plotinfo || !world || !Core::getInstance().isWorldLoaded())
384 return CR_NOT_FOUND;
385
386 df::game_type gt = game_type::DWARF_MAIN;
387 if (df::global::gametype)
388 gt = *df::global::gametype;
389
390 out->set_save_dir(world->cur_savegame.save_dir);
391
392 if (world->world_data->name.has_name)
393 describeName(out->mutable_world_name(), &world->world_data->name);
394
395 switch (gt)
396 {
397 case game_type::DWARF_MAIN:
398 case game_type::DWARF_RECLAIM:
399 case game_type::DWARF_UNRETIRE:
400 out->set_mode(GetWorldInfoOut::MODE_DWARF);
401 out->set_civ_id(plotinfo->civ_id);
402 out->set_site_id(plotinfo->site_id);
403 out->set_group_id(plotinfo->group_id);
404 out->set_race_id(plotinfo->race_id);
405 break;
406
407 case game_type::ADVENTURE_MAIN:
408 case game_type::ADVENTURE_ARENA:
409 out->set_mode(GetWorldInfoOut::MODE_ADVENTURE);
410
411 if (auto unit = vector_get(world->units.active, 0))
412 out->set_player_unit_id(unit->id);
413
414 if (!adventure)
415 break;
416
417 if (auto nemesis = vector_get(world->nemesis.all, adventure->player_id))
418 {
419 if (nemesis->figure)
420 out->set_player_histfig_id(nemesis->figure->id);
421
422 for (size_t i = 0; i < nemesis->companions.size(); i++)
423 {
424 auto unm = df::nemesis_record::find(nemesis->companions[i]);
425 if (!unm || !unm->figure)
426 continue;
427 out->add_companion_histfig_ids(unm->figure->id);
428 }
429 }
430 break;
431
432 case game_type::VIEW_LEGENDS:
433 out->set_mode(GetWorldInfoOut::MODE_LEGENDS);

Callers

nothing calls this directly

Calls 4

vector_getFunction · 0.85
set_modeMethod · 0.80
findFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected