Ejemplo n.º 1
0
 private void SyncGraphState(FormationDistance edge, FormationDistance edgeReciprocal, GameFormation nodeA, GameFormation nodeB)
 {
     // If neither the source -> target nor target -> source distances are in the Distances graph, create them at default starting range
     if (edge is null && edgeReciprocal is null)
     {
         edge           = this.AddEdge(nodeA, nodeB, Constants.DefaultStartingRange);
         edgeReciprocal = this.AddEdge(nodeB, nodeA, Constants.DefaultStartingRange);
     }
Ejemplo n.º 2
0
        private FormationDistance AddEdge(GameFormation nodeA, GameFormation nodeB, int edgeWeight)
        {
            var newEdge = new FormationDistance(nodeA, nodeB, edgeWeight);

            this.edges.Add(newEdge);

            return(newEdge);
        }
Ejemplo n.º 3
0
        public FormationDistance GetOrEstablishDistance(int sourceId, int targetId, int establishDistance)
        {
            // Ensure valid inputs
            GameFormation nodeA = this.GetNodeById(sourceId);
            GameFormation nodeB = this.GetNodeById(targetId);

            if (establishDistance < 0)
            {
                throw new InvalidOperationException($"Invalid starting distance {establishDistance}: Formation distances must always be nonnegative.");
            }

            FormationDistance edge           = this.GetEdge(nodeA, nodeB);
            FormationDistance edgeReciprocal = this.GetEdge(nodeB, nodeA);

            // edge-weight is equal to the edge-weight of the existing edge(s) or else the specified "establishDistance"
            var edgeWeight = edge != null ? edge.Value : edgeReciprocal != null ? edgeReciprocal.Value : establishDistance;

            // ensure both edge and its reciprocal exist
            edge           = edge ?? this.AddEdge(nodeA, nodeB, edgeWeight);
            edgeReciprocal = edgeReciprocal ?? this.AddEdge(nodeB, nodeA, edgeWeight);

            return(edge);
        }