Why not make all units "actors" capable of "actions" via Lua script? <-- They are by v3.2 some at v3.0 & 1

Various topics about the game, the website, or anything else Freeciv related that doesn't fit elsewhere.
Post Reply
Molo_Parko
Hardened
Posts: 198
Joined: Fri Jul 02, 2021 4:00 pm

Why not make all units "actors" capable of "actions" via Lua script? <-- They are by v3.2 some at v3.0 & 1

Post by Molo_Parko »

Why not make all units "actors" capable of "actions" via Lua scripting?

In Lua scripting, a Diplomat is an actor capable of some actions* but not others such as "Fortify", or "Go to". A Settlers unit is not an "actor" despite being capable of "Build City", "Add to City" (below size 8), mining Tiles, irrigating Tiles, "Build road", etcetera, and despite that those actions can be performed by the Settler when directed to do so by a Player rather than a Lua script.

* Diplomat actions: "Establish Embassy", "Investigate City", "Poison City", "Steal Gold", "Sabotage City", "Targeted Sabotage City", "Steal Tech", "Targeted Steal Tech", "Incite City", "Establish Trade Route", "Enter Marketplace", "Help Wonder", "Bribe Unit", "Sabotage Unit".

Even a Diplomat is not capable of some "actions" via Lua scripting such as "Fortify" despite that the unit can be directed to undertake the action "Fortify" by a Player.
Last edited by Molo_Parko on Mon Dec 02, 2024 5:33 am, edited 3 times in total.
cazfi
Elite
Posts: 3258
Joined: Tue Jan 29, 2013 6:54 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by cazfi »

freeciv-2.6 was the first version with action enablers, and it started with diplomats. Later versions have been greatly extending the action enablers concept. See https://www.freeciv.org/wiki/NEWS-3.0.0, https://www.freeciv.org/wiki/NEWS-3.1.0, and https://www.freeciv.org/wiki/NEWS-3.2.0
Molo_Parko
Hardened
Posts: 198
Joined: Fri Jul 02, 2021 4:00 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by Molo_Parko »

While creating scenarios I was surprised to find that Lua scripting could not direct a unit to do what units can do from the GUI -- Settlers can't "Add to city" from Lua, although that is somewhat resolved in Freeciv 3.3 by the addition of edit.change_city_size(). Lua can't set a goto for a unit such as a Warriors, and can't have a unit Fortify, or Sentry, or Patrol despite that all those actions are possible from the GUI. It greatly limits the use of "scripted events" or "scripted scenes" in scenarios.
cazfi
Elite
Posts: 3258
Joined: Tue Jan 29, 2013 6:54 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by cazfi »

I think all actions that user can do through UI are already action enabler controlled actions in freeciv-3.1.
cazfi
Elite
Posts: 3258
Joined: Tue Jan 29, 2013 6:54 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by cazfi »

Molo_Parko wrote: Fri Nov 29, 2024 9:46 pmSettlers can't "Add to city" from Lua, although that is somewhat resolved in Freeciv 3.3 by the addition of edit.change_city_size().
"Add to City" was made an action enabler controlled action already in freeciv-3.0. No need to wait for 3.3 to "partially resolve" it.
cazfi
Elite
Posts: 3258
Joined: Tue Jan 29, 2013 6:54 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by cazfi »

Just tested the Fortify via lua. This works as expected:

Code: Select all

unit:perform_action(find.action("Fortify"))
Molo_Parko
Hardened
Posts: 198
Joined: Fri Jul 02, 2021 4:00 pm

Re: Why not make all units "actors" capable of "actions" via Lua script?

Post by Molo_Parko »

Hey that's great! I had read the various lists of "action" values at http://freeciv.fandom.com/wiki/Lua_reference_manual and actions such as "Fortify" aren't mentioned there at all, though it does refer to README.actions -- but my copies of that file are of course from Freeciv 2.6.x not 3 so I had no idea the features were already implemented in a newer version.
Post Reply