本文整理汇总了C++中PersistentDataItem::ival方法的典型用法代码示例。如果您正苦于以下问题:C++ PersistentDataItem::ival方法的具体用法?C++ PersistentDataItem::ival怎么用?C++ PersistentDataItem::ival使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PersistentDataItem
的用法示例。
在下文中一共展示了PersistentDataItem::ival方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_state
static void init_state(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
config = pworld->GetPersistentData("workflow/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enabled = isOptionEnabled(CF_ENABLED);
// Parse constraints
std::vector<PersistentDataItem> items;
pworld->GetPersistentData(&items, "workflow/constraints");
for (int i = items.size()-1; i >= 0; i--) {
if (get_constraint(out, items[i].val(), &items[i]))
continue;
out.printerr("Lost constraint %s\n", items[i].val().c_str());
pworld->DeletePersistentData(items[i]);
}
last_tick_frame_count = world->frame_counter;
last_frame_count = world->frame_counter;
if (!enabled)
return;
start_protect(out);
}
示例2: init_state
static void init_state()
{
config = World::GetPersistentData("autolabor/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enable_autolabor = isOptionEnabled(CF_ENABLED);
if (!enable_autolabor)
return;
auto cfg_haulpct = World::GetPersistentData("autolabor/haulpct");
if (cfg_haulpct.isValid())
{
hauler_pct = cfg_haulpct.ival(0);
}
else
{
hauler_pct = 33;
}
// Load labors from save
labor_infos.resize(ARRAY_COUNT(default_labor_infos));
std::vector<PersistentDataItem> items;
World::GetPersistentData(&items, "autolabor/labors/", true);
for (auto p = items.begin(); p != items.end(); p++)
{
string key = p->key();
df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
if (labor >= 0 && labor <= labor_infos.size())
{
labor_infos[labor].config = *p;
labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive;
labor_infos[labor].active_dwarfs = 0;
}
}
// Add default labors for those not in save
for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
if (labor_infos[i].config.isValid())
continue;
std::stringstream name;
name << "autolabor/labors/" << i;
labor_infos[i].config = World::AddPersistentData(name.str());
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
labor_infos[i].active_dwarfs = 0;
reset_labor((df::unit_labor) i);
}
generate_labor_to_skill_map();
}
示例3: setOptionEnabled
static void setOptionEnabled(ConfigFlags flag, bool on)
{
if (!config.isValid())
return;
if (on)
config.ival(0) |= flag;
else
config.ival(0) &= ~flag;
}
示例4: read_persistent
static int read_persistent(lua_State *state, PersistentDataItem ref, bool create)
{
if (!ref.isValid())
{
lua_pushnil(state);
lua_pushstring(state, "entry not found");
return 2;
}
if (create)
lua_createtable(state, 0, 4);
lua_pushvalue(state, lua_upvalueindex(1));
lua_setmetatable(state, -2);
lua_pushinteger(state, ref.entry_id());
lua_setfield(state, -2, "entry_id");
lua_pushstring(state, ref.key().c_str());
lua_setfield(state, -2, "key");
lua_pushstring(state, ref.val().c_str());
lua_setfield(state, -2, "value");
lua_createtable(state, PersistentDataItem::NumInts, 0);
for (int i = 0; i < PersistentDataItem::NumInts; i++)
{
lua_pushinteger(state, ref.ival(i));
lua_rawseti(state, -2, i+1);
}
lua_setfield(state, -2, "ints");
return 1;
}
示例5: init_state
static void init_state()
{
auto pworld = Core::getInstance().getWorld();
config = pworld->GetPersistentData("autolabor/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enable_autolabor = isOptionEnabled(CF_ENABLED);
if (!enable_autolabor)
return;
// Load labors from save
labor_infos.resize(ARRAY_COUNT(default_labor_infos));
std::vector<PersistentDataItem> items;
pworld->GetPersistentData(&items, "autolabor/labors/", true);
for (auto p = items.begin(); p != items.end(); p++)
{
string key = p->key();
df::enums::unit_labor::unit_labor labor = (df::enums::unit_labor::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
if (labor >= 0 && labor <= labor_infos.size())
{
labor_infos[labor].config = *p;
labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive;
labor_infos[labor].active_dwarfs = 0;
}
}
// Add default labors for those not in save
for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
if (labor_infos[i].config.isValid())
continue;
std::stringstream name;
name << "autolabor/labors/" << i;
labor_infos[i].config = pworld->AddPersistentData(name.str());
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
labor_infos[i].active_dwarfs = 0;
reset_labor((df::enums::unit_labor::unit_labor) i);
}
}
示例6: enable_plugin
static void enable_plugin(Core *c)
{
if (!config.isValid())
{
config = c->getWorld()->AddPersistentData("workflow/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enabled = true;
c->con << "Enabling the plugin." << endl;
start_protect(c);
}
示例7: enable_plugin
static void enable_plugin(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
if (!config.isValid())
{
config = pworld->AddPersistentData("workflow/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enabled = true;
out << "Enabling the plugin." << endl;
start_protect(out);
}
示例8: enable_plugin
static void enable_plugin(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
if (!config.isValid())
{
config = pworld->AddPersistentData("autolabor/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enable_autolabor = true;
out << "Enabling the plugin." << endl;
cleanup_state();
init_state();
}
示例9: enable_plugin
/**
* Call this method to enable the plugin.
*/
static void enable_plugin(color_ostream &out)
{
// If there is no config persistent item, make one
if (!config.isValid())
{
config = World::AddPersistentData("autohauler/config");
config.ival(0) = 0;
}
// I think this is already done in init_state(), but it can't hurt
setOptionEnabled(CF_ENABLED, true);
enable_autohauler = true;
// Output to console that the plugin is enabled
out << "Enabling the plugin." << endl;
// Disable autohauler and clear the labor list
cleanup_state();
// Initialize the plugin
init_state();
}
示例10: init
void init(const std::string &str)
{
config.val() = str;
config.ival(2) = 0;
}
示例11: setGoalByCount
void setGoalByCount(bool v) {
if (v)
config.ival(2) |= 1;
else
config.ival(2) &= ~1;
}
示例12: goalByCount
bool goalByCount() { return config.ival(2) & 1; }
示例13: setGoalGap
void setGoalGap(int v) { config.ival(1) = v; }
示例14: goalGap
int goalGap() {
int gcnt = std::max(1, goalCount()/2);
return std::min(gcnt, config.ival(1) <= 0 ? 5 : config.ival(1));
}
示例15: set_mode
void set_mode(labor_mode mode) { config.ival(0) = mode; }