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

  1. -- bed  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.     
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_sleep", "sleep");
  12.         button.addDescription(ACTIVITY, "sleep");
  13.         -- can always be selected by user
  14.         button.addDescription(ALWAYS_USERSELECTABLE, "true");
  15.         -- button.addIcon("guiIconComfort");
  16.  
  17.     end )
  18.     
  19.     -- lay on bed
  20.     onMsg("sleep", function(msg)
  21.         -- get the game object server
  22.         local gameObjectServer = getGameObjectServer();
  23.         -- get character who initiated this action
  24.         local character = getStateObjectFromID(msg.sender);
  25.         
  26.         -- check if activity if possible
  27.         local possible, result, activity = activityPossible(character, msg.name, this);
  28.  
  29.         -- don't care if timeslot is not fulfilled
  30.         if (possible or enumCompare(result, TIMESLOT)) then
  31.             -- walk to the closest action point
  32.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"layDown1", "layDown2"});
  33.             -- get the walk state object
  34.             local wso = character.walkSO;
  35.             if (actionPoint) then
  36.                 -- create state machine contexts
  37.                 local wsoContext = StateMachineContext();
  38.                 -- store the action point
  39.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  40.                 if (wso.walkToActionPoint(actionPoint)) then
  41.                     wso.queueStateMachine("bedChar.layDown", this, wsoContext);
  42.                 else
  43.                     print("no path found");
  44.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.                 end
  46.             else
  47.                 print("bed.lua no action point found of layDown1, layDown2");
  48.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  49.             end
  50.         else
  51.             -- activity not possible
  52.             print(msg.name .. " not possible");
  53.             
  54.             local emoticon;
  55.             if (enumCompare(result, NO_CONDITION)) then
  56.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  57.             else
  58.                 emoticon = EMOTICON_CANNOT;
  59.             end
  60.             instantAbort(character, emoticon, "emoThink");
  61.         end
  62.     end )
  63.             
  64. endStateMachine()
  65.