bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) { if( jsobj.has_object(member) ) { JsonObject j = jsobj.get_object(member); if ( jsonint(j, "num_tests", num_tests ) == false ) { if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) { num_tests = 1; } } else if ( num_tests > 0 ) { str_min = j.get_int("str_min"); str_max = j.get_int("str_max"); } jsonint(j, "str_min_blocked", str_min_blocked ); jsonint(j, "str_max_blocked", str_max_blocked ); jsonint(j, "str_min_roll", str_min_roll ); jsonint(j, "chance", chance ); jsonstring(j, "sound", sound ); jsonstring(j, "sound_fail", sound_fail ); if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) { ter_set = "t_rubble"; debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() ); } if ( j.has_array("items") ) { JsonArray ja = j.get_array("items"); if (ja.size() > 0) { int c=0; while ( ja.has_more() ) { if ( ja.has_object(c) ) { JsonObject jio = ja.next_object(); if ( jio.has_string("item") && jio.has_int("amount") ) { if ( jio.has_int("minamount") ) { map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") ); jsonint(jio, "chance", drop.chance); items.push_back(drop); } else { map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") ); jsonint(jio, "chance", drop.chance); items.push_back(drop); } } else { debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c); } } else { debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c); } c++; } } } //debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() ); return true; } else { return false; } }
void load_map_bash_item_drop_list(JsonArray ja, std::vector<map_bash_item_drop> &items) { while ( ja.has_more() ) { JsonObject jio = ja.next_object(); if ( jio.has_int("minamount") ) { map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") ); jsonint(jio, "chance", drop.chance); items.push_back(drop); } else { map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") ); jsonint(jio, "chance", drop.chance); items.push_back(drop); } } }
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) { if( jsobj.has_object(member) ) { JsonObject j = jsobj.get_object(member); if ( jsonint(j, "num_tests", num_tests ) == false ) { if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) { num_tests = 1; } } else if ( num_tests > 0 ) { str_min = j.get_int("str_min"); str_max = j.get_int("str_max"); } jsonint(j, "str_min_blocked", str_min_blocked ); jsonint(j, "str_max_blocked", str_max_blocked ); jsonint(j, "str_min_roll", str_min_roll ); jsonint(j, "explosive", explosive ); jsonint(j, "chance", chance ); jsonstring(j, "sound", sound ); jsonstring(j, "sound_fail", sound_fail ); jsonstring(j, "furn_set", furn_set ); if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) { ter_set = "t_rubble"; debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() ); } if ( j.has_array("items") ) { load_map_bash_item_drop_list(j.get_array("items"), items); } //debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() ); return true; } else { return false; } }