Skip to content

Commit

Permalink
add chance field for jmapgen_field (#76380)
Browse files Browse the repository at this point in the history
* add chance field for jmapgen_field

* document field

* astyle
  • Loading branch information
GuardianDll authored Sep 14, 2024
1 parent 91f8ef7 commit b35342f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/MAPGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ Example:
| intensity | (optional, integer, array ) how concentrated the field is, from 1 to 3 or more. Arrays are randomized. See `data/json/field_type.json`
| age | (optional, integer) field age. Defaults to 0.
| remove | (optional, bool) If true the given field will be removed rather than added. Defaults to false.
| chance | (optional, integer) chance to spawn field; default `100` as 100%


### Place NPCs with "npcs"
Expand Down
12 changes: 9 additions & 3 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1947,10 +1947,12 @@ class jmapgen_field : public jmapgen_piece
mapgen_value<field_type_id> ftype;
std::vector<int> intensities;
time_duration age;
int chance;
bool remove;
jmapgen_field( const JsonObject &jsi, const std::string_view/*context*/ ) :
ftype( jsi.get_member( "field" ) )
, age( time_duration::from_turns( jsi.get_int( "age", 0 ) ) )
, chance( jsi.get_int( "chance", 100 ) )
, remove( jsi.get_bool( "remove", false ) ) {
if( jsi.has_array( "intensity" ) ) {
for( JsonValue jv : jsi.get_array( "intensity" ) ) {
Expand All @@ -1968,10 +1970,14 @@ class jmapgen_field : public jmapgen_piece
return;
}
if( remove ) {
dat.m.remove_field( tripoint_bub_ms( x.get(), y.get(), dat.zlevel() + z.get() ), chosen_id );
if( x_in_y( chance, 100 ) ) {
dat.m.remove_field( tripoint_bub_ms( x.get(), y.get(), dat.zlevel() + z.get() ), chosen_id );
}
} else {
dat.m.add_field( tripoint_bub_ms( x.get(), y.get(), dat.zlevel() + z.get() ), chosen_id,
random_entry( intensities ), age );
if( x_in_y( chance, 100 ) ) {
dat.m.add_field( tripoint_bub_ms( x.get(), y.get(), dat.zlevel() + z.get() ), chosen_id,
random_entry( intensities ), age );
}
}
}

Expand Down

0 comments on commit b35342f

Please sign in to comment.