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

  1. -- table state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         
  13.         if (this.getDirtiness() > 0.01) then 
  14.             button = addPieMenuButton("pm_clean", "clean");
  15.             button.addDescription(ACTIVITY, "clean");    
  16.             button.addDescription(ACTIVITY, "improveObjectTidiness");
  17.             button.addIcon("guiIconWohnung");
  18.         end;
  19.         
  20.     end )
  21.     
  22.     onMsg("clean", function(msg)
  23.         -- get the game object server
  24.         local gameObjectServer = getGameObjectServer();
  25.         -- get character who initiated this action
  26.         local character = getStateObjectFromID(msg.sender);
  27.         -- if character is too unhappy: abort characters action
  28.         if instantAbortIfUnhappy(character, "clean", this) then return end;
  29.         -- walk to the closest action point
  30.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"chair1", "chair2", "chair3", "chair4", "chair5", "chair6", "front1", "front2"});
  31.         -- get the walk state object
  32.         local wso = character.walkSO;
  33.         if (actionPoint) then
  34.             -- create state machine contexts
  35.             local wsoContext = StateMachineContext();
  36.             -- store the action point
  37.             wsoContext.storeData("actionPointName", actionPoint.getName());
  38.             
  39.             if (wso.walkToActionPoint(actionPoint)) then
  40.                 wso.queueStateMachine("tableChar.clean", this, wsoContext);
  41.             else
  42.                 print("no path found");
  43.                 --queueNextClean(character);
  44.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.             end
  46.         else
  47.             print("no action point found");
  48.             --queueNextClean(character);
  49.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  50.         end
  51.     end )
  52.         
  53.             
  54. endStateMachine()
  55.