Compare commits

..

No commits in common. "1968cffb13df57850e51fa4bf0f8b32a958449bd" and "94de377c0b360d8ebe8c2fa49c028b7214db0695" have entirely different histories.

9 changed files with 12 additions and 132 deletions

@ -8,8 +8,8 @@ project(dfhack)
# set up versioning. # set up versioning.
set(DF_VERSION "50.11") set(DF_VERSION "50.11")
set(DFHACK_RELEASE "r5rc1") set(DFHACK_RELEASE "r4")
set(DFHACK_PRERELEASE TRUE) set(DFHACK_PRERELEASE FALSE)
set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
set(DFHACK_ABI_VERSION 1) set(DFHACK_ABI_VERSION 1)

@ -158,7 +158,7 @@ keybinding add Alt-K@dwarfmode toggle-kbd-cursor
# gui/design # gui/design
keybinding add Ctrl-D@dwarfmode/Default gui/design keybinding add Ctrl-D@dwarfmode/Default gui/design
keybinding add Ctrl-M@dwarfmode/Default gui/mass-remove
##################### #####################

@ -55,7 +55,6 @@ Template for new versions:
## New Features ## New Features
- `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for - `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for
- `gui/mass-remove`: new global keybinding: Ctrl-M while on the fort map
## Fixes ## Fixes
- `reveal`: now avoids revealing blocks that contain divine treasures, encased horrors, and deep vein hollows (so the surprise triggers are not triggered prematurely) - `reveal`: now avoids revealing blocks that contain divine treasures, encased horrors, and deep vein hollows (so the surprise triggers are not triggered prematurely)
@ -74,12 +73,8 @@ Template for new versions:
- `modding-guide`: Add examples for script-only and blueprint-only mods that you can upload to DF's Steam Workshop - `modding-guide`: Add examples for script-only and blueprint-only mods that you can upload to DF's Steam Workshop
## API ## API
- ``random_index``, ``vector_get_random``: new ``MiscUtils`` functions, for getting a random entry in a vector
- ``capitalize_string_words``: new ``MiscUtils`` function, returns string with all words capitalized
- ``grab_token_string_pos``: new ``MiscUtils`` function, used for parsing tokens
## Lua ## Lua
- ``dfhack.capitalizeStringWords``: new function, returns string with all words capitalized
## Removed ## Removed

@ -941,10 +941,6 @@ can be omitted.
Note that the returned string may be longer than the input string. For Note that the returned string may be longer than the input string. For
example, ``ä`` is replaced with ``a``, and ``æ`` is replaced with ``ae``. example, ``ä`` is replaced with ``a``, and ``æ`` is replaced with ``ae``.
* ``dfhack.capitalizeStringWords(string)``
Return a version of the string with each word capitalized.
* ``dfhack.run_command(command[, ...])`` * ``dfhack.run_command(command[, ...])``
Run an arbitrary DFHack command, with the core suspended, and send output to Run an arbitrary DFHack command, with the core suspended, and send output to

@ -1450,7 +1450,6 @@ static std::string df2utf(std::string s) { return DF2UTF(s); }
static std::string utf2df(std::string s) { return UTF2DF(s); } static std::string utf2df(std::string s) { return UTF2DF(s); }
static std::string df2console(color_ostream &out, std::string s) { return DF2CONSOLE(out, s); } static std::string df2console(color_ostream &out, std::string s) { return DF2CONSOLE(out, s); }
static std::string toSearchNormalized(std::string s) { return to_search_normalized(s); } static std::string toSearchNormalized(std::string s) { return to_search_normalized(s); }
static std::string capitalizeStringWords(std::string s) { return capitalize_string_words(s); }
#define WRAP_VERSION_FUNC(name, function) WRAPN(name, DFHack::Version::function) #define WRAP_VERSION_FUNC(name, function) WRAPN(name, DFHack::Version::function)
@ -1469,7 +1468,6 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAP(utf2df), WRAP(utf2df),
WRAP(df2console), WRAP(df2console),
WRAP(toSearchNormalized), WRAP(toSearchNormalized),
WRAP(capitalizeStringWords),
WRAP_VERSION_FUNC(getDFHackVersion, dfhack_version), WRAP_VERSION_FUNC(getDFHackVersion, dfhack_version),
WRAP_VERSION_FUNC(getDFHackRelease, dfhack_release), WRAP_VERSION_FUNC(getDFHackRelease, dfhack_release),
WRAP_VERSION_FUNC(getDFHackBuildID, dfhack_build_id), WRAP_VERSION_FUNC(getDFHackBuildID, dfhack_build_id),

@ -48,11 +48,6 @@ distribution.
#include <map> #include <map>
#include <array> #include <array>
int random_int(int max)
{
return int(int64_t(rand()) * max / (int64_t(RAND_MAX) + 1));
}
std::string stl_sprintf(const char *fmt, ...) { std::string stl_sprintf(const char *fmt, ...) {
va_list lst; va_list lst;
va_start(lst, fmt); va_start(lst, fmt);
@ -176,64 +171,6 @@ std::string to_search_normalized(const std::string &str)
return result; return result;
} }
std::string capitalize_string_words(const std::string& str)
{ // Cleaned up from g_src/basics.cpp, and returns new string
std::string out = str;
bool starting = true;
int32_t bracket_count = 0;
bool conf;
for (size_t s = 0; s < out.length(); s++)
{
if (out[s] == '[') { ++bracket_count; continue; }
else if (out[s] == ']') { --bracket_count; continue; }
else if (bracket_count > 0) continue;
conf = false;
if (!starting)
{
if (out[s - 1] == ' ' || out[s - 1] == '\"')
conf = true;
// Discount single quote if it isn't preceded by space, comma, or nothing
else if (out[s - 1] == '\'' && s >= 2 && (out[s - 2] == ' ' || out[s - 2] == ','))
conf = true;
}
if (starting || conf)
{
// Capitalize
if (out[s] >= 'a' && out[s] <= 'z')
out[s] += 'A' - 'a';
else
{
switch (out[s])
{
case (char)129: // 'ü'
out[s] = (char)154; break; // 'Ü'
case (char)164: // 'ñ'
out[s] = (char)165; break; // 'Ñ'
case (char)132: // 'ä'
out[s] = (char)142; break; // 'Ä'
case (char)134: // 'å'
out[s] = (char)143; break; // 'Å'
case (char)130: // 'é'
out[s] = (char)144; break; // 'É'
case (char)148: // 'ö'
out[s] = (char)153; break; // 'Ö'
case (char)135: // 'ç'
out[s] = (char)128; break; // 'Ç'
case (char)145: // 'æ'
out[s] = (char)146; break; // 'Æ'
}
}
starting = false;
}
}
return out;
}
bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t line_length, bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t line_length,
word_wrap_whitespace_mode mode) word_wrap_whitespace_mode mode)
{ {
@ -293,21 +230,6 @@ bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t lin
return true; return true;
} }
std::string grab_token_string_pos(const std::string& source, int32_t pos, char compc)
{ // Cleaned up from g_src/basics.cpp, return string instead of bool
std::string out;
// Go until you hit compc, ']', or the end
for (auto s = source.begin() + pos; s < source.end(); ++s)
{
if (*s == compc || *s == ']')
break;
out += *s;
}
return out;
}
bool prefix_matches(const std::string &prefix, const std::string &key, std::string *tail) bool prefix_matches(const std::string &prefix, const std::string &key, std::string *tail)
{ {
size_t ksize = key.size(); size_t ksize = key.size();
@ -331,6 +253,11 @@ bool prefix_matches(const std::string &prefix, const std::string &key, std::stri
return false; return false;
} }
int random_int(int max)
{
return int(int64_t(rand())*max/(int64_t(RAND_MAX)+1));
}
#ifdef LINUX_BUILD // Linux #ifdef LINUX_BUILD // Linux
uint64_t GetTimeMs64() uint64_t GetTimeMs64()
{ {

@ -61,8 +61,6 @@ namespace DFHack {
class color_ostream; class color_ostream;
} }
DFHACK_EXPORT int random_int(int max);
template <typename T> template <typename T>
void print_bits ( T val, std::ostream& out ) void print_bits ( T val, std::ostream& out )
{ {
@ -180,17 +178,6 @@ inline int binsearch_index(const std::vector<CT*> &vec, typename CT::key_pointer
return CT::binsearch_index(vec, key, exact); return CT::binsearch_index(vec, key, exact);
} }
template <typename FT>
int random_index(const std::vector<FT>& vec)
{
if (vec.empty())
return -1;
else if (vec.size() == 1)
return 0;
return random_int(vec.size());
}
template<typename FT, typename KT> template<typename FT, typename KT>
inline bool vector_contains(const std::vector<FT> &vec, KT key) inline bool vector_contains(const std::vector<FT> &vec, KT key)
{ {
@ -212,12 +199,6 @@ inline T vector_get(const std::vector<T> &vec, unsigned idx, const T &defval = T
return defval; return defval;
} }
template<typename T>
inline T vector_get_random(const std::vector<T>& vec, const T& defval = T())
{
return vector_get(vec, random_index(vec), defval);
}
template<typename T> template<typename T>
inline void vector_insert_at(std::vector<T> &vec, unsigned idx, const T &val) inline void vector_insert_at(std::vector<T> &vec, unsigned idx, const T &val)
{ {
@ -420,7 +401,6 @@ inline std::string join_strings(const std::string &separator, T &items) {
DFHACK_EXPORT std::string toUpper(const std::string &str); DFHACK_EXPORT std::string toUpper(const std::string &str);
DFHACK_EXPORT std::string toLower(const std::string &str); DFHACK_EXPORT std::string toLower(const std::string &str);
DFHACK_EXPORT std::string to_search_normalized(const std::string &str); DFHACK_EXPORT std::string to_search_normalized(const std::string &str);
DFHACK_EXPORT std::string capitalize_string_words(const std::string& str);
static inline std::string int_to_string(const int n) { static inline std::string int_to_string(const int n) {
std::ostringstream ss; std::ostringstream ss;
@ -464,13 +444,6 @@ DFHACK_EXPORT bool word_wrap(std::vector<std::string> *out,
const std::string &str, const std::string &str,
size_t line_length = 80, size_t line_length = 80,
word_wrap_whitespace_mode mode = WSMODE_KEEP_ALL); word_wrap_whitespace_mode mode = WSMODE_KEEP_ALL);
/**
* Function to assist in parsing tokens. Returns string from source pos until next compc, ']', or end.
* pos should be set to position after '[' to start with, then incremented by the result's size+1 before subsequent calls.
* compc is usually ':', but can be '.' for parsing number ranges.
* Based on Bay12's g_src/basics.cpp
*/
std::string grab_token_string_pos(const std::string& source, int32_t pos, char compc = ':');
inline bool bits_match(unsigned required, unsigned ok, unsigned mask) inline bool bits_match(unsigned required, unsigned ok, unsigned mask)
{ {
@ -484,6 +457,8 @@ inline T clip_range(T a, T1 minv, T2 maxv) {
return a; return a;
} }
DFHACK_EXPORT int random_int(int max);
/** /**
* Returns the amount of milliseconds elapsed since the UNIX epoch. * Returns the amount of milliseconds elapsed since the UNIX epoch.
* Works on both windows and linux. * Works on both windows and linux.

@ -181,10 +181,6 @@ DEFINE_GET_FOCUS_STRING_HANDLER(choose_start_site)
{ {
if (screen->doing_site_finder) if (screen->doing_site_finder)
focusStrings.push_back(baseFocus + "/SiteFinder"); focusStrings.push_back(baseFocus + "/SiteFinder");
else if (screen->choosing_civilization)
focusStrings.push_back(baseFocus + "/ChooseCiv");
else if (screen->choosing_reclaim)
focusStrings.push_back(baseFocus + "/Reclaim");
if (focusStrings.empty()) if (focusStrings.empty())
focusStrings.push_back(baseFocus); focusStrings.push_back(baseFocus);
@ -684,15 +680,8 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
if (game->main_interface.squad_equipment.open) { if (game->main_interface.squad_equipment.open) {
newFocusString = baseFocus; newFocusString = baseFocus;
newFocusString += "/SquadEquipment"; newFocusString += "/SquadEquipment";
if (game->main_interface.squad_equipment.customizing_equipment) { if (game->main_interface.squad_equipment.customizing_equipment)
newFocusString += "/Customizing"; newFocusString += "/Customizing";
if (game->main_interface.squad_equipment.cs_setting_material)
newFocusString += "/Material";
else if (game->main_interface.squad_equipment.cs_setting_color_pattern)
newFocusString += "/Color";
else
newFocusString += "/Default";
}
else else
newFocusString += "/Default"; newFocusString += "/Default";
focusStrings.push_back(newFocusString); focusStrings.push_back(newFocusString);

@ -1 +1 @@
Subproject commit 7e08fb13144e802315c89d826890df3a46155907 Subproject commit 6df7a488081d98d1f8ce3af5aa898251f868ac8c