widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13181
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
Review: Needs Information
see inline comment
Diff comments:
> === modified file 'src/economy/road.cc'
> --- src/economy/road.cc 2018-04-07 16:59:00 +0000
> +++ src/economy/road.cc 2018-04-25 19:41:13 +0000
> @@ -543,68 +543,73 @@
> * \return true if a carrier has been sent on its way, false otherwise.
> */
> bool Road::notify_ware(Game& game, FlagId const flagid) {
> - uint32_t const gametime = game.get_gametime();
> - assert(busyness_last_update_ <= gametime);
> - uint32_t const tdelta = gametime - busyness_last_update_;
> -
> - // Iterate over all carriers and try to find one which takes the ware.
> - for (CarrierSlot& slot : carrier_slots_) {
> - if (Carrier* const carrier = slot.carrier.get(game))
> - if (carrier->notify_ware(game, flagid)) {
> - // notify_ware returns false if the carrier currently can not take
> - // the ware. If we get here, the carrier took the ware. So we
> - // decrement the usage busyness.
> - if (500 < tdelta) {
> - busyness_last_update_ = gametime;
> - if (busyness_) {
> - --busyness_;
> -
> - // If busyness_ drops below a limit, release the donkey.
> - // remember that every time a ware is waiting at the flag
> - // busyness_ increase by 10 but every time a ware is immediatly
> - // acked by a carrier busyness_ is decreased by 1 only.
> - // so the limit is not so easy to reach
> - if (busyness_ < 350) {
> - Carrier* const second_carrier = carrier_slots_[1].carrier.get(game);
> - if (second_carrier && second_carrier->top_state().task == &Carrier::taskRoad) {
> - second_carrier->send_signal(game, "cancel");
> - // this signal is not handled in any special way
> - // so it simply pop the task off the stack
> - // the string "cancel" has been used to make clear
> - // the final goal we want to achieve
> - // ie: cancelling current task
> - carrier_slots_[1].carrier = nullptr;
> - carrier_slots_[1].carrier_request = nullptr;
> - type_ = RoadType::kNormal;
> - mark_map(game);
> - }
> - }
> - }
> - }
> - return true;
> - }
> - }
> -
> - // If we get here, no carrier took the ware. So we check if we should
> - // increment the usage counter. busyness_last_update_ prevents that the
> - // counter is incremented too often.
> - if (100 < tdelta) {
> - busyness_last_update_ = gametime;
> - if (500 < (busyness_ += 10)) {
> - type_ = RoadType::kBusy;
> - mark_map(game);
> - for (CarrierSlot& slot : carrier_slots_) {
> - if (!slot.carrier.get(game) && !slot.carrier_request && slot.carrier_type != 1) {
> - request_carrier(slot);
> - }
> - }
> - }
> - }
> - return false;
> +uint32_t const gametime = game.get_gametime();
> + assert(last_wallet_check_ <= gametime);
> + const int16_t animal_price = 600;
> + const int16_t max_wallet = 2.5 * animal_price;
> +
> + const uint8_t carriers_count = (carrier_slots_[1].carrier == nullptr) ? 1 : 2;
> + printf ("DEBUG Carriers count: %d\n", carriers_count);
> +
> + // Iterate over all carriers and try to find one which takes the ware.
> + for (CarrierSlot& slot : carrier_slots_) {
> + if (Carrier* const carrier = slot.carrier.get(game)) {
> + if (carrier->notify_ware(game, flagid)) {
> + // notify_ware returns false if the carrier currently can not take
> + // the ware. If we get here, the carrier took the ware.
> + wallet_ -= carriers_count * (gametime - last_wallet_check_);
if gametime is in ms this would add an unwanted factor of 1000 in the formula
> + last_wallet_check_ = gametime;
> + wallet_ += 2 * (carriers_count + 1) * (4 * (flags_[flagid]->current_wares() - 1) + path_.get_nsteps());
> + if (wallet_ < 0) {
> + wallet_ = 0;
> + if (type_ == RoadType::kBusy) {
> + // beginning of code for demotion
> + // should be moved in a function
> + Carrier* const second_carrier = carrier_slots_[1].carrier.get(game);
> + if (second_carrier && second_carrier->top_state().task == &Carrier::taskRoad) {
> + second_carrier->send_signal(game, "cancel");
> + // this signal is not handled in any special way
> + // so it simply pop the task off the stack
> + // the string "cancel" has been used to make clear
> + // the final goal we want to achieve
> + // ie: cancelling current task
> + carrier_slots_[1].carrier = nullptr;
> + carrier_slots_[1].carrier_request = nullptr;
> + type_ = RoadType::kNormal;
> + mark_map(game);
> + }
> + // end of code for demotion
> + }
> + } else {
> + if (type_ == RoadType::kNormal) {
> + if (wallet_ > 1.5 * animal_price) {
> + wallet_ -= animal_price;
> + // beginning of code for promotion
> + // should be moved in a function
> + type_ = RoadType::kBusy;
> + mark_map(game);
> + for (CarrierSlot& slot2 : carrier_slots_) {
> + if (!slot2.carrier.get(game) && !slot2.carrier_request && slot2.carrier_type != 1) {
> + request_carrier(slot2);
> + }
> + }
> + // end of code for promotion
> + }
> + }
> + if (wallet_ > max_wallet) wallet_ = max_wallet;
> + }
> + return true;
> + }
> + }
> + }
> + // If we get here, no carrier took the ware.
> + // potentially insert here some logic for edge cases like road congestion
> + return false;
> }
>
> +
> void Road::log_general_info(const EditorGameBase& egbase) {
> PlayerImmovable::log_general_info(egbase);
> - molog("busyness_: %i\n", busyness_);
> + molog("wallet_: %i\n", wallet_);
> }
> }
--
https://code.launchpad.net/~widelands-dev/widelands/road_promotions/+merge/344182
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/road_promotions.
References