Fix some Lua things

develop
Chris Dombroski 2015-01-29 16:35:53 -05:00
parent f2eec3198c
commit f608235b1e
6 changed files with 26 additions and 47 deletions

@ -292,9 +292,6 @@ DFHACK_EXPORT bool isActivityZone(df::building * building);
DFHACK_EXPORT bool isPenPasture(df::building * building); DFHACK_EXPORT bool isPenPasture(df::building * building);
DFHACK_EXPORT bool isPitPond(df::building * building); DFHACK_EXPORT bool isPitPond(df::building * building);
DFHACK_EXPORT bool isActive(df::building * building); DFHACK_EXPORT bool isActive(df::building * building);
DFHACK_EXPORT bool isPenPasture(df::building_civzonest * building);
DFHACK_EXPORT bool isPitPond(df::building_civzonest * building);
DFHACK_EXPORT bool isActive(df::building_civzonest * building);
DFHACK_EXPORT df::building* findPenPitAt(df::coord coord); DFHACK_EXPORT df::building* findPenPitAt(df::coord coord);
} }

@ -239,13 +239,13 @@ DFHACK_EXPORT bool isAvailableForAdoption(df::unit* unit);
DFHACK_EXPORT bool isOwnCiv(df::unit* unit); DFHACK_EXPORT bool isOwnCiv(df::unit* unit);
DFHACK_EXPORT bool isOwnRace(df::unit* unit); DFHACK_EXPORT bool isOwnRace(df::unit* unit);
DFHACK_EXPORT std::string getRaceName(int32_t id); DFHACK_EXPORT std::string getRaceNameById(int32_t race_id);
DFHACK_EXPORT std::string getRaceName(df::unit* unit); DFHACK_EXPORT std::string getRaceName(df::unit* unit);
DFHACK_EXPORT std::string getRaceNamePlural(int32_t id); DFHACK_EXPORT std::string getRaceNamePluralById(int32_t race_id);
DFHACK_EXPORT std::string getRaceNamePlural(df::unit* unit); DFHACK_EXPORT std::string getRaceNamePlural(df::unit* unit);
DFHACK_EXPORT std::string getRaceBabyName(int32_t id); DFHACK_EXPORT std::string getRaceBabyNameById(int32_t race_id);
DFHACK_EXPORT std::string getRaceBabyName(df::unit* unit); DFHACK_EXPORT std::string getRaceBabyName(df::unit* unit);
DFHACK_EXPORT std::string getRaceChildName(int32_t id); DFHACK_EXPORT std::string getRaceChildNameById(int32_t race_id);
DFHACK_EXPORT std::string getRaceChildName(df::unit* unit); DFHACK_EXPORT std::string getRaceChildName(df::unit* unit);
DFHACK_EXPORT bool isBaby(df::unit* unit); DFHACK_EXPORT bool isBaby(df::unit* unit);

@ -1188,45 +1188,27 @@ bool Buildings::isPenPasture(df::building * building)
{ {
if (!isActivityZone(building)) if (!isActivityZone(building))
return false; return false;
return isPenPasture((df::building_civzonest*) building);
}
bool Buildings::isPenPasture(df::building_civzonest* civ) return ((df::building_civzonest*) building)->zone_flags.bits.pen_pasture != 0;
{
CHECK_NULL_POINTER(civ);
return civ->zone_flags.bits.pen_pasture != 0;
} }
bool Buildings::isPitPond(df::building * building) bool Buildings::isPitPond(df::building * building)
{ {
if (!isActivityZone(building)) if (!isActivityZone(building))
return false; return false;
return isPitPond((df::building_civzonest *) building); return ((df::building_civzonest*) building)->zone_flags.bits.pit_pond != 0;
}
bool Buildings::isPitPond(df::building_civzonest* civ)
{
CHECK_NULL_POINTER(civ);
return civ->zone_flags.bits.pit_pond != 0;
} }
bool Buildings::isActive(df::building * building) bool Buildings::isActive(df::building * building)
{ {
if (!isActivityZone(building)) if (!isActivityZone(building))
return false; return false;
return isActive((df::building_civzonest *) building); return ((df::building_civzonest*) building)->zone_flags.bits.active != 0;
}
bool Buildings::isActive(df::building_civzonest* civ)
{
CHECK_NULL_POINTER(civ);
return civ->zone_flags.bits.active != 0;
} }
// returns building of pen/pit at cursor position (NULL if nothing found) // returns building of pen/pit at cursor position (NULL if nothing found)
df::building* Buildings::findPenPitAt(df::coord coord) df::building* Buildings::findPenPitAt(df::coord coord)
{ {
CHECK_NULL_POINTER(coord);
vector<df::building_civzonest*> zones; vector<df::building_civzonest*> zones;
Buildings::findCivzonesAt(&zones, coord); Buildings::findCivzonesAt(&zones, coord);
for (auto zone = zones.begin(); zone != zones.end(); ++zone) for (auto zone = zones.begin(); zone != zones.end(); ++zone)

@ -897,7 +897,7 @@ bool Units::isOwnRace(df::unit* unit)
} }
// get race name by id or unit pointer // get race name by id or unit pointer
string Units::getRaceName(int32_t id) string Units::getRaceNameById(int32_t id)
{ {
df::creature_raw *raw = world->raws.creatures.all[id]; df::creature_raw *raw = world->raws.creatures.all[id];
if (raw) if (raw)
@ -907,11 +907,11 @@ string Units::getRaceName(int32_t id)
string Units::getRaceName(df::unit* unit) string Units::getRaceName(df::unit* unit)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);
return getRaceName(unit->race); return getRaceNameById(unit->race);
} }
// get plural of race name (used for display in autobutcher UI and for sorting the watchlist) // get plural of race name (used for display in autobutcher UI and for sorting the watchlist)
string Units::getRaceNamePlural(int32_t id) string Units::getRaceNamePluralById(int32_t id)
{ {
df::creature_raw *raw = world->raws.creatures.all[id]; df::creature_raw *raw = world->raws.creatures.all[id];
if (raw) if (raw)
@ -922,10 +922,10 @@ string Units::getRaceNamePlural(int32_t id)
string Units::getRaceNamePlural(df::unit* unit) string Units::getRaceNamePlural(df::unit* unit)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);
return getRaceNamePlural(unit->race); return getRaceNamePluralById(unit->race);
} }
string Units::getRaceBabyName(int32_t id) string Units::getRaceBabyNameById(int32_t id)
{ {
df::creature_raw *raw = world->raws.creatures.all[id]; df::creature_raw *raw = world->raws.creatures.all[id];
if (raw) if (raw)
@ -936,10 +936,10 @@ string Units::getRaceBabyName(int32_t id)
string Units::getRaceBabyName(df::unit* unit) string Units::getRaceBabyName(df::unit* unit)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);
return getRaceBabyName(unit->race); return getRaceBabyNameById(unit->race);
} }
string Units::getRaceChildName(int32_t id) string Units::getRaceChildNameById(int32_t id)
{ {
df::creature_raw *raw = world->raws.creatures.all[id]; df::creature_raw *raw = world->raws.creatures.all[id];
if (raw) if (raw)
@ -950,7 +950,7 @@ string Units::getRaceChildName(int32_t id)
string Units::getRaceChildName(df::unit* unit) string Units::getRaceChildName(df::unit* unit)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);
return getRaceChildName(unit->race); return getRaceChildNameById(unit->race);
} }
bool Units::isBaby(df::unit* unit) bool Units::isBaby(df::unit* unit)

@ -1109,14 +1109,14 @@ struct preference_map
case (T_type::LikeCreature): case (T_type::LikeCreature):
{ {
label = "Creature :"; label = "Creature :";
Units::getRaceNamePlural(pref.creature_id); Units::getRaceNamePluralById(pref.creature_id);
break; break;
} }
case (T_type::HateCreature): case (T_type::HateCreature):
{ {
label = "Hates :"; label = "Hates :";
Units::getRaceNamePlural(pref.creature_id); Units::getRaceNamePluralById(pref.creature_id);
break; break;
} }

@ -2433,7 +2433,7 @@ public:
{ {
if(!rconfig.isValid()) if(!rconfig.isValid())
{ {
string keyname = "autobutcher/watchlist/" + getRaceName(raceId); string keyname = "autobutcher/watchlist/" + getRaceNameById(raceId);
rconfig = World::GetPersistentData(keyname, NULL); rconfig = World::GetPersistentData(keyname, NULL);
} }
if(rconfig.isValid()) if(rconfig.isValid())
@ -2448,7 +2448,7 @@ public:
else else
{ {
// this should never happen // this should never happen
string keyname = "autobutcher/watchlist/" + getRaceName(raceId); string keyname = "autobutcher/watchlist/" + getRaceNameById(raceId);
out << "Something failed, could not find/create config key " << keyname << "!" << endl; out << "Something failed, could not find/create config key " << keyname << "!" << endl;
} }
} }
@ -2576,8 +2576,8 @@ std::vector<WatchedRace*> watched_races;
// helper for sorting the watchlist alphabetically // helper for sorting the watchlist alphabetically
bool compareRaceNames(WatchedRace* i, WatchedRace* j) bool compareRaceNames(WatchedRace* i, WatchedRace* j)
{ {
string name_i = getRaceNamePlural(i->raceId); string name_i = getRaceNamePluralById(i->raceId);
string name_j = getRaceNamePlural(j->raceId); string name_j = getRaceNamePluralById(j->raceId);
return (name_i < name_j); return (name_i < name_j);
} }
@ -2917,7 +2917,7 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
bool found_race = false; bool found_race = false;
for(size_t i=0; i<num_races; i++) for(size_t i=0; i<num_races; i++)
{ {
if(getRaceName(i) == target_racenames.back()) if(getRaceNameById(i) == target_racenames.back())
{ {
target_raceids.push_back(i); target_raceids.push_back(i);
target_racenames.pop_back(); target_racenames.pop_back();
@ -3054,7 +3054,7 @@ command_result autoButcher( color_ostream &out, bool verbose = false )
watched_races.push_back(w); watched_races.push_back(w);
string announce; string announce;
announce = "New race added to autobutcher watchlist: " + getRaceNamePlural(w->raceId); announce = "New race added to autobutcher watchlist: " + getRaceNamePluralById(w->raceId);
Gui::showAnnouncement(announce, 2, false); Gui::showAnnouncement(announce, 2, false);
autobutcher_sortWatchList(out); autobutcher_sortWatchList(out);
} }
@ -3090,7 +3090,7 @@ command_result autoButcher( color_ostream &out, bool verbose = false )
stringstream ss; stringstream ss;
ss << slaughter_subcount; ss << slaughter_subcount;
string announce; string announce;
announce = getRaceNamePlural(w->raceId) + " marked for slaughter: " + ss.str(); announce = getRaceNamePluralById(w->raceId) + " marked for slaughter: " + ss.str();
Gui::showAnnouncement(announce, 2, false); Gui::showAnnouncement(announce, 2, false);
} }
} }
@ -3527,7 +3527,7 @@ static void autobutcher_setWatchListRace(color_ostream &out, unsigned id, unsign
watched_races.push_back(w); watched_races.push_back(w);
string announce; string announce;
announce = "New race added to autobutcher watchlist: " + getRaceNamePlural(w->raceId); announce = "New race added to autobutcher watchlist: " + getRaceNamePluralById(w->raceId);
Gui::showAnnouncement(announce, 2, false); Gui::showAnnouncement(announce, 2, false);
autobutcher_sortWatchList(out); autobutcher_sortWatchList(out);
} }
@ -3622,7 +3622,7 @@ static int autobutcher_getWatchList(lua_State *L)
WatchedRace * w = watched_races[i]; WatchedRace * w = watched_races[i];
Lua::SetField(L, w->raceId, ctable, "id"); Lua::SetField(L, w->raceId, ctable, "id");
Lua::SetField(L, w->isWatched, ctable, "watched"); Lua::SetField(L, w->isWatched, ctable, "watched");
Lua::SetField(L, getRaceNamePlural(w->raceId), ctable, "name"); Lua::SetField(L, getRaceNamePluralById(w->raceId), ctable, "name");
Lua::SetField(L, w->fk, ctable, "fk"); Lua::SetField(L, w->fk, ctable, "fk");
Lua::SetField(L, w->mk, ctable, "mk"); Lua::SetField(L, w->mk, ctable, "mk");
Lua::SetField(L, w->fa, ctable, "fa"); Lua::SetField(L, w->fa, ctable, "fa");