move homeless statistics calc fcns from unit.?pp to display_context
This commit is contained in:
parent
d64c296edc
commit
8ecef3b6f0
11 changed files with 88 additions and 81 deletions
|
@ -1423,7 +1423,7 @@ double recruitment::get_estimated_income(int turns) const {
|
|||
double total_income = 0;
|
||||
for (int i = 1; i <= turns; ++i) {
|
||||
double income = (own_villages + village_gain * i) * game_config::village_income;
|
||||
double upkeep = side_upkeep(get_side()) + unit_gain * i -
|
||||
double upkeep = resources::gameboard->side_upkeep(get_side()) + unit_gain * i -
|
||||
(own_villages + village_gain * i) * game_config::village_support;
|
||||
double resulting_income = team.base_income() + income - std::max(0., upkeep);
|
||||
total_income += resulting_income;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "manager.hpp"
|
||||
#include "testing.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../game_board.hpp"
|
||||
#include "../replay.hpp"
|
||||
#include "../util.hpp"
|
||||
#include "../resources.hpp"
|
||||
|
@ -47,8 +48,8 @@ void ai_testing::log_turn(const char* msg, unsigned int side)
|
|||
team& current_team = (*resources::teams)[side-1];
|
||||
|
||||
int _turn_number = resources::tod_manager->turn();
|
||||
int _units = side_units(side);
|
||||
int _units_cost = side_units_cost(side);
|
||||
int _units = resources::gameboard->side_units(side);
|
||||
int _units_cost = resources::gameboard->side_units_cost(side);
|
||||
int _gold = current_team.gold();
|
||||
int _villages = current_team.villages().size();
|
||||
int _income = current_team.total_income();
|
||||
|
@ -108,6 +109,6 @@ void ai_testing::log_game_end()
|
|||
for (std::vector<team>::const_iterator tm = resources::teams->begin(); tm != resources::teams->end(); ++tm) {
|
||||
int side = tm-resources::teams->begin()+1;
|
||||
recorder.add_log_data("ai_log","end_gold"+str_cast(side),str_cast(tm->gold()));
|
||||
recorder.add_log_data("ai_log","end_units"+str_cast(side),str_cast(side_units(side)));
|
||||
recorder.add_log_data("ai_log","end_units"+str_cast(side),str_cast(resources::gameboard->side_units(side)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,3 +97,45 @@ bool display_context::is_observer() const
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Static info getters previously declared at global scope in unit.?pp
|
||||
|
||||
int display_context::side_units(int side) const
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, units()) {
|
||||
if (u.side() == side) ++res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int display_context::side_units_cost(int side) const
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, units()) {
|
||||
if (u.side() == side) res += u.cost();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int display_context::side_upkeep(int side) const
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, units()) {
|
||||
if (u.side() == side) res += u.upkeep();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
team_data display_context::calculate_team_data(const team& tm, int side) const
|
||||
{
|
||||
team_data res;
|
||||
res.units = side_units(side);
|
||||
res.upkeep = side_upkeep(side);
|
||||
res.villages = tm.villages().size();
|
||||
res.expenses = std::max<int>(0,res.upkeep - tm.support());
|
||||
res.net_income = tm.total_income() - res.expenses;
|
||||
res.gold = tm.gold();
|
||||
res.teamname = tm.user_team_name();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#ifndef DISPLAY_CONTEXT_HPP_INCLUDED
|
||||
#define DISPLAY_CONTEXT_HPP_INCLUDED
|
||||
|
||||
#include<vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class team;
|
||||
class gamemap;
|
||||
|
@ -31,6 +32,23 @@ class unit_map;
|
|||
class unit;
|
||||
struct map_location;
|
||||
|
||||
struct team_data
|
||||
{
|
||||
team_data() :
|
||||
units(0),
|
||||
upkeep(0),
|
||||
villages(0),
|
||||
expenses(0),
|
||||
net_income(0),
|
||||
gold(0),
|
||||
teamname()
|
||||
{
|
||||
}
|
||||
|
||||
int units, upkeep, villages, expenses, net_income, gold;
|
||||
std::string teamname;
|
||||
};
|
||||
|
||||
class display_context {
|
||||
public:
|
||||
virtual const std::vector<team> & teams() const = 0;
|
||||
|
@ -53,6 +71,18 @@ public:
|
|||
*/
|
||||
int village_owner(const map_location & loc) const;
|
||||
|
||||
// Accessors from unit.cpp
|
||||
|
||||
/** Returns the number of units of the side @a side_num. */
|
||||
int side_units(int side_num) const;
|
||||
|
||||
/** Returns the total cost of units of side @a side_num. */
|
||||
int side_units_cost(int side_num) const ;
|
||||
|
||||
int side_upkeep(int side_num) const ;
|
||||
|
||||
team_data calculate_team_data(const class team& tm, int side) const;
|
||||
|
||||
// Accessor from team.cpp
|
||||
|
||||
/// Check if we are an observer in this game
|
||||
|
@ -63,4 +93,5 @@ public:
|
|||
virtual ~display_context() {}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -88,7 +88,7 @@ void status_table(display& gui, int selected)
|
|||
|
||||
std::stringstream str;
|
||||
|
||||
const team_data data = calculate_team_data(teams[n],n+1);
|
||||
const team_data data = gui.get_disp_context().calculate_team_data(teams[n],n+1);
|
||||
|
||||
unit_map::const_iterator leader = units.find_leader(n + 1);
|
||||
std::string leader_name;
|
||||
|
|
|
@ -232,7 +232,7 @@ void menu_handler::status_table(int selected)
|
|||
|
||||
std::stringstream str;
|
||||
|
||||
const team_data data = calculate_team_data(teams_[n],n+1);
|
||||
const team_data data = resources::gameboard->calculate_team_data(teams_[n],n+1);
|
||||
|
||||
unit_map::const_iterator leader = units_.find_leader(n + 1);
|
||||
std::string leader_name;
|
||||
|
|
|
@ -578,7 +578,7 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
|
|||
// If the expense is less than the number of villages owned
|
||||
// times the village support capacity,
|
||||
// then we don't have to pay anything at all
|
||||
int expense = side_upkeep(player_number_) -
|
||||
int expense = gamestate_.board_.side_upkeep(player_number_) -
|
||||
current_team().support();
|
||||
if(expense > 0) {
|
||||
current_team().spend_gold(expense);
|
||||
|
|
|
@ -726,7 +726,7 @@ possible_end_play_signal playsingle_controller::play_side()
|
|||
temporary_human = false;
|
||||
// If a side is dead end the turn, but play at least side=1's
|
||||
// turn in case all sides are dead
|
||||
if (side_units(player_number_) != 0
|
||||
if (gamestate_.board_.side_units(player_number_) != 0
|
||||
|| (resources::units->size() == 0 && player_number_ == 1))
|
||||
{
|
||||
possible_end_play_signal signal = before_human_turn();
|
||||
|
|
|
@ -1270,7 +1270,7 @@ REPORT_GENERATOR(villages, rc)
|
|||
std::ostringstream str;
|
||||
int viewing_side = rc.screen().viewing_side();
|
||||
const team &viewing_team = rc.teams()[viewing_side - 1];
|
||||
team_data td = calculate_team_data(viewing_team, viewing_side);
|
||||
team_data td = rc.dc().calculate_team_data(viewing_team, viewing_side);
|
||||
str << td.villages << '/';
|
||||
if (viewing_team.uses_shroud()) {
|
||||
int unshrouded_villages = 0;
|
||||
|
@ -1287,7 +1287,7 @@ REPORT_GENERATOR(villages, rc)
|
|||
|
||||
REPORT_GENERATOR(num_units, rc)
|
||||
{
|
||||
return gray_inactive(rc, str_cast(side_units(rc.screen().viewing_side())));
|
||||
return gray_inactive(rc, str_cast(rc.dc().side_units(rc.screen().viewing_side())));
|
||||
}
|
||||
|
||||
REPORT_GENERATOR(upkeep, rc)
|
||||
|
@ -1295,7 +1295,7 @@ REPORT_GENERATOR(upkeep, rc)
|
|||
std::ostringstream str;
|
||||
int viewing_side = rc.screen().viewing_side();
|
||||
const team &viewing_team = rc.teams()[viewing_side - 1];
|
||||
team_data td = calculate_team_data(viewing_team, viewing_side);
|
||||
team_data td = rc.dc().calculate_team_data(viewing_team, viewing_side);
|
||||
str << td.expenses << " (" << td.upkeep << ")";
|
||||
return gray_inactive(rc,str.str());
|
||||
}
|
||||
|
@ -1304,7 +1304,7 @@ REPORT_GENERATOR(expenses, rc)
|
|||
{
|
||||
int viewing_side = rc.screen().viewing_side();
|
||||
const team &viewing_team = rc.teams()[viewing_side - 1];
|
||||
team_data td = calculate_team_data(viewing_team, rc.screen().viewing_side());
|
||||
team_data td = rc.dc().calculate_team_data(viewing_team, rc.screen().viewing_side());
|
||||
return gray_inactive(rc,str_cast(td.expenses));
|
||||
}
|
||||
|
||||
|
@ -1313,7 +1313,7 @@ REPORT_GENERATOR(income, rc)
|
|||
std::ostringstream str;
|
||||
int viewing_side = rc.screen().viewing_side();
|
||||
const team &viewing_team = rc.teams()[viewing_side - 1];
|
||||
team_data td = calculate_team_data(viewing_team, viewing_side);
|
||||
team_data td = rc.dc().calculate_team_data(viewing_team, viewing_side);
|
||||
char const *end = naps;
|
||||
if (viewing_side != rc.screen().playing_side()) {
|
||||
if (td.net_income < 0) {
|
||||
|
|
40
src/unit.cpp
40
src/unit.cpp
|
@ -2121,45 +2121,6 @@ bool unit::matches_id(const std::string& unit_id) const
|
|||
return id_ == unit_id;
|
||||
}
|
||||
|
||||
int side_units(int side)
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, *resources::units) {
|
||||
if (u.side() == side) ++res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int side_units_cost(int side)
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, *resources::units) {
|
||||
if (u.side() == side) res += u.cost();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int side_upkeep(int side)
|
||||
{
|
||||
int res = 0;
|
||||
BOOST_FOREACH(const unit &u, *resources::units) {
|
||||
if (u.side() == side) res += u.upkeep();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
team_data calculate_team_data(const team& tm, int side)
|
||||
{
|
||||
team_data res;
|
||||
res.units = side_units(side);
|
||||
res.upkeep = side_upkeep(side);
|
||||
res.villages = tm.villages().size();
|
||||
res.expenses = std::max<int>(0,res.upkeep - tm.support());
|
||||
res.net_income = tm.total_income() - res.expenses;
|
||||
res.gold = tm.gold();
|
||||
res.teamname = tm.user_team_name();
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string unit::TC_image_mods() const{
|
||||
std::stringstream modifier;
|
||||
|
@ -2189,7 +2150,6 @@ void unit::remove_attacks_ai()
|
|||
set_attacks(0);
|
||||
}
|
||||
|
||||
|
||||
void unit::remove_movement_ai()
|
||||
{
|
||||
if (movement_left() == total_movement()) {
|
||||
|
|
27
src/unit.hpp
27
src/unit.hpp
|
@ -516,33 +516,6 @@ private:
|
|||
int moves_;
|
||||
};
|
||||
|
||||
/** Returns the number of units of the side @a side_num. */
|
||||
int side_units(int side_num);
|
||||
|
||||
/** Returns the total cost of units of side @a side_num. */
|
||||
int side_units_cost(int side_num);
|
||||
|
||||
int side_upkeep(int side_num);
|
||||
|
||||
struct team_data
|
||||
{
|
||||
team_data() :
|
||||
units(0),
|
||||
upkeep(0),
|
||||
villages(0),
|
||||
expenses(0),
|
||||
net_income(0),
|
||||
gold(0),
|
||||
teamname()
|
||||
{
|
||||
}
|
||||
|
||||
int units, upkeep, villages, expenses, net_income, gold;
|
||||
std::string teamname;
|
||||
};
|
||||
|
||||
team_data calculate_team_data(const class team& tm, int side);
|
||||
|
||||
/**
|
||||
* Gets a checksum for a unit.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue