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
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 22, 2002 3:36 am   

Automapper AutoLink
 
Nifty little class to automatically join those nasty map sections that you snaked through and know line up perfectly.

Of note it isn't very smart so if you had to tweak the spacing at all don't use on that portion of your map.

#CLASS {AutoLink}
#ALIAS SetRange {#IF (%roomnum(%1)=%null) {#ECHO Must specify a valid start room.} { #IF (%roomnum(%2)=%null) {#ECHO Must specify a valid end room.} {RangeData="";#IF (%1<%2) {#ADDKEY RangeData Low %1;#ADDKEY RangeData High %2} {#ADDKEY RangeData Low %2;#ADDKEY RangeData High %1};RoomChecking="";#LOOP %db(@RangeData,Low),%db(@RangeData,High) {#IF (%roomnum(%i)!=%null) {#ADDKEY RangeData %i %roomexit(%i);#ADDITEM RoomChecking %i}}}}}
#ALIAS CalculateSpatial {#IF (%null(@RangeData)) {#ECHO RangeData not set please use SetRange first.} {Xpos=0;Ypos=0;Zpos=0;Spatial="";#ADDKEY Spatial %concat(@Xpos,"|",@Ypos,"|",@Zpos) %item(@RoomChecking,1);#WHILE (@RoomChecking) {RoomPos=0;#LOOPDB @Spatial { #IF (%val=%item(@RoomChecking,1)) {RoomPos=1;Xpos=%item(%key,1);Ypos=%item(%key,2);Zpos=%item(%key,3)}};#IF (@RoomPos) {#FORALL %db(@RangeData,%item(@RoomChecking,1)) { #IF (%db(@RangeData,%roomlink(%item(@RoomChecking,1),%i))!=%null) { #ADDKEY Spatial @Relative(%i) %roomlink(%item(@RoomChecking,1),%i)}};#DELNITEM RoomChecking 1} {RoomPos=%item(@RoomChecking,1);#DELNITEM RoomChecking 1;#ADDITEM RoomChecking @RoomPos}}}}
#ALIAS FixLinks {#IF (@Spatial=%null) {#ECHO Must run CalculateSpacial first.} {#LOOPDB @Spatial {Xpos=%item(%key,1);Ypos=%item(%key,2);Zpos=%item(%key,3);RoomPos=%val;#FORALL %db(@RangeData,%val) { #IF (%roomlink(@RoomPos,%i)=-2) { #IF (%db(@Spatial,@Relative(%i))!=%null) {#NOOP %roomlink(@RoomPos,%i,%db(@Spatial,@Relative(%i)))}}}};RangeData="";Spatial=""}}
#VAR RangeData {} {}
#VAR Spatial {} {}
#VAR Zpos {0} {0}
#VAR Ypos {0} {0}
#VAR Xpos {0} {0}
#VAR RoomChecking {} {}
#VAR RoomPos {0} {0}
#VAR Relative {%if(%1=n,%concat(@Xpos,"|",%eval(@Ypos-1),"|",@Zpos),%if(%1=s,%concat(@Xpos,"|",%eval(@Ypos+1),"|",@Zpos),%if(%1=w,%concat(%eval(@Xpos-1),"|",@Ypos,"|",@Zpos),%if(%1=e,%concat(%eval(@Xpos+1),"|",@Ypos,"|",@Zpos),%if(%1=nw,%concat(%eval(@Xpos-1),"|",%eval(@Ypos-1),"|",@Zpos),%if(%1=sw,%concat(%eval(@Xpos-1),"|",%eval(@Ypos+1),"|",@Zpos),%if(%1=ne,%concat(%eval(@Xpos+1),"|",%eval(@Ypos-1),"|",@Zpos),%if(%1=se,%concat(%eval(@Xpos+1),"|",%eval(@Ypos+1),"|",@Zpos),%if(%1=u,%concat(@Xpos,"|",@Ypos,"|",%eval(@Zpos-1)),%if(%1=d,%concat(@Xpos,"|",@Ypos,"|",%eval(@Zpos+1)),%null))))))))))}
#CLASS 0

Usage is simple find the low and high room numbers for the section you want it to work on, if some room number in that range is associated with a room very far away on the map then the behavior is undefined (read I never tested that most likely will cause infinite loop). You then use those numbers as arguments with SetRange. So long as both point to valid room it will make note of all rooms within that range. Then use CalculateSpatial to build an X,Y,Z coordinate list of those rooms and finally FixLinks attaches all the links to the room that they line up with.

The aliases were kept seperate because it is conciveiable that each might be a little slow and you might not want to devote that much time to do everything just then.

Tested in offline mode.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 22, 2002 4:41 pm   
 
Had a few minor bugs in that post, like forgetting to change Relative from VAR to FUNC, but since I had to track that down I also added a number of improvements. New version.

#CLASS {AutoLink}
#ALIAS SetRange {#IF (%trigger(AutoMapperAll)=0) {#ECHO Map must be active and in map mode.} {#IF (%trigger(AutoMapper)=0) {#ECHO Mapper Switched to Map Mode.;#MENU {Mapper|File|Map Creation Mode}};#IF (%roomnum(%1)=%null) {#ECHO Must specify a valid start room.} {#IF (%roomnum(%2)=%null) {#ECHO Must specify a valid end room.} {RangeData="";#IF (%1<%2) {#ADDKEY RangeData Low %1;#ADDKEY RangeData High %2} {#ADDKEY RangeData Low %2;#ADDKEY RangeData High %1};RoomChecking="";#LOOP %db(@RangeData,Low),%db(@RangeData,High) {#IF (%roomnum(%i)!=%null) {#ADDKEY RangeData %i %roomexit(%i);#ADDKEY RangeData %concat(%i,"PC") 0;#ADDITEM RoomChecking %i;#NOOP %roomcol(%i,%bitnot(%roomcol(%i)))}};#ECHO Ranges set.}}}}
#ALIAS CalculateSpatial {#IF (%trigger( AutoMapperAll)=0) {#ECHO Map must be active and in map mode.} {#IF (%trigger( AutoMapper)=0) {#ECHO Mapper Switched to Map Mode.;#MENU {Mapper|File|Map Creation Mode}};#IF (%null( @RangeData)) {#ECHO RangeData not set please use SetRange first.} {Xpos=0;Ypos=0;Zpos=0;Spatial="";#ADDKEY Spatial %concat( @Xpos, " ", @Ypos, " ", @Zpos) %item( @RoomChecking, 1);#WHILE (@RoomChecking) {RoomPos=0;#LOOPDB @Spatial { #IF (%val=%item( @RoomChecking, 1)) {RoomPos=1;Xpos=%word( %key, 1);Ypos=%word( %key, 2);Zpos=%word( %key, 3)}};#IF (@RoomPos) {#FORALL %db( @RangeData, %item( @RoomChecking, 1)) {#IF ((%db( @RangeData, %roomlink( %item( @RoomChecking, 1), %i))!=%null)&(%db( @RangeData, %roomlink( %item( @RoomChecking, 1), @ConvertDiag(%i)))!=%item(@RoomChecking,1))) { #ADDKEY Spatial @Relative( %i) %roomlink( %item( @RoomChecking, 1), @ConvertDiag(%i))}};#DELNITEM RoomChecking 1;#NOOP %roomcol( %i, %bitnot( %roomcol( %i)))} {RoomPos=%item( @RoomChecking, 1);#DELNITEM RoomChecking 1;#ADDITEM RoomChecking @RoomPos;#IF (%db( @RangeData, %concat( @RoomPos, "PC"))>10) {#ECHO Spatial calculations failed! Room @RoomPos has been attempted to fit more then 10 times.;#FORALL @RoomChecking {#NOOP %roomcol( %i, %bitnot( %roomcol( %i)))};RoomChecking=""} { #ADDKEY RangeData %concat( @RoomPos, "PC") %eval( %db( @RangeData, %concat( @RoomPos, "PC"))+1)}}}}}}
#ALIAS FixLinks {#IF (%trigger(AutoMapperAll)=0) {#ECHO Map must be active and in map mode.} {#IF (%trigger(AutoMapper)=0) {#ECHO Mapper Switched to Map Mode.;#MENU {Mapper|File|Map Creation Mode}};#IF (@Spatial=%null) {#ECHO Must run CalculateSpacial first.} {#LOOPDB @Spatial {Xpos=%word(%key,1);Ypos=%word(%key,2);Zpos=%word(%key,3);RoomPos=%val;#FORALL %db(@RangeData,%val) { #IF (%roomlink(@RoomPos,@ConvertDiag(%i))=-2) { #IF (%roomlink(%db(@Spatial,@Relative(%i)),@ConvertDiag(@Inverse(%i)))=-2) {#NOOP %roomlink(@RoomPos,@ConvertDiag(%i),%db(@Spatial,@Relative(%i)))} {#ECHO Room: @RoomPos Dir: @ConverDiag(%i) did not have a matching unknown link in room %db(@Spatial,@Relative(%i))}}}};RangeData="";Spatial=""}}}
#VAR RangeData {} {}
#VAR Spatial {} {}
#VAR Zpos {0} {0}
#VAR Ypos {0} {0}
#VAR Xpos {0} {0}
#VAR RoomChecking {} {}
#VAR RoomPos {0} {0}
#FU Relative {%if(%1=n,%concat(@Xpos," ",%eval(@Ypos-1)," ",@Zpos),%if(%1=s,%concat(@Xpos," ",%eval(@Ypos+1)," ",@Zpos),%if(%1=w,%concat(%eval(@Xpos-1)," ",@Ypos," ",@Zpos),%if(%1=e,%concat(%eval(@Xpos+1)," ",@Ypos," ",@Zpos),%if(%1=h,%concat(%eval(@Xpos-1)," ",%eval(@Ypos-1)," ",@Zpos),%if(%1=k,%concat(%eval(@Xpos-1)," ",%eval(@Ypos+1)," ",@Zpos),%if(%1=j,%concat(%eval(@Xpos+1)," ",%eval(@Ypos-1)," ",@Zpos),%if(%1=l,%concat(%eval(@Xpos+1)," ",%eval(@Ypos+1)," ",@Zpos),%if(%1=u,%concat(@Xpos," ",@Ypos," ",%eval(@Zpos-1)),%if(%1=d,%concat(@Xpos," ",@Ypos," ",%eval(@Zpos+1)),%null))))))))))}
#FU Inverse {%if(%1=n,s,%if(%1=s,n,%if(%1=e,w,%if(%1=w,e,%if(%1=h,l,%if(%1=l,h,%if(%1=j,k,%if(%1=k,j,%if(%1=u,d,%if(%1=d,u,%null))))))))))}
#FU ConvertDiag {%if(%1="h",nw,%if(%1="j",ne,%if(%1="k",sw,%if(%1="l",se,%1))))}
#CLASS 0

EDITTED: Added ConvertDiag Function after some beta questions regarding %roomlink and its workability with diagonals.
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