Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Rehcra
Novice


Joined: 10 Oct 2000
Posts: 43

PostPosted: Thu Dec 21, 2000 6:27 pm   

Renumber Rooms
 
At one point I had 10,000+ rooms mapped on my mud, split into 50+ zones. On this PK mud the pauses when crossing zones was not working for me. So I merged them all into one zone and life was better. Only now I had 9+ rooms all with vnum 1, and the same with over 750 other vnum's. This broke some scripts, and made for some other problems. Renumbering by hand was out of the question.
The following script ran for about 10 minutes and solved my problems, giving each room a unique vnum. The mapper must be open and it goes much faster if the mapper is in 'off' mode. Always backup your map first.

#ALIAS renumrooms {
#var room 1
#var renum 30000
#t+ Scanning
#say Stage 1
#while (@room <30000) {
#while (%len( %roomname( @room))>0) {
#math renum {%roomnum( @room, @renum)+1}
#say @renum
#if (!%trigger( scanning)) {#abort 1}
}
#add room 1
}
#var room 30000
#var renum 1
#say Stage 2
#while (@room <60000) {
#while (%len( %roomname( @room))>0) {
#math renum {%roomnum( @room, @renum)+1}
#say @room
#if (!%trigger( scanning)) {#abort 1}
}
#add room 1
}
#unvar room
#unvar renum
#say Done!
}

I have a class 'Scanning' which is normally enabled. To provide myself a way to stop this during testing, I made it so if I #t- scanning, disabling the class, the script would abort. Please create a class Scanning, or change the three occurances of 'Scanning' above to one of your own classes.

Hope this helps.
Rehcra
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Fri Dec 22, 2000 1:33 am   
 
This forum is for finished scripts. Please repost this on the General Discussion Forum.


Darmir
Reply with quote
Rehcra
Novice


Joined: 10 Oct 2000
Posts: 43

PostPosted: Fri Dec 22, 2000 2:07 am   
 
Um.. Isn't this a finished script? It runs correctly as it is, for me. It has a purpose, which meets a need I had, and other people probably do as well. And I didn't even ask a single question... :)
Reply with quote
Leto
GURU


Joined: 27 Sep 2000
Posts: 90
Location: USA

PostPosted: Fri Dec 22, 2000 3:54 am   
 
I agree, Rehcra. It is a very nice script. Handy to have in any toolbox.

[url="mailto:RCLapointe@Hotmail.com"][/url]
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Fri Dec 22, 2000 6:00 pm   
 
My mistake I misread the post. I apologize.


Darmir
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Sat Jul 20, 2002 10:07 am   
 
Just updating this script with the times...

From zMUD 6.09 (when the %mapvnum function was added) onward, you can simply do this:

#loop 1,%numrooms() {#noop %roomnum(%mapvnum(%i),%i)}

Contrasting with the original, this script doesn't use any variables or string/number manipulation and only has to go through the main loop %numrooms() times as opposed to 60,000. Like the original, however, it is much faster in Offline mode than not.

This script isn't entirely intuitive, so I will endeavor to prove that it will work in all cases (warning: not for the mathematically faint-hearted).

%roomnum accepts as its first argument a vnum but when multiple rooms in a zone have the same vnum, it will pick the one with the lower absolute room number. So the #noop %roomnum(%mapvnum(%i),%i) in the body of the loop may not always modify the vnum of the room with absolute room number %i. It will modify the room with the lowest absolute number which has the same vnum as absolute room %i. This little quirk is why I've decided to prove my script will work.

The means of my proof shall be the Principal of Mathematical Induction. For those not familiar with it, it says that if you can prove a proposition is true for the n=1 and also that the proposition is true for the n=k+1 case if you assume that the n=k case is true, then it is true for all n=1, 2, ... (because the n=1 case is true which implies the n=2 case which implies the n=3 case and so on).

The proposition in this case shall be that after n iterations of the loop above, the vnums of the first n rooms (that is, the rooms with absolute numbers 1 through n) shall constitute an ordering of the numbers 1 through n.

This is clear in the first case; after you go through the loop the first time you set the vnum of absolute room 1 to 1. The number one alone is clearly an ordering of the numbers 1 to 1 (in fact, the only possible one).

Now, let us assume that the proposition is true for n=k. That is, after k times through the loop, the vnums of the k rooms with absolute numbers 1 through k are an ordering of the numbers 1 through k.

What happens if we go through the loop again? Well, there are two cases:

Case 1: %mapvnum(k+1) is not a number between 1 and k, inclusive.
In this case, the loop will just set the vnum of absolute room k+1 to k+1 and the vnums of the rooms with absolute numbers 1 through k+1 are an ordering of the numbers 1 through k+1, just as we wanted to show.

Case 2: %mapvnum(k+1) _is_ between 1 and k, inclusive.
This case implies that absolute room k+1 shares a vnum with some room with an absolute room number in the range 1 to k. Without loss of generality, we denote the absolute number of the room with which it shares a vnum by x. Since absolute rooms x and k+1 share the same vnum, both the set of vnums of rooms with absolute number 1 through k and the set of vnums of rooms with absolute number 1 through k+1 barring x contain each number 1 through k exactly once and are therefore both orderings of the the numbers 1 through k. Because of the way %roomnum works, #noop %roomnum(%mapvnum(k+1),k+1) is equivalent to #noop %roomnum(%mapvnum(x),k+1) and sets the vnum of absolute room x to k+1. Since the vnums of absolute rooms 1 through k+1 barring x was an ordering of 1 through k, adding absolute room x (with vnum k+1) back into the mix gives us that the vnums of absolute rooms 1 through k+1 are an ordering of 1 through k+1, again what we wanted to show.

By the principle of mathematical induction, this algorithm will produce unique vnums 1 through n for all the n rooms in any zone, assuming n is finite.

You'll need something else for those zones of infinite size (that is, once you get them mapped :P)

A related (and much easier to understand) algorithm will actually ensure that your vnums are identical to your absolute room numbers:

#loop 1,%numrooms() {#noop %roomnum(%mapvnum(%i),%numrooms())}
#loop 1,%numrooms()-1 {#noop %roomnum(%numrooms(),%i)}

Of course, that takes 2*%numrooms()-1 iterations... and can lead to some sloppy coding because you won't necessarily make a distinction between absolute room numbers and vnums in your code, possibly leading to problems if you try to distribute your scripts to people with other maps.


 - Charbal
Reply with quote
Carabas
GURU


Joined: 28 Sep 2000
Posts: 434
Location: USA

PostPosted: Sun Jul 21, 2002 5:52 am   
 
Is it just me, or does that need to be read more than once?

Perhaps a "Wow" is in order here. Good job, Charbal.


Carabas
------
I like work; it fascinates me. I can sit and look at it for hours.
- Jerome K. Jerome
Reply with quote
Rehcra
Novice


Joined: 10 Oct 2000
Posts: 43

PostPosted: Mon Jul 22, 2002 4:24 pm   
 
Bravo.

I never liked that script anyway. It always seems like a bloated kludge.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net