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

  1. -- camera character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local camera = getStateObjectFromID(msg.sender);
  6.         storeStateObject("camera", camera);
  7.         
  8.         if (camera) then
  9. --            -- camera does exist
  10. --            if (getParent().isOneActionPointLocked(camera)) then
  11. --                -- action point is locked
  12. --                getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  13. --                sendMsg("emoThink", getParent().walkSO);
  14. --                exitStateMachine();
  15. --            else
  16. --                getParent().lockActionPoints(camera);
  17. --            end
  18.         else
  19.             -- camera does not exist anymore
  20.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  21.             sendMsg("emoThink", getParent().walkSO);
  22.             exitStateMachine();
  23.         end
  24.         
  25.         freeHands(getParent());
  26.                 
  27.     end )
  28.     
  29.     onExit(function(msg)
  30. --        local camera = retrieveStateObject("camera");
  31. --        if (camera) then
  32. --            getParent().unlockActionPoints(camera);
  33. --            getParent().stopAllActivities(camera);
  34. --            removeStateObject("camera");
  35. --        end
  36.  
  37.         print("----- cameraChar onExit 1 " .. getParent().getCharacterName());            
  38.         unlockAll("camera");
  39.         print("----- cameraChar onExit 2 " .. getParent().getCharacterName());            
  40.         local partner = retrieveStateObject("partner");
  41.         if (partner) then
  42.             getParent().unlockActionPoints(partner.getParent());
  43.             getParent().stopAllActivities(partner.getParent());
  44.             removeStateObject("partner");
  45.         end;
  46.         
  47.         getParent().stopAllActivities();
  48.         
  49.     end )
  50.     
  51. --    state("waitForPartner")
  52. --    
  53. --        onEnter(function(msg)
  54. --            sendDelayedMsgThis("stopWaiting", 20000);
  55. --            this.actionComplete();
  56. --        end )
  57. --        
  58. --        onMsg("stopWaiting", function(msg)
  59. --            local camera = retrieveStateObject("camera");
  60. --            getParent().stopActivity("takePicture", camera);
  61. --            exitStateMachine();
  62. --        end )            
  63. --        
  64. --        onMsg("partnerReady", function(msg)
  65. --            setState("takePicture");
  66. --        end )    
  67. --
  68. --
  69. --        onMsg("queue", function(msg)
  70. --            sendMsgThis("stopWaiting");
  71. --        end )
  72.         
  73.  
  74.         
  75.             
  76.         
  77.         
  78.     state("waitForPartner")
  79.     
  80.         onEnter(function(msg)
  81.         
  82.             local camera = getStateObjectFromID(msg.sender);
  83.             
  84.             if exitIfWrongPosition(getParent(), camera, "use") then return end;    
  85.             
  86.             if (getParent().isActionPointLocked(camera, "use")) then
  87.                 -- action point is locked
  88.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  89.                 sendMsg("emoThink", getParent().walkSO);
  90.                 exitStateMachine();
  91.             else
  92.                 getParent().lockActionPoint(camera, "use");
  93.             end
  94.         
  95.             setPose(archize(getParent(),"stand1"));
  96.         
  97.             print("waitForPartner onEnter");
  98.                         
  99.             sendDelayedMsgThis("callPartner", 1000);
  100.             sendDelayedMsgThis("stopWaiting", 20000);
  101.             --this.actionComplete();
  102.             
  103.             startAnimation("emoSwingArms");
  104.         end )
  105.         
  106.         onMsg("end", function(msg)
  107.             startAnimation("emoSwingArms");
  108.         end )
  109.         
  110.         onMsg("queue", function(msg)
  111.             sendMsgThis("stopWaiting");
  112.         end )
  113.         
  114.         onMsg("stopWaiting", function(msg)
  115.             exitStateMachine();
  116.         end )
  117.                 
  118.         onMsg("callPartner", function(msg)
  119.         
  120.             print("callPartner");
  121.             
  122.             if testCancel() then
  123.                 sendMsgThis("stopWaiting");
  124.                 return
  125.             end            
  126.             
  127.             -- get the game object server
  128.             local gameObjectServer = getParent().getGameObjectServer();
  129.                     
  130.             
  131.             local partner = getOtherCharacter(getParent());
  132.             
  133.             if (not partner) then
  134.                 print("waitForPartner: no partner found");
  135.                 getParent().setEmoticon(EMOTICON_PARTNER, EMOTICON_DELAY);
  136.                 sendDelayedMsgThis("callPartner", 1000);
  137.                 return
  138.             end
  139.             
  140.             local camera = retrieveStateObject("camera");
  141.             
  142.             local poseActionPointsInSight = getActionPointsInSight(camera, "center", 1.7, camera, {"pose1","pose2","pose3"}, 1.7, partner);
  143. --            local poseActionPoint = partner.getClosestFreeActionPoint(partner, camera, tremoven(poseActionPointsInSight));
  144.             local poseActionPoint = partner.getClosestFreeActionPoint(partner, camera, tremoven(poseActionPointsInSight), true);
  145.             if (not poseActionPoint) then
  146.                 print("waitForPartner: poseActionPoint not found");
  147.                 partner.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  148.                 sendDelayedMsgThis("callPartner", 1000);
  149.                 return
  150.             end
  151.             
  152. --            local wso = partner.walkSO;
  153. --            wso.storeData("actionPointName", poseActionPoint.getName());
  154. --            
  155. --            if (not wso.walkToActionPoint(poseActionPoint)) then
  156. --                print("waitForPartner: partner cant reach poseActionPoint");
  157. --                partner.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  158. --                sendDelayedMsgThis("callPartner", 1000);
  159. --                return
  160. --            end
  161. --            
  162. --            storeStateObject("partner", wso);
  163. --            
  164. --            -- create partners state machine contexts
  165. --            local wsoContext = StateMachineContext();
  166. --            wsoContext.storeStateObject("camera", camera);
  167. --            wsoContext.storeStateObject("partner", this);
  168. --            wsoContext.storeData("poseActionPoint", poseActionPoint.getName());
  169. --
  170. --            -- send partner to chair
  171. --            wso.queueStateMachine("cameraChar.pose", camera, wsoContext);
  172.  
  173.             storeStateObject("partner", partner.walkSO);
  174.  
  175.             local wsoContext = StateMachineContext();
  176.             wsoContext.storeStateObject("camera", camera);
  177.             wsoContext.storeStateObject("partner", this);
  178.             wsoContext.storeData("actionPointName", poseActionPoint.getName());
  179.  
  180.             -- queue walk and state change msg for this(passive) character
  181.             local passiveMsg = QueuedMessage();
  182.             passiveMsg.set(Message.MSG_RESERVED_EnterStateMachine, camera.getUniqueID(), "cameraChar.poseWait", wsoContext);
  183.             partner.pushWalkActionPoint("pm_pose", poseActionPoint, false, passiveMsg);
  184.         
  185.         
  186.         
  187.         end )
  188.                         
  189.         onMsg("partnerReady", function(msg)
  190.             print("----- partner of " .. getParent().getCharacterName() .. " is ready -----");            
  191.             local partner = retrieveStateObject("partner");
  192.             setState("takePicture");
  193.             sendMsg("partnerReady", partner);
  194.         end )
  195.             
  196.     
  197.     state("takePicture")
  198.     
  199.         onEnter(function(msg)
  200.             local camera = retrieveStateObject("camera");
  201.             getParent().startActivity("takePicture", camera);
  202.             startAnimation("takePictureStart");
  203.             sendDelayedMsgThis("clickSound", 900);
  204.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  205.         end )
  206.     
  207.         onMsg("clickSound", function(msg)
  208.             getParent().playSound("cameraShots");
  209.         end )
  210.             
  211.         onMsg("stopTakePicture", function(msg)
  212.             setState("takePictureStop");
  213.         end )    
  214.         
  215.         onMsg("testCancel", function(msg)
  216.             if testCancel() then
  217.                 local partner = retrieveStateObject("partner");
  218.                 sendMsg("stopPose", partner);
  219.                 sendMsgThis("stopTakePicture");
  220.             else
  221.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  222.             end
  223.         end )
  224.  
  225.         onMsg("end", function(msg)
  226.             sendDelayedMsgThis("stopTakePicture", 11000);
  227.         end )
  228.             
  229.     state("takePictureStop")
  230.     
  231.         onEnter(function(msg)
  232.             startAnimation("takePictureStop");
  233.         end )
  234.     
  235.  
  236.         onMsg("end", function(msg)
  237.             local camera = retrieveStateObject("camera");
  238.             getParent().stopActivity("takePicture", camera);
  239.             exitStateMachine();
  240.         end )
  241.         
  242.         
  243.     state("poseWait")
  244.     
  245.         onEnter(function(msg)
  246.             print("--poseWait onEnter--- " .. getParent().getCharacterName());
  247.             local camera = retrieveStateObject("camera");
  248.             local actionPointName = retrieveData("actionPointName");
  249.             
  250.             if exitIfWrongPosition(getParent(), camera, actionPointName) then return end;    
  251.             
  252.             
  253.             if (getParent().isActionPointLocked(camera, actionPointName)) then
  254.                 -- action point is locked
  255.                 sendMsgThis("stop");
  256.                 return
  257.             else
  258.                 getParent().lockActionPoint(camera, actionPointName);
  259.             end
  260.                         
  261.             local partner = retrieveStateObject("partner");
  262.             sendDelayedMsgThis("ready", 1000);
  263.             sendDelayedMsgThis("stop", 5000);
  264.             
  265.             startAnimation("emoSwingArms");
  266.         end )
  267.         
  268.         onMsg("end", function(msg)
  269.             startAnimation("emoSwingArms");
  270.         end )
  271.         
  272.         onMsg("stop", function(msg)
  273.             print("----- " .. getParent().getCharacterName() .. " has stopped waiting ----- ");
  274.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  275.             sendMsg("emoThink", getParent().walkSO);
  276.             exitStateMachine();
  277.         end )    
  278.         
  279.         onMsg("ready", function(msg)
  280.             print("----- " .. getParent().getCharacterName() .. " is ready ----- cancel: ");
  281.             -- send a message to the partner
  282.             
  283.             local partner = retrieveStateObject("partner");            
  284.             if (testCancel()) then
  285.                 sendMsgThis("stop");
  286.             else                        
  287.                 sendMsg("partnerReady", partner);
  288.                 sendDelayedMsgThis("ready", 1000);
  289.             end
  290.         end )
  291.         
  292.         onMsg("partnerReady", function(msg)
  293.             print("----- partner of " .. getParent().getCharacterName() .. " is ready -----");
  294.             
  295.             local partner = retrieveStateObject("partner");
  296.             setState("pose");
  297.             sendMsg("partnerReady", partner);
  298.         end )
  299.                     
  300.         
  301.         
  302.     state("pose")
  303.     
  304.         onEnter(function(msg)
  305.             print("----- pose onEnter " .. getParent().getCharacterName());
  306.             local camera = retrieveStateObject("camera");
  307.             getParent().startActivity("pose", camera);
  308.             startAnimation("emoFlirt");
  309.                 
  310.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  311.         end )
  312.         
  313.         
  314.         onMsg("testCancel", function(msg)
  315.             if testCancel() then
  316.                 local partner = retrieveStateObject("partner");
  317.                 sendMsg("stopTakePicture", partner);
  318.                 sendMsgThis("stopPose");
  319.             else
  320.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  321.             end
  322.         end )
  323.         
  324.     
  325.         onMsg("stopPose", function(msg)
  326.             local camera = retrieveStateObject("camera");
  327.             getParent().stopActivity("pose", camera);
  328.             exitStateMachine();
  329.         end )    
  330.  
  331.         onMsg("end", function(msg)
  332.             sendMsgThis("stopPose");
  333.         end )    
  334.         
  335.         
  336.  
  337.                 
  338. endStateMachine()
  339.