std::vector<std::string> MonsterGroupManager::GetMonstersFromGroup(std::string group) { MonsterGroup g = GetMonsterGroup(group); std::vector<std::string> monsters; monsters.push_back(g.defaultMonster); for( auto &elem : g.monsters ) { monsters.push_back( elem.name ); } return monsters; }
std::vector<std::string> MonsterGroupManager::GetMonstersFromGroup(std::string group) { MonsterGroup g = GetMonsterGroup(group); std::vector<std::string> monsters; monsters.push_back(g.defaultMonster); for (FreqDef_iter it = g.monsters.begin(); it != g.monsters.end(); ++it) { monsters.push_back(it->name); } return monsters; }
//Quantity is adjusted directly as a side effect of this function MonsterGroupResult MonsterGroupManager::GetResultFromGroup( std::string group_name, int *quantity, int turn ){ int spawn_chance = rng(1, 1000); auto *groupptr = &GetMonsterGroup( group_name ); int replace_time = DAYS(groupptr->monster_group_time * ACTIVE_WORLD_OPTIONS["MONSTER_GROUP_DIFFICULTY"]) * (calendar::turn.season_length() / 14); while (groupptr->replace_monster_group && calendar::turn.get_turn() > replace_time){ groupptr = &GetMonsterGroup(groupptr->new_monster_group); } auto &group = *groupptr; //Our spawn details specify, by default, a single instance of the default monster MonsterGroupResult spawn_details = MonsterGroupResult(group.defaultMonster, 1); //If the default monster is too difficult, replace this with "mon_null" if(turn != -1 && (turn + 900 < MINUTES(STARTING_MINUTES) + HOURS(GetMType(group.defaultMonster)->difficulty))) { spawn_details = MonsterGroupResult("mon_null", 0); } bool monster_found = false; // Step through spawn definitions from the monster group until one is found or for (FreqDef_iter it = group.monsters.begin(); it != group.monsters.end() && !monster_found; ++it) { // There's a lot of conditions to work through to see if this spawn definition is valid bool valid_entry = true; // I don't know what turn == -1 is checking for, but it makes monsters always valid for difficulty purposes valid_entry = valid_entry && (turn == -1 || (turn + 900) >= (MINUTES(STARTING_MINUTES) + HOURS(GetMType(it->name)->difficulty))); // If we are in classic mode, require the monster type to be either CLASSIC or WILDLIFE if(ACTIVE_WORLD_OPTIONS["CLASSIC_ZOMBIES"]) { valid_entry = valid_entry && (GetMType(it->name)->in_category("CLASSIC") || GetMType(it->name)->in_category("WILDLIFE")); } //Insure that the time is not before the spawn first appears or after it stops appearing valid_entry = valid_entry && (HOURS(it->starts) < calendar::turn.get_turn()); valid_entry = valid_entry && (it->lasts_forever() || HOURS(it->ends) > calendar::turn.get_turn()); std::vector<std::pair<int, int> > valid_times_of_day; bool season_limited = false; bool season_matched = false; //Collect the various spawn conditions, and then insure they are met appropriately for( auto &elem : it->conditions ) { //Collect valid time of day ranges if( ( elem ) == "DAY" || ( elem ) == "NIGHT" || ( elem ) == "DUSK" || ( elem ) == "DAWN" ) { int sunset = calendar::turn.sunset().get_turn(); int sunrise = calendar::turn.sunrise().get_turn(); if( ( elem ) == "DAY" ) { valid_times_of_day.push_back( std::make_pair(sunrise, sunset) ); } else if( ( elem ) == "NIGHT" ) { valid_times_of_day.push_back( std::make_pair(sunset, sunrise) ); } else if( ( elem ) == "DUSK" ) { valid_times_of_day.push_back( std::make_pair(sunset - HOURS(1), sunset + HOURS(1)) ); } else if( ( elem ) == "DAWN" ) { valid_times_of_day.push_back( std::make_pair(sunrise - HOURS(1), sunrise + HOURS(1)) ); } } //If we have any seasons listed, we know to limit by season, and if any season matches this season, we are good to spawn if( ( elem ) == "SUMMER" || ( elem ) == "WINTER" || ( elem ) == "SPRING" || ( elem ) == "AUTUMN" ) { season_limited = true; if( ( calendar::turn.get_season() == SUMMER && ( elem ) == "SUMMER" ) || ( calendar::turn.get_season() == WINTER && ( elem ) == "WINTER" ) || ( calendar::turn.get_season() == SPRING && ( elem ) == "SPRING" ) || ( calendar::turn.get_season() == AUTUMN && ( elem ) == "AUTUMN" ) ) { season_matched = true; } } } //Make sure the current time of day is within one of the valid time ranges for this spawn bool is_valid_time_of_day = false; if(valid_times_of_day.size() < 1) { //Then it can spawn whenever, since no times were defined is_valid_time_of_day = true; } else { //Otherwise, it's valid if it matches any of the times of day for( auto &elem : valid_times_of_day ) { int time_now = calendar::turn.get_turn(); if( time_now > elem.first && time_now < elem.second ) { is_valid_time_of_day = true; } } } if(!is_valid_time_of_day) { valid_entry = false; } //If we are limited by season, make sure we matched a season if(season_limited && !season_matched) { valid_entry = false; } //If the entry was valid, check to see if we actually spawn it if(valid_entry) { //If the monsters frequency is greater than the spawn_chance, select this spawn rule if(it->frequency >= spawn_chance) { if(it->pack_maximum > 1) { spawn_details = MonsterGroupResult(it->name, rng(it->pack_minimum, it->pack_maximum)); } else { spawn_details = MonsterGroupResult(it->name, 1); } //And if a quantity pointer with remaining value was passed, will modify the external value as a side effect //We will reduce it by the spawn rule's cost multiplier if(quantity) { *quantity -= it->cost_multiplier * spawn_details.pack_size; } monster_found = true; //Otherwise, subtract the frequency from spawn result for the next loop around } else { spawn_chance -= it->frequency; } } } return spawn_details; }
bool MonsterGroupManager::IsMonsterInGroup(std::string group, std::string monster) { return GetMonsterGroup( group ).IsMonsterInGroup( monster ); }