Skip to content
Permalink
Browse files

refactor item::is_funnel_container

Use unsigned int as parameter, because it is compared against it_container::contains which is an unsigned int, too.
Return boolean and make the comparison in the function directly instead of after calling. At the same time update the maxcontains value.

And of course check for watertight container to fix CleverRaven#6411
  • Loading branch information...
BevapDin committed Mar 3, 2014
1 parent f111cbe commit d83b722d746ecb31ba881b401b9ba1c6abece121
Showing with 13 additions and 13 deletions.
  1. +8 −7 src/item.cpp
  2. +1 −1 src/item.h
  3. +2 −2 src/map.cpp
  4. +2 −3 src/weather.cpp
@@ -1871,24 +1871,25 @@ bool item::is_watertight_container() const
return ( is_container() != false && has_flag("WATERTIGHT") && has_flag("SEALS") );
}

int item::is_funnel_container(int bigger_than) const
bool item::is_funnel_container(unsigned int &bigger_than) const
{
if ( ! is_container() ) {
return 0;
if ( ! is_watertight_container() ) {
return false;
}
it_container *ct = dynamic_cast<it_container *>(type);
// todo; consider linking funnel to item or -making- it an active item
if ( (int)ct->contains <= bigger_than ) {
return 0; // skip contents check, performance
if ( ct->contains <= bigger_than ) {
return false; // skip contents check, performance
}
if (
contents.empty() ||
contents[0].typeId() == "water" ||
contents[0].typeId() == "water_acid" ||
contents[0].typeId() == "water_acid_weak") {
return (int)ct->contains;
bigger_than = ct->contains;
return true;
}
return 0;
return false;
}

bool item::is_tool() const
@@ -202,7 +202,7 @@ class item : public JsonSerializer, public JsonDeserializer
bool is_book() const;
bool is_container() const;
bool is_watertight_container() const;
int is_funnel_container(int bigger_than) const;
bool is_funnel_container(unsigned int &bigger_than) const;

bool is_tool() const;
bool is_software() const;
@@ -4111,7 +4111,7 @@ bool map::loadn(const int worldx, const int worldy, const int worldz,
for (int x = 0; x < SEEX; x++) {
for (int y = 0; y < SEEY; y++) {
int biggest_container_idx = -1;
int maxvolume = 0;
unsigned int maxvolume = 0;
bool do_container_check = false;

if ( do_funnels && ! rain_backlog.empty() && rain_backlog.find(point(x,y)) != rain_backlog.end() ) {
@@ -4122,7 +4122,7 @@ bool map::loadn(const int worldx, const int worldy, const int worldz,
for(std::vector<item, std::allocator<item> >::iterator it = tmpsub->itm[x][y].begin();
it != tmpsub->itm[x][y].end();) {
if ( do_container_check == true ) { // cannot link trap to mapitems
if ( it->is_funnel_container(maxvolume) > maxvolume ) { // biggest
if ( it->is_funnel_container(maxvolume) ) { // biggest
biggest_container_idx = intidx; // this will survive erases below, it ptr may not
}
}
@@ -220,7 +220,7 @@ void fill_funnels(int rain_depth_mm_per_hour, bool acid, trap_id t)
std::set<point>::iterator i;
for (i = funnel_locs.begin(); i != funnel_locs.end(); ++i) {
item *c = NULL;
char maxcontains = 0;
unsigned int maxcontains = 0;
point loc = *i;
std::vector<item>& items = g->m.i_at(loc.x, loc.y);
if (one_in(turns_per_charge)) { // todo; fixme. todo; fixme
@@ -230,8 +230,7 @@ void fill_funnels(int rain_depth_mm_per_hour, bool acid, trap_id t)
// impure water and acid.
for (int j = 0; j < items.size(); j++) {
item *it = &(items[j]);
int ismax = it->is_funnel_container( maxcontains );
if ( ismax > maxcontains ) {
if ( it->is_funnel_container( maxcontains ) ) {
c = it;
}
}

0 comments on commit d83b722

Please sign in to comment.
You can’t perform that action at this time.