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

  1. -- sink character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         --local sink = getStateObjectFromID(msg.sender);
  7.         
  8.         local sink = getStoredOrSender("dishwasher", msg)
  9.         storeStateObject("sink", sink);
  10.         
  11.         if (sink) then
  12.             -- sink does exist
  13.             local actionPointName = retrieveData("actionPointName");
  14.             if exitIfWrongPosition(getParent(), sink, actionPointName) then return end;                
  15.  
  16.             if (getParent().isOneActionPointLocked(sink)) then
  17.                 -- action point is locked
  18.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  19.                 sendMsg("emoThink", getParent().walkSO);
  20.                 exitStateMachine();
  21.             else
  22.                 getParent().lockActionPoints(sink);
  23.             end
  24.         else
  25.             -- sink does not exist anymore
  26.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  27.             sendMsg("emoThink", getParent().walkSO);
  28.             exitStateMachine();
  29.         end
  30.         
  31.         freeHands(getParent());
  32.                 
  33.     end )
  34.     
  35.     onExit(function(msg)
  36. --        local sink = retrieveStateObject("sink");
  37. --        getParent().unlockActionPoints(sink);
  38. --        getParent().stopAllActivities(sink);
  39. --        removeStateObject("sink");
  40.         
  41.         unlockAll("sink");
  42.         
  43.         getParent().stopAllActivities();        
  44.     end )
  45.     
  46.     
  47.     state("washHandsStart")
  48.     
  49.         onEnter(function(msg)
  50.             startAnimation("washHandsStart");
  51.         end )                
  52.  
  53.         onMsg("end", function(msg)
  54.             if (testCancel()) then
  55.                 exitStateMachine();
  56.             else
  57.                 setState("washHands");
  58.             end
  59.         end )    
  60.     
  61.     
  62.     
  63.     state("washHands")
  64.     
  65.         onEnter(function(msg)
  66.             local sink = retrieveStateObject("sink");
  67.             local washHands = getParent().startActivity("washHands", sink);
  68.             local length, scale = getActivityLength(washHands);
  69.             storeData("scale", scale);
  70.             
  71.             sink.loopSound("washHands");
  72.             startAnimation("washHandsLoop", false, scale);
  73.             sendDelayedMsgThis("complete", length);
  74.         end )
  75.     
  76.         onMsg("complete", function(msg)
  77.             setState("washHandsEnd");
  78.         end )    
  79.  
  80.         onMsg("end", function(msg)        
  81.             if testCancel() then
  82.                 sendMsgThis("complete");
  83.             else
  84.                 startAnimation("washHandsLoop", false, retrieveData("scale"));
  85.             end
  86.         end )    
  87.         
  88.         onExit(function(msg)
  89.             local sink = retrieveStateObject("sink");
  90.             sink.stopSound("washHands");
  91.             getParent().stopActivity("washHands", sink);
  92.         end)
  93.         
  94.     state("washHandsEnd")
  95.     
  96.         onEnter(function(msg)
  97.             -- grab sponge
  98.             startAnimation("washHandsEnd");            
  99.         end )
  100.     
  101.         onMsg("end", function(msg)
  102.             --exitStateMachine();
  103.             --goAway();
  104.             exitAndGoAway();
  105.         end )    
  106.     
  107.     
  108.     --washDishes---------------------------------------------------------------------------------------    
  109.         
  110.     state("washDishesStart")
  111.     
  112.         onEnter(function(msg)
  113.             print("onEnter washDishesStart cancel :" .. tostring(testCancel()));
  114.             local sink = retrieveStateObject("sink");
  115.             addDish(sink, retrieveData("numDishes", 0));
  116.             
  117.             
  118.             
  119.             startAnimation("washDishesStart");            
  120.             sendDelayedMsgThis("grabBrush", 2800);
  121.             
  122.             
  123.                         
  124.             --setTopQueueEntry(getParent(), "pm_washDishes")            
  125.         end )
  126.     
  127.         onMsg("grabBrush", function(msg)
  128.             local brush = getParent().loadGameObject("StandardGO","sinkBrush");            
  129.             storeStateObject("brush", brush);
  130.             getParent().attachRightObjectHolder(brush);
  131.             
  132.             local plate = getParent().loadGameObject("StandardGO","plate");            
  133.             storeStateObject("plate", plate);
  134.             getParent().attachLeftObjectHolder(plate);
  135.             
  136.             local sink = retrieveStateObject("sink");
  137.             addDish(sink, -1);                    
  138.         end )    
  139.     
  140.         onMsg("end", function(msg)
  141.             if (testCancel()) then
  142.                 setState("washDishesEnd");
  143.             else
  144.                 setState("washDishes");
  145.             end
  146.         end )    
  147.                 
  148.     state("washDishes")
  149.     
  150.         onEnter(function(msg)
  151.             
  152.             local sink = retrieveStateObject("sink");
  153.             local washDishes = getParent().startActivity("washDishes", sink);
  154.             local length, scale = getActivityLength(washDishes);
  155.             storeData("length", length);
  156.             storeData("scale", scale);
  157.             print("washDishes length: " .. length);
  158.             
  159.             sendDelayedMsgThis("plateReady", length);
  160.  
  161.             startAnimation("washDishesLoop", false, scale);
  162.             sink.loopSound("washHands");
  163.             
  164.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  165.                                     
  166.         end )
  167.         
  168.         
  169.         onMsg("queue", function(msg)
  170.             sendMsgThis("complete");
  171.         end )    
  172.  
  173.         onMsg("plateReady", function(msg)
  174.             local sink = retrieveStateObject("sink");
  175.             if (getDish(sink) < 1) then
  176.                 sendMsgThis("complete");
  177.             else
  178.                 addDish(sink, -1);
  179.                 sendDelayedMsgThis("plateReady", retrieveData("length"));
  180.             end
  181.         end )    
  182.  
  183.         onMsg("complete", function(msg)
  184.             local sink = retrieveStateObject("sink");
  185.             sink.stopSound("washHands");
  186.             getParent().stopActivity("washDishes", sink);
  187.             setState("washDishesEnd");
  188.         end )    
  189.  
  190.         onMsg("testCancel", function(msg)
  191.             if testCancel() then
  192.                 sendMsgThis("complete");
  193.             else
  194.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  195.             end
  196.         end )
  197.  
  198.         onMsg("end", function(msg)
  199.             local sink = retrieveStateObject("sink");
  200.             if testCancel() or (getDish(sink) < 1) then
  201.                 sendMsgThis("complete");
  202.             else
  203.                 startAnimation("washDishesLoop", false, retrieveData("scale"));
  204.             end
  205.         end )    
  206.         
  207.                         
  208.     state("washDishesEnd")
  209.     
  210.         onEnter(function(msg)
  211.             startAnimation("washDishesEnd");            
  212.             freeHands(getParent());
  213.         end )
  214.     
  215.     
  216.         onMsg("end", function(msg)
  217.             --exitAndGoAway();
  218.             exitStateMachine();
  219.         end )    
  220.  
  221.  
  222.     --brushTeeth---------------------------------------------------------------------------------------    
  223.         
  224.     
  225.     state("brushTeethStart")
  226.     
  227.         onEnter(function(msg)
  228.             startAnimation("brushTeethStart");
  229.             sendDelayedMsgThis("grabBrush", 1600);
  230.         end )
  231.     
  232.         onMsg("grabBrush", function(msg)
  233.             brush = getParent().loadGameObject("StandardGO","toothBrush");
  234.             if (not brush) then
  235.                 print("create brush failed");
  236.             end
  237.             storeStateObject("brush", brush);
  238.             getParent().attachRightObjectHolder(brush);        
  239.         end )    
  240.  
  241.         onMsg("end", function(msg)
  242.             
  243.             if testCancel() then
  244.                 getParent().detachRightObjectHolder();    
  245.                 local brush = retrieveStateObject("brush");
  246.                 if (brush) then brush.deleteGameObject(); end
  247.                 exitStateMachine();
  248.             else
  249.                 setState("brushTeeth");
  250.             end
  251.         end )    
  252.         
  253.     state("brushTeeth")
  254.     
  255.         onEnter(function(msg)
  256.             local sink = retrieveStateObject("sink");
  257.             local brushTeeth = getParent().startActivity("brushTeeth", sink);
  258.             local length, scale = getActivityLength(brushTeeth);
  259.             storeData("scale", scale);
  260.             
  261.             sendDelayedMsgThis("complete", length);
  262.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  263.             
  264.             print("brushTeeth, length:" .. length);
  265.  
  266.             getParent().loopSound("brushTeeth");
  267.             startAnimation(genderize(getParent(), "brushTeethLoop"), false, scale);
  268.             -- this.actionComplete();
  269.         end )
  270.         
  271.             
  272.         onMsg("complete", function(msg)
  273.             local sink = retrieveStateObject("sink");
  274.             getParent().stopSound("brushTeeth");
  275.             getParent().stopActivity("brushTeeth", sink);
  276.             setState("brushTeethEnd");
  277.         end )    
  278.         
  279.  
  280.         onMsg("testCancel", function(msg)
  281.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  282.                 sendMsgThis("complete");
  283.             else
  284.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  285.             end
  286.         end )
  287.  
  288.         onMsg("end", function(msg)
  289.             
  290.             if testCancel() then
  291.                 sendMsgThis("complete");
  292.             else
  293.                 startAnimation(genderize(getParent(), "brushTeethLoop"), false, retrieveData("scale"));
  294.             end
  295.         end )    
  296.     
  297.     state("brushTeethEnd")
  298.     
  299.         onEnter(function(msg)
  300.             startAnimation("brushTeethEnd");
  301.             sendDelayedMsgThis("openWater", 1700);
  302.             sendDelayedMsgThis("dropBrush", 7360);
  303.         end )
  304.         
  305.         onExit(function(msg)
  306.             local sink = retrieveStateObject("sink");
  307.             sink.stopSound("washHands");
  308.             freeHands(getParent());
  309.         end )
  310.     
  311.         onMsg("openWater", function(msg)
  312.             local sink = retrieveStateObject("sink");
  313.             sink.loopSound("washHands");
  314.         end )    
  315.  
  316.         onMsg("dropBrush", function(msg)
  317.             local sink = retrieveStateObject("sink");
  318.             sink.stopSound("washHands");
  319.             freeHands(getParent());
  320.         end )    
  321.         
  322.         onMsg("end", function(msg)
  323.             exitAndGoAway();
  324.         end )
  325.                     
  326.     state("makeHair")
  327.     
  328.         onEnter(function(msg)
  329.             local sink = retrieveStateObject("sink");
  330.             --getParent().startActivity("makeHair", sink);
  331.  
  332.             local makeHair = getParent().startActivity("makeHair", sink);
  333.             local length, scale = getActivityLength(makeHair);
  334.             
  335.             sendDelayedMsgThis("complete", length);
  336.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  337.             
  338.             local hairBrush = getParent().loadGameObject("StandardGO", "hairBrush");
  339.             local hairSpray = getParent().loadGameObject("StandardGO", "hairSpray");
  340.             getParent().attachRightObjectHolder(hairBrush);
  341.             getParent().attachLeftObjectHolder(hairSpray);
  342.  
  343.             sendMsgThis("startLoop");
  344.         end )
  345.     
  346.         onMsg("startLoop", function(msg)
  347.             startAnimation("makeHair");
  348.             sendDelayedMsgThis("brushSound", 600);
  349.             sendDelayedMsgThis("spraySound", 5800);
  350.         end )    
  351.         
  352.         onMsg("brushSound", function(msg)
  353.             getParent().playSound("hairBrush");            
  354.         end )    
  355.         
  356.         onMsg("spraySound", function(msg)
  357.             getParent().playSound("hairSpray");            
  358.         end )    
  359.                 
  360.  
  361.         onMsg("complete", function(msg)
  362.             freeHands(getParent());
  363.             getParent().stopActivity("makeHair", retrieveStateObject("sink"));
  364.             exitAndGoAway();
  365.         end )    
  366.         
  367.         onMsg("testCancel", function(msg)
  368.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  369.                 sendMsgThis("complete");
  370.             else
  371.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  372.             end
  373.         end )
  374.         
  375.         onMsg("end", function(msg)
  376.             if testCancel() then
  377.                 sendMsgThis("complete");
  378.             else
  379.                 sendMsgThis("startLoop");
  380.             end
  381.         end )    
  382.                 
  383. endStateMachine()
  384.