Skip to content

Commit

Permalink
Modify a number of commands to use CR_WRONG_USAGE for displaying help.
Browse files Browse the repository at this point in the history
  • Loading branch information
angavrilov committed Jan 28, 2012
1 parent c59f5c1 commit fa4fb4b
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 204 deletions.
1 change: 1 addition & 0 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue
"by clicking on the program icon in the top bar of the window.\n\n"
"Basic commands:\n"
" help|? - This text.\n"
" help COMMAND - Usage help for the given command.\n"
" ls|dir [PLUGIN] - List available commands. Optionally for single plugin.\n"
" cls - Clear the console.\n"
" fpause - Force DF to pause.\n"
Expand Down
29 changes: 13 additions & 16 deletions plugins/autodump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("autodump",
"Teleport items marked for dumping to the cursor.",
df_autodump));
commands.push_back(PluginCommand(
"autodump", "Teleport items marked for dumping to the cursor.",
df_autodump, false,
" This utility lets you quickly move all items designated to be dumped.\n"
" Items are instantly moved to the cursor position, the dump flag is unset,\n"
" and the forbid flag is set, as if it had been dumped normally.\n"
" Be aware that any active dump item tasks still point at the item.\n"
"Options:\n"
" destroy - instead of dumping, destroy the items instantly.\n"
" destroy-here - only affect the tile under cursor.\n"
));
commands.push_back(PluginCommand(
"autodump-destroy-here", "Destroy items marked for dumping under cursor.",
df_autodump_destroy_here, cursor_hotkey,
Expand Down Expand Up @@ -81,19 +89,8 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
destroy = true;
else if (p == "destroy-here")
destroy = here = true;
else if(p == "?" || p == "help")
{
c->con.print(
"This utility lets you quickly move all items designated to be dumped.\n"
"Items are instantly moved to the cursor position, the dump flag is unset,\n"
"and the forbid flag is set, as if it had been dumped normally.\n"
"Be aware that any active dump item tasks still point at the item.\n\n"
"Options:\n"
"destroy - instead of dumping, destroy the items instantly.\n"
"destroy-here - only affect the tile under cursor.\n"
);
return CR_OK;
}
else
return CR_WRONG_USAGE;
}

DFHack::VersionInfo *mem = c->vinfo;
Expand Down
50 changes: 25 additions & 25 deletions plugins/cleaners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ DFhackCExport command_result spotclean (Core * c, vector <string> & parameters)

DFhackCExport command_result clean (Core * c, vector <string> & parameters)
{
bool help = false;
bool map = false;
bool snow = false;
bool mud = false;
Expand All @@ -168,33 +167,16 @@ DFhackCExport command_result clean (Core * c, vector <string> & parameters)
items = true;
units = true;
}
if(parameters[i] == "snow")
else if(parameters[i] == "snow")
snow = true;
else if(parameters[i] == "mud")
mud = true;
else if(parameters[i] == "help" ||parameters[i] == "?")
{
help = true;
}
else
return CR_WRONG_USAGE;
}
if(!map && !units && !items)
help = true;
if(help)
{
c->con.print("Removes contaminants from map tiles, items and creatures.\n"
"Options:\n"
"map - clean the map tiles\n"
"items - clean all items\n"
"units - clean all creatures\n"
"all - clean everything.\n"
"More options for 'map':\n"
"snow - also remove snow\n"
"mud - also remove mud\n"
"Example: clean all mud snow\n"
"This removes all spatter, including mud and snow from map tiles.\n"
);
return CR_OK;
}
return CR_WRONG_USAGE;

CoreSuspender suspend(c);
if(map)
cleanmap(c,snow,mud);
Expand All @@ -213,8 +195,26 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("clean","Removes contaminants from map tiles, items and creatures.",clean));
commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean,cursor_hotkey));
commands.push_back(PluginCommand(
"clean","Removes contaminants from map tiles, items and creatures.",
clean, false,
" Removes contaminants from map tiles, items and creatures.\n"
"Options:\n"
" map - clean the map tiles\n"
" items - clean all items\n"
" units - clean all creatures\n"
" all - clean everything.\n"
"More options for 'map':\n"
" snow - also remove snow\n"
" mud - also remove mud\n"
"Example:\n"
" clean all mud snow\n"
" Removes all spatter, including mud and snow from map tiles.\n"
));
commands.push_back(PluginCommand(
"spotclean","Cleans map tile under cursor.",
spotclean,cursor_hotkey
));
return CR_OK;
}

Expand Down
44 changes: 18 additions & 26 deletions plugins/cleanowned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("cleanowned",
"Confiscates and dumps garbage owned by dwarfs.",
df_cleanowned));
commands.push_back(PluginCommand(
"cleanowned", "Confiscates and dumps garbage owned by dwarfs.",
df_cleanowned, false,
" This tool lets you confiscate and dump all the garbage\n"
" dwarves ultimately accumulate.\n"
" By default, only rotten and dropped food is confiscated.\n"
"Options:\n"
" dryrun - don't actually do anything, just print what would be done.\n"
" scattered - confiscate owned items on the ground\n"
" all - confiscate everything\n"
" x - confiscate & dump 'x' and worse damaged items\n"
" X - confiscate & dump 'X' and worse damaged items\n"
"Example:\n"
" confiscate scattered X\n"
" This will confiscate rotten and dropped food, garbage on the floors\n"
" and any worn items wit 'X' damage and above.\n"
));
return CR_OK;
}

Expand Down Expand Up @@ -67,30 +81,8 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
wear_dump_level = 1;
else if(param == "X")
wear_dump_level = 2;
else if(param == "?" || param == "help")
{
c->con.print("This tool lets you confiscate and dump all the garbage\n"
"dwarves ultimately accumulate.\n"
"By default, only rotten and dropped food is confiscated.\n"
"Options:\n"
" dryrun - don't actually do anything, just print what would be done.\n"
" scattered - confiscate owned items on the ground\n"
" all - confiscate everything\n"
" x - confiscate & dump 'x' and worse damaged items\n"
" X - confiscate & dump 'X' and worse damaged items\n"
" ? - this help\n"
"Example:\n"
" confiscate scattered X\n"
" This will confiscate rotten and dropped food, garbage on the floors\n"
" and any worn items wit 'X' damage and above.\n"
);
return CR_OK;
}
else
{
c->con.printerr("Parameter '%s' is not valid. See 'cleanowned help'.\n",param.c_str());
return CR_FAILURE;
}
return CR_WRONG_USAGE;
}

CoreSuspender suspend(c);
Expand Down
27 changes: 10 additions & 17 deletions plugins/colonies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("colonies",
"List or change wild colonies (ants hills and such)",
colonies));
commands.push_back(PluginCommand(
"colonies", "List or change wild colonies (ants hills and such)",
colonies, false,
" Without any options, this command lists all the vermin colonies present.\n"
"Options:\n"
" kill - destroy colonies\n"
" bees - turn colonies into honey bees\n"
));
return CR_OK;
}

Expand All @@ -41,27 +46,15 @@ DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
{
bool destroy = false;
bool convert = false;
bool help = false;

for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "kill")
destroy = true;
else if(parameters[i] == "bees")
convert = true;
else if(parameters[i] == "help" || parameters[i] == "?")
{
help = true;
}
}
if(help)
{
c->con.print("Without any options, this command lists all the vermin colonies present.\n"
"Options:\n"
"kill - destroy colonies\n"
"bees - turn colonies into honey bees\n"
);
return CR_OK;
else
return CR_WRONG_USAGE;
}
if (destroy && convert)
{
Expand Down
23 changes: 9 additions & 14 deletions plugins/deramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ using df::global::world;

DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
{
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "help" || parameters[i] == "?")
{
c->con.print("This command does two things:\n"
"If there are any ramps designated for removal, they will be instantly removed.\n"
"Any ramps that don't have their counterpart will be removed (fixes bugs with caveins)\n"
);
return CR_OK;
}
}
if (!parameters.empty())
return CR_WRONG_USAGE;

CoreSuspender suspend(c);

Expand Down Expand Up @@ -97,9 +88,13 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("deramp",
"De-ramp. All ramps marked for removal are replaced with floors.",
df_deramp));
commands.push_back(PluginCommand(
"deramp", "De-ramp. All ramps marked for removal are replaced with floors.",
df_deramp, false,
" If there are any ramps designated for removal, they will be instantly\n"
" removed. Any ramps that don't have their counterpart will also be removed\n"
" (fixes bugs with caveins)\n"
));
return CR_OK;
}

Expand Down
73 changes: 38 additions & 35 deletions plugins/filltraffic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,34 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("filltraffic","Flood-fill with selected traffic designation from cursor",filltraffic));
commands.push_back(PluginCommand("alltraffic","Set traffic for the entire map",alltraffic));

commands.push_back(PluginCommand(
"filltraffic","Flood-fill with selected traffic designation from cursor",
filltraffic, cursor_hotkey,
" Flood-fill selected traffic type from the cursor.\n"
"Traffic Type Codes:\n"
" H: High Traffic\n"
" N: Normal Traffic\n"
" L: Low Traffic\n"
" R: Restricted Traffic\n"
"Other Options:\n"
" X: Fill across z-levels.\n"
" B: Include buildings and stockpiles.\n"
" P: Include empty space.\n"
"Example:\n"
" filltraffic H\n"
" When used in a room with doors,\n"
" it will set traffic to HIGH in just that room.\n"
));
commands.push_back(PluginCommand(
"alltraffic","Set traffic for the entire map",
alltraffic, false,
" Set traffic types for all tiles on the map.\n"
"Traffic Type Codes:\n"
" H: High Traffic\n"
" N: Normal Traffic\n"
" L: Low Traffic\n"
" R: Restricted Traffic\n"
));
return CR_OK;
}

Expand All @@ -55,6 +80,8 @@ DFhackCExport command_result plugin_shutdown ( Core * c )

DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::string> & params)
{
// HOTKEY COMMAND; CORE ALREADY SUSPENDED

//Maximum map size.
uint32_t x_max,y_max,z_max;
//Source and target traffic types.
Expand All @@ -68,24 +95,8 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
//Loop through parameters
for(int i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
c->con.print("Flood-fill selected traffic type from the cursor.\n"
"Traffic Type Codes:\n"
"\tH: High Traffic\n"
"\tN: Normal Traffic\n"
"\tL: Low Traffic\n"
"\tR: Restricted Traffic\n"
"Other Options:\n"
"\tX: Fill across z-levels.\n"
"\tB: Include buildings and stockpiles.\n"
"\tP: Include empty space.\n"
"Example:\n"
"'filltraffic H' - When used in a room with doors,\n"
" it will set traffic to HIGH in just that room."
);
return CR_OK;
}
if (params[i] == "help" || params[i] == "?" || params[i].size() != 1)
return CR_WRONG_USAGE;

switch (toupper(params[i][0]))
{
Expand All @@ -103,12 +114,11 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::stri
checkbuilding = false; break;
case 'P':
checkpit = false; break;
default:
return CR_WRONG_USAGE;
}
}

//Initialization.
CoreSuspender suspend(c);

DFHack::Gui * Gui = c->getGui();
if (!Maps::IsValid())
{
Expand Down Expand Up @@ -238,17 +248,8 @@ DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector<std::strin
//Loop through parameters
for(int i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
c->con.print("Set traffic types for all tiles on the map.\n"
"Traffic Type Codes:\n"
" H: High Traffic\n"
" N: Normal Traffic\n"
" L: Low Traffic\n"
" R: Restricted Traffic\n"
);
return CR_OK;
}
if (params[i] == "help" || params[i] == "?" || params[i].size() != 1)
return CR_WRONG_USAGE;

//Pick traffic type. Possibly set bounding rectangle later.
switch (toupper(params[i][0]))
Expand All @@ -261,6 +262,8 @@ DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector<std::strin
proc = allLow; break;
case 'R':
proc = allRestricted; break;
default:
return CR_WRONG_USAGE;
}
}

Expand Down
Loading

0 comments on commit fa4fb4b

Please sign in to comment.