1 /*
2    Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3    Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY.
11 
12    See the COPYING file for more details.
13 */
14 
15 /**
16  *
17  * This class is an abstract base class designed to simplify the use
18  * of the display object.
19  *
20  **/
21 
22 #pragma once
23 
24 #include <string>
25 #include <vector>
26 
27 class team;
28 class gamemap;
29 class unit_map;
30 
31 class unit;
32 struct map_location;
33 
34 class display_context
35 {
36 public:
37 	virtual const std::vector<team> & teams() const = 0;
38 	virtual const gamemap & map() const = 0;
39 	virtual const unit_map & units() const = 0;
40 	virtual const std::vector<std::string> & hidden_label_categories() const = 0;
41 	virtual std::vector<std::string> & hidden_label_categories() = 0;
42 	const team& get_team(int side) const;
43 
44 	// this one is only a template function to prevent compilation erros when class team is an incomplete type.
45 	template<typename T = void>
has_team(int side) const46 	bool has_team(int side) const
47 	{
48 		return side > 0 && side <= static_cast<int>(teams().size());
49 	}
50 
51 	// Helper for is_visible_to_team
52 
53 	/**
54 	 * Given a location and a side number, indicates whether an invisible unit of that side at that
55 	 * location would be revealed (perhaps ambushed), based on what team side_num can see.
56 	 * If see_all is true then the calculation ignores fog, and enemy ambushers.
57 	 */
58 	bool would_be_discovered(const map_location & loc, int side_num, bool see_all = true);
59 
60 	// Needed for reports
61 
62 	const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
63 
64 	// From actions:: namespace
65 
66 	bool unit_can_move(const unit & u) const;
67 
68 	// From class team
69 
70 	/**
71 	 * Given the location of a village, will return the 0-based index
72 	 * of the team that currently owns it, and -1 if it is unowned.
73 	 */
74 	int village_owner(const map_location & loc) const;
75 
76 	// Accessors from unit.cpp
77 
78 	/** Returns the number of units of the side @a side_num. */
79 	int side_units(int side_num) const;
80 
81 	/** Returns the total cost of units of side @a side_num. */
82 	int side_units_cost(int side_num) const ;
83 
84 	int side_upkeep(int side_num) const ;
85 
86 	// Accessor from team.cpp
87 
88 	/// Check if we are an observer in this game
89 	bool is_observer() const;
90 
91 	// Dtor
92 
~display_context()93 	virtual ~display_context() {}
94 };
95 
96 struct team_data
97 {
98 	team_data(const display_context& dc, const team& tm);
99 
100 	int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
101 };
102