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

  1. -- elaine walk state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onEnter(function(msg)
  6.         print("swimChar enter ------------------------------------------");
  7.         
  8.         local pool = retrieveStateObject("pool")
  9.         if (pool) then
  10.             getParent().startActivity("swim", pool);
  11.         end
  12.         
  13.  
  14.     end )
  15.     
  16.     onExit(function(msg)
  17.         print("swimChar exit ------------------------------------------");
  18.         
  19.         local pool = retrieveStateObject("pool")
  20.         if (pool) then
  21.             getParent().stopActivity("swim", pool);
  22.         end
  23.  
  24.     end )
  25.     
  26.     
  27.     onMsg("goAway", function(msg)
  28.         print("onMsg goAway(swim)-----------------------------------------------------------");
  29.         
  30.         if (isWalking()) then return end;
  31.         
  32.         local minDist = random(1,10);
  33.         local target = getParent().findPointNear(minDist, 10.0);
  34.         if (target) then
  35.             getParent().queueWalkActionPoint("pm_swim", target, true);
  36.         else
  37.             print("goAway(swim) no target");
  38.         end
  39.     end )
  40.     
  41.     
  42. --    onMsg("leavePool", function(msg)
  43. --    
  44. --        local exitPoints = pool.getExitPoints(getParent());
  45. --        for p = 1, getn(exitPoints) do
  46. --            print(" exitPoints " .. p);
  47. --            local actionPoint = exitPoints[p];
  48. --                                                
  49. --            -- get the walk state object
  50. --            if (walkToActionPoint(actionPoint)) then
  51. --                print("leave pool");
  52. --                storeData("exit", true);
  53. --                return
  54. --            end
  55. --        end
  56. --        
  57. --    end )
  58.     
  59.     
  60.  
  61.     onMsg("queue", function(msg)
  62.         nextAction();
  63.         print("stop swim");
  64.     end )                
  65.  
  66.     
  67.     
  68. --    state("goAway")
  69. --        onEnter(function(msg)
  70. --            print("goAway onEnter");
  71. --            local minDist = random(1,10);
  72. --            local target = getParent().findPointNear(minDist, 10.0);
  73. --            if (target) then
  74. --                getParent().queueWalkActionPoint("pm_swim", target, true);
  75. --            else
  76. --                print("no target");
  77. --            end
  78. --        end )    
  79.     
  80.     
  81.     -- stand
  82.     state("stand")
  83.         onEnter(function(msg)
  84.             startAnimation("swimmingStand");
  85.             sendDelayedMsgThis("makeDrop", 1000);
  86.             --actionComplete();
  87.             getParent().loopSound("swimOnPlace");
  88.             sendDelayedMsgThis("complete", 300);
  89.         end )
  90.  
  91.         onExit(function(msg)
  92.             getParent().stopSound("swimOnPlace");
  93.         end )
  94.  
  95.         onMsg("makeDrop", function(msg)        
  96.             getParent().createWaterDrop(0.2, 200);
  97.             sendDelayedMsgThis("makeDrop", 1000);
  98.         end )    
  99.  
  100.         onMsg("end", function(msg)
  101.             startAnimation("swimmingStand");
  102.             actionComplete();
  103.         end )    
  104.  
  105.         onMsg("complete", function(msg)
  106.             actionComplete();
  107.         end )
  108.         
  109.     -- walk
  110.     state("walk")
  111.         onEnter(function(msg)
  112.             print("walk onEnter " .. getParent().getCharacterName());
  113.             
  114.             local pool = retrieveStateObject("pool")
  115.             
  116.             getParent().loopSound("swimLoop");
  117.             
  118.             local walkAnim = "swimmingSlow";
  119.             storeData("walkAnim", walkAnim);
  120.                     
  121.             startWalk(walkAnim, "swimmingStand");
  122.  
  123.             if (pool.isCharacterLeavingPool(getParent())) then
  124.                                 
  125. --                local groundActionPoint = getParent().walkSO.getWantedActionPoint();
  126. --                storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
  127. --                storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  128.  
  129.                 local topEntry = getParent().getActivityQueueEntry(0);
  130.                 if (topEntry) then
  131.                     storeData("groundActionPoint", topEntry.getTarget());
  132.                     storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  133.                 end
  134.  
  135.                 
  136.                 local exitPoints = pool.getExitPoints(getParent());
  137.                 for p = 1, getn(exitPoints) do
  138.                     print(" exitPoints " .. p);
  139.                     local actionPoint = exitPoints[p];
  140.                                                         
  141.                     -- get the walk state object
  142.                     if (walkToActionPoint(actionPoint)) then
  143.                         print("leave pool");
  144.                         storeData("exit", true);
  145.                         return
  146.                     end
  147.                 
  148.                 end
  149.                 print("no path found");
  150.                 --getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  151.                 
  152.             else
  153.                 print("stay in pool");
  154.             end
  155.  
  156.             storeData("exit", false);
  157.             sendDelayedMsgThis("makeDrop", 250);
  158.         end )
  159.         
  160.         onExit(function(msg)
  161.             getParent().stopSound("swimLoop");
  162.         end )
  163.  
  164.         -- target changed durring walk
  165.         onMsg("targetChanged", function(msg)
  166.         
  167.             print("target changed durring walk " .. getParent().getCharacterName());
  168.         
  169.             local pool = retrieveStateObject("pool")
  170.             if (pool.isCharacterLeavingPool(getParent())) then
  171.                                 
  172. --                local groundActionPoint = getParent().walkSO.getWantedActionPoint();
  173. --                storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
  174.  
  175.                 local topEntry = getParent().getActivityQueueEntry(0);
  176.                 if (topEntry) then
  177.                     storeData("groundActionPoint", topEntry.getTarget());
  178.                     storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
  179.                 end
  180.  
  181.                 
  182.                 
  183.                 local exitPoints = pool.getExitPoints(getParent());
  184.                 for p = 1, getn(exitPoints) do
  185.                     print(" exitPoints " .. p);
  186.                     local actionPoint = exitPoints[p];
  187.                                                         
  188.                     -- get the walk state object
  189.                     if (walkToActionPoint(actionPoint)) then
  190.                         print("leave pool");
  191.                         storeData("exit", true);
  192.                         return
  193.                     end
  194.                 
  195.                 end
  196.                 
  197.                 print("no exit point found");
  198.                 storeData("exit", false);
  199.             else
  200.                 print("stay in pool");
  201.                 storeData("exit", false);
  202.             end
  203.  
  204.                 
  205.         end )    
  206.  
  207.         
  208.         onMsg("makeDrop", function(msg)        
  209.             getParent().createWaterDrop(0.2, 500);
  210.             sendDelayedMsgThis("makeDrop", 250);
  211.         end )    
  212.         
  213.         onMsg("next", function(msg)
  214.             if testCancel() then
  215.                 print("next testCancel == true");
  216.                 stopWalk();
  217.                 nextAction();
  218.             else
  219.                 
  220.                 local pool = retrieveStateObject("pool")
  221.                 
  222.                 local walkAnim = retrieveData("walkAnim", "swimming");
  223.                 local newWalkAnim = "swimming";
  224.                 if (pool.isCharacterMovingToEdge(getParent(), 1.5)) then newWalkAnim = "swimmingSlow"; end;
  225.                 storeData("walkAnim", newWalkAnim);
  226.                 
  227.                 --startWalk(newWalkAnim, "swimmingStand");
  228.  
  229.                 if (newWalkAnim == walkAnim) then
  230.                     print("next - startWalk " .. newWalkAnim);
  231.                     startWalk(newWalkAnim, "swimmingStand");
  232.                 else
  233.                     print("next - startWalk changed" .. walkAnim .. " -> " .. newWalkAnim);
  234.                     startWalk(newWalkAnim, "swimmingStand", 1000);
  235.                 end
  236.                 
  237.                 print("next - swim anim " .. newWalkAnim);
  238.             end
  239.         end )    
  240.         
  241.         onMsg("end", function(msg)
  242.             
  243.             if (retrieveData("exit", false) == true) then
  244.                 print("end -> exit");            
  245.                 setState("exitSwim");
  246.             else
  247.                 print("end -> stay");
  248.                 nextAction();            
  249.             end    
  250.  
  251.         end )    
  252.  
  253.     -- walk
  254.     state("exitSwim")
  255.     
  256.         onEnter(function(msg)
  257.             print("exitSwim " .. getParent().getCharacterName());
  258.  
  259.             getParent().replaceQueueEntry(0, "pm_exitPool");
  260.             local groundActionPoint = retrieveData("groundActionPoint");
  261.             if (groundActionPoint) then
  262.                 
  263.                 print("exitSwim queueWalkActionPoint1 queue:" .. getParent().getActivityQueueCount());
  264.                 getParent().pushWalkActionPoint("pm_walk", groundActionPoint, true, retrieveData("afterWalkMsg"));
  265. --                getParent().queueWalkActionPoint("pm_walk", groundActionPoint, true);
  266.                 print("exitSwim queueWalkActionPoint2 queue:" .. getParent().getActivityQueueCount());
  267.             end
  268.             
  269.             exitStateMachine();
  270.         end)
  271.  
  272.     
  273.         
  274. endStateMachine()
  275.