Help request with Patroller Extension

Hello again, I was wondering if anyone out there has used the Patroller’s extension in such a way that the game will warn the player 1 or more turns before the patroller NPC arrives in the room? Usually the patroller just arrives, but I’d like to have an advance warning, which would give the player a chance to leave the room or hide, if they were sneaking around someplace that they shouldn’t be. The extension doesn’t seem to have this built into it, and I haven’t come across anything similar on the forums. I’m not sure if this could be done simply with a few lines of code, or whether an elaborate checking and tracking routine would need to be written. Right now implementing this in Inform 7 is over my head, but if someone knew I way I could do it or get started, I’d be very appreciative for any help!

[code]
The Red Knight is a Patroller. The Red Knight carries a steel key. The description is “From head to foot the Red Knight is concealed within a metal skin of blood red armor.”

The Turn Frequency of the Red Knight is 2. The printed name of the Red Knight is “Red Knight”. The Red Knight is RoomLed. The Red Knight is TwoWayRepeated. The RoomTable of the Red Knight is the Table of Castles Ground Floor.

Table of Castles Ground Floor
TargetRoom
Portcullis
Gatehouse
Guards Hall
Barracks
Antechamber
West Hall
South Great Hall
East Hall
Scullery
North Courtyard
South Courtyard
Storage Chamber
Armory
Gatehouse

The OpeningCapability of the Red Knight is Universal. The ReClosingCapability of the Red Knight is Leave.[/code]

Hi dn. I had a look at Patrollers and it appears that the feature you’re after will be moderately tricky to program.

Since the rooms that are patrolled aren’t necessarily next to each other, and the routes between any two rooms are calculated on the fly, the game can’t just look at a hard database of paths through the game and see how far apart the player and knight are to decide if it should warn the player.

It has to look at where the knight is now, plot a test path to the next location from there and see if the player is on that path. Additionally, if the knight is a move or 2 away from his current target, the program may need to start potting a test path from the current target to the target after that one and check it as well. However if you’re sure you only ever want the program to warn the player if the knight is 1 room away, you could skip the ‘target after the current target’ programming.

An ideal way to program this routine would be so that it would work for any proximity. E.G. You’d be able to say something like ‘Now the danger aura of the Red Knight is 3’ and then the routine would warn the player if the knight was within 3 rooms. Change it to 1 and then it warns them only if he’s 1 room away. But overall, the task involves a little less programming if the knight’s aura will never reach beyond 1 room.

I might be able to have a go at this myself but typically one of the resident coding demons just posts a whole working example before I’ve actually done anything :wink: So I’ll just see if anyone else moves or replies first.

  • Wade

I just though of more problems with this code. It’s easy to check if the knight is just nearby (eg 2 rooms away). It’s a little trickier to check if the player is between the knight and his goal. But it’s trickier again to give accurately helpful information in response to the latter concerning what might happen in a move or two.

Consider a straight corridor with the knight marching up and down it, and it has one alcove off the side. If the player sits in the alcove, he never gets between the knight and his goal and thus never gets a warning. If the knight is one square away from the room in front of the alcove, the player could actually be receiving no warning, step into the room, and immediately die on the next turn when the knight enters.

So before we go on, I think it’s important you (dn) think more about how you want this warning system to work. It seems like it might need some combination of the ‘just nearby’ and ‘in the knight’s path’ approaches. The trouble with a ‘just nearby’ warning is it might go off all the time and not be giving useful information. But without considering extra information, a straight check for you ‘in the knight’s path’ will miss some important cases.

  • Wade

Hello Wade, thanks for the explanation, yeah I figured it might be pretty complicated to work out, way over my head, so I’ll likely just end up doing something else like giving the player 1 turn after the Knight arrives to hide or leave unnoticed, instead of announcing them before they enter the room. Unless somebody suggests a way it could be done, but that seems unlikely now with all the path-finding and tracking that needs to be done behind the scenes.

The only other way I could think of to work it out was to somehow put the Patroller on a timed schedule using a timer, so he would arrive in each different room always at the same time, then checking to see if the player was in the room a minute or so before the Patrollers scheduled arrival, then if so announcing his approach, sort of like an alarm clock. But that might be a whole other ordeal that I’m not sure can be worked out with the Patroller extension as it’s written either.

But thanks very much for the suggestions, if I figure out a way to get it to work I’ll post it in case someone else wants to do something like this in the future!

Are you using “The Patrollers Extension” solely to get the advance warning? If so, then you could just do it without the extension, like so.

[spoiler][code]“Test”

Use no scoring, no deprecated features and full-length room descriptions.

Include Basic Screen Effects by Emily Short.

Section - Grid Test Code

The switch score notification on rule is not listed in the carry out switching score notification on rulebook.
The standard report switching score notification on rule is not listed in the report switching score notification on rulebook.
The switch score notification off rule is not listed in the carry out switching score notification off rulebook.
The standard report switching score notification off rule is not listed in the report switching score notification off rulebook.

Grid is a truth state that varies. Grid is false. Understand “grid” or “grid on” as switching score notification on. Understand “grid off” as switching score notification off.

Check switching score notification on (this is the standard check switch score notification on rule):
if grid is true, say “The grid is already on.” instead.

Check switching score notification off (this is the standard check switch score notification off rule):
if grid is false, say “The grid is already off.” instead.

Carry out switching score notification on (this is the standard carry out switch score notification on rule):
now grid is true.

Carry out switching score notification off (this is the standard carry out switch score notification off rule):
now grid is false.

Report switching score notification on (this is the standard report switch score notification on rule):
say “The grid is now on.”.

Report switching score notification off (this is the standard report switch score notification off rule):
say “The grid is now off.”.

To say (multiply - number) space/spaces:
repeat with value running from 1 to multiply begin;
say " ";
end repeat.

To say (chosen room - a room) status:
if the chosen room is the location of the player begin;
say red letters;
otherwise if the chosen room is the location of alpha beta;
say blue letters;
otherwise;
say black letters;
end if;
say “@”;
say default letters.

Every turn (this is the display grid rule):
if grid is true begin;
say fixed letter spacing;
say “[room 00 status][1 space][room 01 status][1 space][room 02 status][1 space][room 03 status][1 space][line break]”;
say “[room 04 status][1 space][room 05 status][1 space][room 06 status][1 space][room 07 status][1 space][line break]”;
say “[room 08 status][1 space][room 09 status][1 space][room 10 status][1 space][room 11 status][1 space][line break]”;
say “[room 12 status][1 space][room 13 status][1 space][room 14 status][1 space][room 15 status][1 space][line break]”;
say variable letter spacing;
end if.

The display grid rule is listed last in the every turn rulebook.

Section - NPC Movement Code

When play begins (this is the startup rule):
move the player to a random room, without printing a room description;
move alpha beta to a random room;
while the location of the player is the location of alpha beta begin;
move alpha beta to a random room;
end while.

Check an actor entering a room (this is the convert enter room into go rule):
let the way be the best route from the location of the actor to the noun;
try the actor going the way instead.

The convert enter room into go rule is listed first in the check entering rulebook.

The next room is a room that varies. Go count is a number that varies. Go count is zero.

Every turn (this is the NPC movement rule):
if go count is two begin;
now go count is zero;
try alpha beta entering the next room;
otherwise if go count is not zero;
increment go count;
otherwise if a random chance of 1 in 2 succeeds;
increment go count;
let the current room be the location of alpha beta;
now the next room is random room which is adjacent to the current room;
[say “[bracket]Current Room is - [the current room][close bracket][line break]”;
say “[bracket]Next Room is - [the next room][close bracket][line break]”;]
if the player is enclosed by the next room, say “There shall be others entering this room soon.”;
end if.

Alpha Beta is a person.

Room 00 is A Room. Room 01 is east of Room 00. Room 02 is east of Room 01. Room 03 is east of Room 02. Room 04 is south of Room 00 and southwest of Room 01. Room 05 is south of Room 01, southeast of Room 00, southwest of Room 02 and east of Room 04. Room 06 is south of Room 02, southeast of Room 01, southwest of Room 03 and east of Room 05. Room 07 is south of Room 03, southeast of Room 02 and east of Room 06. Room 08 is south of Room 04 and southwest of Room 05. Room 09 is south of Room 05, southeast of Room 04, southwest of Room 06 and east of Room 08. Room 10 is south of Room 06, southeast of Room 05, southwest of Room 07 and east of Room 09. Room 11 is south of Room 07, southeast of Room 06 and east of Room 10. Room 12 is south of Room 08 and southwest of Room 09. Room 13 is south of Room 09, southeast of Room 08, southwest of Room 10 and east of Room 12. Room 14 is south of Room 10, southeast of Room 09, southwest of Room 11 and east of Room 13. Room 15 is south of Room 11, southeast of Room 10 and east of Room 14.

Test me with “grid / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z”.[/code][/spoiler]

This will show a message when the NPC is about to enter the room that the player is in and allows two turns for the player to do something about it. This can be changed to more than two turns if needed.

Hope this helps.

Thanks a lot, I’ll try this out today to see how it works. Yeah, I’m using the Patroller for a number of sequences involving NPC’s moving about, but I’m sure I can also use what you’ve done here too. It would be great if the two could be integrated somehow, or used together in different parts without any conflicts. Should be interesting to play around with!