NPC patrols with rudimentary AI

Hello, everyone.

I'm coding a text game (duh). While I started writing it with Inform7, I am contemplating using Quest instead.
I have a question about a certain script, as I check if everything can be ported from Inform to Quest.

My game will have the player/a space-ship travelling on a map composed of rooms representing x,y coordinates.
I want to have another object, representing a pirate ship, patrol the map, moving from room-to-room each turn.

However, compared to the example of http://docs.textadventures.co.uk/quest/patrolling_npcs.html, I want specific conditions/requirements:

  • If the player is more than 3 rooms away, the pirate ship chooses a direction semi-randomly, with a weight on heading towards the player, to keep things challenging
  • If the player is 3 rooms or less away, the pirate ship "spots" the player and moves in their direction every turn

In Inform7, there is a phrase called best route from [thing A] to [thing B], which allows me to get the number of rooms separating A from B, and to choose the correct direction for A to get to B.
(http://inform7.com/learn/man/WI_6_14.html)

My question is: is there an equivalent of Inform's best route in Quest?

Thank you in advance.


I don't think there's a built-in pathfinding code, you got to code/script it yourself:

using the 'x/y coordinate' Integer Attributes, here's the basic concept of 'seeking' (moving 1 Object towards another Object based upon x/y grid concept/logic) pathfinding:

(you'll have to code in the stuff for the '3 rooms away and its randomization vs not random' and/or navigating/handling any 'locked/blocked' paths, not going to try to code that in here, too much work and/or possibly difficult)

if (pirate_ship.x_coordinate > player.x_coordinate) {
  pirate_ship.x_coordinate = pirate_ship.x_coordinate - 1
} else if (pirate_ship.x_coordinate < player.x_coordinate) {
  pirate_ship.x_coordinate = pirate_ship.x_coordinate + 1
}

if (pirate_ship.y_coordinate > player.y_coordinate) {
  pirate_ship.y_coordinate = pirate_ship.y_coordinate - 1
} else if (pirate_ship.y_coordinate < player.y_coordinate) {
  pirate_ship.y_coordinate = pirate_ship.y_coordinate + 1
}

foreach (object, pirate_ship.parent.adjacent_rooms_list) {
  if (object.x_coordinate = pirate_ship.x_coordinate and object.y_coordinate = pirate_ship.y_coordinate) {
    pirate_ship.parent = object
  }
}

Have a look at the NPC library.

https://github.com/ThePix/quest/wiki/Library:-Independent-NPCs

Further reading:
http://textadventures.co.uk/forum/samples/topic/1gpwpfattuyocvlg1sievq/controlling-npcs
http://docs.textadventures.co.uk/quest/libraries/path_library.html

hope the information helps


There could be a way, but you would need to think outside the box for this one...
You have 4 places where NPC's may want to go:
1=kitchen
2=living room
3=bed room
4=basement
So, you set a destination variable on the NPC... NPC.ToGo=1
In each room, you set up 4 variables that tells the direction to each room:
IE: in kitchen, you have:
kitchen=0 (you are here)
living room=w
bed room=w
basement=s
Yes, living room and bed room is west, because to get to the bed room, you go through the living room.
living room would have:
kitchen=e
living room=0 (here)
bed room=n
basement=e (go through kitchen to get to basement.)

To simplify this, (and shorten the coding) use a split(), just keep the room order the same.
kitchen=split(4,0,w,w,s) (Since Quest counts from 0, and humans count from 1, we need a "spacer" here...)
living room=split(4,e,0,n,e) ("4" works so that we know how many places there is, just incase we need to add one)
bed room=split(4,s,s,0,s) (we know how many we have...)
basement=split(4,n,n,n,0)
Then, you could add a room, like a hallway between the bed room and the living room, but since no one just "goes" to the hallway, it would not need a destination, so...
hallway=split(4,s,s,n,s)
(north to the bedroom, south to everything else...)
You could also have the NPC "goto" the player the same way:
If the NPC is in the bed room and the player is in the basement, then by "telling" the NPC to go to the player and the NPC "knows" the player is in the basement, then the NPC will need to move:
S (to the hall)
S (to the living room)
E (to the kitchen)
then S (to the basement)
msg("Yes, " + player.alias + ", you called?")


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums