Merge lp:~borim/widelands/stockChart into lp:widelands

Proposed by Borim
Status: Merged
Merged at revision: 6390
Proposed branch: lp:~borim/widelands/stockChart
Merge into: lp:widelands
Diff against target: 317 lines (+130/-9)
5 files modified
src/game_io/game_player_info_data_packet.cc (+4/-2)
src/logic/player.cc (+95/-7)
src/logic/player.h (+10/-0)
src/wui/ware_statistics_menu.cc (+20/-0)
src/wui/ware_statistics_menu.h (+1/-0)
To merge this branch: bzr merge lp:~borim/widelands/stockChart
Reviewer Review Type Date Requested Status
Borim (community) Needs Resubmitting
SirVer Disapprove
Review via email: mp+104118@code.launchpad.net

Description of the change

add a new ware chart, which display the amount of stored wares over the time

branch is related to Bug #970840

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

I am against this feature. It contains the same information as the
economy health and therefore imho adds to clutter in the UI more than to
the support of the player.

I think it is unfortunate that this discussion was not done before you
put work into it, Borim. However, we will need to finish this discussion
now before merging.

review: Disapprove
Revision history for this message
Borim (borim) wrote :

As SirVer give his approval in the bug report #970840 resubmitting for merging

review: Needs Resubmitting
Revision history for this message
SirVer (sirver) wrote :

Merged in r6390. Thanks Borim. Sorry for letting this drop.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'pics/menu_tab_wares_stock.png'
2Binary files pics/menu_tab_wares_stock.png 1970-01-01 00:00:00 +0000 and pics/menu_tab_wares_stock.png 2012-04-30 14:10:43 +0000 differ
3=== modified file 'src/game_io/game_player_info_data_packet.cc'
4--- src/game_io/game_player_info_data_packet.cc 2012-02-15 21:25:34 +0000
5+++ src/game_io/game_player_info_data_packet.cc 2012-04-30 14:10:43 +0000
6@@ -30,7 +30,7 @@
7
8 namespace Widelands {
9
10-#define CURRENT_PACKET_VERSION 14
11+#define CURRENT_PACKET_VERSION 15
12
13
14 void Game_Player_Info_Data_Packet::Read
15@@ -111,7 +111,9 @@
16 if (packet_version >= 6)
17 player.setAI(fr.CString());
18
19- if (packet_version >= 14)
20+ if (packet_version >= 15)
21+ player.ReadStatistics(fr, 3);
22+ else if (packet_version >= 14)
23 player.ReadStatistics(fr, 2);
24 else if (packet_version >= 12)
25 player.ReadStatistics(fr, 1);
26
27=== modified file 'src/logic/player.cc'
28--- src/logic/player.cc 2012-04-06 19:26:17 +0000
29+++ src/logic/player.cc 2012-04-30 14:10:43 +0000
30@@ -23,6 +23,7 @@
31 #include "cmd_expire_message.h"
32 #include "cmd_luacoroutine.h"
33 #include "constructionsite.h"
34+#include "economy/economy.h"
35 #include "economy/flag.h"
36 #include "economy/road.h"
37 #include "findimmovable.h"
38@@ -94,7 +95,8 @@
39 m_current_produced_statistics(tribe_descr.get_nrwares ()),
40 m_current_consumed_statistics(tribe_descr.get_nrwares ()),
41 m_ware_productions (tribe_descr.get_nrwares ()),
42- m_ware_consumptions (tribe_descr.get_nrwares ())
43+ m_ware_consumptions (tribe_descr.get_nrwares ()),
44+ m_ware_stocks (tribe_descr.get_nrwares ())
45 {
46 set_name(name);
47 }
48@@ -1057,13 +1059,39 @@
49 {
50 assert (m_ware_productions.size() == tribe().get_nrwares().value());
51 assert (m_ware_consumptions.size() == tribe().get_nrwares().value());
52-
53+ assert (m_ware_stocks.size() == tribe().get_nrwares().value());
54+
55+ //calculate stocks
56+ std::vector<uint32_t> stocks(tribe().get_nrwares().value());
57+
58+ const uint32_t nrecos = get_nr_economies();
59+ for (uint32_t i = 0; i < nrecos; ++i) {
60+ const std::vector<Widelands::Warehouse *> & warehouses =
61+ get_economy_by_number(i)->warehouses();
62+
63+ for
64+ (std::vector<Widelands::Warehouse *>::const_iterator it =
65+ warehouses.begin();
66+ it != warehouses.end();
67+ ++it)
68+ {
69+ for (uint32_t id; id < stocks.size(); ++id) {
70+ stocks[id] += (*it)->get_economy()->stock_ware
71+ (Ware_Index(static_cast<size_t>(id)));
72+ }
73+ }
74+ }
75+
76+
77+ //update statistics
78 for (uint32_t i = 0; i < m_ware_productions.size(); ++i) {
79 m_ware_productions[i].push_back(m_current_produced_statistics[i]);
80 m_current_produced_statistics[i] = 0;
81
82 m_ware_consumptions[i].push_back(m_current_consumed_statistics[i]);
83 m_current_consumed_statistics[i] = 0;
84+
85+ m_ware_stocks[i].push_back(stocks[i]);
86 }
87 }
88
89@@ -1117,6 +1145,14 @@
90 return &m_ware_consumptions[ware];
91 }
92
93+const std::vector<uint32_t> * Player::get_ware_stock_statistics
94+ (Ware_Index const ware) const
95+{
96+ assert(ware.value() < m_ware_stocks.size());
97+
98+ return &m_ware_stocks[ware];
99+}
100+
101
102 /**
103 * Add or remove the given building from building statistics.
104@@ -1193,12 +1229,13 @@
105 * 0 - old style statistics (before WiHack 2010)
106 * 1 - statistics with ware names
107 * 2 - with consumption statistics
108+ * 3 - with stock statistics
109 */
110 void Player::ReadStatistics(FileRead & fr, uint32_t const version)
111 {
112- //version 1 and 2 only differs in an additional statistic.
113- //Use version 1 code for both
114- if ((version == 2) || (version == 1)) {
115+ //version 1, 2 and 3 only differs in an additional statistic.
116+ //Use version 1 code for all of them
117+ if ((version == 2) || (version == 1) || (version == 3)) {
118 uint16_t nr_wares = fr.Unsigned16();
119 uint16_t nr_entries = fr.Unsigned16();
120
121@@ -1222,7 +1259,7 @@
122 }
123
124 //read consumption statistics if it exists
125- if (version == 2) {
126+ if ((version == 2) || (version == 3)) {
127 nr_wares = fr.Unsigned16();
128 nr_entries = fr.Unsigned16();
129
130@@ -1234,7 +1271,7 @@
131 Ware_Index idx = tribe().ware_index(name);
132 if (!idx) {
133 log
134- ("Player %u statistics: unknown ware name %s",
135+ ("Player %u consumption statistics: unknown ware name %s",
136 player_number(), name.c_str());
137 continue;
138 }
139@@ -1244,6 +1281,29 @@
140 for (uint32_t j = 0; j < nr_entries; ++j)
141 m_ware_consumptions[idx][j] = fr.Unsigned32();
142 }
143+
144+ //read stock statistics if it exists
145+ if (version == 3) {
146+ nr_wares = fr.Unsigned16();
147+ nr_entries = fr.Unsigned16();
148+
149+ for (uint32_t i = 0; i < m_ware_stocks.size(); ++i)
150+ m_ware_stocks[i].resize(nr_entries);
151+
152+ for (uint16_t i = 0; i < nr_wares; ++i) {
153+ std::string name = fr.CString();
154+ Ware_Index idx = tribe().ware_index(name);
155+ if (!idx) {
156+ log
157+ ("Player %u stock statistics: unknown ware name %s",
158+ player_number(), name.c_str());
159+ continue;
160+ }
161+
162+ for (uint32_t j = 0; j < nr_entries; ++j)
163+ m_ware_stocks[idx][j] = fr.Unsigned32();
164+ }
165+ }
166 }
167 } else if (version == 0) {
168 uint16_t nr_wares = fr.Unsigned16();
169@@ -1293,8 +1353,24 @@
170 }
171 }
172
173+ //create empty stock statistic if it is missing
174+ if (version < 3) {
175+ uint16_t nr_entries = m_ware_productions[0].size();
176+
177+ for (uint32_t i = 0; i < m_current_consumed_statistics.size(); ++i) {
178+ m_ware_stocks[i].resize(nr_entries);
179+
180+ for (uint32_t j = 0; j < nr_entries; ++j)
181+ m_ware_stocks[i][j] = 0;
182+ }
183+ }
184+
185+ //all statistics should have the same size
186 assert(m_ware_productions.size() == m_ware_consumptions.size());
187 assert(m_ware_productions[0].size() == m_ware_consumptions[0].size());
188+
189+ assert(m_ware_productions.size() == m_ware_stocks.size());
190+ assert(m_ware_productions[0].size() == m_ware_stocks[0].size());
191 }
192
193
194@@ -1327,6 +1403,18 @@
195 for (uint32_t j = 0; j < m_ware_consumptions[i].size(); ++j)
196 fw.Unsigned32(m_ware_consumptions[i][j]);
197 }
198+
199+ //write stock statistics
200+ fw.Unsigned16(m_ware_stocks.size());
201+ fw.Unsigned16(m_ware_stocks[0].size());
202+
203+ for (uint8_t i = 0; i < m_ware_stocks.size(); ++i) {
204+ fw.CString
205+ (tribe().get_ware_descr
206+ (Ware_Index(static_cast<Ware_Index::value_t>(i)))->name());
207+ for (uint32_t j = 0; j < m_ware_stocks[i].size(); ++j)
208+ fw.Unsigned32(m_ware_stocks[i][j]);
209+ }
210 }
211
212 }
213
214=== modified file 'src/logic/player.h'
215--- src/logic/player.h 2012-02-28 22:10:23 +0000
216+++ src/logic/player.h 2012-04-30 14:10:43 +0000
217@@ -534,6 +534,9 @@
218 std::vector<uint32_t> const * get_ware_consumption_statistics
219 (Ware_Index const) const;
220
221+ std::vector<uint32_t> const * get_ware_stock_statistics
222+ (Ware_Index const) const;
223+
224 void ReadStatistics(FileRead &, uint32_t version);
225 void WriteStatistics(FileWrite &) const;
226 void sample_statistics();
227@@ -620,6 +623,13 @@
228 */
229 std::vector< std::vector<uint32_t> > m_ware_consumptions;
230
231+ /**
232+ * Statistics of wares stored inside of warehouses over the
233+ * life of the game, indexed as
234+ * m_ware_stocks[ware_id][time_index]
235+ */
236+ std::vector< std::vector<uint32_t> > m_ware_stocks;
237+
238 BuildingStats m_building_stats;
239 };
240
241
242=== modified file 'src/wui/ware_statistics_menu.cc'
243--- src/wui/ware_statistics_menu.cc 2012-02-15 21:25:34 +0000
244+++ src/wui/ware_statistics_menu.cc 2012-04-30 14:10:43 +0000
245@@ -47,6 +47,7 @@
246 static const char pic_tab_production[] = "pics/menu_tab_wares_production.png";
247 static const char pic_tab_consumption[] = "pics/menu_tab_wares_consumption.png";
248 static const char pic_tab_economy[] = "pics/menu_tab_wares_econ_health.png";
249+static const char pic_tab_stock[] = "pics/menu_tab_wares_stock.png"; //TODO replace place holder
250
251 static const RGBColor colors[] = {
252 RGBColor(115, 115, 115), //inactive
253@@ -203,6 +204,16 @@
254 ("economy_health", g_gr->get_picture(PicMod_UI, pic_tab_economy),
255 m_plot_economy, _("Economy Health"));
256
257+ m_plot_stock = new WUIPlot_Area
258+ (tabs,
259+ 0, 0, plot_width, plot_height);
260+ m_plot_stock->set_sample_rate(STATISTICS_SAMPLE_TIME);
261+ m_plot_stock->set_plotmode(WUIPlot_Area::PLOTMODE_RELATIVE);
262+
263+ tabs->add
264+ ("stock", g_gr->get_picture(PicMod_UI, pic_tab_stock),
265+ m_plot_stock, _("Stock"));
266+
267 tabs->activate(0);
268
269 //add tabbed environment to box
270@@ -232,6 +243,12 @@
271 (cur_ware,
272 parent.get_player()->get_ware_consumption_statistics
273 (Widelands::Ware_Index(cur_ware)));
274+
275+ m_plot_stock->register_plot_data
276+ (cur_ware,
277+ parent.get_player()->get_ware_stock_statistics
278+ (Widelands::Ware_Index(cur_ware)),
279+ colors[cur_ware]);
280 }
281
282 box->add
283@@ -273,6 +290,7 @@
284 m_plot_production->set_plotcolor(static_cast<size_t>(id), colors[color_index]);
285 m_plot_consumption->set_plotcolor(static_cast<size_t>(id), colors[color_index]);
286 m_plot_economy->set_plotcolor(static_cast<size_t>(id), colors[color_index]);
287+ m_plot_stock->set_plotcolor(static_cast<size_t>(id), colors[color_index]);
288
289 } else { //deactivate ware
290 uint8_t old_color = m_color_map[static_cast<size_t>(id)];
291@@ -285,6 +303,7 @@
292 m_plot_production->show_plot(static_cast<size_t>(id), what);
293 m_plot_consumption->show_plot(static_cast<size_t>(id), what);
294 m_plot_economy->show_plot(static_cast<size_t>(id), what);
295+ m_plot_stock->show_plot(static_cast<size_t>(id), what);
296 }
297
298 /**
299@@ -295,5 +314,6 @@
300 m_plot_production->set_time_id(timescale);
301 m_plot_consumption->set_time_id(timescale);
302 m_plot_economy->set_time_id(timescale);
303+ m_plot_stock->set_time_id(timescale);
304 }
305
306
307=== modified file 'src/wui/ware_statistics_menu.h'
308--- src/wui/ware_statistics_menu.h 2012-02-15 21:25:34 +0000
309+++ src/wui/ware_statistics_menu.h 2012-04-30 14:10:43 +0000
310@@ -38,6 +38,7 @@
311 Interactive_Player * m_parent;
312 WUIPlot_Area * m_plot_production;
313 WUIPlot_Area * m_plot_consumption;
314+ WUIPlot_Area * m_plot_stock;
315 DifferentialPlot_Area * m_plot_economy;
316 std::vector<uint8_t> m_color_map; //maps ware index to colors
317 std::vector<bool> m_active_colors;

Subscribers

People subscribed via source and target branches

to status/vote changes: