News:

Want to praise Simutrans?
Your feedback is important for us ;D.

Possible issue with city population code?

Started by jamespetts, December 20, 2012, 01:38:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jamespetts

I am in the process of delving into the city population related code to try to understand it (any help with that would be much appreciated), and have hit a possible anomaly. I am not sure whether it is a bug, or whether I simply do not understand the purpose, but, on balance, I thought it more likely to be a bug, so I have reported it here: feel free to move this if this is intended.

In makeobj, the "level" of buildings has 1 subtracted from it as follows:


uint16                     level            = obj.get_int("level", 1) - 1;


This is compensated elsewhere, for example (in simcity.cc):


buildings.append(add_gb, tile->get_besch()->get_level() + 1, 16);


I am not entirely sure what the purpose of doing this is, but I suspect that it might be linked to passenger generation.

In any event, there is a place in the code that does not seem to add the 1 back, and that is in void stadt_t::baue_gebaeude(const koord k) in simcity.cc:


if (sum_gewerbe > sum_industrie  &&  sum_gewerbe > sum_wohnung) {
         h = hausbauer_t::get_gewerbe(0, current_month, cl);
         if (h != NULL) {
            arb += h->get_level() * 20;
         }
      }

      if (h == NULL  &&  sum_industrie > sum_gewerbe  &&  sum_industrie > sum_wohnung) {
         h = hausbauer_t::get_industrie(0, current_month, cl);
         if (h != NULL) {
            arb += h->get_level() * 20;
         }
      }

      if (h == NULL  &&  sum_wohnung > sum_industrie  &&  sum_wohnung > sum_gewerbe) {
         h = hausbauer_t::get_wohnhaus(0, current_month, cl);
         if (h != NULL) {
            // will be aligned next to a street
            won += h->get_level() * 10;
         }
      }


This has the effect that a building whose level is defined as 1 in the pakset (and is therefore 0) will not increase either "won" or "arb" at all, whereas  all buildings with a greater level do in fact increase won and arb.

Ought the +1 be added here, or is it intended that all city buildings with a level of 1 do not influence the unemployed/homeless population of a city?

Edit: The same issue appears in bool stadt_t::renoviere_gebaeude(gebaeude_t* gb):


switch (alt_typ) {
            case gebaeude_t::wohnung:   won -= level * 10; break;
            case gebaeude_t::gewerbe:   arb -= level * 20; break;
            case gebaeude_t::industrie: arb -= level * 20; break;
            default: break;
        }

        // exchange building; try to face it to street in front
        gb->mark_images_dirty();
        gb->set_tile( h->get_tile(gebaeude_layout[streetdir], 0, 0) );
        welt->lookup_kartenboden(k)->calc_bild();
        update_gebaeude_from_stadt(gb);
        return_value = true;

        switch (will_haben) {
            case gebaeude_t::wohnung:   won += h->get_level() * 10; break;
            case gebaeude_t::gewerbe:   arb += h->get_level() * 20; break;
            case gebaeude_t::industrie: arb += h->get_level() * 20; break;
            default: break;
        }
    }
    return return_value;
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.

jamespetts

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.

Dwachs

Parsley, sage, rosemary, and maggikraut.

jamespetts

Hmm - very odd. Surely it can't be intended that level 1/0 buildings have no effect on arb/won?
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.

Dwachs

Maybe that is the desired effect? think of parks etc.
Parsley, sage, rosemary, and maggikraut.

jamespetts

Hmm - but I don't think that it's just parks that are level 1? And level 1 buildings do generate passengers and mail, so if this is the desired effect, there is a problem in simcity.cc.
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.

prissi

I think this stems back from when level 0 buildings were ignored. My feeling is that level 0 buildings should increase the counter. Otherwise immediately hte next building needs to be spawn. This would explain the "slums" in earlier times with lower building levels.

jamespetts

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.

prissi

Yes +1 was indeed missing. Much less spread out earlier towns.