News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

City power demands - added as supply?

Started by sanna, June 02, 2009, 09:38:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sanna

First of all, I might have totally misread the code, in which case this report is a mere annoyance, not a bug report...

It seemed to me that no matter how high I set the percentage for power coverage in the start up dialogue I got a random amount of power plants, which sent me looking into the code, more specifically bauer/fabrikbauer.cc.

In fabrikbauer_t::increase_industry_density:941-945 there is a loop that iterates through the cities and which I have assumed is intended to add their power demand to the total demand needed:     
    const weighted_vector_tpl<stadt_t*>& staedte = welt->get_staedte();
    for (weighted_vector_tpl<stadt_t*>::const_iterator i = staedte.begin(), end = staedte.end(); i != end; ++i)
    {
      electric_productivity += (*i)->get_power_demand() * 5120;
    }


However, the preceding lines of code (927-939) seems to me to indicate that what is stored in electric_productivity is in fact power supply, not power demand, and that power demand is stored in total_produktivity:
  ITERATE(welt->get_fab_list(), i)
  {
    //fabrik_t * fab = iter.get_current();
    fabrik_t * fab = welt->get_fab_list()[i];
    if(fab->get_besch()->is_electricity_producer())
    {
      electric_productivity += fab->get_base_production();
    }
    else
    {
      total_produktivity += fab->get_base_production();
    }
  }


This said, I must also add that I have no idea what the * 5120 tacked onto the (*i)->get_power_demand() does; I presume it must be related to power being calculated differently in different parts of the code. But its presence makes it (I think) impossible to simply replace  electric_productivity with total_produktivity in the code; at least when I tried I ended up with nothing but power plants no matter how low I put the starting variable... This my lack of understanding of the various ways to calculate power have made it impossible for me to produce a patch :(

Still I hope this post can be useful, if for nothing else then for the possibility to scold me in public for my ignorance  ;)

jamespetts

Saana,

thank you very much for identifying that issue and tracking it down in the code: I am very grateful for your work in this respect. I have found what the code should have been, and it will be changed in the next version. For reference, the correct code was:


for (weighted_vector_tpl<stadt_t*>::const_iterator i = staedte.begin(), end = staedte.end(); i != end; ++i)
{
total_produktivity += ((float)((*i)->get_finance_history_month(0, HIST_CITICENS) * (*i)->get_electricity_consumption(welt->get_timeline_year_month())) * 0.02);
}


Thank you very much :-)
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.