← Back to team overview

widelands-dev team mailing list archive

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

 

@hessenfarmer - see my responses

Diff comments:

> === modified file 'src/logic/map_objects/tribes/productionsite.cc'
> --- src/logic/map_objects/tribes/productionsite.cc	2019-05-18 11:58:43 +0000
> +++ src/logic/map_objects/tribes/productionsite.cc	2019-05-19 20:55:45 +0000
> @@ -954,24 +955,28 @@
>  		top_state().phase = result;
>  	}
>  
> +	const uint32_t current_duration = game.get_gametime() - last_program_end_time;
> +	assert(game.get_gametime() >= last_program_end_time);

yes, it would be more logical, but at the end this does not matter....

> +	last_program_end_time = game.get_gametime();
> +
>  	switch (result) {
>  	case ProgramResult::kFailed:
>  		statistics_.erase(statistics_.begin(), statistics_.begin() + 1);
>  		statistics_.push_back(false);
>  		calc_statistics();
> -		crude_percent_ = crude_percent_ * 8 / 10;
> +		update_crude_statistics(current_duration, false);
>  		break;
>  	case ProgramResult::kCompleted:
>  		skipped_programs_.erase(program_name);
>  		statistics_.erase(statistics_.begin(), statistics_.begin() + 1);
>  		statistics_.push_back(true);
>  		train_workers(game);
> -		crude_percent_ = crude_percent_ * 8 / 10 + 1000000 * 2 / 10;
> +		update_crude_statistics(current_duration, true);
>  		calc_statistics();
>  		break;
>  	case ProgramResult::kSkipped:
>  		skipped_programs_[program_name] = game.get_gametime();
> -		crude_percent_ = crude_percent_ * 98 / 100;
> +		update_crude_statistics(current_duration, false);
>  		break;
>  	case ProgramResult::kNone:
>  		skipped_programs_.erase(program_name);
> @@ -1032,4 +1037,17 @@
>  
>  	default_anim_ = anim;
>  }
> +
> +void ProductionSite::update_crude_statistics(uint32_t duration, const bool produced) {
> +	static const uint32_t duration_cap = 90 * 1000; //This is highest allowed program duration

OK, I will extend to what 3 minutes? I have printf to see the values and did not see any wild numbers, so this is really only insurance for first program run and some corner situations...

> +	// just for case something went very wrong...
> +	static const uint32_t entire_duration = 5 * 60 *1000;
> +	if (duration > duration_cap) {
> +		duration = duration_cap;
> +	};
> +	const uint32_t old_duration = entire_duration - duration;
> +	crude_percent_ = (crude_percent_ * old_duration + produced * duration * 10000) / entire_duration;
> +	assert(crude_percent_ <= 10000); //be sure we do not go above 100 %
> +	}
> +
>  }  // namespace Widelands


-- 
https://code.launchpad.net/~widelands-dev/widelands/ai_productionsites_statistics/+merge/367613
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ai_productionsites_statistics into lp:widelands.


References