Resource split

Hi

How does the engine prioritise whose action was first in the below if everyone sends troops to the same node?

public void DistributeHarvestingActionSlots(IList bots)
{
// update resource nodes available units and re-distribute available slots if the node was over-allocated

        // get all the bot actions that were just received
        var newActions = bots.SelectMany(bot => bot.GetNewActions());
        var resourceActionsGroupedByNode = from action in newActions 
            where IsResourceAction(action.ActionType)
            group action by action.TargetNodeId into g
            select new { NodeId = g.Key, Actions = g.ToList() };

        foreach (var group in resourceActionsGroupedByNode)
        {
            var node = worldStateService.GetResourceNode(group.NodeId);
            var actions = group.Actions;
            DistributeNodeSpaceAmongActions(node, actions);
        }
    }

Say there is 1000 available spaces at the node, and each player (4 in total) each sends 1000 units. Once the engine sees that the node is over-allocated (i.e. there is 4000 nodes instead of 1000), it redistributes it according to each player’s number of units:

new units = (units sent / total units at node) * space available = (1000 / 4000) * 1000 = 250

Only eligible units are accounted for, so if one player decides to send 5000 units only 1000 is used in the formula above.

Thanks Kobus, I’ve been seeing this message come up so it could be the action getting rejected instead of split.

Logger.LogInfo(“ResourceNode Slot Distribution”, $“Not enough space at node id {node.Id}, removing action for bot id {action.Bot.BotId}”);

Might be an engine bug that the Entelect team needs to check.

I don’t quite understand the syntax here but it doesn’t seem like the original action is getting removed when sending troops home, just a new action getting added into the list, I could be wrong.

else
{
SendUnneededUnitsHome(action, newUnits);
action.NumberOfUnits = newUnits;
remainingValidActions.Add(action);
}

It is possible that you are trying to send more units than the node allows.

For example.
Maybe you have 100 wood left on a node.

You run a requirement check, you need 100 wood for strategy A, So you send it.
Then further down you need 50 wood for strategy B.

Now Strategy A would have emptied the node.
Strategy B would trigger:

Logger.LogInfo(“ResourceNode Slot Distribution”, $“Not enough space at node id {node.Id}, removing action for bot id {action.Bot.BotId}”);

The same can happen if you send 1 unit to a node and its full.

At least as far as I know.

1 Like