OR condition for requirement vectors (was possible with nreqs, but not any more)

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
Post Reply
User avatar
Corbeau
Elite
Posts: 1306
Joined: Mon Jan 13, 2014 11:13 pm

OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Corbeau »

The requirement vectors in one effect are connected with AND operator: they all have to be fulfilled for the effect to have effect. However, it isn't possible to combine them in a way that the effect is active if ANY of them is fulfilled. It was possible to do while the nreq field was active, but since nreq is deprecated, it isn't possible anymore.

Having the OR operator (or returning the nreqs) would simplify some things and also make possible stuff that is impossible right now. Right now, if I want to do a simple OR requirement, I have to write down a separate effect for each requirement. Also, implementing the OR (or returning nreqs) would make it possible for building and unit requirements, too, which are now limited to only one "effect".
--
* 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: 655
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Ignatus »

It was theoretically NOT possible with nreqs to make an OR-vector sich that you can't achieve an equivalent effect in reqs (provided that you don't bump into vector length limit):

!(a || b || c) <=> !a && !b && !c

If I recall it right, nreqs are innerly stored in reqs since the version when individual req negation was implemented.

For the building or unit problem, a long while ago city-performed action concept was proposed, when you can have multiple enablers for "Build Unit" or "Build Improvement" actions.
User avatar
Corbeau
Elite
Posts: 1306
Joined: Mon Jan 13, 2014 11:13 pm

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Corbeau »

Ignatus wrote: Sat Jul 20, 2024 6:33 pm It was theoretically NOT possible with nreqs to make an OR-vector sich that you can't achieve an equivalent effect in reqs
I don't understand what this sentence means.

Also, I'm not sure what exactly <=> means.

a OR b OR c

is equal to

NOT ( NOT a AND NOT b AND NOT c)
--
* 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: 655
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Ignatus »

Corbeau wrote: Sat Jul 20, 2024 6:53 pm
Ignatus wrote: Sat Jul 20, 2024 6:33 pm It was theoretically NOT possible with nreqs to make an OR-vector sich that you can't achieve an equivalent effect in reqs
I don't understand what this sentence means.

Also, I'm not sure what exactly <=> means.

a OR b OR c

is equal to

NOT ( NOT a AND NOT b AND NOT c)
I mean that you have lost actually nothing without nreqs. For example, if a building can be built if the city is on Tundra or on Forest, how can nreqs help you? <=> I mean logical equivalence, yes.
User avatar
Corbeau
Elite
Posts: 1306
Joined: Mon Jan 13, 2014 11:13 pm

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Corbeau »

Ignatus wrote: Sat Jul 20, 2024 9:50 pm I mean that you have lost actually nothing without nreqs. For example, if a building can be built if the city is on Tundra or on Forest, how can nreqs help you?

Code: Select all

nreqs = {"type", "name", "range", "present"
         "Terrain", "Tundra", "Local", FALSE
         "Terrain", "Forest", "Local", FALSE
}
Or, if there is another way to do it, please let me know.
--
* 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: 655
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Ignatus »

Corbeau wrote: Sun Jul 21, 2024 11:15 am

Code: Select all

nreqs = {"type", "name", "range", "present"
         "Terrain", "Tundra", "Local", FALSE
         "Terrain", "Forest", "Local", FALSE
}
Won't work. On Forest, the 1st nreq fires, on Tundra, the 2nd. To get ORed reqs, you need either a positive OR-vector or a negative AND-vector. nreqs is a negative OR-vector, thus it does basically the same operation as reqs. You can't fight Boolean arithmetics.
User avatar
Corbeau
Elite
Posts: 1306
Joined: Mon Jan 13, 2014 11:13 pm

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Corbeau »

Wait, you mean in reqs the relation is AND, while in nreqs the relation is OR? Reqs block is YES only of ALL conditions are satisfied, while the whole nreqs block ends up as YES (turning the whole effect into NO) if ANY condition is satisfied?
--
* 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: 655
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: OR condition for requirement vectors (was possible with nreqs, but not any more)

Post by Ignatus »

Yes. I too once wanted to make OR reqs but looked into the code and understood it won't work.
Post Reply