Removed resources::units once again
I had re-added it in a limited context in eaea9be117
since I needed it to fix
(IIRC) a crash in the editor when adding units, since the editor didn't have a game_board.
However, looking at the code again, I realized that the display class (base of editor_display)
holds a pointer to a display_context object. map_context inherits from display_context, and
the editor sets the editor_display's display_context to the current map_context. Therefor, I
could just access the units needed via display::get_units, instead of needing a global pointer.
This commit is contained in:
parent
489dcebd01
commit
6a21fdc675
6 changed files with 16 additions and 21 deletions
|
@ -159,7 +159,6 @@ void editor_controller::init_music(const config& game_config)
|
|||
|
||||
editor_controller::~editor_controller()
|
||||
{
|
||||
resources::units = nullptr;
|
||||
resources::tod_manager = nullptr;
|
||||
resources::filter_con = nullptr;
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
|
||||
// TODO register the tod_manager with the gui?
|
||||
resources::tod_manager = context_manager_.get_map_context().get_time_manager();
|
||||
resources::units = &context_manager_.get_map_context().units();
|
||||
resources::filter_con = &context_manager_.gui();
|
||||
|
||||
context_manager_.gui().replace_overlay_map(&context_manager_.get_map_context().get_overlays());
|
||||
|
|
|
@ -125,7 +125,6 @@ static void clear_resources()
|
|||
resources::tunnels = nullptr;
|
||||
resources::undo_stack = nullptr;
|
||||
resources::recorder = nullptr;
|
||||
resources::units = nullptr;
|
||||
resources::whiteboard.reset();
|
||||
resources::classification = nullptr;
|
||||
}
|
||||
|
@ -212,7 +211,6 @@ void play_controller::init(const config& level)
|
|||
resources::gameboard = &gamestate().board_;
|
||||
resources::gamedata = &gamestate().gamedata_;
|
||||
resources::tod_manager = &gamestate().tod_manager_;
|
||||
resources::units = &gamestate().board_.units_;
|
||||
resources::filter_con = &gamestate();
|
||||
resources::undo_stack = &undo_stack();
|
||||
resources::game_events = gamestate().events_manager_.get();
|
||||
|
@ -295,7 +293,6 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
|
|||
resources::gameboard = nullptr;
|
||||
resources::gamedata = nullptr;
|
||||
resources::tod_manager = nullptr;
|
||||
resources::units = nullptr;
|
||||
resources::filter_con = nullptr;
|
||||
resources::lua_kernel = nullptr;
|
||||
resources::game_events = nullptr;
|
||||
|
@ -312,7 +309,6 @@ void play_controller::reset_gamestate(const config& level, int replay_pos)
|
|||
resources::gameboard = &gamestate().board_;
|
||||
resources::gamedata = &gamestate().gamedata_;
|
||||
resources::tod_manager = &gamestate().tod_manager_;
|
||||
resources::units = &gamestate().board_.units_;
|
||||
resources::filter_con = &gamestate();
|
||||
resources::undo_stack = &undo_stack();
|
||||
resources::game_events = gamestate().events_manager_.get();
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace resources
|
|||
fake_unit_manager *fake_units = nullptr;
|
||||
pathfind::manager *tunnels = nullptr;
|
||||
actions::undo_list *undo_stack = nullptr;
|
||||
unit_map *units = nullptr;
|
||||
std::shared_ptr<wb::manager> whiteboard = std::shared_ptr<wb::manager>();
|
||||
game_classification *classification = nullptr;
|
||||
bool simulation_ = false;
|
||||
|
|
|
@ -57,7 +57,6 @@ namespace resources
|
|||
extern ::tod_manager *tod_manager;
|
||||
extern pathfind::manager *tunnels;
|
||||
extern actions::undo_list *undo_stack;
|
||||
extern unit_map *units;
|
||||
extern std::shared_ptr<wb::manager> whiteboard;
|
||||
extern bool simulation_;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Manage unit-abilities, like heal, cure, and weapon_specials.
|
||||
*/
|
||||
|
||||
#include "display.hpp"
|
||||
#include "display_context.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
|
@ -145,8 +146,8 @@ bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc
|
|||
}
|
||||
}
|
||||
|
||||
assert(resources::units);
|
||||
const unit_map& units = *resources::units;
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
|
@ -186,8 +187,8 @@ unit_ability_list unit::get_abilities(const std::string& tag_name, const map_loc
|
|||
}
|
||||
}
|
||||
|
||||
assert(resources::units);
|
||||
const unit_map& units = *resources::units;
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
|
@ -312,8 +313,8 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
|
||||
assert(resources::units);
|
||||
const unit_map& units = *resources::units;
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
for (const config &i : cfg.child_range("filter_adjacent"))
|
||||
{
|
||||
|
@ -449,15 +450,17 @@ T get_single_ability_value(const config::attribute_value& v, T def, const map_lo
|
|||
return v.apply_visitor(make_get_ability_value_visitor(def, [&](const std::string& s) {
|
||||
|
||||
try {
|
||||
assert(resources::units);
|
||||
auto u_itor = resources::units->find(sender_loc);
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
if(u_itor == resources::units->end()) {
|
||||
auto u_itor = units.find(sender_loc);
|
||||
|
||||
if(u_itor == units.end()) {
|
||||
return def;
|
||||
}
|
||||
wfl::map_formula_callable callable(std::make_shared<wfl::unit_callable>(*u_itor));
|
||||
u_itor = resources::units->find(receiver_loc);
|
||||
if(u_itor != resources::units->end()) {
|
||||
u_itor = units.find(receiver_loc);
|
||||
if(u_itor != units.end()) {
|
||||
callable.add("other", wfl::variant(std::make_shared<wfl::unit_callable>(*u_itor)));
|
||||
}
|
||||
return formula_handler(wfl::formula(s, new wfl::gamestate_function_symbol_table), callable);
|
||||
|
@ -913,8 +916,8 @@ bool attack_type::special_active(const config& special, AFFECTS whom,
|
|||
}
|
||||
|
||||
// Get the units involved.
|
||||
assert(resources::units);
|
||||
const unit_map& units = *resources::units;
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
unit_map::const_iterator self = units.find(self_loc_);
|
||||
unit_map::const_iterator other = units.find(other_loc_);
|
||||
|
|
Loading…
Add table
Reference in a new issue