Awareness of An Approaching Foe

Hail,

I’m looking to make a Survival Horror-style game making some use of the Inform ATTACK extension, involving a character being hunted by some super powerful alien or monster. (Yes, this has everything to do with “Alien: Isolation.”) The idea is that the player will be trying to fulfill various objectives, all while evading detection and subsequent demise. I want the enemy–let’s just call him Alien–to wander about at random and possibly run into the player, at which point he’ll attack. I can implement most of this, I think. For example:

Every turn when the location is not the location of the player:
let X be a random direction;
try Alien going X.

That should let Alien move about freely, though I’m hoping it won’t let him walk through locked doors. But my concern right now is giving the player a heads-up that their doom lurks near. Is their any code I can insert to let the player know Alien is near? My only current option is to make a bunch of regions and have something like this:

Every turn when the region of Alien is the region of the player:
say “You hear scuffling and hissing nearby.”

First of all “the location” always means the location of the player. Make sure you say “Every turn when the location of the Alien is not the location of the player.”

Also, “Let X be a random direction” means the Alien will walk into walls trying directions that aren’t map directions. You may wish to define “viable directions” and make sure the Alien goes a random viable direction instead of just a random direction. (Unless your creature is ineffably stupid! :slight_smile: )

You can check for “If the location of the Alien is adjacent to the location of the player…” You can also check for “the number of steps between…” but I don’t recall the specific syntax off the top of my head.
Check the manual, section 3.25, and the recipe book with examples, section 7.13

If you want to give it some more AI, you could have something like this.

Every turn:
    let N be the number of steps from the location of the alien to the location, using doors;
    let the way be a direction;
    if N is less than 5:
        say "You sense that the alien is [if N is 1]in the next room[else if N is 2]very close now[else if N is 3]close[else if N is 4]somewhere nearby[else]in the vicinity[end if].";
        let the way be the best route from the location of the alien to the location, using doors;
    else:
        let the way be a random direction;
    if the way is a direction:
        let the place be the room way from the location of the alien;
        if the place is a room, try the alien going way.

Basically, the alien and the player can sense each other when they are within 5 moves, and at this point the alien will attempt to go toward the player. Closed doors don’t block this (I believe NPCs can open them automatically now), but locked ones do. If the alien is farther away than that, he picks a random direction each turn, and goes that way if possible (otherwise he does nothing).

That is PERFECT!!! Closed doors are fine, I just want locked doors to impede the Alien. Thanks so much. Also, what is the difference between the use of “else” rather than “otherwise”?

Also, I’ve noticed a bit of a problem: after the alien gets within the 5 move radius–let’s call that “chasing” the player–there’s no way to stop him, short of a locked door. That is, once he’s found you once, he can’t unfind you. For every one move you make, he’ll either get closer or stay the same distance away. How can I modify the above code to let the player actually escape for a while.

Here’s an idea: when the alien gets within five moves of the player, set a countdown. If it can’t get to to the player within, let’s say, six moves, it switches to random movement for at least five or so turns.

Or just put a possibility of random delay in when alien is in the location.

There’s no real difference between “else” and “otherwise”. I generally use “else” within text and “otherwise” in other places.

To give the player a chance to escape:

Definition: a direction (called the way) is alien-usable:
    let the place be the room-or-door way from the location of the alien;
    if the place is nothing, no;
    if the place is a door and the place is locked, no;
    yes.

Every turn:
    let N be the number of steps from the location of the alien to the location, using doors;
    let the way be a direction;
    if N is less than 5:
        say "You sense that the alien is [if N is 1]in the next room[else if N is 2]very close now[else if N is 3]close[else if N is 4]somewhere nearby[else]in the vicinity[end if].";
        let the way be the best route from the location of the alien to the location, using doors;
    else:
        let the way be a random alien-usable direction;
    if the way is a direction:
        if a random chance of 3 in 4 succeeds:
            try the alien going way.

Now the alien moves, on average, three out of every four turns. The “alien-usable” code means that he now only picks directions leading to rooms.

This is perfect! Thanks so much.

Just an artistic suggestion: Would it help the story if the monster is distractable? For example, drop a hunk of meat at your location, then move away. The monster finds it and then spends the next N moves eating it.

That would be insanely cool/helpful!!! A hunk of meat or a noise-maker or something to keep its attention drawn.

Just add a property…

The alien can be currently feeding. The alien is not currently feeding.

…with a check before the movement code…

if the alien is not currently feeding:

…and an additional rule to handle the meat.

The meat has a number called the feeding duration. The feeding duration of the meat is 5.
Every turn when the alien can touch the meat:
    now the alien is currently feeding;
    decrement the feeding duration of the meat;
    [text here];
    if the feeding duration of the meat is zero:
        remove the meat from play;
        now the monster is not currently feeding;
        [text here].

This is amazing. I have just one last annoying request for you. Would you be willing to put all that great code (the meat/feeding code and the alien movement code) into one post where I could just copy/paste it neatly into play. I hate to ask that, but I’m blind, and my braille computer makes doing that kind of tricky.

Certainly. I’ll actually wrap it into a small sample project, so that you can compile it as-is and see how it works.

[spoiler][code]
Alpha, Beta, Gamma, Delta, Epsilon, Zeta, Eta, Theta, and Omega are rooms.
Alpha is north of Beta. Gamma is west of Beta and southwest of Alpha. Delta is below Gamma. Epsilon is south of Beta. Zeta is southeast of Epsilon. Eta is below Zeta. Theta is southeast of Delta and northwest of Eta.

The airlock is a locked door. “The airlock is [if the airlock is open]open[else]closed[end if] to the [if the location is Alpha]north[else]south[end if].” It is north of Alpha and south of Omega. There is a passcard in Eta. The passcard unlocks the airlock.
Every turn when the player is in Omega:
if the airlock is closed and the airlock is locked and the alien is not in Omega:
end the story finally saying “You have escaped”.

The alien is a person in Zeta. “The alien has arrived, and looks angry!”
The alien can be currently feeding. The alien is not currently feeding.

The player carries a blob of alien meat. The description of the meat is “Green and squishy. You have no idea what it is, but you’ve been told that aliens like to eat it.”
The blob of meat has a number called the feeding duration. The feeding duration of the meat is 5.

Every turn when the alien can touch the meat and the meat is not carried:
now the alien is currently feeding;
decrement the feeding duration of the meat;
if the player can see the alien:
say “The alien is contentedly eating the meat.”;
if the feeding duration of the meat is zero:
remove the meat from play;
now the alien is not currently feeding;
if the player can see the alien:
say “The alien finishes the meat and turns toward you again.”

Definition: a direction (called the way) is alien-usable:
let the place be the room-or-door way from the location of the alien;
if the place is nothing, no;
if the place is a door and the place is locked, no;
yes.

Every turn when the alien is not currently feeding:
let N be the number of moves from the location of the alien to the location, using doors;
let the way be a direction;
if N is less than 5:
say “You sense that the alien is [if N is 1]in the next room[else if N is 2]very close now[else if N is 3]close[else if N is 4]somewhere nearby[else]in the vicinity[end if].”;
let the way be the best route from the location of the alien to the location, using doors;
else:
let the way be a random alien-usable direction;
if the way is a direction:
if a random chance of 3 in 4 succeeds:
try the alien going way.

Every turn when the alien is in the location and the alien is not currently feeding:
say “The alien has found you!”;
end the story saying “You die a horrible death”.
[/code][/spoiler]

This is excellent!!! Thank you so much!

Thanks Draconis, that is very useful for me also.