added a tod_manager member to classes battle_context,
...attack and mouse_handler (in preparation of gamestatus removal)
This commit is contained in:
parent
8cf542c170
commit
ae8725eebb
12 changed files with 35 additions and 25 deletions
|
@ -263,7 +263,7 @@ map_location under_leadership(const unit_map& units,
|
|||
}
|
||||
|
||||
battle_context::battle_context(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,
|
||||
int attacker_weapon, int defender_weapon, double aggression, const combatant *prev_def, const unit* attacker_ptr)
|
||||
: attacker_stats_(NULL), defender_stats_(NULL), attacker_combatant_(NULL), defender_combatant_(NULL)
|
||||
|
@ -847,7 +847,7 @@ void attack::refresh_bc()
|
|||
return;
|
||||
}
|
||||
|
||||
*bc_ = battle_context(map_, teams_, units_, state_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_);
|
||||
*bc_ = battle_context(map_, teams_, units_, state_, tod_manager_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_);
|
||||
a_stats_ = &bc_->get_attacker_stats();
|
||||
d_stats_ = &bc_->get_defender_stats();
|
||||
a_.cth_ = a_stats_->chance_to_hit;
|
||||
|
@ -905,6 +905,7 @@ attack::attack(game_display& gui, const gamemap& map,
|
|||
int defend_with,
|
||||
unit_map& units,
|
||||
const gamestatus& state,
|
||||
const tod_manager& tod_mng,
|
||||
bool update_display) :
|
||||
gui_(gui),
|
||||
map_(map),
|
||||
|
@ -916,6 +917,7 @@ attack::attack(game_display& gui, const gamemap& map,
|
|||
d_(defender, defend_with, units),
|
||||
units_(units),
|
||||
state_(state),
|
||||
tod_manager_(tod_mng),
|
||||
errbuf_(),
|
||||
update_display_(update_display),
|
||||
OOS_error_(false),
|
||||
|
@ -945,7 +947,7 @@ attack::attack(game_display& gui, const gamemap& map,
|
|||
// If the attacker was invisible, she isn't anymore!
|
||||
a_.get_unit().set_state(unit::STATE_HIDDEN,false);
|
||||
|
||||
bc_ = new battle_context(map_, teams_, units_, state_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_);
|
||||
bc_ = new battle_context(map_, teams_, units_, state_, tod_manager_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_);
|
||||
a_stats_ = &bc_->get_attacker_stats();
|
||||
d_stats_ = &bc_->get_defender_stats();
|
||||
if(a_stats_->weapon) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
class display;
|
||||
class gamestatus;
|
||||
class tod_manager;
|
||||
class game_display;
|
||||
class replay;
|
||||
struct combatant;
|
||||
|
@ -122,7 +123,7 @@ public:
|
|||
* prev_def is for predicting multiple attacks against a defender.
|
||||
*/
|
||||
battle_context(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,
|
||||
int attacker_weapon = -1, int defender_weapon = -1, double aggression = 0.0, const combatant *prev_def = NULL, const unit* attacker_ptr=NULL);
|
||||
|
||||
|
@ -181,6 +182,7 @@ class attack {
|
|||
int defend_with,
|
||||
unit_map& units,
|
||||
const gamestatus& state,
|
||||
const tod_manager& tod_mng,
|
||||
bool update_display = true);
|
||||
~attack();
|
||||
private:
|
||||
|
@ -218,6 +220,7 @@ class attack {
|
|||
unit_info a_, d_;
|
||||
unit_map& units_;
|
||||
const gamestatus& state_;
|
||||
const tod_manager& tod_manager_;
|
||||
std::stringstream errbuf_;
|
||||
|
||||
bool update_display_;
|
||||
|
|
|
@ -529,7 +529,7 @@ void readwrite_context_impl::attack_enemy(const map_location u,
|
|||
}
|
||||
try {
|
||||
attack(get_info().disp, get_info().map, get_info().teams, u, target, weapon, def_weapon,
|
||||
get_info().units, get_info().state);
|
||||
get_info().units, get_info().state, get_info().tod_manager_);
|
||||
}
|
||||
catch (end_level_exception&)
|
||||
{
|
||||
|
|
|
@ -144,7 +144,7 @@ protected:
|
|||
if(best_defense != -1) {
|
||||
move_unit(best_movement.second,best_movement.first,possible_moves);
|
||||
battle_context bc(get_info().map, get_info().teams,
|
||||
get_info().units, get_info().state,
|
||||
get_info().units, get_info().state, get_info().tod_manager_,
|
||||
best_movement.first,
|
||||
i->first, -1, -1, current_team().aggression());
|
||||
attack_enemy(best_movement.first,i->first,
|
||||
|
@ -459,7 +459,7 @@ map_location ai_default::move_unit(map_location from, map_location to, ai::moves
|
|||
const unit_map::const_iterator itor = units_.find(*adj_i);
|
||||
if(itor != units_.end() && current_team().is_enemy(itor->second.side()) &&
|
||||
!itor->second.incapacitated()) {
|
||||
battle_context bc(map_, teams_, units_, state_,
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_,
|
||||
res, *adj_i, -1, -1, current_team().aggression());
|
||||
attack_enemy(res,itor->first,bc.get_attacker_stats().attack_num,bc.get_defender_stats().attack_num);
|
||||
break;
|
||||
|
@ -872,7 +872,7 @@ bool ai_default::do_combat(std::map<map_location,paths>& possible_moves, const m
|
|||
}
|
||||
|
||||
// Recalc appropriate weapons here: AI uses approximations.
|
||||
battle_context bc(map_, teams_, units_, state_,
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_,
|
||||
to, target_loc, -1, -1,
|
||||
current_team().aggression());
|
||||
attack_enemy(to, target_loc, bc.get_attacker_stats().attack_num,
|
||||
|
@ -1160,7 +1160,7 @@ bool ai_default::move_to_targets(std::map<map_location, paths>& possible_moves,
|
|||
if (!enemy || !current_team().is_enemy(enemy->side()) || enemy->incapacitated())
|
||||
continue;
|
||||
// Current behavior is to only make risk-free attacks.
|
||||
battle_context bc(map_, teams_, units_, state_, arrived_at, adj[n], -1, -1, 100.0);
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_, arrived_at, adj[n], -1, -1, 100.0);
|
||||
#ifndef SUOKKO
|
||||
if (bc.get_defender_stats().damage == 0) {
|
||||
attack_enemy(arrived_at, adj[n], bc.get_attacker_stats().attack_num,
|
||||
|
|
|
@ -199,7 +199,7 @@ public:
|
|||
|
||||
void analyze(const gamemap& map, unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
class ai_default& ai_obj,
|
||||
const move_map& dstsrc, const move_map& srcdst,
|
||||
const move_map& enemy_dstsrc, double aggression);
|
||||
|
|
|
@ -268,7 +268,7 @@ void ai_default::do_attack_analysis(
|
|||
|
||||
cur_analysis.is_surrounded = is_surrounded;
|
||||
|
||||
cur_analysis.analyze(map_, units_, teams_, state_, *this, dstsrc, srcdst, enemy_dstsrc, current_team().aggression());
|
||||
cur_analysis.analyze(map_, units_, teams_, state_, tod_manager_, *this, dstsrc, srcdst, enemy_dstsrc, current_team().aggression());
|
||||
|
||||
//This logic to sometimes not add the attack because it doesn't
|
||||
//rate high enough seems to remove attacks from consideration
|
||||
|
@ -297,7 +297,7 @@ void ai_default::do_attack_analysis(
|
|||
|
||||
void ai_default::attack_analysis::analyze(const gamemap& map, unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const gamestatus& status,
|
||||
const gamestatus& status, const tod_manager& tod_mng,
|
||||
class ai_default& ai_obj,
|
||||
const move_map& dstsrc, const move_map& srcdst,
|
||||
const move_map& enemy_dstsrc, double aggression)
|
||||
|
@ -388,7 +388,7 @@ void ai_default::attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
from_cache = true;
|
||||
bc = new battle_context(usc->second.first, usc->second.second);
|
||||
} else {
|
||||
bc = new battle_context(map, teams, units, status, m->second, target, att_weapon, def_weapon, aggression, prev_def);
|
||||
bc = new battle_context(map, teams, units, status, tod_mng, m->second, target, att_weapon, def_weapon, aggression, prev_def);
|
||||
}
|
||||
const combatant &att = bc->get_attacker_combatant(prev_def);
|
||||
const combatant &def = bc->get_defender_combatant(prev_def);
|
||||
|
@ -779,7 +779,7 @@ bool ai_default::desperate_attack(const map_location &loc)
|
|||
// Skip weapons with attack_weight=0
|
||||
if (attacks[i].attack_weight() == 0)
|
||||
continue;
|
||||
battle_context bc(map_, teams_, units_, state_, loc, adj[n], i);
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_, loc, adj[n], i);
|
||||
combatant att(bc.get_attacker_stats());
|
||||
combatant def(bc.get_defender_stats());
|
||||
att.fight(def);
|
||||
|
@ -811,7 +811,7 @@ bool ai_default::desperate_attack(const map_location &loc)
|
|||
// SKip weapons with attack_weight=0
|
||||
if (attacks[i].attack_weight() == 0)
|
||||
continue;
|
||||
battle_context bc(map_, teams_, units_, state_, adj[n], loc, i);
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_, adj[n], loc, i);
|
||||
combatant att(bc.get_attacker_stats());
|
||||
combatant def(bc.get_defender_stats());
|
||||
att.fight(def);
|
||||
|
@ -824,7 +824,7 @@ bool ai_default::desperate_attack(const map_location &loc)
|
|||
|
||||
// It is possible that there were no adjacent units to attack...
|
||||
if (least_hp != u.hitpoints() + 1) {
|
||||
battle_context bc(map_, teams_, units_, state_, loc, adj[best_dir], -1, -1, 0.5);
|
||||
battle_context bc(map_, teams_, units_, state_, tod_manager_, loc, adj[best_dir], -1, -1, 0.5);
|
||||
attack_enemy(loc, adj[best_dir], bc.get_attacker_stats().attack_num,
|
||||
bc.get_defender_stats().attack_num);
|
||||
return true;
|
||||
|
|
|
@ -509,7 +509,7 @@ private:
|
|||
}
|
||||
|
||||
battle_context bc(ai_.get_info().map, ai_.get_info().teams, ai_.get_info().units,
|
||||
ai_.get_info().state, convert_variant<location_callable>(args()[1]->evaluate(variables))->loc(),
|
||||
ai_.get_info().state, ai_.get_info().tod_manager_, convert_variant<location_callable>(args()[1]->evaluate(variables))->loc(),
|
||||
defender_location, weapon, -1, 1.0, NULL, &ai_.get_info().units.find(attacker_location)->second);
|
||||
std::vector<double> hp_dist = bc.get_attacker_combatant().hp_dist;
|
||||
std::vector<double>::iterator it = hp_dist.begin();
|
||||
|
@ -895,7 +895,7 @@ public:
|
|||
int weapon)
|
||||
: move_from_(move_from), src_(src), dst_(dst),
|
||||
bc_(ai.get_info().map, ai.get_info().teams, ai.get_info().units,
|
||||
ai.get_info().state, src, dst, weapon, -1, 1.0, NULL,
|
||||
ai.get_info().state, ai.get_info().tod_manager_, src, dst, weapon, -1, 1.0, NULL,
|
||||
&ai.get_info().units.find(move_from)->second)
|
||||
{
|
||||
}
|
||||
|
@ -2138,7 +2138,7 @@ bool formula_ai::execute_variant(const variant& var, bool commandline)
|
|||
|
||||
if(get_info().units.count(att_src)) {
|
||||
battle_context bc(get_info().map, get_info().teams,
|
||||
get_info().units, get_info().state,
|
||||
get_info().units, get_info().state, get_info().tod_manager_,
|
||||
att_src, att_dst, -1, -1, 1.0, NULL,
|
||||
&get_info().units.find(att_src)->second);
|
||||
attack_enemy(attack_analysis->movements.front().second,
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace events{
|
|||
|
||||
|
||||
mouse_handler::mouse_handler(game_display* gui, std::vector<team>& teams,
|
||||
unit_map& units, gamemap& map, gamestatus& status,
|
||||
unit_map& units, gamemap& map, gamestatus& status, tod_manager& tod_mng,
|
||||
undo_list& undo_stack, undo_list& redo_stack) :
|
||||
mouse_handler_base(),
|
||||
map_(map),
|
||||
|
@ -44,6 +44,7 @@ mouse_handler::mouse_handler(game_display* gui, std::vector<team>& teams,
|
|||
teams_(teams),
|
||||
units_(units),
|
||||
status_(status),
|
||||
tod_manager_(tod_mng),
|
||||
undo_stack_(undo_stack),
|
||||
redo_stack_(redo_stack),
|
||||
previous_hex_(),
|
||||
|
@ -579,7 +580,7 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
|
|||
for (i = 0; i < attacker->second.attacks().size(); i++) {
|
||||
// skip weapons with attack_weight=0
|
||||
if (attacker->second.attacks()[i].attack_weight() > 0) {
|
||||
battle_context bc(map_, teams_, units_, status_, attacker->first, defender->first, i);
|
||||
battle_context bc(map_, teams_, units_, status_, tod_manager_, attacker->first, defender->first, i);
|
||||
bc_vector.push_back(bc);
|
||||
if (bc.better_attack(bc_vector[best], 0.5)) {
|
||||
best = i;
|
||||
|
@ -672,7 +673,7 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
|
|||
current_team().set_action_bonus_count(1 + current_team().action_bonus_count());
|
||||
|
||||
try {
|
||||
attack(gui(),map_,teams_,attacker_loc,defender_loc,att.attack_num,def.attack_num,units_,status_);
|
||||
attack(gui(),map_,teams_,attacker_loc,defender_loc,att.attack_num,def.attack_num,units_,status_, tod_manager_);
|
||||
} catch(end_level_exception&) {
|
||||
//if the level ends due to a unit being killed, still see if
|
||||
//either the attacker or defender should advance
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "unit_map.hpp"
|
||||
#include "mouse_handler_base.hpp"
|
||||
class gamestatus;
|
||||
class tod_manager;
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
@ -32,7 +33,7 @@ namespace events{
|
|||
class mouse_handler : public mouse_handler_base {
|
||||
public:
|
||||
mouse_handler(game_display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
|
||||
gamestatus& status, undo_list& undo_stack, undo_list& redo_stack);
|
||||
gamestatus& status, tod_manager& tod_mng, undo_list& undo_stack, undo_list& redo_stack);
|
||||
~mouse_handler();
|
||||
static mouse_handler* get_singleton() { return singleton_ ;}
|
||||
void set_side(int side_number);
|
||||
|
@ -94,6 +95,7 @@ private:
|
|||
std::vector<team>& teams_;
|
||||
unit_map& units_;
|
||||
gamestatus& status_;
|
||||
tod_manager& tod_manager_;
|
||||
undo_list& undo_stack_;
|
||||
undo_list& redo_stack_;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
|
|||
halo_manager_(),
|
||||
labels_manager_(),
|
||||
help_manager_(&game_config, &map_),
|
||||
mouse_handler_(NULL, teams_, units_, map_, status_, undo_stack_, redo_stack_),
|
||||
mouse_handler_(NULL, teams_, units_, map_, status_, tod_manager_, undo_stack_, redo_stack_),
|
||||
menu_handler_(NULL, units_, teams_, level, map_, game_config, status_, state_of_game, undo_stack_, redo_stack_),
|
||||
soundsources_manager_(),
|
||||
tod_manager_(level, num_turns, &state_of_game),
|
||||
|
|
|
@ -99,6 +99,8 @@ public:
|
|||
const config& time_cfg) {tod_manager_.add_time_area(id, locs, time_cfg);}
|
||||
void remove_time_area(const std::string& id) {tod_manager_.remove_time_area(id);}
|
||||
|
||||
const tod_manager& get_tod_manager() const {return tod_manager_;} //FIXME: added getter for tod_manager until do_replay_handle is fixed
|
||||
|
||||
config to_config();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1116,7 +1116,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map,
|
|||
|
||||
DBG_REPLAY << "Attacker XP (before attack): " << u->second.experience() << "\n";;
|
||||
|
||||
DELAY_END_LEVEL(delayed_exception, attack(disp, map, teams, src, dst, weapon_num, def_weapon_num, units, state, !get_replay_source().is_skipping()));
|
||||
DELAY_END_LEVEL(delayed_exception, attack(disp, map, teams, src, dst, weapon_num, def_weapon_num, units, state, controller.get_tod_manager(), !get_replay_source().is_skipping()));
|
||||
|
||||
DBG_REPLAY << "Attacker XP (after attack): " << u->second.experience() << "\n";;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue