Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Units attacking twice #2431

Open
lmoureaux opened this issue Nov 2, 2024 · 19 comments
Open

Units attacking twice #2431

lmoureaux opened this issue Nov 2, 2024 · 19 comments
Labels
bug Something isn't working gui This issue requires changes to the user interface server This issue requires changes to the server
Milestone

Comments

@lmoureaux
Copy link
Contributor

Describe the bug
It has been reported that sometimes units attack twice without being asked. For one user attack is automatic, for another the action choice popup is shown again after attacking. This does not always happen.

Will try to investigate for v3.1 but fixing this is not critical.

To Reproduce
Steps to reproduce the behavior:

  1. Attack a city with a stack
  2. Repeat until the same unit attacks twice

Expected behavior
Units don't attack without being asked.

Platform and version (please complete the following information):

  • OS: Linux
  • Freeciv21 version: assuming 3.1-beta.1
  • Ruleset/Longturn game (if applicable): Sim06

Additional context
We have more action dialog issues: #768 #2039

@lmoureaux lmoureaux added bug Something isn't working gui This issue requires changes to the user interface labels Nov 2, 2024
@lmoureaux lmoureaux added this to the v3.1-stable milestone Nov 2, 2024
@hugomflavio
Copy link
Contributor

I'm still running the last version you asked me to test (the one with the fixed maps).

@hugomflavio
Copy link
Contributor

logged back in just to see how the server recorded the attacks over time. 0 to 2 seconds difference, it seems:

image

image

image

image

@lmoureaux
Copy link
Contributor Author

When the client gets a unit_actions packet with disturb_player set, it either performs the default action or pops up the action selection dialog depending on the settings. Need to investigate why the server thinks it should perform the same action again.

@lmoureaux lmoureaux added server This issue requires changes to the server and removed gui This issue requires changes to the user interface labels Nov 2, 2024
@lmoureaux
Copy link
Contributor Author

The server only ever sends a unit_actions packet when the client requests it by sending unit_get_actions.

@lmoureaux lmoureaux added the gui This issue requires changes to the user interface label Nov 2, 2024
@lmoureaux
Copy link
Contributor Author

...which is itself sent upon receiving a unit packet and the packet's action_decision_want is different from what the player knows about the unit (either because the unit is new or from what the client already knew). action_decision_want can be Nothing, Passive, or Active. Only Active always triggers the dialog.

@lmoureaux
Copy link
Contributor Author

The GUI is supposed to call action_decision_clear_want() whenever it no longer wants to be bugged about a unit.

@lmoureaux
Copy link
Contributor Author

I eliminated an entire civ with Combat_Rounds set to 2 (what a pain!) and couldn't see this. Maybe with occupychance...

@lmoureaux
Copy link
Contributor Author

No difference after a few attempts with occupychance

@hugomflavio
Copy link
Contributor

hugomflavio commented Nov 3, 2024 via email

@lmoureaux
Copy link
Contributor Author

Maybe a network delay is involved then... :(

@hugomflavio
Copy link
Contributor

Are you testing it on a local server? Could it have something to do with reaching the remote server and returning?

@lmoureaux
Copy link
Contributor Author

Yes... maybe I need to introduce a delay in the server response...

@hugomflavio
Copy link
Contributor

Well, there's always tomorrow's turn 😄

@lmoureaux
Copy link
Contributor Author

lmoureaux commented Nov 3, 2024

Reproduced it! With questions disabled:

  1. Add a sleep(10) in unit_versus_unit (unittools.cpp)
  2. Attack a city (the unit needs plenty of MP)
  3. While the unit is attacking, select another unit
  4. The initial unit attacks twice

@lmoureaux
Copy link
Contributor Author

It's not necessary to select another unit. Clicking on the attacker while the server is busy is enough.

@lmoureaux
Copy link
Contributor Author

The issue is that while action_decision_want is active, selecting the unit causes the client to trigger the action selection process.

@lmoureaux
Copy link
Contributor Author

There are two flags:

  • A per-unit flag (action_decision_want) that the server sets when it wants input for an action. When a unit is selected and the flag is set, the client asks the server for actions to perform. The client can also ask the server to clear the flag. This is asynchronous.
  • A global client-side flag (action_selection_in_progress_for) used by the client to prevent multiple action dialogs from popping up.

The fundamental issue is the client-side flag:

  • To prevent double attacks, it must remain set until the per-unit flag is cleared by the server. This is currently not the case.
  • When moving focus to another unit, we want to query the server immediately for the next unit's actions. This requires clearing the global flag earlier.

I think we need a second per-unit flag that the client can use to prevent duplicate requests for the same unit without constraining (or adding latency to) focus change.

@hugomflavio
Copy link
Contributor

indeed, I was able to consistently reproduce by selecting another unit before the attack actually went through.

@lmoureaux
Copy link
Contributor Author

On top of the above, managing state in the action dialog is a nightmare of static variables and functions that need to be called in a precise order from multiple places. I think a rewrite is needed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gui This issue requires changes to the user interface server This issue requires changes to the server
Projects
None yet
Development

No branches or pull requests

2 participants