Commit Graph

769 Commits

Author SHA1 Message Date
RoosterDragon
0c4dff77c9 Fix moves being reported as blocked when already at the destination.
When a move is made where the source and target locations are the same and no actual moving is required, a path of length 0 is returned. When a move cannot be made as there is no valid route, a path of length 0 is also returned. This means Move is unable to tell the difference between no movement required, and no path is possible. Currently it will hit the `hadNoPath` case and report CompleteDestinationBlocked.

To fix the scenario where the source and target location match, track a alreadyAtDestination field. When this scenario triggers, report CompleteDestinationReached instead.

This fixes activities that were using this result to inform their next actions. e.g. MoveOntoAndTurn would previously cancel the Turn portion of the activity, believing that the destination could not be reached. Now, it knows the destination was reached (since we are already there!) and will perform the turn.
2024-08-19 14:33:38 +03:00
RoosterDragon
88fb83bc57 Remove caching of CurrentAdjacentCells in Cargo
In 05ed9d9a73 we stopped caching the values with ToArray to resolve a desync. But even caching the enumerable can lead to a desync, so remove the caching entirely.

----

Let's explain how the code that cached values via ToArray could desync.

Usually, the cell given by `self.Location` matches with the cell given by `self.GetTargetablePositions()`. However if the unit is moving and close to the boundary between two cells, it is possible for the targetable position to be an adjacent cell instead.

Combined with the fact hovering over the unit will evaluate `CurrentAdjacentCells` only for the local player and not everybody, the following sequence becomes possible to induce a desync:
- As the APC is moving into the last cell before unloading, the local player hovers over it. `self.Location` is the last cell, but `self.GetTargetablePositions()` gives the *previous* cell (as the unit is close to the boundary between the cells)
- The local player then caches `CurrentAdjacentCells`. The cache key of `self.Location` is the final cell, but the values are calculated for `self.GetTargetablePositions()` of an *adjacent* cell.
- When the order to unload is resolved, the cache key of `CurrentAdjacentCells` is already `self.Location` and so `CurrentAdjacentCells` is *not* updated.
- The units unload into cells based on the *adjacent* cell.

Then, for other players in the game:
- The hover does nothing for these players.
- When the order is resolved, `CurrentAdjacentCells` is out of date and is re-evaluated.
- `self.Location` and `self.GetTargetablePositions()` are both the last cell, because the unit has finished moving.
- So the cache is updated with a key of `self.Location` and values from the *same* cell.
- The units unload into cells based on the *current* cell.

As the units unload into different cells, a desync occurs. Ultimately the cause here is that cache key is insufficient - `self.Location` can have the same value but the output can differ. The function isn't a pure function so memoizing the result via `ToArray()` isn't sound.

Reverting it to cache the enumerable, which is then lazily re-evaluated reduces the scope of possible desyncs but is NOT a full solve. The cached enumerable caches the result of `Actor.GetTargetablePositions()` which isn't a fully lazy sequence. A different result is returned depending on `EnabledTargetablePositions.Any()`. Therefore, if the traits were to enable/disable inbetween, then we can still end up with different results. Memoizing the enumerable isn't sound either!

Currently our only trait is `HitShape` which is enabled based on conditions. A condition that enables/disables it based on movement would be one way to trigger this scenario. Let's say you have a unit where you toggle between two hit shapes when it is moving and when it stops moving. That would allow you to replicate the above scenario once again.

Instead of trying to come up with a sound caching mechanism in the face of a series of complex inputs, we just give up on trying to cache this information at all.
2024-08-01 22:58:15 +02:00
RoosterDragon
0649f3dc32 RCS0056 - roslynator_max_line_length = 160 2024-07-29 21:56:36 +02:00
RoosterDragon
9d5d2ab493 RCS0056 - roslynator_max_line_length = 180 2024-07-29 21:56:36 +02:00
Moritz Heller
81bcff0f8a Fix movement on ramps when moving to subcell
Fix movement on ramps when moving to subcell
2024-07-22 13:52:24 +03:00
tjk-ws
bdc142ae51 Fix a crash caused by invalid target in FlyAttack 2024-07-21 11:31:37 +02:00
Gustas
dccab8fd21 Fix PortableChrono not working 2024-07-17 20:36:57 +03:00
RoosterDragon
2ed0656d1b Introduce MoveCooldownHelper to prevent lag spikes from failed pathfinding
Several activities that queue child Move activities can get into a bad scenario where the actor is pathfinding and then gets stuck because the destination is unreachable. When the Move activity then completes, then parent activity sees it has yet to reach the destination and tries to move again. However, the actor is still blocked in the same spot as before and thus the movment finishes immediately. This causes a performance death spiral where the actor attempts to pathfind every tick. The pathfinding attempt can also be very expensive if it must exhaustively check the whole map to determine no route is possible.

In order to prevent blocked actors from running into this scenario, we introduce MoveCooldownHelper. In its default setup it allows the parent activity to bail out if the actor was blocked during a pathfinding attempt. This means the activity will be dropped rather than trying to move endlessly. It also has an option to allow retrying if pathfinding was blocked, but applies a cooldown to avoid the performance penalty. For activities such as Enter, this means the actors will still try and enter their target if it is unreachable, but will only attempt once a second now rather than every tick.

MoveAdjacentTo will now cancel if it fails to reach the destination. This fixes MoveOntoAndTurn to skip the Turn if the move didn't reach the intended destination. Any other derived classes will similarly benefit from skipping follow-up actions.
2024-07-01 15:56:11 +03:00
tjk-ws
a16542e052 Always complete FlyAttack for a zero MaximumRange to avoid stalling 2024-06-29 14:15:39 +03:00
tjk-ws
6a7159e9a1 Fix aircraft that don't rearm stalling over invalid targets 2024-06-17 11:51:19 +03:00
darkademic
b693f20789 Fix crash caused by queuing multiple pick up orders for a single unit. 2024-05-27 15:03:21 +03:00
Gustas
5fc36bd45f Make player stance colours universally respected 2024-05-04 16:31:35 +02:00
michaeldgg2
3760b14235 Land activity: fix bug which causes crash in Aircraft.AddInflunce()
Fixes #21302
2024-02-19 10:56:31 +02:00
Gustas
1a4f366e4b Make notifyAttacks more consistent 2024-02-07 15:30:41 +01:00
Gustas
8e7fa26709 Add TransformsIntoDockClient 2023-12-02 13:50:46 +01:00
dnqbob
deacc7ad65 Fix InitialActor in Carryall not initialized correctly 2023-12-02 13:56:36 +02:00
RoosterDragon
e6914f707a Introduce FirstOrDefault extensions method for Array.Find and List.Find.
This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
2023-11-19 19:28:57 +02:00
RoosterDragon
330ca92045 Fix RCS1077 2023-11-19 19:28:57 +02:00
RoosterDragon
360f24f609 Fix IDE0055
This rule no longer appears to be buggy, so enforce it. Some of the automated fixes are adjusted in order to improve the result. #pragma directives have no option to control indentation, so remove them where possible.
2023-11-16 08:45:10 +02:00
RoosterDragon
fcfee31972 Fix RCS1134 2023-10-30 23:31:33 +02:00
michaeldgg2
12fb091bbc Added callback in Passenger during unload from cargo just before the actor is added back to the world 2023-10-09 18:21:04 +03:00
Gustas
d427072cc9 Extract StoresResources from Harvester 2023-09-23 19:06:07 +02:00
Gustas
4dec79a5fb Fix Armament not working properly with value 0 in BurstDelays 2023-09-23 14:33:27 +02:00
Gustas
b25146265d Fix units considering terrain when entering other actors 2023-09-22 17:06:00 +02:00
Gustas
5cc59ae3ac Move ValidRelations from Capturable to Captures
To better match weapon definitions
2023-09-09 13:24:33 +02:00
RoosterDragon
23f3f8d90c Add helper methods to locate actors that can be reached via a path.
Previously, the ClosestTo and PositionClosestTo existed to perform a simple distance based check to choose the closest location from a choice of locations to a single other location. For some functions this is sufficient, but for many functions we want to then move between the locations. If the location selected is in fact unreachable (e.g. on another island) then we would not want to consider it.

We now introduce ClosestToIgnoringPath for checks where we don't care about a path existing, e.g. weapons hitting nearby targets. When we do care about paths, we introduce ClosestToWithPathFrom and ClosestToWithPathTo which will check that a path exists. The PathFrom check will make sure one of the actors from the list can make it to the single target location. The PathTo check will make sure the single actor can make it to one of the target locations. This difference allows us to specify which actor will be doing the moving. This is important as a path might exists for one actor, but not another. Consider two islands with a hovercraft on one and a tank on the other. The hovercraft can path to the tank, but the tank cannot path to the hovercraft.

We also introduce WithPathFrom and WithPathTo. These will perform filtering by checking for valid paths, but won't select the closest location.

By employing the new methods that filter for paths, we fix various behaviour that would cause actors to get confused. Imagine an islands map, by checking for paths we ensure logic will locate reachable locations on the island, rather than considering a location on a nearby island that is physically closer but unreachable. This fixes AI squad automation, and other automated behaviours such as rearming.
2023-09-07 17:46:35 +03:00
RoosterDragon
93a97d5d6f Fix CA1851, assume_method_enumerates_parameters = true 2023-08-20 20:41:27 +02:00
RoosterDragon
3275875ae5 Fix CA1851 2023-08-20 20:41:27 +02:00
Matthias Mailänder
1899eed839 Add localisation support to transient lines. 2023-08-19 20:46:04 +03:00
Matthias Mailänder
98896f9a75 Make Cargo and Carryall conditional. 2023-08-13 18:38:17 +03:00
Gustas
3ab421cbe3 Allow queueing up scatter and move Nudge to an activity 2023-08-08 16:10:53 +02:00
Gustas
82458b5f7e Add INotifyClientMoving interface 2023-08-08 14:48:59 +02:00
Gustas
d0974cfdd2 Abstract docking logic from Harvester and Refinery 2023-08-08 14:48:59 +02:00
Gustas
da16e4ed99 Rename docking activities
HarvesterDockSequence -> GenericDockSequence
DeliverResources -> MoveToDock
2023-08-08 14:48:59 +02:00
Gustas
d686634c0b Fix aircraft jittering 2023-08-05 13:27:32 +02:00
Vapre
1ce916182d RingBuffer primitive. 2023-08-02 19:42:31 +03:00
dnqbob
2ac85ac61d Add InstantlyRepairsProperties 2023-08-01 12:21:19 +02:00
dnqbob
44e024a94e Make InstantRepair public 2023-08-01 12:21:19 +02:00
Gustas
723ffdf33d Revert Hunt to move within 2 cells of the target
Otherwise infantry get stuck within weapon range but outside of vision range
2023-07-30 20:26:41 +02:00
dnqbob
a3c5945f2a Set BackwardDuration to -1 means ignore the time and set MaxBackwardCells to -1 means ignore the distance. 2023-07-29 18:01:40 +03:00
dnqbob
d7ef22d64f Add MaxBackwardCells for moving backward control 2023-07-29 18:01:40 +03:00
michaeldgg2
74f8db0578 LayMines: render minefield cells only if the planned minefield has more than 1 cell 2023-07-28 12:55:06 +03:00
Gustas
c093e7c90b Fix hunt incorrectly pathing to uncrushable targets 2023-07-27 16:14:29 +03:00
michaeldgg2
66cf912da0 LayMines: fixed occasional incorrect mine position when using BeginMinefield order
When laying mine with PreLayDelay > 0, end activity's tick immediately. That means don't try to immediately move to next cell.

This change unifies the behavior with scenario when a mine is laid without any PreLayDelay.
2023-07-26 22:05:42 +03:00
Gustas
3207d01cf2 Consider AutoTarget ScanRadius when attack moving 2023-07-25 19:48:57 +02:00
Gustas
c7e0bc4c08 Add missing carryall checks 2023-07-25 10:02:46 +03:00
Gustas
a69417f0a6 Fix caryall not removing influence when cargo dies 2023-07-25 10:02:46 +03:00
Gustas
1edf313090 Don't calculate range when it is unused 2023-07-25 10:02:46 +03:00
michaeldgg2
ce6e73dc92 Minelayer: supports specifying both mine laying and post laying delays 2023-07-17 20:18:52 +02:00
Gustas
659ec5e335 Make phase transport uncloak on loading cargo 2023-07-14 17:25:30 +02:00