Skip to content

Commit

Permalink
Merge pull request #73665 from PatrikLundell/livestock2
Browse files Browse the repository at this point in the history
Provided 3D camp construction + Livestock 2 example
  • Loading branch information
Maleclypse authored May 11, 2024
2 parents bc9c909 + cabc0eb commit 3f174dd
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@
"rrrrrrr ",
"r r "
],
"flags": [ "ALLOW_TERRAIN_UNDER_OTHER_DATA" ],
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"update_mapgen_id": "fbml_2_coop_construction",
"method": "json",
"object": { "place_nested": [ { "chunks": [ "fbml_2_coop_construction" ], "x": 13, "y": 0 } ] }
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_coop_construction" ], "x": 13, "y": 0, "z": 0 },
{ "chunks": [ "fbml_2_coop_roof_construction" ], "x": 13, "y": 0, "z": 1 }
]
}
},
{
"type": "mapgen",
Expand Down Expand Up @@ -116,14 +120,49 @@
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "fbml_2_shack_roof_construction",
"object": {
"parameters": {
"fbml_2_construction_palette": {
"type": "palette_id",
"scope": "omt",
"default": {
"distribution": [
"fbml_2_concrete_palette",
"fbml_2_log_palette",
"fbml_2_metal_palette",
"fbml_2_migo_resin_palette",
"fbml_2_rammed_earth_palette",
"fbml_2_rock_palette",
"fbml_2_wad_palette",
"fbml_2_wood_palette"
]
}
}
},
"mapgensize": [ 5, 5 ],
"rows": [
"rrrrr",
"rrrrr",
"rrrrr",
"rrrrr",
"rrrrr"
],
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"update_mapgen_id": "fbml_2_shack_construction",
"method": "json",
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_shack_construction" ], "x": 15, "y": 18 },
{ "chunks": [ "fbml_2_shack_furniture" ], "x": 16, "y": 19 }
{ "chunks": [ "fbml_2_shack_construction" ], "x": 15, "y": 18, "z": 0 },
{ "chunks": [ "fbml_2_shack_furniture" ], "x": 16, "y": 19, "z": 0 },
{ "chunks": [ "fbml_2_shack_roof_construction" ], "x": 15, "y": 18, "z": 1 }
]
}
},
Expand Down Expand Up @@ -163,14 +202,50 @@
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "fbml_2_stall_1_roof_construction",
"object": {
"parameters": {
"fbml_2_construction_palette": {
"type": "palette_id",
"scope": "omt",
"default": {
"distribution": [
"fbml_2_concrete_palette",
"fbml_2_log_palette",
"fbml_2_metal_palette",
"fbml_2_migo_resin_palette",
"fbml_2_rammed_earth_palette",
"fbml_2_rock_palette",
"fbml_2_wad_palette",
"fbml_2_wood_palette"
]
}
}
},
"mapgensize": [ 6, 6 ],
"rows": [
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr",
" "
],
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"update_mapgen_id": "fbml_2_stall_1_construction",
"method": "json",
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_stall_1_construction" ], "x": 0, "y": 18 },
{ "chunks": [ "fbml_2_stall_1" ], "x": 3, "y": 19 }
{ "chunks": [ "fbml_2_stall_1_construction" ], "x": 0, "y": 18, "z": 0 },
{ "chunks": [ "fbml_2_stall_1" ], "x": 3, "y": 19, "z": 0 },
{ "chunks": [ "fbml_2_stall_1_roof_construction" ], "x": 0, "y": 18, "z": 1 }
]
}
},
Expand Down Expand Up @@ -210,14 +285,50 @@
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "fbml_2_stall_2_3_4_roof_construction",
"object": {
"parameters": {
"fbml_2_construction_palette": {
"type": "palette_id",
"scope": "omt",
"default": {
"distribution": [
"fbml_2_concrete_palette",
"fbml_2_log_palette",
"fbml_2_metal_palette",
"fbml_2_migo_resin_palette",
"fbml_2_rammed_earth_palette",
"fbml_2_rock_palette",
"fbml_2_wad_palette",
"fbml_2_wood_palette"
]
}
}
},
"mapgensize": [ 6, 6 ],
"rows": [
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr",
" ",
" "
],
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"update_mapgen_id": "fbml_2_stall_2_construction",
"method": "json",
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_stall_2_4_construction" ], "x": 0, "y": 14 },
{ "chunks": [ "fbml_2_stall_bench" ], "x": 3, "y": 15 }
{ "chunks": [ "fbml_2_stall_2_4_construction" ], "x": 0, "y": 14, "z": 0 },
{ "chunks": [ "fbml_2_stall_bench" ], "x": 3, "y": 15, "z": 0 },
{ "chunks": [ "fbml_2_stall_2_3_4_roof_construction" ], "x": 0, "y": 14, "z": 1 }
]
}
},
Expand Down Expand Up @@ -263,8 +374,9 @@
"method": "json",
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_stall_3_construction" ], "x": 0, "y": 10 },
{ "chunks": [ "fbml_2_stall_3" ], "x": 3, "y": 11 }
{ "chunks": [ "fbml_2_stall_3_construction" ], "x": 0, "y": 10, "z": 0 },
{ "chunks": [ "fbml_2_stall_3" ], "x": 3, "y": 11, "z": 0 },
{ "chunks": [ "fbml_2_stall_2_3_4_roof_construction" ], "x": 0, "y": 10, "z": 1 }
]
}
},
Expand All @@ -274,8 +386,9 @@
"method": "json",
"object": {
"place_nested": [
{ "chunks": [ "fbml_2_stall_2_4_construction" ], "x": 0, "y": 6 },
{ "chunks": [ "fbml_2_stall_bench" ], "x": 3, "y": 7 }
{ "chunks": [ "fbml_2_stall_2_4_construction" ], "x": 0, "y": 6, "z": 0 },
{ "chunks": [ "fbml_2_stall_bench" ], "x": 3, "y": 7, "z": 0 },
{ "chunks": [ "fbml_2_stall_2_3_4_roof_construction" ], "x": 0, "y": 6, "z": 1 }
]
}
},
Expand Down Expand Up @@ -315,12 +428,51 @@
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"method": "json",
"nested_mapgen_id": "fbml_2_stall_5_roof_construction",
"object": {
"parameters": {
"fbml_2_construction_palette": {
"type": "palette_id",
"scope": "omt",
"default": {
"distribution": [
"fbml_2_concrete_palette",
"fbml_2_log_palette",
"fbml_2_metal_palette",
"fbml_2_migo_resin_palette",
"fbml_2_rammed_earth_palette",
"fbml_2_rock_palette",
"fbml_2_wad_palette",
"fbml_2_wood_palette"
]
}
}
},
"mapgensize": [ 6, 6 ],
"rows": [
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr",
"rrrrrr"
],
"palettes": [ { "param": "fbml_2_construction_palette" } ]
}
},
{
"type": "mapgen",
"update_mapgen_id": "fbml_2_stall_5_construction",
"method": "json",
"object": {
"place_nested": [ { "chunks": [ "fbml_2_stall_5_construction" ], "x": 0, "y": 0 }, { "chunks": [ "fbml_2_stall_5" ], "x": 3, "y": 1 } ]
"place_nested": [
{ "chunks": [ "fbml_2_stall_5_construction" ], "x": 0, "y": 0, "z": 0 },
{ "chunks": [ "fbml_2_stall_5" ], "x": 3, "y": 1, "z": 0 },
{ "chunks": [ "fbml_2_stall_5_roof_construction" ], "x": 0, "y": 0, "z": 1 }
]
}
}
]
23 changes: 23 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9164,6 +9164,29 @@ fake_map::fake_map( const ter_id &ter_type )

fake_map::~fake_map() = default;

small_fake_map::small_fake_map( const ter_id &ter_type )
{
set_abs_sub( tripoint_abs_sm( tripoint_zero ) );

for( int gridx = 0; gridx < get_my_MAPSIZE(); gridx++ ) {
for( int gridy = 0; gridy < get_my_MAPSIZE(); gridy++ ) {
for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) {
std::unique_ptr<submap> sm = std::make_unique<submap>();

sm->set_all_ter( ter_type );
sm->set_all_furn( furn_str_id::NULL_ID() );
sm->set_all_traps( tr_null );

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

temp_submaps_.emplace_back( std::move( sm ) );
}
}
}
}

small_fake_map::~small_fake_map() = default;

void map::set_graffiti( const tripoint &p, const std::string &contents )
{
if( !inbounds( p ) ) {
Expand Down
12 changes: 11 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,7 @@ class fake_map : public tinymap

/**
* Smallmap is similar to tinymap in that it covers a single overmap terrain (OMT) tile, but differs
* from it in that it covers all Z levels, not just a single one. It's intended usage is for cases
* from it in that it covers all Z levels, not just a single one. Its intended usage is for cases
* where you need to operate on an OMT, but cannot guarantee you needs are restricted to a single
* Z level.
* The smallmap's natural relative reference system is the tripoint_omt_ms one.
Expand All @@ -2751,4 +2751,14 @@ class smallmap : public tinymap
tinymap::cut_down_tree( p, dir );
};
};

class small_fake_map : public smallmap
{
private:
std::vector<std::unique_ptr<submap>> temp_submaps_;
public:
explicit small_fake_map( const ter_id &ter_type = ter_str_id( "t_dirt" ).id() );
~small_fake_map() override;
};

#endif // CATA_SRC_MAP_H
22 changes: 12 additions & 10 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7972,7 +7972,7 @@ bool apply_construction_marker( const update_mapgen_id &update_mapgen_id,
return false;
}

fake_map tmp_map( ter_t_grass );
small_fake_map tmp_map( ter_t_grass );

mapgendata base_fake_md( *tmp_map.cast_to_map(), mapgendata::dummy_settings );
mapgendata fake_md( base_fake_md, args );
Expand Down Expand Up @@ -8029,21 +8029,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 tmp_map( base_ter );
small_fake_map tmp_map( base_ter );

mapgendata base_fake_md( *tmp_map.cast_to_map(), mapgendata::dummy_settings );
mapgendata fake_md( base_fake_md, mapgen_args );
fake_md.skip = { mapgen_phase::zones };

if( update_function->second.funcs()[0]->update_map( fake_md ) ) {
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 != base_ter ) {
terrains[ter_at_pos] += 1;
}
if( tmp_map.has_furn( pos ) ) {
furn_id furn_at_pos = tmp_map.furn( pos );
furnitures[furn_at_pos] += 1;
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_DEPTH; z++ ) {
for( const tripoint &pos : tmp_map.points_on_zlevel( z ) ) {
ter_id ter_at_pos = tmp_map.ter( pos );
if( ter_at_pos != base_ter ) {
terrains[ter_at_pos] += 1;
}
if( tmp_map.has_furn( pos ) ) {
furn_id furn_at_pos = tmp_map.furn( pos );
furnitures[furn_at_pos] += 1;
}
}
}
}
Expand Down

0 comments on commit 3f174dd

Please sign in to comment.