Page 1 of 1

Specials frequency and location

Posted: Thu Jan 06, 2022 11:28 am
by XYZ
It would be nice to be able to modify how often and where a special appears. As of now, as far as I'm concerned, every special just spawns randomly anywhere on the defined terrain in more or less equal numbers.
My intention is to introduce certain specials that are rarer like uranium or that only appear if the tile is adjacent to water for seals for example.

Re: Specials frequency and location

Posted: Thu Jan 06, 2022 12:34 pm
by cazfi
Yes, improving support for that is something to look at.

I don't know if anyone has actually tested it, but there's been talk about a trick you might be able to do with current version: list same resource multiple times for the same terrain. That doesn't affect the overall amount of the resources, but their relative frequency.

Re: Specials frequency and location

Posted: Thu Jan 06, 2022 12:59 pm
by cazfi

Re: Specials frequency and location

Posted: Fri Jan 07, 2022 6:01 am
by Dino the Dinosore
Can restrict seals to tiles adjacent to water by using lua script. Should also do Ivory.

Code: Select all

function coast_only(tile, resource, replace_resource)
  isOK = false
  for t in tile:square_iterate(1) do
    class = t.terrain:class_name()
    if class == "Oceanic" then
      isOK = true
      break;
    end
  end -- for tile:square_iterate
  if not isOK then
    tile:remove_extra(resource)
    tile:create_extra(replace_resource)
  end
end

function coasts_only_callback()
  for tile in whole_map_iterate() do
    local resource = "Ivory"
    if tile:has_extra(resource) then
      coast_only(tile, resource, "Furs")
    end
    resource = "Seals"
    if tile:has_extra(resource) then
      coast_only(tile, resource, "Oil")
    end
  end -- for whole_map_iterate
  return false
end

signal.connect("map_generated", "coasts_only_callback")

Re: Specials frequency and location

Posted: Fri Jan 07, 2022 9:48 pm
by XYZ
cazfi wrote:Yes, improving support for that is something to look at.

I don't know if anyone has actually tested it, but there's been talk about a trick you might be able to do with current version: list same resource multiple times for the same terrain. That doesn't affect the overall amount of the resources, but their relative frequency.
Tested it and you are right!

resources = "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Buffalo", "Horses"

Counted on a map 39 buffalos and 3 horses so almost a perfect 10:1 ratio.

Re: Specials frequency and location

Posted: Sat Jan 08, 2022 4:29 am
by Dino the Dinosore
I spoke too soon about my code testing OK - seeing some weird things. And just noticed in the chat log a bunch of assert failures -
in dbv_isset() [../../freeciv-3.0.0/utility/bitvector.c::122]: assertion 'pdbv->vec != ((void*)0)' failed.
Please report this message at https://osdn.net/projects/freeciv/ticket/
Guess I should file a ticket. edit.remove_extra(tile, resource) seems to trigger it.

Re: Specials frequency and location

Posted: Sat Jan 08, 2022 5:52 am
by cazfi
Dino the Dinosore wrote:I spoke too soon about my code testing OK - seeing some weird things. And just noticed in the chat log a bunch of assert failures -
in dbv_isset() [../../freeciv-3.0.0/utility/bitvector.c::122]: assertion 'pdbv->vec != ((void*)0)' failed.
Please report this message at https://osdn.net/projects/freeciv/ticket/
Guess I should file a ticket. edit.remove_extra(tile, resource) seems to trigger it.
Thanks. Should be fixed in 3.0.0. Meanwhile, if it bothers you, you may try to do the resource removal in the beginning of the first turn (the problem was that things are not properly initialized at the time 'map_generated' signal gets emitted).

This script might cause fairness issues. Player start positions have already been assigned with the assumption that those resources are there.

Re: Specials frequency and location

Posted: Sun Jan 09, 2022 4:04 am
by Dino the Dinosore
Thanks. Good point about fairness issues - I edited my code in previous post to replace the resource with another one.