TADS Programming (4) - Vehicles Sent in by The Grue! This little bit on TADS will hopefully explain how to create a vehicle that the player can get in and travel to another location in your game. In this example the vehicle is a taxi-cab and the player will have to travel from outside his house to terminal B at the airport. This was written using the new TADS (v2.1); if using old TADS (v1.2), replace & with #. ***************************************** The first thing to do is create your cab. ***************************************** cab: fixeditem, vehicle sdesc = "black cab" noun = 'cab' 'car' 'auto' 'automobile' 'limo' 'taxi' adjective = 'black' isListed = true location = outsidehouse ****************************************************************** In the example the cab is already outside your house waiting but you could set it up to arrive after you had made a telephone call to the cab company. The next bit to add is the doBoard, this will allow the player to get in the cab. As the player gets into the cab, we will notify the cab's travel routine and change the cab's isListed status to nil, the reason we have to do this is so that when we are travelling in the cab the game doesn't say there is a black cab here, when the player is already in the cab. We also have to allow for if the player tries to get in the cab while he is already in the cab and if he tries to get in it once he has reached the terminal. ****************************************************************** verDoEnter( actor ) = { self.verDoBoard( actor ); } doEnter( actor ) = { self.doBoard( actor ); } verDoBoard(actor) = {} doBoard( actor ) = { if (self.location=outsidehouse) { "\bYou climb in the car and the driver starts the engine and heads for the airport. "; notify(cab, &travel, 0); self.isListed := nil; return(cab); } else if (self.location=termB) {"\"Hey! you haven't paid for the first ride.\"";return(termB);} else { "You are already in the cab.";} } ****************************************************************** Now we do the Unboard, again making sure the player can't get out of the cab while it is moving. We will handle the player getting out of the cab at the airport later on. Finally do the ldesc for the cab, one for when the player is in the cab and one when he is not. ****************************************************************** verDoUnboard(actor) = { "You can't get out of the car while it's moving!"; } ldesc = { if(Me.location = cab) "The rear of the car is comfortable without being lavish. "; else "It's just an ordinary black car with Capital Cars written on the door. "; } ****************************************************************** So now we have a cab that is outside your house that the player can get into. The next thing to do is the travel position and the list of places it will travel through on the way to the airport. The travel position always starts at one (the first location the cab will travel through). The travel list contains the names of the locations or rooms that the cab travels through. The travel name is the list of descriptions printed on screen before each of the cab's travel locations. What the player will see on the screen is something like this, 'The cab turns right on to Burscough St' and every move in the game the routine will pair up the next position from the travel list and the travel name to make the player travel the route inside the cab to the airport terminal. ****************************************************************** travelPos = 1 travelList = [burscst derbyst1 derbyst2 helensrd1 helensrd2 m581 m582 m61 m62 m561 m562 manchester1 manchester2 termB] travelName = ['turns right on to' 'turns left on to' 'continues on' 'turns left on to' 'continues on' 'turns off on to the' 'continues on the ' 'turns off on to the' 'continues on the' 'turns off the M6 on to the' 'continues on the' 'turns left off the motorway on to' 'continues on' 'turns right into'] ****************************************************************** This is the actual travel routine that we called with the NOTIFY (cab, &travel, 0) line earlier. What this routine does is firstly set the position of the cab to the first location on the travel position and travel list, and continues to move the cab and player along the travel position and travel list every time a move is made in the game by the player. Once the end of the travel position and travel list has been reached which is 14 locations/moves in this example but it could be longer or shorter, the cab will have reached terminal B of the airport. The first thing we must do is to UNNOTIFY the (cab, &travel) and then move the player automatically into Terminal B and then make the cab isListed = true again, so the player can see the cab is also there. If you wished you could just make the player get out of the cab and move the cab into nil and display a message saying something like, 'As you alight from the cab the driver quickly drives away, perhaps to pick up another passenger'. ****************************************************************** travel = { local pos, exitname; pos := self.travelPos; exitname := self.travelName[pos]; self.moveInto(self.travelList[pos]); Me.moveInto(self); "\bThe car <> <>.\b"; if (pos = 14) { unnotify(cab, &travel); "The driver holds open the passenger door for you as you get out of the cab.\b"; Me.moveInto(termB); cab.moveInto(termB); self.isListed:=true; return;} pos := pos+1; self.travelPos := pos; exit; } ****************************************************************** There is one problem with this at the moment and that is because the cab is a vehicle and thereby a nested room and the vehicle moves from one location to another every move. When the player drops an item inside the cab which is a nested room, the item falls into the outer room, which the player can never get back to since the cab moves once every move, hence the item is lost! (don't ya just luv playtesters!). Fortunately by adding these two lines under your main cab description this problem can be easily overcome. ****************************************************************** locationOK = true roomDrop (obj) = { "dropped.";obj.moveInto(self);} ****************************************************************** Now if we put all the code together it should look like this.... cab: fixeditem, vehicle sdesc = "black cab" noun = 'cab' 'car' 'auto' 'automobile' 'limo' 'taxi' adjective = 'black' isListed = true locationOK = true roomDrop (obj) = { "dropped.";obj.moveInto(self);} verDoEnter( actor ) = { self.verDoBoard( actor ); } doEnter( actor ) = { self.doBoard( actor ); } verDoBoard(actor) = {} doBoard( actor ) = { if (self.location=outsidehouse) { "\bYou climb in the car and the driver starts the engine and heads for the airport. "; notify(cab, &travel, 0); self.isListed := nil; return(cab); } else if (self.location=termB) {"\"Hey! you haven't paid for the first ride.\"";return(termB);} else { "You are already in the cab.";} } verDoUnboard(actor) = { "You can't get out of the car while it's moving!"; } ldesc = { if(Me.location = cab) "The rear of the car is comfortable without being lavish. "; else "It's just an ordinary black car with Capital Cars written on the door. "; } travelPos = 1 travelList = [burscst derbyst1 derbyst2 helensrd1 helensrd2 m581 m582 m61 m62 m561 m562 manchester1 manchester2 termB] TravelName = ['turns right on to' 'turns left on to' 'continues on' 'turns left on to' 'continues on' 'turns off on to the' 'continues on the ' 'turns off on to the' 'continues on the' 'turns off the M6 on to the' 'continues on the' 'turns left off the motorway on to' 'continues on' 'turns right into'] travel = { local pos, exitname; pos := self.travelPos; exitname := self.travelName[pos]; self.moveInto(self.travelList[pos]); Me.moveInto(self); "\bThe car <> <>.\b"; if (pos = 14) { unnotify(cab, &travel); "The driver holds open the passenger door for you as you get out of the cab.\b"; Me.moveInto(termB); cab.moveInto(termB); self.isListed:=true; return;} pos := pos+1; self.travelPos := pos; exit; } ; ****************************************************************** The only thing that is left to add are the locations or rooms that the cab will travel though. These are the ones listed in the travel list in the code. I'm sure this is not the shortest way to achieve the effect of a player travelling through various locations in a cab BUT it does work. It also allows you a lot of scope to build in other problems along the way. ****************************************************************** burscst: room sdesc = "Burscough St" ldesc = "You're travelling along Burscough St. The library is on your right." ; derbyst1: room sdesc = "Derby St" ldesc = "You're travelling along Derby St." ; derbyst2: room sdesc = "Derby St" ldesc = "You're travelling along Derby St." ; helensrd1 : room sdesc = "St Helens Rd" ldesc = "You're travelling along St Helens Rd. The old water tower is on your left." ; helensrd2 : room sdesc = "St Helens Rd" ldesc = "You're travelling along St Helens Rd and you've just past the Ormskirk car auctions." ; m581 : room sdesc = "M58" ldesc = "You're on the M58, the new town of Skemersdale is to your left." ; m582: room sdesc = "M58" ldesc = "You're nearing the end of the M58, approaching a large island where you join the M6." ; m61 : room sdesc = "M6" ldesc = "You're now travelling along the M6." ; m62: room sdesc = "M6" ldesc = "You're now travelling south on the M6, you've just past Haydock race course on your left." ; m561 : room sdesc = "M56" ldesc = "You're now on the M56." ; m562 : room sdesc = "M56" ldesc = "You're travelling on the M56 to Manchester Airport." ; manchester1: room sdesc = "Manchester Airport Drive" ldesc = "You're on Manchester Airport Drive." ; manchester2: room sdesc = "Manchester Airport Drive" ldesc = "You're on Manchester Airport Drive." ; termB: room sdesc = "Manchester International Airport, Terminal B Driveway" ldesc = "You're in the Terminal B driveway of the airport. Parking is to the south, and the entrance to the airport is to the north." south = {"There's no point in going there. ";return(nil);} ; - o -