Skip to content

Commit

Permalink
refactor tod_manager::get_illuminated_tod to take unit_map as arg
Browse files Browse the repository at this point in the history
Improve encapsulation, eventually remove all resources::pointers
from this object.
  • Loading branch information
cbeck88 committed Jun 13, 2014
1 parent a5b9489 commit 80be563
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/actions/attack.cpp
Expand Up @@ -160,7 +160,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit &u,
// Get the damage multiplier applied to the base damage of the weapon.
int damage_multiplier = 100;
// Time of day bonus.
damage_multiplier += combat_modifier(resources::gameboard->map(), u_loc, u.alignment(), u.is_fearless());
damage_multiplier += combat_modifier(resources::gameboard->units(), resources::gameboard->map(), u_loc, u.alignment(), u.is_fearless());
// Leadership bonus.
int leader_bonus = 0;
if (under_leadership(units, u_loc, &leader_bonus).valid())
Expand Down Expand Up @@ -1615,11 +1615,11 @@ map_location under_leadership(const unit_map& units, const map_location& loc,
return abil.highest("value").second;
}

int combat_modifier(const gamemap & map, const map_location &loc, unit_type::ALIGNMENT alignment,
int combat_modifier(const unit_map & units, const gamemap & map, const map_location &loc, unit_type::ALIGNMENT alignment,
bool is_fearless)
{
const tod_manager & tod_m = *resources::tod_manager;
int lawful_bonus = tod_m.get_illuminated_time_of_day(map, loc).lawful_bonus;
int lawful_bonus = tod_m.get_illuminated_time_of_day(units, map, loc).lawful_bonus;
return generic_combat_modifier(lawful_bonus, alignment, is_fearless);
}

Expand Down
2 changes: 1 addition & 1 deletion src/actions/attack.hpp
Expand Up @@ -248,7 +248,7 @@ map_location under_leadership(const unit_map& units, const map_location& loc,
* Returns the amount that a unit's damage should be multiplied by
* due to the current time of day.
*/
int combat_modifier(const gamemap & map, const map_location &loc, unit_type::ALIGNMENT alignment,
int combat_modifier(const unit_map & units, const gamemap & map, const map_location &loc, unit_type::ALIGNMENT alignment,
bool is_fearless);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ai/formula/function_table.cpp
Expand Up @@ -611,7 +611,7 @@ class timeofday_modifier_function : public function_expression {
loc = &u_call->get_location();
}

return variant(combat_modifier(resources::gameboard->map(),*loc, un.alignment(), un.is_fearless()));
return variant(combat_modifier(resources::gameboard->units(), resources::gameboard->map(),*loc, un.alignment(), un.is_fearless()));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/attack_prediction_display.cpp
Expand Up @@ -211,7 +211,7 @@ void battle_prediction_pane::get_unit_strings(const battle_context_unit_stats& s
}

// Time of day modifier.
int tod_modifier = combat_modifier(resources::gameboard->map(), u_loc, u.alignment(), u.is_fearless());
int tod_modifier = combat_modifier(resources::gameboard->units(), resources::gameboard->map(), u_loc, u.alignment(), u.is_fearless());
if(tod_modifier != 0) {
left_strings.push_back(_("Time of day"));
str.str("");
Expand Down
8 changes: 4 additions & 4 deletions src/reports.cpp
Expand Up @@ -345,7 +345,7 @@ static config unit_alignment(reports::context & rc, const unit* u)
std::ostringstream str, tooltip;
const std::string align = unit_type::alignment_description(u->alignment(), u->gender());
const std::string align_id = lexical_cast<std::string>(u->alignment());
int cm = combat_modifier(rc.map(), rc.screen().displayed_unit_hex(), u->alignment(),
int cm = combat_modifier(rc.units(), rc.map(), rc.screen().displayed_unit_hex(), u->alignment(),
u->is_fearless());

SDL_Color color = font::weapon_color;
Expand Down Expand Up @@ -663,7 +663,7 @@ static int attack_info(reports::context & rc, const attack_type &at, config &res
int base_damage = at.damage();
int specials_damage = at.modified_damage(false);
int damage_multiplier = 100;
int tod_bonus = combat_modifier(rc.map(), displayed_unit_hex, u.alignment(), u.is_fearless());
int tod_bonus = combat_modifier(rc.units(), rc.map(), displayed_unit_hex, u.alignment(), u.is_fearless());
damage_multiplier += tod_bonus;
int leader_bonus = 0;
if (under_leadership(rc.units(), displayed_unit_hex, &leader_bonus).valid())
Expand Down Expand Up @@ -1114,7 +1114,7 @@ static config time_of_day_at(reports::context & rc, const map_location& mouseove
// Don't show illuminated time on fogged tiles.
tod = rc.tod().get_time_of_day(mouseover_hex);
} else {
tod = rc.tod().get_illuminated_time_of_day(rc.map(), mouseover_hex);
tod = rc.tod().get_illuminated_time_of_day(rc.units(), rc.map(), mouseover_hex);
}

int b = tod.lawful_bonus;
Expand Down Expand Up @@ -1164,7 +1164,7 @@ static config unit_box_at(reports::context & rc, const map_location& mouseover_h
// Don't show illuminated time on fogged tiles.
local_tod = rc.tod().get_time_of_day(mouseover_hex);
} else {
local_tod = rc.tod().get_illuminated_time_of_day(rc.map(),mouseover_hex);
local_tod = rc.tod().get_illuminated_time_of_day(rc.units(), rc.map(),mouseover_hex);
}

int bonus = local_tod.lawful_bonus;
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/lua.cpp
Expand Up @@ -1364,7 +1364,7 @@ static int intf_get_time_of_day(lua_State *L)
}

const time_of_day& tod = consider_illuminates ?
resources::tod_manager->get_illuminated_time_of_day(resources::gameboard->map(), loc, for_turn) :
resources::tod_manager->get_illuminated_time_of_day(resources::gameboard->units(), resources::gameboard->map(), loc, for_turn) :
resources::tod_manager->get_time_of_day(loc, for_turn);

lua_newtable(L);
Expand Down
2 changes: 1 addition & 1 deletion src/terrain_filter.cpp
Expand Up @@ -242,7 +242,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
if(flat_) {
tod = resources::tod_manager->get_time_of_day(loc);
} else {
tod = resources::tod_manager->get_illuminated_time_of_day(resources::gameboard->map(),loc);
tod = resources::tod_manager->get_illuminated_time_of_day(resources::gameboard->units(), resources::gameboard->map(),loc);
}

if(!tod_type.empty()) {
Expand Down
4 changes: 1 addition & 3 deletions src/tod_manager.cpp
Expand Up @@ -193,10 +193,8 @@ const time_of_day& tod_manager::get_time_of_day(const map_location& loc, int n_t
return get_time_of_day_turn(times_, n_turn, currentTime_);
}

const time_of_day tod_manager::get_illuminated_time_of_day(const gamemap & map, const map_location& loc, int for_turn) const
const time_of_day tod_manager::get_illuminated_time_of_day(const unit_map & units, const gamemap & map, const map_location& loc, int for_turn) const
{
const unit_map& units = *resources::units;

// get ToD ignoring illumination
time_of_day tod = get_time_of_day(loc, for_turn);

Expand Down
2 changes: 1 addition & 1 deletion src/tod_manager.hpp
Expand Up @@ -75,7 +75,7 @@ class tod_manager : public savegame::savegame_config
* tod areas matter, for_turn = 0 means current turn
* taking account of illumination caused by units
*/
const time_of_day get_illuminated_time_of_day(const gamemap & map, const map_location& loc,
const time_of_day get_illuminated_time_of_day(const unit_map & units, const gamemap & map, const map_location& loc,
int for_turn = 0) const;

const time_of_day& get_previous_time_of_day() const;
Expand Down

0 comments on commit 80be563

Please sign in to comment.