Ejemplo n.º 1
0
void Game_Map::SetupCommon(int _id) {
	// Execute remaining events (e.g. ones listed after a teleport)
	Update();
	Dispose();

	location.map_id = _id;

	// Try loading EasyRPG map files first, then fallback to normal RPG Maker
	std::stringstream ss;
	ss << "Map" << std::setfill('0') << std::setw(4) << location.map_id << ".emu";

	std::string map_file = FileFinder::FindDefault(ss.str());
	if (map_file.empty()) {
		ss.str("");
		ss << "Map" << std::setfill('0') << std::setw(4) << location.map_id << ".lmu";

		map = LMU_Reader::Load(FileFinder::FindDefault(ss.str()), Player::encoding);
		if (map.get() == NULL) {
			Output::ErrorStr(LcfReader::GetError());
		}
	}
	else {
		map = LMU_Reader::LoadXml(map_file);
		if (map.get() == NULL) {
			Output::ErrorStr(LcfReader::GetError());
		}
	}

	if (map->parallax_flag) {
		SetParallaxName(map->parallax_name);
		SetParallaxScroll(map->parallax_loop_x, map->parallax_loop_y,
			map->parallax_auto_loop_x, map->parallax_auto_loop_y,
			map->parallax_sx, map->parallax_sy);
	}
	else {
		SetParallaxName("");
	}

	SetChipset(map->chipset_id);
	need_refresh = true;

	scroll_direction = 2;
	scroll_rest = 0;
	scroll_speed = 4;
	map_info.encounter_rate = Data::treemap.maps[GetMapIndex(location.map_id)].encounter_steps;

	for (int i = 0; i < 3; i++)
		vehicles[i]->Refresh();

	pan_locked = false;
	pan_wait = false;
	pan_speed = 0;

	// Make RPG_RT happy
	// Otherwise current event not resumed after loading
	location.map_save_count = map->save_count;

	ResetEncounterSteps();
}
Ejemplo n.º 2
0
void Game_Map::SetupFromSave() {
	SetupCommon(location.map_id, true);

	// Make main interpreter "busy" if save contained events to prevent auto-events from starting
	interpreter->SetupFromSave(Main_Data::game_data.events.commands);

	events.reserve(map->events.size());
	for (size_t i = 0; i < map->events.size(); ++i) {
		if (i < map_info.events.size()) {
			events.emplace_back(location.map_id, map->events[i], map_info.events[i]);
		}
		else {
			events.emplace_back(location.map_id, map->events[i]);
		}

		if (events.back().IsMoveRouteOverwritten())
			pending.push_back(&events.back());
	}

	for (size_t i = 0; i < Main_Data::game_data.common_events.size() && i < common_events.size(); ++i) {
		common_events[i].SetSaveData(Main_Data::game_data.common_events[i].event_data);
	}

	for (size_t i = 0; i < 3; i++)
		if (vehicles[i]->IsMoveRouteOverwritten())
			pending.push_back(vehicles[i].get());

	map_info.Fixup(GetMap());
	map_info.Fixup(GetMapInfo());
	SetChipset(map_info.chipset_id);

	SetEncounterSteps(location.encounter_steps);


	// We want to support loading rm2k3e panning chunks
	// but also not break other saves which don't have them.
	// To solve this problem, we reuse the scrolling methods
	// which always reset the position anyways when scroll_horz/vert
	// is false.
	// This produces compatible behavior for old RPG_RT saves, namely
	// the pan_x/y is always forced to 0.
	// If the later async code will load panorama, set the flag to not clear the offsets.
	Game_Map::Parallax::ChangeBG(GetParallaxParams());
}
Ejemplo n.º 3
0
void Game_Map::Setup(int _id) {
	Dispose();
	first_frame = true;
	SetupCommon(_id, false);
	map_info.encounter_rate = GetMapInfo().encounter_steps;
	SetEncounterSteps(0);
	reset_panorama_x_on_next_init = true;
	reset_panorama_y_on_next_init = true;
	panorama = {};

	Parallax::ClearChangedBG();

	SetChipset(map->chipset_id);

	for (size_t i = 0; i < map_info.lower_tiles.size(); i++) {
		map_info.lower_tiles[i] = i;
	}
	for (size_t i = 0; i < map_info.upper_tiles.size(); i++) {
		map_info.upper_tiles[i] = i;
	}

	events.reserve(map->events.size());
	for (const RPG::Event& ev : map->events) {
		events.emplace_back(location.map_id, ev);
	}

	// pan_state does not reset when you change maps.
	location.pan_speed = default_pan_speed;
	location.pan_finish_x = default_pan_x;
	location.pan_finish_y = default_pan_y;
	location.pan_current_x = default_pan_x;
	location.pan_current_y = default_pan_y;

	// Save allowed
	int current_index = GetMapIndex(location.map_id);
	int can_save = Data::treemap.maps[current_index].save;
	int can_escape = Data::treemap.maps[current_index].escape;
	int can_teleport = Data::treemap.maps[current_index].teleport;

	while (can_save == RPG::MapInfo::TriState_parent
			|| can_escape == RPG::MapInfo::TriState_parent
			|| can_teleport == RPG::MapInfo::TriState_parent)
	{
		int parent_index = GetMapIndex(Data::treemap.maps[current_index].parent_map);
		if (parent_index == 0) {
			// If parent is 0 and flag is parent, it's implicitly enabled.
			break;
		}
		if (parent_index == current_index) {
			Output::Warning("Map %d has parent pointing to itself!", current_index);
			break;
		}
		if (parent_index < 0) {
			Output::Warning("Map %d has invalid parent id %d!", Data::treemap.maps[current_index].parent_map);
			break;
		}
		current_index = parent_index;
		if (can_save == RPG::MapInfo::TriState_parent) {
			can_save = Data::treemap.maps[current_index].save;
		}
		if (can_escape == RPG::MapInfo::TriState_parent) {
			can_escape = Data::treemap.maps[current_index].escape;
		}
		if (can_teleport == RPG::MapInfo::TriState_parent) {
			can_teleport = Data::treemap.maps[current_index].teleport;
		}
	}
	Game_System::SetAllowSave(can_save != RPG::MapInfo::TriState_forbid);
	Game_System::SetAllowEscape(can_escape != RPG::MapInfo::TriState_forbid);
	Game_System::SetAllowTeleport(can_teleport != RPG::MapInfo::TriState_forbid);
}