Skip to content

Commit

Permalink
Merge pull request #35754 from ZhilkinSerg/refactor-map-point-functio…
Browse files Browse the repository at this point in the history
…ns-2019-11-28

Cleanup point-related code
  • Loading branch information
Rivet-the-Zombie authored Dec 1, 2019
2 parents 67f223b + 8e290ef commit 847e182
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 309 deletions.
9 changes: 5 additions & 4 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,13 @@ void debug()
}
veh_menu.query();
if( veh_menu.ret >= 0 && veh_menu.ret < static_cast<int>( veh_strings.size() ) ) {
//Didn't cancel
// Didn't cancel
const vproto_id &selected_opt = veh_strings[veh_menu.ret].second;
tripoint dest = u.pos(); // TODO: Allow picking this when add_vehicle has 3d argument
vehicle *veh = m.add_vehicle( selected_opt, dest.xy(), -90, 100, 0 );
// TODO: Allow picking this when add_vehicle has 3d argument
tripoint dest = u.pos();
vehicle *veh = m.add_vehicle( selected_opt, dest, -90, 100, 0 );
if( veh != nullptr ) {
m.board_vehicle( u.pos(), &u );
m.board_vehicle( dest, &u );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5658,7 +5658,7 @@ int iuse::unfold_generic( player *p, item *it, bool, const tripoint & )
p->add_msg_if_player( m_info, _( "You cannot do that while mounted." ) );
return 0;
}
vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), p->pos().xy(), 0, 0, 0, false );
vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), p->pos(), 0, 0, 0, false );
if( veh == nullptr ) {
p->add_msg_if_player( m_info, _( "There's no room to unfold the %s." ), it->tname() );
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ int unfold_vehicle_iuse::use( player &p, item &it, bool, const tripoint & ) cons
}
}

vehicle *veh = g->m.add_vehicle( vehicle_id, p.pos().xy(), 0, 0, 0, false );
vehicle *veh = g->m.add_vehicle( vehicle_id, p.pos(), 0, 0, 0, false );
if( veh == nullptr ) {
p.add_msg_if_player( m_info, _( "There's no room to unfold the %s." ), it.tname() );
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void map::add_light_from_items( const tripoint &p, item_stack::iterator begin,
}
}

// TODO: Consider making this just clear the cache and dynamically fill it in as trans() is called
// TODO: Consider making this just clear the cache and dynamically fill it in as is_transparent() is called
bool map::build_transparency_cache( const int zlev )
{
auto &map_cache = get_cache( zlev );
Expand Down Expand Up @@ -497,7 +497,7 @@ float map::ambient_light_at( const tripoint &p ) const
return get_cache_ref( p.z ).lm[p.x][p.y].max();
}

bool map::trans( const tripoint &p ) const
bool map::is_transparent( const tripoint &p ) const
{
return light_transparency( p ) > LIGHT_TRANSPARENCY_SOLID;
}
Expand Down
52 changes: 5 additions & 47 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "map_iterator.h"
#include "map_selector.h"
#include "mapbuffer.h"
#include "mapdata.h"
#include "messages.h"
#include "mongroup.h"
#include "monster.h"
Expand Down Expand Up @@ -76,7 +75,6 @@
#include "map_memory.h"
#include "math_defines.h"
#include "optional.h"
#include "player.h"
#include "tileray.h"
#include "weighted_list.h"
#include "enums.h"
Expand Down Expand Up @@ -2320,16 +2318,6 @@ int map::bash_rating( const int str, const tripoint &p, const bool allow_floor )

// End of 3D bashable

void map::make_rubble( const tripoint &p )
{
make_rubble( p, f_rubble, false, t_dirt, false );
}

void map::make_rubble( const tripoint &p, const furn_id &rubble_type, const bool items )
{
make_rubble( p, rubble_type, items, t_dirt, false );
}

void map::make_rubble( const tripoint &p, const furn_id &rubble_type, const bool items,
const ter_id &floor_type, bool overwrite )
{
Expand Down Expand Up @@ -3558,7 +3546,7 @@ void map::shoot( const tripoint &p, projectile &proj, const bool hit_items )
spawn_item( p, "glass_shard", rng( 8, 16 ) );
dam = 0; //Prevent damaging additional items, since we shot at the ceiling.
}
} else if( impassable( p ) && !trans( p ) ) {
} else if( impassable( p ) && !is_transparent( p ) ) {
bash( p, dam, false );
dam = 0; // TODO: Preserve some residual damage when it makes sense.
}
Expand Down Expand Up @@ -5567,12 +5555,6 @@ void map::draw( const catacurses::window &w, const tripoint &center )
}
}

void map::drawsq( const catacurses::window &w, player &u, const tripoint &p,
const bool invert, const bool show_items ) const
{
drawsq( w, u, p, invert, show_items, u.pos() + u.view_offset, false, false, false );
}

void map::drawsq( const catacurses::window &w, player &u, const tripoint &p, const bool invert_arg,
const bool show_items_arg, const tripoint &view_center,
const bool low_light, const bool bright_light, const bool inorder ) const
Expand Down Expand Up @@ -5917,7 +5899,7 @@ bool map::sees( const tripoint &F, const tripoint &T, const int range, int &bres
if( new_point.x == T.x && new_point.y == T.y ) {
return false;
}
if( !this->trans( tripoint( new_point, T.z ) ) ) {
if( !this->is_transparent( tripoint( new_point, T.z ) ) ) {
visible = false;
return false;
}
Expand All @@ -5937,16 +5919,16 @@ bool map::sees( const tripoint &F, const tripoint &T, const int range, int &bres

// TODO: Allow transparent floors (and cache them!)
if( new_point.z == last_point.z ) {
if( !this->trans( new_point ) ) {
if( !this->is_transparent( new_point ) ) {
visible = false;
return false;
}
} else {
const int max_z = std::max( new_point.z, last_point.z );
if( ( has_floor_or_support( {new_point.xy(), max_z} ) ||
!trans( {new_point.xy(), last_point.z} ) ) &&
!is_transparent( {new_point.xy(), last_point.z} ) ) &&
( has_floor_or_support( {last_point.xy(), max_z} ) ||
!trans( {last_point.xy(), new_point.z} ) ) ) {
!is_transparent( {last_point.xy(), new_point.z} ) ) ) {
visible = false;
return false;
}
Expand Down Expand Up @@ -6519,30 +6501,6 @@ void map::saven( const tripoint &grid )
MAPBUFFER.add_submap( abs, submap_to_save );
}

// worldx & worldy specify where in the world this is;
// gridx & gridy specify which nonant:
// 0,0 1,0 2,0
// 0,1 1,1 2,1
// 0,2 1,2 2,2 etc
// (worldx,worldy,worldz) denotes the absolute coordinate of the submap
// in grid[0].
void map::loadn( const point &grid, const bool update_vehicles )
{
if( zlevels ) {
for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) {
loadn( tripoint( grid, gridz ), update_vehicles );
}

// Note: we want it in a separate loop! It is a post-load cleanup
// Since we're adding roofs, we want it to go up (from lowest to highest)
for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) {
add_roofs( tripoint( grid, gridz ) );
}
} else {
loadn( tripoint( grid, abs_sub.z ), update_vehicles );
}
}

// Optimized mapgen function that only works properly for very simple overmap types
// Does not create or require a temporary map and does its own saving
static void generate_uniform( const tripoint &p, const ter_id &terrain_type )
Expand Down
Loading

0 comments on commit 847e182

Please sign in to comment.