added population of team.recall_list_ in by menu events and wml functions
This commit is contained in:
parent
7be030bc4a
commit
0a3380a364
2 changed files with 52 additions and 2 deletions
|
@ -1996,6 +1996,7 @@ static bool try_add_unit_to_recall_list(const map_location& loc, const unit& u)
|
|||
|
||||
if(player != NULL) {
|
||||
player->available_units.push_back(u);
|
||||
(*rsrc.teams)[u.side()-1].recall_list().push_back(u);
|
||||
return true;
|
||||
} else {
|
||||
ERR_NG << "Cannot create unit: location (" << loc.x << "," << loc.y <<") is not on the map, and player "
|
||||
|
@ -2084,6 +2085,7 @@ WML_HANDLER_FUNCTION(recall, /*event_info*/, cfg)
|
|||
|
||||
std::vector<unit>& avail = player->available_units;
|
||||
|
||||
int position = 0; //track position of unit to delete
|
||||
for(std::vector<unit>::iterator u = avail.begin(); u != avail.end(); ++u) {
|
||||
DBG_NG << "checking unit against filter...\n";
|
||||
u->set_game_context(rsrc.units, rsrc.game_map, &rsrc.controller->get_tod_manager(), rsrc.teams);
|
||||
|
@ -2092,11 +2094,14 @@ WML_HANDLER_FUNCTION(recall, /*event_info*/, cfg)
|
|||
map_location loc = cfg_to_loc(cfg);
|
||||
unit to_recruit(*u);
|
||||
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
|
||||
(*rsrc.teams)[index].recall_list().erase((*rsrc.teams)[index].recall_list().begin() + position);
|
||||
recruit_unit(*rsrc.game_map, index + 1, *rsrc.units, to_recruit, loc, true, utils::string_bool(cfg["show"], true), false, true, true);
|
||||
unit_recalled = true;
|
||||
break;
|
||||
}
|
||||
++position;
|
||||
}
|
||||
//assert(player->available_units.size() == (*rsrc.teams)[index].recall_list().size()); //FIXME: remove after player_info removal
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2334,6 +2339,20 @@ WML_HANDLER_FUNCTION(kill, event_info, cfg)
|
|||
}
|
||||
}
|
||||
}
|
||||
//remove the unit from the corresponding team's recall list aswell
|
||||
for(std::vector<team>::iterator pi = rsrc.teams->begin();
|
||||
pi!=rsrc.teams->end(); ++pi)
|
||||
{
|
||||
std::vector<unit>& avail_units = pi->recall_list();
|
||||
for(std::vector<unit>::iterator j = avail_units.begin(); j != avail_units.end();) {
|
||||
j->set_game_context(rsrc.units, rsrc.game_map, &rsrc.controller->get_tod_manager(), rsrc.teams);
|
||||
if(game_events::unit_matches_filter(*j, cfg,map_location())) {
|
||||
j = avail_units.erase(j);
|
||||
} else {
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2495,6 +2514,21 @@ WML_HANDLER_FUNCTION(store_unit, /*event_info*/, cfg)
|
|||
}
|
||||
}
|
||||
}
|
||||
//remove unit from team.recall_list_ aswell
|
||||
if (kill_units) {
|
||||
for(std::vector<team>::iterator pi = rsrc.teams->begin();
|
||||
pi != rsrc.teams->end(); ++pi) {
|
||||
std::vector<unit>& avail_units = pi->recall_list();
|
||||
for(std::vector<unit>::iterator j = avail_units.begin(); j != avail_units.end();) {
|
||||
j->set_game_context(rsrc.units, rsrc.game_map, &rsrc.controller->get_tod_manager(), rsrc.teams);
|
||||
if(game_events::unit_matches_filter(*j, filter,map_location()) == false) {
|
||||
++j;
|
||||
continue;
|
||||
}
|
||||
j = avail_units.erase(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mode != "append") {
|
||||
varinfo.vars->clear_children(varinfo.key);
|
||||
|
@ -2588,6 +2622,8 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
|
|||
* a vector to a map and use the underlying_id as key.
|
||||
*/
|
||||
const size_t key = u.underlying_id();
|
||||
int position = 0; //FIXME: stores position of iterator for team.recall_list_, remove once player_info is removed
|
||||
team& t = (*rsrc.teams)[u.side()-1];
|
||||
for(std::vector<unit>::iterator itor =
|
||||
player->available_units.begin();
|
||||
itor != player->available_units.end(); ++itor) {
|
||||
|
@ -2596,10 +2632,13 @@ WML_HANDLER_FUNCTION(unstore_unit, /*event_info*/, cfg)
|
|||
<< key << "' on the recall list\n";
|
||||
if(itor->underlying_id() == key) {
|
||||
player->available_units.erase(itor);
|
||||
t.recall_list().erase(t.recall_list().begin() + position);
|
||||
break;
|
||||
}
|
||||
++position;
|
||||
}
|
||||
player->available_units.push_back(u);
|
||||
t.recall_list().push_back(u);
|
||||
} else {
|
||||
ERR_NG << "Cannot unstore unit: no recall list for player " << u.side()
|
||||
<< " and the map location is invalid.\n";
|
||||
|
|
|
@ -58,13 +58,14 @@ namespace events{
|
|||
class delete_recall_unit : public gui::dialog_button_action
|
||||
{
|
||||
public:
|
||||
delete_recall_unit(game_display& disp, gui::filter_textbox& filter, std::vector<unit>& units, undo_list& undo_stack, undo_list& redo_stack) : disp_(disp), filter_(filter), units_(units), undo_stack_(undo_stack), redo_stack_(redo_stack) {}
|
||||
delete_recall_unit(game_display& disp, gui::filter_textbox& filter, std::vector<unit>& units, std::vector<unit>& units_teams, undo_list& undo_stack, undo_list& redo_stack) : disp_(disp), filter_(filter), units_(units), units_teams_(units_teams), undo_stack_(undo_stack), redo_stack_(redo_stack) {}
|
||||
private:
|
||||
gui::dialog_button_action::RESULT button_pressed(int menu_selection);
|
||||
|
||||
game_display& disp_;
|
||||
gui::filter_textbox& filter_;
|
||||
std::vector<unit>& units_;
|
||||
std::vector<unit>& units_teams_; //FIXME: remove once player_info is removed
|
||||
undo_list& undo_stack_;
|
||||
undo_list& redo_stack_;
|
||||
};
|
||||
|
@ -100,7 +101,9 @@ namespace events{
|
|||
filter_.delete_item(menu_selection);
|
||||
//add dismissal to the undo stack
|
||||
undo_stack_.push_back(undo_action(u, map_location(), static_cast<int>(index), true));
|
||||
//assert(units_.size() == units_teams_.size()); //FIXME: remove once player_info is removed
|
||||
units_.erase(units_.begin() + index);
|
||||
units_teams_.erase(units_teams_.begin() + index);
|
||||
recorder.add_disband(index);
|
||||
//clear the redo stack to avoid duplication of dismissals
|
||||
redo_stack_.clear();
|
||||
|
@ -831,10 +834,12 @@ private:
|
|||
}
|
||||
|
||||
std::vector<unit>& recall_list = player->available_units;
|
||||
std::vector<unit>& recall_list_team = current_team.recall_list();
|
||||
|
||||
//sort the available units into order by value
|
||||
//so that the most valuable units are shown first
|
||||
sort_units(recall_list);
|
||||
sort_units(recall_list_team);
|
||||
|
||||
gui_->draw(); //clear the old menu
|
||||
|
||||
|
@ -909,7 +914,7 @@ private:
|
|||
_("Filter: "), options, options_to_filter, 1, rmenu, 200);
|
||||
rmenu.set_textbox(filter);
|
||||
|
||||
delete_recall_unit recall_deleter(*gui_, *filter, recall_list, undo_stack_, redo_stack_);
|
||||
delete_recall_unit recall_deleter(*gui_, *filter, recall_list, recall_list_team, undo_stack_, redo_stack_);
|
||||
gui::dialog_button_info delete_button(&recall_deleter,_("Dismiss Unit"));
|
||||
rmenu.add_button(delete_button);
|
||||
|
||||
|
@ -957,7 +962,9 @@ private:
|
|||
|
||||
redo_stack_.clear();
|
||||
|
||||
//assert(recall_list.size() == recall_list_team.size());
|
||||
recall_list.erase(recall_list.begin()+res);
|
||||
recall_list_team.erase(recall_list_team.begin()+res);
|
||||
gui_->invalidate_game_status();
|
||||
gui_->invalidate_all();
|
||||
recorder.add_checksum_check(loc);
|
||||
|
@ -985,6 +992,7 @@ private:
|
|||
} else {
|
||||
std::vector<unit>& recall_list = player->available_units;
|
||||
recall_list.insert(recall_list.begin()+action.recall_pos,action.affected_unit);
|
||||
current_team.recall_list().insert(current_team.recall_list().begin()+action.recall_pos,action.affected_unit);
|
||||
}
|
||||
} else if(action.is_recall()) {
|
||||
player_info *player = gamestate_.get_player(current_team.save_id());
|
||||
|
@ -1004,6 +1012,7 @@ private:
|
|||
|
||||
std::vector<unit>& recall_list = player->available_units;
|
||||
recall_list.insert(recall_list.begin()+action.recall_pos,un);
|
||||
current_team.recall_list().insert(current_team.recall_list().begin()+action.recall_pos,un);
|
||||
// invalidate before erasing allow us
|
||||
// to also do the ovelerlapped hexes
|
||||
gui_->invalidate(action.recall_loc);
|
||||
|
@ -1104,6 +1113,7 @@ private:
|
|||
std::vector<unit>& recall_list = player->available_units;
|
||||
recorder.add_disband(action.recall_pos);
|
||||
recall_list.erase(recall_list.begin()+action.recall_pos);
|
||||
current_team.recall_list().erase(current_team.recall_list().begin()+action.recall_pos);
|
||||
}
|
||||
} else if(action.is_recall()) {
|
||||
player_info *player = gamestate_.get_player(current_team.save_id());
|
||||
|
@ -1123,6 +1133,7 @@ private:
|
|||
statistics::recall_unit(un);
|
||||
current_team.spend_gold(game_config::recall_cost);
|
||||
recall_list.erase(recall_list.begin()+action.recall_pos);
|
||||
current_team.recall_list().erase(current_team.recall_list().begin()+action.recall_pos);
|
||||
|
||||
gui_->invalidate(action.recall_loc);
|
||||
gui_->draw();
|
||||
|
|
Loading…
Add table
Reference in a new issue