개척 소스

2007.04.12 13:06

그리움 조회 수:302 추천:58

/*
이 함수는 제가 머드에 왕국 기능을 만들면서 사용자들이 자신의 왕국존을
개척하는데 있어 쉬운 방제작 명령어를 마련하기 위해 제작한 것입니다.
쓰다보니 존제작하는데도 편리해서 지금은 주로 개척 명령으로 방제작하고
있습니다. ^^;

사용 방법은 현재 위치에서
<만들어질출구이름> <되돌아올출구이름> 개척 또는,
<만들어질 출구이름> 개척
이라고 하시면 현재 자신이 있는 방번호부터 시작해서 방 화일이 존재않는
방번호를 검색하여 자동으로 그 번호로 방번호가 부여되며 출구도 자동으로
생성되게 해놓았습니다.

방번호는 현재위치의 방번호부터 시작하니, 다른 존제작들에게 각기 다른 방
번호를 배정해주고 하려면 r *방제작 으로 해당 방번호의 방을 만든 후 그곳
에서 개척명령으로 존제작을 해나가면 됩니다.

현재 제 머드에서는 주변 방들의 지도를 검색하여 방을 새로 만들것인지 아
니면 출구만 만들것인지를 판단하게 하고 개척되는 방향이 현재 지도에서 적
합한지를 검색하여 개척이 되게 하고 있으나 그런 보완책이 없다면 사용자들
에게 이 명령어를 열어놓는건 좀 위험하다고 생각합니다.

이 소스는 제 동의없이 상용머드에서 사용을 허락치 않습니다.
-- 우르
*/

/**********************************************************************/
/* settle 개척 */
/**********************************************************************/

int settle(ply_ptr, cmnd)
creature *ply_ptr;
cmd *cmnd;
{
       int fd, ff, iroom;
       char file[80];
       char tempstr[20];
       room *rom_ptr, *new_rom;

       fd = ply_ptr->fd;

       rom_ptr = ply_ptr->parent_rom;

       if(ply_ptr->class < DM)
               return(PROMPT);
/*
       if(ply_ptr->gold <5000000){
               print(fd, "집을 만드려면 돈이 있어야죠!\n");
               print(fd, "흥! 돈두 없으면서...\n");
               return(0);
       }
*/
       if(cmnd->num < 2 ) {
               print(fd, "어느쪽으로 개척할까요?\n");
               return(0);
       }

       if( find_ext(ply_ptr, rom_ptr->first_ext, cmnd->str[1], 1)){
               print(fd, "%s쪽으론 출구가 있습니다.\n", cmnd->str[1]);
               return(0);
       }

       if(cmnd->num < 3 ){
           if(!strcmp(cmnd->str[1], "남")) strcpy(tempstr, "북");
           else if(!strcmp(cmnd->str[1], "북")) strcpy(tempstr, "남");
           else if(!strcmp(cmnd->str[1], "서")) strcpy(tempstr, "동");
           else if(!strcmp(cmnd->str[1], "동")) strcpy(tempstr, "서");
           else if(!strcmp(cmnd->str[1], "위")) strcpy(tempstr, "밑");
           else if(!strcmp(cmnd->str[1], "밑")) strcpy(tempstr, "위");
           else if(!strcmp(cmnd->str[1], "남동")) strcpy(tempstr, "북서");
           else if(!strcmp(cmnd->str[1], "북서")) strcpy(tempstr, "남동");
           else if(!strcmp(cmnd->str[1], "남서")) strcpy(tempstr, "북동");
           else if(!strcmp(cmnd->str[1], "북동")) strcpy(tempstr, "남서");
           else strcpy(tempstr, "밖");
       }
       else
               strcpy(tempstr, cmnd->str[2]);

       for (iroom = ply_ptr->parent_rom->rom_num + 1; iroom < RMAX; iroom++){
               sprintf(file, "%s/r%02ld/r%05ld", ROOMPATH, iroom/1000, iroom);
               ff = open(file, O_RDONLY, 0);
               if(ff >= 0)
                       close(ff);
               else
                       break;
       }

       new_rom = (room *)malloc(sizeof(room));
       if(!new_rom)
               merror("settle", FATAL);
       new_rom->rom_num = iroom;
       sprintf(new_rom->name, "Room #%ld", iroom);

       zero(new_rom, sizeof(room));

       ff = open(file, O_RDWR | O_CREAT, ACC);
       if(ff < 0) {
               print(fd, "에러: Unable open files.\n");
               free(new_rom);
               return(-1);
       }

       if(write_rom(ff, new_rom, 0) < 0) {
               print(fd, "Write failed.\n");
               free(new_rom);
               return(-1);
       }

       close(ff);
       free(new_rom);

       load_rom(iroom, &new_rom);
       link_rom(&rom_ptr, iroom, cmnd->str[1]);
       print(fd, "%s쪽으로 지도를 개척합니다.(#%ld)\n", cmnd->str[1], iroom);
       link_rom(&new_rom, rom_ptr->rom_num, tempstr);
       print(fd, "\n되돌아오는 출구 : %s\n", tempstr);

       if(resave_rom(ply_ptr->rom_num) < 0){
               print(ply_ptr->fd,"출구 저장 실패.\n");
               print(ply_ptr->fd,"방번호와 함께 관리자에게 이야기 하십시오.\n"
               return(-1);
       }

       if(resave_rom(new_rom->rom_num) < 0){
               print(ply_ptr->fd,"새로운 영역 저장 실패.\n");
               print(ply_ptr->fd,"방번호와 함께 관리자에게 이야기 하십시오.\n"
               return(-1);
       }
       else
               print(ply_ptr->fd, "저장되었습니다.\n");

/*
       ply_ptr->gold = ply_ptr->gold - 5000000L;
       print(fd, "당신은 부동산 구입비로 5백만원을 지급합니다.\n");
       return(0);
*/
}


홈지기 "그륨"


XE Login