示例#1
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
}
示例#2
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();
		}
	}
}