Fix GCC warnings in 'tweak kitchen-prefs-all' and dev plugins

develop
lethosor 2018-06-01 10:02:05 -04:00
parent 02b7f2145f
commit 03968db344
9 changed files with 39 additions and 54 deletions

@ -42,8 +42,8 @@ namespace DFHack {
} }
class Callback { class Callback {
T_func *func;
T_hook *hook; T_hook *hook;
T_func *func;
bool enabled; bool enabled;
public: public:
Callback(T_hook *hook, T_func *func) : hook(hook), func(func) Callback(T_hook *hook, T_func *func) : hook(hook), func(func)

@ -144,7 +144,8 @@ command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
out.print("\t[STATE_COLOR:%s:%s]\n", state_names[state], world->raws.descriptors.colors[mat->state_color[state]]->id.c_str()); out.print("\t[STATE_COLOR:%s:%s]\n", state_names[state], world->raws.descriptors.colors[mat->state_color[state]]->id.c_str());
if (mat->state_name[state] == mat->state_adj[state]) if (mat->state_name[state] == mat->state_adj[state])
{ {
if (mat->state_name[state].size() && mat->state_name[state] != def_name[state] || mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state]) if ((mat->state_name[state].size() && mat->state_name[state] != def_name[state]) ||
(mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state]))
out.print("\t[STATE_NAME_ADJ:%s:%s]\n", state_names[state], mat->state_name[state].c_str()); out.print("\t[STATE_NAME_ADJ:%s:%s]\n", state_names[state], mat->state_name[state].c_str());
} }
else else
@ -189,11 +190,11 @@ command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
if (mat->heat.mat_fixed_temp != 60001) if (mat->heat.mat_fixed_temp != 60001)
out.print("\t[MAT_FIXED_TEMP:%i]\n", mat->heat.mat_fixed_temp); out.print("\t[MAT_FIXED_TEMP:%i]\n", mat->heat.mat_fixed_temp);
if (mat->solid_density != 0xFBBC7818) if (uint32_t(mat->solid_density) != 0xFBBC7818)
out.print("\t[SOLID_DENSITY:%i]\n", mat->solid_density); out.print("\t[SOLID_DENSITY:%i]\n", mat->solid_density);
if (mat->liquid_density != 0xFBBC7818) if (uint32_t(mat->liquid_density) != 0xFBBC7818)
out.print("\t[LIQUID_DENSITY:%i]\n", mat->liquid_density); out.print("\t[LIQUID_DENSITY:%i]\n", mat->liquid_density);
if (mat->molar_mass != 0xFBBC7818) if (uint32_t(mat->molar_mass) != 0xFBBC7818)
out.print("\t[MOLAR_MASS:%i]\n", mat->molar_mass); out.print("\t[MOLAR_MASS:%i]\n", mat->molar_mass);
FOR_ENUM_ITEMS(strain_type, strain) FOR_ENUM_ITEMS(strain_type, strain)
@ -228,9 +229,9 @@ command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
if (mat->block_name[0].size() || mat->block_name[1].size()) if (mat->block_name[0].size() || mat->block_name[1].size())
out.print("\t[BLOCK_NAME:%s:%s]\n", mat->block_name[0].c_str(), mat->block_name[1].c_str()); out.print("\t[BLOCK_NAME:%s:%s]\n", mat->block_name[0].c_str(), mat->block_name[1].c_str());
for (int i = 0; i < mat->reaction_class.size(); i++) for (std::string *s : mat->reaction_class)
out.print("\t[REACTION_CLASS:%s]\n", mat->reaction_class[i]->c_str()); out.print("\t[REACTION_CLASS:%s]\n", s->c_str());
for (int i = 0; i < mat->reaction_product.id.size(); i++) for (size_t i = 0; i < mat->reaction_product.id.size(); i++)
{ {
if ((*mat->reaction_product.str[0][i] == "NONE") && (*mat->reaction_product.str[1][i] == "NONE")) if ((*mat->reaction_product.str[0][i] == "NONE") && (*mat->reaction_product.str[1][i] == "NONE"))
out.print("\t[MATERIAL_REACTION_PRODUCT:%s:%s:%s%s%s]\n", mat->reaction_product.id[i]->c_str(), mat->reaction_product.str[2][i]->c_str(), mat->reaction_product.str[3][i]->c_str(), mat->reaction_product.str[4][i]->size() ? ":" : "", mat->reaction_product.str[4][i]->c_str()); out.print("\t[MATERIAL_REACTION_PRODUCT:%s:%s:%s%s%s]\n", mat->reaction_product.id[i]->c_str(), mat->reaction_product.str[2][i]->c_str(), mat->reaction_product.str[3][i]->c_str(), mat->reaction_product.str[4][i]->size() ? ":" : "", mat->reaction_product.str[4][i]->c_str());
@ -245,7 +246,7 @@ command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
if (mat->soap_level != -0) if (mat->soap_level != -0)
out.print("\t[SOAP_LEVEL:%o]\n", mat->soap_level); out.print("\t[SOAP_LEVEL:%o]\n", mat->soap_level);
for (int i = 0; i < mat->syndrome.size(); i++) for (size_t i = 0; i < mat->syndrome.size(); i++)
out.print("\t[SYNDROME] ...\n"); out.print("\t[SYNDROME] ...\n");
} }
return CR_OK; return CR_OK;

@ -20,12 +20,10 @@ using df::global::world;
int changeLiquid (df::tile_liquid type) int changeLiquid (df::tile_liquid type)
{ {
int tiles = 0; int tiles = 0;
for (int i = 0; i < world->map.map_blocks.size(); i++) for (df::map_block *block : world->map.map_blocks)
{ {
df::map_block *block = world->map.map_blocks[i]; for (df::block_square_event *evt : block->block_events)
for (size_t j = 0; j < block->block_events.size(); j++)
{ {
df::block_square_event *evt = block->block_events[j];
if (evt->getType() != block_square_event_type::frozen_liquid) if (evt->getType() != block_square_event_type::frozen_liquid)
continue; continue;
df::block_square_event_frozen_liquidst *frozen = (df::block_square_event_frozen_liquidst *)evt; df::block_square_event_frozen_liquidst *frozen = (df::block_square_event_frozen_liquidst *)evt;

@ -19,7 +19,10 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
DFHACK_PLUGIN("kittens");
DFHACK_PLUGIN_IS_ENABLED(is_enabled); DFHACK_PLUGIN_IS_ENABLED(is_enabled);
REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(world);
//FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core. //FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core.
volatile bool shutdown_flag = false; volatile bool shutdown_flag = false;
@ -30,7 +33,7 @@ bool trackpos_flg = false;
bool statetrack = false; bool statetrack = false;
int32_t last_designation[3] = {-30000, -30000, -30000}; int32_t last_designation[3] = {-30000, -30000, -30000};
int32_t last_mouse[2] = {-1, -1}; int32_t last_mouse[2] = {-1, -1};
uint32_t last_menu = 0; df::ui_sidebar_mode last_menu = df::ui_sidebar_mode::Default;
uint64_t timeLast = 0; uint64_t timeLast = 0;
command_result kittens (color_ostream &out, vector <string> & parameters); command_result kittens (color_ostream &out, vector <string> & parameters);
@ -40,8 +43,6 @@ command_result trackpos (color_ostream &out, vector <string> & parameters);
command_result trackstate (color_ostream &out, vector <string> & parameters); command_result trackstate (color_ostream &out, vector <string> & parameters);
command_result colormods (color_ostream &out, vector <string> & parameters); command_result colormods (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("kittens");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens)); commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens));
@ -103,9 +104,9 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
} }
if(trackmenu_flg) if(trackmenu_flg)
{ {
if (last_menu != df::global::ui->main.mode) if (last_menu != ui->main.mode)
{ {
last_menu = df::global::ui->main.mode; last_menu = ui->main.mode;
out.print("Menu: %d\n",last_menu); out.print("Menu: %d\n",last_menu);
} }
} }
@ -140,21 +141,13 @@ command_result trackmenu (color_ostream &out, vector <string> & parameters)
return CR_OK; return CR_OK;
} }
else else
{
if(df::global::ui)
{ {
trackmenu_flg = true; trackmenu_flg = true;
is_enabled = true; is_enabled = true;
last_menu = df::global::ui->main.mode; last_menu = ui->main.mode;
out.print("Menu: %d\n",last_menu); out.print("Menu: %d\n",last_menu);
return CR_OK; return CR_OK;
} }
else
{
out.printerr("Can't read menu state\n");
return CR_FAILURE;
}
}
} }
command_result trackpos (color_ostream &out, vector <string> & parameters) command_result trackpos (color_ostream &out, vector <string> & parameters)
{ {
@ -172,13 +165,12 @@ command_result trackstate ( color_ostream& out, vector< string >& parameters )
command_result colormods (color_ostream &out, vector <string> & parameters) command_result colormods (color_ostream &out, vector <string> & parameters)
{ {
CoreSuspender suspend; CoreSuspender suspend;
auto & vec = df::global::world->raws.creatures.alphabetic; auto & vec = world->raws.creatures.alphabetic;
for(int i = 0; i < vec.size();i++) for(df::creature_raw* rawlion : vec)
{ {
df::creature_raw* rawlion = vec[i];
df::caste_raw * caste = rawlion->caste[0]; df::caste_raw * caste = rawlion->caste[0];
out.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers); out.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers);
for(int j = 0; j < caste->color_modifiers.size();j++) for(size_t j = 0; j < caste->color_modifiers.size();j++)
{ {
out.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]); out.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]);
} }
@ -284,7 +276,7 @@ command_result kittens (color_ostream &out, vector <string> & parameters)
} }
con.flush(); con.flush();
con.msleep(60); con.msleep(60);
((int&)color) ++; color = Console::color_value(int(color) + 1);
if(color > COLOR_MAX) if(color > COLOR_MAX)
color = COLOR_BLUE; color = COLOR_BLUE;
} }

@ -37,9 +37,8 @@ static void eggscan(color_ostream &out)
{ {
CoreSuspender suspend; CoreSuspender suspend;
for (int i = 0; i < world->buildings.all.size(); ++i) for (df::building *build : world->buildings.all)
{ {
df::building *build = world->buildings.all[i];
auto type = build->getType(); auto type = build->getType();
if (df::enums::building_type::NestBox == type) if (df::enums::building_type::NestBox == type)
{ {
@ -51,7 +50,7 @@ static void eggscan(color_ostream &out)
if (u && u->pregnancy_timer > 0) if (u && u->pregnancy_timer > 0)
fertile = true; fertile = true;
} }
for (int j = 1; j < nb->contained_items.size(); j++) for (size_t j = 1; j < nb->contained_items.size(); j++)
{ {
df::item* item = nb->contained_items[j]->item; df::item* item = nb->contained_items[j]->item;
if (item->flags.bits.forbid != fertile) if (item->flags.bits.forbid != fertile)

@ -26,7 +26,7 @@ struct renderer_msg : public Renderer::renderer_wrap {
virtual void update_tile (int32_t x, int32_t y) { virtual void update_tile (int32_t x, int32_t y) {
static std::string str = std::string("DFHack: ") + plugin_name + " active"; static std::string str = std::string("DFHack: ") + plugin_name + " active";
Screen::paintString(Screen::Pen(' ', 9, 0), 0, gps->dimy - 1, str); Screen::paintString(Screen::Pen(' ', 9, 0), 0, gps->dimy - 1, str);
for (size_t i = 0; i < gps->dimx; ++i) for (int32_t i = 0; i < gps->dimx; ++i)
((scdata*)screen)[i * gps->dimy + gps->dimy - 1].bg = 2; ((scdata*)screen)[i * gps->dimy + gps->dimy - 1].bg = 2;
renderer_wrap::update_tile(x, y); renderer_wrap::update_tile(x, y);
}; };

@ -63,7 +63,7 @@ command_result rprobe (color_ostream &out, vector <string> & parameters)
CoreSuspender suspend; CoreSuspender suspend;
bool set = false; bool set = false;
int to_set, set_field, set_val; int to_set = -1, set_field = -1, set_val = -1;
// Embark screen active: estimate using world geology data // Embark screen active: estimate using world geology data
VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen()); VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen());
@ -107,16 +107,15 @@ command_result rprobe (color_ostream &out, vector <string> & parameters)
} }
df::world_data *data = world->world_data; df::world_data *data = world->world_data;
coord2d cur_region = screen->location.region_pos;
// Compute biomes // Compute biomes
for (int i = 0; i < screen->location.biome_rgn.size(); i++) for (size_t i = 0; i < screen->location.biome_rgn.size(); i++)
{ {
coord2d rg = screen->location.biome_rgn[i]; coord2d rg = screen->location.biome_rgn[i];
auto rd = &data->region_map[rg.x][rg.y]; auto rd = &data->region_map[rg.x][rg.y];
if (set && i == to_set) { if (set && int(i) == to_set) {
if (set_field == 0) if (set_field == 0)
rd->rainfall = set_val; rd->rainfall = set_val;
else if (set_field == 1) else if (set_field == 1)

@ -29,9 +29,7 @@ using df::global::selection_rect;
using df::building_stockpilest; using df::building_stockpilest;
static command_result copystock(color_ostream &out, vector <string> & parameters);
static command_result stockcheck(color_ostream &out, vector <string> & parameters); static command_result stockcheck(color_ostream &out, vector <string> & parameters);
static bool copystock_guard(df::viewscreen *top);
DFHACK_PLUGIN("stockcheck"); DFHACK_PLUGIN("stockcheck");
@ -122,9 +120,8 @@ static command_result stockcheck(color_ostream &out, vector <string> & parameter
std::vector<StockpileInfo*> stockpiles; std::vector<StockpileInfo*> stockpiles;
for (int i = 0; i < world->buildings.all.size(); ++i) for (df::building *build : world->buildings.all)
{ {
df::building *build = world->buildings.all[i];
auto type = build->getType(); auto type = build->getType();
if (df::enums::building_type::Stockpile == type) if (df::enums::building_type::Stockpile == type)
{ {
@ -239,9 +236,8 @@ static command_result stockcheck(color_ostream &out, vector <string> & parameter
int canHoldCount = 0; int canHoldCount = 0;
StockpileInfo *current = 0; StockpileInfo *current = 0;
for (int idx = 0; idx < stockpiles.size(); idx++) for (StockpileInfo *spi : stockpiles)
{ {
StockpileInfo *spi = stockpiles[idx];
if (spi->canHold(item)) canHoldCount++; if (spi->canHold(item)) canHoldCount++;
if (spi->inStockpile(item)) current=spi; if (spi->inStockpile(item)) current=spi;
} }

@ -24,7 +24,7 @@ struct kitchen_prefs_all_hook : df::viewscreen_kitchenprefst {
exc_type = df::kitchen_exc_type::Brew; exc_type = df::kitchen_exc_type::Brew;
} }
if (flag.whole && cursor < forbidden[page].size()) if (flag.whole && size_t(cursor) < forbidden[page].size())
{ {
bool was_forbidden = forbidden[page][cursor].whole & flag.whole; bool was_forbidden = forbidden[page][cursor].whole & flag.whole;
for (size_t i = 0; i < forbidden[page].size(); i++) for (size_t i = 0; i < forbidden[page].size(); i++)