[Widelands-dev] [Merge] lp:~widelands-dev/widelands/mines-worldsavior into lp:widelands

2018-08-01 Thread bunnybot
Continuous integration builds have changed state:

Travis build 3746. State: failed. Details: 
https://travis-ci.org/widelands/widelands/builds/411028029.
Appveyor build 3546. State: success. Details: 
https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_mines_worldsavior-3546.
-- 
https://code.launchpad.net/~widelands-dev/widelands/mines-worldsavior/+merge/350716
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/mines-worldsavior.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/ferry into lp:widelands

2018-08-01 Thread bunnybot
Continuous integration builds have changed state:

Travis build 3745. State: failed. Details: 
https://travis-ci.org/widelands/widelands/builds/410977319.
Appveyor build 3545. State: failed. Details: 
https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ferry-3545.
-- 
https://code.launchpad.net/~widelands-dev/widelands/ferry/+merge/351880
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/ferry into lp:widelands.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into lp:widelands

2018-08-01 Thread bunnybot
Continuous integration builds have changed state:

Travis build 3744. State: passed. Details: 
https://travis-ci.org/widelands/widelands/builds/410949945.
Appveyor build 3544. State: failed. Details: 
https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1783878_editor_random_map_tribe-3544.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1783878_editor_random_map_tribe/+merge/352038
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into 
lp:widelands.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into lp:widelands

2018-08-01 Thread kaputtnik
kaputtnik has proposed merging 
lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into 
lp:widelands.

Commit message:
Set random tribes when using the random map generator

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1783878 in widelands: "Editor: Saved random map does segfault on load if 
no tribe is explicitly set"
  https://bugs.launchpad.net/widelands/+bug/1783878

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1783878_editor_random_map_tribe/+merge/352038

Fixes a bug in random map generator -> explicitly set a tribe to each player. 
The tribe is set randomly.
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1783878_editor_random_map_tribe into 
lp:widelands.
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc	2018-07-21 07:53:42 +
+++ src/editor/map_generator.cc	2018-08-01 18:31:33 +
@@ -28,6 +28,7 @@
 #include "logic/editor_game_base.h"
 #include "logic/findnode.h"
 #include "logic/map.h"
+#include "logic/map_objects/tribes/tribe_basic_info.h"
 #include "logic/map_objects/world/map_gen.h"
 #include "logic/map_objects/world/world.h"
 #include "scripting/lua_interface.h"
@@ -661,7 +662,6 @@
 	// Care about players and place their start positions
 	map_.set_nrplayers(map_info_.numPlayers);
 	assert(map_info_.numPlayers >= 1);
-	const std::string tribe = map_.get_scenario_player_tribe(1);
 	const std::string ai = map_.get_scenario_player_ai(1);
 	FindNodeSize functor(FindNodeSize::sizeBig);
 	Coords playerstart(Coords::null());
@@ -714,6 +714,7 @@
 	for (PlayerNumber n = 1; n <= map_info_.numPlayers; ++n) {
 		// Set scenario information - needed even if it's not a scenario
 		map_.set_scenario_player_name(n, _("Random Player"));
+		const std::string tribe = get_all_tribenames()[rng.rand() % get_all_tribenames().size()];
 		map_.set_scenario_player_tribe(n, tribe);
 		map_.set_scenario_player_ai(n, ai);
 		map_.set_scenario_player_closeable(n, false);

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/congestion2 into lp:widelands

2018-08-01 Thread ypopezios
Replied to inline comments. Will update the code soon.

Diff comments:

> === modified file 'src/economy/flag.cc'
> --- src/economy/flag.cc   2018-07-11 08:32:54 +
> +++ src/economy/flag.cc   2018-07-30 09:36:58 +
> @@ -505,14 +576,43 @@
>   sizeof(wares_[0]) * (ware_filled_ - best_index));
>  
>   ware->set_location(game, nullptr);
> -
> - // wake up capacity wait queue
> - wake_up_capacity_queue(game);
> -
>   return ware;
>  }
>  
>  /**
> + * Called by carrier code to notify waiting carriers
> + * which may be interested in the new state of this flag.
> + */
> +void Flag::ware_departing(Game& game) {
> + // Wake up one sleeper from the capacity queue.
> + while (!capacity_wait_.empty()) {
> + Worker* const w = capacity_wait_[0].get(game); // NOCOM 
> consider using a deque

Yes please.

> + capacity_wait_.erase(capacity_wait_.begin());
> + if (w && w->wakeup_flag_capacity(game, *this)) {
> + return;
> + }
> + }
> +
> + // Consider pending wares of neighboring flags.
> + for (int32_t dir = 1; dir <= WalkingDir::LAST_DIRECTION; ++dir) {
> + Road* const road = get_road(dir);
> + if (!road) {
> + continue;
> + }
> +
> + Flag* other = >get_flag(Road::FlagEnd);
> + if (other == this) {
> + other = >get_flag(Road::FlagStart);
> + }
> +
> + PendingWare* pw = other->get_ware_for_flag(*this, kPendingOnly);
> + if (pw && road->notify_ware(game, *other)) {
> + pw->pending = false;
> + }
> + }
> +}
> +
> +/**
>   * Accelerate potential promotion of roads adjacent to a newly promoted road.
>   */
>  void Flag::propagate_promoted_road(Road* const promoted_road) {
> @@ -681,6 +779,72 @@
>  }
>  
>  /**
> + * Called by neighboring flags, before agreeing for a carrier
> + * to take one of their wares heading to this flag.
> + * \return true/allow on low congestion-risk.
> + */
> +bool Flag::allow_ware_from_flag(WareInstance& ware, Flag& flag) {
> + // avoid iteration for the easy cases
> + if (ware_filled_ < ware_capacity_ - 2) {
> + return true;
> + }
> +
> + DescriptionIndex const descr_index = ware.descr_index();
> + bool has_swappable = false;
> + for (int i = 0; i < ware_filled_; ++i) {
> + PendingWare& pw = wares_[i];
> + if (pw.pending && pw.nextstep == ) {
> + has_swappable = true;
> + } else if (pw.ware->descr_index() == descr_index) {
> + return false;
> + }
> + }
> + return (ware_filled_ < ware_capacity_ || has_swappable) ? true : false;
> +}
> +
> +/**
> + * Called when a ware is trying to reach this flag through the provided road,
> + * having just arrived to the provided flag.
> + * Swaps pending wares if possible. Otherwise,
> + * asks road for carrier on low congestion-risk.
> + * \return false if the ware is not immediately served.
> + */
> +bool Flag::update_ware_from_flag(Game& game, PendingWare& pw1, Road& road, 
> Flag& flag) {
> + WareInstance& w1 = *pw1.ware;
> + DescriptionIndex const w1_descr_index = w1.descr_index();
> + bool has_same_ware = false;
> + bool has_swappable = false;
> + for (int i = 0; i < ware_filled_; ++i) {
> + PendingWare& pw2 = wares_[i];
> + WareInstance& w2 = *pw2.ware;
> + if (w2.descr_index() == w1_descr_index) {
> + if (pw2.nextstep == ) {
> + // swap pending wares remotely
> + init_ware(game, w1, pw2);
> + flag.init_ware(game, w2, pw1);
> + w1.update(game);
> + w2.update(game);
> + return true;
> + }
> +
> + has_same_ware = true;
> + } else if (pw2.pending && pw2.nextstep == ) {
> + has_swappable = true;
> + }
> + }
> +
> + // ask road for carrier on low congestion-risk
> + if (ware_filled_ < ware_capacity_ - 2 ||
> + (!has_same_ware && (ware_filled_ < ware_capacity_ || 
> has_swappable))) {

I don't think so. We may be able to unify this code in a future branch, after 
wares get stripped off their code, in favour to flags.

> + if (road.notify_ware(game, flag)) {
> + pw1.pending = false;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +/**
>   * Called whenever a road gets broken or split.
>   * Make sure all wares on this flag are rerouted if necessary.
>   *
> 
> === modified file 'src/logic/map_objects/tribes/carrier.h'
> --- src/logic/map_objects/tribes/carrier.h2018-04-15 06:13:09 +
> +++ 

Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/congestion2 into lp:widelands

2018-08-01 Thread GunChleoc
Another round of code review done - just some small nits.

Diff comments:

> === modified file 'src/economy/flag.cc'
> --- src/economy/flag.cc   2018-07-11 08:32:54 +
> +++ src/economy/flag.cc   2018-07-30 09:36:58 +
> @@ -400,103 +450,124 @@
>  #define MAX_TRANSFER_PRIORITY 16
>  
>  /**
> - * Called by carrier code to indicate that the carrier is moving to pick up 
> an
> - * ware. Ware with highest transfer priority is chosen.
> - * \return true if an ware is actually waiting for the carrier.
> - */
> -bool Flag::ack_pickup(Game&, Flag& destflag) {
> - int32_t highest_pri = -1;
> - int32_t i_pri = -1;
> -
> - for (int32_t i = 0; i < ware_filled_; ++i) {
> - if (!wares_[i].pending)
> - continue;
> -
> - if (wares_[i].nextstep != )
> - continue;
> -
> - if (wares_[i].priority > highest_pri) {
> - highest_pri = wares_[i].priority;
> - i_pri = i;
> -
> - // Increase ware priority, it matters only if the ware 
> has to wait.
> - if (wares_[i].priority < MAX_TRANSFER_PRIORITY)
> - wares_[i].priority++;
> - }
> - }
> -
> - if (i_pri >= 0) {
> - wares_[i_pri].pending = false;
> - return true;
> - }
> -
> - return false;
> -}
> -/**
>   * Called by the carriercode when the carrier is called away from his job
>   * but has acknowledged a ware before. This ware is then freed again
> - * to be picked by another carrier. Returns true if an ware was indeed
> - * made pending again
> + * to be picked by another carrier. Returns true if a ware was indeed
> + * made pending again.
>   */
>  bool Flag::cancel_pickup(Game& game, Flag& destflag) {
> - int32_t lowest_prio = MAX_TRANSFER_PRIORITY + 1;
> - int32_t i_pri = -1;
> -
>   for (int32_t i = 0; i < ware_filled_; ++i) {
> - if (wares_[i].pending)
> - continue;
> -
> - if (wares_[i].nextstep != )
> - continue;
> -
> - if (wares_[i].priority < lowest_prio) {
> - lowest_prio = wares_[i].priority;
> - i_pri = i;
> + PendingWare& pw = wares_[i];
> + if (!pw.pending && pw.nextstep == ) {
> + pw.pending = true;
> + pw.ware->update(game);  //  will call call_carrier() if 
> necessary
> + return true;
>   }
>   }
>  
> - if (i_pri >= 0) {
> - wares_[i_pri].pending = true;
> - wares_[i_pri].ware->update(game);  //  will call call_carrier() 
> if necessary
> - return true;
> - }
> -
>   return false;
>  }
>  
>  /**
> - * Wake one sleeper from the capacity queue.
> -*/
> -void Flag::wake_up_capacity_queue(Game& game) {
> - while (!capacity_wait_.empty()) {
> - Worker* const w = capacity_wait_[0].get(game);
> - capacity_wait_.erase(capacity_wait_.begin());
> - if (w && w->wakeup_flag_capacity(game, *this))
> - break;
> - }
> -}
> -
> -/**
> - * Called by carrier code to retrieve one of the wares on the flag that is 
> meant
> - * for that carrier.
> - *
> - * This function may return 0 even if \ref ack_pickup() has already been
> - * called successfully.
> -*/
> -WareInstance* Flag::fetch_pending_ware(Game& game, PlayerImmovable& dest) {
> - int32_t best_index = -1;
> -
> - for (int32_t i = 0; i < ware_filled_; ++i) {
> - if (wares_[i].nextstep != )
> - continue;
> -
> - // We prefer to retrieve wares that have already been acked
> - if (best_index < 0 || !wares_[i].pending)
> - best_index = i;
> - }
> -
> - if (best_index < 0)
> + * Called by carrier code to find the best among the wares on this flag
> + * that are meant for the provided dest.
> + * \return index of found ware (carrier will take it)
> + * or kNotFoundAppropriate (carrier will leave empty-handed)
> + */
> +int32_t Flag::find_pending_ware(PlayerImmovable& dest) {
> + int32_t highest_pri = -1;
> + int32_t best_index = kNotFoundAppropriate;
> + bool ware_pended = false;
> +
> + for (int32_t i = 0; i < ware_filled_; ++i) {
> + PendingWare& pw = wares_[i];
> + if (pw.nextstep != ) {
> + continue;
> + }
> +
> + if (pw.priority < MAX_TRANSFER_PRIORITY) {
> + pw.priority++;
> + }
> + // Release promised pickup, in case we find a preferable ware
> + if (!ware_pended && !pw.pending) {
> + ware_pended = pw.pending = true;
> + }
> +
> + // If dest is flag, we exclude wares that can stress it
> + if ( != building_ &&
> + 
>