Skip to content

Commit

Permalink
Change mapgen_function_json_base::setup_setmap to take a const reference
Browse files Browse the repository at this point in the history
And iterate over it via a range-based loop.
  • Loading branch information
BevapDin committed Dec 18, 2019
1 parent 84a53d7 commit f4fa18c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ int jmapgen_int::get() const
* Turn json gobbldigook into machine friendly gobbldigook, for applying
* basic map 'set' functions, optionally based on one_in(chance) or repeat value
*/
void mapgen_function_json_base::setup_setmap( JsonArray &parray )
void mapgen_function_json_base::setup_setmap( const JsonArray &parray )
{
std::string tmpval;
std::map<std::string, jmapgen_setmap_op> setmap_opmap;
Expand All @@ -590,8 +590,7 @@ void mapgen_function_json_base::setup_setmap( JsonArray &parray )
jmapgen_setmap_op tmpop;
int setmap_optype = 0;

while( parray.has_more() ) {
JsonObject pjo = parray.next_object();
for( const JsonObject &pjo : parray ) {
if( pjo.read( "point", tmpval ) ) {
setmap_optype = JMAPGEN_SETMAP_OPTYPE_POINT;
} else if( pjo.read( "set", tmpval ) ) {
Expand Down Expand Up @@ -2304,8 +2303,7 @@ bool mapgen_function_json_base::setup_common( const JsonObject &jo )
}

if( jo.has_array( "set" ) ) {
parray = jo.get_array( "set" );
setup_setmap( parray );
setup_setmap( jo.get_array( "set" ) );
}

// "add" is deprecated in favor of "place_item", but kept to support mods
Expand Down
2 changes: 1 addition & 1 deletion src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class mapgen_function_json_base

void setup_common();
bool setup_common( const JsonObject &jo );
void setup_setmap( JsonArray &parray );
void setup_setmap( const JsonArray &parray );
// Returns true if the mapgen qualifies at this point already
virtual bool setup_internal( const JsonObject &jo ) = 0;
virtual void setup_setmap_internal() { }
Expand Down

0 comments on commit f4fa18c

Please sign in to comment.