fire-eggs / CivOne

An open source implementation of Sid Meier's Civilization 1 using C# and .NET.
Creative Commons Zero v1.0 Universal
20 stars 4 forks source link

Switch unit: Waiting order do not switch to free unit inside the city #167

Closed iegik closed 2 years ago

iegik commented 2 years ago

I have a Sail and Diplomat (created in previous turn) in the city

fire-eggs commented 2 years ago

I'm seeing a similar issue.

I have several units. I press 'w' on the active unit, and it does NOT wait, it stays active.

I have to click on another available unit to activate that one.

fire-eggs commented 2 years ago

Another situation: pressed 'f' to fortify the active unit. Said unit stayed flashing with the 'F' marker. Again, had to click on another unit to switch.

fire-eggs commented 2 years ago

So far, this is a two-part problem.

Part 1. BaseUnit.Busy was modified incorrectly:

- return (Sentry || Fortify);
+return MovesLeft <= 0 || PartMoves <= 0 && (Sentry || Fortify || _order != Order.None);

needs to be:

+return MovesLeft <= 0 && PartMoves <= 0 || (Sentry || Fortify || _order != Order.None);

That is, a unit was marked busy if it had partial moves left (and thus issue #178). Also, a unit was NOT marked busy if it was Fortifying.

Part 2. Game.ActiveUnit was modified to prevent an infinite loop of looking for the next active unit. The infinite loop would have occurred because BaseUnit.Busy was incorrect [actually busy units would have been flagged as not-busy].

The removed code had the function of advancing through the units to find the NEXT not-busy unit. By removing the code, the returned unit was always the FIRST not-busy unit. The FIRST not-busy unit is usually the unit the player just ordered to wait. Thus the problems where "waiting" a unit did not switch to another unit.