home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Script / initGame.lua < prev    next >
Text File  |  2004-03-05  |  79KB  |  2,746 lines

  1. -- globals
  2. include("globals")
  3.  
  4. -- disable print if wstats is not defined mode
  5. if (not isDefined("WSTATS")) then
  6.     print("disabling lua print");
  7.     print = function() end
  8. end
  9.  
  10. -- high level convenience scription functions
  11.  
  12. -- this: global
  13. -- object: StandardGO
  14. -- checks if this item is on a table, if there is a chair on the closest
  15. -- action point and returns the chair game object, otherwise it returns nil
  16.  
  17. function getChairForItemOnTable(object, character)
  18.  
  19.     local goParent = object.getGOParent();
  20. --    local currentCharacter = object.getGameObjectServer().getCurrentCharacter();
  21.     
  22.     if (goParent) then
  23.         if (goParent.hasBehavior("table")) then
  24.             -- check if chair is on action point
  25. --            local chairActionPoint = object.getClosestActionPoint(currentCharacter);
  26.             local chairActionPoint = object.getActionPoint("chair");
  27.             if (chairActionPoint) then
  28.                 local chair = object.getGameObjectOnActionPoint(chairActionPoint.getName());
  29.                 if (chair) then
  30.                     if (chair.hasBehavior("chair")) then
  31.                         --orientation must be correct
  32.                         if (chair.hasActionPointOrientation(chairActionPoint)) then
  33.                             return chair;
  34.                         else
  35.                             print("wrong orientation");
  36.                         end
  37.                     else
  38.                         print("this is not a chair");
  39.                     end
  40.                 else
  41.                     print("must sit on something");
  42.                 end
  43.             else
  44.                 print("the current object has no action point");
  45.             end
  46.         else
  47.             print("the computer must stand on a table");
  48.         end
  49.     else
  50.         print("the computer must not stand on the ground");
  51.     end    
  52.     
  53.     return nil;
  54. end
  55.  
  56.  
  57.  
  58. function enumCompare(enum1, enum2)
  59.     if (tonumber(enum1) == tonumber(enum2)) then
  60.         return true;
  61.     else
  62.         return false;
  63.     end
  64. end
  65.  
  66.  
  67. -- this: walkStateObject
  68. -- chooses an action and does the action, if one was chosen
  69. function doSomething()
  70.  
  71.     local character = getParent();
  72.     print("doSomething "  .. character.getCharacterName() .. "--getActivityQueueCount:" .. character.getActivityQueueCount());
  73.     
  74.     if (character.getActivityQueueCount() == 0) then
  75.         
  76.         -- AI
  77.         local ai = character.getGameObjectServer().autonomousCharacters();
  78.         -- local ai = (readConfig("Interface", "autonomousCharacters", "true") == "true");
  79.  
  80.         if (ai) then
  81.                 
  82.             if (not urgentOutfitChange(character)) then
  83.             
  84.                 print("doSomething chooseCommand");
  85.                 local chosenObjectCommand = character.chooseCommand();
  86.                 if (chosenObjectCommand) then
  87.                     print("doSomething queue chosenObjectCommand");
  88.                     character.queueCommand(chosenObjectCommand, true);
  89.                 else
  90.                     --print("doSomething goAway");
  91.                     if (character.isSwimming()) then
  92.                         sendMsg("goAway", character.walkSO);
  93.                     else
  94.                         makeConditionPose();
  95.                     end
  96.                 end
  97.             end
  98.                     
  99.         else
  100.             print("doSomething ai disabled");
  101.             makeConditionPose();
  102.         end
  103.         
  104.         
  105.     end
  106. end
  107.  
  108. function urgentOutfitChange(character)
  109.  
  110. --    if (not character.getGameObjectServer().automaticActions()) then
  111. --        return false;
  112. --    end
  113.     
  114.     if not checkShyness(character) then
  115.         return false;
  116.     end
  117.     
  118.     local kommoden = character.getPrivateObjectsWithBehavior("kommode");
  119.     for k = 1, getn(kommoden) do
  120.         local kommode = kommoden[k];
  121.         if (not kommode.isBroken()) then
  122.             local outfit = character.getOutfitDescription(ARCHTYPE);
  123.             character.queueCommand(outfit.getName(), "outfit", kommode, tostring(outfit.getID()));
  124.             return true;
  125.         end    
  126.     end
  127.     
  128.     return false;
  129. end
  130.  
  131. -- this: walkStateObject
  132. --function urgentArgueCharacter(activeCharacter)
  133. --    
  134. --    local others = activeCharacter.getOtherCharacters();
  135. --    
  136. --    for index, passiveCharacter in others do
  137. --        if (checkInjustice(activeCharacter, passiveCharacter) and not passiveCharacter.isBusy()) then
  138. --            activeCharacter.queueCommand("pm_talkArgue", "talk", passiveCharacter, "Argue");
  139. --            return true;
  140. --        end
  141. --    end
  142. --    
  143. --    return false;
  144. --end
  145.  
  146. function checkInjustice(activeCharacter)
  147.  
  148.     local justiceValue = activeCharacter.getCondition(NEED_JUSTICE);
  149.     local tolerance = activeCharacter.getJusticeTolerance();
  150.     local passiveCharacter = getOtherCharacter(activeCharacter);
  151.     
  152.     if (justiceValue < activeCharacter.getJusticeTolerance()) and (not passiveCharacter.isBusy()) then
  153.         activeCharacter.queueCommand("pm_talkArgue", "talk", passiveCharacter, "Argue");
  154.         return true;
  155.     end
  156.     
  157.     if (justiceValue < lerp(tolerance, 1.0, tonumber(readConfig("Game", "justiceWarningLevel", "0.3")))) then
  158.         activeCharacter.setEmoticon(EMOTICON_JUSTICE, EMOTICON_DELAY);
  159.         return true;
  160.     end
  161.     
  162.     return false;
  163.     
  164. end
  165.  
  166.  
  167. -- this: walkStateObject
  168. function makeConditionPose()
  169.  
  170.     local character = getParent();
  171.     
  172.     if checkShyness(character) then
  173.         return
  174.     end
  175.     
  176. --    if (urgentArgueCharacter(character)) then
  177. --        return
  178. --    end
  179.  
  180.     if (not character.getGameObjectServer().automaticActions()) then
  181.         return
  182.     end
  183.     
  184.     if checkInjustice(character) then
  185.         return
  186.     end
  187.     
  188.     local now = character.getGameObjectServer().getGameTime();
  189.     local nextPoseTime = character.retrieveData("nextPoseTime", 0);
  190.     --print("makeConditionPose: now " .. now .. " nextPoseTime " .. nextPoseTime .. " for " .. character.getCharacterName());
  191.     
  192.     if (now < nextPoseTime) then
  193.         --print("makeConditionPose: return now < nextPoseTime");
  194.         return
  195.     end
  196.     
  197.     character.setEmoticon("");
  198.     
  199.     nextPoseTime = now + random(CONDITION_POSE_PAUSE, CONDITION_POSE_PAUSE * 2);
  200.     
  201.     if (random() > CONDITION_POSE_PROB) then
  202.         --print("makeConditionPose: return CONDITION_POSE_PROB");
  203.         character.storeData("nextPoseTime", nextPoseTime);
  204.         return
  205.     end
  206.     
  207.     -- interaction poses
  208.     local partner = getOtherCharacter(character);
  209.             
  210.     local needs = character.getNeedsSorted();
  211.     local worstNeed = needs[1];
  212.     --print("  worstNeed:", worstNeed);
  213.     
  214.     --for testing
  215.     if (enumCompare(worstNeed, NEED_APARTMENT)) then worstNeed = needs[2]; end;
  216.     
  217.     local worstNeedValue = character.getCondition(worstNeed);
  218.     --print("  worstNeedValue:", worstNeedValue);
  219.     
  220.     
  221.     if (partner) then
  222.         local distance = character.getDistanceToGameObject(partner);
  223.         
  224.         -- smell the other character
  225.         if (distance < 2.0) then
  226.             local partnersHygiene = partner.getCondition(NEED_HYGIENE);
  227.             local partnersState = partner.walkSO.getStateMachine().getName();
  228.             if ((partnersHygiene < 0.2) or (partnersState == "toiletChar")) then
  229.                 partner.sendMsg("emoYouSmell", character.walkSO);
  230.                 character.setEmoticon(EMOTICON_SMELL, EMOTICON_DELAY);
  231.                 character.storeData("nextPoseTime", nextPoseTime);
  232.                 return
  233.             end
  234.         end
  235.         
  236.         -- flirt
  237.         if (distance < 4.0) then
  238.             if (enumCompare(worstNeed, NEED_LIBIDO) and (worstNeedValue < 0.2)) then
  239.                 partner.sendMsg("emoFlirt", character.walkSO);
  240.                 character.setEmoticon(EMOTICON_EROTIC, EMOTICON_DELAY);
  241.                 character.storeData("nextPoseTime", nextPoseTime);
  242.                 return
  243.             end
  244.         end
  245.         
  246.     end
  247.     
  248.     
  249.     
  250.     
  251.     if (worstNeedValue > 0.7) then
  252.         -- happy because all needs satisfied
  253.         character.setEmoticon(EMOTICON_SMILE, EMOTICON_DELAY);
  254.         sendMsg("emoHappy", character.walkSO);
  255.         character.storeData("nextPoseTime", nextPoseTime);
  256.         return
  257.     end
  258.     
  259.  
  260.     if (worstNeedValue > 0.2) then
  261.         -- nothing really critical
  262.         return
  263.     end
  264.     
  265.     
  266.     -- no fun
  267.     if (enumCompare(worstNeed, NEED_FUN)) then
  268.         sendMsg("emoSwing", character.walkSO);
  269.         character.setEmoticon(EMOTICON_SAD, EMOTICON_DELAY);
  270.         character.storeData("nextPoseTime", nextPoseTime);
  271.     -- no comfort
  272.     elseif (enumCompare(worstNeed, NEED_COMFORT)) then
  273.         sendMsg("emoSwing", character.walkSO);
  274.         character.setEmoticon(EMOTICON_SAD, EMOTICON_DELAY);
  275.         character.storeData("nextPoseTime", nextPoseTime);
  276.     -- bad apartment
  277.     elseif (enumCompare(worstNeed, NEED_APARTMENT)) then
  278.         sendMsg("emoThink", character.walkSO);
  279.         character.setEmoticon(EMOTICON_APARTMENT, EMOTICON_DELAY);
  280.         character.storeData("nextPoseTime", nextPoseTime);
  281.     -- no hygiene
  282.     elseif (enumCompare(worstNeed, NEED_HYGIENE)) then
  283.         sendMsg("emoHygiene", character.walkSO);
  284.         character.setEmoticon(EMOTICON_SMELL, EMOTICON_DELAY);
  285.         character.storeData("nextPoseTime", nextPoseTime);
  286.     -- hungry
  287.     elseif (enumCompare(worstNeed, NEED_HUNGER)) then
  288.         sendMsg("emoHungry", character.walkSO);
  289.         character.setEmoticon(EMOTICON_SAD, EMOTICON_DELAY);
  290.         character.storeData("nextPoseTime", nextPoseTime);
  291.     -- tired
  292.     elseif (enumCompare(worstNeed, NEED_TIREDNESS)) then
  293.         sendMsg("emoYawn", character.walkSO);
  294.         character.setEmoticon(EMOTICON_SLEEPY, EMOTICON_DELAY);
  295.         character.storeData("nextPoseTime", nextPoseTime);
  296.     end
  297.     
  298.  
  299. end
  300.  
  301. -- returns true if character activeCharacter is ashamed of passiveCharacter
  302. -- in the current state
  303. function isCharacterAshamed(activeCharacter, passiveCharacter)
  304.  
  305.     if (hasOutfit(activeCharacter, UNDERWEAR) or hasOutfit(activeCharacter, TOWEL)) then
  306.         local activity = activeCharacter.createActivity("showInUnderwear", passiveCharacter)
  307.         return not enumCompare(activity.getActivityResult(), POSSIBLE)
  308.     elseif hasOutfit(activeCharacter, NOTHING) then
  309.         local activity = activeCharacter.createActivity("showNaked", passiveCharacter)
  310.         return not enumCompare(activity.getActivityResult(), POSSIBLE)
  311.     end
  312.     
  313.     return false;
  314. end
  315.     
  316. function checkShyness(character)
  317.  
  318.     if (hasOutfit(character, UNDERWEAR) or hasOutfit(character, TOWEL)) then
  319.         local other, result = getDisturbingChar(character, "showInUnderwear")
  320.         if (other) then
  321.             --character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  322.             other.sendMsg("emoShameChar", character.walkSO);        
  323.             return true;    
  324.         end;
  325.     elseif hasOutfit(character, NOTHING) then
  326.         local other, result = getDisturbingChar(character, "showNaked")
  327.         if (other) then
  328.             --character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  329.             other.sendMsg("emoShameNackedChar", character.walkSO);        
  330.             return true;    
  331.         end;
  332.     end;
  333.  
  334.     return false;    
  335.  
  336.  
  337. --    
  338. --    local others = character.getCharactersInRoom();
  339. --            
  340. --    for c = 1, getn(others) do
  341. --        local other = others[c];
  342. --        --print("checkShyness other found");
  343. --        if (not activityPossible(character, "showInUnderwear", other)) then
  344. --            --print("checkShyness sendMsg emoShame");
  345. --            character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  346. --            other.sendMsg("emoShameChar", character.walkSO);        
  347. --            return true;    
  348. --        end;
  349. --    end;
  350. --    
  351. --    return false;
  352.     
  353. end
  354.  
  355. -- looks for other character in same room on wich the given activity is not possible
  356. function getDisturbingChar(character, activity)
  357.  
  358.     local others = character.getCharactersInRoom();
  359.             
  360.     for c = 1, getn(others) do
  361.         local other = others[c];
  362.         
  363.         local watchedActionPoint = other.getActionPoint("kiss");
  364.         local watchingActionPoint = character.getActionPoint("kiss");
  365.         
  366.         -- check line of sigth
  367.         local gameObjectServer = character.getGameObjectServer();
  368.         --local blockingObject = gameObjectServer.getGameObjectBetween(watchingActionPoint, watchedActionPoint, 1.5, 1.5);
  369.         local blockingObject = character.getGameObjectBetween(other, "center", "center", 1.7, 1.7);
  370.         if (not blockingObject) then
  371.             if (not character) then print("getDisturbingChar character == nil"); end;                    
  372.             local possible, result = activityPossible(character, activity, other);
  373.             if (not possible) then
  374.                 return other, result;    
  375.             end;
  376.         else
  377.             print("getDisturbingChar :: Sight from " .. character.getType() .. " blocked by " .. blockingObject.getType());
  378.             return nil;
  379.         end
  380.     end;
  381.     
  382.     return nil;    
  383. end
  384.  
  385.  
  386. function getActionPointsInSight(fromObject, fromActionPointName, fromHeight, toObject, toActionPointNames, toHeight, ignoredObject)
  387.  
  388.     local result = {};
  389.     
  390.     for p = 1, getn(toActionPointNames) do
  391.         local toActionPointName = toActionPointNames[p];
  392. --        local blockingObject = fromObject.getGameObjectBetween(toObject, fromActionPointName, toActionPointName, fromHeight, toHeight, true);
  393.         local blockingObject = ignoredObject.getGameObjectBetween(fromObject, toObject, fromActionPointName, toActionPointName, fromHeight, toHeight, true);
  394.         
  395. --        if ((not blockingObject) or (blockingObject == ignoredObject)) then
  396.         if not blockingObject then
  397.             print("getActionPointsInSight toActionPointName:" .. toActionPointName .. " OK");
  398.             tinsert(result, toActionPointName);
  399.         else
  400.             print("getActionPointsInSight toActionPointName:" .. toActionPointName .. " blocked by:" .. blockingObject.getType());
  401.         end
  402.     end
  403.     
  404.     --print("getActionPointsInSight input:  " .. tostring(toActionPointNames))
  405.     --print("getActionPointsInSight output: " .. tostring(result))
  406.     
  407.     return result;
  408. end
  409.  
  410.  
  411. function getOtherCharacter(thisChar)
  412.     if (thisChar) then
  413.         local others = thisChar.getOtherCharacters();
  414.         return others[1];
  415.     else
  416.         return nil
  417.     end
  418. end
  419.  
  420.  
  421. -- this: walkStateObject
  422. function actionComplete()
  423.     if (this.actionComplete()) then
  424.         doSomething();
  425.     end
  426. end
  427.  
  428. -- this: walkStateObject
  429. -- this is called when the caracter is sleeping    
  430. -- returns true if sleeping shall be canceled
  431. function testCancelSleeping()
  432.     local goOnSleeping = true 
  433.     
  434.     local character = getParent()
  435.     
  436.     -- local currentDate = GameDate.createGameDate(character.getGameObjectServer().getGameTime());
  437.     local currentDate = character.getGameObjectServer().getGameDate()
  438.     local workPrepareTime = character.retrieveData("workPrepareTime", 2);
  439.     local getUpTime = character.getWorkBeginTime().getHoursF() - workPrepareTime;
  440.     
  441. --    print("testCancelSleeping: " .. character.getCharacterName() .. "-------------------------");
  442. --    print("workPrepareTime: " .. workPrepareTime);
  443. --    print("getUpTime: " .. getUpTime);
  444. --    print("character.getCondition(NEED_TIREDNESS): " .. character.getCondition(NEED_TIREDNESS));
  445. --    print("currentDate.isWorkingDay(): " .. tostring(currentDate.isWorkingDay()));
  446. --    print("currentDate.getHoursF(): " .. currentDate.getHoursF());
  447.             
  448.     -- get up if it is time to get up
  449.     -- characters must be at least "minGetUpTiredness" rested
  450.     local minGetUpTiredness = tonumber(readConfig("Game", "minGetUpTiredness", "0.8"));
  451.     
  452.     if (character.getCondition(NEED_TIREDNESS) > minGetUpTiredness) then
  453.         -- check if this is working day
  454.         if (currentDate.isWorkingDay()) then
  455.             local sleepActivity = character.getCurrentActivity();
  456.             if (currentDate.getHoursF() > getUpTime) then
  457.                 if (sleepActivity) then
  458.                     -- local sleepStartDate = GameDate.createGameDate(sleepActivity.getStartTime());
  459.                     local sleepStartDate = character.getGameObjectServer().createGameDate(sleepActivity.getStartTime());
  460. --                    print("sleepStartDate.getDays(): " .. sleepStartDate.getDays());
  461. --                    print("currentDate.getDays(): " .. currentDate.getDays());
  462. --                    print("sleepStartDate.getHoursF(): " .. sleepStartDate.getHoursF());
  463.                     if ((sleepStartDate.getDays() < currentDate.getDays()) or 
  464.                         (sleepStartDate.getHoursF() < getUpTime)) then
  465.                         -- time to get up            
  466.                         goOnSleeping = false
  467.                     end
  468.                 end
  469.             end
  470.         end
  471.     end
  472.     
  473. --    -- get up if normal sleep duration in milliseconds passed
  474. --    if (sleepActivity) then
  475. --        local length = getActivityLength(sleepActivity);
  476. --        local currentTime = character.getGameObjectServer().getGameTime();
  477. --        local startTime = sleepActivity.getStartTime();
  478. --        print("length: " .. length);
  479. --        print("currentTime: " .. currentTime);
  480. --        print("startTime: " .. startTime);
  481. --        if (startTime+length < currentTime) then
  482. --            print("sleep duration passed: start:" .. startTime .. " stoptime:" .. startTime+length .. "currentTime:" .. currentTime);
  483. --            goOnSleeping = false;
  484. --        end
  485. --    end
  486.     
  487.     -- get up if not tired anymore and not in the middle of the night
  488.     local currentHours = currentDate.getHoursF();
  489.     local nightStart = tonumber(readConfig("Display", "nightTime", "22"));
  490.     local nightEnd = tonumber(readConfig("Display", "morningTime", "6"));
  491.     if (character.getCondition(NEED_TIREDNESS) > 0.99)
  492.         and (currentHours > nightEnd)
  493.         and (currentHours < nightStart) then
  494.         -- not tired anymore
  495.         goOnSleeping = false
  496.     end
  497.     
  498.     if (character.hasWalkQueued(1)) then
  499.         goOnSleeping = false;
  500.     end
  501.     
  502.     return (not goOnSleeping);
  503. end
  504.  
  505. -- looks for the closest free chair by a table
  506. function getNextFreeChairByTable(character, tableObject, checkPartnerChair)
  507.  
  508.     print("getNextFreeChairByTable");
  509.  
  510.     local tables = character.getObjectsWithBehavior("table");
  511.     -- go trough tables    
  512.     for t = 1, getn(tables) do
  513.         print(" table " .. t);
  514.         local table = tables[t]; 
  515.         local actionPoints = table.getActionPoints();
  516.         -- go trough action points of table
  517.         --for a, actionPoint in actionPoints  do
  518.         for a = 1, getn(actionPoints) do
  519.             local actionPoint = actionPoints[a];
  520.             local actionPointName = actionPoint.getName();
  521.             print(" actionPoint " .. actionPointName);
  522.             if (strsub(actionPointName,1,5) == "chair") then
  523.                 local chair = table.getGameObjectOnActionPoint(actionPointName);
  524.                 if (chair) then
  525.                     if (chair.hasBehavior("chair")) then
  526.                         local chairActionPoint = character.getClosestFreeActionPoint(character, chair, {"sit1", "sit2"}, true);
  527.                         if (chairActionPoint) then
  528.                             if (chair.hasActionPointOrientation(actionPoint)) then
  529.                                 local partnerChair = getOpposedChair(table, actionPointName);
  530.                                 print("getNextFreeChairByTable: partnerChair: "..tostring(partnerChair).." checkPartnerChair "..tostring(checkPartnerChair));
  531.                                 if (partnerChair or (not checkPartnerChair)) then
  532.                                     if (tableObject) then
  533.                                         local tablePos = tableObject.tableYPosition;
  534.                                         if (not tablePos) then print("WARNING no attribute -tableYPosition- found"); tablePos = 0; end;
  535.                                         local placeOnTable = table.canObjectBeAddedToActionPoint(tableObject, actionPointName, 0, tablePos, tableHeight);
  536.                                         if (placeOnTable) then                                
  537.                                             print("getNextFreeChairByTable:  enough place for tableObject" .. tableObject.getType());
  538.                                             return table, actionPointName, chair;
  539.                                         else
  540.                                             print("getNextFreeChairByTable:  no place on table for tableObject" .. tableObject.getType());
  541.                                         end
  542.     
  543.                                     else
  544.                                         print("getNextFreeChairByTable:  no tableObject to check");
  545.                                         return table, actionPointName, chair;
  546.                                     end
  547.                                 else
  548.                                     print("getNextFreeChairByTable partnerChair not found");
  549.                                 end    
  550.     
  551.                             else
  552.                                 print("getNextFreeChairByTable: free chair has wrong orient to table");
  553.                             end                                                                            
  554.                         else
  555.                             print("   getNextFreeChairByTable: chair is blocked");                                
  556.                         end
  557.                     else
  558.                         print("getNextFreeChairByTable: object is not a chair");                                
  559.                     end
  560.                 else
  561.                     print("getNextFreeChairByTable:nothing on actionPoint " .. actionPointName);                
  562.                 end
  563.             else
  564.                 print("getNextFreeChairByTable:not a chair actionPoint " .. actionPointName);                
  565.             end
  566.         end
  567.     end
  568.             
  569.     return nil;
  570. end
  571.  
  572. function getChildByStoredData(parent, dataName, data)
  573.  
  574.     local children = parent.getGOChildren();
  575.     for c = 1, getn(children) do
  576.         local child = children[c];
  577.         local childData = child.retrieveData(dataName);
  578.         if (childData and (childData == data)) then
  579.             return child;
  580.         end
  581.     end
  582.     return nil;
  583.  
  584. end
  585.  
  586. function getChildrenWithBehavior(parent, behavior)
  587.  
  588.     local result = {};
  589.     local children = parent.getGOChildren();
  590.     for c = 1, getn(children) do
  591.         local child = children[c];
  592.         if (child.hasBehavior(behavior)) then
  593.             tinsert(result, child);
  594.         end
  595.     end
  596.     return result;
  597.  
  598. end
  599.  
  600.  
  601. -- returns an object's action point wich is opposed to the action point described by actionPointName
  602. function getOpposedActionPoint(object, actionPointName)
  603.  
  604.     local actionPoint = object.getActionPoint(actionPointName);
  605.     if (not actionPoint) then
  606.         print("getOpposedActionPoint: no actionpoint with name " , actionPointName);
  607.     end
  608.     
  609.     local actionPoints = object.getActionPoints();
  610.     
  611.     for a = 1, getn(actionPoints) do
  612.         --local point = actionPoints[a];
  613.         --local name = currentActionPoint.getName();
  614.         if (not(actionPoints[a].getName() == actionPointName)) then
  615.         
  616.             local facing1 = actionPoints[a].getFacingFraction(actionPoint);            
  617.             local facing2 = actionPoint.getFacingFraction(actionPoints[a]);
  618.             local facing = facing1 + facing2;
  619.             
  620.             if (facing > 1.9) then
  621.                 return actionPoints[a];            
  622.             end
  623.             
  624.         end
  625.     end
  626.     
  627.     print("getOpposedActionPoint: no opposed actionpoint found for " , actionPointName);
  628.     return nil;
  629. end
  630.  
  631. function getOpposedChair(table, actionPointName)
  632.  
  633.     local oppActionPoint = getOpposedActionPoint(table, actionPointName);    
  634.     if (not oppActionPoint) then
  635.         --print("getOpposedChair: no opposed actionpoint found for " , actionPointName);
  636.         return nil;
  637.     end
  638.     
  639.     local chair = table.getGameObjectOnActionPoint(oppActionPoint.getName());
  640.     if (not chair) then
  641.         --print("getOpposedChair: nothing on opposed actionpoint " , oppActionPoint.getName());
  642.         return nil;
  643.     end
  644.     
  645.     if (not chair.hasBehavior("chair")) then
  646.         --print("getOpposedChair: not a chair on opposed actionpoint " , oppActionPoint.getName());
  647.         return nil;
  648.     end
  649.     
  650.     return chair;
  651.     
  652. end
  653.  
  654. function getTableForChair(chair)
  655.  
  656.     local tables = chair.getObjectsWithBehavior("table");
  657.     -- go trough tables    
  658.     for t = 1, getn(tables) do
  659.         print(" table " .. t);
  660.         local table = tables[t]; 
  661.         local actionPoints = table.getActionPoints();
  662.         -- go trough action points of table
  663.         for a = 1, getn(actionPoints) do
  664.             local actionPoint = actionPoints[a];
  665.             local actionPointName = actionPoint.getName();
  666.             if (strfind(actionPointName, "chair") == 1) then
  667.                 print(" actionPoint " .. actionPointName);
  668.                 local go = table.getGameObjectOnActionPoint(actionPointName);
  669.                 
  670.                 if (go == chair) then
  671.                     if (chair.hasActionPointOrientation(actionPoint)) then
  672.                         print("getTableForChair: return actionPointName " .. actionPointName);
  673.                         return table, actionPointName;
  674.                     end                                                                            
  675.                 end
  676.             end
  677.         end
  678.     end
  679.     
  680.     return nil;
  681.     
  682. end
  683.  
  684. ---- this: walk state object
  685. --function goAway()
  686. --    local queueCount = getQueueCount();
  687. --    print("queueCount: " .. queueCount);
  688. --    if (queueCount < 1) then 
  689. --        sendMsg("goAway", this);
  690. --    else
  691. --        print("dont go away, somthing to do");
  692. --    end
  693. --end
  694.  
  695.  
  696. -- this: walk state object
  697. function exitAndGoAway(minDist)
  698.  
  699.         
  700.     exitStateMachine()
  701.     
  702.     local activityQueueCount = getParent().getActivityQueueCount();
  703.     if (activityQueueCount > 0) then 
  704.         print("something to do! activityQueueCount:" .. activityQueueCount);
  705.     else
  706.         print("nothing to do -> go away !!!");
  707.         if (minDist) then
  708.             sendDelayedMsgThis("goAway", 500, tostring(minDist));
  709.         else
  710.             sendDelayedMsgThis("goAway", 500);
  711.         end
  712.     end
  713.     
  714. end
  715.  
  716.  
  717. function queueNextClean(character)
  718.     
  719.     --local character = getParent();            
  720.     local activityQueueCount = character.getActivityQueueCount();    
  721.     if (activityQueueCount > 1) then 
  722.         print("queueNextClean something to do! activityQueueCount:" .. activityQueueCount);
  723.         return
  724.     end
  725.     
  726.     local tiredness = character.getCondition(NEED_TIREDNESS);
  727.     if (tiredness < 0.1) then 
  728.         print("queueNextClean too tired" .. tiredness);
  729.         return
  730.     end
  731.     
  732.     local nextDirty = getNextDirtyObject(character);
  733.     if (nextDirty) then
  734.         print("queueNextClean next:" .. nextDirty.getType());
  735.         character.queueCommand("pm_clean", "clean", nextDirty, "");
  736.     else
  737.         print("queueNextClean nothing to clean");
  738.     end 
  739.     
  740. end
  741.  
  742. function getNextDirtyObject(character)
  743.  
  744.     local cleanables = character.getObjectsWithBehavior("cleanable");
  745.     local characterRoom = character.getRoomNumber();
  746.     for c = 1, getn(cleanables) do
  747.         local cleanable = cleanables[c];
  748.         if (cleanable.getDirtiness() > 0.01) and (cleanable.getRoomNumber() == characterRoom) then
  749.             return cleanable;
  750.         end
  751.     end 
  752.     
  753.     return nil;
  754.  
  755. end
  756.  
  757. function getNextTableWithDishes(character)
  758.  
  759.     local tables = character.getObjectsWithBehavior("table");
  760.     local dishFound = false;
  761.     -- go trough tables    
  762.     for t = 1, getn(tables) do
  763.         print(" table " .. t);
  764.         local table = tables[t];
  765.         local dishes = getChildrenWithBehavior(table, "dish");
  766.         local dish = dishes[1];
  767.         
  768.         if (dish) then
  769.             dishFound = true;
  770.             --local actionPoint = character.getClosestFreeActionPoint(dish, table, {"front1", "front2"});
  771.             local actionPoint = character.getClosestFreeActionPoint(dish, table);
  772.             if (actionPoint) then
  773.                 return table, actionPoint, dishFound;
  774.             else
  775.                 print("no actionPoint");
  776.             end
  777.         else
  778.             print("no dish");
  779.         end
  780.                 
  781. --        if (getn(dishes) > 0) then
  782. --            return table;
  783. --        end
  784.          
  785.     end
  786.     return nil, nil, dishFound;
  787. end
  788.  
  789.  
  790. function getReachableObjectWithBehavior(character, behavior, actionPointNames, checkBroken)
  791.  
  792.     local objects = character.getObjectsWithBehavior(behavior);
  793.     for o = 1, getn(objects) do
  794.         local object = objects[o];
  795.         if ((not checkBroken) or (not object.isBroken())) then
  796.             local actionPoint = character.getClosestFreeActionPoint(character, object, actionPointNames, true);
  797.             if (actionPoint) then
  798.                 return object, actionPoint;
  799.             end
  800.         end
  801.     end
  802.     return nil;
  803.     
  804. end
  805.  
  806.  
  807. function getNextReadSit(character)
  808.  
  809.     return getReachableObjectWithBehavior(character, "readSeat", {"sit", "sit1", "sit2", "sit3"}, true)
  810.  
  811.  
  812. --    local seats = character.getObjectsWithBehavior("readSeat");
  813. --    print("getNextReadSit total seats" .. getn(seats));
  814. --    for s = 1, getn(seats) do
  815. --        local seat = seats[s];
  816. --        print("   getNextReadSit seat no" .. s);
  817. --        
  818. --        if (not seat.isBroken()) then
  819. --        
  820. --            print("seat " .. s .. " is " .. seats[s].getResourceName());
  821. --            local actionPoint = character.getClosestFreeActionPoint(character, seat, {"sit", "sit1", "sit2", "sit3"}, true);
  822. --            if (actionPoint) then
  823. --                return seat, actionPoint;
  824. --            end
  825. --        
  826. --        end
  827. --    end
  828. --    return nil;    
  829. end
  830.  
  831. -- looks for a seat to watch an objects "watch" actionpoint
  832. function getNextWatchSit(character, watchedObject, objectHeight, seatHeigth)
  833.     print("getNextWatchSit");
  834.     
  835.     watchedActionPoint = watchedObject.getActionPoint("watch");
  836.     if (not watchedActionPoint) then
  837.         print("watchedObject has no action point --watch--");
  838.         return nil;
  839.     end    
  840.     
  841.     local bestSeat = nil;
  842.     local bestActionPointName = "";
  843.     local bestFacing = 1;
  844.     
  845.     local maxFacing = MAX_WATCH_FACING;
  846.     local maxDistance = MAX_WATCH_DISTANCE;
  847.  
  848.     local gameObjectServer = watchedObject.getGameObjectServer();
  849.     local seats = watchedObject.getObjectsWithBehavior("watchSeat", maxDistance + 1);
  850.     
  851.     for s = 1, getn(seats) do
  852.         local seat = seats[s];
  853.         print(" seat:" .. s .. " type:" .. seat.getType());
  854.         
  855.         if (not seat.isBroken()) then
  856.             
  857.             local actionPoints = character.getFreeActionPoints(seat, {"sit", "sit1", "sit2", "sit3"});
  858.             
  859.             for a = 1, getn(actionPoints) do
  860.             
  861.                 local actionPoint = actionPoints[a];
  862.                 if (character.canReachActionPoint(actionPoint)) then
  863.             
  864.                     local facing1 = actionPoint.getFacingFraction(watchedActionPoint);
  865.                     local facing2 = watchedActionPoint.getFacingFraction(actionPoint);
  866.                     local facing = max(facing1, facing2); --facing1 + facing2;
  867.                     local distance = actionPoint.getDistance(watchedActionPoint)
  868.                                 
  869.                     print("getNextWatchSit distance:"..distance.." facing1:"..facing1.." facing2:"..facing2.." facing:"..facing.." maxFacing:"..maxFacing);
  870.                     
  871.                     if ((facing < MAX_WATCH_FACING) and (distance < MAX_WATCH_DISTANCE)) then
  872.                         if (facing < bestFacing) then
  873.                         
  874.                             -- check line of sigth
  875.                             --local blockingObject = character.getGameObjectBetween(actionPoints[a], watchedActionPoint, seatHeigth, objectHeight);
  876.                             --local blockingObject = seat.getGameObjectBetween(watchedObject, actionPoint.getName(), watchedActionPoint.getName(), seatHeigth, objectHeight, true);
  877.                             local blockingObject = character.getGameObjectBetween(seat, watchedObject, actionPoint.getName(), watchedActionPoint.getName(), seatHeigth, objectHeight, true);
  878.                             if (not blockingObject) then
  879.                                 bestSeat = seat;
  880.                                 bestActionPointName = actionPoint.getName(); 
  881.                                 bestFacing = facing;
  882.                             else
  883.                                 print("Sight from action point " .. actionPoint.getName() .. " blocked by " .. blockingObject.getResourceName());
  884.                             end
  885.                         end
  886.                     end
  887.                 end            
  888.             end
  889.             
  890.         else
  891.             print("seat " .. seat.getType() .. " broken");
  892.         end
  893.         
  894.         
  895.  
  896.     end
  897.     
  898.     if (bestSeat) then
  899.         print("bestActionPoint: " .. bestActionPointName .. " bestFacing" .. bestFacing);
  900.         return bestSeat, bestSeat.getActionPoint(bestActionPointName);
  901.     else
  902.         print("no watching ActionPoint found");
  903.         return nil;
  904.     end            
  905.     
  906. end
  907.  
  908.  
  909. -- frees the hands of a character. deletes held objects. removes anims from the HandStateObject
  910. function freeHands(character)
  911.  
  912.  
  913.     local leftHeldObject = character.getLeftHeldObject();
  914.     if (leftHeldObject) then
  915.         character.detachLeftObjectHolder();
  916.         print("deleting leftHeldObject " .. leftHeldObject.getResourceName());
  917.         leftHeldObject.deleteGameObject();
  918.     end
  919.     
  920.     local rightHeldObject = character.getRightHeldObject();
  921.     if (rightHeldObject) then
  922.         character.detachRightObjectHolder();
  923.         print("deleting rightHeldObject " .. rightHeldObject.getResourceName());
  924.         rightHeldObject.deleteGameObject();
  925.     end
  926.     
  927.  
  928.     local hso = character.handSO;
  929.     if (not hso) then
  930.         print("freeHands no hand state object found");
  931.     else
  932.         hso.stopAnimation();
  933.     end
  934.     
  935.     
  936. end
  937.  
  938. -- returns true if an activity on an object can be done by the given character
  939. -- returns as the second return value the activityResult (why did the activity fail)
  940. -- returns as the third return value the activity itself
  941. function activityPossible(characterGO, activityName, standardGO, data, ignoreBroken)
  942.     
  943.     -- check debug flags first
  944.     if (CharacterAI.checkFailing(CharacterAI.ALWAYS_FAIL)) then return false; end
  945.     if (CharacterAI.checkFailing(CharacterAI.NEVER_FAIL)) then return true; end
  946.     
  947.     if (not type(characterGO) == "userdata") then
  948.         print("WARNING activityPossible: characterGO not valid !!!!");
  949.         return false, UNKNOWN, nil;
  950.     end
  951.     
  952.     local activity = characterGO.createActivity(activityName, standardGO);
  953.     
  954.     -- check if character is ashamed
  955.     if (standardGO.isCharacter()) then
  956.         if (isCharacterAshamed(characterGO, standardGO)) then
  957.             return false, NO_RELATIONSHIPCONDITION, activity;
  958.         end
  959.     end
  960.  
  961.     local activityResult = activity.getActivityResult(ignoreBroken);
  962.     
  963.     
  964. --    -- do not make it possible to sleep in bed during day time
  965. --    if (standardGO.hasBehavior("bed") and activityName == "sleep") then
  966. --        if (enumCompare(standardGO.getGameObjectServer().getDayTime(), DAY)) then
  967. --            activityResult = UNKNOWN
  968. --        end
  969. --    end
  970.  
  971. --    print("activityPossible " .. activityName .. " activityResult " .. tostring(activityResult));    
  972.     return enumCompare(activityResult, POSSIBLE), activityResult, activity;    
  973.     
  974. end
  975.  
  976. function getActivityLength(activity)
  977.     local scale = activity.getEffectivity();
  978.     if (scale < 0.1) then scale = 1.0 end
  979.     local length = activity.getLength();
  980.     --if (length < 1000) then length = 5000 end
  981.     
  982.     length = length / scale;
  983.     
  984.     local name = activity.getActivityName();
  985.     print("getActivityLength for " .. name ..  " l:" .. length .. " s:" .. scale);    
  986.     
  987.     return length, scale;
  988.     --return 10000, 2.0;
  989.     
  990. end
  991.  
  992.  
  993. -- shows the repair menu if this game object is broken
  994. -- this: a game object
  995. -- returns true if the menu is shown
  996. function repairMenu()
  997.     if (this.isBroken()) then
  998.         this.clearPieMenu();
  999.         local button ;
  1000.         button = this.addPieMenuButton(PM_REPAIR, REPAIR_COMMAND);
  1001.         button.addDescription(ACTIVITY, REPAIR);
  1002.         return true;
  1003.     else
  1004.         return false;
  1005.     end
  1006. end
  1007.  
  1008. -- this: a game object
  1009. function abortIfBroken(character)
  1010.     if (this.isBroken()) then
  1011.         print("object broken");
  1012.         instantAbort(character, EMOTICON_CANNOT, "emoThink")
  1013.         return true;
  1014.     else
  1015.         return false;
  1016.     end
  1017. end
  1018.  
  1019. function playShowerAnim(shower, suffix)
  1020.     local name = shower.getResourceName();
  1021.     print("name:" .. name .. " suffix:" .. suffix);
  1022.     if (name == "showerDesign") then
  1023.         shower.startAnimation("showerDesign" .. suffix);            
  1024.     elseif (name == "showerModern") then
  1025.         shower.startAnimation("showerModern" .. suffix);            
  1026.     elseif (name == "showerOldschool") then
  1027.         shower.startAnimation("showerOldschool" .. suffix);            
  1028.     end
  1029. end
  1030.  
  1031. function holdsObject(character, objectType)
  1032.  
  1033.     --print("objectType:" .. objectType);
  1034.     
  1035.     local rightObject = character.getRightHeldObject();
  1036.     local leftObject = character.getLeftHeldObject();
  1037.     
  1038.     if (rightObject) then
  1039.         --print("rightObjectType:" .. rightObject.getType());
  1040.     
  1041.         if (rightObject.getType() == objectType) then
  1042.             --print("RIGHT_HAND:" .. objectType);
  1043.             return true, RIGHT_HAND;
  1044.         end
  1045.     end
  1046.         
  1047.     if (leftObject) then
  1048.         --print("leftObjectType:" .. leftObject.getType());
  1049.     
  1050.         if (leftObject.getType() == objectType) then
  1051.             --print("LEFT_HAND:" .. objectType);
  1052.             return true, LEFT_HAND;
  1053.         end
  1054.     end
  1055.     
  1056.     --print("NO_HAND:" .. objectType);
  1057.     return false, nil;
  1058.     
  1059. end
  1060.  
  1061.  
  1062. function genderizeReal(character, name)
  1063.  
  1064.     local male =    (character.isMale() and not character.isTransgender()) or 
  1065.             (not character.isMale() and character.isTransgender());
  1066.             
  1067.     return name .. cond(male, "Mike", "Elaine");
  1068.     
  1069. end
  1070.  
  1071. function genderizePink(character, name)
  1072.  
  1073.     local male = character.isMale()
  1074.     local homo = character.isTransgender()
  1075.     local suffix = cond(character.isMale(), cond(homo, "Pacifica", "Mike"), cond(homo, "Tom", "Elaine"));
  1076.             
  1077.     return name .. suffix;
  1078.     
  1079. end
  1080.  
  1081. function genderize(character, name)
  1082.     if (character.isMale()) then
  1083.         return name .. "Mike";
  1084.     else
  1085.         return name .. "Elaine";
  1086.     end
  1087. end
  1088.  
  1089.  
  1090. function genderizeSpeech(character, name, active, activeDiff)
  1091.  
  1092.     local maleIsActive = (character.isMale() == active);
  1093.     local suffix1 = cond(activeDiff, cond(maleIsActive, "Mike", "Elaine"), "");
  1094.     
  1095.     local homo = character.isTransgender();
  1096.     local suffix2 = cond(character.isMale(), cond(homo, "Pacifica", "Mike"), cond(homo, "Tom", "Elaine"));
  1097.     
  1098.     local result = name .. suffix1 .. "_" .. suffix2;
  1099.     
  1100.     print("genderizeSpeech:" .. character.getCharacterName() .. " text:" .. name .. " active:" .. tostring(active));
  1101.     print(">>>maleIsActive:" .. tostring(maleIsActive) .. " homo:" .. tostring(homo));
  1102.     print(">>>return: " .. result);
  1103.  
  1104.     return result;    
  1105. end
  1106.  
  1107.  
  1108.  
  1109. function archize(character, name)
  1110.     return name .. getArchtypeSuffix(character);
  1111. end
  1112.  
  1113. function archizeRun(character, name)
  1114.  
  1115.     local archtype = character.getArchtype();
  1116.     local suffix = "Standard";
  1117.             
  1118.     if (character.isMale()) then
  1119.         if    (enumCompare(archtype, CHIEF)) then suffix = "Standard"; 
  1120.         elseif    (enumCompare(archtype, BAD_BOY)) then suffix = "Bold"; 
  1121.         elseif    (enumCompare(archtype, BEST_FRIEND)) then suffix = "Standard"; 
  1122.         elseif    (enumCompare(archtype, CHARMER)) then suffix = "Standard"; 
  1123.         elseif    (enumCompare(archtype, LOST_SOUL)) then suffix = "Bold"; 
  1124.         elseif    (enumCompare(archtype, PROFESSOR)) then suffix = "Standard"; 
  1125.         elseif    (enumCompare(archtype, SWASHBUCKLER)) then suffix = "Bold";
  1126.         elseif    (enumCompare(archtype, WARRIOR)) then suffix = "Sexy";
  1127.         else    suffix = "-Standard"; end;
  1128.     else
  1129.         if    (enumCompare(archtype, BOSS)) then suffix = "Sexy";
  1130.         elseif    (enumCompare(archtype, SEDUCTRESS)) then suffix = "Sexy"; 
  1131.         elseif    (enumCompare(archtype, SPUNKY_KID)) then suffix = "Sexy"; 
  1132.         elseif    (enumCompare(archtype, FREE_SPIRIT)) then suffix = "Aktivist"; 
  1133.         elseif    (enumCompare(archtype, INNOCENT_GIRL)) then suffix = "Sexy"; 
  1134.         elseif    (enumCompare(archtype, SCIENTIST)) then suffix = "Aktivist"; 
  1135.         elseif    (enumCompare(archtype, ACTIVIST)) then suffix = "Aktivist"; 
  1136.         elseif    (enumCompare(archtype, NURSE)) then suffix = "Sexy";
  1137.         else    suffix = "-Sexy"; end;
  1138.     end
  1139.     
  1140.     return name .. suffix;
  1141.  
  1142. end
  1143.  
  1144. function archizeWalk(character, name)
  1145.  
  1146.     local archtype = character.getArchtype();
  1147.     local male = character.isMale() and not character.isTransgender();
  1148.     return name .. cond(male, "Mike", "Elaine");
  1149.  
  1150. end
  1151.  
  1152.  
  1153. function getArchtypeSuffix(character)
  1154.  
  1155.     local archtype = character.getArchtype();
  1156.         
  1157.     if (character.isMale()) then
  1158.         if    (enumCompare(archtype, CHIEF)) then return "Chief"; 
  1159.         elseif    (enumCompare(archtype, BAD_BOY)) then return "Badboy"; 
  1160.         elseif    (enumCompare(archtype, BEST_FRIEND)) then return "Bestfriend"; 
  1161.         elseif    (enumCompare(archtype, CHARMER)) then return "Charmer"; 
  1162.         elseif    (enumCompare(archtype, LOST_SOUL)) then return "Lostsoul"; 
  1163.         elseif    (enumCompare(archtype, PROFESSOR)) then return "Professor"; 
  1164.         elseif    (enumCompare(archtype, SWASHBUCKLER)) then return "Swashbuckler";
  1165.         elseif    (enumCompare(archtype, WARRIOR)) then return "Warrior";
  1166.         else    return "Mike"; end;
  1167.     else
  1168.         if    (enumCompare(archtype, BOSS)) then return "Boss";
  1169.         elseif    (enumCompare(archtype, SEDUCTRESS)) then return "Seductress"; 
  1170.         elseif    (enumCompare(archtype, SPUNKY_KID)) then return "Spunkykid"; 
  1171.         elseif    (enumCompare(archtype, FREE_SPIRIT)) then return "Freespirit"; 
  1172.         elseif    (enumCompare(archtype, INNOCENT_GIRL)) then return "Innocentgirl"; 
  1173.         elseif    (enumCompare(archtype, SCIENTIST)) then return "Scientist"; 
  1174.         elseif    (enumCompare(archtype, ACTIVIST)) then return "Activist"; 
  1175.         elseif    (enumCompare(archtype, NURSE)) then return "Nurse";
  1176.         else    return "Elaine"; end;
  1177.     end
  1178. end
  1179.  
  1180. function findBedForInteraction(character1, character2)
  1181.  
  1182.     local beds = character1.getObjectsWithBehavior("doublebed");
  1183.     for b = 1, getn(beds) do
  1184.         local bed = beds[b];
  1185.         if (not bed.isBroken()) then
  1186.         
  1187.             local actionPoint1 = character1.getClosestFreeActionPoint(character1, bed, {"layDown1", "layDown2"});
  1188.             if (actionPoint1 and character1.canReachActionPoint(actionPoint1)) then
  1189.                 local actionPoint2Name;
  1190.                 if (actionPoint1.getName() == "layDown1") then
  1191.                     actionPoint2Name = "layDown2";
  1192.                 else
  1193.                     actionPoint2Name = "layDown1";
  1194.                 end
  1195.                 local actionPoint2 = character2.getClosestFreeActionPoint(character2, bed, {actionPoint2Name});
  1196.                 if (actionPoint2 and character2.canReachActionPoint(actionPoint2)) then
  1197.                     return bed, actionPoint1, actionPoint2;
  1198.                 else
  1199.                     print("findBedForInteraction actionPoint2 not found or cannot reach");        
  1200.                 end
  1201.             else
  1202.                 print("findBedForInteraction actionPoint1 not found or cannot reach");        
  1203.             end
  1204.         else
  1205.             print("findBedForInteraction bed.isBroken");        
  1206.         end    
  1207.     end
  1208.     
  1209.     return nil
  1210.  
  1211. end
  1212.  
  1213.  
  1214.  
  1215. function findSofaForInteraction(character1, character2)
  1216.  
  1217.     local sofas = character1.getObjectsWithBehavior("sofa");
  1218.     for s = 1, getn(sofas) do
  1219.         local sofa = sofas[s];
  1220.         if (not sofa.isBroken()) then
  1221.         
  1222.             local sofaActionPointNames = {"sit1", "sit2", "sit3"};        
  1223.             local actionPoint1 = character1.getClosestFreeActionPoint(character1, sofa, sofaActionPointNames, true);
  1224.             
  1225.             if (actionPoint1) then
  1226.             
  1227.                 local pos = tfind(sofaActionPointNames, actionPoint1.getName());
  1228.                 print("findSofaForInteraction pos" .. pos);
  1229.                 tremove(sofaActionPointNames, pos);
  1230.                 local actionPoint2 = character2.getClosestFreeActionPoint(character1, sofa, tremoven(sofaActionPointNames), true);
  1231.  
  1232.                 if (actionPoint2) then
  1233.                     return sofa, actionPoint1, actionPoint2;
  1234.                 else
  1235.                     print("findSofaForInteraction actionPoint2 not found or cannot reach");        
  1236.                 end
  1237.             else
  1238.                 print("findSofaForInteraction actionPoint1 not found or cannot reach");        
  1239.             end
  1240.         else
  1241.             print("findSofaForInteraction sofa.isBroken");        
  1242.         end    
  1243.     end
  1244.     
  1245.     return nil
  1246.  
  1247. end
  1248.  
  1249. function getSofaInteractionInfo(character1, character2, actionPointName1, actionPointName2)
  1250.  
  1251.     local name1 = actionPointName1;
  1252.     local name2 = actionPointName2;
  1253.     
  1254.     print("------- getSofaInteractionInfo ---------------------");
  1255.     print(" > character1:" .. character1.getCharacterName());
  1256.     print(" > character2:" .. character2.getCharacterName());
  1257.     print(" > actionPointName1:" .. name1);
  1258.     print(" > actionPointName2:" .. name2);
  1259.     
  1260.     if ((name1 == "sit1") and (name2 == "sit3")) or ((name1 == "sit3") and (name2 == "sit1")) then
  1261.         return false, false;
  1262.     end
  1263.     
  1264.     local male1 = character1.isMale();
  1265.     local mirror = false;
  1266.     
  1267.     if (name1 == "sit1") then 
  1268.         if (not male1) then
  1269.             mirror = true;
  1270.         end
  1271.     elseif (name1 == "sit2") then
  1272.         if (male1 and name2 == "sit1") then
  1273.             mirror = true;
  1274.         end
  1275.     elseif (name1 == "sit3") then
  1276.         if (male1) then
  1277.             mirror = true;
  1278.         end
  1279.     end
  1280.     
  1281.     print(" > getSofaInteractionInfo return mirror:" .. tostring(mirror));
  1282.     return true, mirror;
  1283.  
  1284. end
  1285.  
  1286. function getInteractionBed(character1, character2)
  1287.  
  1288.     local sm1 = character1.walkSO.getStateMachine().getName();
  1289.     local s1 = character1.walkSO.getState();
  1290.     local sm2 = character2.walkSO.getStateMachine().getName();
  1291.     local s2 = character2.walkSO.getState();
  1292.     
  1293.     
  1294.     --if ((sm1 ~= "doublebedChar") or (s1 ~= "doIntimate")) then
  1295.     if (sm1 ~= "doublebedChar") then
  1296. --        print("getInteractionBed: wrong state char 1 :" .. sm1 .. "." .. s1);
  1297.         return nil 
  1298.     end;
  1299.     --if ((sm2 ~= "doublebedChar") or (s2 ~= "doIntimate")) then
  1300.     if (sm2 ~= "doublebedChar") then
  1301. --        print("getInteractionBed: wrong state char 2 :" .. sm2 .. "." .. s2);
  1302.         return nil 
  1303.     end;
  1304.     
  1305.     local bed1 = character1.getObjectWithActivity("lie");
  1306.     local bed2 = character2.getObjectWithActivity("lie");
  1307.     
  1308.     if (not bed1) then 
  1309. --        print("getInteractionBed: no bed1"); 
  1310.         return nil; 
  1311.     end;
  1312.     if (not bed2) then 
  1313. --        print("getInteractionBed: no bed2"); 
  1314.         return nil; 
  1315.     end;
  1316.     
  1317.     if (bed1 ~= bed2) then 
  1318. --        print("getInteractionBed: diferrent beds"); 
  1319.         return nil; 
  1320.     end;
  1321.     
  1322.     return bed1;
  1323.         
  1324.         
  1325. end
  1326.  
  1327. function getIntimateBed(character1, character2)
  1328.     local interactionBed = getInteractionBed(character1, character2);
  1329.     if (not interactionBed) then return nil end;
  1330.     
  1331.     local s1 = character1.walkSO.getState();
  1332.     local s2 = character2.walkSO.getState();
  1333.     
  1334.     if (s1 ~= "doIntimate") then
  1335.         print("getInteractionBed: wrong state char 1 :" .. s1);
  1336.         return nil 
  1337.     end;
  1338.     
  1339.     if (s2 ~= "doIntimate") then
  1340.         print("getInteractionBed: wrong state char 2 :" .. s2);
  1341.         return nil 
  1342.     end;
  1343.     
  1344.     return interactionBed;    
  1345. end
  1346.  
  1347.  
  1348. function getOtherUsers(character, object, activity)
  1349.  
  1350.     local result = {};
  1351.     local users = object.getCharactersWithActivity(activity);
  1352.     for u = 1, getn(users) do
  1353.         local user = users[u];
  1354.         if (user ~= character) then
  1355.             tinsert(result, user);
  1356.         end
  1357.     end
  1358.     return result;
  1359.  
  1360. end
  1361.  
  1362. function getOtherUser(character, object, activity)
  1363.     local otherUsers = getOtherUsers(character, object, activity);
  1364.     return otherUsers[1];
  1365. end
  1366.  
  1367.  
  1368. function getCharactersWithActivities(object, activities)
  1369.  
  1370.     local result = {};
  1371.     for a = 1, getn(activities) do
  1372.     local activity = activities[a];
  1373.         local users = object.getCharactersWithActivity(activity);
  1374.         for u = 1, getn(users) do
  1375.             local user = users[u];
  1376.             tinsert(result, user);
  1377.         end
  1378.     end
  1379.     return result;
  1380.  
  1381. end
  1382.  
  1383.  
  1384.  
  1385. function isUser(character, object, activities)
  1386.  
  1387.     for a = 1, getn(activities) do
  1388.     local activity = activities[a];
  1389.         local users = object.getCharactersWithActivity(activity);
  1390.         for u = 1, getn(users) do
  1391.             local user = users[u];
  1392.             if (user == character) then
  1393.                 return true;
  1394.             end
  1395.         end
  1396.     end    
  1397.     return nil;
  1398.  
  1399. end
  1400.  
  1401.  
  1402. function changeOutfit(character, outfit)
  1403.     if (not hasOutfit(character, outfit)) then
  1404.         character.changeOutfit(outfit);
  1405.     else
  1406.         print("already had that outfit");
  1407.     end
  1408. end
  1409.  
  1410.  
  1411. function hasOutfit(character, outfit)
  1412.     local current = character.getOutfit();
  1413.     return (enumCompare(outfit, current));
  1414. end
  1415.  
  1416. function getChangeOutfitAnim(character)
  1417.     if (hasOutfit(character, ARCHTYPE) or hasOutfit(character, STANDARD)) then 
  1418.         print("getChangeOutfitAnim ausziehen2");
  1419.         return "ausziehen2"; 
  1420.     else
  1421.         print("getChangeOutfitAnim ausziehen1");
  1422.         return "ausziehen1"; 
  1423.     end;
  1424. end
  1425.  
  1426.  
  1427. function replaceActivities(object, oldActivities, newActivity)
  1428.  
  1429.     local allUsers = {};
  1430.  
  1431.     for a = 1, getn(oldActivities) do
  1432.     local oldActivity = oldActivities[a];
  1433.         local users = object.getCharactersWithActivity(oldActivity);
  1434.         for u = 1, getn(users) do
  1435.             local user = users[u];
  1436.             user.stopActivity(oldActivity, object);
  1437.             tinsert(allUsers, user);
  1438.         end
  1439.     end
  1440.  
  1441.     if (not newActivity) then return end;
  1442.  
  1443.     for u = 1, getn(allUsers) do
  1444.         local user = allUsers[u];
  1445.         user.startActivity(newActivity, object);
  1446.     end
  1447.  
  1448. end
  1449.  
  1450.  
  1451.  
  1452.  
  1453. function getTableVersion(object)
  1454.  
  1455.     if (not object) then return nil; end;
  1456.  
  1457.     local name = object.getResourceName();
  1458.     local tableName = "";
  1459.     
  1460.     if     (name == "pizzaBox") then tableName = "tabletPizza";
  1461.     elseif (name == "boardgameBox") then tableName = "boardgame";
  1462.     end;
  1463.     
  1464.     if (tableName == "") then
  1465.         return object;
  1466.     else
  1467.         local tableVer = getParent().loadGameObject("StandardGO", tableName);
  1468.         return tableVer;
  1469.     end
  1470.  
  1471. end
  1472.  
  1473. function getDirtyDishVersion(object)
  1474.  
  1475.     local leftoverName = "plate";
  1476.     
  1477.     if (not object) then
  1478.         print("getDirtyDishVersion(nil) returning plate");
  1479.     else
  1480.         local name = object.getResourceName();
  1481.         
  1482.         if     (name == "tabletPizza") then leftoverName = "dirtyDishPizza";
  1483.         elseif (name == "tabletBreakfast") then leftoverName = "dirtyDishBreakfast";
  1484.         elseif (name == "tabletCooked") then leftoverName = "dirtyDishCooked";
  1485.         elseif (name == "tabletDinner") then leftoverName = "dirtyDishDinner";
  1486.         end;    
  1487.     end;
  1488.     
  1489.     local dirtyDish = getParent().loadGameObject("StandardGO", leftoverName);
  1490.     if (not dirtyDish) then
  1491.         print("getDirtyDishVersion(" .. name .. ") = " .. leftoverName .. " NOT FOUND");
  1492.     end;
  1493.     
  1494.     return dirtyDish;
  1495.  
  1496. end
  1497.  
  1498.  
  1499.  
  1500. -- called by an objects msg handler to instantly abort an impossible action. 
  1501. -- character must be in the walk-SM
  1502. function instantAbort(character, emoticon, emoMsg, sender)
  1503.  
  1504.     print("instantAbort by " .. character.getCharacterName());
  1505.     
  1506.     -- there could be a walk in the queue when walkToActionPoint 
  1507.     -- was called to find out that there is no path. clear it:
  1508.     character.walkSO.clearQueue();
  1509.     
  1510.  
  1511.     local stateMachine = character.walkSO.getStateMachine();
  1512.     local stateMachineName = stateMachine.getName();
  1513.     if (stateMachineName ~= "walk") then
  1514.         print("instantAbort(".. character.getCharacterName() ..") is in state machine " .. stateMachineName);
  1515.         -- remove the aborted queue entry manualy, because we cannot call nextAction()
  1516.         character.popQueueEntry();
  1517.     else
  1518.         character.walkSO.nextAction();
  1519.     end
  1520.     
  1521.     if (not character.getLastMsgAI()) then
  1522.     
  1523.         print("instantAbort user action");
  1524.     
  1525.         if (emoticon) then character.setEmoticon(emoticon, EMOTICON_DELAY); end;
  1526.         
  1527.         if (emoMsg) then 
  1528.             if (sender) then
  1529.                 sender.sendDelayedMsg(emoMsg, character.walkSO, 500); 
  1530.             else
  1531.                 sendDelayedMsg(emoMsg, character.walkSO, 500); 
  1532.             end;
  1533.         end;
  1534.     else
  1535.         print("instantAbort AI action");
  1536.     end    
  1537.     
  1538.     
  1539. end
  1540.  
  1541. -- called by an objects msg handler to instantly abort an impossible action. 
  1542. -- character must be in the walk-SM
  1543. function instantAbortIfNotIdle(character, charcterToCheck)
  1544.     if (not isIdle(charcterToCheck) or charcterToCheck.isSwimming()) then
  1545.         instantAbort(character, EMOTICON_CANNOT, "emoThink");
  1546.         return true;
  1547.     else
  1548.         return false;
  1549.     end;    
  1550. end
  1551.  
  1552. -- called by an objects msg handler to instantly abort an impossible action. 
  1553. -- character must be in the walk-SM
  1554. function instantAbortIfUnhappy(character, activityName, object)
  1555.  
  1556.     
  1557.     local alwaysFail = (CharacterAI.checkFailing(CharacterAI.ALWAYS_FAIL));
  1558.     local neverFail = (CharacterAI.checkFailing(CharacterAI.NEVER_FAIL));
  1559.     
  1560.     local activity = character.createActivity(activityName, object);
  1561.     local minSatisfaction = activity.getRequiredSatisfaction();
  1562.     local satisfaction = character.calculateSatisfaction();
  1563.     print("instantAbortIfUnhappy minSatisfaction " .. minSatisfaction .. " satisfaction:" .. satisfaction);
  1564.  
  1565.     if ((satisfaction < minSatisfaction or alwaysFail) and (not neverFail)) then
  1566.         instantAbort(character, EMOTICON_SAD, "emoRefuseChar", object);
  1567.         print("returning true");
  1568.         return true;
  1569.     else
  1570.         print("returning false");
  1571.         return false;
  1572.     end;    
  1573. end
  1574.  
  1575.  
  1576.  
  1577. -- this: game object
  1578. function sendMsgAllUsers(msg, activities, data)
  1579.  
  1580.     local users = getCharactersWithActivities(this, activities);
  1581.     for u = 1, getn(users) do
  1582.         local user = users[u];
  1583.         if (data) then
  1584.             sendMsg(msg, user.walkSO, data);
  1585.         else
  1586.             sendMsg(msg, user.walkSO);
  1587.         end
  1588.     end
  1589. end
  1590.  
  1591.  
  1592. -- this: tv or pc object in a active state
  1593. function startAnim(frames, frameDurration)
  1594.  
  1595.     if (not frameDurration) then frameDurration = TV_ANIM_FRAME_DURRATION; end;
  1596.  
  1597.     for f = 1, getn(frames) do
  1598.         local frame = frames[f];
  1599.         --print(frame);
  1600.         sendDelayedMsgThis("showPic", (f-1) * frameDurration, frame);
  1601.     end
  1602.     sendDelayedMsgThis("startAnim", getn(frames) * frameDurration);
  1603.  
  1604. end
  1605.  
  1606. function preloadTextures(object, texures)
  1607.     for t = 1, getn(texures) do
  1608.         object.preloadTexture(texures[t]);
  1609.     end
  1610. end
  1611.  
  1612.  
  1613.  
  1614. -- this: walkSO
  1615. function createDirt(dirtType, size, probability)
  1616.  
  1617.     if (not probability) then probability = 1.0; end; -- default value
  1618.     
  1619.     local character = getParent(); 
  1620.     
  1621.     local messy = character.getCharacterCondition(CHAR_MESSY);
  1622.     messy = 0.1 * messy; -- convert to 0.0 .. 1.0
  1623.     
  1624.     --print("prob " .. probability * messy)
  1625.     probability = probability * messy;
  1626.     if (random() > probability) then 
  1627.         --print("createDirt probability: " .. probability .. " messy: " .. messy); 
  1628.         return
  1629.     end;
  1630.     
  1631.     -- dont make dirt on some floor types
  1632.     local floorGO = getParent().getFloorUnderCharacter();
  1633.     if (floorGO) then
  1634.         local foorType = floorGO.getFloorType();
  1635.         if (tfind(NO_DIRT_FLOOR_TYPES, foorType)) then
  1636.             --print("createDirt foorType " .. foorType); 
  1637.             return
  1638.         end;
  1639.     end;
  1640.     
  1641.     -- don't make dirt outside
  1642.     local roomNumber = character.getRoomNumber();
  1643.     local room = character.getGameObjectServer().getApartment().getRoom(roomNumber);
  1644.     if (not room.isIndoor()) then 
  1645.         --print("createDirt outside"); 
  1646.         return 
  1647.     end;
  1648.     
  1649.     
  1650.     -- dont make dirt if cleaning
  1651.     local holds, hand = holdsObject(character, "hoover");
  1652.     if (holds) then return end;
  1653.     
  1654.     -- dont make dirt if someonelse cleaning
  1655.     local others = getCharactersHoldingObject(character, "hoover")
  1656.     if (getn(others) > 0) then return end;
  1657.  
  1658.     --print("createDirt by " ..  character.getCharacterName());
  1659.     character.createDirt(size, dirtType);
  1660.     
  1661. end
  1662.  
  1663. function getCharactersHoldingObject(character, objectType)
  1664.  
  1665.     local result = {};
  1666.     local others = character.getOtherCharacters();
  1667.     for c = 1, getn(others) do
  1668.         if (holdsObject(others[c], objectType)) then
  1669.             tinsert(result, others[c]); 
  1670.         end;
  1671.     end
  1672.     return result;
  1673.  
  1674. end
  1675.  
  1676. -- this: walkSO
  1677. function createTrash(amount)
  1678.  
  1679.     -- dont make dirt if cleaning
  1680.     local character = getParent(); 
  1681.  
  1682.     -- remaining trash to distribute
  1683.     local remain = amount;
  1684.     
  1685.     local trashCans = character.getObjectsWithBehavior("trashCan");
  1686.     -- go trough trashCans    
  1687.     for t = 1, getn(trashCans) do
  1688.         print("    createTrash trashCan:" .. t .. "  remain:" .. remain);
  1689.         local trashCan = trashCans[t];
  1690.         remain = addTrash(trashCan, remain);
  1691.         
  1692.         if (remain < 0.01) then 
  1693.             return
  1694.         end;
  1695.     end
  1696.     
  1697.     -- TODO: place remaing trash on floor near character
  1698.     
  1699.     character.createDirt(max(TRASH_TO_DIRT*remain, 0.1), DIRT_TRASH);
  1700.  
  1701. end
  1702.  
  1703.  
  1704.  
  1705.  
  1706. function addTrash(trashCan, amount)
  1707.  
  1708.     local canType = trashCan.getType();
  1709.     local capacity = trashCan.capacity;
  1710.     
  1711.     --if (canType == "TrashCanModern") then capacity = 1.5 end;
  1712.  
  1713.  
  1714.     local fillLevel = trashCan.retrieveData("fillLevel", 0.0);
  1715.     local newFillLevel = fillLevel + (amount/capacity);
  1716.     local remain = max(0.0, newFillLevel - 1.0);
  1717.     newFillLevel = clamp(newFillLevel, 0.0, 1.0);
  1718.      
  1719.     print("addTrash cap:" .. capacity .. " old:" .. fillLevel .. "   delta:" .. amount .. "  new:" .. newFillLevel.. "  remain:" .. remain);
  1720.     
  1721.     trashCan.storeData("fillLevel", newFillLevel);
  1722.     
  1723.     local stinkRate = newFillLevel;
  1724.     
  1725.     if (stinkRate < MIN_STINK_RATE) then
  1726.         print("no emit")
  1727.         trashCan.setChildEnable("stink", false);
  1728.     else
  1729.         print("emit")
  1730.         trashCan.setChildEnable("stink", true);
  1731.         stink = trashCan.findChildGO("stink");
  1732.         stink.setEmitRate(stinkRate);
  1733.     end
  1734.     
  1735.     trashCan.setDirtiness(newFillLevel/FULL_TRASHCAN_DIRTINESS);
  1736.     
  1737.     return remain;
  1738.     
  1739. end
  1740.  
  1741. function getDish(sink)
  1742.     local dishes = getChildrenWithBehavior(sink, "dish");
  1743.     return getn(dishes);
  1744. end
  1745.  
  1746. function addDish(sink, amount)
  1747.  
  1748.     local dishes = getChildrenWithBehavior(sink, "dish");
  1749.     local numDishes = getn(dishes);
  1750.     local maxDishes = sink.maxDishes;
  1751.     
  1752.     print("addDish(" .. amount .. ") current:" .. numDishes);
  1753.     
  1754.     if (amount > 0) then
  1755.         local toAdd = min(amount, maxDishes-numDishes);
  1756.         print("addDish toAdd:" .. toAdd);
  1757.         for i = 1, toAdd do
  1758.             local dish = sink.loadGameObject("StandardGO", "plate");
  1759.             local offsetZ = sink.dishesBaseHeight + (numDishes * dish.stackingZAdd);
  1760.             sink.addObjectToActionPoint(dish, "dish", 0, 0, offsetZ);
  1761.             numDishes = numDishes + 1;
  1762.         end
  1763.                 
  1764.         return numDishes;    
  1765.             
  1766.     elseif (amount < 0) then
  1767.         local toSub = min(abs(amount), numDishes);
  1768.         print("addDish toSub:" .. toSub);
  1769.         for i = 1, toSub do
  1770.             local dish = dishes[(numDishes-i+1)];
  1771.             dish.deleteGameObject();
  1772.         end
  1773.         
  1774.         return numDishes-toSub;        
  1775.     end
  1776.     
  1777.     return numDishes;        
  1778.     
  1779. end
  1780.  
  1781.  
  1782. function activeDiff(interaction)
  1783.  
  1784.     if (interaction == "talkFlirt") then return false; end;
  1785.     if (interaction == "talkGossip") then return false; end;
  1786.     
  1787.     return true;
  1788.  
  1789. end
  1790.  
  1791. function isMonologue(interaction)
  1792.     if (interaction == "talkRelation") then return true; end;
  1793.     return false;
  1794. end
  1795.  
  1796.  
  1797.  
  1798.  
  1799. function getIconForAction(action)
  1800.  
  1801.     if (action == "talkHobby") then return EMOTICON_HOBBY end;
  1802.     if (action == "talkComfort") then return EMOTICON_COMFORT end;
  1803.     if (action == "talkCompliment") then return EMOTICON_COMPLIMENT end;
  1804.     if (action == "talkRelation") then return EMOTICON_INLOVE end;
  1805.     if (action == "talkArgue") then return EMOTICON_ARGUE end;
  1806.     if (action == "talkCasual") then return EMOTICON_SMALLTALK end;
  1807.     if (action == "talkJoke") then return EMOTICON_JOKE end;
  1808.     if (action == "talkILoveYou") then return EMOTICON_INLOVE end;
  1809.     if (action == "talkFlirt") then return EMOTICON_EROTIC end;
  1810.     if (action == "talkTease") then return EMOTICON_TEASE end;
  1811.     if (action == "talkGossip") then return EMOTICON_GOSSIP end;
  1812.     
  1813.     return EMOTICON_DUNNO;
  1814.  
  1815. end
  1816.  
  1817. function isIdle(character)
  1818.  
  1819.     local stateMachine = character.walkSO.getStateMachine();
  1820.     local stateMachineName = stateMachine.getName();
  1821.     if (stateMachineName ~= "walk") then
  1822.         print("isIdle(".. character.getCharacterName() ..") is state machine " .. stateMachineName);
  1823.         return false;        
  1824.     end
  1825.  
  1826.     local activityQueueCount = character.getActivityQueueCount();
  1827.     if (activityQueueCount > 0) then
  1828.         print("isIdle(".. character.getCharacterName() ..") has " .. activityQueueCount .. " action queued");
  1829.         return false;
  1830.     end
  1831.     
  1832.     return true;
  1833.  
  1834. end
  1835.  
  1836. -- sets the top queue entry to the given text. if
  1837. function setTopQueueEntry(character, buttonText, clearCancel)
  1838.  
  1839.     local activityQueueCount = character.getActivityQueueCount();
  1840.     print("setTopQueueEntry " .. activityQueueCount);
  1841.     
  1842.     if (activityQueueCount == 0) then
  1843.         character.pushQueueEntry(buttonText);
  1844.     else
  1845.         local entry = character.replaceQueueEntry(0, buttonText, not clearCancel);
  1846. --        if (clearCancel) then
  1847. --            entry.clearCancel();
  1848. --            character.clearCancel();
  1849. --            character.updateActivityQueue();
  1850. --        end
  1851.     end
  1852.  
  1853. end
  1854.  
  1855. function queueFollowCommand(character, buttonText, command, object, data)
  1856.  
  1857.     if (not character) then
  1858.         print("queueFollowComand no character");
  1859.         return
  1860.     end
  1861.  
  1862.     if (not object) then
  1863.         print("queueFollowComand no object");
  1864.         return
  1865.     end
  1866.  
  1867.     local activityQueueCount = character.getActivityQueueCount();
  1868.     print("queueFollowComand " .. activityQueueCount);
  1869.     
  1870.     if (activityQueueCount == 1) then
  1871.         character.queueCommand(buttonText, command, object, data);
  1872.     end
  1873.  
  1874. end
  1875.  
  1876.  
  1877.  
  1878. function isBarefoot(character)
  1879.     local current = character.getOutfit();
  1880.     return (enumCompare(TOWEL, current) or 
  1881.         enumCompare(SWIMMING, current) or
  1882.         enumCompare(UNDERWEAR, current) or
  1883.         enumCompare(NOTHING, current));
  1884.  
  1885. end
  1886.  
  1887.  
  1888. -- this: walkWSO
  1889. function makeStepSound(foorType)
  1890.  
  1891.  
  1892.     if (not foorType) then 
  1893.         local floorGO = getParent().getFloorUnderCharacter();
  1894.         if (floorGO) then
  1895.             foorType = floorGO.getFloorType();
  1896.             --print("makeStepSound type under character " .. foorType)
  1897.         else
  1898.             foorType = "";
  1899.             --print("makeStepSound: no floor under character ")
  1900.         end
  1901.     end; 
  1902.     
  1903.     
  1904.     if isBarefoot(getParent()) then
  1905.         foorType = "Barefoot";
  1906.     end;
  1907.     
  1908.     if (not tfind(STEP_SOUNDS, foorType)) then
  1909.         foorType = "";
  1910.     end;
  1911.  
  1912.     
  1913.     local stepSound = "step" .. foorType;
  1914.     stepSound = stepSound .. random(1,2);
  1915.     
  1916.     --print("makeStepSound " .. stepSound);
  1917.     
  1918.     getParent().playSound(stepSound);
  1919.     
  1920. end
  1921.  
  1922. -- this: walkWSO
  1923. function makeChairSound(chair, sound)
  1924.  
  1925.     -- defaults
  1926.     local chairType = chair.chairType;
  1927.     if (not chairType) then chairType = "Wood"; end;
  1928.     if (not sound) then sound = "Down"; end;
  1929.     
  1930.     
  1931.     local character = getParent();
  1932.     local name = "chair" .. sound .. chairType;
  1933.     
  1934.     print("makeChairSound: " .. name);
  1935.     
  1936.     chair.playSound(name);
  1937.  
  1938. end
  1939.  
  1940.  
  1941. -- this: walkWSO
  1942. function groan(n)
  1943.     --if (getParent().isMale() == true) then
  1944.     if (false) then
  1945.         return
  1946.     else
  1947.         if (not n) then n = random(1,9); end;
  1948.         local sound = "groan" .. n;
  1949.         sound = genderizeReal(getParent(), sound);
  1950.         print("sound " .. sound .. "  by " .. getParent().getCharacterName());
  1951.         getParent().playSound(sound);
  1952.     end
  1953. end
  1954.  
  1955.  
  1956. function swapDirtTextures(object)
  1957.  
  1958. --    local textures = {"kloOldschool", "kloModern"}; -- TODO: get from dynamic attribs
  1959.  
  1960.     if (not object.dirtableTextures) or (not object.dirtSteps) then return end;
  1961.  
  1962.     local textures = object.dirtableTextures;
  1963.     local step = 1 / object.dirtSteps;
  1964.     
  1965.  
  1966.         
  1967.     
  1968.     local dirt = object.getDirtiness();
  1969.     local suffix = "";
  1970.     
  1971.     local level = floor(dirt / step);
  1972.     level = clamp(level, 0, object.dirtSteps - 1);
  1973.     if (level > 0) then suffix = "_d" .. level; end;
  1974.     
  1975.     print("dirtStep:" .. step .. " level:" .. level .. " suffix:" .. suffix);
  1976.     
  1977.     
  1978. --    if    (dirt > 0.75) then suffix = "_d3";
  1979. --    elseif    (dirt > 0.50) then suffix = "_d2";
  1980. --    elseif    (dirt > 0.25) then suffix = "_d1"; 
  1981. --    end;
  1982.     
  1983.     
  1984.     for i = 1, getn(textures) do
  1985.         local texture = textures[i];
  1986.         local newTexture = texture .. suffix;
  1987.         print("swapDirtTextures: " .. texture .. " -> " .. newTexture);
  1988.         object.replaceTexture(texture, newTexture);
  1989.     end
  1990.     
  1991. end
  1992.  
  1993.  
  1994.  
  1995. function changeDirtiness(object, amount)
  1996.     
  1997.     local oldDirt = object.getDirtiness();
  1998.     local newDirt = oldDirt + amount;
  1999.     newDirt = clamp(newDirt, 0.0, 1.0);
  2000.     
  2001.     print("change dirt of " .. object.getType() .. " from " .. oldDirt .. " to " .. newDirt);
  2002.         
  2003.     object.setDirtiness(newDirt);
  2004.     
  2005.     swapDirtTextures(object);
  2006. end
  2007.  
  2008. -- this: walkWSO
  2009. function clean(object, amount)
  2010.  
  2011.     local character = getParent();
  2012.     
  2013.     local clean = character.createActivity("clean", object);
  2014.     local effect = clean.getEffectivity();
  2015.     
  2016.     amount = -(amount * effect);
  2017.     
  2018.     changeDirtiness(object, amount);
  2019. end
  2020.  
  2021. -- this: walkWSO
  2022. function dirtify(object, amount)
  2023.  
  2024.     local character = getParent();
  2025.     
  2026.     local messy = character.getCharacterCondition(CHAR_MESSY);
  2027.     messy = (0.1 * messy) - 0.5; -- scale to -1.0 .. 1.0
  2028.     amount = max(amount, 0.0);
  2029.  
  2030.     amount = amount + (amount * messy);
  2031.     
  2032.     changeDirtiness(object, amount);
  2033. end
  2034.  
  2035.  
  2036. -- returns true (the name of the action point) if this door is a bathroom door
  2037. function isBathroomDoor(doorGO)
  2038.     local actionPoints = doorGO.getActionPoints();
  2039.     for i = 1, getn(actionPoints) do
  2040.         local actionPoint = actionPoints[i];
  2041.         local room = doorGO.getRoomFromActionPoint(actionPoint);
  2042.         if (room) then
  2043.             if (room.getRoomTypeValue(BATHROOM) > 0) then
  2044.                 return actionPoint.getName();
  2045.             end
  2046.         end
  2047.     end
  2048.     
  2049.     return false;
  2050. end
  2051.  
  2052. -- this: walkSO
  2053. function checkShortcut(object, commands, states, messages)
  2054.  
  2055.     local character = getParent();
  2056.     local entry = character.peekActivityQueue();
  2057.     
  2058.     if (not entry) then
  2059.         print("checkShortcut no next entry in the queue");
  2060.         return false;
  2061.     end;    
  2062.     
  2063.     local entryCommand = entry.getCommand();
  2064.     local entryObject = entry.getGameObject();
  2065.     local entryData = entry.getData();
  2066.     
  2067.     if (not object) then
  2068.         print("checkShortcut no valid object");
  2069.         return false;
  2070.     end;
  2071.  
  2072.     if (not entryObject) then
  2073.         print("checkShortcut no valid entryObject:" .. tostring(entryObject));
  2074.         return false;
  2075.     end;
  2076.  
  2077.     if (entryObject ~= object) then
  2078.         print("checkShortcut wrong object:" .. object.getType() .. " queue:" .. entryObject.getType());
  2079.         return false;
  2080.     end
  2081.     
  2082.     local index = tfind(commands, entryCommand)
  2083.         
  2084.     if (not index) then index = tfind(commands, entryData) end;
  2085.     
  2086.     if (not index) then
  2087.         print("checkShortcut command not found!  command:" .. entryCommand .. " data:" .. entryData);
  2088.         return false
  2089.     end
  2090.     
  2091.     if (getn(commands) ~= getn(states)) then
  2092.         print("checkShortcut given: " .. getn(commands) .. " commands but " .. getn(states) .. " states");
  2093.         return false
  2094.     end
  2095.     
  2096.     print("checkShortcut -> taking shortcut to state: "..states[index]..
  2097.             " entryCommand:"..entryCommand..
  2098.             " entryData:"..entryData..
  2099.             " index:"..index..
  2100.             " entryObject:"..entryObject.getType()
  2101.             );
  2102.     
  2103.     character.popQueueEntry();
  2104.     character.getActivityQueueEntry(0).setStarted(true);
  2105.     clearCancel();
  2106.     
  2107.     if (messages) then
  2108.         local message = messages[index];
  2109.         if (message) then
  2110.             print("checkShortcut sending msg:" .. message .. " data:" .. tostring(entryData) .. " to " .. object.getType());
  2111.             character.sendMsg(message, entryObject, tostring(entryData));
  2112.         end;
  2113.     end    
  2114.  
  2115. --    if (messages) then
  2116. --        local message = messages[index];
  2117. --        if (message) then
  2118. --            print("checkShortcut sending msg:" .. message .. " to " .. object.getType());
  2119. --            character.sendMsg(message, object);
  2120. --        end;
  2121. --    end    
  2122.     
  2123.     setState(states[index]);
  2124.     
  2125.     
  2126. --    if (messages) then
  2127. --        local message = messages[index];
  2128. --        if (message) then
  2129. --            local name, data = strsplit(message, ".");
  2130. --            if (data) then
  2131. --                print("checkShortcut sending msg:" .. name .. " data:" .. data .. " to " .. object.getType());
  2132. --                character.sendMsg(name, object, data);
  2133. --            else
  2134. --                print("checkShortcut sending msg:" .. name .. " to " .. object.getType());
  2135. --                character.sendMsg(name, object);
  2136. --            end
  2137. --        end;
  2138. --    end
  2139.     
  2140.     return true;    
  2141.  
  2142. end
  2143.  
  2144. -- this: walkSO
  2145. function checkWatchShortcut(object, commands, states, messages)
  2146.  
  2147.     local character = getParent();
  2148.     local entry = character.peekActivityQueue();
  2149.  
  2150.     if (not entry) then
  2151.         print("checkShortcut no next entry in the queue");
  2152.         return false;
  2153.     end;    
  2154.         
  2155.     local entryCommand = entry.getCommand();
  2156.     local entryObject = entry.getGameObject();
  2157.     local entryData = entry.getData();
  2158.     
  2159.     if (not object) then
  2160.         print("checkShortcut no valid object");
  2161.         return false;
  2162.     end;
  2163.  
  2164.     if (not entryObject) then
  2165.         print("checkShortcut no valid entry");
  2166.         return false;
  2167.     end;
  2168.  
  2169.     local optimalSeat = getNextWatchSit(character, entryObject, 1.0, 1.5);
  2170.     if (not optimalSeat) then
  2171.         print("checkShortcut no optimalSeat");
  2172.         return false;
  2173.     end
  2174.     
  2175.     
  2176.     if (optimalSeat ~= object) then
  2177.         print("checkShortcut wrong optimalSeat:" .. optimalSeat.getType() .. " currentSeat:" .. object.getType());
  2178.         return false;
  2179.     end
  2180.     
  2181.     local index = tfind(commands, entryCommand)
  2182.         
  2183. --    if (not index) then index = tfind(commands, entryData) end;
  2184.     
  2185.     if (not index) then
  2186.         print("checkShortcut command not found!  command:" .. entryCommand .. " data:" .. entryData);
  2187.         return false
  2188.     end
  2189.     
  2190.     if (getn(commands) ~= getn(states)) then
  2191.         print("checkShortcut given: " .. getn(commands) .. " commands but " .. getn(states) .. " states");
  2192.         return false
  2193.     end
  2194.     
  2195.     print("checkShortcut -> taking shortcut to state: " .. states[index]);
  2196.     
  2197.     character.popQueueEntry();
  2198.     character.getActivityQueueEntry(0).setStarted(true);
  2199.     clearCancel();
  2200.     
  2201.     
  2202.     if (messages) then
  2203.         local message = messages[index];
  2204.         if (message) then
  2205.             print("checkShortcut sending msg:" .. message .. " data:" .. tostring(entryData) .. " to " .. object.getType());
  2206.             character.sendMsg(message, entryObject, tostring(entryData));
  2207.         end;
  2208.     end    
  2209.     
  2210.     setState(states[index]);
  2211.     
  2212.     
  2213.     return true;    
  2214.  
  2215. end
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221. function getSofaIteractionInfo(character1, character2)
  2222.  
  2223.     
  2224.     local male = 0;
  2225.     if (character1.isMale()) then male = 1; else male = 2; end;
  2226.     
  2227.     local wso1 = character1.walkSO;
  2228.     local wso2 = character2.walkSO;
  2229.     
  2230.     local actionPointName1 = wso1.retrieveData("actionPointName");
  2231.     local actionPointName2 = wso2.retrieveData("actionPointName");
  2232.     
  2233.     if ((not actionPointName1) or (not actionPointName2)) then 
  2234.         print("getSofaIteractionInfo fail actionPointName");
  2235.         return false;
  2236.     end;
  2237.     
  2238.     local sofa1 = character1.getObjectWithActivity("sit");
  2239.     local sofa2 = character1.getObjectWithActivity("sit");
  2240.     
  2241.     if ((not sofa1) or (not sofa2) or (sofa1 ~= sofa2)) then 
  2242.         print("getSofaIteractionInfo fail sofa");
  2243.         return false;
  2244.     end;
  2245.     
  2246.     local possible;
  2247.     local mirrorAnims;
  2248.     
  2249.     
  2250.     if     (actionPointName1 == "sit1" and actionPointName2 == "sit2") then
  2251.         possible = true;
  2252.         mirrorAnims = (male == 2);
  2253.     elseif (actionPointName1 == "sit2" and actionPointName2 == "sit1") then
  2254.         possible = true;
  2255.         mirrorAnims = (male == 1);
  2256.     elseif (actionPointName1 == "sit2" and actionPointName2 == "sit3") then
  2257.         possible = true;
  2258.         mirrorAnims = (male == 2);
  2259.     elseif (actionPointName1 == "sit3" and actionPointName2 == "sit2") then
  2260.         possible = true;
  2261.         mirrorAnims = (male == 1);
  2262.     else
  2263.         possible = false;
  2264.         mirrorAnims = false;
  2265.     end
  2266.         
  2267.     return possible, mirrorAnims;
  2268. end
  2269.  
  2270.  
  2271. -- this walkSO with "activePart" stored
  2272. function getInteractionWaitTime()
  2273.     if retrieveData("activePart") or retrieveData("waitLong") then
  2274.         return WAIT_INTERACTION_ACTIVE;
  2275.     else
  2276.         return WAIT_INTERACTION_PASSIVE;
  2277.     end
  2278. end
  2279.  
  2280.  
  2281. function getStoredOrSender(name, msg)
  2282.  
  2283.     if (type(name) == "table") then
  2284.         for n = 1, getn(name) do
  2285.             print(">getStoredOrSender name table element " .. name[n]);
  2286.             local stored = retrieveStateObject(name[n]);
  2287.             if (stored) then
  2288.                 print(">getStoredOrSender stored as " .. name[n]);
  2289.                 return stored;
  2290.             end
  2291.         end
  2292.     else
  2293.         local stored = retrieveStateObject(name);
  2294.         if (stored) then
  2295.             print(">getStoredOrSender stored as " .. name);
  2296.             return stored;
  2297.         end
  2298.     end
  2299.  
  2300.     print(">getStoredOrSender not stored");
  2301.     return getStateObjectFromID(msg.sender);    
  2302. end
  2303.  
  2304. function unlockAll(storeName)
  2305.  
  2306.     local character = getParent();
  2307.     local object = retrieveStateObject(storeName);
  2308.     if (object) then
  2309.         character.unlockActionPoints(object);
  2310.         character.stopAllActivities(object);
  2311.         object.stopAllSounds();
  2312.     end;
  2313.     removeStateObject(storeName);
  2314.  
  2315. end
  2316.  
  2317.  
  2318. function getEatActivityName(tablet)
  2319.  
  2320.     local activity = tablet.activity;
  2321.     if (not activity) then
  2322.         activity = "eat";
  2323.     end
  2324.     return activity;
  2325.  
  2326. end
  2327.  
  2328. function hasLightenCandles(table)
  2329.  
  2330.     local children = table.getGOChildren();
  2331.     for c = 1, getn(children) do
  2332.         local child = children[c];
  2333.         if (child.hasBehavior("candle") and child.getLightOn()) then
  2334.             return true;
  2335.         end
  2336.     end
  2337.     return false;
  2338.     
  2339. end
  2340.  
  2341.  
  2342. -- this: walkSO
  2343. -- finds character sitting at the same table in front of this character
  2344. function getTableTalkPartner(character, table)
  2345. --~     local table = retrieveStateObject("table");
  2346. --~     local tableActionPointName = retrieveData("tableActionPointName");
  2347. --~     if ((not table) or (not tableActionPointName)) then
  2348. --~         print("lookForPartner: no table or tableActionPointName");
  2349. --~         return nil;
  2350. --~     end
  2351. --~     
  2352. --~     local partnerChair = getOpposedChair(table, tableActionPointName);
  2353. --~     if (not partnerChair) then
  2354. --~         print("lookForPartner: no partner chair found");
  2355. --~         return nil;
  2356. --~     end
  2357. --~     
  2358. --~     local siting = partnerChair.getCharactersWithActivity("sit");
  2359. --~     local partner = siting[1];
  2360. --~     if (not partner) then
  2361. --~         print("lookForPartner: no partner found");
  2362. --~         return nil;
  2363. --~     end
  2364. --~     
  2365. --~     -- somebody is sitting in front of characer -> smalltalk
  2366. --~     print("partner found -> smalltalk");
  2367. --~     return partner;
  2368. --~     
  2369.     -- get all chairs
  2370.     local tableActionPoints = table.getActionPoints();
  2371.     
  2372.     for i = 1, getn(tableActionPoints) do
  2373.         local actionPoint = tableActionPoints[i];
  2374.         local chair = table.getGameObjectOnActionPoint(actionPoint.getName());
  2375.         
  2376.         if (chair) then
  2377.             if chair.hasBehavior("chair") then
  2378.                 local sitting = chair.getCharactersWithActivity("sit");
  2379.                 local partner = sitting[1];
  2380.                 if (partner) then
  2381.                     if (not enumCompare(partner.getCharacterID(), character.getCharacterID())) then
  2382.                         return partner
  2383.                     end
  2384.                 end
  2385.             end
  2386.         end
  2387.         
  2388.     end
  2389.     
  2390.     -- print("getTableTalkPartner: no partner on table found)
  2391.     return nil;
  2392. end
  2393.  
  2394. function canLeave(character)
  2395.  
  2396.     local gameObjectServer = character.getGameObjectServer();
  2397.     
  2398.         
  2399.     local current = gameObjectServer.getOutsideWorld();
  2400.     
  2401.     local other = getOtherCharacter(character);
  2402.     if ((not other) or (not other.getAtHome())) then
  2403.         return false;
  2404.     end;
  2405.     
  2406.     
  2407.     -- check the world rules if this world can be left
  2408.     if (not gameObjectServer.getCurrentWorldRules().getTravelEnable()) then
  2409.         return false;
  2410.     end
  2411.     
  2412.     
  2413.     if (enumCompare(current, CITY)) then
  2414.         print("canLeave to COUNTRY");
  2415.         
  2416.         local cheat = (readConfig("Debug", "beachHouseAlways", "false") == "true");
  2417.         local neverFail = CharacterAI.checkFailing(CharacterAI.NEVER_FAIL);
  2418.         if (cheat or neverFail) then
  2419.             return true;
  2420.         end
  2421.         
  2422.             
  2423.         -- wenn sie das Ja-Wort gegeben hat - vorsicht nicht den honeymoonquest zerschiessen!!
  2424.         if (    gameObjectServer["mission"] and 
  2425.             gameObjectServer["mission"]["questHoneymoon"] and 
  2426.             gameObjectServer["mission"]["questHoneymoon"].getState() == "done" ) then
  2427.                 
  2428.                 return true;
  2429.         
  2430. --                -- TODO: check if they have the beach house already
  2431. --                local mike = gameObjectServer.getCharacter(MIKE);
  2432. --                local elaine = gameObjectServer.getCharacter(ELAINE);
  2433. --                local minCond = min(    mike.getRelationshipCondition(ELAINE, REL_FRIENDSHIP),
  2434. --                            elaine.getRelationshipCondition(MIKE, REL_FRIENDSHIP));
  2435. --                if (minCond < 5) then
  2436. --                    return false;
  2437. --                end
  2438.                 ------------------------------------------------------
  2439.                 
  2440.                 
  2441. --                local gameDate = gameObjectServer.getGameDate();
  2442. --                local weekDay = gameDate.getWeekDay();
  2443. --                local hour = gameDate.getHours();
  2444. --                
  2445. --                if (enumCompare(weekDay, SATURDAY) or enumCompare(weekDay, SUNDAY)) then
  2446. --                    return true;
  2447. --                end
  2448. --                
  2449. --                if (enumCompare(weekDay, FRIDAY) and not character.timeForWork()) then
  2450. --                    return true;
  2451. --                end
  2452.         else
  2453.             print("questHoneymoon not done yet ");
  2454.         end
  2455.     
  2456.     else
  2457.         print("canLeave to CITY");
  2458.         return true;
  2459.     end
  2460.     
  2461.     return false;
  2462.     
  2463. end
  2464.  
  2465. function toggleOutsideWorld(gameObject)
  2466.  
  2467.     local gameObjectServer = gameObject.getGameObjectServer();
  2468.     local current = gameObjectServer.getOutsideWorld();
  2469.     if (enumCompare(current, CITY)) then
  2470.         print("toggleOutsideWorld to COUNTRY");
  2471.         gameObjectServer.setOutsideWorldDeferred(COUNTRY);
  2472.     else
  2473.         print("toggleOutsideWorld to CITY");
  2474.         gameObjectServer.setOutsideWorldDeferred(CITY);
  2475.     end
  2476. end
  2477.  
  2478. function getOtherWaitingToLeave(character, staircase)
  2479.  
  2480.     local other = getOtherCharacter(character);
  2481.     
  2482.     if (not other) or (not staircase) then return nil; end;
  2483.     
  2484.     local oStateMachine = other.walkSO.getStateMachine().getName();
  2485.     local oState = other.walkSO.getState();
  2486.     local oStaircase = other.walkSO.retrieveStateObject("staircase");
  2487.     
  2488. --    print("getOtherWaitingToLeave oStateMachine " .. oStateMachine);
  2489. --    print("getOtherWaitingToLeave oState " .. oState);
  2490. --    print("getOtherWaitingToLeave oStaircase " .. tostring(oStaircase));
  2491. --    print("getOtherWaitingToLeave tStaircase " .. tostring(staircase));
  2492. --    if (oStaircase) then 
  2493. --        print("getOtherWaitingToLeave oStaircase " .. oStaircase.getUniqueID());
  2494. --    end        
  2495. --    print("getOtherWaitingToLeave tStaircase " .. staircase.getUniqueID());
  2496.     
  2497.     if (oStateMachine == "staircaseChar") and (oState == "atOtherHouse") and (oStaircase == staircase) then
  2498.         print("getOtherWaitingToLeave found");
  2499.         return other;
  2500.     end
  2501.     
  2502.     return nil;
  2503.  
  2504. end
  2505.  
  2506.  
  2507. function getLeaveButtonText(gameObject)
  2508.  
  2509.     local gameObjectServer = gameObject.getGameObjectServer();
  2510.     local current = gameObjectServer.getOutsideWorld();
  2511.     if (enumCompare(current, CITY)) then
  2512.         return "pm_gotoCountry";
  2513.     else
  2514.         return "pm_gotoCity";
  2515.     end
  2516.     
  2517.     return "pm_goOut";    
  2518. end
  2519.  
  2520. function getComeBackButtonText(gameObject)
  2521.  
  2522.     local gameObjectServer = gameObject.getGameObjectServer();
  2523.     local current = gameObjectServer.getOutsideWorld();
  2524.     if (enumCompare(current, CITY)) then
  2525.         return "pm_fromCountry";
  2526.     else
  2527.         return "pm_fromCity";
  2528.     end
  2529.     
  2530.     return "pm_goOut";    
  2531. end
  2532.  
  2533.  
  2534. function canMarry(char1, char2)
  2535.     if char1.isMale() then
  2536.         local mike = char1;
  2537.         local elaine = char2;
  2538.  
  2539.         local friendship = min(mike.getRelationshipCondition(ELAINE, REL_FRIENDSHIP),
  2540.             elaine.getRelationshipCondition(MIKE, REL_FRIENDSHIP));
  2541.         local romantic = min(mike.getRelationshipCondition(ELAINE, REL_ROMANTIC),
  2542.             elaine.getRelationshipCondition(MIKE, REL_ROMANTIC));
  2543.         local erotic = min(mike.getRelationshipCondition(ELAINE, REL_EROTIC),
  2544.             elaine.getRelationshipCondition(MIKE, REL_EROTIC));
  2545.         local questHoneymoon = char1.getGameObjectServer()["mission"]["questHoneymoon"];
  2546.  
  2547.         if ( 
  2548.             not (questHoneymoon and questHoneymoon.getState() == "done")
  2549.             and
  2550.             (            
  2551.                 ( -- eines davon 10 und die anderen mindestens 5 sind und der honeymoon-quest schon im state "marryme" ist
  2552.                     max(max(friendship, romantic), erotic) >= 10
  2553.                     and    
  2554.                     min(min(friendship, romantic), erotic) >= 5
  2555.                     and
  2556.                     questHoneymoon and questHoneymoon.getState() == "waitForMarriage"
  2557.                 )
  2558.                 or
  2559.                 ( -- falls questHoneymoon hΣngt: alle drei Bewertungen 10 sind - man also praktisch fertig ist
  2560.                     min(min(friendship, romantic), erotic) >= 10
  2561.                 )
  2562.             )
  2563.         )
  2564.         then
  2565.             -- here condition for marriage
  2566.             return true;
  2567.         end
  2568.     else
  2569.         return false;
  2570.     end
  2571. end
  2572.  
  2573. -- this: walkSO in intraction
  2574. function storeActivityPossible(activity)
  2575.  
  2576.     local thisChar = getParent();
  2577.     local partner = retrieveStateObject("partner");
  2578.  
  2579.     if not partner then
  2580.         print("storeActivityPossible no partner");
  2581.         return 
  2582.     end
  2583.     
  2584.     local partnerChar = partner.getParent();
  2585.     
  2586.     local activePart = retrieveData("activePart");
  2587.     
  2588.     local active = cond(activePart, thisChar, partnerChar);
  2589.     local passive = cond(activePart, partnerChar, thisChar);
  2590.     
  2591.     local result = activityPossible(active, activity, passive);
  2592.     
  2593.     -- if the character has a never fail action, return true
  2594.     local firstEntry = thisChar.getActivityQueue().getFirst();
  2595.     if (firstEntry) then
  2596.         if (firstEntry.getNoFail()) then
  2597.             result = true
  2598.         end
  2599.     end
  2600.     
  2601.     storeData("activityPossible", result);
  2602.     
  2603.     print("storeActivityPossible stored: " .. tostring(result));
  2604.     print(">>active : " .. active.getCharacterName());
  2605.     print(">>passive : " .. passive.getCharacterName());
  2606.     
  2607. end
  2608.  
  2609. -- this: questSO
  2610. function talkingCancelled(charID, topic)
  2611.  
  2612.     local gameObjectServer = getParent().getParent();
  2613.     local character = gameObjectServer.getCharacter(charID);
  2614.     if character then
  2615.         local walkSO = character.walkSO;
  2616.         if walkSO then
  2617.             print("talkingCancelled topic: " .. topic .. " to" .. character.getCharacterName());
  2618.             sendMsg("talkingCancelled", walkSO, topic);
  2619.         end
  2620.     end
  2621.     
  2622. end
  2623.  
  2624. function isOnActionPoint(character, object, actionPointName)
  2625.  
  2626.     if not character then
  2627.         print("isOnActionPoint : character == nil ");
  2628.         return false;
  2629.     end
  2630.  
  2631.     if not actionPointName then
  2632.         print("isOnActionPoint : actionPointName == nil ");
  2633.         return false;
  2634.     end
  2635.  
  2636.     local actionPoint = object.getActionPoint(actionPointName);
  2637.     if actionPoint then
  2638.         print("isOnActionPoint : actionPoint ".. actionPointName.." found");
  2639.         return character.isOnActionPoint(actionPoint, 0.1, 0.1);
  2640.     else
  2641.         print("isOnActionPoint : actionPoint " .. actionPointName .. " not found in " .. object.getType());
  2642.         return false;
  2643.     end
  2644. end
  2645.  
  2646.  
  2647. function exitIfWrongPosition(character, object, actionPointName)
  2648.  
  2649.     if not character then
  2650.         print("-----------------exitIfWrongPosition : character == nil !!! ----------------- ");
  2651.         return false;
  2652.     end
  2653.  
  2654.     if not object then
  2655.         print("-----------------exitIfWrongPosition : object == nil !!! ----------------- ");
  2656.         return false;
  2657.     end
  2658.  
  2659.     if not actionPointName then
  2660.         print("-----------------exitIfWrongPosition : actionPointName == nil !!! ----------------- ");
  2661.         return false;
  2662.     end
  2663.  
  2664.  
  2665.     if not hasRightPosition(character, object, actionPointName) then
  2666.         exitStateMachine();
  2667.         character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  2668.         return true;
  2669.     else
  2670.         return false;
  2671.     end
  2672.  
  2673. end
  2674.  
  2675. function hasRightPosition(character, object, actionPointName)
  2676.  
  2677.     if isOnActionPoint(character, object, actionPointName) then
  2678.         return true;
  2679.     else
  2680.         return false;
  2681.     end
  2682.  
  2683. end
  2684.  
  2685. -- returns true if the story is active (checks for mission and questor)
  2686. function storyActive(gameObjectServer)
  2687.     local mission = gameObjectServer["mission"];
  2688.     if (mission) then
  2689.         local missionStateMachine = mission.getStateMachine();
  2690.         if (missionStateMachine) then
  2691.             if (missionStateMachine.getName() == "questor") then
  2692.                 return true;
  2693.             end
  2694.         end
  2695.     end
  2696.     return false
  2697. end
  2698.  
  2699. -- returns true if the given character is eating
  2700. function isEating(character)
  2701.     if (character.hasActivityName("eat")) then return true end;
  2702.     if (character.hasActivityName("eatBreakfast")) then return true end;
  2703.     if (character.hasActivityName("eatSupper")) then return true end;
  2704.     if (character.hasActivityName("eatPizza")) then return true end;
  2705.     if (character.hasActivityName("eatDinner")) then return true end;
  2706.     return false
  2707. end
  2708.  
  2709. -- takes a condition and returns the appropriate emoticon
  2710. function conditionToEmoticon(condition)
  2711.  
  2712.     if (enumCompare(condition, NEED_HUNGER)) then
  2713.         return EMOTICON_HUNGER
  2714.     elseif (enumCompare(condition, NEED_COMFORT)) then
  2715.         return EMOTICON_NOCOMFORT
  2716.     elseif (enumCompare(condition, NEED_HYGIENE)) then
  2717.         return EMOTICON_SMELL
  2718.     elseif (enumCompare(condition, NEED_TIREDNESS)) then
  2719.         return EMOTICON_SLEEPY
  2720.     elseif (enumCompare(condition, NEED_FUN)) then
  2721.         return EMOTICON_NOFUN
  2722.     elseif (enumCompare(condition, NEED_RELATIONSHIP)) then
  2723.     elseif (enumCompare(condition, NEED_LIBIDO)) then
  2724.     elseif (enumCompare(condition, NEED_APARTMENT)) then
  2725.         return EMOTICON_NOAPARTMENT
  2726.     elseif (enumCompare(condition, NEED_HYGIENE_BODY)) then
  2727.         return EMOTICON_SMELL
  2728.     elseif (enumCompare(condition, NEED_HYGIENE_MOUTH)) then
  2729.         return EMOTICON_SMELL
  2730.     elseif (enumCompare(condition, NEED_HYGIENE_HAND)) then
  2731.         return EMOTICON_SMELL
  2732.     elseif (enumCompare(condition, NEED_LIBIDO_EROTIC)) then
  2733.     elseif (enumCompare(condition, NEED_LIBIDO_SEX)) then
  2734.     elseif (enumCompare(condition, NEED_RELATIONSHIP_FRIENDSHIP)) then
  2735.     elseif (enumCompare(condition, NEED_RELATIONSHIP_ROMANTIC)) then
  2736.     elseif (enumCompare(condition, NEED_JUSTICE)) then
  2737.         return EMOTICON_JUSTICE
  2738.     elseif (enumCompare(condition, NEED_WORK)) then
  2739.     elseif (enumCompare(condition, NEED_TROUBLE)) then
  2740.     elseif (enumCompare(condition, NEED_BLADDER)) then
  2741.         return EMOTICON_BLADDER
  2742.     end
  2743.  
  2744.     -- no specific emoticon found
  2745.     return EMOTICON_CANNOT
  2746. end