Elevator Implementation

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 9333
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Elevator Implementation

Post by Tdarcos »

A multi-story department store has to have an elevator. (For the purists in the peanut gallery who are screaming about my revolving door and the extra work to travel, there are also escalators elsewhere in the building, which simply go up and down.)

So here's how I implement an elevator.

Code: Select all

!! Verbs
verb "push","press"
	*                                  DoVague
	* pushable                         DoPush
	* "b"/"1"/"2"/"3"                  DoElevator

!! Verb processing code
Routine DoPush
{

!... push something else ...
		
! Push elevator call button		
	if (object = callb) {
		if (location=parent(callb))
		{		
			print "The elevator is already here. Go IN to enter elevator."
			
		} else {
			move elevator_object to location	
			elevator.name = nameelevator(location)
		
			print "Ding! The elevator arrives."
			moveplayer (location)
		}	
        }

! ... push other things ...

}

routine DoElevator
{
local destination

	if (location ~= elevator)
	{
		print "I don't see that here"
		return
	}
	
	select word[2]
		case "b":	destination = Store_B_elevator 
		case "1":	destination = Store_1_elevator 
		case "2":	destination = Store_2_elevator 
		case "3":	destination = Store_3_elevator 
	
	if (destination = parent(elevator_object))
	{
		print "You're already there."
		return
	}

	print "The doors close, the elevator starts, 
		  the elevator moves, it stops, the bell rings, the doors open."
	move elevator_object to destination
	elevator.name = NameElevator(destination)
	move callb to destination
	moveplayer(location) ! So the elevator title is redrawn
}

Routine NameElevator (Where)
{
	select where
		case Store_B_elevator 
			return "Inside the elevator, at the basement"
		case Store_1_elevator 
			return "Inside the elevator, on the first floor"
		case Store_2_elevator 
			return "Inside the elevator, on the second floor"
		case Store_3_elevator 		
			return "Inside the elevator, on the third floor"
	
	return "** Unknown elevator location **"
}


!! Attributes / properties
attribute Pushable                    ! Can be pushed or pressed


!! Rooms/Objects
room Store_1_elevator "First floor elevator waiting area"
{

	E_to            Store     ! unimportant location
	NE_to			Store_1_06
	IN_to			
	{
		if (location=parent(elevator_object))
		{
			moveplayer(elevator)
		} else {
			print "The elevator isn't here."
		}
	}
	
	long_desc
	{
	if location = parent(elevator_object)
		{
		print "Go IN to enter elevator."
		}
	else
		{
		move callB to location
		print	"Press CALL button to call for the elevator.  Go IN when it arrives."
		}
	print "Go EAST to return to the store entrance,
		or NORTHEAST to Department 6."
	}
}

object CallB "elevator call button"
{
	in store_1_elevator
	article "the"
	adjectives "call","button"
	is pushable,static,hidden
}

object elevator_object 
{
	article "the"
	in store_1_elevator
	is static
	short_desc
	{
		"The elevator is here."
	}
}

room elevator	"Inside the elevator, on the first floor"
{

	OUT_to 
	{
		moveplayer(parent(elevator_object))
	}
	
	long_desc
	{
		if elevator is not beenhere			! Only show picture first time
			picture "wnselevator.jpg"
		elevator is beenhere
		print "Press button for desired floor: PRESS B, PRESS 1, PRESS 2 or PRESS 3.  
		When the elevator arrives, go OUT or EXIT to leave.\n
		\"NOTICE: Smoking is not permitted in elevators.\" \n- Winnemac B&E Code Sec. 70005."		
	}
}

room Store_1_06 "First floor Department 6."
{
	SE_to 		Store        ! Unimportant location for this demo
	E_to		Store_1_escalator  ! Unimportant location for this demo
	SW_to		
	{
		move CallB to Store_1_elevator
		MovePlayer(Store_1_elevator)
	}
	
	long_desc
		"Go SOUTHEAST to return to the store entrance, 
		SOUTHWEST to the elevator, or 
		EAST to the escalators."
}

! Basement

room Store_B_elevator "Basement elevator waiting area"
{

	NE_to			Store_B_06  ! Unimportant location for this demo
	IN_to			
	{
		if (location=parent(elevator_object))
		{
			moveplayer(elevator)
		} else {
			print "The elevator isn't here."
		}
	}
	
	long_desc
	{
		if location ~= parent(elevator_object)
			print	"Press CALL button to call for the elevator.\n
				Go ";
		else
			print "Go IN to enter elevator, or ";
		print "NORTHEAST to Department 6."
	}
}
room Store_B_06 "Basement Department 6."
{
	
	E_to		Store_B_escalator  ! Unimportant location for this demo
	SW_to		
	{
		move CallB to Store_B_elevator
		MovePlayer(Store_B_elevator)
	}
	
	long_desc
		"Go SOUTHWEST to the elevator, or EAST to the escalator."
}

! Second Floor
room Store_2_elevator "Second Floor elevator waiting area"
{

	NE_to Store_2_06  ! Unimportant location for this demo
	IN_to			
	{
		if (location=parent(elevator_object))
		{
			moveplayer(elevator)
		} else {
			print "The elevator isn't here."
		}
	}
	
	long_desc
	{
		if location ~= parent(elevator_object)
			print	"Press CALL button to call for the elevator.\n
				Go ";
		else
			print "Go IN to enter elevator, or ";
		print "NORTHEAST to Department 6."
	}
}
room Store_2_06 "Second Floor Department 6."
{
	
	E_to		Store_2_escalator  ! Unimportant location for this demo
	SW_to		
	{
		move CallB to Store_2_elevator
		MovePlayer(Store_2_elevator)
	}
	
	long_desc
		"Go SOUTHWEST to the elevator, or EAST to the escalators."
}

!! additional floors as needed

I use an object as the elevator cage in order to have one room as the elevator, which appears to move as the elevator does. If the user uses the escalator to go to a floor where the elevator isn't there, then they PUSH CALL to call for the elevator. Doing that when it is there doesn't do anything.

I have the room before the elevator - as well as the elevator itself when moved - move the call button to the elevator waiting area of the floor where the user is at. This way there only needs to be one call button.
Alan Francis wrote a book containing everything men understand about women. It consisted of 100 blank pages.

Roody_Yogurt
Posts: 2179
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

I forgot I did my own elevator implementation over at the IF Wiki as a Hugo coding example. My elevator behavior is modeled after the elevator in Infocom's The Lurking Horror:
http://ifwiki.org/index.php/Elevator_an ... example%29

Post Reply