Special exits as normal exits

Post Reply
Tagon
Posts: 24
Joined: Thu Sep 19, 2013 8:38 pm

Special exits as normal exits

Post by Tagon » Thu Sep 26, 2013 11:38 am

Okay, next roadblock in my quest...

I haven't had chance to test this code yet so I'm more asking if I'm doing this the hard way or if there's a better way to achieve the same aim. The plan is to have special exits (e.g. "leap through window") to be activated by a standard numpad direction. The reason being, I want to be able to numpad all over the map, into camps, towns, quest areas etc without typing out the special commands (the fun is in working them out, not retyping them every time!). I'm also wary that this has to work with speed walking, otherwise I'm asking for trouble!

So imagine this scenario. A map with 2 rooms. Room 1 has a single exit "east" which takes you east to room 2. Room 2 has a single special exit "leap through window" which takes you west into room 1. In this scenario I want to be able to move between rooms 1 and 2 using just "east" and "west". I have intentions on removing "in" and "out" from the exitmap and making those into special exits too (which would solve the problem of where to position them).

Currently I'm doing the following in a function called by "sysDataSendRequest":
Code: [show] | [select all] lua
if shortdir[command]~=null then lastCommand=shortdir[command]
	else lastCommand=command end
	if mapStatus>0 and currentRoom~=0 then
		local tmp = getRoomExits(currentRoom)
		if tmp[lastCommand]~=null then --if exit exists
			currentRoom=tmp[lastCommand]
			currentArea=getRoomArea(currentRoom)
			centerview(currentRoom) --update location
		end
	end
shortdir is just a lookup table for "e"="east" etc
mapStatus is a series of levels (0 = ignore the map, 1 = follow on map, 2 = write map is appropriate)

Going back to the example my plan is to have 2 exits from room 2, both going to room 1. The first would be a special exit with the command "leap through window", the second would be a standard exit west and locked. I would then, after checking the exit exists, check if the exit is locked. If it's not locked, proceed as normal. If it's locked I would fetch the list of special exits from the current room and look for one with the same destination as the exit matching the command. I know, that's convoluted to write! Let me try to code it.. replace the code above with this:
Code: [show] | [select all] lua
if shortdir[command]~=null then lastCommand=shortdir[command]
	else lastCommand=command end
	if mapStatus>0 and currentRoom~=0 then
		local tmp = getRoomExits(currentRoom)
		if tmp[lastCommand]~=null then --if exit exists
			if hasExitLock(currentRoom,exitmap[lastCommand]) then
				tmp2 = getSpecialExits(currentRoom)
				if tmp2[tmp[lastCommand]]~=null then
					denyCurrentSend() --cancel the fake direction
					expandAlias(tmp2[tmp[lastCommand]],true) --send replacement command
					currentRoom=tmp[lastCommand]
					currentArea=getRoomArea(currentRoom)
					centerview(currentRoom) --update location
				else
					-- give in, you just can't go that way, accept it!
				end
			else
				currentRoom=tmp[lastCommand]
				currentArea=getRoomArea(currentRoom)
				centerview(currentRoom) --update location
			end
		end
	end
I'm fairly certain I could clean the logic up a bit more, and I plan to later, but for now what do you think? Can you see any potential pitfalls (other than me becoming mapper reliant to navigate, I can live with that)?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests