Example #1
0
void load_furniture(JsonObject &jsobj)
{
  if ( furnlist.empty() ) {
      furn_t new_null = null_furniture_t();
      furnmap[new_null.id] = new_null;
      furnlist.push_back(new_null);
  }
  furn_t new_furniture;
  new_furniture.id = jsobj.get_string("id");
  if ( new_furniture.id == "f_null" ) {
      return;
  }
  new_furniture.name = _(jsobj.get_string("name").c_str());
  new_furniture.sym = jsobj.get_string("symbol").c_str()[0];

  bool has_color = jsobj.has_member("color");
  bool has_bgcolor = jsobj.has_member("bgcolor");
  if(has_color && has_bgcolor) {
    debugmsg("Found both color and bgcolor for %s, use only one of these.", new_furniture.name.c_str());
    new_furniture.color = c_white;
  } else if(has_color) {
    new_furniture.color = color_from_string(jsobj.get_string("color"));
  } else if(has_bgcolor) {
    new_furniture.color = bgcolor_from_string(jsobj.get_string("bgcolor"));
  } else {
    debugmsg("Furniture %s needs at least one of: color, bgcolor.", new_furniture.name.c_str());
  }

  new_furniture.movecost = jsobj.get_int("move_cost_mod");
  new_furniture.move_str_req = jsobj.get_int("required_str");

  new_furniture.transparent = false;
  new_furniture.bitflags = 0;
  JsonArray flags = jsobj.get_array("flags");
  while(flags.has_more()) {
    new_furniture.set_flag(flags.next_string());
  }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_furniture.examine = iexamine_function_from_string(function_name);
  } else {
    //If not specified, default to no action
    new_furniture.examine = iexamine_function_from_string("none");
  }

  new_furniture.open = "";
  if ( jsobj.has_member("open") ) {
      new_furniture.open = jsobj.get_string("open");
  }
  new_furniture.close = "";
  if ( jsobj.has_member("close") ) {
      new_furniture.close = jsobj.get_string("close");
  }
  new_furniture.bash.load(jsobj, "bash", true);

  new_furniture.loadid = furnlist.size();
  furnmap[new_furniture.id] = new_furniture;
  furnlist.push_back(new_furniture);
}
Example #2
0
void furn_t::load( JsonObject &jo )
{
    mandatory( jo, was_loaded, "name", name, translated_string_reader );
    mandatory( jo, was_loaded, "move_cost_mod", movecost );
    mandatory( jo, was_loaded, "required_str", move_str_req );
    optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE );
    optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" );

    load_symbol( jo );
    transparent = false;

    for( auto & flag : jo.get_string_array( "flags" ) ) {
        set_flag( flag );
    }

    if( jo.has_member( "examine_action" ) ) {
        examine = iexamine_function_from_string( jo.get_string( "examine_action" ) );
    } else {
        examine = iexamine_function_from_string( "none" );
    }

    optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, NULL_ID );
    optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, NULL_ID );

    bash.load( jo, "bash", true );
    deconstruct.load( jo, "deconstruct", true );
}
Example #3
0
void ter_t::load( JsonObject &jo )
{
    mandatory( jo, was_loaded, "name", name, translated_string_reader );
    mandatory( jo, was_loaded, "move_cost", movecost );
    optional( jo, was_loaded, "max_volume", max_volume, MAX_VOLUME_IN_SQUARE );
    optional( jo, was_loaded, "trap", trap_id_str );

    load_symbol( jo );

    trap = tr_null;
    transparent = false;
    connect_group = TERCONN_NONE;

    for( auto &flag : jo.get_string_array( "flags" ) ) {
        set_flag( flag );
    }
    // connect_group is initialised to none, then terrain flags are set, then finally
    // connections from JSON are set. This is so that wall flags can set wall connections
    // but can be overridden by explicit connections in JSON.
    if( jo.has_member( "connects_to" ) ) {
        set_connects( jo.get_string( "connects_to" ) );
    }

    if( jo.has_member( "examine_action" ) ) {
        examine = iexamine_function_from_string( jo.get_string( "examine_action" ) );
    } else {
        examine = iexamine_function_from_string( "none" );
    }

    optional( jo, was_loaded, "harvestable", harvestable );
    optional( jo, was_loaded, "open", open, NULL_ID );
    optional( jo, was_loaded, "close", close, NULL_ID );
    optional( jo, was_loaded, "transforms_into", transforms_into, NULL_ID );
    optional( jo, was_loaded, "roof", roof, NULL_ID );

    if( jo.has_member("harvest_season") ) {
        const std::string season = jo.get_string( "harvest_season" );

        if( season == "SPRING" ) {
            harvest_season = season_type::SPRING;
        } else if( season == "SUMMER" ) {
            harvest_season = season_type::SUMMER;
        } else if( season == "AUTUMN" ) {
            harvest_season = season_type::AUTUMN;
        } else if( season == "WINTER" ) {
            harvest_season = season_type::WINTER;
        } else {
            harvest_season = season_type::AUTUMN;
            debugmsg( "Invalid harvest season \"%s\" in \"%s\".", season.c_str(), id.c_str() );
        }
    }

    bash.load( jo, "bash", false );
    deconstruct.load( jo, "deconstruct", false );
}
Example #4
0
void load_furniture(JsonObject &jsobj)
{
  if ( furnlist.empty() ) {
      furn_t new_null = null_furniture_t();
      furnmap[new_null.id] = new_null;
      furnlist.push_back(new_null);
  }
  furn_t new_furniture;
  new_furniture.id = jsobj.get_string("id");
  if ( new_furniture.id == "f_null" ) {
      return;
  }
  new_furniture.name = _(jsobj.get_string("name").c_str());

    new_furniture.load_symbol( jsobj );

  new_furniture.movecost = jsobj.get_int("move_cost_mod");
  new_furniture.move_str_req = jsobj.get_int("required_str");
  new_furniture.max_volume = jsobj.get_int("max_volume", MAX_VOLUME_IN_SQUARE);

  new_furniture.crafting_pseudo_item = jsobj.get_string("crafting_pseudo_item", "");

  new_furniture.transparent = false;
    for( auto & flag : jsobj.get_string_array( "flags" ) ) {
        new_furniture.set_flag( flag );
    }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_furniture.examine = iexamine_function_from_string(function_name);
  } else {
    //If not specified, default to no action
    new_furniture.examine = iexamine_function_from_string("none");
  }

  new_furniture.open = "";
  if ( jsobj.has_member("open") ) {
      new_furniture.open = jsobj.get_string("open");
  }
  new_furniture.close = "";
  if ( jsobj.has_member("close") ) {
      new_furniture.close = jsobj.get_string("close");
  }
  new_furniture.bash.load(jsobj, "bash", true);
  new_furniture.deconstruct.load(jsobj, "deconstruct", true);

  new_furniture.loadid = furn_id( furnlist.size() );
  furnmap[new_furniture.id] = new_furniture;
  furnlist.push_back(new_furniture);
}
Example #5
0
void map_data_common_t::load( JsonObject &jo, const std::string &src )
{
    if( jo.has_member( "examine_action" ) ) {
        examine = iexamine_function_from_string( jo.get_string( "examine_action" ) );
    } else {
        examine = iexamine_function_from_string( "none" );
    }

    if( jo.has_array( "harvest_by_season" ) ) {
        JsonArray jsarr = jo.get_array( "harvest_by_season" );
        while( jsarr.has_more() ) {
            JsonObject harvest_jo = jsarr.next_object();
            auto season_strings = harvest_jo.get_tags( "seasons" );
            std::set<season_type> seasons;
            std::transform( season_strings.begin(), season_strings.end(), std::inserter( seasons,
                            seasons.begin() ),
            []( const std::string & data ) {
                return io::string_to_enum<season_type>( data );
            } );

            harvest_id hl;
            if( harvest_jo.has_array( "entries" ) ) {
                // @todo: A better inline name - can't use id or name here because it's not set yet
                size_t num = harvest_list::all().size() + 1;
                hl = harvest_list::load( harvest_jo, src,
                                         string_format( "harvest_inline_%d", static_cast<int>( num ) ) );
            } else if( harvest_jo.has_string( "id" ) ) {
                hl = harvest_id( harvest_jo.get_string( "id" ) );
            } else {
                jo.throw_error( "Each harvest entry must specify either \"entries\" or \"id\"",
                                "harvest_by_season" );
            }

            for( season_type s : seasons ) {
                harvest_by_season[ s ] = hl;
            }
        }
    }

    optional( jo, false, "description", description, translated_string_reader );
}
Example #6
0
furn_t null_furniture_t() {
  furn_t new_furniture;
  new_furniture.id = furn_str_id::NULL_ID();
  new_furniture.name_ = translate_marker( "nothing" );
  new_furniture.symbol_.fill( ' ' );
  new_furniture.color_.fill( c_white );
  new_furniture.movecost = 0;
  new_furniture.move_str_req = -1;
  new_furniture.transparent = true;
  new_furniture.set_flag("TRANSPARENT");
  new_furniture.examine = iexamine_function_from_string("none");
  new_furniture.max_volume = DEFAULT_MAX_VOLUME_IN_SQUARE;
  return new_furniture;
}
Example #7
0
ter_t null_terrain_t() {
  ter_t new_terrain;

  new_terrain.id = ter_str_id::NULL_ID();
  new_terrain.name_ = translate_marker( "nothing" );
  new_terrain.symbol_.fill( ' ' );
  new_terrain.color_.fill( c_white );
  new_terrain.movecost = 0;
  new_terrain.transparent = true;
  new_terrain.set_flag("TRANSPARENT");
  new_terrain.set_flag("DIGGABLE");
  new_terrain.examine = iexamine_function_from_string("none");
  new_terrain.max_volume = DEFAULT_MAX_VOLUME_IN_SQUARE;
  return new_terrain;
}
Example #8
0
ter_t null_terrain_t() {
  ter_t new_terrain;
  new_terrain.id = "t_null";
  new_terrain.name = _("nothing");
  new_terrain.sym = ' ';
  new_terrain.color = c_white;
  new_terrain.movecost = 2;
  new_terrain.transparent = true;
  new_terrain.bitflags = 0;
  new_terrain.set_flag("TRANSPARENT");
  new_terrain.set_flag("DIGGABLE");
  new_terrain.examine = iexamine_function_from_string("none");
  new_terrain.loadid = 0;
  new_terrain.open = "";
  new_terrain.close = "";
  return new_terrain;
};
Example #9
0
furn_t null_furniture_t() {
  furn_t new_furniture;
  new_furniture.id = "f_null";
  new_furniture.name = _("nothing");
  new_furniture.sym = ' ';
  new_furniture.color = c_white;
  new_furniture.movecost = 0;
  new_furniture.move_str_req = -1;
  new_furniture.transparent = true;
  new_furniture.bitflags = 0;
  new_furniture.set_flag("TRANSPARENT");
  new_furniture.examine = iexamine_function_from_string("none");
  new_furniture.loadid = 0;
  new_furniture.open = "";
  new_furniture.close = "";
  return new_furniture;
};
Example #10
0
furn_t null_furniture_t() {
  furn_t new_furniture;
  new_furniture.id = "f_null";
  new_furniture.name = _("nothing");
  new_furniture.symbol_.fill( ' ' );
  new_furniture.color_.fill( c_white );
  new_furniture.movecost = 0;
  new_furniture.move_str_req = -1;
  new_furniture.transparent = true;
  new_furniture.set_flag("TRANSPARENT");
  new_furniture.examine = iexamine_function_from_string("none");
  new_furniture.loadid = furn_id( 0 );
  new_furniture.open = "";
  new_furniture.close = "";
  new_furniture.max_volume = MAX_VOLUME_IN_SQUARE;
  return new_furniture;
}
Example #11
0
ter_t null_terrain_t() {
  ter_t new_terrain;
  new_terrain.id = "t_null";
  new_terrain.name = _("nothing");
  new_terrain.sym = ' ';
  new_terrain.color = c_white;
  new_terrain.movecost = 2;
  new_terrain.trap = tr_null;
  new_terrain.trap_id_str = "";
  new_terrain.transparent = true;
  new_terrain.bitflags = 0;
  new_terrain.set_flag("TRANSPARENT");
  new_terrain.set_flag("DIGGABLE");
  new_terrain.examine = iexamine_function_from_string("none");
  new_terrain.harvest_season = 0;
  new_terrain.harvestable = "";
  new_terrain.loadid = 0;
  new_terrain.open = "";
  new_terrain.close = "";
  new_terrain.max_volume = MAX_VOLUME_IN_SQUARE;
  return new_terrain;
};
Example #12
0
void load_terrain(JsonObject &jsobj)
{
  if ( terlist.empty() ) {
      ter_t new_null = null_terrain_t();
      termap[new_null.id] = new_null;
      terlist.push_back(new_null);
  }
  ter_t new_terrain;
  new_terrain.id = jsobj.get_string("id");
  if ( new_terrain.id == "t_null" ) {
      return;
  }
  new_terrain.name = _(jsobj.get_string("name").c_str());

  //Special case for the LINE_ symbols
  std::string symbol = jsobj.get_string("symbol");
  if("LINE_XOXO" == symbol) {
    new_terrain.sym = LINE_XOXO;
  } else if("LINE_OXOX" == symbol) {
    new_terrain.sym = LINE_OXOX;
  } else {
    new_terrain.sym = symbol.c_str()[0];
  }

  new_terrain.color = color_from_string(jsobj.get_string("color"));
  new_terrain.movecost = jsobj.get_int("move_cost");

  if(jsobj.has_member("trap")) {
      // Store the string representation of the trap id.
      // Overwrites the trap field in set_trap_ids() once ids are assigned..
      new_terrain.trap_id_str = jsobj.get_string("trap");
  }
  new_terrain.trap = tr_null;
  new_terrain.max_volume = jsobj.get_int("max_volume", MAX_VOLUME_IN_SQUARE);

  new_terrain.transparent = false;
  new_terrain.bitflags = 0;
  JsonArray flags = jsobj.get_array("flags");
  while(flags.has_more()) {
    new_terrain.set_flag(flags.next_string());
  }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_terrain.examine = iexamine_function_from_string(function_name);
  } else {
    //If not specified, default to no action
    new_terrain.examine = iexamine_function_from_string("none");
  }
  //if the terrain has something harvestable it will have a product & season to be harvested in the json
  if (jsobj.has_member("harvestable")) {
    new_terrain.harvestable = jsobj.get_string("harvestable");
    if (jsobj.get_string("harvest_season") == "SPRING") {new_terrain.harvest_season = 0;} //convert the season to int for calendar compare
    if (jsobj.get_string("harvest_season") == "SUMMER") {new_terrain.harvest_season = 1;}
    if (jsobj.get_string("harvest_season") == "AUTUMN") {new_terrain.harvest_season = 2;}
    if (jsobj.get_string("harvest_season") == "WINTER") {new_terrain.harvest_season = 3;}
  }
  new_terrain.open = "";
  if ( jsobj.has_member("open") ) {
      new_terrain.open = jsobj.get_string("open");
  }
  new_terrain.close = "";
  if ( jsobj.has_member("close") ) {
      new_terrain.close = jsobj.get_string("close");
  }
  new_terrain.bash.load(jsobj, "bash", false);
  new_terrain.deconstruct.load(jsobj, "deconstruct", false);
  new_terrain.loadid=terlist.size();
  termap[new_terrain.id]=new_terrain;
  terlist.push_back(new_terrain);
}
Example #13
0
void load_terrain(JsonObject &jsobj)
{
  if ( terlist.empty() ) {
      ter_t new_null = null_terrain_t();
      termap[new_null.id] = new_null;
      terlist.push_back(new_null);
  }
  ter_t new_terrain;
  new_terrain.id = jsobj.get_string("id");
  if ( new_terrain.id == "t_null" ) {
      return;
  }
  new_terrain.name = _(jsobj.get_string("name").c_str());

  //Special case for the LINE_ symbols
  std::string symbol = jsobj.get_string("symbol");
  if("LINE_XOXO" == symbol) {
    new_terrain.sym = LINE_XOXO;
  } else if("LINE_OXOX" == symbol) {
    new_terrain.sym = LINE_OXOX;
  } else {
    new_terrain.sym = symbol.c_str()[0];
  }

  new_terrain.color = color_from_string(jsobj.get_string("color"));
  new_terrain.movecost = jsobj.get_int("move_cost");

  if(jsobj.has_member("trap")) {
      // Store the string representation of the trap id.
      // Overwrites the trap field in set_trap_ids() once ids are assigned..
      new_terrain.trap_id_str = jsobj.get_string("trap");
  }
  new_terrain.trap = tr_null;

  new_terrain.transparent = false;
  new_terrain.bitflags = 0;
  JsonArray flags = jsobj.get_array("flags");
  while(flags.has_more()) {
    new_terrain.set_flag(flags.next_string());
  }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_terrain.examine = iexamine_function_from_string(function_name);
  } else {
    //If not specified, default to no action
    new_terrain.examine = iexamine_function_from_string("none");
  }

  new_terrain.open = "";
  if ( jsobj.has_member("open") ) {
      new_terrain.open = jsobj.get_string("open");
  }
  new_terrain.close = "";
  if ( jsobj.has_member("close") ) {
      new_terrain.close = jsobj.get_string("close");
  }
  new_terrain.bash.load(jsobj, "bash", false);
  new_terrain.loadid=terlist.size();
  termap[new_terrain.id]=new_terrain;
  terlist.push_back(new_terrain);
}
Example #14
0
void load_terrain(JsonObject &jsobj)
{
  if ( terlist.empty() ) {
      ter_t new_null = null_terrain_t();
      termap[new_null.id] = new_null;
      terlist.push_back(new_null);
  }
  ter_t new_terrain;
  new_terrain.id = jsobj.get_string("id");
  if ( new_terrain.id == "t_null" ) {
      return;
  }
  new_terrain.name = _(jsobj.get_string("name").c_str());

    new_terrain.load_symbol( jsobj );

  new_terrain.movecost = jsobj.get_int("move_cost");

  if(jsobj.has_member("trap")) {
      // Store the string representation of the trap id.
      // Overwrites the trap field in set_trap_ids() once ids are assigned..
      new_terrain.trap_id_str = jsobj.get_string("trap");
  }
  new_terrain.trap = tr_null;
  new_terrain.max_volume = jsobj.get_int("max_volume", MAX_VOLUME_IN_SQUARE);

  new_terrain.transparent = false;
    new_terrain.connect_group = TERCONN_NONE;

    for( auto & flag : jsobj.get_string_array( "flags" ) ) {
        new_terrain.set_flag( flag );
    }

    // connect_group is initialised to none, then terrain flags are set, then finally
    // connections from JSON are set. This is so that wall flags can set wall connections
    // but can be overridden by explicit connections in JSON.
    if(jsobj.has_member("connects_to")) {
    new_terrain.set_connects( jsobj.get_string("connects_to") );
    }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_terrain.examine = iexamine_function_from_string(function_name);
  } else {
    // if not specified, default to no action
    new_terrain.examine = iexamine_function_from_string("none");
  }

  // if the terrain has something harvestable
  if (jsobj.has_member("harvestable")) {
    new_terrain.harvestable = jsobj.get_string("harvestable"); // get the harvestable
  }

  if (jsobj.has_member("transforms_into")) {
    new_terrain.transforms_into = jsobj.get_string("transforms_into"); // get the terrain to transform into later on
  }

  if (jsobj.has_member("roof")) {
    new_terrain.roof = jsobj.get_string("roof"); // Get the terrain to create above this one if there would be open air otherwise
  }

  if (jsobj.has_member("harvest_season")) {
    //get the harvest season
    if (jsobj.get_string("harvest_season") == "SPRING") {new_terrain.harvest_season = 0;} // convert the season to int for calendar compare
    else if (jsobj.get_string("harvest_season") == "SUMMER") {new_terrain.harvest_season = 1;}
    else if (jsobj.get_string("harvest_season") == "AUTUMN") {new_terrain.harvest_season = 2;}
    else {new_terrain.harvest_season = 3;}
  }

  new_terrain.open = "";
  if ( jsobj.has_member("open") ) {
      new_terrain.open = jsobj.get_string("open");
  }
  new_terrain.close = "";
  if ( jsobj.has_member("close") ) {
      new_terrain.close = jsobj.get_string("close");
  }
  new_terrain.bash.load(jsobj, "bash", false);
  new_terrain.deconstruct.load(jsobj, "deconstruct", false);
  new_terrain.loadid = ter_id( terlist.size() );
  termap[new_terrain.id]=new_terrain;
  terlist.push_back(new_terrain);
}
Example #15
0
void load_terrain(JsonObject &jsobj)
{
  ter_t new_terrain;
  new_terrain.id = jsobj.get_string("id");
  new_terrain.name = _(jsobj.get_string("name").c_str());

  //Special case for the LINE_ symbols
  std::string symbol = jsobj.get_string("symbol");
  if("LINE_XOXO" == symbol) {
    new_terrain.sym = LINE_XOXO;
  } else if("LINE_OXOX" == symbol) {
    new_terrain.sym = LINE_OXOX;
  } else {
    new_terrain.sym = symbol.c_str()[0];
  }

  new_terrain.color = color_from_string(jsobj.get_string("color"));
  new_terrain.movecost = jsobj.get_int("move_cost");

  if(jsobj.has_member("trap")) {
    new_terrain.trap = trap_id_from_string(jsobj.get_string("trap"));
  } else {
    new_terrain.trap = tr_null;
  }


  new_terrain.transparent = false;
  new_terrain.bitflags = 0;
  JsonArray flags = jsobj.get_array("flags");
  while(flags.has_more()) {
    new_terrain.set_flag(flags.next_string());
  }

  if(jsobj.has_member("examine_action")) {
    std::string function_name = jsobj.get_string("examine_action");
    new_terrain.examine = iexamine_function_from_string(function_name);
  } else {
    //If not specified, default to no action
    new_terrain.examine = iexamine_function_from_string("none");
  }

  new_terrain.open = "";
  if ( jsobj.has_member("open") ) {
      new_terrain.open = jsobj.get_string("open");
  }
  new_terrain.close = "";
  if ( jsobj.has_member("close") ) {
      new_terrain.close = jsobj.get_string("close");
  }
/*
  requires copying json object
  if( jsobj.has_member("bash") ) {
      if( jsobj.is_object("bash") ) {
          JsonObject delayed(jsobj.get_object("bash"));
          delayed_json["terrain_bash"][new_terrain.id] = delayed;//jsobj.get_object("bash");
      } else if (jsobj.is_string("bash") ) {
//          delayed_json["terrain_bash_link"][new_terrain.id] = jsobj.get_string("bash");
      }
  }
*/
  new_terrain.bash.load(jsobj, "bash", false);

  new_terrain.loadid=terlist.size();
  termap[new_terrain.id]=new_terrain;
  terlist.push_back(new_terrain);
}