<commit_before>#include "framework/data.h"
#include "framework/framework.h"
#include "game/state/city/building.h"
#include "game/state/city/city.h"
#include "game/state/city/vehicle.h"
#include "game/state/gamestate.h"
#include "game/state/rules/battle/battlemap.h"
#include "game/state/rules/city/ufopaedia.h"
#include "library/strings_format.h"
#include "tools/extractors/common/ufo2p.h"
#include "tools/extractors/extractors.h"

namespace OpenApoc
{

void InitialGameStateExtractor::extractBuildingFunctions(GameState &state) const
{
	auto &data = this->ufo2p;

	for (unsigned i = 0; i < data.building_functions->count(); i++)
	{
		auto f = mksp<BuildingFunction>();
		f->name = data.building_functions->get(i);
		if (i < data.infiltration_speed_building->count())
		{
			f->infiltrationSpeed = data.infiltration_speed_building->get(i).speed;
		}
		if (i < buildingFunctionDetectionWeights.size())
		{
			f->detectionWeight = buildingFunctionDetectionWeights[i];
		}
		auto id = format("%s%s", BuildingFunction::getPrefix(), canon_string(f->name));
		auto ped = format("%s%s", UfopaediaEntry::getPrefix(), canon_string(f->name));
		f->ufopaedia_entry = {&state, ped};
		state.building_functions[id] = f;
	}
}

void InitialGameStateExtractor::extractBuildings(GameState &state, UString bldFileName,
                                                 sp<City> city, bool alienBuilding) const
{
	auto &data = this->ufo2p;

	auto fileName = "xcom3/ufodata/" + bldFileName + ".bld";

	auto inFile = fw().data->fs.open(fileName);
	if (!inFile)
	{
		LogError("Failed to open \"%s\"", fileName);
	}
	auto fileSize = inFile.size();
	auto bldCount = fileSize / sizeof(struct BldFileEntry);

	LogInfo("Loading %lu buildings from %s", (unsigned long)bldCount, fileName);

	for (unsigned i = 0; i < bldCount; i++)
	{
		struct BldFileEntry entry;
		inFile.read((char *)&entry, sizeof(entry));

		auto b = mksp<Building>();
		if (alienBuilding)
		{
			b->name = data.alien_building_names->get(entry.function_idx);
			b->function = {&state,
			               format("%s%s", BuildingFunction::getPrefix(), canon_string(b->name))};
			LogInfo("Alien bld %d %s func %d %s", entry.name_idx, b->name, entry.function_idx,
			        b->function.id);

			b->accessTopic = {&state, format("RESEARCH_ALIEN_BUILDING_%d", i)};
			if (i < 9)
			{
				b->researchUnlock.emplace_back(&state,
				                               format("RESEARCH_UNLOCK_ALIEN_BUILDING_%d", i + 1));
			}
			else
			{
				b->victory = true;
			}

			// Load crew
			auto crew = ufo2p.crew_alien_building->get(entry.function_idx);
			UFO2P::fillCrew(state, crew, b->preset_crew);
		}
		else
		{
			b->name = data.building_names->get(entry.name_idx);
			b->function = {&state,
			               format("%s%s", BuildingFunction::getPrefix(),
			                      canon_string(data.building_functions->get(entry.function_idx)))};
		}
		int battle_map_index = entry.function_idx - 1 + (alienBuilding ? 39 : 0);
		// Fix battle index for buildings that use other maps
		switch (battle_map_index)
		{
			// 24 Car Factory uses 25 Flying Car Factory
			case 23:
				battle_map_index = 24;<commit_msg>Extract values if it's not an alien building<commit_after>#include "framework/data.h"
#include "framework/framework.h"
#include "game/state/city/building.h"
#include "game/state/city/city.h"
#include "game/state/city/vehicle.h"
#include "game/state/gamestate.h"
#include "game/state/rules/battle/battlemap.h"
#include "game/state/rules/city/ufopaedia.h"
#include "library/strings_format.h"
#include "tools/extractors/common/ufo2p.h"
#include "tools/extractors/extractors.h"

namespace OpenApoc
{

void InitialGameStateExtractor::extractBuildingFunctions(GameState &state) const
{
	auto &data = this->ufo2p;

	for (unsigned i = 0; i < data.building_functions->count(); i++)
	{
		auto f = mksp<BuildingFunction>();
		f->name = data.building_functions->get(i);
		if (i < data.infiltration_speed_building->count())
		{
			f->infiltrationSpeed = data.infiltration_speed_building->get(i).speed;
		}
		if (i < buildingFunctionDetectionWeights.size())
		{
			f->detectionWeight = buildingFunctionDetectionWeights[i];
		}
		auto id = format("%s%s", BuildingFunction::getPrefix(), canon_string(f->name));
		auto ped = format("%s%s", UfopaediaEntry::getPrefix(), canon_string(f->name));
		f->ufopaedia_entry = {&state, ped};
		state.building_functions[id] = f;
	}
}

void InitialGameStateExtractor::extractBuildings(GameState &state, UString bldFileName,
                                                 sp<City> city, bool alienBuilding) const
{
	auto &data = this->ufo2p;

	auto fileName = "xcom3/ufodata/" + bldFileName + ".bld";

	auto inFile = fw().data->fs.open(fileName);
	if (!inFile)
	{
		LogError("Failed to open \"%s\"", fileName);
	}
	auto fileSize = inFile.size();
	auto bldCount = fileSize / sizeof(struct BldFileEntry);

	LogInfo("Loading %lu buildings from %s", (unsigned long)bldCount, fileName);

	for (unsigned i = 0; i < bldCount; i++)
	{
		struct BldFileEntry entry;
		inFile.read((char *)&entry, sizeof(entry));

		auto b = mksp<Building>();
		if (alienBuilding)
		{
			b->name = data.alien_building_names->get(entry.function_idx);
			b->function = {&state,
			               format("%s%s", BuildingFunction::getPrefix(), canon_string(b->name))};
			LogInfo("Alien bld %d %s func %d %s", entry.name_idx, b->name, entry.function_idx,
			        b->function.id);

			b->accessTopic = {&state, format("RESEARCH_ALIEN_BUILDING_%d", i)};
			if (i < 9)
			{
				b->researchUnlock.emplace_back(&state,
				                               format("RESEARCH_UNLOCK_ALIEN_BUILDING_%d", i + 1));
			}
			else
			{
				b->victory = true;
			}

			// Load crew
			auto crew = ufo2p.crew_alien_building->get(entry.function_idx);
			UFO2P::fillCrew(state, crew, b->preset_crew);
		}
		else
		{
			b->name = data.building_names->get(entry.name_idx);
			b->function = {&state,
			               format("%s%s", BuildingFunction::getPrefix(),
			                      canon_string(data.building_functions->get(entry.function_idx)))};

			b->isPurchesable = entry.is_purchaseable;
			b->purchasePrice = entry.price * 2000;
			b->maintenanceCosts = entry.maintenance_costs;
			b->currentWorkforce = entry.current_workforce;
			b->maximumWorkforce = entry.maximum_workforce;
			b->incomePerCapita = entry.income_per_capita;
			b->currentWage = entry.current_wage;
			b->investment = entry.investment_value;
			b->prestige = entry.respect_value;
		}
		int battle_map_index = entry.function_idx - 1 + (alienBuilding ? 39 : 0);
		// Fix battle index for buildings that use other maps
		switch (battle_map_index)
		{
			// 24 Car Factory uses 25 Flying Car Factory
			case 23:
				battle_map_index = 24;
{'fraction_non_alphanumeric': 0.1486707262735779, 'fraction_numerical': 0.007129065795336403, 'mean_word_length': 3.686151704940849, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6800824', 'n_tokens_mistral': 2596, 'n_tokens_neox': 2321, 'n_words': 441}