Initialize maps in a MSVC 2010-compatible way

develop
lethosor 2016-04-22 18:45:32 -04:00
parent 52728babd4
commit 8784a133e8
1 changed files with 49 additions and 49 deletions

@ -1317,48 +1317,47 @@ df::building* getAssignableBuildingAtCursor(color_ostream& out)
// ZONE FILTERS (as in, filters used by 'zone') // ZONE FILTERS (as in, filters used by 'zone')
// Maps parameter names to filters. // Maps parameter names to filters.
unordered_map<string, function<bool(df::unit*)>> zone_filters = { unordered_map<string, function<bool(df::unit*)>> zone_filters;
{ "caged", isContainedInItem }, static struct zone_filters_init { zone_filters_init() {
{ "egglayer", isEggLayer }, zone_filters["caged"] = isContainedInItem;
{ "female", isFemale }, zone_filters["egglayer"] = isEggLayer;
{ "grazer", isGrazer }, zone_filters["female"] = isFemale;
{ "hunting", isHunter }, zone_filters["grazer"] = isGrazer;
{ "male", isMale }, zone_filters["hunting"] = isHunter;
{ "milkable", isMilkable }, zone_filters["male"] = isMale;
{ "naked", isNaked }, zone_filters["milkable"] = isMilkable;
{ "own", isOwnCiv }, zone_filters["naked"] = isNaked;
{ "tamable", isTamable }, zone_filters["own"] = isOwnCiv;
{ "tame", isTame }, zone_filters["tamable"] = isTamable;
{ "trainablewar", [](df::unit *unit) -> bool zone_filters["tame"] = isTame;
{ zone_filters["trainablewar"] = [](df::unit *unit) -> bool
return !isWar(unit) && !isHunter(unit) && isTrainableWar(unit); {
} return !isWar(unit) && !isHunter(unit) && isTrainableWar(unit);
}, };
{ "trainablehunt", [](df::unit *unit) -> bool zone_filters["trainablehunt"] = [](df::unit *unit) -> bool
{ {
return !isWar(unit) && !isHunter(unit) && isTrainableHunting(unit); return !isWar(unit) && !isHunter(unit) && isTrainableHunting(unit);
} };
}, zone_filters["trained"] = isTrained;
{ "trained", isTrained },
// backwards compatibility // backwards compatibility
{ "unassigned", [](df::unit *unit) -> bool zone_filters["unassigned"] = [](df::unit *unit) -> bool
{ {
return !isAssigned(unit); return !isAssigned(unit);
} };
}, zone_filters["war"] = isWar;
{ "war", isWar }, }} zone_filters_init_;
};
// Extra annotations / descriptions for parameter names. // Extra annotations / descriptions for parameter names.
unordered_map<string, string> zone_filter_notes = { unordered_map<string, string> zone_filter_notes;
{ "caged", "caged (ignores built cages)" }, static struct zone_filter_notes_init { zone_filter_notes_init() {
{ "hunting", "trained hunting creature" }, zone_filter_notes["caged"] = "caged (ignores built cages)";
{ "named", "has name or nickname" }, zone_filter_notes["hunting"] = "trained hunting creature";
{ "own", "own civilization" }, zone_filter_notes["named"] = "has name or nickname";
{ "trainablehunt", "trainable for hunting" }, zone_filter_notes["own"] = "own civilization";
{ "trainablewar", "trainable for war" }, zone_filter_notes["trainablehunt"] = "trainable for hunting";
{ "war", "trained war creature" }, zone_filter_notes["trainablewar"] = "trainable for war";
}; zone_filter_notes["war"] = "trained war creature";
}} zone_filter_notes_init_;
pair<string, function<bool(df::unit*)>> createRaceFilter(vector<string> &filter_args) pair<string, function<bool(df::unit*)>> createRaceFilter(vector<string> &filter_args)
{ {
@ -1463,12 +1462,13 @@ pair<string, function<bool(df::unit*)>> createMaxAgeFilter(vector<string> &filte
// Result filter functions are not permitted to throw std::exceptions. // Result filter functions are not permitted to throw std::exceptions.
// Result filter functions should not store references // Result filter functions should not store references
unordered_map<string, pair<int, unordered_map<string, pair<int,
function<pair<string, function<bool(df::unit*)>>(vector<string>&)>>> zone_param_filters = { function<pair<string, function<bool(df::unit*)>>(vector<string>&)>>> zone_param_filters;
{ "race", { 1, createRaceFilter } }, static struct zone_param_filters_init { zone_param_filters_init() {
{ "age", { 1, createAgeFilter } }, zone_param_filters["race"] = { 1, createRaceFilter };
{ "minage", { 1, createMinAgeFilter } }, zone_param_filters["age"] = { 1, createAgeFilter };
{ "maxage", { 1, createMaxAgeFilter } }, zone_param_filters["minage"] = { 1, createMinAgeFilter };
}; zone_param_filters["maxage"] = { 1, createMaxAgeFilter };
}} zone_param_filters_init_;
command_result df_zone (color_ostream &out, vector <string> & parameters) command_result df_zone (color_ostream &out, vector <string> & parameters)
{ {
@ -1616,7 +1616,7 @@ command_result df_zone (color_ostream &out, vector <string> & parameters)
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
} }
} }
out << "Unassigning unit(s) from building..." << endl; out << "Unassigning unit(s) from building..." << endl;
building_unassign = true; building_unassign = true;
start_index = 1; start_index = 1;
@ -1632,7 +1632,7 @@ command_result df_zone (color_ostream &out, vector <string> & parameters)
const char* const building_type = p0 == "assign" ? "building" : "cage zone"; const char* const building_type = p0 == "assign" ? "building" : "cage zone";
// if followed by another parameter, check if it's numeric // if followed by another parameter, check if it's numeric
bool target_building_given = false; bool target_building_given = false;
if(parameters.size() >= 2) if(parameters.size() >= 2)
{ {
@ -2137,13 +2137,13 @@ command_result df_zone (color_ostream &out, vector <string> & parameters)
else if(building_unassign) else if(building_unassign)
{ {
bool removed = unassignUnitFromBuilding(unit); bool removed = unassignUnitFromBuilding(unit);
if (removed) if (removed)
{ {
out << "Unit " << unit->id out << "Unit " << unit->id
<< "(" << getRaceName(unit) << ")" << "(" << getRaceName(unit) << ")"
<< " unassigned from"; << " unassigned from";
if (isActivityZone(target_building)) if (isActivityZone(target_building))
{ {
out << " zone "; out << " zone ";