The International Simutrans Forum

 

Author Topic: Possible issue with city population code?  (Read 1819 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18745
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Possible issue with city population code?
« on: December 20, 2012, 01:38:50 AM »
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:

Code: [Select]
uint16                     level            = obj.get_int("level", 1) - 1;

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

Code: [Select]
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:

Code: [Select]
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):

Code: [Select]
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;
« Last Edit: December 20, 2012, 01:44:06 AM by jamespetts »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18745
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Possible issue with city population code?
« Reply #1 on: December 21, 2012, 11:56:59 AM »
Any thoughts on this, anyone...?

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4601
  • Languages: EN, DE, AT
Re: Possible issue with city population code?
« Reply #2 on: December 21, 2012, 02:04:05 PM »
No idea :)

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18745
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Possible issue with city population code?
« Reply #3 on: December 21, 2012, 02:23:07 PM »
Hmm - very odd. Surely it can't be intended that level 1/0 buildings have no effect on arb/won?

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4601
  • Languages: EN, DE, AT
Re: Possible issue with city population code?
« Reply #4 on: December 21, 2012, 03:40:59 PM »
Maybe that is the desired effect? think of parks etc.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18745
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Possible issue with city population code?
« Reply #5 on: December 21, 2012, 07:47:56 PM »
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.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9566
  • Languages: De,EN,JP
Re: Possible issue with city population code?
« Reply #6 on: December 21, 2012, 08:14:36 PM »
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.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18745
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Possible issue with city population code?
« Reply #7 on: December 21, 2012, 10:05:45 PM »
Should one +1 these figures, too, then?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9566
  • Languages: De,EN,JP
Re: Possible issue with city population code?
« Reply #8 on: December 22, 2012, 09:04:15 PM »
Yes +1 was indeed missing. Much less spread out earlier towns.