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

Allow overmap specials to use eocs. #57127

Merged
merged 1 commit into from
May 15, 2022
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
8 changes: 7 additions & 1 deletion doc/OVERMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ rotation for the referenced overmap terrains (e.g. the `_north` version for all)
| `mapgen_end` | Specify a C++ mapgen function for a LINEAR feature variation. Prefer JSON instead. |
| `mapgen_tee` | Specify a C++ mapgen function for a LINEAR feature variation. Prefer JSON instead. |
| `mapgen_four_way` | Specify a C++ mapgen function for a LINEAR feature variation. Prefer JSON instead. |
| `eoc` | Supply an effect_on_condition id or an inline effect_on_condition. The condition of the eoc will be tested to see if the special can be placed. The effect of the eoc will be run when the special is placed. See [effect_on_condition.md](effect_on_condition.md). |

### Example

Expand All @@ -268,7 +269,12 @@ an exhaustive example...
"mapgen_curved": [ { "method": "builtin", "name": "road_curved" } ],
"mapgen_end": [ { "method": "builtin", "name": "road_end" } ],
"mapgen_tee": [ { "method": "builtin", "name": "road_tee" } ],
"mapgen_four_way": [ { "method": "builtin", "name": "road_four_way" } ]
"mapgen_four_way": [ { "method": "builtin", "name": "road_four_way" } ],
"eoc": {
"id": "EOC_REFUGEE_CENTER_GENERATE",
"condition": { "compare_int": [ { "global_val": "var", "var_name": "refugee_centers", "default": 0 }, "<", { "const": 1 } ] },
"effect": [ { "arithmetic": [ { "global_val": "var", "var_name": "refugee_centers" }, "++" ] } ]
}
}
```

Expand Down
10 changes: 10 additions & 0 deletions src/effect_on_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ bool effect_on_condition::check_deactivate( dialogue &d ) const
return deactivate_condition( d );
}

bool effect_on_condition::test_condition( dialogue &d ) const
{
return !has_condition || condition( d );
}

void effect_on_condition::apply_true_effects( dialogue &d ) const
{
true_effect.apply( d );
}

void effect_on_conditions::clear( Character &you )
{
while( !you.queued_effect_on_conditions.empty() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/effect_on_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct effect_on_condition {
duration_or_var recurrence;
bool activate( dialogue &d ) const;
bool check_deactivate( dialogue &d ) const;
bool test_condition( dialogue &d ) const;
void apply_true_effects( dialogue &d ) const;
void load( const JsonObject &jo, const std::string &src );
void finalize();
void check() const;
Expand Down
9 changes: 8 additions & 1 deletion src/omdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ class overmap_special
bool is_rotatable() const {
return rotatable_;
}
bool has_eoc() const {
return has_eoc_;
}
effect_on_condition_id get_eoc() const {
return eoc;
}
bool can_spawn() const;
/** Returns terrain at the given point. */
const overmap_special_terrain &get_terrain_at( const tripoint &p ) const;
Expand Down Expand Up @@ -559,7 +565,8 @@ class overmap_special
overmap_special_subtype subtype_;
overmap_special_placement_constraints constraints_;
shared_ptr_fast<const overmap_special_data> data_;

effect_on_condition_id eoc;
bool has_eoc_ = false;
bool rotatable_ = true;
overmap_special_spawns monster_spawns_;
cata::flat_set<std::string> flags_;
Expand Down
18 changes: 17 additions & 1 deletion src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>

#include "all_enum_values.h"
#include "avatar.h"
#include "assign.h"
#include "cached_options.h"
#include "cata_assert.h"
Expand All @@ -27,6 +28,7 @@
#include "cuboid_rectangle.h"
#include "debug.h"
#include "distribution.h"
#include "effect_on_condition.h"
#include "flood_fill.h"
#include "game.h"
#include "generic_factory.h"
Expand Down Expand Up @@ -2677,6 +2679,10 @@ special_placement_result overmap_special::place(
overmap &om, const tripoint_om_omt &origin, om_direction::type dir,
const city &cit, bool must_be_unexplored ) const
{
if( has_eoc() ) {
dialogue d( get_talker_for( get_avatar() ), nullptr );
get_eoc()->apply_true_effects( d );
}
const bool blob = has_flag( "BLOB" );
return data_->place( om, origin, dir, blob, cit, must_be_unexplored );
}
Expand All @@ -2701,7 +2707,10 @@ void overmap_special::load( const JsonObject &jo, const std::string &src )

optional( jo, was_loaded, "subtype", subtype_, overmap_special_subtype::fixed );
optional( jo, was_loaded, "locations", default_locations_ );

if( jo.has_member( "eoc" ) ) {
eoc = effect_on_conditions::load_inline_eoc( jo.get_member( "eoc" ), "" );
has_eoc_ = true;
}
switch( subtype_ ) {
case overmap_special_subtype::fixed: {
shared_ptr_fast<fixed_overmap_special_data> fixed_data =
Expand Down Expand Up @@ -5896,6 +5905,13 @@ bool overmap::can_place_special( const overmap_special &special, const tripoint_
return false;
}

if( special.has_eoc() ) {
dialogue d( get_talker_for( get_avatar() ), nullptr );
if( !special.get_eoc()->test_condition( d ) ) {
return false;
}
}

const std::vector<overmap_special_locations> fixed_terrains = special.required_locations();

return std::all_of( fixed_terrains.begin(), fixed_terrains.end(),
Expand Down
7 changes: 7 additions & 0 deletions tests/overmap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "coordinates.h"
#include "enums.h"
#include "game_constants.h"
#include "global_vars.h"
#include "map.h"
#include "omdata.h"
#include "overmap.h"
Expand Down Expand Up @@ -245,6 +246,9 @@ TEST_CASE( "mutable_overmap_placement", "[overmap][slow]" )
constexpr int num_overmaps = 100;
constexpr int num_trials_per_overmap = 100;

global_variables &globvars = get_globals();
globvars.clear_global_values();

for( int j = 0; j < num_overmaps; ++j ) {
// overmap objects are really large, so we don't want them on the
// stack. Use unique_ptr and put it on the heap
Expand Down Expand Up @@ -346,6 +350,9 @@ TEST_CASE( "overmap_terrain_coverage", "[overmap][slow]" )
std::unordered_set<oter_type_id> done;
std::vector<oter_type_id> missing;

global_variables &globvars = get_globals();
globvars.clear_global_values();

for( const oter_t &ter : overmap_terrains::get_all() ) {
oter_type_id id = ter.get_type_id();
oter_type_str_id id_s = id.id();
Expand Down