int AddChild(int room_id) { Room r = map.rooms[room_id]; int place_x = r.x; int place_y = r.y; int room_w = r.w; int room_h = r.h; int new_w, new_h, new_x, new_y; int room_pos; int trying; int attempts; trying = 1; attempts = 0; while (trying) { attempts++; if (( (total_rooms+1) % 500)==0) { new_w = 20; new_h = 15; } else { CreateRoomDimensions(&new_w, &new_h); } room_pos = (rdir++)%4; if (room_pos < 2) { /* vertical placement */ new_x = rndval(place_x - (new_w - 3), place_x + (room_w - 3)); if (room_pos == 0) { new_y = place_y - new_h; } else { new_y = place_y + room_h; } } else { /* horiz placement */ new_y = rndval(place_y - (new_h - 3), place_y + (room_h - 3)); if (room_pos == 2) { new_x = place_x - new_w; } else { new_x = place_x + room_w; } } if (NoRoomCollision(new_x, new_y, new_w, new_h)) { /* printf("SUCCESS\n"); */ r_successes[room_pos]++; NewRoom(new_x, new_y, new_w, new_h, room_id); return 1; } else { /* printf("FAIL %d\n", attempts); */ r_fails[room_pos]++; if (attempts > 20) return 0; } } return 0; }
int Generate() { int attempts = 0; int i; int correct_dist = 0; int maxdist = 0; rdir = rand()%4; NewRoom(map.w / 2 - 20 / 2, map.h / 2 - 15 / 2, 20, 15, -1); for (attempts = 0; attempts < 100000; attempts++) { assert(map.w == 512); AddChild(rndval(rndval(0, total_rooms-1), total_rooms-1)); if (total_rooms % 100 == 99) { LoadingScreen(0, (float)total_rooms / (float) NUM_ROOMS); } if (total_rooms == NUM_ROOMS) break; } if ((total_rooms < NUM_ROOMS)||(DoRepeat == 1)) { DoRepeat = 0; ResetLevel(); return 0; } RecurseSetDist(); for (i = 0; i < NUM_ROOMS; i++) { if (map.rooms[i].s_dist > maxdist) { maxdist = map.rooms[i].s_dist; } if (map.rooms[i].s_dist >= 50) { correct_dist = 1; } } if (correct_dist == 0) { /*printf("Dist fail (only %d)\n", maxdist);*/ DoRepeat = 0; ResetLevel(); return 0; } /*printf("Rooms: %d\n", total_rooms);*/ MakeSpecialRooms(); map.totalRooms = total_rooms; return 1; }
void Init(clock_t &tLast) { setlocale(LC_CTYPE, "Spanish"); //Set acentos tLast = clock(); bag.SetName(BAG); bag.SetDescription(BAG_DESC); bag.SetLatitude(0); bag.SetLongitude(0); bag.SetState('s'); bag.ilist.Push((std::string)"llave", (std::string)"Una llave de acero oxidada"); //objeto no lo pongo en las strings de constants.h colortext(YELLOW); printf(MISSION); NewRoom(); Prompt(); gameState = loop; }
int run_dialog_request (int parmtr) { play.stop_dialog_at_end = DIALOG_RUNNING; gameinst->RunTextScriptIParam("dialog_request", RuntimeScriptValue().SetInt32(parmtr)); if (play.stop_dialog_at_end == DIALOG_STOP) { play.stop_dialog_at_end = DIALOG_NONE; return -2; } if (play.stop_dialog_at_end >= DIALOG_NEWTOPIC) { int tval = play.stop_dialog_at_end - DIALOG_NEWTOPIC; play.stop_dialog_at_end = DIALOG_NONE; return tval; } if (play.stop_dialog_at_end >= DIALOG_NEWROOM) { int roomnum = play.stop_dialog_at_end - DIALOG_NEWROOM; play.stop_dialog_at_end = DIALOG_NONE; NewRoom(roomnum); return -2; } play.stop_dialog_at_end = DIALOG_NONE; return -1; }
/* -------------------------------------------------------------------- */ static void makeSendFile(void) { char line[100], line2[100]; label troo; label fn; FILE *file; int i = 0, rm; if ((file = fopen(roomreqin, "rb")) == NULL) { perror("Error opening roomreq.in"); } doccr(); cPrintf(" Fetching:"); doccr(); GetStr(file, troo, LABELSIZE); while(strlen(troo) && !feof(file)) { if ((rm = roomExists(troo)) != ERROR) { if (nodecanseeroom(node.ndname, rm)) { sprintf(fn, "room.%d", i); cPrintf(" %-20s ", troo); if( !((i+1) % 3) ) doccr(); NewRoom(rm, fn); } else { doccr(); cPrintf(" No access to %s room.", troo); doccr(); amPrintf(" '%s' room not available to remote.\n", troo); netError = TRUE; } } else { doccr(); cPrintf(" No %s room on system.", troo); doccr(); amPrintf(" '%s' room not found for remote.\n", troo); netError = TRUE; } i++; GetStr(file, troo, LABELSIZE); } doccr(); fclose(file); unlink(roomreqin); cPrintf(" Copying mail file."); doccr(); sprintf(line, "%s\\%s", cfg.transpath, node.ndmailtmp); sprintf(line2, "%s\\mesg.tmp", cfg.temppath); if ((file = fopen(line2, "wb")) != NULL) { fclose(file); } copyfile(line, line2); cPrintf(" Compressing message files."); doccr(); /* * Zip them up */ sformat(line, node.zip, "df", roomdataout, "mesg.tmp room.*"); apsystem(line); /* * Remove them. */ ambigUnlink("room.*", FALSE); unlink("mesg.tmp"); }
void TERMWINDOWMEMBER makeSendFile(void) { char line[100], line2[100]; label troo; label fn; FILE *file; int i = 0; int crcounter = 0; if ((file = fopen(roomreqIn, FO_RB)) == NULL) { perror(getnetmsg(90)); return; // ok } doccr(); cPrintf(getnetmsg(2)); doccr(); GetStr(file, troo, LABELSIZE); while (*troo && !feof(file)) { r_slot rm = RoomExists(troo); if (rm == CERROR) { rm = IdExists(troo, TRUE); } if (rm != CERROR) { if (CurrentUser->CanAccessRoom(rm)) { sprintf(fn, getnetmsg(126), i); cPrintf(getnetmsg(128), deansi(troo)); if (!((crcounter+1) % 3)) { doccr(); } crcounter++; NewRoom(rm, fn, NULL); } else { doccr(); cPrintf(getnetmsg(111), deansi(troo)); doccr(); amPrintf(getnetmsg(4), troo, bn); netError = TRUE; } } else { doccr(); cPrintf(getnetmsg(97), deansi(troo)); doccr(); amPrintf(getnetmsg(6), troo, bn); netError = TRUE; } i++; GetStr(file, troo, LABELSIZE); } doccr(); fclose(file); unlink(roomreqIn); cPrintf(getnetmsg(98)); doccr(); sprintf(line, sbs, cfg.transpath, node->GetMailFileName()); sprintf(line2, sbs, LocalTempPath, mesgTmp); if ((file = fopen(line2, FO_WB)) != NULL) { fclose(file); } copyfile(line, line2); cPrintf(getnetmsg(99), cfg.Lmsg_nym); doccr(); // Zip them up sprintf(line2, getnetmsg(113), mesgTmp, roomStar); sformat(line, node->GetCreatePacket(), getmsg(49), roomdataOut, line2, 0); apsystem(line, TRUE); // Remove them. changedir(LocalTempPath); ambigUnlink(roomStar); unlink(mesgTmp); }
Bool TERMWINDOWMEMBER Net1Slave(void) { char line[100]; label troo; label fn; FILE *file; int i = 0; const protocols *theProt = GetProtocolByKey(node->GetProtocol(), TRUE); if (!theProt) { doccr(); cPrintf(getnetmsg(177)); doCR(); return (FALSE); } cPrintf(getnetmsg(178)); doccr(); sprintf(line, sbs, cfg.transpath, node->GetMailFileName()); // create empty mail file if there is none if ((file = fopen(line, FO_AB)) != NULL) { fclose(file); } wxsnd(LocalTempPath, line, theProt, 0); if (!CommPort->HaveConnection()) { return (FALSE); } cPrintf(getnetmsg(179)); doccr(); sprintf(line, sbs, LocalTempPath, roomreqTmp); unlink(line); wxrcv(LocalTempPath, roomreqTmp, theProt); changedir(LocalTempPath); if (!CommPort->HaveConnection()) { return (FALSE); } sprintf(line, sbs, LocalTempPath, roomreqTmp); if ((file = fopen(line, FO_RB)) == NULL) { perror(getnetmsg(1)); return (FALSE); } doccr(); cPrintf(getnetmsg(2)); doccr(); GetStr(file, troo, LABELSIZE); while (*troo && !feof(file)) { KBReady(); r_slot rm; if ((rm = RoomExists(troo)) != CERROR) { if (CurrentUser->CanAccessRoom(rm)) { sprintf(fn, getnetmsg(126), i); cPrintf(getnetmsg(166), deansi(troo)); if (!((i+1) % 3)) { doccr(); } NewRoom(rm, fn, NULL); } else { doccr(); cPrintf(getnetmsg(111), deansi(troo)); doccr(); amPrintf(getnetmsg(4), troo, bn); netError = TRUE; } } else { doccr(); cPrintf(getnetmsg(5), deansi(troo)); doccr(); amPrintf(getnetmsg(167), troo, bn); netError = TRUE; } i++; GetStr(file, troo, LABELSIZE); } doccr(); fclose(file); unlink(line); cPrintf(getnetmsg(7), cfg.Lmsg_nym); doccr(); if (!CommPort->HaveConnection()) { return (FALSE); } wxsnd(LocalTempPath, getnetmsg(162), theProt, 0); ambigUnlink(getnetmsg(162)); return (TRUE); }
void ShowCommands() { //acciones de palabras simples std::string action = stackCommands.Consult().c_str(); int i = 0; char result = 's'; switch (Hashit(Upcase(action))) { case ayuda: printf(HELP_LIST); colortext(WHITE); printf(LEAVE); colortext(LIGHTGREY); printf(HELP_LEAVE); colortext(WHITE); printf(OPEN_DOOR); colortext(LIGHTGREY); printf(HELP_OPEN_DOOR); colortext(WHITE); printf(CLEAR_SCREEN); colortext(LIGHTGREY); printf(HELP_CLEAR_SCREEN); colortext(WHITE); printf(PICKUP); colortext(LIGHTGREY); printf(HELP_PICKUP); colortext(WHITE); printf(EAST); colortext(LIGHTGREY); printf(HELP_EAST); colortext(WHITE); printf(PUT_IN_BAG); colortext(LIGHTGREY); printf(HELP_PUT_IN_BAG); colortext(WHITE); printf(INV); colortext(LIGHTGREY); printf(HELP_INV); colortext(WHITE); printf(LOOK); colortext(LIGHTGREY); printf(HELP_LOOK); colortext(WHITE); printf(NORTH); colortext(LIGHTGREY); printf(HELP_NORTH); colortext(WHITE); printf(WEST); colortext(LIGHTGREY); printf(HELP_WEST); colortext(WHITE); printf(EXITS); colortext(LIGHTGREY); printf(HELP_EXITS); colortext(WHITE); printf(DROP); colortext(LIGHTGREY); printf(HELP_DROP); colortext(WHITE); printf(GET_FROM_BAG); colortext(LIGHTGREY); printf(GET_FROM_BAG); colortext(WHITE); printf(SOUTH); colortext(LIGHTGREY); printf(HELP_SOUTH); break; case mirar: NewRoom(); break; case norte: if (myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) > 0 && myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100) { myPlayer.SetLatitude(myPlayer.GetLatitude() - 1); NewRoom(); } else printf(NO_EXITS); break; case sur: if (myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100) { myPlayer.SetLatitude(myPlayer.GetLatitude() + 1); NewRoom(); } else printf(NO_EXITS); break; case este: if (myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100) { myPlayer.SetLongitude(myPlayer.GetLongitude() + 1); NewRoom(); } else printf(NO_EXITS); break; case oeste: if (myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100) { myPlayer.SetLongitude(myPlayer.GetLongitude() - 1); NewRoom(); } else printf(NO_EXITS); break; case salidas: myMap.ShowExits(myPlayer.GetLatitude(), myPlayer.GetLongitude()); break; case cls: system("cls"); break; case inventario: printf(INVENTORY); if (bag.GetState() == 's') printf(Show_Item(bag.GetDescription().c_str())); if (myPlayer.inventory.Size() > 0) { for (int i = 0; i < myPlayer.inventory.Size(); ++i) printf(Show_Item(myPlayer.inventory.GetDescPosN(i).c_str())); } else if ( bag.GetState() != 's' ) printf( NOTHING_TO_SHOW ); break; default: result = 'n'; break; } //acciones de 2 palabras action = GetWord(stackCommands.Consult().c_str()); Item::Node *tmp; switch (Hashit(Upcase(action))) { case coger: action = CutFirstWord(stackCommands.Consult().c_str()); action = GetWord(action.c_str()); if (action == BAG) { bag.ToInventory(myPlayer.GetLatitude(), myPlayer.GetLongitude()); } else { tmp = myMap.GetFromMap(myPlayer.GetLatitude(), myPlayer.GetLongitude(), action); if (tmp != nullptr) { printf(Pick(action.c_str())); myPlayer.inventory.Push(tmp->name, tmp->description); if (tmp->name == "espada") // habitacion - El burladero de la esquina sur este. { colortext(YELLOW); printf(GAME_OVER); gameState = endLoop; return; } delete tmp; } else { printf(Not_found(action.c_str())); } } break; case tirar: action = CutFirstWord(stackCommands.Consult().c_str()); action = GetWord(action.c_str()); if (action == BAG) { bag.DropItem(myPlayer.GetLatitude(), myPlayer.GetLongitude()); } else { tmp = myPlayer.GetInventory(action); if (tmp != nullptr) { printf(Drop_Item(action.c_str())); myMap.DropToMap(myPlayer.GetLatitude(), myPlayer.GetLongitude(), tmp); delete tmp; } else { printf(Inventory_void(action.c_str())); } } break; case guardar: if (bag.GetState() != 's') printf(NO_BAG); else { action = CutFirstWord(stackCommands.Consult().c_str()); action = GetWord(action.c_str()); tmp = myPlayer.GetInventory(action); if (tmp != nullptr) { printf(Put_in_bag(action.c_str())); bag.ilist.Push(tmp->name, tmp->description); delete tmp; } else { if (action == BAG) printf(BAG_IN_BAG); else printf(Inventory_void(action.c_str())); } } break; case sacar: if (bag.GetState() != 's') printf(NO_BAG); else { action = CutFirstWord(stackCommands.Consult().c_str()); action = GetWord(action.c_str()); tmp = bag.GetFromContainer(action); if (tmp != nullptr) { printf(Pick(action.c_str())); myPlayer.inventory.Push(tmp->name, tmp->description); delete tmp; } else { printf(Not_In_bag(action.c_str())); } } break; case abrir: if (myPlayer.inventory.Size() > 0) if (myPlayer.inventory.HaveItem("llave")) { action = CutFirstWord(stackCommands.Consult().c_str()); action = GetWord(action.c_str()); switch ((Hashit(Upcase(action)))) { case sur: myMap.OpenDoor(myPlayer.GetLatitude() + 1 , myPlayer.GetLongitude()); break; case norte: myMap.OpenDoor(myPlayer.GetLatitude() - 1, myPlayer.GetLongitude()); break; case este: myMap.OpenDoor(myPlayer.GetLatitude(), myPlayer.GetLongitude() + 1); break; case oeste: myMap.OpenDoor(myPlayer.GetLatitude(), myPlayer.GetLongitude() - 1); break; default: break; } } else printf(Inventory_void("llave")); else printf(Inventory_void("llave")); break; default: if (result == 'n') printf(NO_ACTION); break; } Prompt(); stackCommands.Pop(); }