Skip to content

Commit

Permalink
Merge pull request #34725 from KorGgenT/tripoint-to-char
Browse files Browse the repository at this point in the history
move scope of player::position plus getters and setters to Character::
  • Loading branch information
ZhilkinSerg authored Oct 14, 2019
2 parents b1dd83c + 2b4c288 commit 7530296
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
24 changes: 24 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,27 @@ class Character : public Creature, public visitable<Character>
WT_GOOD,
NUM_WATER_TOLERANCE
};
inline int posx() const override {
return position.x;
}
inline int posy() const override {
return position.y;
}
inline int posz() const override {
return position.z;
}
inline void setx( int x ) {
setpos( tripoint( x, position.y, position.z ) );
}
inline void sety( int y ) {
setpos( tripoint( position.x, y, position.z ) );
}
inline void setz( int z ) {
setpos( tripoint( position.xy(), z ) );
}
inline void setpos( const tripoint &p ) override {
position = p;
}
private:
/** Retrieves a stat mod of a mutation. */
int get_mod( const trait_id &mut, const std::string &arg ) const;
Expand Down Expand Up @@ -1085,6 +1106,9 @@ class Character : public Creature, public visitable<Character>
void deserialize( JsonIn &jsin );
};

// The player's position on the local map.
tripoint position;

/** Bonuses to stats, calculated each turn */
int str_bonus;
int dex_bonus;
Expand Down
24 changes: 1 addition & 23 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1489,27 +1489,7 @@ class player : public Character
tripoint global_omt_location() const;

// ---------------VALUES-----------------
inline int posx() const override {
return position.x;
}
inline int posy() const override {
return position.y;
}
inline int posz() const override {
return position.z;
}
inline void setx( int x ) {
setpos( tripoint( x, position.y, position.z ) );
}
inline void sety( int y ) {
setpos( tripoint( position.x, y, position.z ) );
}
inline void setz( int z ) {
setpos( tripoint( position.xy(), z ) );
}
inline void setpos( const tripoint &p ) override {
position = p;
}

tripoint view_offset;
// Means player sit inside vehicle on the tile he is now
bool in_vehicle;
Expand Down Expand Up @@ -1705,8 +1685,6 @@ class player : public Character
known_magic magic;

protected:
// The player's position on the local map.
tripoint position;

trap_map known_traps;

Expand Down
26 changes: 13 additions & 13 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ void Character::load( JsonObject &data )
{
Creature::load( data );

if( !data.read( "posx", position.x ) ) { // uh-oh.
debugmsg( "BAD PLAYER/NPC JSON: no 'posx'?" );
}
data.read( "posy", position.y );
if( !data.read( "posz", position.z ) && g != nullptr ) {
position.z = g->get_levz();
}
// stats
data.read( "str_cur", str_cur );
data.read( "str_max", str_max );
Expand Down Expand Up @@ -524,6 +531,12 @@ void Character::store( JsonOut &json ) const
{
Creature::store( json );

// assumes already in Character object
// positional data
json.member( "posx", position.x );
json.member( "posy", position.y );
json.member( "posz", position.z );

// stat
json.member( "str_cur", str_cur );
json.member( "str_max", str_max );
Expand Down Expand Up @@ -591,12 +604,6 @@ void player::store( JsonOut &json ) const
{
Character::store( json );

// assumes already in player object
// positional data
json.member( "posx", position.x );
json.member( "posy", position.y );
json.member( "posz", position.z );

// energy
json.member( "stim", stim );
json.member( "last_sleep_check", last_sleep_check );
Expand Down Expand Up @@ -705,13 +712,6 @@ void player::load( JsonObject &data )
JsonArray parray;
character_id tmpid;

if( !data.read( "posx", position.x ) ) { // uh-oh.
debugmsg( "BAD PLAYER/NPC JSON: no 'posx'?" );
}
data.read( "posy", position.y );
if( !data.read( "posz", position.z ) && g != nullptr ) {
position.z = g->get_levz();
}
data.read( "stim", stim );
data.read( "pkill", pkill );
data.read( "tank_plut", tank_plut );
Expand Down

0 comments on commit 7530296

Please sign in to comment.