home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / ovenChar.lua < prev    next >
Text File  |  2004-03-05  |  9KB  |  357 lines

  1. -- oven character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         local oven = getStateObjectFromID(msg.sender);
  7.         storeStateObject("oven", oven);
  8.         
  9. --        local tablet = retrieveStateObject("tablet");
  10. --        if (tablet) then
  11. --            tablet.deleteGameObject();            
  12. --        end            
  13. --        getParent().detachRightObjectHolder();
  14. --        getParent().detachLeftObjectHolder();
  15. --        
  16. --        -- we need free hands for cooking
  17. --        local hands = getParent().handSO;
  18. --        if (not hands) then
  19. --            print("no hands found");
  20. --        else
  21. --            hands.stopPose();
  22. --        end
  23.  
  24.         
  25.         if (oven) then
  26.             -- oven does exist
  27.             local actionPointName = retrieveData("actionPointName");
  28.             if exitIfWrongPosition(getParent(), oven, actionPointName) then return end;                
  29.             
  30.             if (getParent().isOneActionPointLocked(oven)) then
  31.                 -- action point is locked
  32.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  33.                 sendMsg("emoThink", getParent().walkSO);
  34.                 exitStateMachine();
  35.             else
  36.                 getParent().lockActionPoints(oven);
  37.                                 
  38.             end
  39.         else
  40.             -- oven does not exist anymore
  41.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  42.             sendMsg("emoThink", getParent().walkSO);
  43.             exitStateMachine();
  44.         end
  45.         
  46.         freeHands(getParent());
  47.         
  48.         
  49.     end )
  50.     
  51.     onExit(function(msg)
  52.         
  53.         
  54.         local pot = retrieveStateObject("pot");
  55.         if (pot) then
  56.             pot.deleteGameObject();
  57.             removeStateObject("pot");
  58.         end;
  59.         
  60.         local spoon = retrieveStateObject("spoon");
  61.         if (spoon) then
  62.             spoon.deleteGameObject();
  63.             removeStateObject("spoon");
  64.         end;
  65.         
  66.         local oven = retrieveStateObject("oven");
  67.         --oven.setChildEnable("pot", false);
  68.         if (oven) then
  69.             oven.setChildEnable("spoon", false);
  70.             
  71.             local damp = oven.findChildGO("damp");
  72.             damp.setEmitRate(0.0);
  73.             oven.setChildEnable("damp", false);            
  74.                         
  75. --            getParent().unlockActionPoints(oven);
  76. --            removeStateObject("oven");
  77.         end;
  78.         
  79.         unlockAll("oven");
  80.         
  81.         getParent().stopAllActivities();
  82.     end )
  83.     
  84.     -- open the oven
  85.     state("open")
  86.     
  87.         onEnter(function(msg)
  88.             local oven = retrieveStateObject("oven");
  89.             -- create the cracker box
  90.             local pot = oven.createGameObject("pot");
  91.             storeStateObject("pot", pot);
  92.             local spoon = oven.createGameObject("spoon");
  93.             storeStateObject("spoon", spoon);
  94.             
  95.             -- start to open the oven
  96.             startAnimation("openOven");
  97.             oven.startAnimation("ovenDoorOpen");
  98.             -- send a delayed message for open sound
  99.             sendDelayedMsgThis("openSound", 0);
  100.             -- send a delayed message for attach
  101.             sendDelayedMsgThis("grabPot", 3000);
  102.             sendDelayedMsgThis("dropPot", 4880);
  103.             -- send a delayed message for close sound
  104.             --sendDelayedMsgThis("closeSound", 6000);
  105.         end )
  106.     
  107.         onMsg("openSound", function(msg)
  108.             local oven = retrieveStateObject("oven");
  109.             oven.playSound("openOven");
  110.         end)
  111.         
  112.         onMsg("grabPot", function(msg)
  113.             -- attach pot to left hand of character
  114.             local oven = retrieveStateObject("oven");
  115.             local pot = retrieveStateObject("pot");
  116.             print("setChildEnable");
  117.             oven.setChildEnable("pot", true);            
  118.             getParent().attachLeftObjectHolder(pot);
  119.         end)
  120.         
  121.         onMsg("dropPot", function(msg)
  122.             local oven = retrieveStateObject("oven");
  123.             getParent().detachLeftObjectHolder();
  124.             oven.setChildEnable("spoon", true);
  125.  
  126.         end)
  127.         
  128.         
  129.  
  130.         onMsg("closeSound", function(msg)
  131.             local oven = retrieveStateObject("oven");
  132.             oven.playSound("fridgeClose");
  133.         end)
  134.  
  135.         onMsg("end", function(msg)
  136.             
  137.             if testCancel() then
  138. --                freeHands(getParent());
  139. --                -- remove the pot
  140. --                local pot = retrieveStateObject("pot");
  141. --                if (pot) then
  142. --                    getParent().detachRightObjectHolder();
  143. --                    pot.deleteGameObject();
  144. --                end
  145. --                -- remove the spoon
  146. --                local spoon = getParent().getRightHeldObject();
  147. --                if (spoon) then
  148. --                    getParent().detachRightObjectHolder();
  149. --                    spoon.deleteGameObject();
  150. --                end
  151.  
  152.                 freeHands(getParent());
  153.                 local oven = retrieveStateObject("oven");
  154.                 oven.setChildEnable("spoon", false);
  155.                 oven.setChildEnable("pot", false);
  156.                 exitStateMachine();
  157.             else
  158.                 setState("cookTaste");
  159.             end
  160.         end )    
  161.         
  162.         onExit(function(msg)
  163.             -- getParent().detachObjectAnimator();
  164.         end)
  165.     
  166.  
  167.     state("cookTaste")
  168.     
  169.         onEnter(function(msg)
  170.             local oven = retrieveStateObject("oven");
  171.             local cook = getParent().startActivity("cook", oven)
  172.             
  173.             local length, scale = getActivityLength(cook);
  174.             storeData("scale", scale);
  175.             
  176.             -- animation
  177.             startAnimation("cookTaste", false, scale);
  178.             sendDelayedMsgThis("grabSpoon", 800/scale);
  179.             
  180.             
  181.             -- sounds
  182.             oven.playSound("cookingFadein");
  183.             sendDelayedMsgThis("cookingLoopSound", 1360/scale);
  184.             
  185.             sendDelayedMsgThis("completeCooking", length);
  186.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  187.             
  188.             sendDelayedMsgThis("moreDamp", 1000);
  189.             oven.setChildEnable("damp", true);            
  190.                                     
  191.         end )
  192.         
  193.         onExit(function(msg)
  194.             local oven = retrieveStateObject("oven");
  195.             getParent().stopAllActivities(oven);
  196.             
  197.             local damp = oven.findChildGO("damp");
  198.             damp.setEmitRate(0.0);
  199.             oven.setChildEnable("damp", FALSE);            
  200.             
  201.             createTrash(0.2);
  202.  
  203.         end )
  204.         
  205.         onMsg("grabSpoon", function(msg)
  206.             -- attach spoon to right hand of character
  207.             local oven = retrieveStateObject("oven");
  208.             oven.setChildEnable("spoon", true);            
  209.             getParent().attachRightObjectHolder(oven, "spoon");
  210.             sendDelayedMsgThis("dropSpoon", 2960/retrieveData("scale"));
  211.             
  212.         end)
  213.         
  214.         onMsg("dropSpoon", function(msg)
  215.             getParent().detachRightObjectHolder();
  216.         end)
  217.         
  218.         onMsg("moreDamp", function(msg)
  219.             local oven = retrieveStateObject("oven");
  220.             local damp = oven.findChildGO("damp");
  221.             local rate = damp.getEmitRate();
  222.             if (rate < MAX_OVEN_DAMP_RATE) then 
  223.                 damp.setEmitRate(rate + (0.1 * MAX_OVEN_DAMP_RATE));
  224.                 sendDelayedMsgThis("moreDamp", 1000);
  225.             end;
  226.         end)
  227.         
  228.         onMsg("cookingLoopSound", function(msg)
  229.             print("cookingLoopSound");
  230.             local oven = retrieveStateObject("oven");
  231.             oven.loopSound("cookingLoop");
  232.         end)
  233.                 
  234.         onMsg("cancelCooking", function(msg)
  235.         
  236.             print("cancelCooking");
  237.  
  238. --            local pot = getParent().getLeftHeldObject();
  239. --            if (pot) then
  240. --                getParent().detachLeftObjectHolder();
  241. --                pot.deleteGameObject();
  242. --            end
  243. --            -- remove the spoon
  244. --            local spoon = getParent().getRightHeldObject();
  245. --            if (spoon) then
  246. --                getParent().detachRightObjectHolder();
  247. --                spoon.deleteGameObject();
  248. --            end
  249.             
  250.             freeHands(getParent());
  251.             
  252.  
  253.             local oven = retrieveStateObject("oven");
  254.             oven.setChildEnable("spoon", false);
  255.             oven.setChildEnable("pot", false);
  256.             oven.stopSound("cookingLoop");
  257.             oven.playSound("cookingFadeout");
  258.  
  259.             exitAndGoAway();
  260.         end)
  261.         
  262.         
  263.         onMsg("completeCooking", function(msg)
  264.         
  265.             print("completeCooking");
  266.         
  267.             local oven = retrieveStateObject("oven");
  268.             freeHands(getParent());
  269.             
  270.             --oven.setChildEnable("pot", false);
  271.             -- leave the cooked food on the oven
  272.             sendDelayedMsg("hidePot", oven, OVEN_FOOD_REMAIN_TIME);
  273.             
  274.             oven.setChildEnable("spoon", false);
  275.             
  276.                         
  277. --            -- attach tablet
  278. --            print("create tablet");
  279. --            local tablet = getParent().loadGameObject("StandardGO", "tabletCooked");
  280. --            --storeStateObject("tablet", tablet);
  281. --            getParent().handSO.setPose("leftHandHold");
  282. --            getParent().attachLeftObjectHolder(tablet);                            
  283. --            
  284. --            oven.stopSound("cookingLoop");
  285. --            oven.playSound("cookingFadeout");
  286. --            
  287. --            getParent().replaceQueueEntry(0, "pm_eat");
  288. --            
  289. --            local wsoContext = StateMachineContext();
  290. --            wsoContext.storeStateObject("tablet", tablet);
  291. --            wsoContext.storeStateObject("tableObject", tablet);
  292. --            wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
  293. --            queueStateMachine("tableChairChar.findChair", this, wsoContext);
  294. --            exitStateMachine();
  295.  
  296.             getParent().pushCommand("pm_takeFood", "takeFood", oven, "");
  297.             exitStateMachine();
  298.  
  299.         end)
  300.         
  301.         
  302.         onMsg("testCancel", function(msg)
  303.             if testCancel() then
  304.                 sendMsgThis("cancelCooking");
  305.             else
  306.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  307.             end
  308.         end )
  309.         
  310.     
  311.         onMsg("end", function(msg)
  312.  
  313.             if testCancel() then
  314.                 sendMsgThis("cancelCooking");
  315.             else
  316.                 -- animation
  317.                 local scale = retrieveData("scale");
  318.                 startAnimation("cookTaste", false, scale);
  319.                 sendDelayedMsgThis("grabSpoon", 800/scale);
  320.             end
  321.         end )
  322.         
  323.         
  324.         
  325.     state("takeFood")
  326.     
  327.         onEnter(function(msg)
  328.         
  329.             local oven = retrieveStateObject("oven");
  330.             
  331.             if (oven.getChildEnable("pot")) then
  332.                 -- attach tablet
  333.                 print("create tablet");
  334.                 local tablet = getParent().loadGameObject("StandardGO", "tabletCooked");
  335.                 getParent().handSO.setPose("leftHandHold");
  336.                 getParent().attachLeftObjectHolder(tablet);
  337.                                                         
  338.                 getParent().replaceQueueEntry(0, "pm_eat");
  339.                 
  340.                 -- find place to eat
  341.                 local wsoContext = StateMachineContext();
  342.                 wsoContext.storeStateObject("tablet", tablet);
  343.                 wsoContext.storeStateObject("tableObject", tablet);
  344.                 wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
  345.                 wsoContext.storeData("checkPartnerChair", true);
  346.                 queueStateMachine("tableChairChar.findChair", this, wsoContext);
  347.                 exitStateMachine();
  348.             else
  349.                 exitAndGoAway();
  350.             end
  351.  
  352.         end)
  353.         
  354.  
  355.         
  356. endStateMachine()
  357.