Filters for requirements

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
Ignatus
Hardened
Posts: 230
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Filters for requirements

Postby Ignatus » Thu Feb 14, 2019 8:07 pm

A step to make requirements mechanism in rulesets more flexible: for requirements that test or count several objects, make filters that are requirement vectors for the entities to take into account. For example, design "Wall Street" small wonder that can be built only with 5 banks at the player, as in CivIII:

Code: Select all

;Somewhere, e.g. in game.ruleset or effects.ruleset
[filter_bank]
name = "f_bank"
reqs =
    { "type", "name", "range"
      "Building", "Bank", "City"
    }

;buildings.ruleset
[building_wall_street]
name      = _("Wall Street")
genus      = "SmallWonder"
reqs   =
    { "type", "name", "range", "filter"
      "MinCities", 5, "Player", "f_bank" ; with no filter, number of ALL player cities would be compared to 5
    }
   
;(for CivIII compatibility, we also need an effect of treasury
; growing MAX(pplayer->economic.gold/20, 50) per turn with it)


For "World"/"Alliance"/etc. ranged requirements, the filters should filter by players; for "Player"/"Continent"/"Traderoute" ranges, by cities; for "City" ranged, by citizens/buildings/etc. by context; terrain requirements with "Local" range should iterate by extras and/or tiles, and MaxUnitsOnTile, by units. This enhancement of the mechanics should be more or less understandable for the AI (like, 'we are interested in growing our treasury; aha, effect_wall_street gives us a good bonus, we want it; then we want to build Wall Street; then we need to fulfill the requirement, but we have only 2 cities that pass the filter; aha, what we need in a city is to build there a Bank; then build banks in 5 - 2 = 3 cities')

nef
Hardened
Posts: 168
Joined: Mon Jun 25, 2018 5:01 pm

Re: Filters for requirements

Postby nef » Mon Feb 18, 2019 2:30 pm

There is a fairly simple extension to the notion of commodities (aka Output_Type) that would IMO solve most of the issues you have with Civ III and a host of others as well with current fc rulesets.

It would be dead easy to count things e.g.

Code: Select all

[effect_count_banks]
type = "Output_Add_Tile"
value = 1
reqs  =
    { "type",       "name",         "range"
      "Building",   "Bank",         "City"
      "OutputType", "Bank_Counter", "Local"
      "CityTile",   "Center",       "Local"
    }


Such commodities would be defined in game.ruleset with some additional fields:

Code: Select all

[Commodity_bank_counter]
Commodity = "Bank_counter"
Persistent =  FALSE  ;  i.e. ephemeral - not accumulating turn by turn
Box_size = 5
Roll_up = <range> ;  in this case "Player" (the parser could actually figure this out)
Under = <event_under>  ; not needed in this case
Full = <event_full>  ; in this case "Banks_5" 
amongst others.

With this approach one could get rid of a slew of special purpose commodities/counters that are current and proliferating.

Current candidates would be

    Field military "unhappiness" upkeep
    Both types of pollution. A real advantage here is that one could soften the relation between source (Shields or pop) and pollution - e.g. one might want forests to have low pollution,while coal mines are a little more - these easily done with tile effects.
    Definition of what makes citizens H/C/U/A
    Definition of what makes a city H/C/U (both of these are especially relevant to solving CMA problems)
    City Growth/famine
    Tech discovery/loss
    Forced building selloff
    Forced disbanding of unsupported units
    New feature of "Goods"
    New feature of "Culture"

Ultimately, one would want to soften the existing commodities (F/P/T - G/L/S) but that raises some issues concerning binding to current hard coded features (e.g. tax office).

The "events" - under/full etc. would also need to be defined, but these could then be directly referenced in a reqs predicate:

Code: Select all

;buildings.ruleset
[building_wall_street]
name      = _("Wall Street")
genus      = "SmallWonder"
reqs   =
    { "type",      "name",    "range"
      "Condition", "Banks_5"  "Player"
    }


In my view your point about AI (and therefore also AGH) is critical. I would be interested in your opinion as to whether this scheme would be more difficult than your filters. Aside from that I think this general approach would simplify the ruleset name space (removing many effect types), and at the same time provide a great deal more flexibility.

Ignatus
Hardened
Posts: 230
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Filters for requirements

Postby Ignatus » Mon Feb 18, 2019 8:28 pm

Yes, putting some kind of counters of national level would be great; some of them may be allowed to be traded, like CivIII strategic resources and luxuries. Especially, CivIII unit support style would be nice which depends on whole population, not home cities (currently not doable even by Lua). I have tried to draw a model of a game with unhardcoded output flows, but I am not any close to dare coding it; if only somebody finds a ready-made library and other developers support it. Something like this was suggested also here. I think, basic tile outputs should be left intact until global game rewriting; counter effects are better added above the system. If sources of the counters are rare enough (like cities and strategic resources in CivIII) and arithmetics for conditions kept simple, the performance required and AI complexity likely won't grow dramatically.