home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
eatByTableChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
14KB
|
477 lines
beginStateMachine()
onEnter(function(msg)
print("EatByTable onEnter------------------------------");
end )
onExit(function(msg)
print("EatByTable onExit--------------------------------");
-- local chair = retrieveStateObject("chair");
-- if (chair) then
-- getParent().unlockActionPoints(chair);
-- getParent().stopAllActivities(chair);
-- removeStateObject("chair");
-- end;
--
-- local table = retrieveStateObject("table");
-- if (table) then
-- getParent().unlockActionPoints(table);
-- getParent().stopAllActivities(table);
-- removeStateObject("table");
-- end;
unlockAll("chair");
unlockAll("table");
local partner = retrieveStateObject("partner");
if (partner) then
getParent().unlockActionPoints(partner);
getParent().stopAllActivities(partner);
removeStateObject("partner");
end;
getParent().stopAllActivities();
end )
-- sit down on chair
state("sitDown")
onEnter(function(msg)
print("sitDown onEnter");
local chair = retrieveStateObject("chair");
if (chair) then
--chair does exist
if exitIfWrongPosition(getParent(), chair, retrieveData("chairActionPointName")) then return end;
if (getParent().isOneActionPointLocked(chair)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitAndGoAway();
return
else
getParent().lockActionPoints(chair);
-- check wich side of chair
local actionPointName = retrieveData("chairActionPointName");
print("Eat by table actionPointName" .. actionPointName);
if (actionPointName == "sit2") then
storeData("mirrorAnims", true);
else
storeData("mirrorAnims", false);
end
end
else
-- chair does not exist anymore
print("no chair");
getParent().setEmoticon(EMOTICON_NOSEAT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitAndGoAway();
return
end
-- tablet can be a pizza box too
local tablet = getParent().getLeftHeldObject();
if (not tablet) then
print("no tablet");
freeHands(getParent());
exitAndGoAway();
return
end;
getParent().detachLeftObjectHolder();
getParent().handSO.stopPose();
local tableVer = getTableVersion(tablet);
if (tableVer ~= tablet) then tablet.deleteGameObject(); end;
tablet = tableVer;
if (not tablet) then
print("no table tablet");
exitAndGoAway();
return
end;
tablet.buy(); -- pay money for food
storeStateObject("tablet", tablet);
local table = retrieveStateObject("table");
local tableActionPointName = retrieveData("tableActionPointName");
local tableHeight = table.getTableHeight();
local tablePos = tablet.tableYPosition;
if (not tablePos) then print("WARNING no attribute -tableYPosition- found"); tablePos = 0; end;
table.addObjectToActionPoint(tablet, tableActionPointName, 0, tablePos, tableHeight);
setPose("sitdownChair", retrieveData("mirrorAnims"));
--print("sitDown onEnter mirrorAnims" .. retrieveData("mirrorAnims"));
chair.startAnimation("ChairSitdown");
chair.playSound("Stuhl hinsetzen");
-- send a delayed message for sit sound
sendDelayedMsgThis("sitSound", 2500);
end )
--
onMsg("end", function(msg)
setCurrentPosition();
if testCancel() then
setState("standUp");
else
setState("eatSitting");
end
end )
onMsg("queue", function(msg)
setState("standUp");
end )
onMsg("sitSound", function(msg)
local chair = retrieveStateObject("chair");
--chair.playSound("Stuhl setzen");
makeChairSound(chair, "Down");
end )
onMsg("act", function(msg)
doSomething();
sendDelayedMsgThis("act", 5000);
end )
-- eat sitting on chair
state("eatSitting")
onEnter(function(msg)
print("eatSitting onEnter");
local tablet = retrieveStateObject("tablet");
--local eat = getParent().startActivity("eat", tablet);
local eat = getParent().startActivity(getEatActivityName(tablet), tablet);
local length = getActivityLength(eat);
print("eatSitting onEnter started " .. getEatActivityName(tablet) .. " on ".. tablet.getType() .." for " .. length);
local chair = retrieveStateObject("chair");
getParent().startActivity("sit", chair);
-- doesnt work because of a bug. objects are not deleted if tablet is.
-- local fork = tablet.createGameObject("fork");
-- local knife = tablet.createGameObject("knife");
-- local glass = tablet.createGameObject("glass");
local glassName = cond(tablet.glass, tablet.glass, "glass")
storeData("glassName", glassName);
-- create hand objects
local fork = getParent().loadGameObject("StandardGO","fork");
local knife = getParent().loadGameObject("StandardGO","knife");
local glass = getParent().loadGameObject("StandardGO", glassName);
storeStateObject("fork", fork);
storeStateObject("knife", knife);
storeStateObject("glass", glass);
fork.setVisibility(false);
knife.setVisibility(false);
glass.setVisibility(false);
-- fork.setMeshVisibility("fork", false);
-- knife.setMeshVisibility("knife", false);
-- glass.setMeshVisibility("glass", false);
-- getParent().attachLeftObjectHolder(fork);
-- getParent().attachRightObjectHolder(knife);
-- getParent().attachRightObjectHolder(glass);
sendDelayedMsgThis("lookForPartner", 1200);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
sendDelayedMsgThis("testComplete", length);
sendMsgThis("startLoop");
local buttonText = tablet.buttonText;
if (not buttonText) then buttonText = "pm_eat"; end;
setTopQueueEntry(getParent(), buttonText)
end )
onExit(function(msg)
print("eatSitting onExit");
local table = retrieveStateObject("table");
dirtify(table, DIRTIFY_PER_TABLE_EAT);
partner = retrieveStateObject("partner");
if (partner) then
print("eatSitting onExit: getParent().stopAllActivities(partner)");
getParent().stopAllActivities(partner);
removeStateObject("partner");
end
end )
onMsg("startLoop", function(msg)
startAnimation("eatSitting", false);
sendDelayedMsgThis("grabFork", 1200);
sendDelayedMsgThis("grabKnife", 1200);
sendDelayedMsgThis("eatSound", 3500);
sendDelayedMsgThis("dropFork", 8000);
sendDelayedMsgThis("dropKnife", 8000);
sendDelayedMsgThis("eatSound", 7000);
sendDelayedMsgThis("grabGlass", 9400);
sendDelayedMsgThis("drinkSound", 10500);
sendDelayedMsgThis("dropGlass", 12200);
end )
onMsg("eatSound", function(msg)
getParent().playSound("eat2");
end )
onMsg("drinkSound", function(msg)
getParent().playSound(genderizeReal(getParent(), "drink"));
end )
onMsg("grabFork", function(msg)
-- show hand fork
local fork = retrieveStateObject("fork");
fork.setVisibility(true);
--fork.setMeshVisibility("fork", true);
--fork.setEnable(true, false);
getParent().attachLeftObjectHolder(fork);
-- hide tablet fork
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("fork", false); end;
end )
onMsg("grabKnife", function(msg)
-- show hand knife
local knife = retrieveStateObject("knife");
knife.setVisibility(true);
--knife.setMeshVisibility("knife", true);
--knife.setEnable(true, false);
getParent().attachRightObjectHolder(knife);
-- hide tablet knife
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("knife", false); end;
end )
onMsg("grabGlass", function(msg)
-- show hand glass
local glass = retrieveStateObject("glass");
glass.setVisibility(true);
--glass.setMeshVisibility("glass", true);
--glass.setEnable(true, false);
getParent().attachRightObjectHolder(glass);
-- hide tablet glass
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("glass", false); end;
end )
onMsg("dropFork", function(msg)
-- hide hand fork
local fork = retrieveStateObject("fork");
fork.setVisibility(false);
--fork.setMeshVisibility("fork", false);
--fork.setEnable(false, false);
getParent().detachLeftObjectHolder();
-- show tablet fork
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("fork", true); end;
end )
onMsg("dropKnife", function(msg)
-- hide hand knife
local knife = retrieveStateObject("knife");
knife.setVisibility(false);
--knife.setMeshVisibility("knife", false);
--knife.setEnable(false, false);
getParent().detachRightObjectHolder();
-- show tablet knife
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("knife", true); end;
end )
onMsg("dropGlass", function(msg)
-- hide hand glass
local glass = retrieveStateObject("glass");
glass.setVisibility(false);
--glass.setMeshVisibility("glass", false);
--glass.setEnable(false, false);
getParent().detachRightObjectHolder();
-- show tablet glass
local tablet = retrieveStateObject("tablet");
if (tablet) then tablet.setChildEnable("glass", true); end;
end )
onMsg("lookForPartner", function(msg)
local table = retrieveStateObject("table");
local partner = getTableTalkPartner(getParent(), table);
if (not partner) then
print("lookForPartner: no partner found");
partner = retrieveStateObject("partner");
if (partner) then
print("lookForPartner: getParent().stopAllActivities(partner)");
getParent().stopAllActivities(partner);
removeStateObject("partner");
end
sendDelayedMsgThis("lookForPartner", 1000);
return
end
storeStateObject("partner", partner);
if (isEating(getParent()) and isEating(partner)) then
if (getParent().hasActivityName("eatDinner") and partner.hasActivityName("eatDinner") and hasLightenCandles(table)) then
-- start candle light dinner
print("start candlelightDinner " .. getParent().getCharacterName() .. " -> " .. partner.getCharacterName());
local candlelightDinner = getParent().startActivity("candlelightDinner", partner);
local length = getActivityLength(candlelightDinner);
print("start candlelightDinner " .. getParent().getCharacterName() .. " -> " .. partner.getCharacterName() .. " for " .. length);
sendDelayedMsgThis("complete", length);
else
-- start normal eating together
if (not getParent().hasActivityName("eatTogether")) then
-- start activity "eat together
local eatTogether = getParent().startActivity("eatTogether", partner);
end
end
end
sendDelayedMsg("talk", getParent().mimicSO, random(0,9000));
sendDelayedMsgThis("lookForPartner", 13000);
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("testComplete", function(msg)
if (getParent().hasActivityName("candlelightDinner")) then
sendDelayedMsgThis("testComplete", CANCEL_POLLING_INTERVAL);
else
sendMsgThis("complete");
end
end )
onMsg("complete", function(msg)
getParent().detachLeftObjectHolder();
getParent().detachRightObjectHolder();
local fork = retrieveStateObject("fork");
if (fork) then fork.deleteGameObject(); removeStateObject("fork"); end;
local knife = retrieveStateObject("knife");
if (knife) then knife.deleteGameObject(); removeStateObject("knife"); end;
local glass = retrieveStateObject("glass");
if (glass) then glass.deleteGameObject(); removeStateObject("glass"); end;
setState("standUp");
end )
onMsg("end", function(msg)
-- if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("complete");
else
sendMsgThis("startLoop");
end
end )
-- stand up from chair
state("standUp")
onEnter(function(msg)
print("standUp::onEnter");
local tablet = retrieveStateObject("tablet");
local plate = getDirtyDishVersion(tablet);
if (tablet) then
getParent().stopAllActivities(tablet);
tablet.deleteGameObject();
end;
-- place dirty plate on table
--local plate = getParent().loadGameObject("StandardGO","plate");
local table = retrieveStateObject("table");
local actionPointName = retrieveData("tableActionPointName");
plate.storeData("placeActionPointName", actionPointName);
local tableHeight = table.getTableHeight();
local tablePos = plate.tableYPosition;
if (not tablePos) then print("WARNING no attribute -tableYPosition- found"); tablePos = 0; end;
table.addObjectToActionPoint(plate, actionPointName, 0, tablePos, tableHeight);
startAnimation("standupChair", retrieveData("mirrorAnims"));
sendDelayedMsgThis("upSound", 900);
local chair = retrieveStateObject("chair");
chair.startAnimation("ChairSitdown", -1);
getParent().stopAllActivities(chair);
end )
onMsg("upSound", function(msg)
local chair = retrieveStateObject("chair");
makeChairSound(chair, "Up");
end )
onMsg("end", function(msg)
setCurrentPosition();
exitAndGoAway();
end )
endStateMachine()