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

  1. -- bed  state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         local currentCharacter = getStateObjectFromID(msg.sender);
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button;
  11.         local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
  12.         
  13.         if currentCharacter and (currentCharacter.timeForWork() or neverFail) then
  14.             button = addPieMenuButton("pm_gotoWork", "work");
  15.             button.addDescription(ACTIVITY, "work");
  16.             button.addDescription(NO_NEGATIVE_ICON, "NEED_HUNGER");
  17.         end
  18.         
  19.         if currentCharacter and (canLeave(currentCharacter) or neverFail) then
  20.             button = addPieMenuButton(getLeaveButtonText(this), "changeHouse", "active");
  21.             button.addDescription(NO_AI, "true");
  22.         end
  23.         
  24. --        if canGoTo(CITY, this) then
  25. --            button = addPieMenuButton("pm_gotoCity", "changeHouse");
  26. --        end
  27.         
  28.         
  29.         --button = addPieMenuButton("Einkaufen gehen", "shop"); -- no game play function yet
  30.         -- button.addDescription(ACTIVITY, "shop");
  31.         
  32.         --button = addPieMenuButton("pm_goOut", "out");
  33.         -- button.addDescription(ACTIVITY, "out");
  34.         
  35.         local otherCharacter = getOtherCharacter(currentCharacter);
  36.         if (otherCharacter and activityPossible(currentCharacter, "giveGift", otherCharacter)) then
  37.             button = addPieMenuButton("pm_goBuyGift", "gift");
  38.             button.addDescription(ACTIVITY, "buyGift");
  39.             button.addDescription(NO_AI, "true");
  40.         end;
  41.     end )
  42.     
  43.     -- go to work
  44.     onMsg("work", function(msg)
  45.         -- get the game object server
  46.         local gameObjectServer = getGameObjectServer();
  47.         -- get character who initiated this action
  48.         local character = getStateObjectFromID(msg.sender);
  49.         
  50.         -- check if activity if possible
  51.         local possible, result, activity = activityPossible(character, msg.name, this);
  52.         
  53.         -- don't care if timeslot is not fulfilled
  54.         if (possible or enumCompare(result, TIMESLOT)) then
  55.             local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
  56.             if (not character.timeForWork()) and (not neverFail) then
  57.                 print("not time for work");
  58.                 instantAbort(character, EMOTICON_CANNOT, "emoThink");
  59.                 return
  60.             end
  61.             
  62.             -- if character is too unhappy: abort characters action
  63.             if instantAbortIfUnhappy(character, "work", this) then return end;
  64.             -- walk to the closest action point
  65.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  66.             if (actionPoint) then
  67.             -- get the walk state object
  68.                 local wso = character.walkSO;
  69.                 -- create state machine contexts
  70.                 local wsoContext = StateMachineContext();
  71.                 -- store the action point
  72.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  73.                 if (wso.walkToActionPoint(actionPoint)) then
  74.                     wso.queueStateMachine("staircaseChar.goToWork", this, wsoContext);
  75.                 else
  76.                     print("no path found");
  77.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  78.                 end
  79.             else
  80.                 print("no action point found");
  81.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  82.             end
  83.         else
  84.             -- activity not possible
  85.             print(msg.name .. " not possible");
  86.             
  87.             local emoticon;
  88.             if (enumCompare(result, NO_CONDITION)) then
  89.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  90.             else
  91.                 emoticon = EMOTICON_CANNOT;
  92.             end
  93.             instantAbort(character, emoticon, "emoThink");
  94.         end
  95.     end )
  96.     
  97.     -- go shopping
  98.     onMsg("shop", function(msg)
  99.         -- get the game object server
  100.         local gameObjectServer = getGameObjectServer();
  101.         -- get character who initiated this action
  102.         local character = getStateObjectFromID(msg.sender);
  103.         
  104.         -- check if activity if possible
  105.         local possible, result, activity = activityPossible(character, msg.name, this);
  106.         
  107.         -- don't care if timeslot is not fulfilled
  108.         if (possible or enumCompare(result, TIMESLOT)) then
  109.             -- walk to the closest action point
  110.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  111.             if (actionPoint) then
  112.             -- get the walk state object
  113.                 local wso = character.walkSO;
  114.                 -- create state machine contexts
  115.                 local wsoContext = StateMachineContext();
  116.                 -- store the action point
  117.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  118.                 if (wso.walkToActionPoint(actionPoint)) then
  119.                     wso.queueStateMachine("staircaseChar.goToShop", this, wsoContext);
  120.                 else
  121.                     print("no path found (in staircase.lua onMsg shop)");
  122.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  123.                 end
  124.             else
  125.                 print("no action point found (in staircase.lua onMsg shop)");
  126.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  127.             end
  128.         else
  129.             -- activity not possible
  130.             print(msg.name .. " not possible");
  131.             
  132.             local emoticon;
  133.             if (enumCompare(result, NO_CONDITION)) then
  134.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  135.             else
  136.                 emoticon = EMOTICON_CANNOT;
  137.             end
  138.             instantAbort(character, emoticon, "emoThink");
  139.         end
  140.     end )
  141.     
  142.     -- go shopping
  143.     onMsg("out", function(msg)
  144.         -- get the game object server
  145.         local gameObjectServer = getGameObjectServer();
  146.         -- get character who initiated this action
  147.         local character = getStateObjectFromID(msg.sender);
  148.         
  149.         -- check if activity if possible
  150.         local possible, result, activity = activityPossible(character, msg.name, this);
  151.         
  152.         -- don't care if timeslot is not fulfilled
  153.         if (possible or enumCompare(result, TIMESLOT)) then
  154.             -- walk to the closest action point
  155.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  156.             if (actionPoint) then
  157.             -- get the walk state object
  158.                 local wso = character.walkSO;
  159.                 -- create state machine contexts
  160.                 local wsoContext = StateMachineContext();
  161.                 -- store the action point
  162.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  163.                 if (wso.walkToActionPoint(actionPoint)) then
  164.                     wso.queueStateMachine("staircaseChar.goToShop", this, wsoContext);
  165.                 else
  166.                     print("no path found (in staircase.lua onMsg shop)");
  167.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  168.                 end
  169.             else
  170.                 print("no action point found (in staircase.lua onMsg shop)");
  171.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  172.             end
  173.         else
  174.             -- activity not possible
  175.             print(msg.name .. " not possible");
  176.             
  177.             local emoticon;
  178.             if (enumCompare(result, NO_CONDITION)) then
  179.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  180.             else
  181.                 emoticon = EMOTICON_CANNOT;
  182.             end
  183.             instantAbort(character, emoticon, "emoThink");
  184.         end
  185.     end )
  186.  
  187.  
  188.     -- go shopping
  189.     onMsg("gift", function(msg)
  190.         -- get the game object server
  191.         local gameObjectServer = getGameObjectServer();
  192.         -- get character who initiated this action
  193.         local character = getStateObjectFromID(msg.sender);
  194.         
  195.         -- check if activity if possible
  196.         local possible, result, activity = activityPossible(character, "buyGift", this);
  197.         
  198.         -- don't care if timeslot is not fulfilled
  199.         if (possible or enumCompare(result, TIMESLOT)) then
  200.             -- walk to the closest action point
  201.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  202.             if (actionPoint) then
  203.             -- get the walk state object
  204.                 local wso = character.walkSO;
  205.                 -- create state machine contexts
  206.                 local wsoContext = StateMachineContext();
  207.                 -- store the action point
  208.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  209.                 if (wso.walkToActionPoint(actionPoint)) then
  210.                     wso.queueStateMachine("staircaseChar.goBuyGift", this, wsoContext);
  211.                 else
  212.                     print("no path found (in staircase.lua onMsg gift)");
  213.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  214.                 end
  215.             else
  216.                 print("no action point found (in staircase.lua onMsg gift)");
  217.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  218.             end
  219.         else
  220.             -- activity not possible
  221.             print("buyGift not possible");
  222.             
  223.             local emoticon;
  224.             if (enumCompare(result, NO_CONDITION)) then
  225.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  226.             else
  227.                 emoticon = EMOTICON_CANNOT;
  228.             end
  229.             instantAbort(character, emoticon, "emoThink");
  230.         end
  231.     end )
  232.     
  233.     
  234.     -- go shopping
  235.     onMsg("changeHouse", function(msg)
  236.         -- get the game object server
  237.         local gameObjectServer = getGameObjectServer();
  238.         -- get character who initiated this action
  239.         local character = getStateObjectFromID(msg.sender);
  240.         
  241.         -- check if activity if possible
  242.         local possible, result, activity = activityPossible(character, msg.name, this);
  243.         
  244.         -- don't care if timeslot is not fulfilled
  245.         if (possible or enumCompare(result, TIMESLOT)) then
  246.             -- walk to the closest action point
  247.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
  248.             if (actionPoint) then
  249.             -- get the walk state object
  250.                 local wso = character.walkSO;
  251.                 -- create state machine contexts
  252.                 local wsoContext = StateMachineContext();
  253.                 -- store the action point
  254.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  255.                 wsoContext.storeData("activePart", not(msg.data == ""));
  256.                 if (wso.walkToActionPoint(actionPoint)) then
  257.                     wso.queueStateMachine("staircaseChar.goToOtherHouse", this, wsoContext);
  258.                 else
  259.                     print("no path found (in staircase.lua onMsg gift)");
  260.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  261.                 end
  262.             else
  263.                 print("no action point found (in staircase.lua onMsg gift)");
  264.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  265.             end
  266.         else
  267.             -- activity not possible
  268.             print(msg.name .. " not possible");
  269.             
  270.             local emoticon;
  271.             if (enumCompare(result, NO_CONDITION)) then
  272.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  273.             else
  274.                 emoticon = EMOTICON_CANNOT;
  275.             end
  276.             instantAbort(character, emoticon, "emoThink");
  277.         end
  278.     end )
  279.     
  280.     
  281.     
  282.             
  283. endStateMachine()
  284.