home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
oven.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
5KB
|
174 lines
-- oven state machine
beginStateMachine()
onEnter(function(msg)
local damp = findChildGO("damp");
damp.setEmitRate(0.0);
end )
onMsg("buildMenu", function(msg)
if (repairMenu()) then return end
-- build the pie menu
clearPieMenu();
if (getChildEnable("pot")) then
button = addPieMenuButton("pm_takeFood", "takeFood");
button.addDescription(ACTIVITY, "eat");
else
button = addPieMenuButton("pm_cook", "cook");
button.addDescription(ACTIVITY, "cook");
button.addDescription(ACTIVITY, "eat");
end
end )
--
onMsg("cook", 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, "cook");
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
-- create state machine contexts
local wsoContext = StateMachineContext();
-- store the action point
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
-- notify current mission
character.sendMsg("cook", gameObjectServer.mission);
-- enque action
wso.queueStateMachine("ovenChar.open", 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
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 )
-- takeFood
onMsg("takeFood", function(msg)
print("onMsg takeFood");
-- 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, "eat", 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, "cook");
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
-- create state machine contexts
local wsoContext = StateMachineContext();
-- store the action point
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("ovenChar.takeFood", 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
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("hidePot", function(msg)
print("onMsg hidePot");
this.setChildEnable("pot", false);
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();
-- store the action point
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()