Topic: suggestions for scripting api
aDiscoverer Topic Opener |
Posted at: 2023-06-22, 17:53
Some suggestions to make scripting simpler of more powerful. check if map object is removedHow can I check if a mapobject (building, soldier, ...) still exists? Using any attribute after it disappeared raises an error "ConstructionSite no longer exists!". I propose aMapObject:exists() or aMapObject.exists my workaround for immovables is using the (main) field:
allow evicting a worker from by scriptI propose to add ps:evict(worker_xx) to productionsite. I am unsure how to identify the workers, probably as bob. The function would return false when it failed (because of a worker not belonging to the building or ...) Use case: I try to write a script assisting the ai player with poor hamlet. A worker needs to change between lumber jack and wood hardener. add possibility to detect human players in multiplayer gameHow can I find out if a player is human-controlled in a multiplayer game? I can easily find out which player is the human of this game instance (with wl.Game().interactive_player). But not the players playing on the other computers. The best I found is checking if player.name is Computer %d with %d being the player number. There are several drawbacks. (1) A human could enter his name like this. (2) The name is translated by the host. When the netclient runs with a different language, it will likely not match. note to case (1): The button to join is disabled when the human chooses a name with a space in it. But with a double click on the game, joining continues anyway. (Bug, using widelands 1.1) If the map is chosen before, the name is occupied by the (potential) ai player and the human gets 1 attached to his name. If the map is not yet selected or changed (to one with more players), the human has his name already. In case both players end up in the game and should have the same name, the computer gets a different number. (one higher/lower). allow win conditions to have a config dialogueShow a button for those win conditions which allow a config dialogue. see more details in forum post ..92 allow to adapt the build costs of workersthe-x-mod adapts build costs of buildings. Adapting costs for workers and soldiers could be interesting as well.
allow to add an additional ai player to any mapTo make artifacts which are defended. more details in forum post ..93 include(xxx) returns the scripts return valueI found out normal lua supports require(xxx) which returns the return value of the script and only includes the script if it is not yet imported. The return value would make reusing of start conditions simpler. ( forum post ..93) Thank you for the game. Looks like I like it Edited: 2023-06-23, 14:20
Top Quote |
Nordfriese |
Posted at: 2023-07-01, 19:47
These are some good suggestions, I opened a PR to add for v1.2:
Sadly not possible – from a client's perspective there is no way to tell whether any given player is controlled by AI or humans. Only the host has that information. But control of a player can even be shared across multiple players and potentially an AI as well.
For this to work, the win condition would have to specify what kind of parameters it has and how they should be represented (data type, widget type, min/max/initial values), and the UI would have to present all that to the user… that's doable but would be pretty involved to implement.
Unfortunately that's not doable at all
That's not actually that hard but would require some tricky fiddling with the lua_State API. That could be a Good First Issue for anyone who wants to delve deeper into the C++/Lua interfacing logic. Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-07-03, 18:14
Great, thank you very much indeed!
Sad. Some more details later in a separate answer.
My suggestions in the forum post #..92 was to support integers only. I agree to max, min and initial. I see no need for any other data types and widget type. (It might pop up later of course for ideas I can not imagine.)
To support this for multiplayer as well, it would even have to be transferred to the netclients. It could be for single player only.
I can imagine this is totally against the way widelands works. I forget it.
Good first issue but tricky fiddling? Sounds a bit too challenging. I probably stay with scripting -\(")/- Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-07-05, 15:08
With pr 5933 - Lua UI api extension maybe the win condition just needs to declare a function like Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-07-06, 00:44
Some more details I understand that multiple humans can control a player. And with Short wish: could Longer, why I wish it: Imagine I want to disable some buildings for all AI players by script (until they have built something specific). Detecting the ai players is no problem for single player as I can identify the human player by The nethost knows what players are not human controlled. But this is only published to lua by player name (on nethost and netclient). The name of a user might interfer. (About problems of its localisation #5991) Could something more helpful be available to lua like I am aware that this information does not exclude that additionally a human controls this player. But only in edge cases, which I do not care about. I am aware that a player controlled by a human will be controlled by an AI after the connection to the human player is lost. I ignore this. Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-07-08, 00:45
Ah, now I undestand your statement. src/ai/defaultai.h writes that only the host runs the ai code and sends the player commands to the clients. So Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-10-11, 10:43
https://www.widelands.org/documentation/autogen_wl_map/#wl.map.MapObject.exists It was introduced in commit 10b692a0 as announced in a post above Edited: 2023-10-11, 10:46
Top Quote |
aDiscoverer Topic Opener |
Posted at: 2023-10-11, 11:28
Status, there is a pull request for Top Quote |