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

Method getCasteProfessionName

library/modules/Units.cpp:1847–1947  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1845}
1846
1847string Units::getCasteProfessionName(int race, int casteid, df::profession pid, bool plural) {
1848 string prof, race_prefix;
1849 if (!is_valid_enum_item(pid) || pid == profession::NONE)
1850 return "";
1851
1852 int16_t current_race = plotinfo->race_id;
1853 if (auto adv = World::getAdventurer())
1854 current_race = adv->race;
1855 bool use_race_prefix = (race >= 0 && race != current_race); // TODO: Use anyway if unit->curse.name_visible and not noble
1856
1857 if (auto creature = df::creature_raw::find(race)) {
1858 if (auto caste = vector_get(creature->caste, casteid))
1859 {
1860 race_prefix = caste->caste_name[0];
1861
1862 if (plural)
1863 prof = caste->caste_profession_name.plural[pid];
1864 else
1865 prof = caste->caste_profession_name.singular[pid];
1866
1867 if (prof.empty()) {
1868 switch (pid)
1869 {
1870 case profession::CHILD:
1871 prof = caste->child_name[plural ? 1 : 0];
1872 if (!prof.empty())
1873 use_race_prefix = false;
1874 break;
1875 case profession::BABY:
1876 prof = caste->baby_name[plural ? 1 : 0];
1877 if (!prof.empty())
1878 use_race_prefix = false;
1879 break;
1880 default:
1881 break;
1882 }
1883 }
1884 }
1885
1886 if (race_prefix.empty())
1887 race_prefix = creature->name[0];
1888
1889 if (prof.empty()) {
1890 if (plural)
1891 prof = creature->profession_name.plural[pid];
1892 else
1893 prof = creature->profession_name.singular[pid];
1894
1895 if (prof.empty()) {
1896 switch (pid)
1897 {
1898 case profession::CHILD:
1899 prof = creature->general_child_name[plural ? 1 : 0];
1900 if (!prof.empty())
1901 use_race_prefix = false;
1902 break;
1903 case profession::BABY:
1904 prof = creature->general_baby_name[plural ? 1 : 0];

Callers

nothing calls this directly

Calls 4

is_valid_enum_itemFunction · 0.85
vector_getFunction · 0.85
findFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected