Hooks
static bool BeforeCvPlot_changeVisibilityCount(CvPlot* self, TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisible, bool bInformExplorationTracking, bool bAlwaysSeeInvisible, CvUnit* pUnit, PlotVisibilityChangeResult& result);static void AfterCvPlot_changeVisibilityCount(CvPlot* self, TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisible, bool bInformExplorationTracking, bool bAlwaysSeeInvisible, CvUnit* pUnit, PlotVisibilityChangeResult& result);static PlotVisibilityChangeResult ReplaceCvPlot_changeVisibilityCount(PlotVisibilityChangeResult (*original)(CvPlot*, TeamTypes, int, InvisibleTypes, bool, bool, CvUnit*), CvPlot* self, TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisible, bool bInformExplorationTracking, bool bAlwaysSeeInvisible, CvUnit* pUnit);CivRegisterBefore<CivHooks::CvPlot_changeVisibilityCount>(host, &BeforeCvPlot_changeVisibilityCount);CivRegisterAfter<CivHooks::CvPlot_changeVisibilityCount>(host, &AfterCvPlot_changeVisibilityCount);CivRegisterReplace<CivHooks::CvPlot_changeVisibilityCount>(host, &ReplaceCvPlot_changeVisibilityCount);
Code
8736#if defined(MOD_API_EXTENSIONS)8737PlotVisibilityChangeResult CvPlot::changeVisibilityCount(TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisible, bool bInformExplorationTracking, bool bAlwaysSeeInvisible, CvUnit* pUnit)8738#else8739PlotVisibilityChangeResult CvPlot::changeVisibilityCount(TeamTypes eTeam, int iChange, InvisibleTypes eSeeInvisible, bool bInformExplorationTracking, bool bAlwaysSeeInvisible)8740#endif8741{8742 CvCity* pCity;8743 CvPlot* pAdjacentPlot;8744 bool bOldVisible;87458746 CvAssertMsg(eTeam >= 0, "eTeam is expected to be non-negative (invalid Index)");8747 CvAssertMsg(eTeam < MAX_TEAMS, "eTeam is expected to be within maximum bounds (invalid Index)");87488749 PlotVisibilityChangeResult eResult = VISIBILTY_CHANGE_NONE;8750 if(iChange != 0)8751 {8752 bOldVisible = isVisible(eTeam);87538754 m_aiVisibilityCount[eTeam] += iChange;8755 CvAssertFmt(m_aiVisibilityCount[eTeam]>=0, "Changing plot X:%d, Y:%d to a negative visibility", getX(), getY());8756 if (m_aiVisibilityCount[eTeam] < 0)8757 m_aiVisibilityCount[eTeam] = 0;87588759 if(eSeeInvisible != NO_INVISIBLE)8760 {8761 changeInvisibleVisibilityCount(eTeam, eSeeInvisible, iChange);8762 }87638764 if(bAlwaysSeeInvisible)8765 {8766 for(int iI = 0; iI < NUM_INVISIBLE_TYPES; iI++)8767 {8768 changeInvisibleVisibilityCount(eTeam, (InvisibleTypes) iI, iChange);8769 }8770 }87718772 if(bOldVisible != isVisible(eTeam))8773 {8774 // We couldn't see the Plot before but we can now8775 if(isVisible(eTeam))8776 {8777 eResult = VISIBILITY_CHANGE_TO_VISIBLE;8778 bool bOldRevealed = isRevealed(eTeam);8779#if defined(MOD_API_EXTENSIONS)8780 if (!setRevealed(eTeam, true, pUnit)) // Change to revealed, returns true if the visibility was changed8781#else8782 if (!setRevealed(eTeam, true)) // Change to revealed, returns true if the visibility was changed8783#endif8784 {8785 // The visibility was not changed because it was already revealed, but we are changing to a visible state as well, so we must update.8786 // Just trying to avoid redundant messages.8787 if (eTeam == GC.getGame().getActiveTeam())8788 {8789 updateSymbols();8790 updateFog(true);8791 updateVisibility();8792 }8793 }87948795 if(bInformExplorationTracking && !bOldRevealed)8796 {8797 // slewis - ghetto-tastic hack. ugh8798 for(int iI = 0; iI < MAX_PLAYERS; iI++)8799 {8800 CvPlayerAI& playerI = GET_PLAYER((PlayerTypes)iI);8801 if(playerI.isAlive())8802 {8803 if(playerI.getTeam() == eTeam)8804 {8805 playerI.GetEconomicAI()->m_bExplorationPlotsDirty = true;8806 }8807 }8808 }8809 }88108811 for(int iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)8812 {8813 pAdjacentPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));88148815 if(pAdjacentPlot != NULL)8816 {8817 pAdjacentPlot->updateRevealedOwner(eTeam);8818 }8819 }88208821 // If there are any Units here, meet their owners8822 for(int iUnitLoop = 0; iUnitLoop < getNumUnits(); iUnitLoop++)8823 {8824 // If the AI spots a human Unit, don't meet - wait for the human to find the AI8825 CvUnit* loopUnit = getUnitByIndex(iUnitLoop);88268827 if(!loopUnit) continue;88288829 if(!GET_TEAM(eTeam).isHuman() && loopUnit->isHuman())8830 {8831 continue;8832 }88338834 GET_TEAM(eTeam).meet(loopUnit->getTeam(), false);8835 }88368837 // If there's a City here, meet its owner8838 if(isCity())8839 {8840 // If the AI spots a human City, don't meet - wait for the human to find the AI8841 if(GET_TEAM(eTeam).isHuman() || !getPlotCity()->isHuman())8842 {8843 GET_TEAM(eTeam).meet(getTeam(), false); // If there's a City here, we can assume its owner is the same as the plot owner8844 }8845 }8846 }8847 else8848 {8849 eResult = VISIBILITY_CHANGE_TO_INVISIBLE;8850 if(eTeam == GC.getGame().getActiveTeam())8851 updateFog(true);8852 }88538854 pCity = getPlotCity();88558856 if(eTeam == GC.getGame().getActiveTeam())8857 {8858 //updateFog();8859 updateCenterUnit();8860 }8861 }8862 }88638864 return eResult;8865}