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

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