Skip to main content
Topic: [patch] Field locations (Read 6361 times) previous topic - next topic

[patch] Field locations

What: locations for building fields.

Old: only on same height.

New: on all allowed climates.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #1
You must test for minimum z height, otherwise the filed will be too high (on an artifical slope). I think there was another problem with this, apart from the fact that the farmer needs a ropeway in certain cases.

Re: [patch] Field locations

Reply #2
Shouldn't gr->get_grund_hang() == hang_t::flach catch cases where a foundation would be needed? Also the climate function has tests for out of bounds values, so nothing bad could happen there.

You have a point though - maybe a maximal difference of 2 height steps from farm?

PS: I get "cannot destroy karte in any rotation", but no idea if it belongs to this. It was only once, and then all attempts to repeat the process did not work.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #3
The height for getting the climate should be welt->max_height(pos) This take automatically slopes into account. But I remembered, which I took this out: To have more irregular fields around a factory, while on all height all fields around a factory are filled. But I did not touch this for some time now.

Re: [patch] Field locations

Reply #4
Fields never build on slopes, I tested this thoroughly (although it might be a nice possibility for some non-agricultural uses).

The error probably did not belong to this. I checked, and the conditions are enough to prevent fields from spawning outside map and on the industry itself when it stands on slope (?). No idea what else could go wrong.

I will change this more anyway. You are right that difference of even two heights looks strange, so I'll try with just one. Or maybe a more complicated condition could be used: if there is a field or factory next to location, add it, if slope, check again behind it.

What I did not like was that when a farm is built on a hill, there is no way to get fields, and when it is near just a single slope, they are limited a lot, too. I don't know how much you consider "enough", but in pak128 I started with 10 and soon increased the maximal number to 40, otherwise it does not look very agricultural, compared to forests. I would still like more, maybe 70, radius 10 should be still enough for that. With such numbers, a hill in the middle does not matter so much.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #5
Something strange happens... fields destroy slopes under nearby things. When I rotate the map, it is fixed.

Is there a way to ask if a tile has fundament on it? I could probably ask for heights +1 and +2 but it seems too much for something so simple.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #6
Could you be more specific?

Re: [patch] Field locations

Reply #7
Well, what happens is that when I build a farm with fields, some of the fundaments nearby disappear from under the building and other things. Nearby is one or two tiles - usually it happens to the farm itself. This is fixed when rotating map.

Maybe, somehow, the tiles with slope are checked "below", while the "higher" part has things... or the check fails and it is not visible when the building is on the same height (as was before). Or it is something completely different. But I do not see how the code even avoids houses :(

Currently the code looks like this - I play with conditions in the first (long) if:

   // pick a coordinate to use - create a list of valid locations and choose a random one
   slist_tpl<grund_t *> build_locations;
   do {
      for(sint32 xoff = -radius; xoff < radius + get_besch()->get_haus()->get_groesse().x ; xoff++) {
         for(sint32 yoff =-radius ; yoff < radius + get_besch()->get_haus()->get_groesse().y; yoff++) {
            // if we can build on this tile then add it to the list
            const koord k = pos.get_2d()+koord(xoff,yoff);
            grund_t *gr = welt->lookup_kartenboden(k);
            if (gr != NULL &&
                  gr->get_typ() == grund_t::boden &&
                  gr->get_grund_hang() == hang_t::flach &&
                  abs(gr->get_hoehe() - pos.z) < 2 && // VS: allow diference of one ground level from factory
                  (get_besch()->get_haus()->get_allowed_climate_bits() & 1<<welt->get_climate(pos.z)) && // VS: only allowed climates
                  gr->ist_natur() &&
                  (gr->find<leitung_t>() || gr->kann_alle_obj_entfernen(NULL) == NULL)) {
               build_locations.append(gr);
               ****ert(gr->find<field_t>() == NULL);
            }
            // skip inside of rectange (already checked earlier)
            if(radius > 1 && yoff == -radius && (xoff > -radius && xoff < radius + get_besch()->get_haus()->get_groesse().x - 1)) {
               yoff = radius + get_besch()->get_haus()->get_groesse().y - 2;
            }
         }
      }
      if(build_locations.count() == 0) {
         radius++;
      }
   } while (radius < 10 && build_locations.count() == 0);


I would think that check for grund_t::boden should do the job as there is grund_t::fundament...

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #8
VS, your description sound more like an error in the picture calculations of the fundaments than an error in the field placement. No idea how to solve this.

Are the errors gone if you rotate the map 360 degrees (four times) ?
Parsley, sage, rosemary, and maggikraut.

Re: [patch] Field locations

Reply #9
Yes. But the error must be triggered by the fields somehow.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #10
Did someone save the patch?

Re: [patch] Field locations

Reply #11
No. IIRC it was rather trivial anyway. And it was denied (or canceled?). And there is the code just a few posts higher ;)

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Re: [patch] Field locations

Reply #12
Ok, was this working and tested. COuld you comment?

Re: [patch] Field locations

Reply #13
It is not really important to have this; it's just eye candy. Main problem with farms is that to make them look nice you need A LOT of fields and sometimes the one level restriction makes this impossible. Thus this attempt. On the other hand, empty slopes in the middle of fields don't look good, either.

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!