void encounters(void) { region *r; for (r = regions; r; r = r->next) { if (fval(r->terrain, LAND_REGION) && fval(r, RF_ENCOUNTER)) { int c = 0; unit *u; for (u = r->units; u; u = u->next) { c += u->number; } if (c > 0) { int i = 0; int n = rng_int() % c; for (u = r->units; u; u = u->next) { if (i + u->number > n) break; i += u->number; } assert(u && u->number); encounter(r, u); } } } }
// TODO: this function should be merged into LoadResetTimes and rename to LoadInstances void InstanceSaveManager::LoadCompletedEncounters() { m_completedEncounters.clear(); QueryResult result = CharacterDatabase.Query("SELECT id, map, difficulty, completedEncounters FROM instance"); if (result) { do { Field* fields = result->Fetch(); uint32 instanceId = fields[0].GetUInt32(); uint32 mapid = fields[1].GetUInt16(); uint32 difficulty = fields[2].GetUInt8(); uint32 completedEncounters = fields[3].GetUInt32(); InstanceEncounter encounter(mapid, Difficulty(difficulty), completedEncounters); m_completedEncounters.insert(InstanceCompletedEncounters::value_type(instanceId, encounter)); } while (result->NextRow()); } }
void run_game(){ char buf[40]; int x,y; int flags; int result=1; int index; int theme; while(1){ // World map gen_areamap(&x,&y); theme=get_random(0,NUM_MAP_THEME); while(1){ // Area map area_menu(&x,&y); flags=get_area_map(x,y); if(flags&AMAP_ENCOUNTER_BIT){ result=encounter(theme); if(!result){ destroy_game(); return; } } if(flags&AMAP_TREASURE_BIT){ index=spawn_item_by_price(50,500); add_item(index); sprintf(buf,"Obtained %s!",eq_name(index)); print_message(buf); } if(flags&AMAP_EXIT_BIT) break; explore_areamap(x,y); } world_menu(); } }
void procmain(void) { int ch; /* input */ double x; /* desired new x coordinate */ double y; /* desired new y coordinate */ double temp; /* for temporary calculations */ FILE *fp; /* for opening files */ int loop; /* a loop counter */ bool hasmoved = FALSE; /* set if player has moved */ ch = inputoption(); mvaddstr(4, 0, "\n\n"); /* clear status area */ move(7, 0); clrtobot(); /* clear data on bottom area of screen */ if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7')) /* valar cannot move */ ch = ' '; switch (ch) { case 'K': /* move up/north */ case 'N': x = Player.p_x; y = Player.p_y + MAXMOVE(); hasmoved = TRUE; break; case 'J': /* move down/south */ case 'S': x = Player.p_x; y = Player.p_y - MAXMOVE(); hasmoved = TRUE; break; case 'L': /* move right/east */ case 'E': x = Player.p_x + MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; case 'H': /* move left/west */ case 'W': x = Player.p_x - MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; default: /* rest */ Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0 + Player.p_level / 3.0 + 2.0; Player.p_energy = MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield); if (Player.p_status != S_CLOAKED) { /* cannot find mana if cloaked */ Player.p_mana += (Circle + Player.p_level) / 4.0; if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) /* wandering monster */ encounter(-1); } break; case 'X': /* change/examine a character */ changestats(TRUE); break; case '1': /* move */ for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) != 2) mvaddstr(5, 0, "Try again\n"); else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE()) ILLMOVE(); else { hasmoved = TRUE; break; } } break; case '2': /* players */ userlist(TRUE); break; case '3': /* message */ mvaddstr(4, 0, "Message ? "); getstring(Databuf, SZ_DATABUF); /* we open the file for writing to erase any data which is already there */ fp = fopen(_PATH_MESS, "w"); if (Databuf[0] != '\0') fprintf(fp, "%s: %s", Player.p_name, Databuf); fclose(fp); break; case '4': /* stats */ allstatslist(); break; case '5': /* good-bye */ leavegame(); /* NOTREACHED */ case '6': /* cloak */ if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK) ILLCMD(); else if (Player.p_status == S_CLOAKED) Player.p_status = S_PLAYING; else if (Player.p_mana < MM_CLOAK) mvaddstr(5, 0, "No mana left.\n"); else { Changed = TRUE; Player.p_mana -= MM_CLOAK; Player.p_status = S_CLOAKED; } break; case '7': /* teleport */ /* * conditions for teleport * - 20 per (level plus magic level) * - OR council of the wise or valar or ex-valar * - OR transport from throne * transports from throne cost no mana */ if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT) ILLCMD(); else for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) == 2) { temp = distance(Player.p_x, x, Player.p_y, y); if (!Throne /* can transport anywhere from throne */ && Player.p_specialtype <= SC_COUNCIL /* council, valar can transport anywhere */ && temp > (Player.p_level + Player.p_magiclvl) * 20.0) /* can only move 20 per exp. level + mag. level */ ILLMOVE(); else { temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */ if (!Throne && temp > Player.p_mana) mvaddstr(5, 0, "Not enough power for that distance.\n"); else { if (!Throne) Player.p_mana -= temp; hasmoved = TRUE; break; } } } } break; case 'C': case '9': /* monster */ if (Throne) /* no monsters while on throne */ mvaddstr(5, 0, "No monsters in the chamber!\n"); else if (Player.p_specialtype != SC_VALAR) { /* the valar cannot call monsters */ Player.p_sin += 1e-6; encounter(-1); } break; case '0': /* decree */ if (Wizard || (Player.p_specialtype == SC_KING && Throne)) /* kings must be on throne to decree */ dotampered(); else ILLCMD(); break; case '8': /* intervention */ if (Wizard || Player.p_specialtype >= SC_COUNCIL) dotampered(); else ILLCMD(); break; } if (hasmoved) { /* player has moved -- alter coordinates, and do random monster */ altercoordinates(x, y, A_SPECIFIC); if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) encounter(-1); } }