예제 #1
0
    public IEnumerator ProcessStacks()
    {
        while (true)
        {
            while (stackExec.Count == 0)
            {
                //If we don't have any executables to process, then we have to unpack clauses until we do have an executable

                if (stackClause.Count > 0)
                {
                    //If we have a clause on our stack, then unpack that to hopefully add an executable to the stack
                    if (bDEBUGENGINE)
                    {
                        Debug.Log("No Executables, so unpack a Clause");
                    }
                    ResolveClause();
                }
                else
                {
                    //If we have no clauses on our stack, then our stack is completely empty, so we can push
                    // a new executable for the next phase of the turn
                    if (bDEBUGENGINE)
                    {
                        Debug.Log("No Clauses or Executables so move to the next part of the turn");
                    }
                    ContTurns.Get().FinishedTurnPhase();
                }
            }

            //If we've gotten this far, then we know we have an executable to examine

            //Check if the executable on top of our stack has dealt with its pre-triggers/replacements yet
            if (stackExec.Peek().bPreTriggered)
            {
                //If we've already dealt with all its pretriggers/replacements, then we're ready to actually evaluate and we can
                //  exit our loop
                break;
            }
            else
            {
                //Debug.Log("Performing Replacement effects and Pre-Triggers");

                //Pop off the top element
                Executable top = stackExec.Pop();

                //Check for any replacement effects
                //Initially, we reset the cycle-checking flags for each registered replacement effect
                Replacement.ResetReplacedFlags();

                //Resolve any full replacement effects (so we settle on a single type of executable)
                top = ResolveFullReplacements(top);

                //Now we modify that executable as much as necessary
                top = ResolveReplacements(top);

                //Push the modified executable back onto the stack at the top
                stackExec.Push(top);

                //Now we can push all of the pre-triggers onto the stack
                top.GetPreTrigger().NotifyObs(null, top);

                //Set our flag so that we don't pre-trigger this effect again
                top.bPreTriggered = true;

                //Now we can continue our loop to process whatever executable is now at the top of the stack
            }
        }

        //If we've gotten this far, then we know we have an executable at the top of our stack and
        //  we are ready to process it
        yield return(ResolveExec());
    }