コード例 #1
0
ファイル: SpaceStation.cpp プロジェクト: abramhindle/pioneer
// Fill the list of starships on sale. Ships that
// can't fit atmo shields are only available in
// atmosphereless environments
void SpaceStation::UpdateShipyard()
{
	bool atmospheric = false;
	if (IsGroundStation()) {
		Body *planet = GetFrame()->GetBody();
		atmospheric = planet->GetSystemBody()->HasAtmosphere();
	}

	const std::vector<ShipType::Id> &ships = atmospheric ? ShipType::playable_atmospheric_ships : ShipType::player_ships;

	unsigned int toAdd = 0, toRemove = 0;

	if (m_shipsOnSale.size() == 0)
		// fill shipyard
		toAdd = Pi::rng.Int32(20);

	else if (Pi::rng.Int32(2))
		// add one
		toAdd = 1;

	else if(m_shipsOnSale.size() > 0)
		// remove one
		toRemove = 1;

	else
		// nothing happens
		return;

	for (; toAdd > 0; toAdd--) {
		ShipType::Id id = ships[Pi::rng.Int32(ships.size())];
		std::string regId = Ship::MakeRandomLabel();
		SceneGraph::ModelSkin skin;
		skin.SetRandomColors(Pi::rng);
		skin.SetPattern(Pi::rng.Int32(0, Pi::FindModel(id)->GetNumPatterns()));
		skin.SetLabel(regId);
		ShipOnSale sos(id, regId, skin);
		m_shipsOnSale.push_back(sos);
	}

	for (; toRemove > 0; toRemove--) {
		int pos = Pi::rng.Int32(m_shipsOnSale.size());
		m_shipsOnSale.erase(m_shipsOnSale.begin() + pos);
	}

	onShipsForSaleChanged.emit();
}
コード例 #2
0
ファイル: CityOnPlanet.cpp プロジェクト: tnicoll/pioneer
//static
void CityOnPlanet::SetCityModelPatterns(const SystemPath &path)
{
	Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED };
	Random rand(_init, 5);

	typedef std::set<SceneGraph::Model*, ModelNameComparator> ModelSet;
	typedef ModelSet::iterator TSetIter;
	ModelSet modelSet;
	for (unsigned int i=0; i<COUNTOF(s_buildingLists); i++) {
		for (unsigned int j=0; j < s_buildingLists[i].numBuildings; j++) {
			SceneGraph::Model *m = s_buildingLists[i].buildings[j].resolvedModel;
			modelSet.insert(m);
		}
	}

	SceneGraph::ModelSkin skin;
	for (TSetIter it=modelSet.begin(), itEnd=modelSet.end(); it!=itEnd; ++it) {
		SceneGraph::Model *m = (*it);
		if (!m->SupportsPatterns()) continue;
		skin.SetRandomColors(rand);
		skin.SetPattern(rand.Int32(0, m->GetNumPatterns()));
		skin.Apply(m);
	}
}