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

  1. -- hifi 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_dance", "dance");
  12.         button.addDescription(ACTIVITY, "dance");
  13.         button = addPieMenuButton("pm_rockMusic", "music1");
  14.         button.addDescription(DONTQUEUE, "true");
  15.         --button = addPieMenuButton("pm_danceMusic", "music2");
  16.  
  17.         if getGameObjectServer().addListener(0) > 0 then
  18.             button = addPieMenuButton("pm_switchOff", "aus");
  19.             button.addDescription(DONTQUEUE, "true");
  20.         end
  21.         -- button.addIcon("guiIconSpass");
  22.     end )
  23.  
  24.  
  25.  
  26.     -- 
  27.     onMsg("dance", function(msg)
  28.         -- get character who initiated this action
  29.         local character = getStateObjectFromID(msg.sender);
  30.         -- if this is broken: abort characters action
  31.         if abortIfBroken(character) then return end;        
  32.         
  33.         -- check if activity if possible
  34.         local possible, result, activity = activityPossible(character, msg.name, this);
  35.         
  36.         -- don't care if timeslot is not fulfilled
  37.         if (possible or enumCompare(result, TIMESLOT)) then
  38.             -- walk to the closest action point
  39.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"dance1", "dance2"});
  40.             if (actionPoint) then
  41.                 -- get the walk state object
  42.                 local wso = character.walkSO;
  43.                 local wsoContext = StateMachineContext();
  44.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  45.                 if (wso.walkToActionPoint(actionPoint)) then
  46.                     wso.queueStateMachine("hifiChar.dance", this, wsoContext);
  47.                 else
  48.                     print("no path found");
  49.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  50.                 end
  51.             else
  52.                 print("no action point found");
  53.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  54.             end
  55.         else
  56.             -- activity not possible
  57.             print(msg.name .. " not possible");
  58.             
  59.             local emoticon;
  60.             if (enumCompare(result, NO_CONDITION)) then
  61.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  62.             else
  63.                 emoticon = EMOTICON_CANNOT;
  64.             end
  65.             instantAbort(character, emoticon, "emoThink");
  66.         end
  67.     end )
  68.     
  69.     
  70.     onMsg("addListener", function(msg)
  71.         -- increase number of listeners for this object for relationship control (are mike and elaine dancing together?)
  72.         local numListeners = retrieveData("numListeners", 0) + 1;
  73.         storeData("numListeners", numListeners);
  74.         
  75.         -- increase number of global listeners for music control
  76.         local s = getGameObjectServer();
  77.         if (s.addListener(1) == 1) then
  78.             --loopSound("radioGitklirr");
  79.             s.setMusic("radioGitklirr");
  80.         end
  81.     end )
  82.  
  83.     onMsg("removeListener", function(msg)
  84.         -- decrease number of listeners for this object
  85.         local numListeners = max(retrieveData("numListeners", 0) - 1, 0);
  86.         storeData("numListeners", numListeners);
  87.  
  88.         -- decrease number of global listeners
  89.         local s = getGameObjectServer();
  90.         if (s.addListener(-1) == 0) then
  91.             --stopSound("radioGitklirr");
  92.             s.setMusic("");
  93.         end
  94.     end )
  95.  
  96.     onMsg("music1", function(msg)
  97.         local s = getGameObjectServer();
  98.         if s.addListener(0) == 0 then
  99.             s.addListener(1);
  100.         end
  101.  
  102.         s.setMusic("radioGitklirr");
  103.         
  104. --        local character = getStateObjectFromID(msg.sender);
  105. --        character.walkSO.nextAction();
  106.     end )
  107.     
  108.     onMsg("music2", function(msg)
  109.         local s = getGameObjectServer();
  110.         if s.addListener(0) == 0 then
  111.             s.addListener(1);
  112.         end
  113.  
  114.         s.setMusic("danceMusic");
  115.         
  116.     end )
  117.  
  118.     onMsg("aus", function(msg)
  119.         local s = getGameObjectServer();
  120.         s.addListener(-999); -- remove all listeners
  121.  
  122.         s.setMusic("");
  123.         
  124. --        local character = getStateObjectFromID(msg.sender);
  125. --        character.walkSO.nextAction();
  126.     end )
  127.     
  128.     -- repair
  129.     onMsg("repair", function(msg)
  130.     
  131.         print("onMsg repair");
  132.         -- get character who initiated this action
  133.         local character = getStateObjectFromID(msg.sender);
  134.         -- walk to the closest action point
  135.         local actionPoint = character.getFreeActionPoint(this, "repair");
  136.         -- get the walk state object
  137.         local wso = character.walkSO;
  138.         if (actionPoint) then
  139.             -- create state machine contexts
  140.             local wsoContext = StateMachineContext();
  141.             -- store the action point
  142.             wsoContext.storeData("actionPointName", actionPoint.getName());
  143.             if (wso.walkToActionPoint(actionPoint)) then
  144.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  145.             else
  146.                 print("no path found");
  147.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  148.             end
  149.         else
  150.             print("no action point found");
  151.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  152.         end
  153.     end )
  154.                 
  155. endStateMachine()
  156.