Code
1511void CvEconomicAI::LogCityMonitor()1512{1513 if(!(GC.getLogging() && GC.getAILogging()))1514 {1515 return;1516 }15171518 // don't log minor civs for now1519 if(m_pPlayer->isMinorCiv())1520 {1521 return;1522 }15231524 static bool bFirstRun = true;1525 bool bBuildHeader = false;1526 CvString strHeader;1527 if(bFirstRun)1528 {1529 bFirstRun = false;1530 bBuildHeader = true;1531 }15321533 // go through all the plots the player has under their control1534 CvPlotsVector& aiPlots = m_pPlayer->GetPlots();15351536 CvString strLog;15371538 // Find the name of this civ and city1539 CvString strPlayerName;1540 strPlayerName = m_pPlayer->getCivilizationShortDescription();1541 CvString strLogName;15421543 // Open the log file1544 if(GC.getPlayerAndCityAILogSplit())1545 {1546 strLogName = "EconomicCityMonitorLog_" + strPlayerName + ".csv";1547 }1548 else1549 {1550 strLogName = "EconomicCityMonitorLog.csv";1551 }15521553 FILogFile* pLog;1554 pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);15551556 CvString str;15571558 float fRatio;15591560 // per city1561 int iLoopCity = 0;1562 CvCity* pLoopCity = NULL;15631564 FFastVector<int> aiCityYields;1565 aiCityYields.push_back_copy(-1, NUM_YIELD_TYPES);15661567 FFastVector<int> aiSpecialistsYields;1568 aiSpecialistsYields.push_back_copy(-1, NUM_YIELD_TYPES);15691570 for(pLoopCity = m_pPlayer->firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = GetPlayer()->nextCity(&iLoopCity))1571 {1572 for(uint ui = 0; ui < aiCityYields.size(); ui++)1573 {1574 aiCityYields[ui] = 0;1575 }15761577 for(uint ui = 0; ui < aiSpecialistsYields.size(); ui++)1578 {1579 aiSpecialistsYields[ui] = 0;1580 }15811582 strHeader = "";1583 strLog = "";15841585 // civ name1586 AppendToLog(strHeader, strLog, "Civ Name", strPlayerName);15871588 // turn1589 AppendToLog(strHeader, strLog, "Turn", GC.getGame().getGameTurn());15901591 // city name1592 str = pLoopCity->getName();1593 AppendToLog(strHeader, strLog, "City Name", str);15941595 // pop1596 AppendToLog(strHeader, strLog, "Population", pLoopCity->getPopulation());15971598 // total yields1599 for(uint ui = 0; ui < NUM_YIELD_TYPES; ui++)1600 {1601 aiCityYields[ui] = pLoopCity->getYieldRate((YieldTypes)ui, false);1602 switch(ui)1603 {1604 case YIELD_FOOD:1605 AppendToLog(strHeader, strLog, "food", aiCityYields[ui]);1606 break;1607 case YIELD_PRODUCTION:1608 AppendToLog(strHeader, strLog, "production", aiCityYields[ui]);1609 break;1610 case YIELD_SCIENCE:1611 AppendToLog(strHeader, strLog, "science", aiCityYields[ui]);1612 break;1613 case YIELD_GOLD:1614 AppendToLog(strHeader, strLog, "city gold", aiCityYields[ui]);1615 break;1616 case YIELD_CULTURE:1617 AppendToLog(strHeader, strLog, "culture", aiCityYields[ui]);1618 break;1619 case YIELD_FAITH:1620 AppendToLog(strHeader, strLog, "faith", aiCityYields[ui]);1621 break;1622#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)1623 case YIELD_TOURISM:1624 AppendToLog(strHeader, strLog, "tourism", aiCityYields[ui]);1625 break;1626#endif1627#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)1628 case YIELD_GOLDEN_AGE_POINTS:1629 AppendToLog(strHeader, strLog, "goldenage", aiCityYields[ui]);1630 break;1631#endif1632 }1633 }16341635 // yields / pop1636 for(uint ui = 0; ui < NUM_YIELD_TYPES; ui++)1637 {1638 fRatio = 0.0f;1639 if(pLoopCity->getPopulation() > 0)1640 {1641 fRatio = aiCityYields[ui] / (float)pLoopCity->getPopulation();1642 }16431644 switch(ui)1645 {1646 case YIELD_FOOD:1647 AppendToLog(strHeader, strLog, "food / pop", fRatio);1648 break;1649 case YIELD_PRODUCTION:1650 AppendToLog(strHeader, strLog, "production / pop", fRatio);1651 break;1652 case YIELD_SCIENCE:1653 AppendToLog(strHeader, strLog, "science / pop", fRatio);1654 break;1655 case YIELD_GOLD:1656 AppendToLog(strHeader, strLog, "gold / pop", fRatio);1657 break;1658 case YIELD_CULTURE:1659 AppendToLog(strHeader, strLog, "culture / pop", fRatio);1660 break;1661 case YIELD_FAITH:1662 AppendToLog(strHeader, strLog, "faith / pop", fRatio);1663 break;1664#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)1665 case YIELD_TOURISM:1666 AppendToLog(strHeader, strLog, "tourism / pop", fRatio);1667 break;1668#endif1669#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)1670 case YIELD_GOLDEN_AGE_POINTS:1671 AppendToLog(strHeader, strLog, "goldenage / pop", fRatio);1672 break;1673#endif1674 }1675 }16761677 // yields from specialists1678 for(uint ui = 0; ui < NUM_YIELD_TYPES; ui++)1679 {1680 aiSpecialistsYields[ui] = pLoopCity->getExtraSpecialistYield((YieldTypes)ui);1681 switch(ui)1682 {1683 case YIELD_FOOD:1684 AppendToLog(strHeader, strLog, "food specialist", aiSpecialistsYields[ui]);1685 break;1686 case YIELD_PRODUCTION:1687 AppendToLog(strHeader, strLog, "production specialist", aiSpecialistsYields[ui]);1688 break;1689 case YIELD_SCIENCE:1690 AppendToLog(strHeader, strLog, "science specialist", aiSpecialistsYields[ui]);1691 break;1692 case YIELD_GOLD:1693 AppendToLog(strHeader, strLog, "gold specialist", aiSpecialistsYields[ui]);1694 break;1695 case YIELD_CULTURE:1696 AppendToLog(strHeader, strLog, "culture specialist", aiSpecialistsYields[ui]);1697 break;1698 case YIELD_FAITH:1699 AppendToLog(strHeader, strLog, "faith specialist", aiSpecialistsYields[ui]);1700 break;1701#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)1702 case YIELD_TOURISM:1703 AppendToLog(strHeader, strLog, "tourism specialist", aiSpecialistsYields[ui]);1704 break;1705#endif1706#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)1707 case YIELD_GOLDEN_AGE_POINTS:1708 AppendToLog(strHeader, strLog, "goldenage specialist", aiSpecialistsYields[ui]);1709 break;1710#endif1711 }1712 }17131714 // ratio from specialists1715 for(uint ui = 0; ui < NUM_YIELD_TYPES; ui++)1716 {1717 fRatio = 0.0f;1718 if(aiCityYields[ui] > 0)1719 {1720 fRatio = aiSpecialistsYields[ui] / (float)aiCityYields[ui];1721 }1722 switch(ui)1723 {1724 case YIELD_FOOD:1725 AppendToLog(strHeader, strLog, "food specialist / food", fRatio);1726 break;1727 case YIELD_PRODUCTION:1728 AppendToLog(strHeader, strLog, "production specialist / production", fRatio);1729 break;1730 case YIELD_SCIENCE:1731 AppendToLog(strHeader, strLog, "science specialist / science", fRatio);1732 break;1733 case YIELD_GOLD:1734 AppendToLog(strHeader, strLog, "gold specialist / gold", fRatio);1735 break;1736 case YIELD_CULTURE:1737 AppendToLog(strHeader, strLog, "culture specialist / culture", fRatio);1738 break;1739 case YIELD_FAITH:1740 AppendToLog(strHeader, strLog, "faith specialist / faith", fRatio);1741 break;1742#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)1743 case YIELD_TOURISM:1744 AppendToLog(strHeader, strLog, "tourism specialist / tourism", fRatio);1745 break;1746#endif1747#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)1748 case YIELD_GOLDEN_AGE_POINTS:1749 AppendToLog(strHeader, strLog, "goldenage specialist / tourism", fRatio);1750 break;1751#endif1752 }1753 }17541755 // % of worked tiles that are improved1756 // worked tiles1757 int iTiles = 0;1758 int iWorkedTiles = 0;1759 int iImprovedTiles = 0;1760 for(uint uiPlotIndex = 0; uiPlotIndex < aiPlots.size(); uiPlotIndex++)1761 {1762 // when we encounter the first plot that is invalid, the rest of the list will be invalid1763 if(aiPlots[uiPlotIndex] == -1)1764 {1765 break;1766 }17671768 CvPlot* pPlot = GC.getMap().plotByIndex(aiPlots[uiPlotIndex]);1769 if(!pPlot)1770 {1771 continue;1772 }17731774 // plot has city in it, don't count1775 if(pPlot->getPlotCity())1776 {1777 continue;1778 }17791780 if(!pLoopCity->GetCityCitizens()->IsCanWork(pPlot))1781 {1782 continue;1783 }17841785 iTiles++;17861787 if(pPlot->getWorkingCity() == pLoopCity)1788 {1789 iWorkedTiles++;1790 }17911792 if(pPlot->getImprovementType() != NO_IMPROVEMENT)1793 {1794 iImprovedTiles++;1795 }1796 }17971798 AppendToLog(strHeader, strLog, "Tiles", iTiles);1799 AppendToLog(strHeader, strLog, "Worked (non-city) tiles", iWorkedTiles);1800 AppendToLog(strHeader, strLog, "Improved tiles", iImprovedTiles);18011802 // % of worked tiles that are improved1803 // improved / worked tiles1804 fRatio = 0.0f;1805 if(iWorkedTiles > 0)1806 {1807 fRatio = iImprovedTiles / (float)iWorkedTiles;1808 }1809 AppendToLog(strHeader, strLog, "improved / worked", fRatio);18101811 if(bBuildHeader)1812 {1813 bBuildHeader = false;1814 pLog->Msg(strHeader);1815 }1816 pLog->Msg(strLog);1817 }1818}