widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #02265
[Merge] lp:~f-thiessen/widelands/bug-1307844 into lp:widelands
Ferdinand T. has proposed merging lp:~f-thiessen/widelands/bug-1307844 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~f-thiessen/widelands/bug-1307844/+merge/226596
Fixed Bug 1307844 - Enhancement-system
Tested without problems.
--
https://code.launchpad.net/~f-thiessen/widelands/bug-1307844/+merge/226596
Your team Widelands Developers is requested to review the proposed merge of lp:~f-thiessen/widelands/bug-1307844 into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2014-07-08 18:25:49 +0000
+++ src/ai/defaultai.cc 2014-07-12 23:55:42 +0000
@@ -1269,7 +1269,7 @@
// but I do not know how to identify such buildings
if (bo.cnt_built_ == 1
and game().get_gametime() > 60 * 60 * 1000
- and !bo.desc->enhancements().empty()
+ and bo.desc->enhancement() != INVALID_INDEX
and !mines_.empty()) {
prio = max_preciousness + bulgarian_constant;
}
@@ -2204,60 +2204,60 @@
// Check whether building is enhanceable and if wares of the enhanced
// buildings are needed. If yes consider an upgrade.
- std::set<Building_Index> enhancements = productionsite->enhancements();
+ Building_Index enhancement = productionsite->enhancement();
int32_t maxprio = 0;
Building_Index enbld = INVALID_INDEX;
BuildingObserver* bestbld = nullptr;
- container_iterate_const(std::set<Building_Index>, enhancements, x) {
- // Only enhance buildings that are allowed (scenario mode)
- if (player->is_building_type_allowed(*x.current)) {
- const Building_Descr& bld = *tribe->get_building_descr(*x.current);
- BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
-
- // do not build the same building so soon (kind of duplicity check)
- if (gametime - en_bo.construction_decision_time_ < kBuildingMinInterval)
- continue;
-
+
+ // Only enhance buildings that are allowed (scenario mode)
+ if (player->is_building_type_allowed(enhancement)) {
+ const Building_Descr& bld = *tribe->get_building_descr(enhancement);
+ BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
+
+ // do not build the same building so soon (kind of duplicity check)
+ if (gametime - en_bo.construction_decision_time_ >= kBuildingMinInterval)
+ {
// Don't enhance this building, if there is already one of same type
// under construction or unoccupied_
- if (en_bo.cnt_under_construction_ + en_bo.unoccupied_ > 0)
- continue;
-
- // don't upgrade without workers
- if (!productionsite->has_workers(*x.current, game()))
- continue;
-
- // forcing first upgrade
- if ((en_bo.cnt_under_construction_ + en_bo.cnt_built_ + en_bo.unoccupied_) == 0
- and (productionsite_observer.bo->cnt_built_ -
- productionsite_observer.bo->unoccupied_) >= 1
- and (game().get_gametime() - productionsite_observer.built_time_) > 30 * 60 * 1000
- and !mines_.empty()) {
- if (kUpgradeDebug)
- log(" UPGRADE: upgrading (forcing as first) %12s at %3d x %3d: age %d min.\n",
- productionsite_observer.bo->name,
- productionsite->get_position().x,
- productionsite->get_position().y,
- (game().get_gametime() - productionsite_observer.built_time_) / 60000);
-
- game().send_player_enhance_building(*productionsite, (*x.current));
- return true;
+ if (en_bo.cnt_under_construction_ + en_bo.unoccupied_ <= 0)
+ {
+ // don't upgrade without workers
+ if (productionsite->has_workers(enhancement, game()))
+ {
+ // forcing first upgrade
+ if ((en_bo.cnt_under_construction_ + en_bo.cnt_built_ + en_bo.unoccupied_) == 0
+ and (productionsite_observer.bo->cnt_built_ -
+ productionsite_observer.bo->unoccupied_) >= 1
+ and (game().get_gametime() - productionsite_observer.built_time_) > 30 * 60 * 1000
+ and !mines_.empty()) {
+
+ if (kUpgradeDebug)
+ log(" UPGRADE: upgrading (forcing as first) %12s at %3d x %3d: age %d min.\n",
+ productionsite_observer.bo->name,
+ productionsite->get_position().x,
+ productionsite->get_position().y,
+ (game().get_gametime() - productionsite_observer.built_time_) / 60000);
+
+ game().send_player_enhance_building(*productionsite, enhancement);
+ return true;
+ }
+ }
}
-
- // now, let consider normal upgrade
-
- if (kUpgradeDebug)
- log(" UPGRADE: %1d: working enhanced buildings (%15s): %1d, statitistics: %2d\n",
- player_number(),
- en_bo.name,
- en_bo.cnt_built_ - en_bo.unoccupied_,
- en_bo.current_stats_);
-
- // do not upgrade if candidate production % is too low
- if ((en_bo.cnt_built_ - en_bo.unoccupied_) ==
- 0 or(en_bo.cnt_under_construction_ + en_bo.unoccupied_) > 0 or en_bo.current_stats_ <
- 50)
- continue;
+ }
+
+ // now, let consider normal upgrade
+
+ if (kUpgradeDebug)
+ log(" UPGRADE: %1d: working enhanced buildings (%15s): %1d, statitistics: %2d\n",
+ player_number(),
+ en_bo.name,
+ en_bo.cnt_built_ - en_bo.unoccupied_,
+ en_bo.current_stats_);
+
+ // do not upgrade if candidate production % is too low
+ if ((en_bo.cnt_built_ - en_bo.unoccupied_) !=
+ 0 or(en_bo.cnt_under_construction_ + en_bo.unoccupied_) <= 0 or en_bo.current_stats_ >= 50)
+ {
int32_t prio = 0;
@@ -2278,7 +2278,7 @@
if (prio > maxprio) {
maxprio = prio;
- enbld = (*x.current);
+ enbld = enhancement;
bestbld = &en_bo;
}
}
@@ -2356,57 +2356,55 @@
}
// Check whether building is enhanceable. If yes consider an upgrade.
- std::set<Building_Index> enhancements = mine->enhancements();
+ Building_Index enhancement = mine->enhancement();
int32_t maxprio = 0;
Building_Index enbld = INVALID_INDEX;
BuildingObserver* bestbld = nullptr;
bool changed = false;
- container_iterate_const(std::set<Building_Index>, enhancements, x) {
- // Only enhance buildings that are allowed (scenario mode)
- if (player->is_building_type_allowed(*x.current)) {
- // first exclude possibility there are enhancements in construction or unoccupied_
- const Building_Descr& bld = *tribe->get_building_descr(*x.current);
- BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
-
- if (kMinesUpdateDebug)
- log(" MINES_UPDATE: considering upgrade to %15s, count B:%1d(stat:%3d) U:%1d "
- "C:%1d\n",
- en_bo.name,
- en_bo.cnt_built_,
- en_bo.current_stats_,
- en_bo.unoccupied_,
- en_bo.cnt_under_construction_);
-
- if (en_bo.unoccupied_ + en_bo.cnt_under_construction_ > 0)
- continue;
-
+ // Only enhance buildings that are allowed (scenario mode)
+ if (player->is_building_type_allowed(enhancement)) {
+ // first exclude possibility there are enhancements in construction or unoccupied_
+ const Building_Descr& bld = *tribe->get_building_descr(enhancement);
+ BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
+
+ if (kMinesUpdateDebug)
+ log(" MINES_UPDATE: considering upgrade to %15s, count B:%1d(stat:%3d) U:%1d "
+ "C:%1d\n",
+ en_bo.name,
+ en_bo.cnt_built_,
+ en_bo.current_stats_,
+ en_bo.unoccupied_,
+ en_bo.cnt_under_construction_);
+
+ if (en_bo.unoccupied_ + en_bo.cnt_under_construction_ <= 0)
+ {
// do not upgrade target building are not working properly (probably do not have food)
- if (en_bo.cnt_built_ > 0 and en_bo.current_stats_ < 60)
- continue;
-
- // do not build the same building so soon (kind of duplicity check)
- if (gametime - en_bo.construction_decision_time_ < kBuildingMinInterval)
- continue;
-
- // Check if mine needs an enhancement to mine more resources
- uint8_t const until = field->get_starting_res_amount() *
- (100 - productionsite_observer.bo->mines_percent_) / 100;
-
- if (kMinesUpdateDebug)
- log(" MINES_UPDATE: until:%3d ?>, current: %3d\n", until, current);
-
- if (until >= current) {
- // add some randomness - just for the case if more than one
- // enhancement is available (not in any tribe yet)
- int32_t const prio = time(nullptr) % 3 + 1;
-
- if (prio > maxprio) {
- maxprio = prio;
- enbld = (*x.current);
- bestbld = &en_bo;
+ if (en_bo.cnt_built_ > 0 and en_bo.current_stats_ >= 60)
+ {
+ // do not build the same building so soon (kind of duplicity check)
+ if (gametime - en_bo.construction_decision_time_ >= kBuildingMinInterval)
+ {
+ // Check if mine needs an enhancement to mine more resources
+ uint8_t const until = field->get_starting_res_amount() *
+ (100 - productionsite_observer.bo->mines_percent_) / 100;
if (kMinesUpdateDebug)
- log(" MINES_UPDATE: ..is candidate\n");
+ log(" MINES_UPDATE: until:%3d ?>, current: %3d\n", until, current);
+
+ if (until >= current) {
+ // add some randomness - just for the case if more than one
+ // enhancement is available (not in any tribe yet)
+ int32_t const prio = time(nullptr) % 3 + 1;
+
+ if (prio > maxprio) {
+ maxprio = prio;
+ enbld = enhancement;
+ bestbld = &en_bo;
+
+ if (kMinesUpdateDebug)
+ log(" MINES_UPDATE: ..is candidate\n");
+ }
+ }
}
}
}
=== modified file 'src/logic/building.cc'
--- src/logic/building.cc 2014-07-05 13:28:20 +0000
+++ src/logic/building.cc 2014-07-12 23:55:42 +0000
@@ -96,39 +96,37 @@
// Parse build options
m_buildable = global_s.get_bool("buildable", true);
m_destructible = global_s.get_bool("destructible", true);
- while
- (Section::Value const * const v = global_s.get_next_val("enhancement"))
- try {
- std::string const target_name = v->get_string();
- if (target_name == name())
- throw wexception("enhancement to same type");
- if (target_name == "constructionsite")
- throw wexception("enhancement to special type constructionsite");
- Building_Index const en_i = tribe().building_index(target_name);
- if (en_i != INVALID_INDEX) {
- if (enhancements().count(en_i))
- throw wexception("this has already been declared");
- m_enhancements.insert(en_i);
-
- // Merge the enhancements workarea info into this building's
- // workarea info.
- const Building_Descr & enhancement =
- *tribe().get_building_descr(en_i);
+ m_enhancement = INVALID_INDEX;
+
+ if(Section::Value const * const v = global_s.get_next_val("enhancement"))
+ {
+ std::string const target_name = v->get_string();
+ if (target_name == name())
+ throw wexception("enhancement to same type");
+ if (target_name == "constructionsite")
+ throw wexception("enhancement to special type constructionsite");
+ Building_Index const en_i = tribe().building_index(target_name);
+ if (en_i != INVALID_INDEX) {
+ m_enhancement = en_i;
+
+ // Merge the enhancements workarea info into this building's
+ // workarea info.
+ const Building_Descr & tmp_enhancement =
+ *tribe().get_building_descr(en_i);
+ container_iterate_const
+ (Workarea_Info, tmp_enhancement.m_workarea_info, j)
+ {
+ std::set<std::string> & r = m_workarea_info[j.current->first];
container_iterate_const
- (Workarea_Info, enhancement.m_workarea_info, j)
- {
- std::set<std::string> & r = m_workarea_info[j.current->first];
- container_iterate_const
- (std::set<std::string>, j.current->second, i)
- r.insert(*i.current);
- }
- } else
- throw wexception
- ("\"%s\" has not been defined as a building type (wrong declaration order?)",
- target_name.c_str());
- } catch (const _wexception & e) {
- throw wexception("\"enhancements=%s\": %s", v->get_string(), e.what());
- }
+ (std::set<std::string>, j.current->second, i)
+ r.insert(*i.current);
+ }
+ } else
+ throw wexception
+ ("\"%s\" has not been defined as a building type (wrong declaration order?)",
+ target_name.c_str());
+ }
+
m_enhanced_building = global_s.get_bool("enhanced_building", false);
m_global = directory.find("global/") < directory.size();
if (m_buildable || m_enhanced_building) {
@@ -350,7 +348,7 @@
if (d.is_buildable() or d.is_enhanced())
caps |= PCap_Dismantle;
}
- if (d.enhancements().size())
+ if (d.enhancement() != INVALID_INDEX)
caps |= PCap_Enhancable;
return caps;
}
=== modified file 'src/logic/building.h'
--- src/logic/building.h 2014-07-05 16:41:51 +0000
+++ src/logic/building.h 2014-07-12 23:55:42 +0000
@@ -58,7 +58,6 @@
* Common to all buildings!
*/
struct Building_Descr : public Map_Object_Descr {
- typedef std::set<Building_Index> Enhancements;
typedef std::vector<Building_Index> FormerBuildings;
Building_Descr
@@ -96,11 +95,7 @@
bool get_isport() const {return m_port;}
virtual uint32_t get_ui_anim() const {return get_animation("idle");}
- const Enhancements & enhancements() const {return m_enhancements;}
- void add_enhancement(const Building_Index & i) {
- assert(not m_enhancements.count(i));
- m_enhancements.insert(i);
- }
+ const Building_Index & enhancement() const {return m_enhancement;}
/// Create a building of this type in the game. Calls init, which does
/// different things for different types of buildings (such as conquering
@@ -147,7 +142,7 @@
int32_t m_size; // size of the building
bool m_mine;
bool m_port;
- Enhancements m_enhancements;
+ Building_Index m_enhancement;
bool m_enhanced_building; // if it is one, it is bulldozable
BuildingHints m_hints; // hints (knowledge) for computer players
bool m_global; // whether this is a "global" building
@@ -233,15 +228,15 @@
void collect_priorities
(std::map<int32_t, std::map<Ware_Index, int32_t> > & p) const;
- const std::set<Building_Index> & enhancements() const {
- return descr().enhancements();
+ const Building_Index & enhancement() const {
+ return descr().enhancement();
}
/**
* The former buildings vector keeps track of all former buildings
* that have been enhanced up to the current one. The current building
* index will be in the last position. For construction sites, it is
- * empty exceptenhancements. For a dismantle site, the last item will
+ * empty except enhancements. For a dismantle site, the last item will
* be the one being dismantled.
*/
const FormerBuildings get_former_buildings() {
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc 2014-07-05 14:22:44 +0000
+++ src/logic/player.cc 2014-07-12 23:55:42 +0000
@@ -133,7 +133,7 @@
++i)
{
const Widelands::Building_Descr* ob = tribe_descr.get_building_descr(i);
- if (ob->enhancements().count(oldest_idx)) {
+ if (ob->enhancement() == oldest_idx) {
former_buildings->insert(former_buildings->begin(), i);
break;
}
@@ -721,7 +721,7 @@
{
if (&building->owner() ==
this and(index_of_new_building == INVALID_INDEX ||
- building->descr().enhancements().count(index_of_new_building))) {
+ building->descr().enhancement() == index_of_new_building)) {
Building::FormerBuildings former_buildings = building->get_former_buildings();
const Coords position = building->get_position();
=== modified file 'src/map_io/widelands_map_buildingdata_data_packet.cc'
--- src/map_io/widelands_map_buildingdata_data_packet.cc 2014-07-03 19:26:30 +0000
+++ src/map_io/widelands_map_buildingdata_data_packet.cc 2014-07-12 23:55:42 +0000
@@ -281,7 +281,7 @@
}
for (Building_Index i = 0; i < t.get_nrbuildings(); ++i) {
Building_Descr const * ob = t.get_building_descr(i);
- if (ob->enhancements().count(former_idx)) {
+ if (ob->enhancement() == former_idx) {
b.m_old_buildings.insert(b.m_old_buildings.begin(), i);
break;
}
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2014-07-03 19:26:30 +0000
+++ src/wui/buildingwindow.cc 2014-07-12 23:55:42 +0000
@@ -222,13 +222,12 @@
} // upcast to productionsite
if (m_capscache & Widelands::Building::PCap_Enhancable) {
- const std::set<Widelands::Building_Index> & enhancements =
- m_building.enhancements();
+ const Widelands::Building_Index & enhancement =
+ m_building.enhancement();
const Widelands::Tribe_Descr & tribe = owner.tribe();
- container_iterate_const(std::set<Widelands::Building_Index>, enhancements, i)
- if (owner.is_building_type_allowed(*i.current)) {
+ if (owner.is_building_type_allowed(enhancement)) {
const Widelands::Building_Descr & building_descr =
- *tribe.get_building_descr(*i.current);
+ *tribe.get_building_descr(enhancement);
char buffer[128];
snprintf
(buffer, sizeof(buffer),
@@ -241,11 +240,9 @@
std::string(buffer) + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +
waremap_to_richtext(tribe, building_descr.enhancement_cost()));
// button id = building id
- enhancebtn->sigclicked.connect
- (boost::bind
- (&Building_Window::act_enhance,
- boost::ref(*this),
- boost::ref(*i.current)));
+ enhancebtn->sigclicked.connect([this, &enhancement] {
+ this->act_enhance(enhancement);
+ });
capsbuttons->add
(enhancebtn,
UI::Box::AlignCenter);