Specials frequency and location

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
Post Reply
XYZ
Elite
Posts: 432
Joined: Fri Jan 31, 2014 12:00 pm

Specials frequency and location

Post 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.
Attachments
Seals, forest game and horses come with the shipped version but are dormant. You only have to "activate" them in the ruleset.
Seals, forest game and horses come with the shipped version but are dormant. You only have to "activate" them in the ruleset.
cazfi
Elite
Posts: 3105
Joined: Tue Jan 29, 2013 6:54 pm

Re: Specials frequency and location

Post 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.
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Specials frequency and location

Post 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")
Last edited by Dino the Dinosore on Sun Jan 09, 2022 4:02 am, edited 2 times in total.
XYZ
Elite
Posts: 432
Joined: Fri Jan 31, 2014 12:00 pm

Re: Specials frequency and location

Post 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.
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Specials frequency and location

Post 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.
cazfi
Elite
Posts: 3105
Joined: Tue Jan 29, 2013 6:54 pm

Re: Specials frequency and location

Post 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.
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Specials frequency and location

Post by Dino the Dinosore »

Thanks. Good point about fairness issues - I edited my code in previous post to replace the resource with another one.
Post Reply