上一种是一个room生成迷宫,下面要说的是多个room生成迷宫
//2>多个room生成迷宫
//modified by hyee
//将指定的一个房间目录连成一个圆周,并随机取两个房间连接出入口。
//must define:
//要变的房间目录home
//string home=house+"/dynamic/"
//出入口(entry and exit)的file_name
//string entry=house+"/yongdao3"
//string exit=house+"/hall"
//string *add_room:house以外的room
//default:add_room=({});
//string *add_obj:要在里面放入的obj的base_name集
//add_obj=({});
/*
eg:
//ddd.c
#include SILENT
void create()
{
seteuid(getuid());
home=HYEE("room/chzhuang/dynamic/");
entry=HYEE("room/chzhuang/yongdao3");
exit=HYEE("room/chzhuang/hall");
add_obj=({HYEE("center/killer/dizi")});
call_out("r_map",1);
return;
}
*/
int i,j,size;
string *dyna_room,dir1,rev_dir1,*dirs,*rev_dirs,home,entry,exit;
object *room_object,cur_room,room;
mixed *room_list,*add_room=({}),*add_obj=({});
private int r_map();
private int r_map()
{
object *inv;
string *di,*rd;
remove_call_out("r_map");
//call_out("r_map",3600); // regenerate map every 30 mins.
// CHANNEL_D->do_channel( this_object(), "sys",
// "动态地图已经启动。\n");
room_list = get_dir(home+"*.c");
for(i=0;i<sizeof(room_list);i++)
room_list[i] = home+room_list[i];
add_room-=({0});
if(!sizeof(add_room))
add_room=({});
room_list += add_room;
dyna_room = ({});
while(sizeof(room_list))
{
j = random(sizeof(room_list));
if(!objectp(room=load_object(room_list[j]))
||!inherits(ROOM,room))
{
room_list-=({room_list[j]});
continue;
}
dyna_room += ({room_list[j]});
room_list -= ({room_list[j]});
}
//随机分配位置完毕
//hyee remodified,太复杂了反而不好.
//CHANNEL_D->do_channel(this_object(),
//"sys","开始重新生成地图。\n");
size = sizeof(dyna_room);
room_object = ({});
for(i=0;i<size;i++)
{
if( !(cur_room = find_object(dyna_room[i])) )
cur_room = load_object(dyna_room[i]);
inv=all_inventory(cur_room);
if(sizeof(inv))
for(j=0;j<sizeof(inv);j++)
{
if(!clonep(inv[j]))
continue;
if(userp(inv[j]))
continue;
if(!random(2))
reload_object(inv[j]);
else destruct(inv[j]);
}
else if(!random(2)&&sizeof(add_obj)) {
j=random(sizeof(add_obj));
if(objectp(new(add_obj[j])))
new(add_obj[j])->move(cur_room);
}
cur_room->delete("exits");
cur_room->delete("blocks");
cur_room->set("no_clean_up",1);
room_object += ({cur_room});
tell_room(cur_room,HIY
"\n 突然黄沙狂卷,大地强烈地震动着,发出隆隆的巨响,\n"
" 顿时一阵天旋地转...\n\n"NOR);
}
dirs = ({ "north","northeast","northwest","south",
"southwest","southeast","east","west",
"up","down","enter","out",
"northup","northdown","eastup","eastdown",
"westup","westdown","southup","southdown",
});
rev_dirs = ({ "south","southwest","southeast","north",
"northeast","northwest","west","east",
"down","up","out","enter",
"southdown","southup","westdown","westup",
"eastdown","eastup","northdown","northup",
});
di=dirs;
rd=rev_dirs;
//开始生成路径
for(i=0;i<size;i++)
{
j= random(sizeof(di));
dir1 = di[j];
rev_dir1 = rd[j];
di=dirs;
rd=rev_dirs;
di-=({rev_dir1});
rd-=({dir1});
if(i>0)
{
(room_object[i])->set("exits/"+dir1,dyna_room[i-1]);
(room_object[i-1])->set("exits/"+rev_dir1,dyna_room[i]);
}
else {
(room_object[0])->set("exits/across",dyna_room[size-1]);
(room_object[size-1])->set("exits/across",dyna_room[0]);
}
tell_room(room_object[i],HIW
" ...终于声止尘定,你发现一切都已经变了...\n"NOR);
}
j=random(sizeof(room_object));
room=load_object(entry);
room->set("exits/in",dyna_room[j]);
(room_object[j])->set("exits/comeout",entry);
j=random(sizeof(room_object));
room=load_object(exit);
room->set("exits/in",dyna_room[j]);
(room_object[j])->set("exits/comeout",exit);
return 1;
}
尊重作者 转载请注明出处52mud.com