Track whiteboard gold with less future map building.

This commit is contained in:
Gabriel Morin 2011-11-25 17:52:02 +00:00
parent a1fea70ff5
commit 625452d4bf
8 changed files with 34 additions and 48 deletions

View File

@ -781,13 +781,11 @@ bool menu_handler::do_recruit(const std::string &name, int side_num,
const unit_type *u_type = unit_types.find(name);
assert(u_type);
{ wb::future_map future; // so gold takes into account planned spending
if (u_type->cost() > current_team.gold() - resources::whiteboard->get_spent_gold_for(side_num)) {
gui2::show_transient_message(gui_->video(), "",
_("You dont have enough gold to recruit that unit"));
return false;
}
} // end planned unit map scope
if (u_type->cost() > current_team.gold() - resources::whiteboard->get_spent_gold_for(side_num)) {
gui2::show_transient_message(gui_->video(), "",
_("You dont have enough gold to recruit that unit"));
return false;
}
last_recruit_ = name;
const events::command_disabler disable_commands;
@ -982,19 +980,17 @@ void menu_handler::recall(int side_num, const map_location &last_hex)
}
{ wb::future_map future; // so gold takes into account planned spending
int wb_gold = resources::whiteboard->get_spent_gold_for(side_num);
if (current_team.gold() - wb_gold < current_team.recall_cost()) {
utils::string_map i18n_symbols;
i18n_symbols["cost"] = lexical_cast<std::string>(current_team.recall_cost());
std::string msg = vngettext(
"You must have at least 1 gold piece to recall a unit",
"You must have at least $cost gold pieces to recall a unit",
current_team.recall_cost(), i18n_symbols);
gui2::show_transient_message(gui_->video(), "", msg);
return;
}
} // end planned unit map scope
int wb_gold = resources::whiteboard->get_spent_gold_for(side_num);
if (current_team.gold() - wb_gold < current_team.recall_cost()) {
utils::string_map i18n_symbols;
i18n_symbols["cost"] = lexical_cast<std::string>(current_team.recall_cost());
std::string msg = vngettext(
"You must have at least 1 gold piece to recall a unit",
"You must have at least $cost gold pieces to recall a unit",
current_team.recall_cost(), i18n_symbols);
gui2::show_transient_message(gui_->video(), "", msg);
return;
}
LOG_NG << "recall index: " << res << "\n";
const events::command_disabler disable_commands;

View File

@ -126,6 +126,15 @@ bool mapbuilder::visit(size_t, team&, side_actions&, side_actions::iterator itor
return true;
}
bool mapbuilder::pre_visit_team(size_t team_index, team&, side_actions& sa)
{
//Reset spent gold to zero, it'll be recalculated during the map building
if( resources::controller->current_side() == (int)team_index+1)
sa.reset_gold_spent();
return !sa.hidden();
}
bool mapbuilder::post_visit_team(size_t, team&, side_actions&)
{
acted_this_turn_.clear();

View File

@ -50,6 +50,7 @@ public:
private:
//"Inherited" from enable_visit_all
bool visit(size_t team_index, team&, side_actions&, side_actions::iterator);
bool pre_visit_team(size_t team_index, team&, side_actions&);
bool post_visit_team(size_t team_index, team&, side_actions&);
//helper for visit(), above

View File

@ -57,8 +57,7 @@ recall::recall(size_t team_index, bool hidden, const unit& unit, const map_locat
temp_unit_(new class unit(unit)),
recall_hex_(recall_hex),
valid_(true),
fake_unit_(new class game_display::fake_unit(unit) ),
temp_cost_(0)
fake_unit_(new class game_display::fake_unit(unit) )
{
this->init();
}
@ -69,7 +68,6 @@ recall::recall(config const& cfg, bool hidden)
, recall_hex_(cfg.child("recall_hex_")["x"],cfg.child("recall_hex_")["y"])
, valid_(true)
, fake_unit_()
, temp_cost_(0)
{
// Construct and validate temp_unit_
size_t underlying_id = cfg["temp_unit_"];
@ -141,8 +139,8 @@ void recall::apply_temp_modifier(unit_map& unit_map)
temp_unit_ = NULL;
//Add cost to money spent on recruits.
temp_cost_ = resources::teams->at(team_index()).recall_cost();
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(temp_cost_);
int cost = resources::teams->at(team_index()).recall_cost();
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
// Update gold in top bar
resources::screen->invalidate_game_status();
@ -155,13 +153,6 @@ void recall::remove_temp_modifier(unit_map& unit_map)
//Put unit back into recall list
resources::teams->at(team_index()).recall_list().push_back(*temp_unit_);
/*
* Remove cost from money spent on recruits.
*/
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(-temp_cost_);
temp_cost_ = 0;
resources::screen->invalidate_game_status();
}
void recall::draw_hex(map_location const& hex)

View File

@ -80,7 +80,6 @@ private:
map_location recall_hex_;
bool valid_;
fake_unit_ptr fake_unit_;
int temp_cost_;
};
std::ostream& operator<<(std::ostream& s, recall_ptr recall);

View File

@ -58,8 +58,7 @@ recruit::recruit(size_t team_index, bool hidden, const std::string& unit_name, c
recruit_hex_(recruit_hex),
temp_unit_(create_corresponding_unit()),
valid_(true),
fake_unit_(create_corresponding_unit()),
temp_cost_()
fake_unit_(create_corresponding_unit())
{
this->init();
}
@ -71,7 +70,6 @@ recruit::recruit(config const& cfg, bool hidden)
, temp_unit_()
, valid_(true)
, fake_unit_()
, temp_cost_()
{
// Validate unit_name_
if(!unit_types.find(unit_name_))
@ -119,10 +117,9 @@ void recruit::apply_temp_modifier(unit_map& unit_map)
DBG_WB << "Inserting future recruit [" << temp_unit_->id()
<< "] at position " << temp_unit_->get_location() << ".\n";
temp_cost_ = temp_unit_->type()->cost();
int cost = temp_unit_->type()->cost();
// Add cost to money spent on recruits.
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(temp_cost_);
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
// Temporarily insert unit into unit_map
unit_map.insert(temp_unit_);
@ -137,13 +134,6 @@ void recruit::remove_temp_modifier(unit_map& unit_map)
{
temp_unit_ = unit_map.extract(recruit_hex_);
assert(temp_unit_);
/*
* Remove cost from money spent on recruits.
*/
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(-temp_cost_);
temp_cost_ = 0;
resources::screen->invalidate_game_status();
}
void recruit::draw_hex(map_location const& hex)

View File

@ -84,8 +84,6 @@ protected:
bool valid_;
fake_unit_ptr fake_unit_;
int temp_cost_;
private:
void init();

View File

@ -243,6 +243,8 @@ public:
int get_gold_spent() const { return gold_spent_; }
///Used to track gold spending by recruits/recalls when building the future unit map
void change_gold_spent_by(int difference) { gold_spent_ += difference; assert(gold_spent_ >= 0);}
///Set gold spent back to zero
void reset_gold_spent() { gold_spent_ = 0; }
void raw_turn_shift();
void synced_turn_shift();