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

  1. -- find chair at table character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         local chairCommand = retrieveData("chairCommand", "chairChar.sitDown");    
  7.         print("tableChairChar on Enter chairCommand:" .. chairCommand);                    
  8.     end )
  9.     
  10.     onExit(function(msg)
  11.         print("tableChairChar on Exit chairCommand");                    
  12.         removeStateObject("tableObject");
  13.     end )
  14.     
  15.  
  16.  
  17.     -- find a chair to sit down
  18.     state("findChair")
  19.     
  20.         onEnter(function(msg)
  21.         
  22.             local character = getParent();
  23.             local tableObject = retrieveStateObject("tableObject");
  24.             local checkPartnerChair = retrieveData("checkPartnerChair", false);
  25.             
  26.             print("findChair checkPartnerChair " .. tostring(checkPartnerChair));
  27.             
  28.             -- try first to get a table with a partner chair        
  29.             local table, tableActionPointName, chair = getNextFreeChairByTable(character, tableObject, checkPartnerChair);
  30.             -- if failed try any table
  31.             if (not chair and checkPartnerChair) then
  32.                 table, tableActionPointName, chair = getNextFreeChairByTable(character, tableObject);
  33.             end
  34.             
  35.             if (chair) then
  36.                 
  37.                 -- go to chair
  38.                 local actionPoint = getParent().getClosestFreeActionPoint(character, chair, {"sit1", "sit2"});
  39.                 if (actionPoint) then
  40.                 
  41.                     print("free chair found , ap:" .. actionPoint.getName());
  42.                                             
  43.                     if (walkToActionPoint(actionPoint)) then
  44.                     
  45.                     
  46.                         local wsoContext = StateMachineContext();
  47.                         -- store the action point                        
  48.                         wsoContext.storeStateObject("chair", chair);
  49.                         wsoContext.storeStateObject("table", table);
  50.                         wsoContext.storeData("tableActionPointName", tableActionPointName);
  51.                         wsoContext.storeData("chairActionPointName", actionPoint.getName());
  52.                     
  53.                         queueStateMachine(retrieveData("chairCommand", "chairChar.sitDown"), this, wsoContext);
  54.                         exitStateMachine();
  55.                         
  56.  
  57.                     else
  58.                         -- no path to chair was found
  59.                         character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  60.                         --sendMsg("emoThink", character.walkSO);
  61.                         --sendDelayedMsgThis("cancelFind", 2000);
  62.                         setState("fail");
  63.                     end
  64.                                             
  65.                 else
  66.                     character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  67.                     --sendMsg("emoThink", character.walkSO);
  68.                     --sendDelayedMsgThis("cancelFind", 2000);
  69.                     setState("fail");
  70.                 end
  71.                 
  72.             else
  73.                 character.setEmoticon(EMOTICON_NOSEAT, EMOTICON_DELAY);
  74.                 --sendMsg("emoThink", character.walkSO);
  75.                 --sendDelayedMsgThis("cancelFind", EMOTICON_DELAY);
  76.                 setState("fail");
  77.             end                
  78.         
  79.         end )
  80.     
  81.  
  82.  
  83.     state("fail")
  84.     
  85.         onEnter(function(msg)
  86.             startAnimation("emoThink");
  87.         end )
  88.     
  89.         onMsg("end", function(msg)
  90.             freeHands(getParent());
  91.             exitAndGoAway();
  92.         end )    
  93.  
  94.  
  95.             
  96.                 
  97. endStateMachine()
  98.