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

  1. -- dish collecting character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         --local dishwasher = getStateObjectFromID(msg.sender);
  7.         local dishwasher = getStoredOrSender("dishwasher", msg)
  8.         storeStateObject("dishwasher", dishwasher);
  9.         
  10.         freeHands(getParent());
  11.                         
  12.     end )
  13.     
  14.     onExit(function(msg)
  15.         local dishwasher = retrieveStateObject("dishwasher");
  16.         if (dishwasher) then
  17.             getParent().unlockActionPoints(dishwasher);
  18.             removeStateObject("dishwasher");
  19.         end;        
  20.  
  21.         local table = retrieveStateObject("table");
  22.         if (table) then
  23.             print("onExit table removed");
  24.             getParent().unlockActionPoints(table);
  25.             removeStateObject("table");
  26.         else        
  27.             print("onExit table NOT removed");
  28.         end
  29.         
  30.         local dish = retrieveStateObject("dish");
  31.         if (dish) then
  32.             print("onExit dish removed");
  33.             removeStateObject("dish");
  34.         else        
  35.             print("onExit dish NOT removed");
  36.         end
  37.     end )
  38.     
  39.     state("findDishes")
  40.     
  41.         onEnter(function(msg)
  42.             print("findDishes onEnter");
  43.             local table, actionPoint, dishFound = getNextTableWithDishes(getParent());
  44.             if (not table or testCancel()) then
  45.                 print("no table with dishes found or cannot reach table");
  46.  
  47.                 if (dishFound) then
  48.                     print(" --> dish was found but reachable");
  49.                     -- dish was found but reachable
  50.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);            
  51.                 end
  52.                 
  53. --                local dishHeap = getParent().getRightHeldObject();
  54. --                if (dishHeap) then setState("gotoDishwasher"); return end;
  55.                 setState("gotoDishwasher");
  56. --                exitStateMachine();
  57.                 return
  58.             end
  59.             
  60.             storeStateObject("table", table);
  61.             storeData("actionPointName", actionPoint.getName());
  62.                         
  63.             if (walkToPointImmediate(actionPoint)) then
  64.             
  65.                 enterStateMachine("subwalk.walk");
  66.  
  67.             else
  68.             
  69.                 print("no path found");
  70.                 getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);            
  71.                 
  72. --                local dishHeap = getParent().getRightHeldObject();
  73. --                if (dishHeap) then setState("gotoDishwasher"); return end
  74.                 setState("gotoDishwasher");
  75. --                exitStateMachine();
  76.                 return
  77.             end
  78.                         
  79.         end )
  80.         
  81.         
  82.         onReturn(function(msg)
  83.             print("dish collecting character findDishes onReturn");
  84.             setState("takePlate");
  85.         end )
  86.         
  87.     
  88.     state("takePlate")
  89.     
  90.         onEnter(function(msg)
  91.             print("takePlate onEnter");
  92.         
  93.             local table = retrieveStateObject("table"); 
  94.             local actionPointName = retrieveData("actionPointName");
  95.  
  96.             if (table) then
  97.                 -- table does exist
  98.                 
  99. --                if hasRightPosition(getParent(), table, actionPointName) then 
  100. --                    print("takePlate not on action point");
  101. --                    setState("findDishes");
  102. --                    return
  103. --                end;                
  104.                 
  105.                 if (getParent().isActionPointLocked(table, actionPointName)) then
  106.                     -- action point is locked
  107.                     print("takePlate action point is locked");
  108.                     setState("findDishes");
  109.                     return
  110.                 else
  111.                     getParent().lockActionPoint(table, actionPointName);
  112.                 end
  113.             else
  114.                 -- table does not exist anymore
  115.                 print("takePlate table does not exist anymore");
  116.                 setState("findDishes");
  117.                 return
  118.             end
  119.             
  120.             local dishes = getChildrenWithBehavior(table, "dish");
  121.             local dish = dishes[1];
  122.             if (dish) then
  123.                 storeStateObject("dish", dish);
  124.                 startAnimation("takePlate");
  125.                 sendDelayedMsgThis("grabPlate", 360);
  126.                 sendDelayedMsgThis("dropPlate", 840);
  127.             else
  128.                 setState("findDishes");
  129.                 return
  130.             end
  131.             
  132.         end )
  133.         
  134.         
  135.         onExit(function(msg)
  136.         
  137.             local table = retrieveStateObject("table");
  138.             if (table) then
  139.                 print("takePlate onExit table removed");
  140.                 getParent().unlockActionPoints(table);
  141.                 removeStateObject("table");
  142.             else        
  143.                 print("takePlate onExit table NOT removed");
  144.             end
  145.             
  146.             local dish = retrieveStateObject("dish");
  147.             if (dish) then
  148.                 print("takePlate onExit dish removed");
  149.                 removeStateObject("dish");
  150.             else        
  151.                 print("takePlate onExit dish NOT removed");
  152.             end
  153.             
  154.             
  155.         end )
  156.  
  157.         
  158.         onMsg("grabPlate", function(msg)
  159. --            local dish = retrieveStateObject("dish");
  160. --            removeStateObject("dish");
  161. --            dish.moveGameObject(getParent());
  162. --            getParent().attachLeftObjectHolder(dish);
  163.  
  164.             local dish = retrieveStateObject("dish");
  165.             removeStateObject("dish");
  166.             dish.deleteGameObject();
  167.             
  168.             dish = getParent().loadGameObject("StandardGO","plate");
  169.             getParent().attachLeftObjectHolder(dish);            
  170.         end )    
  171.         
  172.         onMsg("dropPlate", function(msg)
  173.         
  174.             local numDishes = retrieveData("numDishes", 0);
  175.             storeData("numDishes", numDishes+1);
  176.         
  177.             local dish = getParent().getLeftHeldObject();
  178.             getParent().detachLeftObjectHolder();
  179.             
  180.             getParent().playSound("stackPlates");
  181.             
  182.             local dishHeap = getParent().getRightHeldObject();
  183.             if (dishHeap) then
  184.                 print("right hand full, delete plate");
  185.                 dish.deleteGameObject();
  186.             else
  187.                 print("move to right hand");
  188.                 getParent().attachRightObjectHolder(dish);
  189.                 getParent().handSO.setPose("rightHandHoldPlate");
  190.             end
  191.         end )    
  192.          
  193.         onMsg("end", function(msg)
  194.             setState("findDishes");
  195.         end )    
  196.         
  197.  
  198.     state("gotoDishwasher")
  199.     
  200.         onEnter(function(msg)
  201.             print("gotoDishwasher");
  202.             local character = getParent();
  203.             local numDishes = retrieveData("numDishes", 0);
  204.             
  205.             local dishwasher = retrieveStateObject("dishwasher");
  206.             
  207.             
  208.             if ((numDishes < 1) and (getDish(dishwasher) < 1)) then
  209.                 freeHands(getParent());
  210.                 exitStateMachine();
  211.                 return
  212.             end
  213.             
  214.             --local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
  215.             local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
  216.             if (actionPoint) then
  217.                 if (walkToPointImmediate(actionPoint)) then
  218.                     storeData("actionPointName", actionPoint.getName());
  219.                     enterStateMachine("subwalk.walk");
  220.                     return
  221.                 else
  222.                     print("no path to dishwasher found");
  223.                     character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  224.                     sendMsg("emoThink", character.walkSO);
  225.                 end
  226.             else
  227.                 print("no load dishwasher action point found");
  228.                 character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  229.                 sendMsg("emoThink", character.walkSO);
  230.             end
  231.             
  232.             freeHands(getParent());
  233.             exitStateMachine();
  234.                         
  235.         end )
  236.  
  237.         onReturn(function(msg)
  238.             -- returned from subwalk to dishwasher/sink
  239. --            print("dish collecting character gotoDishwasher onReturn");
  240. --            local wsoContext = StateMachineContext();
  241. --            wsoContext.storeData("numDishes", retrieveData("numDishes", 0));
  242. --            queueStateMachine(retrieveData("washState"), retrieveStateObject("dishwasher"), wsoContext);
  243. --            exitStateMachine();
  244.             
  245.             setState("atDishwasher");
  246.         end )
  247.  
  248.  
  249.  
  250.  
  251.  
  252.     state("atDishwasher")
  253.     
  254.         onEnter(function(msg)
  255.             print("atDishwasher entering " .. retrieveData("washState"));
  256.             enterStateMachine(retrieveData("washState"));
  257.                         
  258.         end )
  259.  
  260.         onReturn(function(msg)
  261.             -- returned from  dishwasher/sink
  262.             print("dish collecting character atDishwasher onReturn");
  263.             exitStateMachine();
  264.         end )
  265.  
  266.         
  267.         
  268. --    state("gotoDishwasher")
  269. --    
  270. --        onEnter(function(msg)
  271. --            print("gotoDishwasher");
  272. --            local character = getParent();
  273. --            local numDishes = retrieveData("numDishes", 0);
  274. --            
  275. --            if (numDishes < 1) then
  276. --                freeHands(getParent());
  277. --                exitStateMachine();
  278. --                return
  279. --            end
  280. --            
  281. --            local dishwasher = retrieveStateObject("dishwasher");
  282. --            --local actionPoint = getParent().getFreeActionPoint(dishwasher, {"load","washHands"});
  283. --            local actionPoint = getParent().getClosestFreeActionPoint(getParent(), dishwasher, {"load","washHands"});
  284. --            if (actionPoint) then
  285. --                if (walkToActionPoint(actionPoint)) then
  286. --                    -- create state machine contexts
  287. --                    local wsoContext = StateMachineContext();
  288. --                    wsoContext.storeData("numDishes", numDishes);
  289. --                    queueStateMachine(retrieveData("washState"), dishwasher, wsoContext);
  290. --                    --queueStateMachine("dishwasherChar.load", dishwasher);
  291. --                    exitStateMachine();
  292. --                    return
  293. --                else
  294. --                    print("no path to dishwasher found");
  295. --                    character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  296. --                    sendMsg("emoThink", character.walkSO);
  297. --                end
  298. --            else
  299. --                print("no load dishwasher action point found");
  300. --                character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  301. --                sendMsg("emoThink", character.walkSO);
  302. --            end
  303. --            
  304. ----            local dishHeap = getParent().getRightHeldObject();
  305. ----            if (dishHeap) then dishHeap.deleteGameObject(); end
  306. ----            getParent().detachRightObjectHolder();
  307. --            freeHands(getParent());
  308. --            exitStateMachine();
  309. --                        
  310. --        end )
  311.             
  312.                 
  313. endStateMachine()
  314.