home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / sinkToilet.lua < prev    next >
Text File  |  2004-03-05  |  6KB  |  188 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_brushTeeth", "brushTeeth");
  14.         button.addDescription(ACTIVITY, "brushTeeth");
  15.         button = addPieMenuButton("pm_makeHair", "makeHair");
  16.         button.addDescription(ACTIVITY, "makeHair");
  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.         
  27.         -- check if activity if possible
  28.         local possible, result, activity = activityPossible(character, msg.name, this);
  29.         
  30.         -- don't care if timeslot is not fulfilled
  31.         if (possible or enumCompare(result, TIMESLOT)) then
  32.             -- if this is broken: abort characters action
  33.             if abortIfBroken(character) then return end;
  34.             -- walk to the closest action point
  35.             local actionPoint = character.getFreeActionPoint(this, "washHands");
  36.             if (actionPoint) then
  37.                 -- notify current mission 
  38.                 character.sendMsg("washHands", gameObjectServer.mission);
  39.                 
  40.                 -- get the walk state object
  41.                 local wso = character.walkSO;
  42.                 local wsoContext = StateMachineContext();
  43.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  44.                 if (wso.walkToActionPoint(actionPoint)) then
  45.                     wso.queueStateMachine("sinkChar.washHandsStart", this, wsoContext);
  46.                 else
  47.                     print("no path found");
  48.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  49.                 end
  50.             else
  51.                 print("no action point found");
  52.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  53.             end
  54.         else
  55.             -- activity not possible
  56.             print(msg.name .. " not possible");
  57.             
  58.             local emoticon;
  59.             if (enumCompare(result, NO_CONDITION)) then
  60.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  61.             else
  62.                 emoticon = EMOTICON_CANNOT;
  63.             end
  64.             instantAbort(character, emoticon, "emoThink");
  65.         end
  66.     end )
  67.             
  68.     onMsg("brushTeeth", function(msg)
  69.         -- get the game object server
  70.         local gameObjectServer = getGameObjectServer();
  71.         -- get character who initiated this action
  72.         local character = getStateObjectFromID(msg.sender);
  73.         
  74.         -- check if activity if possible
  75.         local possible, result, activity = activityPossible(character, msg.name, this);
  76.         
  77.         -- don't care if timeslot is not fulfilled
  78.         if (possible or enumCompare(result, TIMESLOT)) then
  79.             -- if this is broken: abort characters action
  80.             if abortIfBroken(character) then return end;
  81.             -- walk to the closest action point
  82.             local actionPoint = character.getFreeActionPoint(this, "washHands");
  83.             if (actionPoint) then
  84.                 -- get the walk state object
  85.                 local wso = character.walkSO;
  86.                 local wsoContext = StateMachineContext();
  87.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  88.                 if (wso.walkToActionPoint(actionPoint)) then
  89.                     wso.queueStateMachine("sinkChar.brushTeethStart", this, wsoContext);
  90.                 else
  91.                     print("no path found");
  92.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  93.                 end
  94.             else
  95.                 print("no action point found");
  96.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  97.             end
  98.         else
  99.             -- activity not possible
  100.             print(msg.name .. " not possible");
  101.             
  102.             local emoticon;
  103.             if (enumCompare(result, NO_CONDITION)) then
  104.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  105.             else
  106.                 emoticon = EMOTICON_CANNOT;
  107.             end
  108.             instantAbort(character, emoticon, "emoThink");    
  109.         end
  110.     end )
  111.     
  112.     
  113.     onMsg("makeHair", function(msg)
  114.         -- get the game object server
  115.         local gameObjectServer = getGameObjectServer();
  116.         -- get character who initiated this action
  117.         local character = getStateObjectFromID(msg.sender);
  118.         
  119.         -- check if activity if possible
  120.         local possible, result, activity = activityPossible(character, msg.name, this);
  121.         
  122.         -- don't care if timeslot is not fulfilled
  123.         if (possible or enumCompare(result, TIMESLOT)) then
  124.             -- if this is broken: abort characters action
  125.             if abortIfBroken(character) then return end;
  126.             -- walk to the closest action point
  127.             local actionPoint = character.getFreeActionPoint(this, "washHands");
  128.             if (actionPoint) then
  129.                 -- get the walk state object
  130.                 local wso = character.walkSO;
  131.                 local wsoContext = StateMachineContext();
  132.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  133.                 if (wso.walkToActionPoint(actionPoint)) then
  134.                     wso.queueStateMachine("sinkChar.makeHair", this, wsoContext);
  135.                 else
  136.                     print("no path found");
  137.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  138.                 end
  139.             else
  140.                 print("no action point found");
  141.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  142.             end
  143.         else
  144.             -- activity not possible
  145.             print(msg.name .. " not possible");
  146.             
  147.             local emoticon;
  148.             if (enumCompare(result, NO_CONDITION)) then
  149.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  150.             else
  151.                 emoticon = EMOTICON_CANNOT;
  152.             end
  153.             instantAbort(character, emoticon, "emoThink");
  154.         end
  155.     end )
  156.     
  157.     
  158.     -- repair
  159.     onMsg("repair", function(msg)
  160.     
  161.         print("onMsg repair");
  162.         -- get character who initiated this action
  163.         local character = getStateObjectFromID(msg.sender);
  164.         -- walk to the closest action point
  165.         local actionPoint = character.getFreeActionPoint(this, "repair");
  166.         -- get the walk state object
  167.         local wso = character.walkSO;
  168.         if (actionPoint) then
  169.             -- create state machine contexts
  170.             local wsoContext = StateMachineContext();
  171.             -- store the action point
  172.             wsoContext.storeData("actionPointName", actionPoint.getName());
  173.             if (wso.walkToActionPoint(actionPoint)) then
  174.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  175.             else
  176.                 print("no path found");
  177.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  178.             end
  179.         else
  180.             print("no action point found");
  181.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  182.         end
  183.     end )
  184.     
  185.     
  186.             
  187. endStateMachine()
  188.