from eventAPI import *
from APIUtils import *

def fireEvent(e):
    if ((getTag(e, "lFlagS") & 0x100) == 0):
        return 1
    global kp
    kp = getTag(e, "kssPlot")
    if (kp == 0):
        arrival(e)
        return 1
    elif (kp == 1):
        welcome(e)
        return 1
    elif (kp == 2):
        dinner (e)
        return 1
    elif (kp < 11):
        wall (e)
        return 1
    else:
        return portal(e)
        
def arrival(e):
    showMessage(e, ["You experience a brief moment of disorientation...","","When you come to your senses, you find yourselves in a dimly lit tunnel. You see no way to go back.","","Ahead, a group of humanoids is watching you silently; they smile affably, waiting for you to make a move."])
    setTag(e, "kssPlot", 1)

def welcome(e):
    showMessage(e, ["The humanoids are waiting patiently, smiling in welcome."])

def dinner(e):
    showMessage(e, ["Your new friends are still waiting for you to join them for dinner, smiling as ever. Now, however, you see the teeth behind the smiles..."])

def wall(e):
    showMessage(e, ["There is nothing here but a bare rock wall."])
                    
def portal(e):
    showPicture(e, "kssportal")
    if (getTag(e, "kssPlot") == 11):
        setTag(e, "kssPlot", 12)
        showMessage(e, ["A portal has opened at the end of the hallway; it emits a faint vibration."])
    setExit(e, "maps/renwild.cfg", 195, 174, 270)
    return (poseYesNo(e,
  ["Through this portal, you see the place whence you arrived.","",
   "Do you wish to enter the portal ?"]) == 0)
