// Main generation loop public void UniverseCreation() { int _current_year = 0; int _end_year = 10000; int action_queue_count, counter; IActionTaker current_myth_object; CreationMythState.CreationString = createCreationString(); // Generate the creation tree from the grammar rules. generateCreationTree(); // Begin with the first primordial force CreationMythState.PrimordialForces.Add(new PrimordialForce() { Name = "Chaos", Creator = null }); CreationMythState.ActionableMythObjects.Enqueue(CreationMythState.PrimordialForces[0]); CreationMythState.MythObjects.Add(CreationMythState.PrimordialForces[0]); CreationMythState.CreationTree.TreeRoot.Children.First.Value.Value.MythObject = CreationMythState.PrimordialForces[0]; CreationMythState.CreationTree.traverseTree(PrintCreationTree); // each tick is one year. Each myth object that can take actions can take one action per year at most. while (_current_year < _end_year) { // LOg the current year CreationMythLogger.UpdateLog(_current_year); // go through action queue once. counter = 0; action_queue_count = CreationMythState.ActionableMythObjects.Count; while (counter < action_queue_count) { current_myth_object = CreationMythState.ActionableMythObjects.Dequeue(); current_myth_object.takeAction(_current_year); CreationMythLogger.UpdateLog((BaseMythObject)current_myth_object, "UPDATE"); CreationMythState.ActionableMythObjects.Enqueue(current_myth_object); counter = counter + 1; } //CreationMythLogger.Write(); _current_year += 1; } CreationMythLogger.UpdateLog("END OF CREATION"); CreationMythLogger.Write(); CreationMythLogger.Clear(); // Update the user interface data class. _user.Update(); // END OF CREATION }
public override void takeAction(int current_year) { if (CurrentGoal == ActionGoal.None) { determineNextGoal(); } if (CurrentAction.getDuration() <= 0) { CreationMythLogger.UpdateActionLog(this); CurrentAction.resetDuration(); determineNextAction(); } else { CurrentAction.reduceDuration(); } }
public override void Effect(ActionTakerMythObject taker) { if (taker.CurrentGoal == ActionGoal.CreatePlane) { CreationMythState.MythObjects.Add(taker.CreatedPlane); CreationMythState.Planes.Add(taker.CreatedPlane); CreationMythState.CreationTree.TreeRoot.traverseTree(addPlaneToCreationTree, new CreationTreeNode(taker)); } else if (taker.CurrentGoal == ActionGoal.CreateDeity) { CreationMythState.ActionableMythObjects.Enqueue(taker.CreadedDeity); CreationMythState.MythObjects.Add(taker.CreadedDeity); CreationMythState.Deities.Add(taker.CreadedDeity); CreationMythState.CreationTree.TreeRoot.traverseTree(addDeityToCreationTree, new CreationTreeNode(taker)); } taker.CurrentGoal = ActionGoal.None; CreationMythLogger.UpdateActionLog(taker, true); }
private void PrintCreationTree(TreeNode <CreationTreeNode> current_node) { CreationMythLogger.UpdateTreeLog(current_node); }
public void determineNextGoal() { TreeNode <CreationTreeNode> action_taker_node = CreationMythState.CreationTree.TreeRoot.searchNode(compareNode, new CreationTreeNode(this)); if (action_taker_node == null) { _current_goal = ActionGoal.None; _action_fsm.Advance(new Wait()); CreationMythLogger.UpdateActionLog(this); return; } foreach (TreeNode <CreationTreeNode> child in action_taker_node.Children) { if (child.Value.MythObject != null) { continue; } switch (child.Value.Character) { case "p": CreationMythLogger.UpdateActionLog("Start the creation of a plane."); _current_goal = ActionGoal.CreatePlane; child.Value.UnderConstruction = true; child.Value.Creator = this; return; case "d": CreationMythLogger.UpdateActionLog("Start the creation of a deity."); _current_goal = ActionGoal.CreateDeity; child.Value.UnderConstruction = true; child.Value.Creator = this; return; default: _current_goal = ActionGoal.None; break; } } if (_current_goal == ActionGoal.None) { foreach (TreeNode <CreationTreeNode> child in action_taker_node.Children) { if (_current_goal == ActionGoal.None && child.Value.Character == "p") { foreach (TreeNode <CreationTreeNode> child_of_child in child.Children) { if (child_of_child.Value.MythObject == null) { switch (child_of_child.Value.Character) { case "w": CreationMythLogger.UpdateActionLog("Start the creation of a world."); _current_goal = ActionGoal.CreateWorld; child_of_child.Value.UnderConstruction = true; child.Value.Creator = this; return; case "a": CreationMythLogger.UpdateActionLog("Start the creation of a sapient species."); _current_goal = ActionGoal.CreateSapientSpecies; child.Value.UnderConstruction = true; child.Value.Creator = this; return; default: _current_goal = ActionGoal.None; break; } } } } } } }