Better handling of plants in getplants plugin.

develop
Petr Mrázek 2011-10-29 02:15:36 +02:00
parent a3179093ef
commit 6e3dbbdd72
1 changed files with 15 additions and 9 deletions

@ -80,20 +80,21 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
c->Suspend(); c->Suspend();
Materials *mats = c->getMaterials(); Materials *mats = c->getMaterials();
mats->ReadOrganicMaterials(); for (vector<df_plant_type *>::const_iterator it = mats->df_organic->begin(); it != mats->df_organic->end(); it++)
for (vector<t_matgloss>::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++)
{ {
if (plantNames.find((*it).id) != plantNames.end()) df_plant_type &plant = **it;
if (plantNames.find(plant.ID) != plantNames.end())
{ {
plantNames.erase((*it).id); plantNames.erase(plant.ID);
plantIDs.insert(it - mats->organic.begin()); plantIDs.insert(it - mats->df_organic->begin());
} }
} }
if (plantNames.size() > 0) if (plantNames.size() > 0)
{ {
c->con.printerr("Invalid plant ID(s):"); c->con.printerr("Invalid plant ID(s):");
for (set<string>::const_iterator it = plantNames.begin(); it != plantNames.end(); it++) for (set<string>::const_iterator it = plantNames.begin(); it != plantNames.end(); it++)
c->con.printerr(" %s", (*it).c_str()); c->con.printerr(" %s", it->c_str());
c->con.printerr("\n");
c->Resume(); c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -101,8 +102,13 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
if (plantIDs.size() == 0) if (plantIDs.size() == 0)
{ {
c->con.print("Valid plant IDs:\n"); c->con.print("Valid plant IDs:\n");
for (vector<t_matgloss>::const_iterator it = mats->organic.begin(); it != mats->organic.end(); it++) for (vector<df_plant_type *>::const_iterator it = mats->df_organic->begin(); it != mats->df_organic->end(); it++)
c->con.print("* %s\n", (*it).id.c_str()); {
df_plant_type &plant = **it;
if (plant.flags.is_set(PLANT_GRASS))
continue;
c->con.print("* (%s) %s - %s\n", plant.flags.is_set(PLANT_TREE) ? "tree" : "shrub", plant.ID.c_str(), plant.name.c_str());
}
c->Resume(); c->Resume();
return CR_OK; return CR_OK;
} }
@ -137,7 +143,7 @@ DFhackCExport command_result df_getplants (Core * c, vector <string> & parameter
{ {
for (vector<df_plant *>::const_iterator it = plants->begin(); it != plants->end(); it++) for (vector<df_plant *>::const_iterator it = plants->begin(); it != plants->end(); it++)
{ {
const df_plant &plant = *(*it); const df_plant &plant = **it;
uint32_t tx = plant.x % 16; uint32_t tx = plant.x % 16;
uint32_t ty = plant.y % 16; uint32_t ty = plant.y % 16;
if (plantIDs.find(plant.material) != plantIDs.end()) if (plantIDs.find(plant.material) != plantIDs.end())