/**
 * Populates the build list from the current "available" facilities
 */
void BuildFacilitiesState::PopulateBuildList()
{
	const std::vector<std::string> &facilities = _game->getRuleset()->getBaseFacilitiesList();
	for (std::vector<std::string>::const_iterator i = facilities.begin(); i != facilities.end(); ++i)
	{
		RuleBaseFacility *rule = _game->getRuleset()->getBaseFacility(*i);
		if (_game->getSavedGame()->isResearched(rule->getRequirements()) && !rule->isLift())
			_facilities.push_back(rule);
	}

	for (std::vector<RuleBaseFacility*>::iterator i = _facilities.begin(); i != _facilities.end(); ++i)
	{
		_lstFacilities->addRow(1, _game->getLanguage()->getString((*i)->getType()).c_str());
	}
}
	ArticleStateTFTDFacility::ArticleStateTFTDFacility(ArticleDefinitionTFTD *defs) : ArticleStateTFTD(defs)
	{
		RuleBaseFacility *facility = _game->getMod()->getBaseFacility(defs->id, true);

		_lstInfo = new TextList(150, 50, 168, 150);
		add(_lstInfo);

		_lstInfo->setColor(Palette::blockOffset(0)+2);
		_lstInfo->setColumns(2, 104, 46);
		_lstInfo->setDot(true);

		std::ostringstream ss;
		int row = 0;
		if (facility->getDefenseValue() > 0)
		{
			_lstInfo->setY(_lstInfo->getY() - 16);
			ss.str("");ss.clear();
			ss << facility->getDefenseValue();
			_lstInfo->addRow(2, tr("STR_DEFENSE_VALUE").c_str(), ss.str().c_str());
			_lstInfo->setCellColor(row++, 1, Palette::blockOffset(15)+4);

			ss.str("");ss.clear();
			ss << Unicode::formatPercentage(facility->getHitRatio());
			_lstInfo->addRow(2, tr("STR_HIT_RATIO").c_str(), ss.str().c_str());
			_lstInfo->setCellColor(row++, 1, Palette::blockOffset(15)+4);
		}

		ss.str("");ss.clear();
		_lstInfo->addRow(2, tr("STR_CONSTRUCTION_TIME").c_str(), tr("STR_DAY", facility->getBuildTime()).c_str());
		_lstInfo->setCellColor(row++, 1, Palette::blockOffset(15)+4);

		ss << Unicode::formatFunding(facility->getBuildCost());
		_lstInfo->addRow(2, tr("STR_CONSTRUCTION_COST").c_str(), ss.str().c_str());
		_lstInfo->setCellColor(row++, 1, Palette::blockOffset(15)+4);

		ss.str("");ss.clear();
		ss << Unicode::formatFunding(facility->getMonthlyCost());
		_lstInfo->addRow(2, tr("STR_MAINTENANCE_COST").c_str(), ss.str().c_str());
		_lstInfo->setCellColor(row++, 1, Palette::blockOffset(15)+4);

		centerAllSurfaces();
	}
	ArticleStateBaseFacility::ArticleStateBaseFacility(ArticleDefinitionBaseFacility *defs) : ArticleState(defs->id)
	{
		RuleBaseFacility *facility = _game->getRuleset()->getBaseFacility(defs->id);

		// add screen elements
		_txtTitle = new Text(200, 17, 10, 24);

		// Set palette
		setPalette("PAL_BASESCAPE");

		ArticleState::initLayout();

		// add other elements
		add(_txtTitle);

		// Set up objects
		_game->getResourcePack()->getSurface("BACK09.SCR")->blit(_bg);
		_btnOk->setColor(Palette::blockOffset(4));
		_btnPrev->setColor(Palette::blockOffset(4));
		_btnNext->setColor(Palette::blockOffset(4));

		_txtTitle->setColor(Palette::blockOffset(13)+10);
		_txtTitle->setBig();
		_txtTitle->setText(tr(defs->title));

		// build preview image
		int tile_size = 32;
		_image = new Surface(tile_size*2, tile_size*2, 232, 16);
		add(_image);

		SurfaceSet *graphic = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
		Surface *frame;
		int x_offset, y_offset;
		int x_pos, y_pos;
		int num;

		if (facility->getSize()==1)
		{
			x_offset = y_offset = tile_size/2;
		}
		else
		{
			x_offset = y_offset = 0;
		}

		num = 0;
		y_pos = y_offset;
		for (int y = 0; y < facility->getSize(); ++y)
		{
			x_pos = x_offset;
			for (int x = 0; x < facility->getSize(); ++x)
			{
				frame = graphic->getFrame(facility->getSpriteShape() + num);
				frame->setX(x_pos);
				frame->setY(y_pos);
				frame->blit(_image);

				if (facility->getSize()==1)
				{
					frame = graphic->getFrame(facility->getSpriteFacility() + num);
					frame->setX(x_pos);
					frame->setY(y_pos);
					frame->blit(_image);
				}

				x_pos += tile_size;
				num++;
			}
			y_pos += tile_size;
		}

		_txtInfo = new Text(300, 90, 10, 104);
		add(_txtInfo);

		_txtInfo->setColor(Palette::blockOffset(13)+10);
		_txtInfo->setWordWrap(true);
		_txtInfo->setText(tr(defs->text));

		_lstInfo = new TextList(200, 42, 10, 42);
		add(_lstInfo);

		_lstInfo->setColor(Palette::blockOffset(13)+10);
		_lstInfo->setColumns(2, 140, 60);
		_lstInfo->setDot(true);

		_lstInfo->addRow(2, tr("STR_CONSTRUCTION_TIME").c_str(), tr("STR_DAY", facility->getBuildTime()).c_str());
		_lstInfo->setCellColor(0, 1, Palette::blockOffset(13)+0);

		std::wostringstream ss;
		ss << Text::formatFunding(facility->getBuildCost());
		_lstInfo->addRow(2, tr("STR_CONSTRUCTION_COST").c_str(), ss.str().c_str());
		_lstInfo->setCellColor(1, 1, Palette::blockOffset(13)+0);

		ss.str(L"");ss.clear();
		ss << Text::formatFunding(facility->getMonthlyCost());
		_lstInfo->addRow(2, tr("STR_MAINTENANCE_COST").c_str(), ss.str().c_str());
		_lstInfo->setCellColor(2, 1, Palette::blockOffset(13)+0);

		if (facility->getDefenseValue() > 0)
		{
			ss.str(L"");ss.clear();
			ss << facility->getDefenseValue();
			_lstInfo->addRow(2, tr("STR_DEFENSE_VALUE").c_str(), ss.str().c_str());
			_lstInfo->setCellColor(3, 1, Palette::blockOffset(13)+0);

			ss.str(L"");ss.clear();
			ss << Text::formatPercentage(facility->getHitRatio());
			_lstInfo->addRow(2, tr("STR_HIT_RATIO").c_str(), ss.str().c_str());
			_lstInfo->setCellColor(4, 1, Palette::blockOffset(13)+0);
		}
		centerAllSurfaces();
	}
Beispiel #4
0
/**
 * Loads a ruleset's contents from a YAML file.
 * Rules that match pre-existing rules overwrite them.
 * @param filename YAML filename.
 */
void Ruleset::loadFile(const std::string &filename)
{
	YAML::Node doc = YAML::LoadFile(filename);

	for (YAML::const_iterator i = doc["countries"].begin(); i != doc["countries"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleCountry *rule;
		if (_countries.find(type) != _countries.end())
		{
			rule = _countries[type];
		}
		else
		{
			rule = new RuleCountry(type);
			_countries[type] = rule;
			_countriesIndex.push_back(type);
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["regions"].begin(); i != doc["regions"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleRegion *rule;
		if (_regions.find(type) != _regions.end())
		{
			rule = _regions[type];
		}
		else
		{
			rule = new RuleRegion(type);
			_regions[type] = rule;
			_regionsIndex.push_back(type);
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["facilities"].begin(); i != doc["facilities"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleBaseFacility *rule;
		if (_facilities.find(type) != _facilities.end())
		{
			rule = _facilities[type];
		}
		else
		{
			rule = new RuleBaseFacility(type);
			_facilities[type] = rule;
			_facilitiesIndex.push_back(type);
		}
		_facilityListOrder += 100;
		rule->load(*i, _modIndex, _facilityListOrder);
	}
 	for (YAML::const_iterator i = doc["crafts"].begin(); i != doc["crafts"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleCraft *rule;
		if (_crafts.find(type) != _crafts.end())
		{
			rule = _crafts[type];
		}
		else
		{
			rule = new RuleCraft(type);
			_crafts[type] = rule;
			_craftsIndex.push_back(type);
		}
		_craftListOrder += 100;
		rule->load(*i, this, _modIndex, _craftListOrder);
	}
 	for (YAML::const_iterator i = doc["craftWeapons"].begin(); i != doc["craftWeapons"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleCraftWeapon *rule;
		if (_craftWeapons.find(type) != _craftWeapons.end())
		{
			rule = _craftWeapons[type];
		}
		else
		{
			rule = new RuleCraftWeapon(type);
			_craftWeapons[type] = rule;
			_craftWeaponsIndex.push_back(type);
		}
		rule->load(*i, _modIndex);
	}
 	for (YAML::const_iterator i = doc["items"].begin(); i != doc["items"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleItem *rule;
		if (_items.find(type) != _items.end())
		{
			rule = _items[type];
		}
		else
		{
			rule = new RuleItem(type);
			_items[type] = rule;
			_itemsIndex.push_back(type);
		}
		_itemListOrder += 100;
		rule->load(*i, _modIndex, _itemListOrder);
	}
 	for (YAML::const_iterator i = doc["ufos"].begin(); i != doc["ufos"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleUfo *rule;
		if (_ufos.find(type) != _ufos.end())
		{
			rule = _ufos[type];
		}
		else
		{
			rule = new RuleUfo(type);
			_ufos[type] = rule;
			_ufosIndex.push_back(type);
		}
		rule->load(*i, this);
	}
 	for (YAML::const_iterator i = doc["invs"].begin(); i != doc["invs"].end(); ++i)
	{
		std::string type = (*i)["id"].as<std::string>();
		RuleInventory *rule;
		if (_invs.find(type) != _invs.end())
		{
			rule = _invs[type];
		}
		else
		{
			rule = new RuleInventory(type);
			_invs[type] = rule;
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["terrains"].begin(); i != doc["terrains"].end(); ++i)
	{
		std::string type = (*i)["name"].as<std::string>();
		RuleTerrain *rule;
		if (_terrains.find(type) != _terrains.end())
		{
			rule = _terrains[type];
		}
		else
		{
			rule = new RuleTerrain(type);
			_terrains[type] = rule;
			_terrainIndex.push_back(type);
		}
		rule->load(*i, this);
	}
 	for (YAML::const_iterator i = doc["armors"].begin(); i != doc["armors"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		Armor *rule;
		if (_armors.find(type) != _armors.end())
		{
			rule = _armors[type];
		}
		else
		{
			rule = new Armor(type, "", 0);
			_armors[type] = rule;
			_armorsIndex.push_back(type);
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["soldiers"].begin(); i != doc["soldiers"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		RuleSoldier *rule;
		if (_soldiers.find(type) != _soldiers.end())
		{
			rule = _soldiers[type];
		}
		else
		{
			rule = new RuleSoldier(type);
			_soldiers[type] = rule;
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["units"].begin(); i != doc["units"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		Unit *rule;
		if (_units.find(type) != _units.end())
		{
			rule = _units[type];
		}
		else
		{
			rule = new Unit(type, "", "");
			_units[type] = rule;
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["alienRaces"].begin(); i != doc["alienRaces"].end(); ++i)
	{
		std::string type = (*i)["id"].as<std::string>();
		AlienRace *rule;
		if (_alienRaces.find(type) != _alienRaces.end())
		{
			rule = _alienRaces[type];
		}
		else
		{
			rule = new AlienRace(type);
			_alienRaces[type] = rule;
			_aliensIndex.push_back(type);
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["alienDeployments"].begin(); i != doc["alienDeployments"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		AlienDeployment *rule;
		if (_alienDeployments.find(type) != _alienDeployments.end())
		{
			rule = _alienDeployments[type];
		}
		else
		{
			rule = new AlienDeployment(type);
			_alienDeployments[type] = rule;
			_deploymentsIndex.push_back(type);
		}
		rule->load(*i);
	}
 	for (YAML::const_iterator i = doc["research"].begin(); i != doc["research"].end(); ++i)
	{
		std::string type = (*i)["name"].as<std::string>();
		RuleResearch *rule;
		if (_research.find(type) != _research.end())
		{
			rule = _research[type];
		}
		else
		{
			rule = new RuleResearch(type);
			_research[type] = rule;
			_researchIndex.push_back(type);
		}
		_researchListOrder += 100;
		rule->load(*i, _researchListOrder);
	}
 	for (YAML::const_iterator i = doc["manufacture"].begin(); i != doc["manufacture"].end(); ++i)
	{
		std::string type = (*i)["name"].as<std::string>();
		RuleManufacture *rule;
		if (_manufacture.find(type) != _manufacture.end())
		{
			rule = _manufacture[type];
		}
		else
		{
			rule = new RuleManufacture(type);
			_manufacture[type] = rule;
			_manufactureIndex.push_back(type);
		}
		_manufactureListOrder += 100;
		rule->load(*i, _manufactureListOrder);
	}
 	for (YAML::const_iterator i = doc["ufopaedia"].begin(); i != doc["ufopaedia"].end(); ++i)
	{
		std::string id = (*i)["id"].as<std::string>();
		ArticleDefinition *rule;
		if (_ufopaediaArticles.find(id) != _ufopaediaArticles.end())
		{
			rule = _ufopaediaArticles[id];
		}
		else
		{
			UfopaediaTypeId type = (UfopaediaTypeId)(*i)["type_id"].as<int>();
			switch (type)
			{
			case UFOPAEDIA_TYPE_CRAFT: rule = new ArticleDefinitionCraft(); break;
			case UFOPAEDIA_TYPE_CRAFT_WEAPON: rule = new ArticleDefinitionCraftWeapon(); break;
			case UFOPAEDIA_TYPE_VEHICLE: rule = new ArticleDefinitionVehicle(); break;
			case UFOPAEDIA_TYPE_ITEM: rule = new ArticleDefinitionItem(); break;
			case UFOPAEDIA_TYPE_ARMOR: rule = new ArticleDefinitionArmor(); break;
			case UFOPAEDIA_TYPE_BASE_FACILITY: rule = new ArticleDefinitionBaseFacility(); break;
			case UFOPAEDIA_TYPE_TEXTIMAGE: rule = new ArticleDefinitionTextImage(); break;
			case UFOPAEDIA_TYPE_TEXT: rule = new ArticleDefinitionText(); break;
			case UFOPAEDIA_TYPE_UFO: rule = new ArticleDefinitionUfo(); break;
			default: rule = 0; break;
			}
			_ufopaediaArticles[id] = rule;
			_ufopaediaIndex.push_back(id);
		}
		_ufopaediaListOrder += 100;
		rule->load(*i, _ufopaediaListOrder);
	}
 	//_startingBase->load(i->second, 0);
	if (doc["startingBase"])
		_startingBase = YAML::Node(doc["startingBase"]);
 	_startingTime.load(doc["startingTime"]);
 	_costSoldier = doc["costSoldier"].as<int>(_costSoldier);
 	_costEngineer = doc["costEngineer"].as<int>(_costEngineer);
 	_costScientist = doc["costScientist"].as<int>(_costScientist);
 	_timePersonnel = doc["timePersonnel"].as<int>(_timePersonnel);
 	for (YAML::const_iterator i = doc["ufoTrajectories"].begin(); i != doc["ufoTrajectories"].end(); ++i)
	{
		std::string id = (*i)["id"].as<std::string>();
		if (_ufoTrajectories.find(id) != _ufoTrajectories.end())
		{
			_ufoTrajectories[id]->load(*i);
		}
		else
		{
			std::auto_ptr<UfoTrajectory> rule(new UfoTrajectory);
			rule->load(*i);
			_ufoTrajectories[id] = rule.release();
		}
	}
 	for (YAML::const_iterator i = doc["alienMissions"].begin(); i != doc["alienMissions"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		if (_alienMissions.find(type) != _alienMissions.end())
		{
			_alienMissions[type]->load(*i);
		}
		else
		{
			std::auto_ptr<RuleAlienMission> rule(new RuleAlienMission());
			rule->load(*i);
			_alienMissions[type] = rule.release();
			_alienMissionsIndex.push_back(type);
		}
	}
 	_alienItemLevels.clear();
	for (YAML::const_iterator i = doc["alienItemLevels"].begin(); i != doc["alienItemLevels"].end(); ++i)
	{
		std::vector<int> type = (*i).as< std::vector<int> >();
		_alienItemLevels.push_back(type);
	}
 	for (YAML::const_iterator i = doc["MCDPatches"].begin(); i != doc["MCDPatches"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		if (_MCDPatches.find(type) != _MCDPatches.end())
		{
			_MCDPatches[type]->load(*i);
		}
		else
		{
			std::auto_ptr<MCDPatch> patch(new MCDPatch());
			patch->load(*i);
			_MCDPatches[type] = patch.release();
			_MCDPatchesIndex.push_back(type);
		}
	}
 	for (YAML::const_iterator i = doc["extraSprites"].begin(); i != doc["extraSprites"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		std::auto_ptr<ExtraSprites> extraSprites(new ExtraSprites());
		extraSprites->load(*i, _modIndex);
		_extraSprites.push_back(std::make_pair(type, extraSprites.release()));
		_extraSpritesIndex.push_back(type);
	}
 	for (YAML::const_iterator i = doc["extraSounds"].begin(); i != doc["extraSounds"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		std::auto_ptr<ExtraSounds> extraSounds(new ExtraSounds());
		extraSounds->load(*i, _modIndex);
		_extraSounds.push_back(std::make_pair(type, extraSounds.release()));
		_extraSoundsIndex.push_back(type);
	}
 	for (YAML::const_iterator i = doc["extraStrings"].begin(); i != doc["extraStrings"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		if (_extraStrings.find(type) != _extraStrings.end())
		{
			_extraStrings[type]->load(*i);
		}
		else
		{
			std::auto_ptr<ExtraStrings> extraStrings(new ExtraStrings());
			extraStrings->load(*i);
			_extraStrings[type] = extraStrings.release();
			_extraStringsIndex.push_back(type);
		}
	}

	_modIndex += 1000;
}