Implementation of a teleporter
Posted: Sun Sep 02, 2012 5:17 pm
This thread explains the implementation of a teleporter in Hugo. Due to lack of means to create tables, code is marked in yellow, file names in violet.
Now, the first thing to ask is, how do you do an immediate move from room to room. Well, it's really simple. You call moveplayer(I) [hugolib.h] where I is the room to go to.
Now, all you have to do is figure out how to determine what the room is. In Teleporter Test, I first had to decide how to do that. What I did was, I created the following attributes:
attribute Teleport_incoming ! Room can be teleported into
attribute Teleport_Outgoing ! room has a teleporter pad (can teleport out)
attribute roomtype ! to flag rooms for teleporting
attribute List_Incoming_Only ! can only teleport to an inbound Teleport_incoming spot
attribute List_Outgoing_Only ! can only teleport to another teleport pad
In the list of rooms, the first room that I want to be able to display is given the following attribute to its description
roomcount 1
the teleport lister ignores all rooms until it finds one with this value (this way it doesn't list or look at the nothing object). Roomcount 1 is only used once in the game.
A room that has a teleporter is an incoming only, outgoing only, or both. So you add one or both of the following to the room's description
is Teleport_incoming
is Teleport_outgoing
depending on whether you want the room an entry point, an exit point, or both.
The list routine will show all teleporters, incoming and outgoing. To restrict this, you put in one or the other in the room's description:
is List_Outgoing_Only
is List_Incoming_Only
Now, I could have had the room lister use the teleport pad in the room you're in to restrict what it shows, but because it was a demonstration and I wanted to be able to have a room that could teleport into both an outgoing only room as well as to a teleporter pad, I had to have the ability to show everything.
Now, the lister has to know when it's run out of rooms so that it isn't searching objects that aren't rooms. So, after the Main routine I have an empty room as the last declared room in the game (or at least, the last one that can be listed by the teleporter list routine):
room emptyroom "(empty room)"
{
roomcount 2
}
When the room lister finds a room with attribute roomcount 2 it stops listing rooms. Now, I had to add a teleport command, At the bottom of verblib.g I added the following:
verb "teleport"
* DoTeleport
* player_character DoTeleport
* player_character "to" DoTeleport
This allows the user to type teleport or teleport me
I'll continue this in the next message.
Now, the first thing to ask is, how do you do an immediate move from room to room. Well, it's really simple. You call moveplayer(I) [hugolib.h] where I is the room to go to.
Now, all you have to do is figure out how to determine what the room is. In Teleporter Test, I first had to decide how to do that. What I did was, I created the following attributes:
attribute Teleport_incoming ! Room can be teleported into
attribute Teleport_Outgoing ! room has a teleporter pad (can teleport out)
attribute roomtype ! to flag rooms for teleporting
attribute List_Incoming_Only ! can only teleport to an inbound Teleport_incoming spot
attribute List_Outgoing_Only ! can only teleport to another teleport pad
In the list of rooms, the first room that I want to be able to display is given the following attribute to its description
roomcount 1
the teleport lister ignores all rooms until it finds one with this value (this way it doesn't list or look at the nothing object). Roomcount 1 is only used once in the game.
A room that has a teleporter is an incoming only, outgoing only, or both. So you add one or both of the following to the room's description
is Teleport_incoming
is Teleport_outgoing
depending on whether you want the room an entry point, an exit point, or both.
The list routine will show all teleporters, incoming and outgoing. To restrict this, you put in one or the other in the room's description:
is List_Outgoing_Only
is List_Incoming_Only
Now, I could have had the room lister use the teleport pad in the room you're in to restrict what it shows, but because it was a demonstration and I wanted to be able to have a room that could teleport into both an outgoing only room as well as to a teleporter pad, I had to have the ability to show everything.
Now, the lister has to know when it's run out of rooms so that it isn't searching objects that aren't rooms. So, after the Main routine I have an empty room as the last declared room in the game (or at least, the last one that can be listed by the teleporter list routine):
room emptyroom "(empty room)"
{
roomcount 2
}
When the room lister finds a room with attribute roomcount 2 it stops listing rooms. Now, I had to add a teleport command, At the bottom of verblib.g I added the following:
verb "teleport"
* DoTeleport
* player_character DoTeleport
* player_character "to" DoTeleport
This allows the user to type teleport or teleport me
I'll continue this in the next message.