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

  1. -- computer state machine
  2.  
  3. beginStateMachine()
  4.  
  5.  
  6.     onEnter(function(msg)
  7.         setState("off");
  8.     end )
  9.  
  10.     
  11.     onMsg("buildMenu", function(msg)
  12.     
  13.         if (repairMenu()) then return end
  14.         
  15.         local character = getStateObjectFromID(msg.sender);
  16.     
  17.         -- build the pie menu
  18.         clearPieMenu();
  19.         local button ;
  20.         
  21. --        button = addPieMenuButton("pm_chat", "chat");
  22. --        button.addDescription(ACTIVITY, "chatComputer");
  23. --
  24. --        button = addPieMenuButton("pm_play", "play");
  25. --        button.addDescription(ACTIVITY, "playComputer");
  26.         
  27.         --local isUsing = isUser(character, this, PC_ACTIVITIES);
  28.  
  29.  
  30.  
  31.         if (not isUser(character, this, {"playComputer"})) then
  32.             button = addPieMenuButton("pm_play", "use", "play");
  33.             button.addDescription(ACTIVITY, "playComputer");
  34.             --if (isUsing) then button.addDescription(DONTQUEUE, "true"); end;
  35.         end
  36.         
  37.         if (not isUser(character, this, {"chatComputer"})) then
  38.             button = addPieMenuButton("pm_chat", "use", "chat");
  39.             button.addDescription(ACTIVITY, "chatComputer");
  40.             --if (isUsing) then button.addDescription(DONTQUEUE, "true"); end;
  41.         end
  42.         
  43.         
  44.     end )
  45.     
  46.     -- chat on the computer
  47.     onMsg("use", function(msg)
  48.         -- get the game object server
  49.         local gameObjectServer = getGameObjectServer();
  50.         -- get character who initiated this action
  51.         local character = getStateObjectFromID(msg.sender);
  52.         
  53.         -- check if activity if possible
  54.         local possible, result, activity = activityPossible(character, msg.data .. "Computer", this);
  55.  
  56.         -- don't care if timeslot is not fulfilled
  57.         if (possible or enumCompare(result, TIMESLOT)) then
  58.             -- get the walk state object
  59.             local wso = character.walkSO;
  60.             -- which program to use
  61.             local program = msg.data;
  62.             
  63.     --        if (isUser(character, this, PC_ACTIVITIES)) then
  64.     --            --character allready using this PC:  send switch msg
  65.     --            print(" PC onMsg use is User" .. wso.getStateMachine().getName() .. "." .. wso.getState());    
  66.     --            sendMsg("switch", wso, msg.data);
  67.     --        else        
  68.                 -- check if computer is on table and retrieve the chair
  69.                 local chair = getChairForItemOnTable(this);
  70.                 if (chair) then
  71.                     -- get the chairs action point
  72.                     local actionPoint = character.getClosestFreeActionPoint(character, chair, {"sit1", "sit2"} );
  73.                     if (actionPoint) then
  74.                         if (wso.walkToActionPoint(actionPoint)) then
  75.                             -- create state machine contexts
  76.                             local wsoContext = StateMachineContext();
  77.                             -- store the action point
  78.                             wsoContext.storeData("actionPointName", actionPoint.getName());
  79.                             wsoContext.storeData("program", program);
  80.                                                     
  81.                             wso.queueStateMachine("computerChar.sitDown", this, wsoContext);
  82.                         else
  83.                             print("no path found");
  84.                             instantAbort(character, EMOTICON_NOPATH, "emoThink")
  85.                         end
  86.                     else
  87.                         print("no action point found");
  88.                         instantAbort(character, EMOTICON_CANNOT, "emoThink")
  89.                     end
  90.                 else 
  91.                     print("no chair found");
  92.                     instantAbort(character, EMOTICON_NOSEAT, "emoThink")
  93.                 end
  94.             else
  95.                 -- activity not possible
  96.                 print(msg.data .. "Computer" .. " not possible");
  97.                 
  98.                 local emoticon;
  99.                 if (enumCompare(result, NO_CONDITION)) then
  100.                     emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  101.                 else
  102.                     emoticon = EMOTICON_CANNOT;
  103.                 end
  104.                 instantAbort(character, emoticon, "emoThink");
  105.             end
  106. --        end
  107.         
  108.         
  109.     end )
  110.     
  111. --    -- play on the computer
  112. --    onMsg("play", function(msg)
  113. --                -- get the game object server
  114. --        local gameObjectServer = getGameObjectServer();
  115. --        -- get character who initiated this action
  116. --        local character = getStateObjectFromID(msg.sender);
  117. --        -- check if computer is on table and retrieve the chair
  118. --        local chair = getChairForItemOnTable(this);
  119. --        if (chair) then
  120. --            -- get the chairs action point
  121. --            local actionPoint = character.getClosestFreeActionPoint(character, chair, {"sit1", "sit2"});
  122. --            -- get the walk state object
  123. --            local wso = character.walkSO;
  124. --            if (actionPoint) then
  125. --                -- create state machine contexts
  126. --                local wsoContext = StateMachineContext();
  127. --                -- store the action point
  128. --                wsoContext.storeData("actionPointName", actionPoint.getName());
  129. --                if (wso.walkToActionPoint(actionPoint)) then
  130. --                    wso.queueStateMachine("computerChar.sitDownPlay", this, wsoContext);
  131. --                else
  132. --                    print("no path found");
  133. --                    instantAbort(character, EMOTICON_NOPATH, "emoThink")
  134. --                end
  135. --            else
  136. --                print("no action point found");
  137. --                instantAbort(character, EMOTICON_CANNOT, "emoThink")
  138. --            end
  139. --        else 
  140. --            print("no chair found");
  141. --            instantAbort(character, EMOTICON_NOSEAT, "emoThink")
  142. --        end
  143. --    end )
  144.     
  145.     
  146.     
  147.     
  148.     state("off")
  149.     
  150.         onEnter(function(msg)
  151.             print("Comp off enter ----------------------------");            
  152.             replaceTexture("tvOff", "tvOff");            
  153.             --stopAllSounds();
  154.         end )
  155.     
  156.         
  157.         onExit(function(msg)
  158.             playSound("computerStartup");
  159.         end )        
  160.         
  161.     state("play")
  162.     
  163.         onEnter(function(msg)
  164.             print("Comp play enter ----------------------------");
  165.             sendMsgThis("startAnim");
  166.         end )
  167.         
  168.         onExit(function(msg)
  169.         end )        
  170.         
  171.         
  172.         onMsg("startAnim", function(msg)
  173.             startAnim({"pcGame1", "pcGame2", "pcGame3", "pcGame4", "pcGame3", "pcGame2"});
  174.         end )
  175.     
  176.         onMsg("showPic", function(msg)
  177.             replaceTexture("tvOff", msg.data);
  178.         end )
  179.     
  180.     
  181.     state("chat")
  182.     
  183.         onEnter(function(msg)
  184.             print("Comp chat enter ----------------------------");
  185.             sendMsgThis("startAnim");
  186.         end )
  187.         
  188.         onExit(function(msg)
  189.         end )        
  190.         
  191.         
  192.         onMsg("startAnim", function(msg)
  193.             startAnim({"pcChat1", "pcChat2", "pcChat3", "pcChat4"}, 3000);
  194.         end )
  195.     
  196.         onMsg("showPic", function(msg)
  197.             replaceTexture("tvOff", msg.data);
  198.         end )
  199.     
  200.     
  201.     
  202.     
  203.             
  204. endStateMachine()
  205.