initial commit, lordsawar source, slightly modified
[lordsawar] / src / vectormap.h
1 //  Copyright (C) 2007, 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef VECTORMAP_H
19 #define VECTORMAP_H
20
21 #include <sigc++/signal.h>
22
23 #include "overviewmap.h"
24 #include "input-events.h"
25
26 class City;
27
28 //! Draw city production on a miniature map graphic.
29 /**
30  * 
31  * This is a map where you can select a city's vector, i.e. the position where
32  * freshly produced units automatically go to.  They show up at the destination
33  * in 2 turns.
34  * VectorMap is the image in the CityDialog which provides a detailed view of  
35  * the production of a Player.  It draws City objects on top of the graphic
36  * that the OverviewMap class provides, but changes the icons over the City
37  * objects to depict production.  It is interactive in that it handles 
38  * mouse clicks on City objects and planted standard objects, but the 
39  * behaviour of what the click does can change based on other calls to methods
40  * in this class.
41  * It can show vectoring by drawing lines between cities, and it can show
42  * which cities are producing Army production bases, and which are not.
43  * Clicking can select that City object, or clicking can set a vectoring
44  * destination for a selected City, or it can change all City objects vectoring
45  * to the currently selected city by vectoring them all to the newly 
46  * selected city.
47  */
48 class VectorMap : public OverviewMap
49 {
50 public:
51     //! The different ways of depicting vectoring on a VectorMap.
52     enum ShowVectoring
53       {
54         //! Don't depict any vectoring at all.
55         SHOW_NO_VECTORING,
56         //! Only depict vectoring that involves the selected city.
57         SHOW_ORIGIN_CITY_VECTORING,
58         //! Depict vectoring for all City objects that the Player owns.
59         SHOW_ALL_VECTORING,
60       };
61
62     //! The different effects that a mouse click can have on a VectorMap.
63     enum ClickAction
64       {
65         //! Clicking a City object makes it the newly selected City.
66         CLICK_SELECTS,
67         //! Clicking on a City or Planted standard vectors to the selected City.
68         CLICK_VECTORS,
69         //! Changes vectoring from the old selected city to the new city.
70         /**
71          * Changes all cities vectoring to the currently selected city, to 
72          * vector to the newly selected city.  This makes the newly clicked 
73          * City object the selected city..
74          */
75         CLICK_CHANGES_DESTINATION,
76       };
77
78     //! Default constructor.
79     /**
80      * Make a new VectorMap.
81      *
82      * @param city    The City object that is initially selected.
83      * @param vector  How much vectoring we're going to depict.
84      * @param see_opponents_production  Whether or not we can click City 
85      *                                  objects that belong to other Players.
86      *                                  This is only useful when the 
87      *                                  ClickAction is CLICK_SELECTS.
88      */
89     VectorMap(City *city, enum ShowVectoring vector, 
90               bool see_opponents_production);
91
92     //! Realize a mouse button event.
93     void mouse_button_event(MouseButtonEvent e);
94
95     // Emitted whenever a city is selected.
96     sigc::signal<void, Vector<int> > destination_chosen;
97
98     // Emitted whenever something is drawn on to the miniature map graphic.
99     sigc::signal<void, Glib::RefPtr<Gdk::Pixmap> > map_changed;
100
101     //! Change what kind of vectoring is depicted on the VectorMap.
102     void setShowVectoring (enum ShowVectoring v) { show_vectoring = v;}
103
104     //! Return the currently selected City object.
105     City* getCity() {return city;}
106
107     //! show vectoring from a different city.
108     void setCity(City *c);
109
110     //! Change what happens when a City object is clicked on.
111     void setClickAction (enum ClickAction a) { click_action = a;}
112
113     //! Return what happens when a City object is clicked on.
114     enum ClickAction getClickAction () { return click_action;}
115
116 private:
117     //! The currently selected city object.
118     City *city;
119
120     //! The Player's planted standard.
121     /**
122      * This value is (-1,-1) if the Player does not have a standard planted
123      * anywhere on the game map.
124      */
125     Vector<int> planted_standard;
126
127     //! The current amount of vectoring that the VectorMap is showing.
128     enum ShowVectoring show_vectoring;
129
130     //! The current behaviour of a click on a City object.
131     enum ClickAction click_action;
132
133     //! Whether or not City objects belonging to other players can be selected.
134     bool d_see_opponents_production;
135
136     //! Depict the vectoring and production onto the miniature map graphic.
137     /**
138      * This method is automatically called by the VectorMap::draw method.
139      */
140     virtual void after_draw();
141
142     //! Draw a city icon in the given fashion.
143     /**
144      * Draw an icon on top of a City object on the miniature map.
145      *
146      * @param city  The city to depict production or vectoring for.
147      * @param type  When type is 0 it means it is the currently selected city.
148      *              When type is 1 it means that the given city is not being
149      *              vectored to or from.  When type is 2 it means that the 
150      *              city is being vectored to.  When type is 3 it means that 
151      *              the city is being vectored from.
152      * @param prod  Whether or not we're showing production or vectoring.
153      */
154     void draw_city (City *city, guint32 &type, bool &prod);
155
156     //! Draw a list of city objects in the given fashion.
157     /**
158      * @param citylist  The list of city objects to depict.
159      * @param type  When type is 0 it means it is the currently selected city.
160      *              When type is 1 it means that the given city is not being
161      *              vectored to or from.  When type is 2 it means that the 
162      *              city is being vectored to.  When type is 3 it means that 
163      *              the city is being vectored from.
164      */
165     void draw_cities (std::list<City*> citylist, guint32 type);
166
167     //! Draw lines from src to dests according to each city's vectoring policy.
168     void draw_lines (std::list<City*> srcs, std::list<City*> dests);
169
170     //! Draw a hero icon on the spot where a Hero has planted the standard.
171     /**
172      * @param pos  The position of a tile on the map to draw a hero icon.
173      */
174     void draw_planted_standard(Vector<int> pos);
175
176     //! Draw a yellow line to a place on the map.
177     /**
178      * Draw a yellow line from the currently selected city to the given 
179      * position on the map.
180      *
181      * @param dest  The position of a tile on the map to draw a line to.
182      */
183     void draw_vectoring_line_from_here_to (Vector<int> dest);
184
185     //! Draw an orange line to a place on the map.
186     /**
187      * Draw an orange line from the given position on the map to the currently 
188      * selected city.
189      *
190      * @param src   The position of a tile on the map to draw a line from.
191      */
192     void draw_vectoring_line_to_here_from (Vector<int> src);
193
194     //! Draw a line between the given points, in a given colour.
195     /**
196      * @param src   The position of a tile on the map to draw a line from.
197      * @param dest  The position of a tile on the map to draw a line to.
198      * @param to    Whether or not the line will be drawn in a yellow colour
199      *              or an orange colour.  If true, then yellow.  Otherwise
200      *              orange.
201      */
202     void draw_vectoring_line(Vector<int> src, Vector<int> dest, bool to);
203
204     void draw_square_around_active_city();
205 };
206
207 #endif