Skip to content

Commit

Permalink
Merge pull request #31483 from jbytheway/no_longs_in_json
Browse files Browse the repository at this point in the history
Removing long (part 4): Remove support for serializing longs
  • Loading branch information
ZhilkinSerg authored Jun 15, 2019
2 parents 5ba735a + 988b18e commit 2b18892
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,8 @@ void it_artifact_tool::deserialize( JsonObject &jo )
m_to_hit = jo.get_int( "m_to_hit" );
item_tags = jo.get_tags( "item_flags" );

tool->max_charges = jo.get_long( "max_charges" );
tool->def_charges = jo.get_long( "def_charges" );
tool->max_charges = jo.get_int( "max_charges" );
tool->def_charges = jo.get_int( "def_charges" );

tool->charges_per_use = jo.get_int( "charges_per_use" );
tool->turns_per_charge = jo.get_int( "turns_per_charge" );
Expand Down
4 changes: 2 additions & 2 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ void Item_factory::load( islot_ammo &slot, JsonObject &jo, const std::string &sr
assign( jo, "range", slot.range, strict, 0 );
assign( jo, "dispersion", slot.dispersion, strict, 0 );
assign( jo, "recoil", slot.recoil, strict, 0 );
assign( jo, "count", slot.def_charges, strict, 1L );
assign( jo, "count", slot.def_charges, strict, 1 );
assign( jo, "loudness", slot.loudness, strict, 0 );
assign( jo, "effects", slot.ammo_effects, strict );
assign( jo, "prop_damage", slot.prop_damage, strict );
Expand Down Expand Up @@ -1630,7 +1630,7 @@ void Item_factory::load( islot_comestible &slot, JsonObject &jo, const std::stri

assign( jo, "comestible_type", slot.comesttype, strict );
assign( jo, "tool", slot.tool, strict );
assign( jo, "charges", slot.def_charges, strict, 1L );
assign( jo, "charges", slot.def_charges, strict, 1 );
assign( jo, "quench", slot.quench, strict );
assign( jo, "fun", slot.fun, strict );
assign( jo, "stim", slot.stim, strict );
Expand Down
2 changes: 1 addition & 1 deletion src/item_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Item_modifier
* Charges to spawn the item with, if this turns out to
* be negative, the default charges are used.
*/
std::pair<long, long> charges;
std::pair<int, int> charges;
/**
* Ammo for guns. If NULL the gun spawns without ammo.
* This takes @ref charges and @ref with_ammo into account.
Expand Down
4 changes: 2 additions & 2 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct islot_comestible {
std::string tool = "null";

/** Defaults # of charges (drugs, loaf of bread? etc) */
long def_charges = 1;
int def_charges = 1;

/** effect on character thirst (may be negative) */
int quench = 0;
Expand Down Expand Up @@ -638,7 +638,7 @@ struct islot_ammo : common_ranged_data {
/**
* Default charges.
*/
long def_charges = 1;
int def_charges = 1;

/**
* TODO: document me.
Expand Down
56 changes: 0 additions & 56 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,6 @@ int JsonObject::get_int( const std::string &name, const int fallback )
return jsin->get_int();
}

long JsonObject::get_long( const std::string &name )
{
int pos = verify_position( name );
jsin->seek( pos );
return jsin->get_long();
}

long JsonObject::get_long( const std::string &name, const long fallback )
{
long pos = positions[name];
if( pos <= start ) {
return fallback;
}
jsin->seek( pos );
return jsin->get_long();
}

double JsonObject::get_float( const std::string &name )
{
int pos = verify_position( name );
Expand Down Expand Up @@ -514,13 +497,6 @@ int JsonArray::next_int()
return jsin->get_int();
}

long JsonArray::next_long()
{
verify_index( index );
jsin->seek( positions[index++] );
return jsin->get_long();
}

double JsonArray::next_float()
{
verify_index( index );
Expand Down Expand Up @@ -571,13 +547,6 @@ int JsonArray::get_int( int i )
return jsin->get_int();
}

long JsonArray::get_long( int i )
{
verify_index( i );
jsin->seek( positions[i] );
return jsin->get_long();
}

double JsonArray::get_float( int i )
{
verify_index( i );
Expand Down Expand Up @@ -1046,13 +1015,6 @@ int JsonIn::get_int()
return static_cast<int>( get_float() );
}

long JsonIn::get_long()
{
// get float value and then convert to int,
// because "1.359e3" is technically a valid integer.
return static_cast<long>( get_float() );
}

double JsonIn::get_float()
{
// this could maybe be prettier?
Expand Down Expand Up @@ -1372,24 +1334,6 @@ bool JsonIn::read( unsigned int &u )
return true;
}

bool JsonIn::read( long &l )
{
if( !test_number() ) {
return false;
}
l = get_long();
return true;
}

bool JsonIn::read( unsigned long &ul )
{
if( !test_number() ) {
return false;
}
ul = get_long();
return true;
}

bool JsonIn::read( float &f )
{
if( !test_number() ) {
Expand Down
7 changes: 0 additions & 7 deletions src/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class JsonIn
// data parsing
std::string get_string(); // get the next value as a string
int get_int(); // get the next value as an int
long get_long(); // get the next value as an long
bool get_bool(); // get the next value as a bool
double get_float(); // get the next value as a double
std::string get_member_name(); // also strips the ':'
Expand Down Expand Up @@ -259,8 +258,6 @@ class JsonIn
bool read( short int &s );
bool read( int &i );
bool read( unsigned int &u );
bool read( long &l );
bool read( unsigned long &ul );
bool read( float &f );
bool read( double &d );
bool read( std::string &s );
Expand Down Expand Up @@ -686,8 +683,6 @@ class JsonObject
bool get_bool( const std::string &name, const bool fallback );
int get_int( const std::string &name );
int get_int( const std::string &name, const int fallback );
long get_long( const std::string &name );
long get_long( const std::string &name, const long fallback );
double get_float( const std::string &name );
double get_float( const std::string &name, const double fallback );
std::string get_string( const std::string &name );
Expand Down Expand Up @@ -853,7 +848,6 @@ class JsonArray
// iterative access
bool next_bool();
int next_int();
long next_long();
double next_float();
std::string next_string();
JsonArray next_array();
Expand All @@ -863,7 +857,6 @@ class JsonArray
// static access
bool get_bool( int index );
int get_int( int index );
long get_long( int index );
double get_float( int index );
std::string get_string( int index );
JsonArray get_array( int index );
Expand Down
2 changes: 1 addition & 1 deletion src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class mission
std::string description;
mission_status status;
// Cash/Favor value of completing this
unsigned long value;
unsigned int value;
// If there's a special reward for completing it
npc_favor reward;
// Unique ID number, used for referencing elsewhere
Expand Down
6 changes: 3 additions & 3 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2828,15 +2828,15 @@ void conditional_t::set_npc_role_nearby( JsonObject &jo )

void conditional_t::set_npc_allies( JsonObject &jo )
{
const unsigned long min_allies = jo.get_int( "npc_allies" );
const unsigned int min_allies = jo.get_int( "npc_allies" );
condition = [min_allies]( const dialogue & ) {
return g->allies().size() >= min_allies;
};
}

void conditional_t::set_u_has_cash( JsonObject &jo )
{
const signed long min_cash = jo.get_int( "u_has_cash" );
const int min_cash = jo.get_int( "u_has_cash" );
condition = [min_cash]( const dialogue & d ) {
return d.alpha->cash >= min_cash;
};
Expand Down Expand Up @@ -2924,7 +2924,7 @@ void conditional_t::set_npc_override( JsonObject &jo )

void conditional_t::set_days_since( JsonObject &jo )
{
const unsigned long days = jo.get_int( "days_since_cataclysm" );
const unsigned int days = jo.get_int( "days_since_cataclysm" );
condition = [days]( const dialogue & ) {
return to_turn<int>( calendar::turn ) >= DAYS( days );
};
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ class player : public Character
int blocks_left;
int stim;
int radiation;
signed long cash;
int cash;
int movecounter;
std::shared_ptr<monster> mounted_creature;
bool death_drops;// Turned to false for simulating NPCs on distant missions so they don't drop all their gear in sight
Expand Down
4 changes: 2 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2925,7 +2925,7 @@ void map_memory::load( JsonIn &jsin )
p.x = jsin.get_int();
p.y = jsin.get_int();
p.z = jsin.get_int();
const long symbol = jsin.get_long();
const int symbol = jsin.get_int();
memorize_symbol( std::numeric_limits<int>::max(), p, symbol );
jsin.end_array();
}
Expand All @@ -2950,7 +2950,7 @@ void map_memory::load( JsonObject &jsin )
while( map_memory_curses.has_more() ) {
JsonObject pmap = map_memory_curses.next_object();
const tripoint p( pmap.get_int( "x" ), pmap.get_int( "y" ), pmap.get_int( "z" ) );
memorize_symbol( std::numeric_limits<int>::max(), p, pmap.get_long( "symbol" ) );
memorize_symbol( std::numeric_limits<int>::max(), p, pmap.get_int( "symbol" ) );
}
}

Expand Down

0 comments on commit 2b18892

Please sign in to comment.