home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
sink.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
5KB
|
154 lines
-- sink state machine
beginStateMachine()
onMsg("buildMenu", function(msg)
if (repairMenu()) then return end
-- build the pie menu
clearPieMenu();
button = addPieMenuButton("pm_washHands", "washHands");
button.addDescription(ACTIVITY, "washHands");
button = addPieMenuButton("pm_washDishes", "washDishes");
button.addDescription(ACTIVITY, "washDishes");
button.addDescription(ACTIVITY, "improvePlateTidiness");
button.addIcon("guiIconWohnung");
-- button.addIcon("guiIconHygiene");
end )
--
onMsg("washHands", function(msg)
-- get the game object server
local gameObjectServer = getGameObjectServer();
-- get character who initiated this action
local character = getStateObjectFromID(msg.sender);
-- check if activity if possible
local possible, result, activity = activityPossible(character, msg.name, this);
-- don't care if timeslot is not fulfilled
if (possible or enumCompare(result, TIMESLOT)) then
-- if this is broken: abort characters action
if abortIfBroken(character) then return end;
-- walk to the closest action point
local actionPoint = character.getFreeActionPoint(this, "washHands");
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
local wsoContext = StateMachineContext();
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("sinkChar.washHandsStart", this, wsoContext);
else
print("no path found");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found");
instantAbort(character, EMOTICON_CANNOT, "emoThink")
-- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
end
else
-- activity not possible
print(msg.name .. " not possible");
local emoticon;
if (enumCompare(result, NO_CONDITION)) then
emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
else
emoticon = EMOTICON_CANNOT;
end
instantAbort(character, emoticon, "emoThink");
end
end )
-- onMsg("washDishes", function(msg)
-- -- get the game object server
-- local gameObjectServer = getGameObjectServer();
-- -- get character who initiated this action
-- local character = getStateObjectFromID(msg.sender);
-- -- walk to the closest action point
-- local actionPoint = character.getFreeActionPoint(this, "washHands");
-- if (actionPoint) then
-- -- get the walk state object
-- local wso = character.walkSO;
-- if (wso.walkToActionPoint(actionPoint)) then
-- wso.queueStateMachine("sinkChar.washDishes", this);
-- else
-- print("no path found");
-- character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
-- else
-- print("no action point found");
-- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
-- end )
onMsg("washDishes", function(msg)
-- get character who initiated this action
local character = getStateObjectFromID(msg.sender);
-- check if activity if possible
local possible, result, activity = activityPossible(character, msg.name, this);
-- don't care if timeslot is not fulfilled
if (possible or enumCompare(result, TIMESLOT)) then
-- if this is broken: abort characters action
if abortIfBroken(character) then return end;
-- get the walk state object
local wso = character.walkSO;
local wsoContext = StateMachineContext();
wsoContext.storeData("washState", "sinkChar.washDishesStart");
wso.queueStateMachine("collectDishesChar.findDishes", this, wsoContext);
--wsoContext.storeData("numDishes", 2);
--wso.queueStateMachine("collectDishesChar.gotoDishwasher", this, wsoContext);
else
-- activity not possible
print(msg.name .. " not possible");
local emoticon;
if (enumCompare(result, NO_CONDITION)) then
emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
else
emoticon = EMOTICON_CANNOT;
end
instantAbort(character, emoticon, "emoThink");
end
end )
-- repair
onMsg("repair", function(msg)
print("onMsg repair");
-- get character who initiated this action
local character = getStateObjectFromID(msg.sender);
-- walk to the closest action point
local actionPoint = character.getFreeActionPoint(this, "repair");
-- get the walk state object
local wso = character.walkSO;
if (actionPoint) then
-- create state machine contexts
local wsoContext = StateMachineContext();
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
else
print("no path found");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found");
instantAbort(character, EMOTICON_CANNOT, "emoThink")
end
end )
endStateMachine()