Merge lp:~widelands-dev/widelands/bug-1538549-dismantle-enemy-buildings into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7941
Proposed branch: lp:~widelands-dev/widelands/bug-1538549-dismantle-enemy-buildings
Merge into: lp:widelands
Diff against target: 119 lines (+32/-42)
3 files modified
src/logic/map_objects/tribes/dismantlesite.cc (+18/-26)
src/logic/map_objects/tribes/dismantlesite.h (+1/-1)
src/wui/buildingwindow.cc (+13/-15)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1538549-dismantle-enemy-buildings
Reviewer Review Type Date Requested Status
Miroslav Remák code review + testing Approve
Review via email: mp+290895@code.launchpad.net

Commit message

For the dismantle function, buildings now check which wares the tribe can use and adjust the dismantle button / returned wares accordingly.

Description of the change

See commit message.

To post a comment you must log in.
Revision history for this message
Miroslav Remák (miroslavr256) wrote :

LGTM.

review: Approve (code review + testing)
Revision history for this message
TiborB (tiborb95) wrote :

Just lately I modified AI to sent away wares before upgrading, but I believe no conflict here...

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 961. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/120671195.
Appveyor build 794. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1538549_dismantle_enemy_buildings-794.

Revision history for this message
GunChleoc (gunchleoc) wrote :

No, no there shouldn't be a conflict.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
2--- src/logic/map_objects/tribes/dismantlesite.cc 2016-03-19 09:58:41 +0000
3+++ src/logic/map_objects/tribes/dismantlesite.cc 2016-04-04 16:27:33 +0000
4@@ -107,45 +107,37 @@
5 {
6 PartiallyFinishedBuilding::init(egbase);
7
8- std::map<DescriptionIndex, uint8_t> wares;
9- count_returned_wares(this, wares);
10-
11- std::map<DescriptionIndex, uint8_t>::const_iterator it = wares.begin();
12- wares_.resize(wares.size());
13-
14- for (size_t i = 0; i < wares.size(); ++i, ++it) {
15- WaresQueue & wq =
16- *(wares_[i] = new WaresQueue(*this, it->first, it->second));
17-
18- wq.set_filled(it->second);
19- work_steps_ += it->second;
20+ for (const auto& ware: count_returned_wares(this)) {
21+ WaresQueue* wq = new WaresQueue(*this, ware.first, ware.second);
22+ wq->set_filled(ware.second);
23+ wares_.push_back(wq);
24+ work_steps_ += ware.second;
25 }
26 }
27
28 /*
29 ===============
30-Count wich wares you get back if you dismantle the given building
31+Count which wares you get back if you dismantle the given building
32 ===============
33 */
34-void DismantleSite::count_returned_wares
35- (Building* building,
36- std::map<DescriptionIndex, uint8_t> & res)
37+const Buildcost DismantleSite::count_returned_wares(Building* building)
38 {
39+ Buildcost result;
40 for (DescriptionIndex former_idx : building->get_former_buildings()) {
41- const std::map<DescriptionIndex, uint8_t> * return_wares;
42 const BuildingDescr* former_descr = building->owner().tribe().get_building_descr(former_idx);
43- if (former_idx != building->get_former_buildings().front()) {
44- return_wares = & former_descr->returned_wares_enhanced();
45- } else {
46- return_wares = & former_descr->returned_wares();
47- }
48- assert(return_wares != nullptr);
49+ const Buildcost& return_wares =
50+ former_idx != building->get_former_buildings().front() ?
51+ former_descr->returned_wares_enhanced() :
52+ former_descr->returned_wares();
53
54- std::map<DescriptionIndex, uint8_t>::const_iterator i;
55- for (i = return_wares->begin(); i != return_wares->end(); ++i) {
56- res[i->first] += i->second;
57+ for (const auto& ware : return_wares) {
58+ // TODO(GunChleoc): Once we have trading, we might want to return all wares again.
59+ if (building->owner().tribe().has_ware(ware.first)) {
60+ result[ware.first] += ware.second;
61+ }
62 }
63 }
64+ return result;
65 }
66
67
68
69=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
70--- src/logic/map_objects/tribes/dismantlesite.h 2016-01-31 15:31:00 +0000
71+++ src/logic/map_objects/tribes/dismantlesite.h 2016-04-04 16:27:33 +0000
72@@ -72,7 +72,7 @@
73
74 bool get_building_work(Game &, Worker &, bool success) override;
75
76- static void count_returned_wares(Building* building, std::map<DescriptionIndex, uint8_t> & res);
77+ static const Buildcost count_returned_wares(Building* building);
78
79 protected:
80 void update_statistics_string(std::string*) override;
81
82=== modified file 'src/wui/buildingwindow.cc'
83--- src/wui/buildingwindow.cc 2016-03-29 10:04:48 +0000
84+++ src/wui/buildingwindow.cc 2016-04-04 16:27:33 +0000
85@@ -272,21 +272,19 @@
86 }
87
88 if (capscache_ & Widelands::Building::PCap_Dismantle) {
89- std::map<Widelands::DescriptionIndex, uint8_t> wares;
90- Widelands::DismantleSite::count_returned_wares(&building_, wares);
91- UI::Button * dismantlebtn =
92- new UI::Button
93- (capsbuttons, "dismantle", 0, 0, 34, 34,
94- g_gr->images().get("images/ui_basic/but4.png"),
95- g_gr->images().get(pic_dismantle),
96- std::string(_("Dismantle")) + "<br><font size=11>" + _("Returns:") + "</font><br>" +
97- waremap_to_richtext(owner.tribe(), wares));
98- dismantlebtn->sigclicked.connect(boost::bind(&BuildingWindow::act_dismantle, boost::ref(*this)));
99- capsbuttons->add
100- (dismantlebtn,
101- UI::Align::kHCenter);
102-
103- requires_destruction_separator = true;
104+ const Widelands::Buildcost wares = Widelands::DismantleSite::count_returned_wares(&building_);
105+ if (!wares.empty()) {
106+ UI::Button * dismantlebtn =
107+ new UI::Button
108+ (capsbuttons, "dismantle", 0, 0, 34, 34,
109+ g_gr->images().get("images/ui_basic/but4.png"),
110+ g_gr->images().get(pic_dismantle),
111+ std::string(_("Dismantle")) + "<br><font size=11>" + _("Returns:") + "</font><br>" +
112+ waremap_to_richtext(owner.tribe(), wares));
113+ dismantlebtn->sigclicked.connect(boost::bind(&BuildingWindow::act_dismantle, boost::ref(*this)));
114+ capsbuttons->add(dismantlebtn, UI::Align::kHCenter);
115+ requires_destruction_separator = true;
116+ }
117 }
118
119 if (requires_destruction_separator && can_see) {

Subscribers

People subscribed via source and target branches

to status/vote changes: