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

  1. -- walk state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onEnter(function(msg)
  6.         setState("stand");
  7.     end )
  8.  
  9.     onReturn(function(msg)
  10.         nextAction();
  11.     end )
  12.         
  13.     onMsg("queue", function(msg)
  14.         nextAction();
  15.     end )                
  16.  
  17.     onMsg("waitForChar", function(msg)
  18.         --cancel();
  19.         print("interaction." .. msg.data);
  20.         enterStateMachine("interaction." .. msg.data);
  21.     end )
  22.     
  23.     onMsg("enterStateMachine", function(msg)
  24.         print("enterStateMachine :" .. msg.data);
  25.         enterStateMachine(msg.data);
  26.     end )
  27.  
  28.     
  29.     -- emotion pose messages
  30.     onMsg("emoThink", function(msg)
  31.         print("think");
  32.         setState("think");        
  33.     end )
  34.     
  35.     onMsg("emoHungry", function(msg)
  36.         print("hungry");
  37.         setState("hungry");        
  38.     end )
  39.     
  40.     onMsg("emoYawn", function(msg)
  41.         print("yawn");
  42.         setState("yawn");        
  43.     end )
  44.     
  45.     onMsg("emoHygiene", function(msg)
  46.         print("Elaine hygiene");
  47.         setState("hygiene");        
  48.     end )
  49.     
  50.     onMsg("emoSwing", function(msg)
  51.         print("swing");
  52.         setState("swing");        
  53.     end )
  54.     
  55.     onMsg("emoHappy", function(msg)
  56.         print("happy");
  57.         setState("happy");        
  58.     end )
  59.     
  60.     onMsg("emoFlirt", function(msg)
  61.         print("flirt");
  62.         storeData("flirtChar", msg.sender);
  63.         setState("flirt");        
  64.     end )
  65.     
  66.     onMsg("emoRefuse", function(msg)
  67.         print("refuse");
  68.         setState("refuse");        
  69.     end )
  70.     
  71.     onMsg("emoRefuseChar", function(msg)
  72.         print("onMsg emoRefuseChar");
  73.         storeData("refuseChar", msg.sender);
  74.         setState("refuseChar");        
  75.     end )
  76.     
  77.     onMsg("emoShameChar", function(msg)
  78.         print("onMsg emoShameChar");
  79.         storeData("shameChar", msg.sender);
  80.         setState("shameChar");        
  81.     end )
  82.     
  83.     onMsg("emoShameNackedChar", function(msg)
  84.         print("onMsg emoShameNackedChar");
  85.         storeData("shameChar", msg.sender);
  86.         setState("shameNackedChar");        
  87.     end )
  88.     
  89.     
  90.     onMsg("emoYouSmell", function(msg)
  91.         print("you smell");
  92.         storeData("smellChar", msg.sender);
  93.         setState("youSmell");        
  94.     end )
  95.     
  96.     onMsg("goAway", function(msg)
  97.         print("onMsg goAway(walk)");
  98.         
  99.         if (isWalking()) then return end;
  100.         
  101.         local minDist = 1.5;
  102.         local maxDist = 3.0;
  103.         local dataNum = tonumber(msg.data)
  104.         if (dataNum) then
  105.             minDist = dataNum;
  106.             maxDist = dataNum * 2;
  107.         end
  108.         
  109.         local target = getParent().findPointNear(minDist, maxDist);
  110.         if (target) then
  111.             print("goAway min dist " .. minDist);
  112.             getParent().queueWalkActionPoint("pm_walk", target, true);
  113.         else
  114.             print("goAway no target");
  115.         end
  116.     end )
  117.     
  118.     
  119.     -- stand : walk returns into this state -> fast fading
  120.     state("stand")
  121.         onEnter(function(msg)
  122.             print("stand " .. getParent().getCharacterName())
  123.             -- mission test
  124.             getParent().getGameObjectServer().mission.sendMsgThis("checkComplete");
  125.             setPose(archize(getParent(), "stand1"));
  126.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  127.             
  128.         end )
  129.         
  130.         onMsg("complete", function(msg)
  131.             actionComplete();
  132.         end )    
  133.         
  134.         onMsg("end", function(msg)
  135.             setDelayedState("stand2", random(1000, 3000));
  136.             --actionComplete();
  137.         end )    
  138.  
  139.     -- same as stand but longer fadetime
  140.     state("stand1")
  141.         onEnter(function(msg)
  142.             print("stand1 " .. getParent().getCharacterName())
  143.             -- mission test
  144.             getParent().getGameObjectServer().mission.sendMsgThis("checkComplete");
  145.             --setPose("standElaine");
  146.             print("stand1 anim: " .. archize(getParent(), "stand1"));
  147.             startAnimation(archize(getParent(), "stand1"), false, 1.0, STAND_POSE_FADE_TIME);
  148.             
  149.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  150.             
  151.         end )
  152.         
  153.         onMsg("complete", function(msg)
  154.             actionComplete();
  155.         end )    
  156.  
  157.         onMsg("end", function(msg)
  158.             setDelayedState("stand" .. randomExclude(1, 4, {1}), random(1000, 3000));
  159.         end )    
  160.  
  161.     state("stand2")
  162.         onEnter(function(msg)
  163.             print("stand2 " .. getParent().getCharacterName())
  164.             --setPose("stand2Elaine");
  165.             print("stand2 anim: " .. archize(getParent(), "stand2"));
  166.             startAnimation(archize(getParent(), "stand2"), false, 1.0, STAND_POSE_FADE_TIME);
  167.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  168.             
  169.         end )
  170.         
  171.         onMsg("complete", function(msg)
  172.             actionComplete();
  173.         end )    
  174.         
  175.         onMsg("end", function(msg)
  176.             setDelayedState("stand" .. randomExclude(1, 4, {2}), random(1000, 3000));
  177.         end )    
  178.  
  179.     state("stand3")
  180.         onEnter(function(msg)
  181.             print("stand3 " .. getParent().getCharacterName())
  182.             --setPose("stand3Elaine");
  183.             print("stand3 anim: " .. archize(getParent(), "stand3"));
  184.             startAnimation(archize(getParent(), "stand3"), false, 1.0, STAND_POSE_FADE_TIME);
  185.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  186.             
  187.         end )
  188.         
  189.         onMsg("complete", function(msg)
  190.             actionComplete();
  191.         end )    
  192.         
  193.         onMsg("end", function(msg)
  194.             setDelayedState("stand" .. randomExclude(1, 4, {3}), random(1000, 3000));
  195.         end )    
  196.         
  197.     state("stand4")
  198.         onEnter(function(msg)
  199.             print("stand4 " .. getParent().getCharacterName())
  200.             --setPose("stand4Elaine");
  201.             print("stand4 anim: " .. archize(getParent(), "stand4"));
  202.             startAnimation(archize(getParent(), "stand4"), false, 1.0, STAND_POSE_FADE_TIME);
  203.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  204.             
  205.         end )
  206.         
  207.         onMsg("complete", function(msg)
  208.             actionComplete();
  209.         end )    
  210.         
  211.         onMsg("end", function(msg)
  212.             setDelayedState("stand" .. randomExclude(1, 4, {4}), random(1000, 3000));
  213.         end )
  214.         
  215.         
  216.         
  217.         
  218.         
  219.     state("think")
  220.         onEnter(function(msg)
  221.             print("setPose(emoThink)");
  222.             setPose("emoThink");
  223.             sendDelayedMsgThis("complete", EMO_POSE_COMPLETE_TIME);            
  224.         end )
  225.         
  226.         onMsg("complete", function(msg)
  227.             this.actionComplete();
  228.         end )    
  229.                         
  230.         onMsg("end", function(msg)
  231.             setState("stand");
  232.         end )    
  233.         
  234.     state("hungry")
  235.         onEnter(function(msg)
  236.             setPose("emoHungry");
  237.             this.actionComplete();            
  238.         end )
  239.         
  240.         onMsg("end", function(msg)
  241.             setState("stand");
  242.         end )
  243.             
  244.     state("yawn")
  245.         onEnter(function(msg)
  246.             setPose("emoYawn");
  247.             this.actionComplete();            
  248.         end )
  249.         
  250.         onMsg("end", function(msg)
  251.             setState("stand");
  252.         end )    
  253.         
  254.     state("hygiene")
  255.         onEnter(function(msg)
  256.             setPose("emoHygiene");
  257.             this.actionComplete();            
  258.         end )
  259.         
  260.         onMsg("end", function(msg)
  261.             setState("stand");
  262.         end )
  263.             
  264.     state("swing")
  265.         onEnter(function(msg)
  266.             setPose("emoSwingArms");
  267.             this.actionComplete();            
  268.         end )
  269.         
  270.         onMsg("end", function(msg)
  271.             setState("stand");
  272.         end )    
  273.         
  274.     state("happy")
  275.         onEnter(function(msg)
  276.             setPose("emoHappy");
  277.             this.actionComplete();            
  278.         end )
  279.         
  280.         onMsg("end", function(msg)
  281.             setState("stand");
  282.         end )    
  283.         
  284.     state("flirt")
  285.         onEnter(function(msg)
  286.             local partner = getStateObjectFromID(retrieveData("flirtChar"));              
  287.             if (not partner) then
  288.                 print("flirtChar not found");
  289.                 setState("stand");
  290.                 return
  291.             end
  292.             
  293.             turnToGameObject(partner)
  294.             setPose("emoFlirt");
  295.             this.actionComplete();        
  296.         end )
  297.         
  298.         onMsg("end", function(msg)
  299.             setState("stand");
  300.         end )    
  301.         
  302.     state("refuseChar")
  303.         onEnter(function(msg)
  304.             print("refuseChar onEnter");
  305.             local partner = getStateObjectFromID(retrieveData("refuseChar"));              
  306.             if (not partner) then
  307.                 print("refuseChar not found");
  308.                 setState("stand");
  309.                 return
  310.             end
  311.  
  312.             turnToGameObject(partner)
  313.             setPose("emoRefuse");
  314.             this.actionComplete();    
  315.         end )
  316.         
  317.         onMsg("end", function(msg)
  318.             setState("stand");
  319.         end )
  320.         
  321.         
  322.     state("shameChar")
  323.         onEnter(function(msg)
  324.             print("state shameChar");
  325.             local partner = getStateObjectFromID(retrieveData("shameChar"));              
  326.             --getOtherCharcter(getParent());
  327.             if (not partner) then
  328.                 print("shameChar not found");
  329.                 setState("stand");
  330.                 return
  331.             end
  332.  
  333.             turnToGameObject(partner);
  334.             setPose("emoShy");
  335.             getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  336.             sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);
  337.         end )
  338.         
  339.         onMsg("complete", function(msg)
  340.             actionComplete();
  341.         end )    
  342.  
  343.         onMsg("end", function(msg)
  344.             setState("stand");
  345.         end )
  346.         
  347.         
  348.     state("shameNackedChar")
  349.         onEnter(function(msg)
  350.             print("state shameChar");
  351.             local partner = getStateObjectFromID(retrieveData("shameChar"));              
  352.             --getOtherCharcter(getParent());
  353.             if (not partner) then
  354.                 print("shameChar not found");
  355.                 setState("stand");
  356.                 return
  357.             end
  358.  
  359.             turnToGameObject(partner);
  360.             setPose("emoShyNacked");
  361.             getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  362.             sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);
  363.         end )
  364.         
  365.         onMsg("complete", function(msg)
  366.             actionComplete();
  367.         end )    
  368.         
  369.         onMsg("end", function(msg)
  370.             local other, result = getDisturbingChar(getParent(), "showNaked")
  371.             if testCancel() or (not other) then
  372.                 setState("stand");
  373.             else
  374.                 if (not urgentOutfitChange(getParent())) then
  375.                     setPose("emoShyNackedLoop");
  376.                     getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  377.                     sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);            
  378.                 end
  379.             end
  380.         end )
  381.         
  382.         
  383.     state("refuse")
  384.         onEnter(function(msg)
  385.             setPose("emoRefuse");
  386.             this.actionComplete();            
  387.         end )
  388.         
  389.         onMsg("end", function(msg)
  390.             setState("stand");
  391.         end )    
  392.             
  393.         
  394.     state("youSmell")
  395.         onEnter(function(msg)
  396.             --local partner = getOtherCharcter(getParent());
  397.             local partner = getStateObjectFromID(retrieveData("smellChar"));              
  398.             if (not partner) then
  399.                 print("smellChar not found");
  400.                 setState("stand");
  401.                 return
  402.             end
  403.             
  404.             turnToGameObject(partner)
  405.             setPose("emoYouSmell");
  406.             this.actionComplete();        
  407.         end )
  408.         
  409.         onMsg("end", function(msg)
  410.             setState("stand");
  411.         end )
  412.         
  413.                 
  414. --    state("goAway")
  415. --        onEnter(function(msg)
  416. --            print("goAway onEnter");
  417. --            local target = getParent().findPointNear(2.0, 5.0);
  418. --            if (target) then
  419. --                if (not walkToActionPoint(target)) then
  420. --                    print("no path");
  421. --                end
  422. --            else
  423. --                print("no target");
  424. --            end
  425. --        end )
  426.         
  427.             
  428. --    state("goAway")
  429. --        onEnter(function(msg)
  430. --            print("goAway onEnter");
  431. --            local target = getParent().findPointNear(2.0, 5.0);
  432. --            if (target) then
  433. --                getParent().queueWalkActionPoint("pm_walk", target, true);
  434. --            else
  435. --                print("no target");
  436. --            end
  437. --        end )
  438.             
  439.             
  440.         
  441.     -- walk
  442.     state("walk")
  443.         onEnter(function(msg)
  444.             print("walk onEnter " .. getParent().getCharacterName());
  445.             -- if distance to walk is greater 4m, run
  446.             if isRunDistance() then
  447.                 setState("runRFF-runLFF");
  448.             else
  449.                 --startWalk("stand-walkLFF-Elaine", "stand-walkLFF-Elaine");
  450.                 local c = getParent();
  451.                 startWalk(archizeWalk(c, "stand-walkLFF-"), archizeWalk(c, "stand-walkLFF-"), WALK_SPEEDUP);
  452.             end
  453.         end )
  454.  
  455.         onMsg("next", function(msg)
  456.             if testCancel() then
  457.                 stopWalk();
  458.                 nextAction();
  459.             else
  460.                 setState("walkLFF-walkRFF");
  461.             end
  462.         end )    
  463.         
  464.         onMsg("end", function(msg)
  465.             nextAction();
  466.             --notify mission
  467.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  468.         end )    
  469.  
  470.     state("walkRFF-walkLFF")
  471.         onEnter(function(msg)
  472.             if isRunDistance() then
  473.                 setState("runRFF-runLFF");
  474.             else
  475.                 --startWalk("walkRFF-walkLFF-Elaine", "walkRFF-stand-Elaine");
  476.                 local c = getParent();
  477.                 startWalk(archizeWalk(c, "walkRFF-walkLFF-"), archizeWalk(c, "walkRFF-stand-"), WALK_SPEEDUP);
  478.                 createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  479.                 makeStepSound();
  480.             end
  481.         end )
  482.  
  483.         onMsg("next", function(msg)
  484.             if testCancel() then
  485.                 stopWalk();
  486.                 nextAction();
  487.             else
  488.                 setState("walkLFF-walkRFF");
  489.             end
  490.         end )    
  491.         
  492.         onMsg("end", function(msg)
  493.             nextAction();
  494.             --notify mission
  495.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  496.         end )    
  497.  
  498.     state("walkLFF-walkRFF")
  499.         onEnter(function(msg)
  500.             --startWalk("walkLFF-walkRFF-Elaine", "walkLFF-stand-Elaine");
  501.             local c = getParent();
  502.             startWalk(archizeWalk(c, "walkLFF-walkRFF-"), archizeWalk(c, "walkLFF-stand-"), WALK_SPEEDUP);
  503.             makeStepSound();
  504.         end )
  505.  
  506.         onMsg("next", function(msg)
  507.             if testCancel() then
  508.                 stopWalk();
  509.                 nextAction();
  510.             else
  511.                 setState("walkRFF-walkLFF");
  512.             end
  513.         end )    
  514.         
  515.         onMsg("end", function(msg)
  516.             nextAction();
  517.             --notify mission
  518.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  519.         end )    
  520.  
  521.     -- run
  522.     state("runRFF-runLFF")
  523.         onEnter(function(msg)
  524.             --startWalk("runRFF-runLFF-Elaine", "walkRFF-stand-Elaine");
  525.             local c = getParent();
  526.             startWalk(archizeRun(c, "runRFF-runLFF-"), archizeWalk(c, "walkRFF-stand-"), RUN_SPEEDUP);
  527.             createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  528.             makeStepSound();
  529.         end )
  530.  
  531.         onMsg("next", function(msg)
  532.             if testCancel() then
  533.                 stopWalk();
  534.                 nextAction();
  535.             else
  536.                 setState("runLFF-runRFF");
  537.             end
  538.         end )    
  539.         
  540.         onMsg("end", function(msg)
  541.             nextAction();
  542.             --notify mission
  543.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  544.         end )    
  545.  
  546.     state("runLFF-runRFF")
  547.         onEnter(function(msg)
  548.             --startWalk("runLFF-runRFF-Elaine", "walkLFF-stand-Elaine");
  549.             local c = getParent();
  550.             startWalk(archizeRun(c, "runLFF-runRFF-"), archizeWalk(c, "walkLFF-stand-"), RUN_SPEEDUP);
  551.             createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  552.             makeStepSound();
  553.         end )
  554.  
  555.         onMsg("next", function(msg)
  556.             if testCancel() then
  557.                 stopWalk();
  558.                 nextAction();
  559.             else
  560.                 setState("runRFF-runLFF");
  561.             end
  562.         end )    
  563.         
  564.         onMsg("end", function(msg)
  565.             nextAction();
  566.             --notify mission
  567.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  568.         end )    
  569.     
  570.         
  571. endStateMachine()
  572.