'User Action 1' not working

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

leo.priori wrote: Tue Jan 02, 2024 4:14 am but of course this is not the correct way:

Code: Select all

/lua cmd find.unit("Marshall"):perform_action("User Action 1") 
I meant, use chat window to test if the action works at all even if not shown in the interface. Place a marshall next to a city, record ids of the marshall unit (say, 1234) and the city (say, 1357) and type in the chat

Code: Select all

/lua cmd find.unit(nil, 1234):perform_action(find.action("User Action 1"), find.city(nil, 1357)) 
Likely, you can find out the ids by midclick, or in edit mode.
leo.priori
Posts: 15
Joined: Mon Jan 01, 2024 3:22 am

Re: 'User Action 1' not working

Post by leo.priori »

cazfi wrote: Tue Jan 02, 2024 9:42 am With both min and max range 1, the action works only when the unit is adjacent to the city, not when inside the city (including when entering the city tile)
Just like a explorer, a diplomatic, a caravan or others when they are adjacent to a city and will enter to the center. The message pops up with the options (Establish Trade Route or Investigate city, etc).
Thats exactly what i want. I want the action 'User Action 1' in this list.
Ignatus wrote: Tue Jan 02, 2024 10:32 am Likely, you can find out the ids by midclick, or in edit mode.
Dear Lord i will take at least a decade to find out this command.
But i am not so lucky.
Im using 3.1 beta4 Qt-client and my midclick not showing the id. :cry: :cry: :cry:
The X,Y helps?
I could try to show the id using script.lua. Something like this inside the function action_mashall

Code: Select all

function action_marshall(action, actor, target)
   local id_unit = actor.getId()
   local id_city = target.getId()
   local msg = string.format("Unit: %d  City: %d", id_unit, id_city) 
   notify.event_msg(nil,nil,2,msg)
end
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

leo.priori wrote: Tue Jan 02, 2024 12:03 pm

Code: Select all

   local id_unit = actor.getId()
That's from some other API, ours has actor.id
And that won't work if you need ids before you run the action. Likely, you can get ids with something like (sorry, didn't test )

Code: Select all

for p in players_iterate() do
  notify.all("%s's units:", p.name)
  for u in p:units_iterate() do
    notify.all("  %4d %s\t%d,%d", u.id, u.utype:rule_name(), u.tile.x, u.tile.y)
  end
  notify.all("%s's cities:", p.name)
  for c in p:cities_iterate() do
    notify.all("  %4d %s\t%d,%d", c.id, c.name, c.tile.x, c.tile.y)
  end
end
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

cazfi wrote: Tue Jan 02, 2024 12:32 am Maybe a building that is not otherwise buildable. That would better show up in the city dialog.
Yes. Like, we could put a requirement

Code: Select all

{"type", "name", "range", "present"
"None", "", "Local", FALSE}
into "Reduced Crime" building reqs and still place the building with

Code: Select all

target:create_building(find.building"Reduced Crime")
?
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

leo.priori wrote: Tue Jan 02, 2024 12:03 pm
cazfi wrote: Tue Jan 02, 2024 9:42 am With both min and max range 1, the action works only when the unit is adjacent to the city, not when inside the city (including when entering the city tile)
Just like a explorer, a diplomatic, a caravan or others when they are adjacent to a city and will enter to the center. The message pops up with the options (Establish Trade Route or Investigate city, etc).
Thats exactly what i want. I want the action 'User Action 1' in this list.
Try setting min range to zero, so the action is legal in the very city tile too.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

cazfi wrote: Tue Jan 02, 2024 12:32 amMaybe a building that is not otherwise buildable.
Except that current ruleset format does not support that. Opened a ticket: RM #116
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

leo.priori wrote: Mon Jan 01, 2024 4:05 am

Code: Select all

[effect_reduce_crime]
type    = "Output_Waste_Pct"
value   = -50
README.effects documents Output_Waste_Pct as:
Output_Waste_Pct
Reduce waste by amount percent.
So I think you mean "50", not "-50"
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

Ok, I got this example for you working.

1) It's for classic ruleset, and for corruption (trade waste) as shield waste does not exist in that ruleset
2) I skipped the unit creation part. Instead diplomats can be used to do the "Found Marshall's Office" action
3) "Marshall's Office" is a tile extra, and in this example it uses Ruins graphics. You likely want to change also your tileset to have an "invisible" extra gfx
Attachments
marshalls_office.patch
(3.21 KiB) Downloaded 3788 times
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

cazfi wrote: Tue Jan 02, 2024 11:21 pmit uses Ruins graphics. You likely want to change also your tileset to have an "invisible" extra gfx
Well, in 3.1 you can as well use negative visibility_req, but I'm afraid it will make some data in client irrelevant, so better yes, get opaque sprite. Maybe we can ever allow spriteless extras?
cazfi wrote: Tue Jan 02, 2024 10:41 pm
cazfi wrote: Tue Jan 02, 2024 12:32 amMaybe a building that is not otherwise buildable.
Except that current ruleset format does not support that. Opened a ticket: RM #116
What about a building with always negative reqs, see my post above☝️? It seems to me Lua does not look at the reqs when you place a building (and maybe it should not since buildings with unsatisfied reqs are generally permitted to exist).
leo.priori
Posts: 15
Joined: Mon Jan 01, 2024 3:22 am

Re: 'User Action 1' not working

Post by leo.priori »

Hello guys!

I did your patch cazfi and still not showing. Can you believe?
I think I understand what this aproach does, and I LOVED it.
Didnt know about this extra class terrain and this 'virtual' building.
Very interesting and it brings me some extra ideas for other posts.
But this effects is taking place each turn after the action, forever and ever, right?

This is what i did, step by step (I'm using Xubuntu 23.10)

1) Deleted the hidden folder '.freeciv' from my home
2) Opened the game (just to create the folder and other stuffs from zero)
3) Created a folder '3.1' inside '.freeciv'
4) Copied the entire classic ruleset from freeciv installed folder '/freeciv/share/freeciv/classic.serv' to '3.1' folder
5) Renamed to classic2, applied all the changes very carefully.
6) Played a few rounds just to make some corruption in a city far away. (dont know if really needs because of lack of Shields like you said)
6) Created and moved a diplomat to that city, but no 'Found Marshall Office' option appeared, only the regular ones (Disband, Wait, etc)

And I know that is not here with my computer.
This is the reason that i created my first post here in the forum in the first place.
After released of beta4, I thought I could make 'User Action 1' to work. So I...

1) Format my desktop and installed Xubunt 23.10
2) Compiled 3.1 beta4 with QT client
3) Crossed my fingers
4) After a few tests, I threw my computer out the window
5) Got divorced
6) Send the lawyer's bill to cazfi and Ignatus's address
7) Got regretted. Assaulted the post office just to take the bills back
8) Made my first post

Maybe my final go could not be possible at the moment, even if this User Action works
Beacuse some effects will take place in that turn,
and other effects will take place in the following turns ahead, but stop after a few turns

Look what i have in mind!

Taking the Marshall example:

1) Create a unit Unique. (flag "Unique")
3) When reach the city far away, open the dialog box automatically. Just like others.
4) Choose the action 'Reduce crime' and disappear. Just like Caravan (In this case i have to set user_action_1_actor_consuming_always = TRUE)

The problem is that The effects must take place in that turn, not forever.
Just like Disband with Recover or Industrial Sabotage or other similars.
It means that if I open the dialog box city after the unit disappeared
I will see the number of corruption lower than before (Ex: -50%)
And after hit 'Turn Done' and open the city again, I will see the corruption back to normal (high levels), just like before the action.

Could this effects be possible? Using just ruleset and LUA?

Look other ideas that i have in mind:

A) Unit Clown or Artist (same performace as Marshall)
flag "Unique"
Action: Make citizens content
Disband after action
Effect: Make citizens happy just one turn (back to normal unhappiness in the following turn)

B) Unit Cleaners (The effect is different)
flag "Unique"
Action: Clean pollution
Disband after action
Effect: Pollution will reduce immediately, but it will come back to normal in a few turns, maybe 2 or 3 dont know yet

C) Unit TaxMen (3 effects)
flag "Unique"
Action: Collect extra money
Disband after action
Effect 1: Substract a % of the city gold. but it will come back after the following turn
Effect 2: Make some crazy multiply math about this amount and apply to the player
Effect 3: Make some citizens unhappy, but come back to normal in 2 or 3 turns.

D) Unit Hackers (the actions is similar to Spy, but needs to be inside a friendly city)
Can create ONE PER CITY
Action: 'Investigate city', 'Disable Production', 'Steal Tech' and defend against attack of the same type.
Can promote
Effect: Same as others effects with these actions (Investigate, Disable production etc)
IMPORTANT: Must be in a friendly city and with a specific building (Ex: Server Center) and the target needs this building too.

E) Unit Doctors (Maybe this one is easy to work, but didnt test yet)
Can create many
Action: Heal Unit in range
Can promote
Effect: Heal unit immediately (And gain experience with that)

F) Unit Cannon Operators (I think this one is easy too)
Can create many
Action: Bombard in big range, but this unit has to be inside the city and the city needs specific building (Ex: City Walls or Coastal Defense)
Can promote
Effect: Bombard in range and possibly KILL the enemy. And gain experience too.

G) Unit Constructors (Probably easy too)
flag "Unique"
Action: Help to build Buildings, not units or wonders.
Disband after action
Effect: Same as 'Disband with Recover', but only effects in buildings production

Using LUA to mark a tile every time a unit or a city is lost, i could make this special one:
H) Unit Archaeologist (inspired from civ6)
flag "Unique"
Action: Look for Artifacts in range
Disband after action
Effect: Gold (Collect Ransom) and Culture (History) depending how much artifacts in range was founded. (And remove the mark of tile in LUA)

Good ideas isnt it?
But i got stuck in level 0, no User Acion 1 for me. Maybe the Marshall didnt got his payment!
Post Reply