Ticket #44779

Lua: support for requirement vectors

Open Date: 2022-06-08 17:46 Last Update: 2022-07-09 19:30

Reporter:
Owner:
(None)
Status:
Open
Component:
MileStone:
Priority:
5 - Medium
Severity:
5 - Medium
Resolution:
None
File:
None

Details

Make a class to get requirement vector properties of unit types etc., as well as create them dynamically for in-script use.

That probably requires creating Lua object type that resides within Lua memory (see comment in the code about destructors in C projects, it's probably still actual). Like this:

struct req_vec_obj {
struct requirement_vector* reqs; bool is_external; // Memory managed by C, editing not allowed bool operation_or; // For obsoleted_by
} #define Req_Vec struct req_vec_obj

We provide methods (Req_Vec):test(elements), (Req_Vec):iterate(), and for editable vectors :insert(pos, {elements}) and :delete(pos). Also, we make module requirements with method .new_vec{table} and .test(req_type, req_range, {elements}, survives?), better with a shortcut to just requirements[ req_type ](...) (e.g., requirements.MaxUnitsOnTile("Local", find.tile(3,14))). "Elements" may be a table with named fields like {city = "Leningrad"} or just a sequence where field is detected by element type (find.city(nil, "Leningrad")). The vector table may look most alike what we have in specfiles {"type", "name", "range"}, {"DiplRel", "IsForeign", "Local"}} or consist of tables with named arguments {{type = "DiplRel", name = "IsForeign", range = "Local ", }}.

Ticket History (3/4 Histories)

2022-06-08 17:46 Updated by: ihnatus
  • New Ticket "Lua: support for requirement vectors" created
2022-06-08 17:58 Updated by: ihnatus
  • Milestone Update from (None) to S3_2 d3f
  • Component Update from (None) to Scripting API
  • Details Updated
2022-07-09 08:00 Updated by: cazfi
Comment

My main concern is that the design is such that things remain stable from version to version, as deprecating anything from the lua script is next to impossible. So having internal structures exposed to lua scripts may mean that we can't change those internals.

2022-07-09 19:30 Updated by: ihnatus
Comment

Reply To cazfi

My main concern is that the design is such that things remain stable from version to version, as deprecating anything from the lua script is next to impossible. So having internal structures exposed to lua scripts may mean that we can't change those internals.

Requirements are not that internal as we set them from rulesets. Requirement factors are well quite backstage but are so firmly tied to the requirements that deprecating existing ones is also very unlikely, only new ones may sometimes arrive, the design I think about is likely more or less resistable to it.

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login