← Back to team overview

widelands-dev team mailing list archive

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

 

Mhh, thhis diff shows some Merge conflicts >>>> <<<<<<
But I do not seem them in the code?

I get lost in tat code change, sorry. 
That complexity in Road and Carrier gives me a headache.

Ill give it another try with the debugger tomorrow.


Diff comments:

> === modified file 'src/economy/flag.cc'
> --- src/economy/flag.cc	2018-07-07 09:05:13 +0000
> +++ src/economy/flag.cc	2018-07-10 13:28:48 +0000
> @@ -394,101 +421,112 @@
>  #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 != &destflag)
> -			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
>   */
>  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 != &destflag)
> -			continue;
> -
> -		if (wares_[i].priority < lowest_prio) {
> -			lowest_prio = wares_[i].priority;
> -			i_pri = i;
> +		PendingWare& pw = wares_[i];
> +		if (!pw.pending && pw.nextstep == &destflag) {
> +			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 != &dest)
> -			continue;
> -
> -		// We prefer to retrieve wares that have already been acked
> -		if (best_index < 0 || !wares_[i].pending)
> -			best_index = i;
> -	}
> -
> + * 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 or -1 if not found appropriate
> +*/
> +int32_t Flag::find_pending_ware(PlayerImmovable& dest) {
> +	int32_t highest_pri = -1;
> +	int32_t best_index = -1;
> +	bool ware_pended = false;
> +
> +	for (int32_t i = 0; i < ware_filled_; ++i) {
> +		PendingWare& pw = wares_[i];
> +		if (pw.nextstep != &dest) 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 (&dest != building_ &&
> +			!dynamic_cast<Flag&>(dest).allow_ware_from_flag(*pw.ware, *this)) {
> +			continue;
> +		}
> +
> +		if (pw.priority > highest_pri) {
> +			highest_pri = pw.priority;
> +			best_index = i;
> +		}
> +	}
> +
> +	return best_index;
> +}
> +
> +/**
> + * Like find_pending_ware above, but for carriers who are currently carrying a ware.
> + * \return -2 if denied drop

what does -1 indicate? (and this should be some constant)

> +*/
> +int32_t Flag::find_swapable_ware(WareInstance& ware, Flag& destflag) {
> +	DescriptionIndex const descr_index = ware.descr_index();
> +	int32_t highest_pri = -1;
> +	int32_t best_index = -1;
> +	bool has_same_ware = false;
> +	bool has_allowed = false;
> +	bool ware_pended = false;
> +
> +	for (int32_t i = 0; i < ware_filled_; ++i) {
> +		PendingWare& pw = wares_[i];
> +		if (pw.nextstep != &destflag) {
> +			if (pw.ware->descr_index() == descr_index) has_same_ware = true;
> +			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;
> +		}
> +
> +		// We prefer to retrieve wares that won't stress the destflag
> +		if (destflag.allow_ware_from_flag(*pw.ware, *this)) {
> +			if (!has_allowed) {
> +				has_allowed = true;
> +				highest_pri = -1;
> +			}
> +		} else {
> +			if (has_allowed) continue;
> +		}
> +
> +		if (pw.priority > highest_pri) {
> +			highest_pri = pw.priority;
> +			best_index = i;
> +		}
> +	}
> +
> +	if (best_index > -1) {
> +		return (ware_filled_ > ware_capacity_ - 3 || has_allowed) ? best_index : -1;
> +	} else {
> +		return (ware_filled_ < ware_capacity_ - 2 ||
> +			(ware_filled_ < ware_capacity_ && !has_same_ware)) ? -1 : -2;
> +	}

we need some comments about this magic here

> +}
> +
> +/**
> + * Called by carrier code to retrieve a ware found by the previous methods.
> +*/
> +WareInstance* Flag::fetch_pending_ware(Game& game, int32_t best_index) {
>  	if (best_index < 0)
>  		return nullptr;
>  


-- 
https://code.launchpad.net/~widelands-dev/widelands/congestion2/+merge/348525
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/congestion2.


References