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

  1. -- toilet 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_sitToilet", "sitToilet");
  13.         button.addDescription(ACTIVITY, "sitToilet");
  14.         -- button.addIcon("guiIconHygiene");
  15.         
  16.         if (this.getDirtiness() > 0.01) then 
  17.             button = addPieMenuButton("pm_clean", "clean");
  18.             button.addDescription(ACTIVITY, "clean");         
  19.             button.addDescription(ACTIVITY, "improveObjectTidiness");            
  20.             button.addIcon("guiIconWohnung");
  21.         end;
  22.         -- button.addIcon("guiIconWohnung");
  23.     end )
  24.     
  25.     -- sit on toilet
  26.     onMsg("sitToilet", function(msg)
  27.         -- get the game object server
  28.         local gameObjectServer = getGameObjectServer();
  29.         -- get character who initiated this action
  30.         local character = getStateObjectFromID(msg.sender);
  31.         -- check if activity if possible
  32.         local possible, result, activity = activityPossible(character, msg.name, this);
  33.         
  34.         -- don't care if timeslot is not fulfilled
  35.         if (possible or enumCompare(result, TIMESLOT)) then
  36.             -- if this is broken: abort characters action
  37.             if abortIfBroken(character) then return end;        
  38.             -- walk to the closest action point
  39.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit"});
  40.             if (actionPoint) then
  41.                 -- get the walk state object
  42.                 local wso = character.walkSO;
  43.                 local wsoContext = StateMachineContext();
  44.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  45.                 if (wso.walkToActionPoint(actionPoint)) then
  46.                     wso.queueStateMachine("toiletChar.sitDown", this, wsoContext);
  47.                 else
  48.                     print("no path found");
  49.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  50.                 end
  51.             else
  52.                 print("no action point found");
  53.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  54.             end
  55.         else
  56.             -- activity not possible
  57.             print(msg.name .. " not possible");
  58.             
  59.             local emoticon;
  60.             if (enumCompare(result, NO_CONDITION)) then
  61.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  62.             else
  63.                 emoticon = EMOTICON_CANNOT;
  64.             end
  65.             instantAbort(character, emoticon, "emoThink");
  66.         end
  67.     end )
  68.     
  69.     
  70.     -- clean on toilet
  71.     onMsg("clean", function(msg)
  72.         -- get the game object server
  73.         local gameObjectServer = getGameObjectServer();
  74.         -- get character who initiated this action
  75.         local character = getStateObjectFromID(msg.sender);
  76.         -- check if activity if possible
  77.         local possible, result, activity = activityPossible(character, msg.name, this);
  78.         
  79.         -- don't care if timeslot is not fulfilled
  80.         if (possible or enumCompare(result, TIMESLOT)) then
  81.             -- if this is broken: abort characters action
  82.             if abortIfBroken(character) then return end;
  83.             -- if character is too unhappy: abort characters action
  84.             if instantAbortIfUnhappy(character, "clean", this) then return end;
  85.             -- walk to the closest action point
  86.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"clean"});
  87.             if (actionPoint) then
  88.                 -- get the walk state object
  89.                 local wso = character.walkSO;
  90.                 local wsoContext = StateMachineContext();
  91.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  92.                 if (wso.walkToActionPoint(actionPoint)) then
  93.                     wso.queueStateMachine("toiletChar.cleanStart", this, wsoContext);
  94.                 else
  95.                     print("no path found");
  96.                     --queueNextClean(character);
  97.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  98.     --                character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  99.     --                sendMsg("emoThink", character.walkSO);
  100.                 end
  101.             else
  102.                 print("no action point found");
  103.                 --queueNextClean(character);
  104.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  105.     --            character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  106.     --            sendMsg("emoThink", character.walkSO);
  107.             end
  108.         else
  109.             -- activity not possible
  110.             print(msg.name .. " not possible");
  111.             
  112.             local emoticon;
  113.             if (enumCompare(result, NO_CONDITION)) then
  114.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  115.             else
  116.                 emoticon = EMOTICON_CANNOT;
  117.             end
  118.             instantAbort(character, emoticon, "emoThink");
  119.         end
  120.     end )
  121.     
  122.     
  123.     
  124.     -- repair
  125.     onMsg("repair", function(msg)
  126.     
  127.         print("onMsg repair");
  128.         -- get character who initiated this action
  129.         local character = getStateObjectFromID(msg.sender);
  130.         -- walk to the closest action point
  131.         local actionPoint = character.getFreeActionPoint(this, "repair");
  132.         -- get the walk state object
  133.         local wso = character.walkSO;
  134.         if (actionPoint) then
  135.             -- create state machine contexts
  136.             local wsoContext = StateMachineContext();
  137.             -- store the action point
  138.             wsoContext.storeData("actionPointName", actionPoint.getName());
  139.             if (wso.walkToActionPoint(actionPoint)) then
  140.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  141.             else
  142.                 print("no path found");
  143.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  144.             end
  145.         else
  146.             print("no action point found");
  147.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  148.         end
  149.     end )
  150.                         
  151. endStateMachine()
  152.