Skip to content

Commit

Permalink
Merge branch 'develop' into adv-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jun 16, 2024
2 parents b148d74 + dd56a60 commit ad2affc
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
28 changes: 3 additions & 25 deletions .github/workflows/watch-df-steam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,20 @@ jobs:
channel: steam
df_steam_branch: testing
steps:
- name: Setup steamcmd
id: steamcmd
uses: CyberAndrii/setup-steamcmd@v1
continue-on-error: true
- name: Setup steamcmd (retry)
id: steamcmd2
uses: CyberAndrii/setup-steamcmd@v1
if: steps.steamcmd.outcome == 'failure'
- name: Fetch state
uses: actions/cache/restore@v4
with:
path: state
key: watchstate-${{ matrix.version }}
restore-keys: watchstate-${{ matrix.version }}
- name: Prep Steam auth
env:
STEAM_CONFIG_VDF: ${{ secrets.STEAM_CONFIG_VDF }}
run: |
mkdir -p $HOME/Steam/config
echo "$STEAM_CONFIG_VDF" | base64 -d >$HOME/Steam/config/config.vdf
- name: Compare branch metadata
uses: nick-fields/retry@v3
env:
STEAM_USERNAME: ${{ secrets.STEAM_USERNAME }}
with:
timeout_minutes: 2
command: |
timestamp=$(${{ steps.steamcmd.outputs.executable || steps.steamcmd2.outputs.executable }} \
+@ShutdownOnFailedCommand 1 \
+login $STEAM_USERNAME \
+app_info_request 975370 \
+app_info_print 975370 \
+quit | \
awk '/^{/,0' | \
awk '/^\t\t"branches"/,0' | \
awk '/^\t\t\t"${{ matrix.df_steam_branch }}"/,0' | \
timestamp=$(curl -X GET 'https://api.steamcmd.net/v1/info/975370?pretty=1' | \
awk '/^ *"branches"/,0' | \
awk '/^ *"${{ matrix.df_steam_branch }}"/,0' | \
fgrep timeupdated | \
head -n1 | \
cut -d'"' -f4)
Expand Down
4 changes: 4 additions & 0 deletions docs/guides/quickfort-user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,10 @@ Property Description
feature
``autotrain`` if set to ``true``, enables the corresponding `logistics`
feature
``autoforbid`` if set to ``true``, enables the corresponding `logistics`
feature
``autoclaim`` if set to ``true``, enables the corresponding `logistics`
feature
================ ===========

Note that specifying building IDs in ``take_from`` or ``give_to`` lists is
Expand Down
20 changes: 19 additions & 1 deletion library/MiscUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,20 @@ static const std::vector<std::pair<const char *, double>> sig_fig_db = {
{"T", 1000000000000.0}, // 100,000,000,000,000+
};

template<typename T>
static int get_magnitude(T absnum) {
static const size_t max_magnitude = sig_fig_db.size() - 1;
if (absnum <= 1)
return 0;
return std::min(max_magnitude, (size_t)std::floor(std::log2(absnum) * (1/std::log2(10))) + 1);
}

DFHACK_EXPORT std::string format_number_by_sig_fig(double num, size_t sig_figs) {
if (num == 0)
return "0";

double absnum = std::abs(num);
int magnitude = absnum <= 1 ? 0 : std::min((size_t)std::floor(std::log2(absnum) * (1/std::log2(10))) + 1, sig_fig_db.size() - 1);
int magnitude = get_magnitude(absnum);
auto & sig_data = sig_fig_db[magnitude];

int sf = (int)sig_figs;
Expand All @@ -127,6 +135,16 @@ DFHACK_EXPORT std::string format_number_by_sig_fig(double num, size_t sig_figs)
return ss.str();
}

DFHACK_EXPORT std::string format_number_by_sig_fig(int64_t num, size_t sig_figs) {
if (std::abs(num) < 10000) {
std::ostringstream ss;
ss << std::fixed << num;
return ss.str();
}

return format_number_by_sig_fig((double)num, sig_figs);
}

int random_int(int max)
{
return int(int64_t(rand()) * max / (int64_t(RAND_MAX) + 1));
Expand Down
3 changes: 2 additions & 1 deletion library/include/MiscUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ DFHACK_EXPORT NumberFormatType get_preferred_number_format_type();
DFHACK_EXPORT void set_preferred_number_format_type(NumberFormatType type);
DFHACK_EXPORT void imbue_with_locale(std::ostringstream &ss, NumberFormatType type);
DFHACK_EXPORT std::string format_number_by_sig_fig(double num, size_t sig_figs);
DFHACK_EXPORT std::string format_number_by_sig_fig(int64_t num, size_t sig_figs);

// format a number according to the give formatting type
template<typename T>
Expand All @@ -479,7 +480,7 @@ static inline std::string format_number(T num, NumberFormatType type) {
ss << (double)num;
break;
case NumberFormatType::SIG_FIG:
ss << format_number_by_sig_fig((double)num, 3);
ss << format_number_by_sig_fig(num, 3);
break;
default:
ss << num;
Expand Down
2 changes: 1 addition & 1 deletion library/xml
Submodule xml updated 3 files
+7 −1 StructFields.pm
+9 −15 df.jobs.xml
+1 −5 df.ui-menus.xml
13 changes: 7 additions & 6 deletions plugins/logistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ REQUIRE_GLOBAL(plotinfo);
REQUIRE_GLOBAL(world);

namespace DFHack {
DBG_DECLARE(logistics, control, DebugCategory::LINFO);
DBG_DECLARE(logistics, cycle, DebugCategory::LINFO);
DBG_DECLARE(logistics, control, DebugCategory::LINFO);
DBG_DECLARE(logistics, cycle, DebugCategory::LINFO);
}

static const string CONFIG_KEY_PREFIX = string(plugin_name) + "/";
Expand Down Expand Up @@ -687,11 +687,12 @@ static void logistics_cycle(color_ostream &out, bool quiet = false) {
static void find_stockpiles(lua_State *L, int idx,
vector<df::building_stockpilest*> &sps) {
if (lua_isnumber(L, idx)) {
sps.emplace_back(find_stockpile(lua_tointeger(L, -1)));
if (auto sp = find_stockpile(lua_tointeger(L, idx)))
sps.emplace_back(sp);
return;
}

const char * pname = lua_tostring(L, -1);
const char * pname = lua_tostring(L, idx);
if (!pname || !*pname)
return;
string name(pname);
Expand Down Expand Up @@ -733,7 +734,7 @@ static int logistics_getStockpileConfigs(lua_State *L) {
validate_stockpile_configs(*out, cache);

vector<df::building_stockpilest*> sps;
find_stockpiles(L, -1, sps);
find_stockpiles(L, 1, sps);
if (sps.empty())
return 0;

Expand Down Expand Up @@ -773,7 +774,7 @@ static int logistics_clearStockpileConfig(lua_State *L) {
DEBUG(control, *out).print("entering logistics_clearStockpileConfig\n");

vector<df::building_stockpilest*> sps;
find_stockpiles(L, -1, sps);
find_stockpiles(L, 1, sps);
if (sps.empty())
return 0;

Expand Down
8 changes: 4 additions & 4 deletions plugins/lua/logistics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ local function do_add_stockpile_config(features, opts)
for _,config in ipairs(configs) do
features.claim = features.claim or features.unforbid -- accept 'add unforbid' in addition to 'add claim'
logistics_setStockpileConfig(config.stockpile_number,
features.melt or config.melt == 1,
features.trade or config.trade == 1,
features.dump or config.dump == 1,
features.train or config.train == 1,
features.melt and true or config.melt == 1,
features.trade and true or config.trade == 1,
features.dump and true or config.dump == 1,
features.train and true or config.train == 1,
(features.forbid and 1) or (features.claim and 2) or config.forbid,
not not opts.melt_masterworks)
end
Expand Down
2 changes: 1 addition & 1 deletion scripts

0 comments on commit ad2affc

Please sign in to comment.