Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zone rotation in faction camp farms #51703

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2402,16 +2402,11 @@ static std::pair<size_t, std::string> farm_action( const tripoint_abs_omt &omt_t
seed_inv = comp->companion_mission_inv.items_with( farm_valid_seed );
}

//farm_json is what the area should look like according to jsons
tinymap farm_json;
// We're probably going to rotate this tinymap to match the actual map.
// Let's make sure we don't move NPCs around when doing this.
farm_json.no_rotate_npcs = true;
// TODO: fix point types
farm_json.generate( project_to<coords::sm>( omt_tgt ).raw(), calendar::turn );
//farm_map is what the area actually looks like
// farm_map is what the area actually looks like
tinymap farm_map;
farm_map.load( project_to<coords::sm>( omt_tgt ), false );
// farm_json is what the area should look like according to jsons (loaded on demand)
std::unique_ptr<fake_map> farm_json;
tripoint mapmin = tripoint( 0, 0, omt_tgt.z() );
tripoint mapmax = tripoint( 2 * SEEX - 1, 2 * SEEY - 1, omt_tgt.z() );
bool done_planting = false;
Expand All @@ -2422,15 +2417,24 @@ static std::pair<size_t, std::string> farm_action( const tripoint_abs_omt &omt_t
break;
}
switch( op ) {
case farm_ops::plow:
//Needs to be plowed to match json
if( is_dirtmound( pos, farm_json, farm_map ) && is_unplowed( pos, farm_map ) ) {
case farm_ops::plow: {
if( !farm_json ) {
farm_json = std::make_unique<fake_map>();
mapgendata dat( omt_tgt, *farm_json, 0, calendar::turn, nullptr );
if( !run_mapgen_func( dat.terrain_type()->get_mapgen_id(), dat ) ) {
debugmsg( "Failed to run mapgen for farm map" );
break;
}
}
// Needs to be plowed to match json
if( is_dirtmound( pos, *farm_json, farm_map ) && is_unplowed( pos, farm_map ) ) {
plots_cnt += 1;
if( comp ) {
farm_map.ter_set( pos, t_dirtmound );
}
}
break;
}
case farm_ops::plant:
if( is_dirtmound( pos, farm_map, farm_map ) ) {
plots_cnt += 1;
Expand Down
7 changes: 3 additions & 4 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7637,8 +7637,7 @@ bool tinymap::inbounds( const tripoint &p ) const

// set up a map just long enough scribble on it
// this tinymap should never, ever get saved
fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
const int fake_map_z )
fake_map::fake_map( const ter_id &ter_type )
{
const tripoint tripoint_below_zero( 0, 0, fake_map_z );

Expand All @@ -7648,8 +7647,8 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_
std::unique_ptr<submap> sm = std::make_unique<submap>();

sm->set_all_ter( ter_type );
sm->set_all_furn( fur_type );
sm->set_all_traps( trap_type );
sm->set_all_furn( f_null );
sm->set_all_traps( tr_null );

setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() );

Expand Down
18 changes: 2 additions & 16 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ class map
// NOLINTNEXTLINE(performance-noexcept-move-constructor)
map &operator=( map && );

/**
* Tinymaps will ocassionally need to skip npc rotation in map::rotate
* Here's a little trigger for them to opt out. We won't be doing that here, though
*/
virtual bool skip_npc_rotation() const {
return false;
}

/**
* Sets a dirty flag on the a given cache.
*
Expand Down Expand Up @@ -2099,21 +2091,15 @@ class tinymap : public map
public:
tinymap() : map( 2, false ) {}
bool inbounds( const tripoint &p ) const override;

/** Sometimes you need to generate and rotate a tinymap without touching npcs */
bool skip_npc_rotation() const override {
return no_rotate_npcs;
}
bool no_rotate_npcs = false;
};

class fake_map : public tinymap
{
private:
std::vector<std::unique_ptr<submap>> temp_submaps_;
public:
fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
int fake_map_z );
explicit fake_map( const ter_id &ter_type = t_dirt );
~fake_map() override;
static constexpr int fake_map_z = -OVERMAP_DEPTH;
};
#endif // CATA_SRC_MAP_H
19 changes: 6 additions & 13 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6110,11 +6110,6 @@ void map::rotate( int turns, const bool setpos_safe )
overmap_buffer.get_npcs_near( tripoint_abs_sm( abs_sub ), radius );
for( const shared_ptr_fast<npc> &i : npcs ) {
npc &np = *i;
// I know we could break out earlier and waste less cycles, this is just easier.
// This is here for tinymaps who don't need to rotate NPCs.
if( skip_npc_rotation() ) {
break;
}
const tripoint sq = np.get_location().raw();
real_coords np_rc;
np_rc.fromabs( sq.xy() );
Expand Down Expand Up @@ -7028,8 +7023,6 @@ bool run_mapgen_update_func( const std::string &update_mapgen_id, mapgendata &da
std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_update(
const std::string &update_mapgen_id )
{
const int fake_map_z = -9;

std::map<ter_id, int> terrains;
std::map<furn_id, int> furnitures;

Expand All @@ -7039,23 +7032,23 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
return std::make_pair( terrains, furnitures );
}

::fake_map fake_map( f_null, t_dirt, tr_null, fake_map_z );
fake_map tmp_map( t_dirt );

oter_id any = oter_id( "field" );
// just need a variable here, it doesn't need to be valid
const regional_settings dummy_settings;

mapgendata fake_md( any, any, any, any, any, any, any, any, any, any, 0, dummy_settings,
fake_map, any, {}, 0.0f, calendar::turn, nullptr );
tmp_map, any, {}, 0.0f, calendar::turn, nullptr );

if( update_function->second[0]->update_map( fake_md ) ) {
for( const tripoint &pos : fake_map.points_on_zlevel( fake_map_z ) ) {
ter_id ter_at_pos = fake_map.ter( pos );
for( const tripoint &pos : tmp_map.points_on_zlevel( fake_map::fake_map_z ) ) {
ter_id ter_at_pos = tmp_map.ter( pos );
if( ter_at_pos != t_dirt ) {
terrains[ter_at_pos] += 1;
}
if( fake_map.has_furn( pos ) ) {
furn_id furn_at_pos = fake_map.furn( pos );
if( tmp_map.has_furn( pos ) ) {
furn_id furn_at_pos = tmp_map.furn( pos );
furnitures[furn_at_pos] += 1;
}
}
Expand Down