Ejemplo n.º 1
0
    void HealthHelper::updatePowerHealth(const CityData& cityData)
    {
        if (cityData.getBuildingsHelper()->isPower())
        {
            if (POWER_HEALTH_CHANGE_ > 0)
            {
                powerGoodHealth_ = POWER_HEALTH_CHANGE_;
            }
            else
            {
                powerBadHealth_ = POWER_HEALTH_CHANGE_;
            }
        }

        if (cityData.getBuildingsHelper()->isDirtyPower())
        {
            if (DIRTY_POWER_HEALTH_CHANGE_ > 0)
            {
                powerGoodHealth_ += DIRTY_POWER_HEALTH_CHANGE_;
            }
            else
            {
                powerBadHealth_ += DIRTY_POWER_HEALTH_CHANGE_;
            }
        }
    }
Ejemplo n.º 2
0
/// Update the settle target information when a city grows
/// \param city The city
void SettleMap::HandleCityGrowth(const Unit & city)
{
	Assert(city.IsValid());
	MapPoint        cityPos     = city.RetPos();
	CityData *      citydata    = city.GetCityData();
	PLAYER_INDEX    playerId    = city.GetOwner();
	sint32          radius      = g_theCitySizeDB->Get(citydata->GetSizeIndex())->GetIntRadius();
	/// @todo Check functionality. Using "2 * current radius + 1" looks arbitrary.
	/// This does not account for future growth (city spacing may become too tight), but it also
	/// prevents any overlap.
	radius += radius + 1;
	
	// Mark tiles near to the grown city as not worth to settle at all
	RadiusIterator it(cityPos, radius);
	for (it.Start(); !it.End(); it.Next()) 
	{
		MapPoint    clearPos = it.Pos();
		m_invalidCells.Set(clearPos.x, clearPos.y, TRUE);
	}

	
	const StrategyRecord & strategy = Diplomat::GetDiplomat(playerId).GetCurrentStrategy();
	sint32                  min_settle_distance = 0;
	strategy.GetMinSettleDistance(min_settle_distance);

	// Mark tiles further away as having only half the usual value
	/// \todo Optimise using CircleIterator, to skip computing values for the already invalidated tiles.
	RadiusIterator settleIt(cityPos, min_settle_distance);
	for (settleIt.Start(); !settleIt.End(); settleIt.Next()) 
	{
		MapPoint        claimPos    = settleIt.Pos();
		double const    new_value   = ComputeSettleValue(claimPos) * 0.5;
		m_settleValues.SetGridValue(claimPos, new_value);
	}
	
	MapAnalysis::GetMapAnalysis().UpdateBoundingRectangle(city);
}
Ejemplo n.º 3
0
void gslog_LogPlayerStats(sint32 player)
{
#ifndef _BFR_
	if(!g_theProfileDB->GetEnableLogs())
		return;

	Player *pl = g_player[player];

	if (!pl) return;


	gslog_print("[Player %d] [Turn %d]\n", player, pl->m_current_round);


	sint32 totalFood = 0, totalFoodCrime = 0, totalFoodConsumed = 0;

	UnitDynamicArray *cityList = pl->GetAllCitiesList();
	sint32 cityIndex;


	for (cityIndex = 0; cityIndex < cityList->Num(); cityIndex++)
    {
		CityData * cityData = (*cityList)[cityIndex].GetData()->GetCityData();

		sint32 foodCrime = 0;
		cityData->GetFoodCrime(foodCrime);

		totalFood           += cityData->GetGrossCityFood();
		totalFoodCrime      += foodCrime;
		totalFoodConsumed   += static_cast<sint32>(cityData->GetConsumedFood());
	}

	sint32 percentFoodCrime = totalFood ?
		((totalFoodCrime * 100) / totalFood) : 0;
	sint32 percentFoodConsumed = totalFood ?
		((totalFoodConsumed * 100) / totalFood) : 0;
	sint32 percentFoodStored = 100 - (percentFoodCrime + percentFoodConsumed);

	gslog_print("  Food Total: %d\n", totalFood);
	gslog_print("  Food Crime: %d (%d%%):\n", totalFoodCrime, percentFoodCrime);
	gslog_print("  Food Consumed: %d (%d%%)\n", totalFoodConsumed, percentFoodConsumed);
	gslog_print("  Food Stored: %d (%d%%)\n", totalFood - (totalFoodConsumed + totalFoodCrime), percentFoodStored);


	sint32 totalProduction = 0, totalProductionCrime = 0,
		totalProductionUnitUpkeep = 0, totalProductionPublicWorks = 0;




	for (cityIndex = 0; cityIndex < cityList->Num(); cityIndex++)
    {
		CityData *cityData = (*cityList)[cityIndex].GetData()->GetCityData();

		totalProduction             += cityData->GetGrossCityProduction();
		totalProductionCrime        += cityData->GetProdCrime();
		totalProductionPublicWorks  += cityData->ComputeMaterialsPaid(pl->m_materialsTax);
	}

	totalProductionUnitUpkeep = pl->GetReadinessCost();

	sint32 percentProductionCrime = totalProduction ?
		((totalProductionCrime * 100) / totalProduction) : 0;
	sint32 percentProductionUnitUpkeep = totalProduction ?
		((totalProductionUnitUpkeep * 100) / totalProduction) : 0;
	sint32 percentProductionPublicWorks = totalProduction ?
		((totalProductionPublicWorks * 100) / totalProduction) : 0;
#if 0   // Unused
	sint32 percentProductionCityUse = 100 - (percentProductionCrime +
		percentProductionUnitUpkeep + totalProductionPublicWorks);
#endif

	gslog_print("  Total Production: %d\n", totalProduction);
	gslog_print("  Production Crime: %d (%d%%)\n", totalProductionCrime, percentProductionCrime);
	gslog_print("  Production Unit Upkeep: %d (%d%%)\n", totalProductionUnitUpkeep, percentProductionUnitUpkeep);
	gslog_print("  Production PW: %d (%d%%)\n", totalProductionPublicWorks, percentProductionPublicWorks);

	sint32 totalCommerce = 0, totalCommerceCrime = 0,
		totalCommerceWages = 0, totalCommerceBuildingUpkeep = 0,
		totalCommerceScience = 0, totalTrade = 0;


	sint32  wonderReduction = wonderutil_GetDecreaseMaintenance(pl->GetBuiltWonders());
	for (cityIndex = 0; cityIndex < cityList->Num(); cityIndex++)
	{
		CityData *cityData = (*cityList)[cityIndex].GetData()->GetCityData();

		sint32 commerceBuildingUpkeep = buildingutil_GetTotalUpkeep
		    (cityData->GetImprovements(), wonderReduction, cityData->GetOwner()); //EMOD added owner

		totalCommerce               += cityData->GetGrossCityGold();
		totalCommerceCrime          += cityData->GetTradeCrime();
		totalCommerceWages          += cityData->CalcWages();
		totalCommerceBuildingUpkeep += commerceBuildingUpkeep;
		totalCommerceScience        += cityData->GetScience();
		totalTrade                  += cityData->GetNetCityGold();
	}

	sint32 percentCommerceCrime = totalCommerce ?
		((totalCommerceCrime * 100) / totalCommerce) : 0;
	sint32 percentCommerceWages = totalCommerce ?
		((totalCommerceWages * 100) / totalCommerce) : 0;
	sint32 percentCommerceBuildingUpkeep = totalCommerce ?
		((totalCommerceBuildingUpkeep * 100) / totalCommerce) : 0;
	sint32 percentCommerceScience = totalCommerce ?
		((totalCommerceScience * 100) / totalCommerce) : 0;
	sint32 percentCommerceSavings = 100 - (percentCommerceCrime +
		percentCommerceWages + percentCommerceBuildingUpkeep +
		percentCommerceScience);

	gslog_print("  Total Commerce: %d\n", totalCommerce);
	gslog_print("  Total Commerce After Science: %d\n", totalCommerce - totalCommerceScience);
	gslog_print("  Commerce Crime: %d (%d%%)\n", totalCommerceCrime, percentCommerceCrime);
	gslog_print("  Commerce Wages: %d (%d%%)\n", totalCommerceWages, percentCommerceWages);
	gslog_print("  Commerce Building Upkeep: %d (%d%%)\n", totalCommerceBuildingUpkeep, percentCommerceBuildingUpkeep);
	gslog_print("  Commerce Science: %d (%d%%):\n", totalCommerceScience, percentCommerceScience);
	gslog_print("  Commerce Savings %%: %d\n", percentCommerceSavings);
	gslog_print("  Net Trade: %d\n", totalTrade);

	gslog_print("  Total accumulated science: %d\n", pl->m_science->GetLevel());

	sint32 riot, content, happy;
	sint32 totalCities = g_player[player]->CountCityHappiness(riot, content, happy);
	gslog_print("  Total cities: %d\n", totalCities);
	gslog_print("    Rioting: %d\n", riot);
	gslog_print("    Content: %d\n", content);
	gslog_print("    Happy: %d\n", happy);

	sint32 pop = 0;
	sint32 partialPop = 0;
	sint32 i;
	for(i = 0; i < g_player[player]->m_all_cities->Num(); i++) {
		pop += g_player[player]->m_all_cities->Access(i).PopCount();
		partialPop += g_player[player]->m_all_cities->Access(i).CD()->GetPartialPopulation();
	}

	sint32 totalPartialPop = (pop * k_PEOPLE_PER_POPULATION) + partialPop;
	gslog_print("  Total population: %d/%d, +%d\n", pop, totalPartialPop, totalPartialPop - s_populationHack[player]);
	s_populationHack[player] = totalPartialPop;

	sint32 totalUnits = g_player[player]->m_all_units->Num();
	sint32 totalMilUnits = 0;
	sint32 totalOffense = 0;

	for(i = 0; i < totalUnits; i++) {
		const UnitRecord *rec = g_player[player]->m_all_units->Access(i).GetDBRec();
		if(rec->GetAttack() > 0.001) {
			totalMilUnits++;
			totalOffense += (sint32)rec->GetAttack();
		}
	}
	gslog_print("  Total Units: %d\n", totalUnits);
	gslog_print("  Total Military Units: %d\n", totalMilUnits);
	gslog_print("  Total Attack Strength: %d\n", totalOffense);

	double s;
	g_player[player]->m_tax_rate->GetScienceTaxRate(s);
	gslog_print("  Settings:\n");
	gslog_print("     Science Tax: %d\n", AsPercentage(s));
	gslog_print("              PW: %d\n", sint32(g_player[player]->m_materialsTax * 100));
	gslog_print("         Workday: %d\n", g_player[player]->m_global_happiness->GetUnitlessWorkday());
	gslog_print("           Wages: %d\n", g_player[player]->m_global_happiness->GetUnitlessWages());
	gslog_print("         Rations: %d\n", g_player[player]->m_global_happiness->GetUnitlessRations());

	gslog_print("  Current research: %s\n", g_theAdvanceDB->Get(g_player[player]->m_advances->GetResearching())->GetNameText());

#endif
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------------
//
// Name       : UnseenCell::UnseenCell
//
// Description: Constructor
//
// Parameters : point			: The point (RC coordinate)
//
// Globals    : g_theWorld		: World information
//
// Returns    : -
//
// Remark(s)  : The constructor to use normally.
//
//----------------------------------------------------------------------------
UnseenCell::UnseenCell(const MapPoint & point)
:
	m_env                           (0),
	m_terrain_type                  (TERRAIN_UNKNOWN),
	m_move_cost                     (MOVECOST_UNKNOWN),
	m_flags                         (0x0000),
	m_bioInfectedOwner              (0x00), /// @todo Check PLAYER_UNASSIGNED?
	m_nanoInfectedOwner             (0x00),
	m_convertedOwner                (0x00),
	m_franchiseOwner                (0x00),
	m_injoinedOwner                 (0x00),
	m_happinessAttackOwner          (0x00),
	m_citySize                      (0),
	m_cityOwner                     (0),
	m_citySpriteIndex               (-1),
	m_cell_owner                    (PLAYER_UNASSIGNED),
	m_slaveBits                     (0x0000),
#ifdef BATTLE_FLAGS
	m_battleFlags                   (0),
#endif
	m_tileInfo                      (NULL),
	m_point                         (point),
	m_installations                 (new PointerList<UnseenInstallationInfo>),
	m_improvements                  (new PointerList<UnseenImprovementInfo>),
	m_cityName                      (NULL),
	m_actor                         (NULL),
	m_poolIndex                     (-1),
	m_visibleCityOwner              (0)
{
	if (g_theWorld->GetTileInfo(point))
	{
		m_tileInfo = new TileInfo(g_theWorld->GetTileInfo(point));
	}

	Cell * cell = g_theWorld->GetCell(point);
	if (cell)
	{
		m_env = cell->GetEnv();
		m_move_cost = sint16(cell->GetMoveCost());
		m_terrain_type = (sint8)TERRAIN_TYPES(cell->GetTerrain());
#ifdef BATTLE_FLAGS
		m_battleFlags = cell->GetBattleFlags();
#endif

		sint32 i;

		// Same as well information about existing
		// tile improvments, except roadlike ones,
		// so that this information is available
		// later as well.
		// And in order not to break anythink use the existing
		// list for unfinished tile improvements.
		for(i = 0; i < cell->GetNumDBImprovements(); i++) {
			sint32 imp = cell->GetDBImprovement(i);
			m_improvements->AddTail(new UnseenImprovementInfo(imp, 100));
		}
		for(i = 0; i < cell->GetNumImprovements(); i++) {
			TerrainImprovement imp = cell->AccessImprovement(i);
			if (imp.IsValid())
			{
				m_improvements->AddTail(new UnseenImprovementInfo(imp.GetType(),
															      imp.PercentComplete()));
			}
		}

		DynamicArray<Installation> instArray;
		g_theInstallationTree->GetAt(point, instArray);
		for(i = 0; i < instArray.Num(); i++) {
			m_installations->AddTail(new UnseenInstallationInfo(instArray[i].GetType(),
														       instArray[i].GetVisibility()));
		}

		m_cell_owner = (sint8) cell->GetOwner();

		// Store the city that controlls this tile.
		m_visibleCityOwner = cell->GetCityOwner().m_id;

		Unit    city = cell->GetCity();

		if (city.IsValid())
		{
			m_citySize = (sint16)city.PopCount();
			m_citySpriteIndex = (sint16)city.CD()->GetDesiredSpriteIndex();
			const MBCHAR *name = city.GetName();
			m_cityName = new MBCHAR[strlen(name) + 1];
			strcpy(m_cityName, name);

			m_cityOwner = static_cast<sint16>(city.GetCityData()->GetOwner());

			CityData *cityData = city.GetData()->GetCityData();

			UnitActor *actor = city.GetActor();

			if (actor) {

				SpriteState *newSS = new SpriteState(city.GetSpriteState()->GetIndex());

				UnitActor *newActor = new UnitActor(newSS,
												    city,
												    city.GetType(),
												    point,
												    city.GetOwner(),
												    TRUE,
												    city.GetVisionRange(),
												    city.CD()->GetDesiredSpriteIndex());

				newActor->SetUnitVisibility((1 << g_selected_item->GetVisiblePlayer())
										    | actor->GetUnitVisibility());
				newActor->SetPos(point);

				newActor->SetIsFortified(actor->IsFortified());
				newActor->SetIsFortifying(actor->IsFortifying());
				newActor->SetHasCityWalls(actor->HasCityWalls());
				newActor->SetHasForceField(actor->HasForceField());

				newActor->SetSize(m_citySize);

				newActor->ChangeImage(newSS, city.GetType(), city);

				newActor->AddIdle();
				newActor->GetNextAction();

				m_actor = newActor;
			} // actor

			SetIsBioInfected(cityData->IsBioInfected());
			SetIsNanoInfected(cityData->IsNanoInfected());
			SetIsConverted(cityData->IsConverted());
			SetIsFranchised(cityData->IsFranchised());
			SetIsInjoined(cityData->IsInjoined());
			SetWasHappinessAttacked(cityData->WasHappinessAttacked());
			SetIsRioting(cityData->GetIsRioting());
			SetHasAirport(cityData->HasAirport());
			SetHasSleepingUnits(cityData->HasSleepingUnits());
			SetIsWatchful(cityData->IsWatchful());
			SetIsCapitol(cityData->IsCapitol()); //emod
			SetIsReligionIcon(cityData->HasReligionIcon()); //emod
			m_bioInfectedOwner = (sint8)cityData->GetBioInfectedBy();
			m_nanoInfectedOwner = (sint8)cityData->GetNanoInfectedBy();
			m_convertedOwner = (sint8)cityData->IsConvertedTo();
			m_franchiseOwner = (sint8)cityData->GetFranchiseOwner();
			m_injoinedOwner = (sint8)cityData->InjoinedBy();
			m_happinessAttackOwner = (sint8)cityData->GetHappinessAttackedBy();
			m_slaveBits = cityData->GetSlaveBits();
			SetIsSpecialIcon(cityData->HasSpecialIcon()); //emod

		    sint32 pollution = cityData->GetPollution();
			SetIsPollutionRisk(pollution > g_theConstDB->Get(0)->GetLocalPollutionLevel());

		} // city.IsValid
	} // cell

	SetHasHut(NULL != g_theWorld->GetGoodyHut(point));
}
Ejemplo n.º 5
0
 void updateCityData(CityData& data, const boost::shared_ptr<ResourceInfo>& pResourceInfo, bool isAdding)
 {
     boost::apply_visitor(CityOutputUpdater(data, isAdding), pResourceInfo->getInfo());
     data.recalcOutputs();
 }
Ejemplo n.º 6
0
void NetCity::Unpacketize(uint16 id, uint8* buf, uint16 size)
{
	Assert(buf[0] == 'C' && buf[1] == 'D');
	Unit uid(getlong(&buf[2]));
	sint32 pos;

	if(g_theUnitPool->IsValid(uid)) {
		DPRINTF(k_DBG_NET, ("Net: received city %lx\n", (uint32)uid));
		UnitData* unitData = g_theUnitPool->AccessUnit(uid);
		uint16 unitSize;
		PLAYER_INDEX oldOwner = unitData->m_owner;

		Assert(unitData->m_city_data != NULL);
		if(unitData->m_city_data == NULL) {
			g_network.RequestResync(RESYNC_INVALID_UNIT);
			return;
		}

		NetUnit::UnpacketizeUnit(&buf[6], unitSize, unitData);

		if(oldOwner != unitData->m_owner) {
			g_player[oldOwner]->RemoveCityReferenceFromPlayer(uid, CAUSE_REMOVE_CITY_UNKNOWN, unitData->m_owner);
			g_player[unitData->m_owner]->AddCityReferenceToPlayer(uid, CAUSE_NEW_CITY_UNKNOWN);
		}
		unitData->m_city_data->m_owner = unitData->m_owner;

		pos = 6 + unitSize;
		CityData* cityData = unitData->m_city_data;

		double oldVision = cityData->GetVisionRadius();

		PULLBYTE(m_isInitialPacket);

		bool resync = false;

#define PLCHK(x) { sint32 tmp = x; PULLLONG(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }}
#define PSCHK(x) { sint16 tmp = x; PULLSHORT(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }}
#define PL32CHK(x) { uint32 tmp = x; PULLLONG(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }}
#define PL64CHK(x) { uint64 tmp = x; PULLLONG64(x); if(cityData->GetOwner() == g_network.GetPlayerIndex() && !m_isInitialPacket) { Assert(tmp == x); if(tmp != x) resync = true; }}
		PL32CHK(cityData->m_slaveBits);
		sint32 shieldstore;
		PULLLONG(shieldstore);
		if(cityData->GetOwner() != g_network.GetPlayerIndex() || m_isInitialPacket) {
			cityData->m_shieldstore = shieldstore;
		}
		PLCHK(cityData->m_shieldstore_at_begin_turn);
		PLCHK(cityData->m_net_gold);
		PLCHK(cityData->m_science);
		PLCHK(cityData->m_luxury);
		PULLLONGTYPE(cityData->m_city_attitude, CITY_ATTITUDE);

		PL64CHK(cityData->m_built_improvements);

		sint32 i;
#ifdef CTP1_TRADE
		uint8 numNonZeroResources;
		PULLBYTE(numNonZeroResources);
		cityData->m_resources.Clear();
		for(i = 0; i < numNonZeroResources; i++) {
			uint8 resource;
			uint16 count;
			PULLBYTE(resource);
			PULLSHORT(count);
			cityData->m_resources.SetResourceCount(resource, count);
		}
#endif

		PLCHK(cityData->m_population);
		for(i = 0; i < (sint32)POP_MAX; i++) {
			PSCHK(cityData->m_numSpecialists[i]);
		}

		PLCHK(cityData->m_partialPopulation);
		PLCHK(cityData->m_sizeIndex);
		PLCHK(cityData->m_workerFullUtilizationIndex);
		PLCHK(cityData->m_workerPartialUtilizationIndex);

		PULLDOUBLE(cityData->m_defensiveBonus);
		PULLBYTE(cityData->m_founder);

		UnpacketizeResources(cityData->m_collectingResources, buf, pos);
		UnpacketizeResources(cityData->m_sellingResources, buf, pos);
		UnpacketizeResources(cityData->m_buyingResources, buf, pos);

		for(sint32 r = 0; r < g_theResourceDB->NumRecords(); r++)
		{
			PULLLONG(cityData->m_distanceToGood[r]);
		}

		cityData->UpdateSprite();

		if(resync)
			g_network.RequestResync(RESYNC_CITY_STATS);
		else if (oldVision != cityData->GetVisionRadius())
		{
			unitData->RemoveOldUnitVision(oldVision);
			unitData->AddUnitVision();
		}
	}
}
Ejemplo n.º 7
0
 void updateRequestData(const CvCity* pCity, CityData& data, const boost::shared_ptr<TechInfo>& pTechInfo)
 {
     data.getCivHelper()->addTech(pTechInfo->getTechType());
     boost::apply_visitor(CityOutputUpdater(pCity, data), pTechInfo->getInfo());
     data.recalcOutputs();
 }