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

  1. -- treadmill oldschool 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.         local button ;
  12.         button = addPieMenuButton("pm_train", "run");
  13.         button.addDescription(ACTIVITY, "run");
  14.         -- button.addIcon("guiIconLibido");
  15.     end )
  16.     
  17.     -- run on tradmill
  18.     onMsg("run", function(msg)
  19.         -- get the game object server
  20.         local gameObjectServer = getGameObjectServer();
  21.         -- get character who initiated this action
  22.         local character = getStateObjectFromID(msg.sender);
  23.         
  24.         -- check if activity if possible
  25.         local possible, result, activity = activityPossible(character, msg.name, this);
  26.         
  27.         -- don't care if timeslot is not fulfilled
  28.         if (possible or enumCompare(result, TIMESLOT)) then
  29.             -- if this is broken: abort characters action
  30.             if abortIfBroken(character) then return end;        
  31.             -- walk to the closest action point
  32.             local actionPoint = character.getFreeActionPoint(this, "run");
  33.             if (actionPoint) then
  34.             -- get the walk state object
  35.                 local wso = character.walkSO;
  36.                 -- create state machine contexts
  37.                 local wsoContext = StateMachineContext();
  38.                 -- store the action point
  39.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  40.                 if (wso.walkToActionPoint(actionPoint)) then
  41.                     wso.queueStateMachine("treadmilChar.enter", this, wsoContext);
  42.                 else
  43.                     print("no path found");
  44.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.                 end
  46.             else
  47.                 print("no action point found");
  48.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  49.             end
  50.         else
  51.             -- activity not possible
  52.             print(msg.name .. " not possible");
  53.             
  54.             local emoticon;
  55.             if (enumCompare(result, NO_CONDITION)) then
  56.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  57.             else
  58.                 emoticon = EMOTICON_CANNOT;
  59.             end
  60.             instantAbort(character, emoticon, "emoThink");
  61.         end
  62.     end )
  63.     
  64.     
  65.     -- repair
  66.     onMsg("repair", function(msg)
  67.     
  68.         print("onMsg repair");
  69.         -- get character who initiated this action
  70.         local character = getStateObjectFromID(msg.sender);
  71.         -- walk to the closest action point
  72.         -- local actionPoint = character.getFreeActionPoint(this, "repair");
  73.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"repair1", "repair2", "repair3"});
  74.         -- get the walk state object
  75.         local wso = character.walkSO;
  76.         if (actionPoint) then
  77.             -- create state machine contexts
  78.             local wsoContext = StateMachineContext();
  79.             -- store the action point
  80.             wsoContext.storeData("actionPointName", actionPoint.getName());
  81.             if (wso.walkToActionPoint(actionPoint)) then
  82.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  83.             else
  84.                 print("no path found");
  85.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  86.             end
  87.         else
  88.             print("no action point found");
  89.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  90.         end
  91.     end )
  92.                         
  93. endStateMachine()
  94.