widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13170
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
TiborB has proposed merging lp:~widelands-dev/widelands/road_promotions into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/road_promotions/+merge/344182
This is only formal request to get windows binary for testing!!!
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/road_promotions into lp:widelands.
=== modified file 'src/economy/road.cc'
--- src/economy/road.cc 2018-04-07 16:59:00 +0000
+++ src/economy/road.cc 2018-04-24 19:52:00 +0000
@@ -50,8 +50,8 @@
*/
Road::Road()
: PlayerImmovable(g_road_descr),
- busyness_(0),
- busyness_last_update_(0),
+ wallet_(0),
+ last_wallet_check_(0),
type_(0),
idle_index_(0) {
flags_[0] = flags_[1] = nullptr;
@@ -543,68 +543,74 @@
* \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 some_factor = 2;
+ const int16_t animal_price = 2;
+ const int16_t max_wallet = 500;
+
+ 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_);
+ last_wallet_check_ = gametime;
+ wallet_ += some_factor * (flags_[flagid]->current_wares() + 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("busyness_: %i\n", wallet_);
}
}
=== modified file 'src/economy/road.h'
--- src/economy/road.h 2018-04-07 16:59:00 +0000
+++ src/economy/road.h 2018-04-24 19:52:00 +0000
@@ -139,10 +139,10 @@
private:
/// Counter that is incremented when a ware does not get a carrier for this
/// road immediately and decremented over time.
- uint32_t busyness_;
+ int32_t wallet_;
/// holds the gametime when busyness_ was last updated
- uint32_t busyness_last_update_;
+ uint32_t last_wallet_check_;
uint8_t type_; ///< RoadType, 2 bits used
Flag* flags_[2]; ///< start and end flag
=== modified file 'src/map_io/map_roaddata_packet.cc'
--- src/map_io/map_roaddata_packet.cc 2018-04-07 16:59:00 +0000
+++ src/map_io/map_roaddata_packet.cc 2018-04-24 19:52:00 +0000
@@ -73,8 +73,8 @@
}
road.set_owner(egbase.get_player(player_index));
- road.busyness_ = fr.unsigned_32();
- road.busyness_last_update_ = fr.unsigned_32();
+ road.wallet_ = fr.unsigned_32();
+ road.last_wallet_check_ = fr.unsigned_32();
road.type_ = fr.unsigned_32();
{
uint32_t const flag_0_serial = fr.unsigned_32();
@@ -190,8 +190,8 @@
// Theres only the owner
fw.unsigned_8(r->owner().player_number());
- fw.unsigned_32(r->busyness_);
- fw.unsigned_32(r->busyness_last_update_);
+ fw.unsigned_32(r->wallet_);
+ fw.unsigned_32(r->last_wallet_check_);
fw.unsigned_32(r->type_);
Follow ups
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-07-10
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: ypopezios, 2018-07-07
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: ypopezios, 2018-07-07
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: noreply, 2018-07-07
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-07-07
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-07-07
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: Klaus Halfmann, 2018-07-07
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-07-07
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: ypopezios, 2018-07-07
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-07-06
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-06-05
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-06-05
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-26
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-05-26
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-16
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-11
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-08
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-07
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-04
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-05-02
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-04-27
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: TiborB, 2018-04-27
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: GunChleoc, 2018-04-27
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-04-27
-
Re: [Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: hessenfarmer, 2018-04-25
-
[Merge] lp:~widelands-dev/widelands/road_promotions into lp:widelands
From: bunnybot, 2018-04-24