home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
staircase.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
10KB
|
284 lines
-- bed state machine
beginStateMachine()
onMsg("buildMenu", function(msg)
local currentCharacter = getStateObjectFromID(msg.sender);
-- build the pie menu
clearPieMenu();
local button;
local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
if currentCharacter and (currentCharacter.timeForWork() or neverFail) then
button = addPieMenuButton("pm_gotoWork", "work");
button.addDescription(ACTIVITY, "work");
button.addDescription(NO_NEGATIVE_ICON, "NEED_HUNGER");
end
if currentCharacter and (canLeave(currentCharacter) or neverFail) then
button = addPieMenuButton(getLeaveButtonText(this), "changeHouse", "active");
button.addDescription(NO_AI, "true");
end
-- if canGoTo(CITY, this) then
-- button = addPieMenuButton("pm_gotoCity", "changeHouse");
-- end
--button = addPieMenuButton("Einkaufen gehen", "shop"); -- no game play function yet
-- button.addDescription(ACTIVITY, "shop");
--button = addPieMenuButton("pm_goOut", "out");
-- button.addDescription(ACTIVITY, "out");
local otherCharacter = getOtherCharacter(currentCharacter);
if (otherCharacter and activityPossible(currentCharacter, "giveGift", otherCharacter)) then
button = addPieMenuButton("pm_goBuyGift", "gift");
button.addDescription(ACTIVITY, "buyGift");
button.addDescription(NO_AI, "true");
end;
end )
-- go to work
onMsg("work", 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
local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
if (not character.timeForWork()) and (not neverFail) then
print("not time for work");
instantAbort(character, EMOTICON_CANNOT, "emoThink");
return
end
-- if character is too unhappy: abort characters action
if instantAbortIfUnhappy(character, "work", this) then return end;
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
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("staircaseChar.goToWork", 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 )
-- go shopping
onMsg("shop", 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
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
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("staircaseChar.goToShop", this, wsoContext);
else
print("no path found (in staircase.lua onMsg shop)");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found (in staircase.lua onMsg shop)");
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 )
-- go shopping
onMsg("out", 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
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
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("staircaseChar.goToShop", this, wsoContext);
else
print("no path found (in staircase.lua onMsg shop)");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found (in staircase.lua onMsg shop)");
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 )
-- go shopping
onMsg("gift", 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, "buyGift", this);
-- don't care if timeslot is not fulfilled
if (possible or enumCompare(result, TIMESLOT)) then
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
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("staircaseChar.goBuyGift", this, wsoContext);
else
print("no path found (in staircase.lua onMsg gift)");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found (in staircase.lua onMsg gift)");
instantAbort(character, EMOTICON_CANNOT, "emoThink")
end
else
-- activity not possible
print("buyGift 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 )
-- go shopping
onMsg("changeHouse", 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
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"topStep"});
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());
wsoContext.storeData("activePart", not(msg.data == ""));
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("staircaseChar.goToOtherHouse", this, wsoContext);
else
print("no path found (in staircase.lua onMsg gift)");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found (in staircase.lua onMsg gift)");
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 )
endStateMachine()