Skip to content

Commit

Permalink
FIX: factory chart stats - take 2
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@8463 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
TurfIt committed May 27, 2018
1 parent 75ed42e commit 27b7ba7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
56 changes: 35 additions & 21 deletions simfab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,7 @@ void fabrik_t::book_weighted_sums(sint64 delta_time)
weighted_sum_boost_mail += prodfactor_mail * delta_time;

// power produced or consumed
sint64 power;
if( desc->is_electricity_producer() ) {
power = ((sint64)get_power_supply() * (sint64)get_power_consumption()) >> leitung_t::FRACTION_PRECISION;
}
else {
power = -(((sint64)get_power_demand() * (sint64)get_power_satisfaction() + (((sint64)1 << leitung_t::FRACTION_PRECISION) - 1)) >> leitung_t::FRACTION_PRECISION);
}
sint64 power = get_power();
weighted_sum_power += power * delta_time;
set_stat( power, FAB_POWER );
}
Expand Down Expand Up @@ -1643,6 +1637,18 @@ sint32 fabrik_t::get_power_satisfaction() const
return trans->get_power_satisfaction();
}

sint64 fabrik_t::get_power() const
{
sint64 power;
if( desc->is_electricity_producer() ) {
power = ((sint64)get_power_supply() * (sint64)get_power_consumption()) >> leitung_t::FRACTION_PRECISION;
}
else {
power = -(((sint64)get_power_demand() * (sint64)get_power_satisfaction() + (((sint64)1 << leitung_t::FRACTION_PRECISION) - 1)) >> leitung_t::FRACTION_PRECISION);
}
return power;
}


sint32 fabrik_t::input_vorrat_an(const goods_desc_t *typ)
{
Expand Down Expand Up @@ -2650,38 +2656,46 @@ void fabrik_t::verteile_waren(const uint32 product)

void fabrik_t::new_month()
{
// calculate weighted averages
if( aggregate_weight > 0 ) {
set_stat( weighted_sum_production / aggregate_weight, FAB_PRODUCTION );
set_stat( weighted_sum_boost_electric / aggregate_weight, FAB_BOOST_ELECTRIC );
set_stat( weighted_sum_boost_pax / aggregate_weight, FAB_BOOST_PAX );
set_stat( weighted_sum_boost_mail / aggregate_weight, FAB_BOOST_MAIL );
set_stat( weighted_sum_power / aggregate_weight, FAB_POWER );
}

// update statistics for input and output goods
for( uint32 in = 0 ; in < input.get_count() ; in++ ){
input[in].roll_stats(desc->get_supplier(in)->get_consumption(), aggregate_weight);
for( uint32 in = 0; in < input.get_count(); in++ ){
input[in].roll_stats( desc->get_supplier(in)->get_consumption(), aggregate_weight );
}
for( uint32 out = 0 ; out < output.get_count() ; out++ ){
output[out].roll_stats(desc->get_product(out)->get_factor(), aggregate_weight);
for( uint32 out = 0; out < output.get_count(); out++ ){
output[out].roll_stats( desc->get_product(out)->get_factor(), aggregate_weight );
}
lieferziele_active_last_month = 0;

// advance statistics a month
for( int s=0; s<MAX_FAB_STAT; ++s ) {
for( int m=MAX_MONTH-1; m>0; --m ) {
for( int s = 0; s < MAX_FAB_STAT; ++s ) {
for( int m = MAX_MONTH - 1; m > 0; --m ) {
statistics[m][s] = statistics[m-1][s];
}
statistics[0][s] = 0;
}

// calculate weighted averages
if( aggregate_weight>0 ) {
statistics[1][FAB_PRODUCTION] = weighted_sum_production / aggregate_weight;
statistics[1][FAB_BOOST_ELECTRIC] = weighted_sum_boost_electric / aggregate_weight;
statistics[1][FAB_BOOST_PAX] = weighted_sum_boost_pax / aggregate_weight;
statistics[1][FAB_BOOST_MAIL] = weighted_sum_boost_mail / aggregate_weight;
statistics[1][FAB_POWER] = weighted_sum_power / aggregate_weight;
}
weighted_sum_production = 0;
weighted_sum_boost_electric = 0;
weighted_sum_boost_pax = 0;
weighted_sum_boost_mail = 0;
weighted_sum_power = 0;
aggregate_weight = 0;

// restore the current values
set_stat( get_current_production(), FAB_PRODUCTION );
set_stat( prodfactor_electric, FAB_BOOST_ELECTRIC );
set_stat( prodfactor_pax, FAB_BOOST_PAX );
set_stat( prodfactor_mail, FAB_BOOST_MAIL );
set_stat( get_power(), FAB_POWER );

// since target cities' population may be increased -> re-apportion pax/mail demand
recalc_demands_at_target_cities();
}
Expand Down
5 changes: 5 additions & 0 deletions simfab.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ class fabrik_t
*/
sint32 get_power_satisfaction() const;

/**
*
*/
sint64 get_power() const;

public:
fabrik_t(loadsave_t *file);
fabrik_t(koord3d pos, player_t* owner, const factory_desc_t* factory_desc, sint32 initial_prod_base);
Expand Down

0 comments on commit 27b7ba7

Please sign in to comment.