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

  1. -- dishwasher 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_washDishes", "washDishes");
  13.         button.addDescription(ACTIVITY, "washDishes");     
  14.         button.addDescription(ACTIVITY, "improvePlateTidiness");
  15.         button.addIcon("guiIconWohnung");
  16.     end )
  17.  
  18.     -- 
  19.     onMsg("washDishes", function(msg)
  20.         -- get character who initiated this action
  21.         local character = getStateObjectFromID(msg.sender);             
  22.         -- if this is broken: abort characters action
  23.         if abortIfBroken(character) then return end;    
  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.             local wsoContext = StateMachineContext();
  33.             
  34.             wsoContext.storeData("washState", "dishwasherChar.washDishes");
  35.             wso.queueStateMachine("collectDishesChar.findDishes", this, wsoContext);
  36.         else
  37.             -- activity not possible
  38.             print(msg.name .. " not possible");
  39.             
  40.             local emoticon;
  41.             if (enumCompare(result, NO_CONDITION)) then
  42.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  43.             else
  44.                 emoticon = EMOTICON_CANNOT;
  45.             end
  46.             instantAbort(character, emoticon, "emoThink");
  47.         end
  48.     end )
  49.  
  50.     -- repair
  51.     onMsg("repair", function(msg)
  52.     
  53.         print("onMsg repair");
  54.         -- get character who initiated this action
  55.         local character = getStateObjectFromID(msg.sender);
  56.         -- walk to the closest action point
  57.         local actionPoint = character.getFreeActionPoint(this, "repair");
  58.         -- get the walk state object
  59.         local wso = character.walkSO;
  60.         if (actionPoint) then
  61.             -- create state machine contexts
  62.             local wsoContext = StateMachineContext();
  63.             -- store the action point
  64.             wsoContext.storeData("actionPointName", actionPoint.getName());
  65.             if (wso.walkToActionPoint(actionPoint)) then
  66.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  67.             else
  68.                 print("no path found");
  69.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  70.             end
  71.         else
  72.             print("no action point found");
  73.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  74.         end
  75.     end )
  76.                 
  77.             
  78. endStateMachine()
  79.