Skip to content

Commit 97d6599

Browse files
committed
Replaced slowwalk/fastwalk settings with unified walkspeed option and added automatic area creation
Added: - New walkspeed setting with three modes (slow/normal/fast) replacing separate slowwalk/fastwalk options - Automatic area creation based on GMCP area information when mapping (autocreateareas setting) - mmp.roomArea function for moving rooms between areas - Support for cross-area exits with automatic area switching during mapping Changed: - Simplified walking speed logic by consolidating into single walkspeed setting - Modified makeroom function to accept optional target area ID for cross-area room creation - Improved error handling in speedwalking with nil checks Fixed: - Stopwatch error when failpath is called without timer initialization - Missing nil check for mmp.specials in stop function
1 parent 38212e5 commit 97d6599

File tree

7 files changed

+146
-41
lines changed

7 files changed

+146
-41
lines changed

src/scripts/GoMudMapper/core/load_settings.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function mmp.startup()
8585
options = "1-5"
8686
elseif opt == "echocolour" then
8787
options = "See mcolor for options"
88+
elseif opt == "walkspeed" then
89+
options = "slow|normal|fast"
8890
else
8991
options = tostring(displayValue)
9092
end

src/scripts/GoMudMapper/core/mconfig_settings_functions.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,5 @@ function mmp.changeMapSource()
7575
end
7676
end
7777

78-
function mmp.setSlowWalk()
79-
if mmp.settings.slowwalk then
80-
mmp.echo(
81-
"Will walk 'slowly' - that is, only try to move in a direction once per room, and move again once we've arrived. This will make us better walkers when it's very laggy, as we won't spam directions unnecessarily and miss certain turns - but it does mean that if we fail to move for some reason, we won't retry again either at all."
82-
)
83-
else
84-
mmp.echo("Will walk as quick as we can!")
85-
end
86-
end
8778

8879
-- GoMud-specific settings functions can be added here

src/scripts/GoMudMapper/core/option_definitions.lua

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ mmp.option_definitions = {
3636
onChange = mmp.changeLaglevel
3737
},
3838

39-
slowwalk = {
40-
default = false,
41-
type = "boolean",
42-
description = "Walk slowly instead of as quick as possible?",
43-
onChange = mmp.setSlowWalk
44-
},
45-
46-
fastwalk = {
47-
default = false,
48-
type = "boolean",
49-
description = "Walk as quick as possible instead of waiting for prompts?",
50-
onChange = mmp.changeBoolFunc
39+
walkspeed = {
40+
default = "normal",
41+
type = "string",
42+
description = "Walking speed (slow/normal/fast)?",
43+
validate = function(v)
44+
return v == "slow" or v == "normal" or v == "fast"
45+
end,
46+
onChange = function(name, value)
47+
if value == "slow" then
48+
mmp.echo("Walking speed set to slow - will pause between moves")
49+
elseif value == "fast" then
50+
mmp.echo("Walking speed set to fast - will move without waiting for prompts")
51+
else
52+
mmp.echo("Walking speed set to normal - will wait for prompts between moves")
53+
end
54+
end
5155
},
5256

5357
updatemap = {
@@ -100,6 +104,21 @@ mmp.option_definitions = {
100104
mmp.echo("Rooms will now be positioned using standard directional offsets (+1)")
101105
end
102106
end
107+
},
108+
109+
autocreateareas = {
110+
default = false,
111+
type = "boolean",
112+
description = "Auto create areas based on GMCP area information when mapping?",
113+
games = {"gomud"},
114+
onChange = function(name, option)
115+
mmp.changeBoolFunc(name, option)
116+
if option then
117+
mmp.echo("Areas will now be automatically created based on GMCP area information")
118+
else
119+
mmp.echo("Areas will need to be created manually")
120+
end
121+
end
103122
}
104123
}
105124

src/scripts/GoMudMapper/mapping/mmp.mappingnewroom.lua

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
--mmp.mappingNewroom
22

3-
local function makeroom(oldid, newid, x, y, z)
3+
local function makeroom(oldid, newid, x, y, z, targetAreaId)
44
assert(x and y and z, "makeroom: need all 3 coordinates")
55
addRoom(newid)
66
setRoomCoordinates(newid, x, y, z)
7-
setRoomArea(newid, getRoomArea(oldid))
7+
-- Use target area if provided, otherwise inherit from old room
8+
if targetAreaId then
9+
setRoomArea(newid, targetAreaId)
10+
else
11+
setRoomArea(newid, getRoomArea(oldid))
12+
end
813
local fgr, fgg, fgb = unpack(color_table.red)
914
local bgr, bgg, bgb = unpack(color_table.blue)
1015
highlightRoom(newid, fgr, fgg, fgb, bgr, bgg, bgb, 1, 100, 100)
@@ -236,14 +241,45 @@ function mmp.mappingnewroom(_, num)
236241
local newY = currentRoomY + (exitData.delta_y * -1)
237242
local newZ = currentRoomZ + exitData.delta_z
238243

239-
s = makeroom(num, id, newX, newY, newZ)
240-
setRoomUserData(id, "Area", currentRoomArea)
244+
-- Check if exit leads to a different area
245+
local targetAreaId = nil
246+
if mmp.settings.autocreateareas and exitData.details and exitData.details.leads_to_area then
247+
local targetAreaName = exitData.details.leads_to_area
248+
-- Try to create the area if it doesn't exist
249+
targetAreaId = mmp.areatable[targetAreaName]
250+
if not targetAreaId then
251+
targetAreaId = addAreaName(targetAreaName)
252+
if targetAreaId then
253+
mmp.echo(string.format("Created new area: %s (ID: %d)", targetAreaName, targetAreaId))
254+
mmp.regenerateareas()
255+
end
256+
end
257+
end
258+
259+
s = makeroom(num, id, newX, newY, newZ, targetAreaId)
260+
setRoomUserData(id, "Area", exitData.details and exitData.details.leads_to_area or currentRoomArea)
241261
else
242262
-- Use standard directional positioning (+1 in direction)
263+
-- Check if exit leads to a different area
264+
local targetAreaId = nil
265+
if mmp.settings.autocreateareas and exitData.details and exitData.details.leads_to_area then
266+
local targetAreaName = exitData.details.leads_to_area
267+
-- Try to create the area if it doesn't exist
268+
targetAreaId = mmp.areatable[targetAreaName]
269+
if not targetAreaId then
270+
targetAreaId = addAreaName(targetAreaName)
271+
if targetAreaId then
272+
mmp.echo(string.format("Created new area: %s (ID: %d)", targetAreaName, targetAreaId))
273+
mmp.regenerateareas()
274+
end
275+
end
276+
end
277+
243278
s = makeroom(
244279
num,
245280
id,
246-
getshiftedcoords(exit, getRoomCoordinates(num))
281+
getshiftedcoords(exit, getRoomCoordinates(num)),
282+
targetAreaId
247283
)
248284
end
249285
else
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function mmp.roomArea(otherroom, name, exact)
2+
local id, fname, ma
3+
if tonumber(name) then
4+
id = tonumber(name);
5+
fname = mmp.areatabler[id]
6+
else
7+
id, fname, ma = mmp.findAreaID(name, exact)
8+
end
9+
if otherroom ~= "" and not mmp.roomexists(otherroom) then
10+
mmp.echo("Room id " .. otherroom .. " doesn't seem to exist.")
11+
return
12+
elseif otherroom == "" and not mmp.roomexists(mmp.currentroom) then
13+
mmp.echo("Don't know where we are at the moment.")
14+
return
15+
end
16+
otherroom = otherroom ~= "" and otherroom or mmp.currentroom
17+
if id then
18+
setRoomArea(otherroom, id)
19+
mmp.echo(
20+
string.format(
21+
"Moved %s to %s (%d).",
22+
(getRoomName(otherroom) ~= "" and getRoomName(otherroom) or "''"),
23+
fname,
24+
id
25+
)
26+
)
27+
centerview(otherroom)
28+
elseif next(ma) then
29+
mmp.echo("Into which area exactly would you like to move the room?")
30+
fg("DimGrey")
31+
for _, name in ipairs(ma) do
32+
echo(" ")
33+
setUnderline(true)
34+
echoLink(
35+
name, [[mmp.roomArea('', "]] .. name .. [[", true)]], "Move the room to " .. name, true
36+
)
37+
setUnderline(false)
38+
echo("\n")
39+
end
40+
resetFormat()
41+
else
42+
mmp.echo("Don't know of that area.")
43+
end
44+
end

src/scripts/GoMudMapper/mapping/scripts.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,11 @@
6262
"eventHandlerList": ["sysExitEvent"],
6363
"script": "",
6464
"isFolder": "no"
65+
},
66+
{
67+
"name": "mmp.roomArea",
68+
"isActive": "yes",
69+
"script": "",
70+
"isFolder": "no"
6571
}
6672
]

src/scripts/GoMudMapper/navigation/mmp.speedwalking.lua

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,15 @@ function mmp.setmovetimer(time, ignoreLatency)
137137
if mmp.movetimer then
138138
killTimer(mmp.movetimer)
139139
end
140-
if mmp.settings.slowwalk and not mmp.hasty then
140+
-- Handle walk speed settings
141+
if mmp.settings.walkspeed == "slow" and not mmp.hasty then
141142
return
142-
end
143-
144-
-- Skip timer for fastwalk mode
145-
if mmp.settings.fastwalk then
143+
elseif mmp.settings.walkspeed == "fast" then
144+
-- Skip timer for fast mode
146145
return
147146
end
148147

149-
-- Normal timer logic for regular walking
148+
-- Normal timer logic for normal walking
150149
local laglevel = mmp.settings.laglevel or 1
151150
time = time or mmp.lagtable[laglevel].time
152151
local latency = ignoreLatency and 0 or getNetworkLatency()
@@ -189,9 +188,9 @@ function mmp.move()
189188
cmd = mmp.speedWalkDir[mmp.speedWalkCounter]
190189
end
191190
cmd = cmd or ""
192-
-- In fastwalk mode, don't set a timer - just send the command
191+
-- In fast mode, don't set a timer - just send the command
193192
-- The next GMCP room event will trigger the next move
194-
if not mmp.settings.fastwalk then
193+
if mmp.settings.walkspeed ~= "fast" then
195194
-- timeout before loadstring, so it can set its own if it would like to.
196195
mmp.setmovetimer()
197196
end
@@ -297,8 +296,10 @@ function mmp.stop()
297296
--if mmp.movetimer then killTimer( mmp.movetimer ) end
298297
mmp.autowalking = false
299298
-- clear all the temps we've got
300-
for trigger, ID in pairs(mmp.specials) do
301-
killTrigger(ID)
299+
if mmp.specials then
300+
for trigger, ID in pairs(mmp.specials) do
301+
killTrigger(ID)
302+
end
302303
end
303304
mmp.specials = {}
304305
mmp.echo("Stopped walking.")
@@ -536,7 +537,7 @@ function mmp.speedwalking(event, num)
536537
mmp.autowalking = false
537538
else
538539
-- For faster movement, call mmp.move directly instead of waiting for prompt
539-
if mmp.settings.fastwalk then
540+
if mmp.settings.walkspeed == "fast" then
540541
mmp.move()
541542
else
542543
tempPromptTrigger(mmp.move, 1)
@@ -608,8 +609,8 @@ function doSpeedWalk(dashtype)
608609
mmp.speedWalkCounter = 1
609610
if mmp.canmove() then
610611
mmp.hasty = true
611-
if mmp.settings.fastwalk then
612-
-- In fastwalk mode, send the first command immediately
612+
if mmp.settings.walkspeed == "fast" then
613+
-- In fast mode, send the first command immediately
613614
mmp.move()
614615
else
615616
mmp.setmovetimer(0.1, true)
@@ -623,9 +624,15 @@ function doSpeedWalk(dashtype)
623624
end
624625

625626
function mmp.failpath()
626-
if mmp.movetimer then
627+
if mmp.speedWalkWatch then
627628
local walktime = stopStopWatch(mmp.speedWalkWatch)
628-
mmp.echo(string.format("Can't continue further! Took us %.1fs to get here.\n", walktime))
629+
if walktime then
630+
mmp.echo(string.format("Can't continue further! Took us %.1fs to get here.\n", walktime))
631+
else
632+
mmp.echo("Can't continue further!")
633+
end
634+
else
635+
mmp.echo("Can't continue further!")
629636
end
630637
mmp.autowalking = false
631638
mmp.speedWalkPath = {}

0 commit comments

Comments
 (0)