private static void ReviveObject(GridPosition position, Color color, string teamName) { lock (GridChangeLock) { GameObject ent = GetObjectAt(position); ent.transform.position = GridPositionToWorld(position); aliveGrid[position.X, position.Z] = true; if (colorGrid[position.X, position.Z].HasValue) { float a = (color.a + colorGrid[position.X, position.Z].Value.a) / 2.0f; float r = (color.r + colorGrid[position.X, position.Z].Value.r) / 2.0f; float g = (color.g + colorGrid[position.X, position.Z].Value.g) / 2.0f; float b = (color.b + colorGrid[position.X, position.Z].Value.b) / 2.0f; colorGrid[position.X, position.Z] = new Color(r, g, b, a); } else { colorGrid[position.X, position.Z] = color; } EntBehaviorManager manager = ent.GetComponent <EntBehaviorManager>(); if (StaticController.GlobalEnableColorBlend && StaticController.GlobalColorBlendDistance > 1) { manager.Reset(teamName, GetColorInRegion(position, StaticController.GlobalColorBlendDistance)); } else { manager.Reset(teamName, color); } } }
/// <summary> /// Evaluate the specified instance. /// </summary> /// <param name="instance">Instance.</param> public byte Evaluate(ref EntBehaviorManager instance) { this.EnforceOneFieldIsNonNull(); if (this.rightStatementOperation != null) { return(this.rightStatementOperation.Evaluate(ref instance)); } if (this.readOnlyVariable != null) { return(this.readOnlyVariable.Evaluate(ref instance)); } if (this.rightMethodCall != null) { return(this.rightMethodCall.Execute(ref instance)); } if (this.literalValue != null) { return(this.literalValue.Value); } throw new InvalidOperationException("Should never get here"); }
/// <summary> /// Evaluate this statement against the specified instance. /// </summary> /// <param name="instance">Instance.</param> public GeneticObject Evaluate(ref EntBehaviorManager instance) { GeneticObject leftHandObject = this.leftHandSide.Evaluate(ref instance); GeneticObject rightHandObject = this.rightHandSide.Evaluate(ref instance); return(GeneticObject.EvaluateOperator(this.operatorSignature, leftHandObject, rightHandObject)); }
/// <summary> /// Evaluate this statement against the specified instance. /// </summary> /// <param name="instance">Instance.</param> public byte Evaluate(ref EntBehaviorManager instance) { byte leftHandObject = this.leftHandSide.Evaluate(ref instance); byte rightHandObject = this.rightHandSide.Evaluate(ref instance); switch (this.operatorSignature.OperatorType) { case OperatorTypeEnum.And: return(this.EvaluateAnd(leftHandObject, rightHandObject)); case OperatorTypeEnum.Equal: return(this.EvaluateEqual(leftHandObject, rightHandObject)); case OperatorTypeEnum.Minus: return(this.EvaluateMinus(leftHandObject, rightHandObject)); case OperatorTypeEnum.NotEqual: return(this.EvaluateNotEqual(leftHandObject, rightHandObject)); case OperatorTypeEnum.Or: return(this.EvaluateOr(leftHandObject, rightHandObject)); case OperatorTypeEnum.Plus: return(this.EvaluatePlus(leftHandObject, rightHandObject)); default: throw new NotImplementedException(string.Format( "Unrecognized operator type: {0}", this.operatorSignature.OperatorType)); } }
public static bool InitializeGame() { if (!GameIsInitialized) { EntBehaviorManager.RegisterGeneticMembers(); } return(true); }
private void ForcePlaceSeedEnt() { GridPosition seedPoint = GameObjectGrid.ChooseRandomPosition(); EntBehaviorManager.TryCreateAndPlaceNewEnt( this.TeamMaterial.color, seedPoint, this.TeamName, true); }
public static bool InitializeGame() { if (!GameIsInitialized) { EntBehaviorManager.RegisterGeneticMembers(); GeneticObject.RegisterOperatorsForAllTypes(); } return(true); }
/// <summary> /// Evaluates the Condition, and if true, executes the LeftStatement. /// </summary> /// <param name="instance">The instance to execute against.</param> public bool Execute(ref EntBehaviorManager instance) { GeneticBool condition = this.condition.Evaluate(ref instance); if ((bool)condition.Value) { return(this.leftStatement.Execute(ref instance)); } return(false); }
/// <summary> /// Evaluates the Condition, and if true, executes the LeftStatement. /// </summary> /// <param name="instance">The instance to execute against.</param> public byte Execute(ref EntBehaviorManager instance) { byte condition = this.condition.Evaluate(ref instance); if (condition == 1) { return(this.leftStatement.Execute(ref instance)); } return(condition); }
/// <summary> /// Evaluates the condition. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public GeneticBool Evaluate(ref EntBehaviorManager instance) { GeneticObject evaluatedObject = this.rightStatement.Evaluate(ref instance); if (evaluatedObject is GeneticBool) { return((GeneticBool)evaluatedObject); } throw new InvalidOperationException("Condition statement did not evaluate to a GeneticBool"); }
/// <summary> /// Evaluates the parameters. /// </summary> /// <returns>The parameters.</returns> /// <param name="instance">Instance.</param> protected IList <byte> EvaluateParameters(ref EntBehaviorManager instance) { List <byte> result = new List <byte>(); foreach (RightStatement rightStatement in this.parameterList) { result.Add(rightStatement.Evaluate(ref instance)); } return(result); }
/// <summary> /// Executes the genetic logic represented by this data structure /// against the given instance. /// </summary> /// <param name="instance">The instance to execute against.</param> public bool Execute(ref EntBehaviorManager instance) { bool halt = false; foreach (RootStatement rootStatement in this.rootStatementList) { halt = rootStatement.Execute(ref instance); if (halt) { // Halts before all code is executed is expected. // Triggered by execution of LeftMethodCall. break; } } return(halt); }
internal static float GetHealthInRegion(GridPosition center, int regionSize) { int total = 0; int count = 0; for (int x = center.X - regionSize; x <= center.X + regionSize; ++x) { for (int z = center.Z - regionSize; z <= center.Z + regionSize; ++z) { // Constructor wraps around world if needed GridPosition position = new GridPosition(x, z); GameObject ent = GetObjectAt(position); EntBehaviorManager manager = ent.GetComponent <EntBehaviorManager> (); total += manager.HealthValue; ++count; } } return((float)total / (float)count); }
private static void ReviveObject(GridPosition position, Color color, string teamName) { lock (GridChangeLock) { GameObject ent = GetObjectAt(position); ent.transform.position = GridPositionToWorld(position); aliveGrid[position.X, position.Z] = true; colorGrid[position.X, position.Z] = color; EntBehaviorManager manager = ent.GetComponent <EntBehaviorManager>(); if (StaticController.GlobalEnableColorBlend && StaticController.GlobalColorBlendDistance > 1) { manager.Reset(teamName, GetColorInRegion(position, StaticController.GlobalColorBlendDistance)); } else { manager.Reset(teamName, color); } } }
/// <summary> /// Evaluates this statement. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public bool Execute(ref EntBehaviorManager instance) { if (this.leftMethodCall != null && this.assignment != null) { throw new InvalidOperationException("Only one field should be not null but both are not null."); } if (this.leftMethodCall != null) { // End of logic for the frame if successful! return(this.leftMethodCall.Execute(ref instance)); } if (this.assignment != null) { this.assignment.Execute(ref instance); return(false); } throw new InvalidOperationException("One field should be not null but they are both null."); }
public bool Execute(ref EntBehaviorManager instance) { // Enforce parsing behavior we expect. if (this.conditionalLeftStatement != null && this.leftStatement != null) { throw new InvalidOperationException("Only one field should be non null"); } if (this.conditionalLeftStatement != null) { return(this.conditionalLeftStatement.Execute(ref instance)); } else if (this.leftStatement != null) { return(this.leftStatement.Execute(ref instance)); } else { // Enforce correct parsing behavior. throw new InvalidOperationException("No field was populated during parsing and this should have been culled"); } }
/// <summary> /// Executes the assignment. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public void Execute(ref EntBehaviorManager instance) { this.readWriteVariable.WriteToVariable(ref instance, this.rightStatement); }
/// <summary> /// Executes the method. /// </summary> /// <returns>The return value of the method.</returns> /// <param name="instance">The instance to execute against.</param> public virtual byte Execute(ref EntBehaviorManager instance) { return(instance.ExecuteRightMethod(this.signature, this.EvaluateParameters(ref instance))); }
/// <summary> /// Evaluates the variable's value. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public virtual GeneticObject Evaluate(ref EntBehaviorManager instance) { return(instance.ReadFromVariable(this.signature)); }
/// <summary> /// Writes to this variable. /// </summary> /// <param name="instance">The instance to execute against.</param> /// <param name="payload">The value to write.</param> public void WriteToVariable(ref EntBehaviorManager instance, RightStatement payload) { GeneticObject value = payload.Evaluate(ref instance); instance.WriteToVariable(this.signature, value); }
/// <summary> /// Objects the is on team. /// </summary> /// <returns><c>true</c>, if is on team was objected, <c>false</c> otherwise.</returns> /// <param name="obj">Object.</param> /// <param name="teamName">Team name.</param> public static bool ObjectIsOnTeam(GameObject obj, string teamName) { EntBehaviorManager manager = obj.GetComponent <EntBehaviorManager> (); return(CommonHelperMethods.StringsAreEqual(manager.TeamName, teamName)); }
/// <summary> /// Evaluates the condition. /// </summary> /// <param name="instance">The instance to evaluate against.</param> public byte Evaluate(ref EntBehaviorManager instance) { return(this.rightStatement.Evaluate(ref instance)); }
/// <summary> /// Executes the LeftMethod. /// </summary> /// <param name="instance">The instance to execute against.</param> new public bool Execute(ref EntBehaviorManager instance) { return(instance.ExecuteLeftMethod(this.signature, this.EvaluateParameters(ref instance))); }