Example #1
0
 public void bake()
 {
     Kitchen k = new Kitchen(recipes, mainrecipe);
     k.cook();
 }
Example #2
0
        public Container cook()
        {
            ChefGUI gui = GameObject.Find("Scripting Mod").AddComponent <ChefGUI>();
            Dictionary <String, Ingredient> ingredients = recipe.getIngredients();
            List <Method>         methods = recipe.getMethods();
            LinkedList <LoopData> loops   = new LinkedList <LoopData>();
            Component             c;
            int  i          = 0;
            bool deepfrozen = false;

methodloop:
            while (i < methods.Count && !deepfrozen)
            {
                Method m = methods[i];
                switch (m.type)
                {
                case Method.Type.Take:
                case Method.Type.Put:
                case Method.Type.Fold:
                case Method.Type.Add:
                case Method.Type.Remove:
                case Method.Type.Combine:
                case Method.Type.Divide:
                case Method.Type.Liquefy:
                case Method.Type.StirInto:
                case Method.Type.Verb:
                    if (ingredients[m.ingredient] == null)
                    {
                        throw new ChefException(ChefException.METHOD, "Ingredient not found: " + m.ingredient);
                    }
                    break;
                }
                switch (m.type)
                {
                case Method.Type.Take:
                    gui.label = "Set amount of ingredient " + ingredients[m.ingredient].getName() + " to take.";
                    while (gui.label.Equals(""))
                    {
                    }
                    ingredients[m.ingredient].setAmount(int.Parse(gui.input));
                    MonoBehaviour.Destroy(gui);
                    break;

                case Method.Type.Put:
                    mixingbowls[m.mixingbowl].push(new Component(ingredients[m.ingredient]));
                    break;

                case Method.Type.Fold:
                    if (mixingbowls[m.mixingbowl].size() == 0)
                    {
                        throw new ChefException(ChefException.METHOD,
                                                "Folded from empty mixing bowl: " + (m.mixingbowl + 1));
                    }
                    c = mixingbowls[m.mixingbowl].pop();
                    ingredients[m.ingredient].setAmount(c.getValue());
                    ingredients[m.ingredient].setState(c.getState());
                    break;

                case Method.Type.Add:
                    c = mixingbowls[m.mixingbowl].peek();
                    c.setValue(c.getValue() + ingredients[m.ingredient].getAmount());
                    break;

                case Method.Type.Remove:
                    c = mixingbowls[m.mixingbowl].peek();
                    c.setValue(c.getValue() - ingredients[m.ingredient].getAmount());
                    break;

                case Method.Type.Combine:
                    c = mixingbowls[m.mixingbowl].peek();
                    c.setValue(c.getValue() * ingredients[m.ingredient].getAmount());
                    break;

                case Method.Type.Divide:
                    c = mixingbowls[m.mixingbowl].peek();
                    c.setValue(c.getValue() / ingredients[m.ingredient].getAmount());
                    break;

                case Method.Type.AddDry:
                    int sum = 0;
                    foreach (KeyValuePair <string, Ingredient> s in ingredients)
                    {
                        if (s.Value.getstate() == Ingredient.State.Dry)
                        {
                            sum += s.Value.getAmount();
                        }
                    }
                    mixingbowls[m.mixingbowl].push(new Component(sum, Ingredient.State.Dry));
                    break;

                case Method.Type.Liquefy:
                    ingredients[m.ingredient].liquefy();
                    break;

                case Method.Type.LiquefyBowl:
                    mixingbowls[m.mixingbowl].liquefy();
                    break;

                case Method.Type.Stir:
                    mixingbowls[m.mixingbowl].stir(m.time);
                    break;

                case Method.Type.StirInto:
                    mixingbowls[m.mixingbowl].stir(ingredients[m.ingredient].getAmount());
                    break;

                case Method.Type.Mix:
                    mixingbowls[m.mixingbowl].shuffle();
                    break;

                case Method.Type.Clean:
                    mixingbowls[m.mixingbowl].clean();
                    break;

                case Method.Type.Pour:
                    bakingdishes[m.bakingdish].combine(mixingbowls[m.mixingbowl]);
                    break;

                case Method.Type.Verb:
                    int end = i + 1;
                    for (; end < methods.Count; end++)
                    {
                        if (sameVerb(m.verb, methods[end].verb) && methods[end].type == Method.Type.VerbUntil)
                        {
                            break;
                        }
                    }
                    if (end == methods.Count)
                    {
                        throw new ChefException(ChefException.METHOD, "Loop end statement not found.");
                    }
                    if (ingredients[m.ingredient].getAmount() <= 0)
                    {
                        i = end + 1;
                        continue;
                    }
                    else
                    {
                        loops.AddFirst(new LoopData(i, end, m.verb));
                    }
                    break;

                case Method.Type.VerbUntil:
                    if (!sameVerb(loops.First.Value.verb, m.verb))
                    {
                        throw new ChefException(ChefException.METHOD, "Wrong loop end statement found.");
                    }
                    if (ingredients[m.ingredient] != null)
                    {
                        ingredients[m.ingredient].setAmount(ingredients[m.ingredient].getAmount() - 1);
                    }
                    i = loops.First.Value.@from;
                    loops.RemoveFirst();
                    continue;

                case Method.Type.SetAside:
                    if (loops.Count == 0)
                    {
                        throw new ChefException(ChefException.METHOD, "Cannot set aside when not inside loop.");
                    }
                    else
                    {
                        i = loops.First.Value.to + 1;
                        continue;
                    }

                case Method.Type.Serve:
                    if (recipes[m.auxrecipe.ToLower()] == null)
                    {
                        throw new ChefException(ChefException.METHOD, "Unavailable recipe: " + m.auxrecipe);
                    }
                    Kitchen k = new Kitchen(recipes, recipes[m.auxrecipe.ToLower()], mixingbowls,
                                            bakingdishes);
                    Container con = k.cook();
                    mixingbowls[0].combine(con);
                    break;

                case Method.Type.Refrigerate:
                    if (m.time > 0)
                    {
                        serve(m.time);
                    }
                    deepfrozen = true;
                    break;

                case Method.Type.Remember:
                    break;

                default:
                    throw new ChefException(ChefException.METHOD, "Unsupported method found!");
                }
                i++;
            }
            if (recipe.getServes() > 0 && !deepfrozen)
            {
                serve(recipe.getServes());
            }
            if (mixingbowls.Length > 0)
            {
                return(mixingbowls[0]);
            }
            return(null);
        }
Example #3
0
        public void bake()
        {
            Kitchen k = new Kitchen(recipes, mainrecipe);

            k.cook();
        }
Example #4
0
        public Container cook()
        {
            ChefGUI gui = GameObject.Find("Scripting Mod").AddComponent<ChefGUI>();
            Dictionary<String, Ingredient> ingredients = recipe.getIngredients();
            List<Method> methods = recipe.getMethods();
            LinkedList<LoopData> loops = new LinkedList<LoopData>();
            Component c;
            int i = 0;
            bool deepfrozen = false;
            methodloop:
            while (i < methods.Count && !deepfrozen)
            {
                Method m = methods[i];
                switch (m.type)
                {
                    case Method.Type.Take:
                    case Method.Type.Put:
                    case Method.Type.Fold:
                    case Method.Type.Add:
                    case Method.Type.Remove:
                    case Method.Type.Combine:
                    case Method.Type.Divide:
                    case Method.Type.Liquefy:
                    case Method.Type.StirInto:
                    case Method.Type.Verb:
                        if (ingredients[m.ingredient] == null)
                            throw new ChefException(ChefException.METHOD, "Ingredient not found: " + m.ingredient);
                        break;
                }
                switch (m.type)
                {
                    case Method.Type.Take:
                        gui.label = "Set amount of ingredient " + ingredients[m.ingredient].getName() + " to take.";
                        while (gui.label.Equals(""))
                        {
                            
                        }
                        ingredients[m.ingredient].setAmount(int.Parse(gui.input));
                        MonoBehaviour.Destroy(gui);
                        break;
                    case Method.Type.Put:
                        mixingbowls[m.mixingbowl].push(new Component(ingredients[m.ingredient]));
                        break;
                    case Method.Type.Fold:
                        if (mixingbowls[m.mixingbowl].size() == 0)
                            throw new ChefException(ChefException.METHOD,
                                "Folded from empty mixing bowl: " + (m.mixingbowl + 1));
                        c = mixingbowls[m.mixingbowl].pop();
                        ingredients[m.ingredient].setAmount(c.getValue());
                        ingredients[m.ingredient].setState(c.getState());
                        break;
                    case Method.Type.Add:
                        c = mixingbowls[m.mixingbowl].peek();
                        c.setValue(c.getValue() + ingredients[m.ingredient].getAmount());
                        break;
                    case Method.Type.Remove:
                        c = mixingbowls[m.mixingbowl].peek();
                        c.setValue(c.getValue() - ingredients[m.ingredient].getAmount());
                        break;
                    case Method.Type.Combine:
                        c = mixingbowls[m.mixingbowl].peek();
                        c.setValue(c.getValue()*ingredients[m.ingredient].getAmount());
                        break;
                    case Method.Type.Divide:
                        c = mixingbowls[m.mixingbowl].peek();
                        c.setValue(c.getValue()/ingredients[m.ingredient].getAmount());
                        break;
                    case Method.Type.AddDry:
                        int sum = 0;
                        foreach (KeyValuePair<string, Ingredient> s in ingredients)
                            if (s.Value.getstate() == Ingredient.State.Dry)
                                sum += s.Value.getAmount();
                        mixingbowls[m.mixingbowl].push(new Component(sum, Ingredient.State.Dry));
                        break;
                    case Method.Type.Liquefy:
                        ingredients[m.ingredient].liquefy();
                        break;
                    case Method.Type.LiquefyBowl:
                        mixingbowls[m.mixingbowl].liquefy();
                        break;
                    case Method.Type.Stir:
                        mixingbowls[m.mixingbowl].stir(m.time);
                        break;
                    case Method.Type.StirInto:
                        mixingbowls[m.mixingbowl].stir(ingredients[m.ingredient].getAmount());
                        break;
                    case Method.Type.Mix:
                        mixingbowls[m.mixingbowl].shuffle();
                        break;
                    case Method.Type.Clean:
                        mixingbowls[m.mixingbowl].clean();
                        break;
                    case Method.Type.Pour:
                        bakingdishes[m.bakingdish].combine(mixingbowls[m.mixingbowl]);
                        break;
                    case Method.Type.Verb:
                        int end = i + 1;
                        for (; end < methods.Count; end++)
                            if (sameVerb(m.verb, methods[end].verb) && methods[end].type == Method.Type.VerbUntil)
                                break;
                        if (end == methods.Count)
                            throw new ChefException(ChefException.METHOD, "Loop end statement not found.");
                        if (ingredients[m.ingredient].getAmount() <= 0)
                        {
                            i = end + 1;
                            continue;
                        }
                        else
                            loops.AddFirst(new LoopData(i, end, m.verb));
                        break;
                    case Method.Type.VerbUntil:
                        if (!sameVerb(loops.First.Value.verb, m.verb))
                            throw new ChefException(ChefException.METHOD, "Wrong loop end statement found.");
                        if (ingredients[m.ingredient] != null)
                            ingredients[m.ingredient].setAmount(ingredients[m.ingredient].getAmount() - 1);
                        i = loops.First.Value.@from;
                        loops.RemoveFirst();
                        continue;
                    case Method.Type.SetAside:
                        if (loops.Count == 0)
                            throw new ChefException(ChefException.METHOD, "Cannot set aside when not inside loop.");
                        else
                        {
                            i = loops.First.Value.to + 1;
                            continue;
                        }
                    case Method.Type.Serve:
                        if (recipes[m.auxrecipe.ToLower()] == null)
                            throw new ChefException(ChefException.METHOD, "Unavailable recipe: " + m.auxrecipe);
                        Kitchen k = new Kitchen(recipes, recipes[m.auxrecipe.ToLower()], mixingbowls,
                            bakingdishes);
                        Container con = k.cook();
                        mixingbowls[0].combine(con);
                        break;
                    case Method.Type.Refrigerate:
                        if (m.time > 0)

                            serve(m.time);
                        deepfrozen = true;
                        break;
                    case Method.Type.Remember:
                        break;
                    default:
                        throw new ChefException(ChefException.METHOD, "Unsupported method found!");
                }
                i++;
            }
            if (recipe.getServes() > 0 && !deepfrozen)

                serve(recipe.getServes());
            if (mixingbowls.Length > 0)
                return mixingbowls[0];
            return null;
        }