Page 1 of 1

Script-defined game actions

Posted: Tue Jan 01, 2019 3:53 pm
by Ignatus
We could have game actions defined fully by scripts. The basic mechanism could be simple - a client sends to a server (or vice versa) a special kind of a packet that contains a name of a Lua function and arguements it should be called with. If the receiver has the function in a special table of functions callable this way, it executes it (the server prepends the parameters with player id), that for the server may mean some game state changes and sending further requests to other players, and for the client - showing some dialogs for information and further actions. A bit more complicated protocol would use a session token that contains sent datetime, expiration time (e.g. that it would not await for any response after the turn change), number of a session between these agents and number of a message in the session; if the session does not exist or the message number is greater than expected, some callback is activated to restore the session or to inform about an error.

The scripted elements may thus include unit actions (e.g. magicians turn units into toads), custom diplomatic clauses (e.g. units of battlegroup 1 of player A dispatched to continent 29 are handled to player B by lend-lease and after the end of the war with player C will be returned to A or paid for) or just arbitrary actions specified in dialogs (client Lua must contain API for building dialogs and selecting units/tiles; e.g. in a hut you find a bottle with a jinn that suggests you to destroy arbitrary city, to bring you 100 gold or to build a strong fortress anywhere guarnished with your arbitrary units). The UI elements, except dialogs, selection tools and clauses, must include customizing top-window and context menus.

This would not be too complicated to code, except that AI would not understand the whole thing. But in many net games we don't have AI players at all and use advisors limitedly. Also, Lua callbacks may call the same functions on the server instead of AI in certain conditions. And, after some work, we can insert into the AI some points to explain the meaning of Lua code (e.g. we say: "if you see a hostile unit in 3 tiles around your Magician, call maybe_turn_into_toads()!" and "when you consider a unit for an attack, your Magician should be valued as 3.5 Knights against Land units!")

Re: Script-defined game actions

Posted: Tue Jan 01, 2019 7:09 pm
by Lachu
Interesting idea.

Good idea is to consider use WML (Wesnoth Markup Language), because in subset of this language is possible to define AI behavior. I don't read whole documentation about this language, but markup language to define AI could be simpler than lua.

Re: Script-defined game actions

Posted: Tue Jan 01, 2019 10:49 pm
by Ignatus
Don't know WML, but Westnot has also Lua highly customuzeable AI. In fact, it worth studying to not reinvent the wheel, thank you for pointing the direction.