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

  1. -- sink 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.         button = addPieMenuButton("pm_washHands", "washHands");
  12.         button.addDescription(ACTIVITY, "washHands");
  13.         button = addPieMenuButton("pm_washDishes", "washDishes");
  14.         button.addDescription(ACTIVITY, "washDishes");
  15.         button.addDescription(ACTIVITY, "improvePlateTidiness");
  16.         button.addIcon("guiIconWohnung");
  17.         -- button.addIcon("guiIconHygiene");
  18.     end )
  19.  
  20.     -- 
  21.     onMsg("washHands", function(msg)
  22.         -- get the game object server
  23.         local gameObjectServer = getGameObjectServer();
  24.         -- get character who initiated this action
  25.         local character = getStateObjectFromID(msg.sender);
  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.             -- if this is broken: abort characters action
  32.             if abortIfBroken(character) then return end;
  33.             -- walk to the closest action point
  34.             local actionPoint = character.getFreeActionPoint(this, "washHands");
  35.             if (actionPoint) then
  36.                 -- get the walk state object
  37.                 local wso = character.walkSO;
  38.                 local wsoContext = StateMachineContext();
  39.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  40.                 if (wso.walkToActionPoint(actionPoint)) then
  41.                     wso.queueStateMachine("sinkChar.washHandsStart", this, wsoContext);
  42.                 else
  43.                     print("no path found");
  44.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.                 end
  46.             else
  47.                 print("no action point found");
  48.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  49.     --            character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  50.     --            sendMsg("emoThink", character.walkSO);
  51.             end
  52.         else
  53.             -- activity not possible
  54.             print(msg.name .. " not possible");
  55.             
  56.             local emoticon;
  57.             if (enumCompare(result, NO_CONDITION)) then
  58.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  59.             else
  60.                 emoticon = EMOTICON_CANNOT;
  61.             end
  62.             instantAbort(character, emoticon, "emoThink");
  63.         end
  64.     end )
  65.     
  66. --    onMsg("washDishes", function(msg)
  67. --        -- get the game object server
  68. --        local gameObjectServer = getGameObjectServer();
  69. --        -- get character who initiated this action
  70. --        local character = getStateObjectFromID(msg.sender);
  71. --        -- walk to the closest action point
  72. --        local actionPoint = character.getFreeActionPoint(this, "washHands");
  73. --        if (actionPoint) then
  74. --            -- get the walk state object
  75. --            local wso = character.walkSO;
  76. --            if (wso.walkToActionPoint(actionPoint)) then
  77. --                wso.queueStateMachine("sinkChar.washDishes", this);
  78. --            else
  79. --                print("no path found");
  80. --                character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  81. --                sendMsg("emoThink", character.walkSO);
  82. --            end
  83. --        else
  84. --            print("no action point found");
  85. --            character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  86. --            sendMsg("emoThink", character.walkSO);
  87. --        end
  88. --    end )
  89.     
  90.     
  91.     onMsg("washDishes", function(msg)
  92.         -- get character who initiated this action
  93.         local character = getStateObjectFromID(msg.sender);
  94.         -- check if activity if possible
  95.         local possible, result, activity = activityPossible(character, msg.name, this);
  96.         
  97.         -- don't care if timeslot is not fulfilled
  98.         if (possible or enumCompare(result, TIMESLOT)) then
  99.             -- if this is broken: abort characters action
  100.             if abortIfBroken(character) then return end;
  101.             -- get the walk state object
  102.             local wso = character.walkSO;
  103.             local wsoContext = StateMachineContext();
  104.             wsoContext.storeData("washState", "sinkChar.washDishesStart");
  105.             wso.queueStateMachine("collectDishesChar.findDishes", this, wsoContext);
  106.     --wsoContext.storeData("numDishes", 2);
  107.     --wso.queueStateMachine("collectDishesChar.gotoDishwasher", this, wsoContext);
  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.     
  125.     
  126.     -- repair
  127.     onMsg("repair", function(msg)
  128.     
  129.         print("onMsg repair");
  130.         -- get character who initiated this action
  131.         local character = getStateObjectFromID(msg.sender);
  132.         -- walk to the closest action point
  133.         local actionPoint = character.getFreeActionPoint(this, "repair");
  134.         -- get the walk state object
  135.         local wso = character.walkSO;
  136.         if (actionPoint) then
  137.             -- create state machine contexts
  138.             local wsoContext = StateMachineContext();
  139.             wsoContext.storeData("actionPointName", actionPoint.getName());
  140.             if (wso.walkToActionPoint(actionPoint)) then
  141.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  142.             else
  143.                 print("no path found");
  144.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  145.             end
  146.         else
  147.             print("no action point found");
  148.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  149.         end
  150.     end )
  151.                         
  152.             
  153. endStateMachine()
  154.