Dito :)
I just noticed that you didn't increase the version number for the savegame
packet where you made the changes. This is needed so that Widelands will show
an error message instead of crashing when a user tries to load an older game.
Diff comments:
>
> === modified file 'src/ai/defaultai.cc'
> --- src/ai/defaultai.cc 2015-08-28 19:09:59 +0000
> +++ src/ai/defaultai.cc 2015-10-05 17:29:41 +0000
> @@ -3531,61 +3577,97 @@
> return true;
> }
>
> - // doing nothing when failed count is too low
> - if (site.no_resources_count < 4) {
> + // to avoid problems with uint underflow, we discourage considerations
> below
> + if (gametime < 10 * 60 * 1000) {
> return false;
> }
>
> - // dismantling when the failed count is too high
> - if (site.no_resources_count > 12) {
> -
> flags_to_be_removed.push_back(site.site->base_flag().get_position());
> - if (connected_to_wh) {
> - game().send_player_dismantle(*site.site);
> - } else {
> - game().send_player_bulldoze(*site.site);
> - }
> - site.bo->construction_decision_time_ = gametime;
> - return true;
> - }
> -
> - // is output needed (compare stocked materials vs target values)
> - check_building_necessity(*site.bo);
> -
> - // if we have enough of mined materials on stock - do not upgrade (yet)
> - if (site.bo->output_needed_ == ExtendedBool::kFalse) {
> + // if mine is working, doing nothing
> + if (site.no_resources_since_ > gametime - 5 * 60 * 1000) {
> return false;
> }
>
> // Check whether building is enhanceable. If yes consider an upgrade.
> const BuildingIndex enhancement = site.site->descr().enhancement();
> -
> - // if no enhancement is possible
> - if (enhancement == INVALID_INDEX) {
> - // will be destroyed when no_resource_count will overflow
> + bool has_upgrade = false;
> + if (enhancement != INVALID_INDEX) {
> + if (player_->is_building_type_allowed(enhancement)) {
> + has_upgrade = true;
> + }
> + }
> +
> + // every type of mine has minimal number of mines that are to be
> preserved
> + // (we will not dismantle even if there are no mineable resources left
> for this level of mine
> + // and output is not needed)
> + bool forcing_upgrade = false;
> + const uint16_t minimal_mines_count = (site.bo->built_mat_producer_)?2:1;
> + if (has_upgrade &&
> + mines_per_type[site.bo->mines_].total_count() <=
> minimal_mines_count) {
> + forcing_upgrade = true;
> + }
> +
> +
> + // dismantling a mine
> + if (!has_upgrade) { // if no upgrade, now
> +
> flags_to_be_removed.push_back(site.site->base_flag().get_position());
> + if (connected_to_wh) {
> + game().send_player_dismantle(*site.site);
> + } else {
> + game().send_player_bulldoze(*site.site);
> + }
> + site.bo->construction_decision_time_ = gametime;
> + return true;
> + // if having an upgrade, after half hour
> + } else if (site.no_resources_since_ < gametime - 30 * 60 * 1000 &&
> !forcing_upgrade) {
> +
> flags_to_be_removed.push_back(site.site->base_flag().get_position());
> + if (connected_to_wh) {
> + game().send_player_dismantle(*site.site);
> + } else {
> + game().send_player_bulldoze(*site.site);
> + }
> + site.bo->construction_decision_time_ = gametime;
> + return true;
> + }
> +
> + // if we are here, a mine is upgradeable
> +
> + // if we don't need the output, and we have other buildings of the same
> type, the function returns
> + // and building will be dismantled later.
> + check_building_necessity(*site.bo, PerfEvaluation::kForDismantle,
> gametime);
> + if (site.bo->max_needed_preciousness_ == 0 && !forcing_upgrade) {
> return false;
> }
>
> + // again similarly, no upgrading if not connected, other parts of AI
> will dismantle it,
> + // or connect to a warehouse
> if (!connected_to_wh) {
> - // no enhancement possible
> + return false;
> + }
> +
> + // don't upgrade now if other mines of the same type are right now in
> construction
> + if (mines_per_type[site.bo->mines_].in_construction > 0) {
> return false;
> }
>
> bool changed = false;
> - if (player_->is_building_type_allowed(enhancement)) {
> - // first exclude possibility there are enhancements in
> construction or unoccupied_
> - const BuildingDescr& bld =
> *tribe_->get_building_descr(enhancement);
> - BuildingObserver& en_bo =
> get_building_observer(bld.name().c_str());
> -
> - // if it is too soon for enhancement and making sure there are
> no unoccupied mines
> - if (gametime - en_bo.construction_decision_time_ >=
> kBuildingMinInterval &&
> - en_bo.unoccupied_ + en_bo.cnt_under_construction_ == 0) {
> -
> - // now verify that there are enough workers
> - if (site.site->has_workers(enhancement, game())) { //
> enhancing
> - game().send_player_enhance_building(*site.site,
> enhancement);
> - en_bo.construction_decision_time_ = gametime;
> - changed = true;
> - }
> +
> + // first exclude possibility there are enhancements in construction or
> unoccupied_count_
> + const BuildingDescr& bld = *tribe_->get_building_descr(enhancement);
> + BuildingObserver& en_bo = get_building_observer(bld.name().c_str());
> +
> + // if it is too soon for enhancement
> + if (gametime - en_bo.construction_decision_time_ >=
> kBuildingMinInterval) {
> + // now verify that there are enough workers
> + if (site.site->has_workers(enhancement, game())) { // enhancing
If you think you have it covered, that's good. I just wanted to make sure. I
would have been in favour of fixing it in a separate branch anyway if it needed
fixing.
> + game().send_player_enhance_building(*site.site,
> enhancement);
> + if (site.bo->max_needed_preciousness_ == 0) {
> + assert
> (mines_per_type[site.bo->mines_].total_count() <= minimal_mines_count);
> + }
> + if (mines_per_type[site.bo->mines_].total_count() >
> minimal_mines_count) {
> + assert(site.bo->max_needed_preciousness_ > 0);
> + }
> + en_bo.construction_decision_time_ = gametime;
> + changed = true;
> }
> }
>
--
https://code.launchpad.net/~widelands-dev/widelands/ai_persistent_data/+merge/271853
Your team Widelands Developers is subscribed to branch
lp:~widelands-dev/widelands/ai_persistent_data.
_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~widelands-dev
More help : https://help.launchpad.net/ListHelp