void CvDllPythonEvents::reportGameStart() { if (preEvent()) { CyArgsList eventData; eventData.add("GameStart"); // add key to lookup python handler fxn postEvent(eventData); } }
bool CvDllPythonEvents::reportKbdEvent(int evt, int key, int iCursorX, int iCursorY) { if (preEvent()) { NiPoint3 pt3Location; CvPlot* pPlot = gDLL->getEngineIFace()->pickPlot(iCursorX, iCursorY, pt3Location); CyArgsList eventData; eventData.add("kbdEvent"); eventData.add(evt); eventData.add(key); eventData.add(iCursorX); eventData.add(iCursorY); eventData.add(pPlot ? pPlot->getX() : -1); eventData.add(pPlot ? pPlot->getY() : -1); return postEvent(eventData); } return false; }
void CvDllPythonEvents::reportUnitBuilt(CvCity *pCity, CvUnit* pUnit) { if (preEvent()) { CyArgsList eventData; eventData.add("unitBuilt"); // add key to lookup python handler fxn CyCity* pyc = new CyCity(pCity); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyc)); CyUnit* pyu = new CyUnit(pUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyu)); postEvent(eventData); delete pyc; delete pyu; } }
void CvDllPythonEvents::reportCombatLogFlanking(CvUnit* pAttacker, CvUnit* pDefender, int iDamage) { if (preEvent()) { CyArgsList eventData; eventData.add("combatLogFlanking"); // add key to lookup python handler fxn CyUnit* pCyAttacker = new CyUnit(pAttacker); eventData.add(gDLL->getPythonIFace()->makePythonObject(pCyAttacker)); CyUnit* pCyDefender = new CyUnit(pDefender); eventData.add(gDLL->getPythonIFace()->makePythonObject(pCyDefender)); eventData.add(iDamage); postEvent(eventData); delete pCyDefender; delete pCyAttacker; } }
void CvDllPythonEvents::reportGreatPersonBorn( CvUnit *pUnit, PlayerTypes ePlayer, CvCity *pCity ) { if (preEvent()) { CyArgsList eventData; eventData.add("greatPersonBorn"); // add key to lookup python handler fxn CyUnit* py = new CyUnit(pUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(py)); eventData.add((int)ePlayer); CyCity* pyu = new CyCity(pCity); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyu)); postEvent(eventData); delete py; delete pyu; } }
int CvMapGenerator::getRiverValueAtPlot(CvPlot* pPlot) { CvPlot* pAdjacentPlot; CvRandom riverRand; int iSum; int iI; FAssert(pPlot != NULL); long result = 0; CyPlot kPlot = CyPlot(pPlot); CyArgsList argsList; argsList.add(gDLL->getPythonIFace()->makePythonObject(&kPlot)); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getRiverAltitude", argsList.makeFunctionArgs(), &result)) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override { if (result >= 0) { return result; } else { FAssertMsg(false, "python getRiverAltitude() must return >= 0"); } } } iSum = result; iSum += ((NUM_PLOT_TYPES - pPlot->getPlotType()) * 20); for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++) { pAdjacentPlot = plotDirection(pPlot->getX_INLINE(), pPlot->getY_INLINE(), ((DirectionTypes)iI)); if (pAdjacentPlot != NULL) { iSum += (NUM_PLOT_TYPES - pAdjacentPlot->getPlotType()); } else { iSum += (NUM_PLOT_TYPES * 10); } } riverRand.init((pPlot->getX_INLINE() * 43251267) + (pPlot->getY_INLINE() * 8273903)); iSum += (riverRand.get(10, "River Rand")); return iSum; }
void CvDllPythonEvents::reportUnitSetXY(CvPlot* pPlot, CvUnit* pUnit) { if (preEvent()) { if(GC.getUSE_ON_UNIT_SET_XY_CALLBACK()) { CyArgsList eventData; eventData.add("unitSetXY"); // add key to lookup python handler fxn CyPlot* py = new CyPlot(pPlot); eventData.add(gDLL->getPythonIFace()->makePythonObject(py)); CyUnit* pyu = new CyUnit(pUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyu)); postEvent(eventData); delete py; delete pyu; } } }
void CvDllPythonEvents::reportGoodyReceived(PlayerTypes ePlayer, CvPlot *pGoodyPlot, CvUnit *pGoodyUnit, GoodyTypes eGoodyType) { if (preEvent()) { CyArgsList eventData; eventData.add("goodyReceived"); // add key to lookup python handler fxn eventData.add((int)ePlayer); CyPlot* py = new CyPlot(pGoodyPlot); eventData.add(gDLL->getPythonIFace()->makePythonObject(py)); CyUnit* pyu = new CyUnit(pGoodyUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyu)); eventData.add((int) eGoodyType); postEvent(eventData); delete py; delete pyu; } }
void CvDllPythonEvents::reportUnitMove(CvPlot* pPlot, CvUnit* pUnit, CvPlot* pOldPlot) { if (preEvent()) { CyArgsList eventData; eventData.add("unitMove"); // add key to lookup python handler fxn CyPlot* py = new CyPlot(pPlot); eventData.add(gDLL->getPythonIFace()->makePythonObject(py)); CyUnit* pyu = new CyUnit(pUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyu)); CyPlot* pyOld = new CyPlot(pOldPlot); eventData.add(gDLL->getPythonIFace()->makePythonObject(pyOld)); postEvent(eventData); delete py; delete pyu; delete pyOld; } }
void CvDllPythonEvents::reportSelectionGroupPushMission(CvSelectionGroup* pSelectionGroup, MissionTypes eMission) { if (NULL == pSelectionGroup) { return; } if (preEvent()) { CyArgsList eventData; eventData.add("selectionGroupPushMission"); // add key to lookup python handler fxn eventData.add(pSelectionGroup->getOwner()); eventData.add(eMission); int iNumUnits = pSelectionGroup->getNumUnits(); eventData.add(iNumUnits); int* aiUnitIds = new int[iNumUnits]; CLLNode<IDInfo>* pUnitNode = pSelectionGroup->headUnitNode(); for (int i = 0; pUnitNode; i++) { CvUnit* pLoopUnit = ::getUnit(pUnitNode->m_data); pUnitNode = pSelectionGroup->nextUnitNode(pUnitNode); aiUnitIds[i] = pLoopUnit->getID(); FAssert(i < iNumUnits); } if (aiUnitIds) { eventData.add(aiUnitIds, iNumUnits); } postEvent(eventData); delete aiUnitIds; } }
bool CvDllPythonEvents::postEvent(CyArgsList& eventData) { eventData.add(GC.getGameINLINE().isDebugMode()); eventData.add(false); eventData.add(gDLL->altKey()); eventData.add(gDLL->ctrlKey()); eventData.add(gDLL->shiftKey()); eventData.add(gDLL->getChtLvl() > 0); long lResult = -1; bool bOK = gDLL->getPythonIFace()->callFunction(PYEventModule, "onEvent", eventData.makeFunctionArgs(), &lResult); return (bOK && lResult==1); }
void CvDllPythonEvents::reportUnitPillage(CvUnit* pUnit, ImprovementTypes eImprovement, RouteTypes eRoute, PlayerTypes ePlayer, int iPillagedGold) { if (preEvent()) { CyArgsList eventData; eventData.add("unitPillage"); // add key to lookup python handler fxn CyUnit* pCyUnit = new CyUnit(pUnit); eventData.add(gDLL->getPythonIFace()->makePythonObject(pCyUnit)); eventData.add((int) eImprovement); eventData.add((int) eRoute); eventData.add((int) ePlayer); eventData.add((int) iPillagedGold); postEvent(eventData); delete pCyUnit; } }
void CvMapGenerator::addBonuses() { PROFILE("CvMapGenerator::addBonuses"); gDLL->NiTextOut("Adding Bonuses..."); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "addBonuses", NULL)) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) { return; // Python override } } for (int iOrder = 0; iOrder < GC.getNumBonusInfos(); iOrder++) { for (int iI = 0; iI < GC.getNumBonusInfos(); iI++) { gDLL->callUpdater(); if (GC.getBonusInfo((BonusTypes)iI).getPlacementOrder() == iOrder) { CyArgsList argsList; argsList.add(iI); if (!gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "addBonusType", argsList.makeFunctionArgs()) || gDLL->getPythonIFace()->pythonUsingDefaultImpl()) { if (GC.getBonusInfo((BonusTypes)iI).isOneArea()) { addUniqueBonusType((BonusTypes)iI); } else { addNonUniqueBonusType((BonusTypes)iI); } } } } } }
bool CvDllPythonEvents::reportMouseEvent(int evt, int iCursorX, int iCursorY, bool bInterfaceConsumed) { if (preEvent()) { NiPoint3 pt3Location; CvPlot* pPlot = gDLL->getEngineIFace()->pickPlot(iCursorX, iCursorY, pt3Location); CyArgsList eventData; eventData.add("mouseEvent"); // add key to lookup python handler fxn eventData.add(evt); eventData.add(iCursorX); eventData.add(iCursorY); eventData.add(pPlot ? pPlot->getX() : -1); eventData.add(pPlot ? pPlot->getY() : -1); eventData.add(bInterfaceConsumed); // add list of active screens std::vector<int> screens; gDLL->getInterfaceIFace()->getInterfaceScreenIdsForInput(screens); eventData.add(screens.size() ? &screens[0] : NULL, screens.size()); return postEvent(eventData); } return false; }
// pStartPlot = the plot at whose SE corner the river is starting // void CvMapGenerator::doRiver(CvPlot *pStartPlot, CardinalDirectionTypes eLastCardinalDirection, CardinalDirectionTypes eOriginalCardinalDirection, int iThisRiverID) { if (iThisRiverID == -1) { iThisRiverID = GC.getMapINLINE().getNextRiverID(); GC.getMapINLINE().incrementNextRiverID(); } int iOtherRiverID = pStartPlot->getRiverID(); if (iOtherRiverID != -1 && iOtherRiverID != iThisRiverID) { return; // Another river already exists here; can't branch off of an existing river! } CvPlot *pRiverPlot = NULL; CvPlot *pAdjacentPlot = NULL; CardinalDirectionTypes eBestCardinalDirection = NO_CARDINALDIRECTION; if (eLastCardinalDirection==CARDINALDIRECTION_NORTH) { pRiverPlot = pStartPlot; if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if ((pAdjacentPlot == NULL) || pRiverPlot->isWOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setWOfRiver(true, eLastCardinalDirection); pRiverPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_NORTH); } else if (eLastCardinalDirection==CARDINALDIRECTION_EAST) { pRiverPlot = plotCardinalDirection(pStartPlot->getX_INLINE(), pStartPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if ((pAdjacentPlot == NULL) || pRiverPlot->isNOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setNOfRiver(true, eLastCardinalDirection); } else if (eLastCardinalDirection==CARDINALDIRECTION_SOUTH) { pRiverPlot = plotCardinalDirection(pStartPlot->getX_INLINE(), pStartPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if ((pAdjacentPlot == NULL) || pRiverPlot->isWOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setWOfRiver(true, eLastCardinalDirection); } else if (eLastCardinalDirection==CARDINALDIRECTION_WEST) { pRiverPlot = pStartPlot; if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if ((pAdjacentPlot == NULL) || pRiverPlot->isNOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setNOfRiver(true, eLastCardinalDirection); pRiverPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_WEST); } else { //FAssertMsg(false, "Illegal direction type"); // River is starting here, set the direction in the next step pRiverPlot = pStartPlot; long result = 0; CyPlot kPlot = CyPlot(pRiverPlot); CyArgsList argsList; argsList.add(gDLL->getPythonIFace()->makePythonObject(&kPlot)); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getRiverStartCardinalDirection", argsList.makeFunctionArgs(), &result)) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override { if (result >= 0) { eBestCardinalDirection = ((CardinalDirectionTypes)result); } else { FAssertMsg(false, "python getRiverStartCardinalDirection() must return >= 0"); } } } } if (pRiverPlot == NULL) { return; // The river has flowed off the edge of the map. All is well. } else if (pRiverPlot->hasCoastAtSECorner()) { return; // The river has flowed into the ocean. All is well. } if (eBestCardinalDirection == NO_CARDINALDIRECTION) { int iBestValue = MAX_INT; for (int iI = 0; iI < NUM_CARDINALDIRECTION_TYPES; iI++) { if (getOppositeCardinalDirection((CardinalDirectionTypes)iI) != eOriginalCardinalDirection) { if (getOppositeCardinalDirection((CardinalDirectionTypes)iI) != eLastCardinalDirection) { CvPlot* pAdjacentPlot; pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), ((CardinalDirectionTypes)iI)); if (pAdjacentPlot != NULL) { int iValue = getRiverValueAtPlot(pAdjacentPlot); if (iValue < iBestValue) { iBestValue = iValue; eBestCardinalDirection = (CardinalDirectionTypes)iI; } } } } } } if (eBestCardinalDirection != NO_CARDINALDIRECTION) { if (eOriginalCardinalDirection == NO_CARDINALDIRECTION) { eOriginalCardinalDirection = eBestCardinalDirection; } doRiver(pRiverPlot, eBestCardinalDirection, eOriginalCardinalDirection, iThisRiverID); } }
bool CvMapGenerator::canPlaceBonusAt(BonusTypes eBonus, int iX, int iY, bool bIgnoreLatitude) { PROFILE_FUNC(); CvArea* pArea; CvPlot* pPlot; CvPlot* pLoopPlot; int iRange; int iDX, iDY; int iI; pPlot = GC.getMapINLINE().plotINLINE(iX, iY); pArea = pPlot->area(); if (!(pPlot->canHaveBonus(eBonus, bIgnoreLatitude))) { return false; } long result = 0; CyPlot kPlot = CyPlot(pPlot); CyArgsList argsList; argsList.add(gDLL->getPythonIFace()->makePythonObject(&kPlot)); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "canPlaceBonusAt", argsList.makeFunctionArgs(), &result)) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) { if (result >= 0) { return result; } else { FAssertMsg(false, "canPlaceBonusAt() must return >= 0"); } } } for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++) { pLoopPlot = plotDirection(iX, iY, ((DirectionTypes)iI)); if (pLoopPlot != NULL) { if ((pLoopPlot->getBonusType() != NO_BONUS) && (pLoopPlot->getBonusType() != eBonus)) { return false; } } } CvBonusInfo& pInfo = GC.getBonusInfo(eBonus); CvBonusClassInfo& pClassInfo = GC.getBonusClassInfo((BonusClassTypes) pInfo.getBonusClassType()); if (pPlot->isWater()) { if (((GC.getMapINLINE().getNumBonusesOnLand(eBonus) * 100) / (GC.getMapINLINE().getNumBonuses(eBonus) + 1)) < pInfo.getMinLandPercent()) { return false; } } // Make sure there are no bonuses of the same class (but a different type) nearby: iRange = pClassInfo.getUniqueRange(); for (iDX = -(iRange); iDX <= iRange; iDX++) { for (iDY = -(iRange); iDY <= iRange; iDY++) { pLoopPlot = plotXY(iX, iY, iDX, iDY); if (pLoopPlot != NULL) { if (pLoopPlot->area() == pArea) { if (plotDistance(iX, iY, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()) <= iRange) { BonusTypes eOtherBonus = pLoopPlot->getBonusType(); if (eOtherBonus != NO_BONUS) { if (GC.getBonusInfo(eOtherBonus).getBonusClassType() == pInfo.getBonusClassType()) { return false; } } } } } } } // Make sure there are none of the same bonus nearby: iRange = pInfo.getUniqueRange(); for (iDX = -(iRange); iDX <= iRange; iDX++) { for (iDY = -(iRange); iDY <= iRange; iDY++) { pLoopPlot = plotXY(iX, iY, iDX, iDY); if (pLoopPlot != NULL) { if (pLoopPlot->area() == pArea) { if (plotDistance(iX, iY, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()) <= iRange) { if (pLoopPlot->getBonusType() == eBonus) { return false; } } } } } } return true; }
bool CvMapGenerator::canPlaceGoodyAt(ImprovementTypes eImprovement, int iX, int iY) { PROFILE_FUNC(); CvPlot* pPlot; FAssertMsg(eImprovement != NO_IMPROVEMENT, "Improvement is not assigned a valid value"); FAssertMsg(GC.getImprovementInfo(eImprovement).isGoody(), "ImprovementType eImprovement is expected to be a goody"); if (GC.getGameINLINE().isOption(GAMEOPTION_NO_GOODY_HUTS)) { return false; } pPlot = GC.getMapINLINE().plotINLINE(iX, iY); if (!(pPlot->canHaveImprovement(eImprovement, NO_TEAM))) { return false; } long result = 0; CyPlot kPlot = CyPlot(pPlot); CyArgsList argsList; argsList.add(gDLL->getPythonIFace()->makePythonObject(&kPlot)); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "canPlaceGoodyAt", argsList.makeFunctionArgs(), &result)) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override { if (result >= 0) { return result; } else { FAssertMsg(false, "python canPlaceGoodyAt() must return >= 0"); } } } if (pPlot->getImprovementType() != NO_IMPROVEMENT) { return false; } if (pPlot->getBonusType() != NO_BONUS) { return false; } if (pPlot->isImpassable()) { return false; } int iUniqueRange = GC.getImprovementInfo(eImprovement).getGoodyUniqueRange(); for (int iDX = -iUniqueRange; iDX <= iUniqueRange; iDX++) { for (int iDY = -iUniqueRange; iDY <= iUniqueRange; iDY++) { CvPlot *pLoopPlot = plotXY(iX, iY, iDX, iDY); if (pLoopPlot != NULL && pLoopPlot->getImprovementType() == eImprovement) { return false; } } } return true; }