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

  1. -- hoover 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.         button = addPieMenuButton("pm_cleanFloor", "cleanFloor");
  13.         button.addDescription(ACTIVITY, "cleanFloor");        
  14.         button.addDescription(ACTIVITY, "improveFloorTidiness");        
  15.         button.addIcon("guiIconWohnung");
  16.     end )
  17.  
  18.     -- 
  19.     onMsg("cleanFloor", function(msg)
  20.         -- get the game object server
  21.         local gameObjectServer = getGameObjectServer();
  22.         -- get character who initiated this action
  23.         local character = getStateObjectFromID(msg.sender);
  24.         
  25.         -- check if activity if possible
  26.         local possible, result, activity = activityPossible(character, msg.name, this);
  27.  
  28.         -- don't care if timeslot is not fulfilled
  29.         if (possible or enumCompare(result, TIMESLOT)) then
  30.             -- get the walk state object
  31.             local wso = character.walkSO;
  32.             
  33.             local holds, hand = holdsObject(character, "hoover")
  34.             if (holds) then
  35.                 wso.queueStateMachine("cleanFloorChar.findDirt", this);
  36.             else
  37.                 -- walk to the closest action point
  38.                 local actionPoint = character.getFreeActionPoint(this, "take");
  39.                 local wsoContext = StateMachineContext();
  40.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  41.                 if (actionPoint) then
  42.                     if (wso.walkToActionPoint(actionPoint)) then
  43.                         wso.queueStateMachine("cleanFloorChar.takeHoover", this, wsoContext);
  44.                     else
  45.                         print("no path found");
  46.                         instantAbort(character, EMOTICON_NOPATH, "emoThink")
  47.                     end
  48.                 else
  49.                     print("no action point found");
  50.                     instantAbort(character, EMOTICON_CANNOT, "emoThink")
  51.                 end
  52.             end
  53.         else
  54.             -- activity not possible
  55.             print(msg.name .. " not possible");
  56.             
  57.             local emoticon;
  58.             if (enumCompare(result, NO_CONDITION)) then
  59.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  60.             else
  61.                 emoticon = EMOTICON_CANNOT;
  62.             end
  63.             instantAbort(character, emoticon, "emoThink");    
  64.         end
  65.     end )
  66.             
  67.             
  68. endStateMachine()
  69.