Skip to content

Commit

Permalink
2022.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
JeniquePeters committed Aug 20, 2022
1 parent da519fb commit 55e88df
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
25 changes: 21 additions & 4 deletions game-engine/Domain/Models/BotObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public string GetBotMapState()
public void AddAction(PlayerAction playerAction)
{
AvailableUnits -= playerAction.NumberOfUnits;
PendingActions.Add(playerAction);
lock (PendingActions)
{
PendingActions.Add(playerAction);
}
}

public List<PlayerAction> GetActions()
Expand All @@ -124,15 +127,21 @@ public List<PlayerAction> GetNewActions()
{
newActions = PendingActions.ToList();
PendingActions.Clear();
Actions.AddRange(newActions);
lock (Actions)
{
Actions.AddRange(newActions);
}
}
return newActions;
}

public void RemoveAction(PlayerAction playerAction)
{
AvailableUnits += playerAction.NumberOfUnits;
Actions.Remove(playerAction);
lock (Actions)
{
Actions.Remove(playerAction);
}
}

public BotDto ToStateObject(GameState gameState) => new BotDto
Expand All @@ -150,13 +159,21 @@ public void RemoveAction(PlayerAction playerAction)
Stone = Stone,
Gold = Gold,
Heat = Heat,
PendingActions = PendingActions.Select(action => action.ToStateObject()).ToList(),
PendingActions = GetPendingActions(),
Actions = Actions.Select(action => action.ToStateObject()).ToList(),
Territory = Territory.LandInTerritory.ToList(),
StatusMultiplier = StatusMultiplier,
Buildings = Buildings
};

private List<PlayerActionDto> GetPendingActions()
{
lock (PendingActions)
{
return PendingActions.Select(action => action.ToStateObject()).ToList();
}
}

public void UpdateTerritory(Territory territory)
{
//TODO: Use this method
Expand Down
2 changes: 1 addition & 1 deletion game-engine/Engine/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - deploy

variables:
ENGINE_VERSION: 2022.3.7
ENGINE_VERSION: 2022.3.8
# DOCKER_REGISTRY: NOT_SET
# REGION: $AWS_DEFAULT_REGION

Expand Down
4 changes: 3 additions & 1 deletion game-engine/Engine/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void DistributeNodeSpaceAmongActions(ResourceNode node, List<PlayerAction
distributionFactor = availableSpace / totalUnits
This minimizes some computation
*/
var remainingValidActions = new List<PlayerAction>();
var distributionFactor = (double) availableSpace / totalUnitsToAdd;
foreach (var action in actions)
{
Expand All @@ -264,10 +265,11 @@ public void DistributeNodeSpaceAmongActions(ResourceNode node, List<PlayerAction
{
SendUnneededUnitsHome(action, newUnits);
action.NumberOfUnits = newUnits;
remainingValidActions.Add(action);
}

}
var adjustedTotalUnits = actions.Sum(action => action.NumberOfUnits);
var adjustedTotalUnits = remainingValidActions.Sum(action => action.NumberOfUnits);
node.CurrentUnits += adjustedTotalUnits;
}
else
Expand Down
14 changes: 10 additions & 4 deletions game-engine/Engine/Services/TerritoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Domain.Models;
using Domain.Services;
using Engine.Interfaces;

namespace Engine.Services;
Expand Down Expand Up @@ -91,7 +92,7 @@ public void AddBuilding(BotObject bot, BuildingObject building)
var buildingNode = worldStateService.NodeByPosition(building.Position);
if (buildingNode.GetType() != typeof(AvailableNode)) return;
if (((AvailableNode) buildingNode).IsUsed()) return;
if (!bot.Territory.Contains(building.Position)) return;
if (building.Type != BuildingType.Base && !bot.Territory.Contains(building.Position)) return;

bot.Buildings.Add(building);
RemoveAvailableNodeWhereBuildingIsPlaced(bot, (AvailableNode)buildingNode);
Expand Down Expand Up @@ -121,19 +122,24 @@ private bool PositionIsClaimable(Position position)
return !(claimedTerritory.Contains(position) || worldStateService.ScoutTowerPositionsInUse.Contains(position));
}

private Land CreateNewLand(BotObject bot, Position position)
private void CreateNewLand(BotObject bot, Position position)
{
var containedNode = worldStateService.NodeByPosition(position);
var land = new Land(position, bot.BotId, containedNode.Id);

if (containedNode == null)
{
Logger.LogInfo("CreateNewLand", $"Contained Node is null when trying to add land at position X:{position.X} Y:{position.Y}");
return;
}

LandByPosition[containedNode.Position] = land;
LandByNodeId[containedNode.Id] = land;
AddOccupantsToLand(land, bot, 0);

bot.Territory.AddLand(land);
worldStateService.GetScoutTowerByRegion(land).AddTerritoryNode(land);
claimedTerritory.Add(land);

return land;
}

private List<AvailableNode> CreateAvailableNodes(BotObject bot, List<Position> territoryPositions)
Expand Down
2 changes: 1 addition & 1 deletion game-engine/GameRunner/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - deploy

variables:
RUNNER_VERSION: 2022.3.7
RUNNER_VERSION: 2022.3.8
# DOCKER_REGISTRY: NOT_SET
# REGION: $AWS_DEFAULT_REGION

Expand Down
2 changes: 1 addition & 1 deletion game-engine/Logger/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - deploy

variables:
LOGGER_VERSION: 2022.3.7
LOGGER_VERSION: 2022.3.8
# DOCKER_REGISTRY: NOT_SET
# REGION: $AWS_DEFAULT_REGION

Expand Down

0 comments on commit 55e88df

Please sign in to comment.