Building requirement(s): is it possible to have a OR b?

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Building requirement(s): is it possible to have a OR b?

Post by Corbeau »

In buildings.ruleset there is a building requirement field that contains a standard requirement vector. The requirement vector can have more requirements that are in an AND relationship: they all have to be fulfilled for the vector to be positive. Is it possible to have more requirements, and that EITHER needs to be fulfilled in order to construct the building?

When it comes to Effects, it's relatively simple: simple create more effects. But buildings in building.ruleset have only one requirement field.

Any ideas?
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Building requirement(s): is it possible to have a OR b?

Post by Ignatus »

In the future, building requirements will be replaced by city-performed action enablers that may be multiple. Currently, they are not, alas. Try using negative requirements (not A and not B <=> not (A or B)). Try playing with obsoletion requirements (they ar or-ed).
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Re: Building requirement(s): is it possible to have a OR b?

Post by Corbeau »

But I guess there are no double negative requirements, right? _nreq_ is removed form 3.0, correct?

What I wanted was for a city to be able to build a Factory if there is the tech present (Industrialzation) OR if it is connected to a foreign city with a traderoute and thas city also has a Factory.

I haven't checked, but putting two vectors in the same field probably wouldn't work, right? Something like

reqs =
{ 1st set
}
{2nd set
}
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Building requirement(s): is it possible to have a OR b?

Post by Dino the Dinosore »

I have a similar problem in terrain.ruleset with adding a canal extra. I would like it to be enabled with either an oceanic OR river tile adjacent, but that does not seem possible currently. I've tried some workarounds that are not entirely satisfactory.
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Building requirement(s): is it possible to have a OR b?

Post by Dino the Dinosore »

I haven't checked, but putting two vectors in the same field probably wouldn't work, right? Something like

reqs =
{ 1st set
}
{2nd set
}
I tried that and it didn't work. Having _nreq_ and (not A and not B <=> not (A or B)) might be worth trying.
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Building requirement(s): is it possible to have a OR b?

Post by cazfi »

Dino the Dinosore wrote:I have a similar problem in terrain.ruleset with adding a canal extra. I would like it to be enabled with either an oceanic OR river tile adjacent, but that does not seem possible currently. I've tried some workarounds that are not entirely satisfactory.
Have you tried that by introducing two separate extras "Canal from Ocean" and "Canal from River" set to conflict with each other so that one does not build both to the same tile?
cazfi
Elite
Posts: 3077
Joined: Tue Jan 29, 2013 6:54 pm

Re: Building requirement(s): is it possible to have a OR b?

Post by cazfi »

There is no support for ORed requirements. To mitigate the problem, there are a couple of concepts that work in some common cases:
- There can be multiple effects doing the same thing but with different requirements
- There can be multiple action enablers enabling the same thing but with different requirements
- Many ruleset types have "user flags" that one can require instead of "object A or object B", but that helps only when you want to work within same ruleset type (you can't mix terrain and extra requirements for example).

I have vague ideas (freeciv-3.2 at earliest) about extending the last point so that e.g. terrain and extra could provide conceptually same flag, that one could then require.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Building requirement(s): is it possible to have a OR b?

Post by Ignatus »

Dino the Dinosore wrote:I tried that and it didn't work. Having _nreq_ and (not A and not B <=> not (A or B)) might be worth trying.
It never worked since nreqs were OR-ed. So are obsoleted_by; they may be negated individually.
Corbeau wrote:What I wanted was for a city to be able to build a Factory if there is the tech present (Industrialzation) OR if it is connected to a foreign city with a traderoute and thas city also has a Factory.
Currently possible kludge is adding/removing an extra with "AutoOnCityTile" flag and Lua callbacks, and require this extra (or maybe a flag of several extras). But there is a lot of callbacks to write, and I even can't be sure we have API for all the cases we need here (basically, the callbacks are action_started_unit_city, city_destroyed, building_lost, city_transferred, and turn_begin to remove possibility for factories that were enabled by trade route...).
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: Building requirement(s): is it possible to have a OR b?

Post by Ignatus »

cazfi wrote:I have vague ideas (freeciv-3.2 at earliest) about extending the last point so that e.g. terrain and extra could provide conceptually same flag, that one could then require.
We have some custom effects, maybe as a generic solution we can make a requirement like "EffectValueMin", "User_Effect_1:1", "Local"?
Dino the Dinosore
Hardened
Posts: 171
Joined: Sun Dec 31, 2017 3:41 am

Re: Building requirement(s): is it possible to have a OR b?

Post by Dino the Dinosore »

Dino the Dinosore wrote:
I have a similar problem in terrain.ruleset with adding a canal extra. I would like it to be enabled with either an oceanic OR river tile adjacent, but that does not seem possible currently. I've tried some workarounds that are not entirely satisfactory.


Have you tried that by introducing two separate extras "Canal from Ocean" and "Canal from River" set to conflict with each other so that one does not build both to the same tile?
I did try something like that. It sort of works but has 2 problems.#1 the user sees 2 different names for what is the same tile special (with the same graphics). #2 The 2 different extra names don't get their graphics connected the way they should. I set them to "integrates = " with each other, and in the file sandbox/terrain.ruleset it says -
; integrates = list of road types that are suitable next steps
; for travel from this road type; such steps are
; possible for units native to both roads and don`t
; get cost from underlying terrain; graphics are
; drawn accordingly
which implies the connected graphics should work. Maybe this is a bug?

Another thought I had is for a lua script to iterate over every tile in the world, placing a flag on lowland tiles next to an ocean or river. But there's no edit.create_tile_flag(). And a tile could get transformed.

If an extra's flags could include a terrain flag - that would do it. But they seem to be separate name spaces.
Post Reply