dsI/bin/
dsI/extra/creremote/
dsI/extra/mingw/
dsI/extra/wolfpaw/
dsI/fluffos-2.7-ds2.018/
dsI/fluffos-2.7-ds2.018/ChangeLog.old/
dsI/fluffos-2.7-ds2.018/Win32/
dsI/fluffos-2.7-ds2.018/compat/
dsI/fluffos-2.7-ds2.018/compat/simuls/
dsI/fluffos-2.7-ds2.018/testsuite/
dsI/fluffos-2.7-ds2.018/testsuite/clone/
dsI/fluffos-2.7-ds2.018/testsuite/command/
dsI/fluffos-2.7-ds2.018/testsuite/data/
dsI/fluffos-2.7-ds2.018/testsuite/etc/
dsI/fluffos-2.7-ds2.018/testsuite/include/
dsI/fluffos-2.7-ds2.018/testsuite/inherit/
dsI/fluffos-2.7-ds2.018/testsuite/inherit/master/
dsI/fluffos-2.7-ds2.018/testsuite/log/
dsI/fluffos-2.7-ds2.018/testsuite/single/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/compiler/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/efuns/
dsI/fluffos-2.7-ds2.018/testsuite/single/tests/operators/
dsI/fluffos-2.7-ds2.018/testsuite/u/
dsI/fluffos-2.7-ds2.018/tmp/
dsI/lib/cfg/
dsI/lib/cmds/common/
dsI/lib/cmds/creators/include/
dsI/lib/cmds/creators/include/SCCS/
dsI/lib/daemon/services/
dsI/lib/doc/
dsI/lib/domains/Ylsrim/
dsI/lib/domains/Ylsrim/adm/
dsI/lib/domains/Ylsrim/armour/
dsI/lib/domains/Ylsrim/broken/
dsI/lib/domains/Ylsrim/fish/
dsI/lib/domains/Ylsrim/meal/
dsI/lib/domains/Ylsrim/npc/
dsI/lib/domains/Ylsrim/virtual/
dsI/lib/domains/Ylsrim/weapon/
dsI/lib/domains/default/creator/
dsI/lib/domains/default/etc/
dsI/lib/domains/default/room/
dsI/lib/lib/comp/
dsI/lib/lib/lvs/
dsI/lib/lib/user/
dsI/lib/lib/virtual/
dsI/lib/obj/
dsI/lib/obj/include/
dsI/lib/realms/
dsI/lib/save/kills/a/
dsI/lib/save/kills/b/
dsI/lib/save/kills/f/
dsI/lib/save/kills/m/
dsI/lib/save/kills/q/
dsI/lib/save/kills/r/
dsI/lib/secure/cfg/
dsI/lib/secure/cfg/classes/
dsI/lib/secure/cfg/races/SCCS/
dsI/lib/secure/cmds/creators/include/
dsI/lib/secure/cmds/players/
dsI/lib/secure/cmds/players/include/
dsI/lib/secure/daemon/include/
dsI/lib/secure/lib/
dsI/lib/secure/lib/include/
dsI/lib/secure/lib/net/
dsI/lib/secure/lib/net/include/
dsI/lib/secure/lib/std/
dsI/lib/secure/obj/
dsI/lib/secure/obj/include/
dsI/lib/secure/save/
dsI/lib/spells/
dsI/lib/verbs/admins/include/
dsI/lib/verbs/common/
dsI/lib/verbs/common/include/
dsI/lib/verbs/creators/
dsI/lib/verbs/creators/include/
dsI/lib/verbs/players/include/SCCS/
dsI/lib/verbs/rooms/
dsI/lib/verbs/rooms/include/
dsI/lib/www/
dsI/v22.2b14/
dsI/win32/
/*    /lib/virtual/virt_map.c
 *    From DeadSouls Object Library
 *    Provides a map for map based virtual rooms
 *    Created by Dvarsk 980310
 *    Version: @(#) virt_map.c 1.3@(#)
 *    Last modified: 98/08/25
 */      

#include <lib.h>

inherit LIB_DAEMON;

private mapping Location=([]);
private mixed AreaMap;
private string Virt_Room= "";

/******************* virt_map.c required overrides ************/

varargs string array BaseMap(){ //override with actual map
	return 
		({
	//   0
    	//   012
          ({"000",//0
    	    "010",//1
      	    "000",//2
      	    })});
}

/******************* virt_map.c attributes ********************/

int *GetLocations(string str){return Location[str]; }

varargs mixed GetAreaMap(int x, int y, int z){ 
	if(nullp(x) || nullp(y) || nullp(z)) return copy(AreaMap);
	if(	   x<0 
		|| y<0 
		|| z<0
		|| z>sizeof(AreaMap)
		|| y>sizeof(AreaMap[0])
		|| x>sizeof(AreaMap[0][0]))
			return "0";
	return copy(AreaMap[z][y][x..x]);

}

varargs mixed SetAreaMap(int y,int x ,int z, string str){
	if(nullp(x)||nullp(y)||nullp(z)){
		string x_line="";
	    string * y_line=({});
		AreaMap=BaseMap();
		z=sizeof(AreaMap);
		y=sizeof(AreaMap[0]);
		x=sizeof(AreaMap[0][0]);
		while (x --) x_line += "0";
		while (y --) y_line += ({x_line});
		return AreaMap = ({y_line}) +AreaMap + ({y_line});
	}
	else return AreaMap[z][y][x..x]=str;
}

int SetVirtFile( string file){
    string str;
    if( str = catch(call_other(file, "???")) ) {
		if( creatorp() ) message("error", str, previous_object());
                return 0;
	}
	Virt_Room=file+"/";
	SetAreaMap();
	return 1;
}

/******************* virt_map.c events ************************/

int * RecurseLocations(){
	mixed map=GetAreaMap();
	int *locat;
	int z=random(sizeof(map)-2)+1;
	int y=random(sizeof(map[z]));
	int x=random(sizeof(map[z][y]));

	if(map[z][y][x..x]!="1") 
        return RecurseLocations(); // Is it within the general land?
	foreach(string tmp in keys(Location)){ //Is something else here?
		locat=Location[tmp];
		if(locat[0]==x && locat[1]==y && locat[2]==z) 
            return RecurseLocations(); 
	}
	return ({x,y,z});
}

varargs void InitializeLocations(string tmp){
	if(!nullp(tmp)){
		if(!Location[tmp][0] && !Location[tmp][1] 
            && !Location[tmp][2])
			Location[tmp]=RecurseLocations(); 
		SetAreaMap(Location[tmp][1], Location[tmp][0], 
            Location[tmp][2], tmp);
		(Virt_Room+(Location[tmp][0] ) + "," 
            + (Location[tmp][1]) + ","
			+ (Location[tmp][2]))->ResetLocation();
    }
    else foreach(tmp in keys(Location)){
        Location[tmp]=RecurseLocations();
        SetAreaMap(Location[tmp][1], Location[tmp][0],
            Location[tmp][2], tmp);
		(Virt_Room+(Location[tmp][0] ) + "," + (Location[tmp][1])
            + "," +(Location[tmp][2]))->ResetLocation(); 
	}

}

// call this if all the locations randomly move around
void SwitchLocations(){
	int * old_location;
	mixed areas=BaseMap();

	foreach(string tmp in keys(Location)){
		if(Location[tmp][3]) continue;
		old_location=copy(Location[tmp]);
		Location[tmp]=({0,0,0}); 
		SetAreaMap(old_location[1], old_location[0], 
            old_location[2], areas[(old_location[2]-1)]
            [old_location[1]][old_location[0]..old_location[0]]);
		Location[tmp]=RecurseLocations();
		(Virt_Room + (old_location[0]) + ","
			+ (old_location[1]) + "," 
            + (old_location[2]))->ResetLocation();
		SetAreaMap(Location[tmp][1], Location[tmp][0],
            old_location[2], tmp);
		(Virt_Room + (Location[tmp][0] ) + ","
			+ (Location[tmp][1]) + "," 
            + (old_location[2]))->ResetLocation();

	}
}

/******************* virt_map.c driver applies ****************/

varargs static void create(string virt_file) {
    daemon::create();
    SetNoClean(1);
    if(!nullp(virt_file)) SetVirtFile(virt_file);
    else SetVirtFile(base_name(this_object()));
}

/******************* virt_map.c optional settings *************/

// AddLocation(string str, int array where)
// string = unique identifier
// where==({0,0,0}) will randomly place the location

int AddLocation(string str, int array where){ 
	if(!nullp(Location[str])) return 0;
	Location[str]=where; 
	InitializeLocations(str);
	return 1;
}

int RemoveLocation(string str){ 
	int * location=Location[str];
	mixed areas=BaseMap();
	if(nullp(location)) return 0;
	SetAreaMap(location[1],location[0],location[2],
			areas[(location[2]-1)][location[1]]
            [location[0]..location[0]]);
	(Virt_Room + (location[0] ) + ","
			+ (location[1]) + "," 
            + (location[2]))->ResetLocation();
	map_delete(Location,str);
	return 1;
}