added tod_manager member to classes attack_type,
...battle_prediction_pane, attack_prediction_displayer and struct unit_stats (in preparation for gamestatus removal)
This commit is contained in:
parent
ae8725eebb
commit
349edf1e14
9 changed files with 38 additions and 30 deletions
|
@ -277,11 +277,11 @@ battle_context::battle_context(const gamemap& map, const std::vector<team>& team
|
|||
|
||||
if (attacker_weapon == -1) {
|
||||
attacker_weapon = choose_attacker_weapon(attacker, defender, map, teams, units,
|
||||
status, attacker_loc, defender_loc,
|
||||
status, tod_mng, attacker_loc, defender_loc,
|
||||
harm_weight, &defender_weapon, prev_def);
|
||||
} else if (defender_weapon == -1) {
|
||||
defender_weapon = choose_defender_weapon(attacker, defender, attacker_weapon, map, teams,
|
||||
units, status, attacker_loc, defender_loc, prev_def);
|
||||
units, status, tod_mng, attacker_loc, defender_loc, prev_def);
|
||||
}
|
||||
|
||||
// If those didn't have to generate statistics, do so now.
|
||||
|
@ -301,10 +301,10 @@ battle_context::battle_context(const gamemap& map, const std::vector<team>& team
|
|||
assert(!defender_stats_ && !attacker_combatant_ && !defender_combatant_);
|
||||
attacker_stats_ = new unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
true, defender, defender_loc, ddef,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
defender_stats_ = new unit_stats(defender, defender_loc, defender_weapon, false,
|
||||
attacker, attacker_loc, adef,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ battle_context& battle_context::operator=(const battle_context &other)
|
|||
/** @todo FIXME: Hand previous defender unit in here. */
|
||||
int battle_context::choose_defender_weapon(const unit &attacker, const unit &defender, unsigned attacker_weapon,
|
||||
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc,
|
||||
const combatant *prev_def)
|
||||
{
|
||||
|
@ -383,7 +383,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
max_weight = def.defense_weight();
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
min_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
|
||||
|
@ -392,7 +392,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
else if (def.defense_weight() == max_weight) {
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
int simple_rating = static_cast<int>(def_stats->num_blows * def_stats->damage *
|
||||
def_stats->chance_to_hit * def.defense_weight());
|
||||
|
||||
|
@ -407,10 +407,10 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
const attack_type &def = defender.attacks()[choices[i]];
|
||||
unit_stats *att_stats = new unit_stats(attacker, attacker_loc, attacker_weapon,
|
||||
true, defender, defender_loc, &def,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
unit_stats *def_stats = new unit_stats(defender, defender_loc, choices[i], false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
|
||||
combatant *att_comb = new combatant(*att_stats);
|
||||
combatant *def_comb = new combatant(*def_stats, prev_def);
|
||||
|
@ -443,7 +443,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
|
|||
|
||||
int battle_context::choose_attacker_weapon(const unit &attacker, const unit &defender,
|
||||
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc,
|
||||
double harm_weight, int *defender_weapon, const combatant *prev_def)
|
||||
{
|
||||
|
@ -461,7 +461,7 @@ int battle_context::choose_attacker_weapon(const unit &attacker, const unit &def
|
|||
return -1;
|
||||
if (choices.size() == 1) {
|
||||
*defender_weapon = choose_defender_weapon(attacker, defender, choices[0], map, teams, units,
|
||||
status, attacker_loc, defender_loc, prev_def);
|
||||
status, tod_mng, attacker_loc, defender_loc, prev_def);
|
||||
return choices[0];
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ int battle_context::choose_attacker_weapon(const unit &attacker, const unit &def
|
|||
for (i = 0; i < choices.size(); i++) {
|
||||
const attack_type &att = attacker.attacks()[choices[i]];
|
||||
int def_weapon = choose_defender_weapon(attacker, defender, choices[i], map, teams, units,
|
||||
status, attacker_loc, defender_loc, prev_def);
|
||||
status, tod_mng, attacker_loc, defender_loc, prev_def);
|
||||
// If that didn't simulate, do so now.
|
||||
if (!attacker_combatant_) {
|
||||
const attack_type *def = NULL;
|
||||
|
@ -481,10 +481,10 @@ int battle_context::choose_attacker_weapon(const unit &attacker, const unit &def
|
|||
}
|
||||
attacker_stats_ = new unit_stats(attacker, attacker_loc, choices[i],
|
||||
true, defender, defender_loc, def,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
defender_stats_ = new unit_stats(defender, defender_loc, def_weapon, false,
|
||||
attacker, attacker_loc, &att,
|
||||
units, teams, status, map);
|
||||
units, teams, status, tod_mng, map);
|
||||
attacker_combatant_ = new combatant(*attacker_stats_);
|
||||
defender_combatant_ = new combatant(*defender_stats_, prev_def);
|
||||
attacker_combatant_->fight(*defender_combatant_);
|
||||
|
@ -584,6 +584,7 @@ battle_context::unit_stats::unit_stats(const unit &u, const map_location& u_loc,
|
|||
const unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const gamestatus& status,
|
||||
const tod_manager& tod_mng,
|
||||
const gamemap& map) :
|
||||
weapon(0),
|
||||
attack_num(u_attack_num),
|
||||
|
@ -638,9 +639,9 @@ battle_context::unit_stats::unit_stats(const unit &u, const map_location& u_loc,
|
|||
|
||||
// Get the weapon characteristics, if any.
|
||||
if (weapon) {
|
||||
weapon->set_specials_context(*aloc, *dloc, &units, &map, &status, &teams, attacking, opp_weapon);
|
||||
weapon->set_specials_context(*aloc, *dloc, &units, &map, &status, &tod_mng, &teams, attacking, opp_weapon);
|
||||
if (opp_weapon)
|
||||
opp_weapon->set_specials_context(*aloc, *dloc, &units, &map, &status, &teams, !attacking, weapon);
|
||||
opp_weapon->set_specials_context(*aloc, *dloc, &units, &map, &status, &tod_mng, &teams, !attacking, weapon);
|
||||
slows = weapon->get_special_bool("slow");
|
||||
drains = weapon->get_special_bool("drains") && !utils::string_bool(opp.get_state("not_living"));
|
||||
petrifies = weapon->get_special_bool("petrifies");
|
||||
|
|
|
@ -109,7 +109,7 @@ public:
|
|||
const attack_type *opp_weapon,
|
||||
const unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const gamestatus& status, const gamemap& map);
|
||||
const gamestatus& status, const tod_manager& tod_mng, const gamemap& map);
|
||||
~unit_stats();
|
||||
|
||||
/** Dumps the statistics of a unit on stdout. Remove it eventually. */
|
||||
|
@ -155,13 +155,13 @@ private:
|
|||
|
||||
int choose_attacker_weapon(const unit &attacker, const unit &defender,
|
||||
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc,
|
||||
double harm_weight, int *defender_weapon, const combatant *prev_def);
|
||||
|
||||
int choose_defender_weapon(const unit &attacker, const unit &defender, unsigned attacker_weapon,
|
||||
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc, const combatant *prev_def);
|
||||
|
||||
/** Statistics of the units. */
|
||||
|
|
|
@ -91,7 +91,7 @@ void ai_default::do_attack_analysis(
|
|||
std::vector<attack_type>& attacks = unit_itor->second.attacks();
|
||||
for(std::vector<attack_type>::iterator a = attacks.begin(); a != attacks.end(); ++a) {
|
||||
a->set_specials_context(map_location(),map_location(),
|
||||
&units_,&map_,&state_,&teams_,true,NULL);
|
||||
&units_,&map_,&state_,&tod_manager_,&teams_,true,NULL);
|
||||
if(a->get_special_bool("backstab")) {
|
||||
backstab = true;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ const int battle_prediction_pane::max_hp_distrib_rows_ = 10;
|
|||
battle_prediction_pane::battle_prediction_pane(display &disp,
|
||||
const battle_context& bc, const gamemap& map, const
|
||||
std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status, const map_location& attacker_loc,
|
||||
const gamestatus& status, const tod_manager& tod_mng, const map_location& attacker_loc,
|
||||
const map_location& defender_loc) :
|
||||
gui::preview_pane(disp.video()),
|
||||
disp_(disp),
|
||||
|
@ -55,6 +55,7 @@ battle_prediction_pane::battle_prediction_pane(display &disp,
|
|||
teams_(teams),
|
||||
units_(units),
|
||||
status_(status),
|
||||
tod_manager_(tod_mng),
|
||||
attacker_loc_(attacker_loc),
|
||||
defender_loc_(defender_loc),
|
||||
attacker_(units.find(attacker_loc)->second),
|
||||
|
@ -161,7 +162,7 @@ void battle_prediction_pane::get_unit_strings(const battle_context::unit_stats&
|
|||
|
||||
// Set specials context (for safety, it should not have changed normally).
|
||||
const attack_type *weapon = stats.weapon;
|
||||
weapon->set_specials_context(u_loc, opp_loc, &units_, &map_, &status_, &teams_, stats.is_attacker, opp_weapon);
|
||||
weapon->set_specials_context(u_loc, opp_loc, &units_, &map_, &status_, &tod_manager_, &teams_, stats.is_attacker, opp_weapon);
|
||||
|
||||
// Get damage modifiers.
|
||||
unit_ability_list dmg_specials = weapon->get_specials("damage");
|
||||
|
@ -546,7 +547,7 @@ attack_prediction_displayer::RESULT attack_prediction_displayer::button_pressed(
|
|||
const size_t index = size_t(selection);
|
||||
|
||||
if(index < bc_vector_.size()) {
|
||||
battle_prediction_pane battle_pane(disp_, bc_vector_[index], map_, teams_, units_, status_,
|
||||
battle_prediction_pane battle_pane(disp_, bc_vector_[index], map_, teams_, units_, status_, tod_manager_,
|
||||
attacker_loc_, defender_loc_);
|
||||
std::vector<gui::preview_pane*> preview_panes;
|
||||
preview_panes.push_back(&battle_pane);
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
// Lengthy constructor.
|
||||
battle_prediction_pane(display &disp, const battle_context& bc, const gamemap& map,
|
||||
const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc);
|
||||
|
||||
// This method is called to draw the dialog contents.
|
||||
|
@ -50,6 +50,7 @@ private:
|
|||
const std::vector<team>& teams_;
|
||||
const unit_map& units_;
|
||||
const gamestatus& status_;
|
||||
const tod_manager& tod_manager_;
|
||||
const map_location& attacker_loc_;
|
||||
const map_location& defender_loc_;
|
||||
const unit& attacker_;
|
||||
|
@ -131,9 +132,9 @@ class attack_prediction_displayer : public gui::dialog_button_action
|
|||
public:
|
||||
attack_prediction_displayer(display& disp, const std::vector<battle_context>& bc_vector, const gamemap& map,
|
||||
const std::vector<team>& teams, const unit_map& units,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
const map_location& attacker_loc, const map_location& defender_loc)
|
||||
: disp_(disp), bc_vector_(bc_vector), map_(map), teams_(teams), units_(units), status_(status),
|
||||
: disp_(disp), bc_vector_(bc_vector), map_(map), teams_(teams), units_(units), status_(status), tod_manager_(tod_mng),
|
||||
attacker_loc_(attacker_loc), defender_loc_(defender_loc) {}
|
||||
// This method is called when the button is pressed.
|
||||
RESULT button_pressed(int selection);
|
||||
|
@ -145,6 +146,7 @@ private:
|
|||
const std::vector<team>& teams_;
|
||||
const unit_map& units_;
|
||||
const gamestatus& status_;
|
||||
const tod_manager& tod_manager_;
|
||||
const map_location& attacker_loc_;
|
||||
const map_location& defender_loc_;
|
||||
};
|
||||
|
|
|
@ -633,7 +633,7 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
|
|||
gui().highlight_hex(map_location());
|
||||
gui().draw(true,true);
|
||||
|
||||
attack_prediction_displayer ap_displayer(gui(), bc_vector, map_, teams_, units_, status_, attacker_loc, defender_loc);
|
||||
attack_prediction_displayer ap_displayer(gui(), bc_vector, map_, teams_, units_, status_, tod_manager_, attacker_loc, defender_loc);
|
||||
std::vector<gui::dialog_button_info> buttons;
|
||||
buttons.push_back(gui::dialog_button_info(&ap_displayer, _("Damage Calculations")));
|
||||
|
||||
|
|
|
@ -742,7 +742,7 @@ bool attack_type::special_affects_self(const config& cfg) const
|
|||
}
|
||||
void attack_type::set_specials_context(const map_location& aloc,const map_location& dloc,
|
||||
const unit_map* unitmap,
|
||||
const gamemap* map, const gamestatus* game_status,
|
||||
const gamemap* map, const gamestatus* game_status, const tod_manager* tod_mng,
|
||||
const std::vector<team>* /*teams*/, bool attacker,const attack_type* other_attack) const
|
||||
{
|
||||
aloc_ = aloc;
|
||||
|
@ -750,6 +750,7 @@ void attack_type::set_specials_context(const map_location& aloc,const map_locati
|
|||
unitmap_ = unitmap;
|
||||
map_ = map;
|
||||
game_status_ = game_status;
|
||||
tod_manager_ = tod_mng;
|
||||
attacker_ = attacker;
|
||||
other_attack_ = other_attack;
|
||||
}
|
||||
|
@ -760,7 +761,7 @@ void attack_type::set_specials_context(const map_location& loc, const map_locati
|
|||
dloc_ = dloc;
|
||||
unitmap_ = un.units_;
|
||||
map_ = un.map_;
|
||||
game_status_ = un.gamestatus_;
|
||||
game_status_ = un.gamestatus_; //FIXME: set tod_manager_ once unit has a tod_manager member
|
||||
attacker_ = attacker;
|
||||
other_attack_ = NULL;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ attack_type::attack_type(const config& cfg) :
|
|||
unitmap_(NULL),
|
||||
map_(NULL),
|
||||
game_status_(NULL),
|
||||
tod_manager_(NULL),
|
||||
teams_(NULL),
|
||||
other_attack_(NULL),
|
||||
cfg_(cfg),
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
class gamestatus;
|
||||
class tod_manager;
|
||||
class team;
|
||||
class unit;
|
||||
class unit_ability_list;
|
||||
|
@ -60,7 +61,7 @@ public:
|
|||
std::string weapon_specials(bool force=false) const;
|
||||
void set_specials_context(const map_location& aloc,const map_location& dloc,
|
||||
const unit_map* unitmap,
|
||||
const gamemap* map, const gamestatus* game_status,
|
||||
const gamemap* map, const gamestatus* game_status, const tod_manager* tod_mng,
|
||||
const std::vector<team>* teams,bool attacker,const attack_type* other_attack) const;
|
||||
void set_specials_context(const map_location& loc,const map_location& dloc, const unit& un, bool attacker =true) const;
|
||||
|
||||
|
@ -79,6 +80,7 @@ public:
|
|||
mutable const unit_map* unitmap_;
|
||||
mutable const gamemap* map_;
|
||||
mutable const gamestatus* game_status_;
|
||||
mutable const tod_manager* tod_manager_;
|
||||
mutable const std::vector<team>* teams_;
|
||||
mutable const attack_type* other_attack_;
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue