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

  1. -- camera 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_callFriends", "callFriends");
  12.         button.addDescription(ACTIVITY, "callFriends");
  13.         button = addPieMenuButton("pm_callPizza", "callPizza");
  14.         button.addDescription(ACTIVITY, "eatPizza");
  15.         
  16.         
  17.         --button = addPieMenuButton("pm_callOffice", "callOffice");
  18.         -- button.addDescription(ACTIVITY, "callOffice");
  19.     end )
  20.  
  21.     -- 
  22.     onMsg("callFriends", function(msg)
  23.         -- get the game object server
  24.         local gameObjectServer = getGameObjectServer();
  25.         -- get character who initiated this action
  26.         local character = getStateObjectFromID(msg.sender);
  27.         
  28.         -- check if activity if possible
  29.         local possible, result, activity = activityPossible(character, msg.name, this);
  30.         
  31.         -- don't care if timeslot is not fulfilled
  32.         if (possible or enumCompare(result, TIMESLOT)) then
  33.             -- walk to the closest action point
  34.             --local actionPoint = character.getFreeActionPoint(this, "use");
  35.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"use1", "use2", "use3", "use4"});
  36.             if (actionPoint) then
  37.                 -- get the walk state object
  38.                 local wso = character.walkSO;
  39.                 if (wso.walkToActionPoint(actionPoint)) then
  40.                     -- create state machine contexts
  41.                     local wsoContext = StateMachineContext();
  42.                     -- store the action point
  43.                     wsoContext.storeData("actionPointName", actionPoint.getName());
  44.                     wso.queueStateMachine("phoneChar.callFriendsStart", this, wsoContext);
  45.                 else
  46.                     print("no path found");
  47.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  48.                 end
  49.             else
  50.                 print("no action point found");
  51.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  52.             end
  53.         else
  54.             -- activity not possible
  55.             print(msg.name .. " not possible");
  56.             
  57.             local emoticon;
  58.             if (enumCompare(result, NO_CONDITION)) then
  59.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  60.             else
  61.                 emoticon = EMOTICON_CANNOT;
  62.             end
  63.             instantAbort(character, emoticon, "emoThink");    
  64.         end
  65.     end )
  66.     
  67.     
  68.     onMsg("callPizza", 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.             -- walk to the closest action point
  80.             --local actionPoint = character.getFreeActionPoint(this, "use");
  81.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"use1", "use2", "use3", "use4"});
  82.             if (actionPoint) then
  83.                 -- get the walk state object
  84.                 local wso = character.walkSO;
  85.                 if (wso.walkToActionPoint(actionPoint)) then
  86.                     -- create state machine contexts
  87.                     local wsoContext = StateMachineContext();
  88.                     -- store the action point
  89.                     wsoContext.storeData("actionPointName", actionPoint.getName());
  90.                     wso.queueStateMachine("phoneChar.callPizzaStart", this, wsoContext);
  91.                 else
  92.                     print("no path found");
  93.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  94.                 end
  95.             else
  96.                 print("no action point found");
  97.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  98.             end
  99.         else
  100.             -- activity not possible
  101.             print(msg.name .. " not possible");
  102.             
  103.             local emoticon;
  104.             if (enumCompare(result, NO_CONDITION)) then
  105.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  106.             else
  107.                 emoticon = EMOTICON_CANNOT;
  108.             end
  109.             instantAbort(character, emoticon, "emoThink");
  110.         end
  111.     end )
  112.     
  113. --    onMsg("callOffice", 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. --        -- walk to the closest action point
  119. --        local actionPoint = character.getFreeActionPoint(this, "use");
  120. --        if (actionPoint) then
  121. --            -- get the walk state object
  122. --            local wso = character.walkSO;
  123. --            if (wso.walkToActionPoint(actionPoint)) then
  124. --                wso.queueStateMachine("phoneChar.callOffice", this);
  125. --            else
  126. --                print("no path found");
  127. --                instantAbort(character, EMOTICON_NOPATH, "emoThink")
  128. --            end
  129. --        else
  130. --            print("no action point found");
  131. --            instantAbort(character, EMOTICON_CANNOT, "emoThink")
  132. --        end
  133. --    end )
  134.             
  135.             
  136. endStateMachine()
  137.