CleverRaven/Cataclysm-DDA — pull request #3828 by atomicdryad (2013-10-23 21:37:01+00:00)
Title: map: add field functions to match add/remove_field style invocation, and simlify code

int get_field_age(const point p, const field_id t);
int get_field_strength(const point p, const field_id t);
int adjust_field_age(const point p, const field_id t, const int offset);
int adjust_field_strength(game *g, const point p, const field_id t, const int offset);
int set_field_age(const point p, const field_id t, const int age, bool isoffset = false);
int set_field_strength(game *g, const point p, const field_id t, const int str, bool isoffset = false);
field_entry * get_field( const point p, const field_id t );
as per:
bool add_field(game *g, const point p, const field_id t, unsigned int density, const int age);
bool add_field(game *g, const int x, const int y, const field_id t, const unsigned char density);
void remove_field(const int x, const int y, const field_id field_to_remove);
removing the need to:
field & usedonlyonce = m.field_at(x, y);
if ( usedonlyonce.findField(fd_fire) ) {
if ( usedonlyonce.findField(fd_fire).getDensity() == 1 ) {
m.remove_field(x,y, fd_fire);
} else {
usedonlyonce.findField(fd_fire).setDensity(usedonlyonce.findField(fd_fire).getDensity() - 1);
}
}
in favor of:
m.adjust_field_strength(x, y, fd_fire, -1);