Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Design:
- Arr[0] [1] [2] [3] ... [N] => len(Array)=N+1
- Count=N 1st 2nd 3rd ... Nth
- Get(-1) (0) (1) (2) ...(N-1) => for (i=0;i<p->Get(-1);i++) p->Get(i) [...];
- Count=N 1st 2nd 3rd ... Nth Appears like a normal array.
- ======================================================
- CvBuildingInfo::getPrereqOrBonuses()
- ======================================================
- // returns array length when called with -1
- int CvBuildingInfo::getPrereqOrBonuses(int i) const
- {
- FAssertMsg(i < GC.getNUM_BUILDING_PREREQ_OR_BONUSES(), "Index out of bounds");
- if (m_piPrereqOrBonuses)
- {
- int size = m_piPrereqOrBonuses[0];
- if (i == -1) return size;
- if (i < size) return m_piPrereqOrBonuses[i+1];
- return -1;
- }
- return -1;
- }
- ======================================================
- CvBuildingInfo::getCheckSum()
- ======================================================
- if (m_piPrereqOrBonuses) CheckSumI(iSum, m_piPrereqOrBonuses[0]+1, m_piPrereqOrBonuses);
- ======================================================
- CvBuildingInfo::read()
- ======================================================
- if (pXML->TryMoveToXmlFirstChild(L"PrereqBonuses"))
- {
- iNumChildren = pXML->GetXmlChildrenNumber();
- FAssertMsg((iNumChildren <= GC.getNUM_BUILDING_PREREQ_OR_BONUSES()),"Too many Prereq Or Bonuses for the building.");
- int *tmp = new int[iNumChildren];
- int iTotal = 0;
- if (0 < iNumChildren)
- {
- if (pXML->GetChildXmlVal(szTextVal))
- {
- for (j=0; j<iNumChildren; j++)
- {
- int eInfo = pXML->GetInfoClass(szTextVal);
- if (eInfo != -1) tmp[iTotal++] = eInfo;
- if (!pXML->GetNextXmlVal(szTextVal)) break;
- }
- if (iTotal != 0)
- {
- m_piPrereqOrBonuses = new int[iTotal+1];
- m_piPrereqOrBonuses[0] = iTotal;
- for (j=0; j<iTotal; j++) m_piPrereqOrBonuses[j+1] = tmp[j];
- }
- pXML->MoveToXmlParent();
- }
- }
- else SAFE_DELETE_ARRAY(m_piPrereqOrBonuses);
- pXML->MoveToXmlParent();
- }
- else SAFE_DELETE_ARRAY(m_piPrereqOrBonuses);
- ======================================================
- CvBuildingInfo::CopyNonDefaults()
- ======================================================
- int iTotalTheirs = pClassInfo->getPrereqOrBonuses(-1);
- if (iTotalTheirs != -1)
- {
- int iTotalOurs = 0;
- if (m_piPrereqOrBonuses) iTotalOurs = m_piPrereqOrBonuses[0];
- int* tmp = new int[iTotalTheirs+iTotalOurs+1];
- tmp[0] = iTotalTheirs+iTotalOurs;
- for (int j=0; j<iTotalTheirs; j++)
- tmp[j+1] = pClassInfo->getPrereqOrBonuses(j);
- for (int j=0; j<iTotalOurs; j++)
- tmp[j+iTotalTheirs+1] = m_piPrereqOrBonuses[j+1];
- m_piPrereqOrBonuses = tmp;
- }
- ======================================================
- Take Two
- ======================================================
- // Macro for concatenating two packed arrays in CopyNonDefaults()
- #define PACKED_ARRAY_COPYNONDEFAULTS(theirFn, ourArr) if (theirFn(-1) != -1) { \
- int theirSize = theirFn(-1), ourSize = 0; if (ourArr) ourSize = ourArr[0]; \
- int* tmp = new int[theirSize+ourSize+1]; tmp[0] = theirSize+ourSize; \
- for (int i=0; i<theirSize; i++) tmp[i+1] = theirFn(i); \
- for (int i=0; i<ourSize; i++) tmp[i+theirSize+1] = ourArr[i+1]; ourArr = tmp; }
- void CvBuildingInfo::copyNonDefaults(CvBuildingInfo* pClassInfo, CvXMLLoadUtility* pXML)
- { [...]
- PACKED_ARRAY_COPYNONDEFAULTS(pClassInfo->getPrereqAndTechs, m_piPrereqAndTechs);
- if (getPrereqAndBonus() == NO_BONUS) m_iPrereqAndBonus = pClassInfo->getPrereqAndBonus();
- PACKED_ARRAY_COPYNONDEFAULTS(pClassInfo->getPrereqOrBonuses, m_piPrereqOrBonuses);
- [...] }
- ======================================================
- CvCity::CanConstructInternal()
- This modification applies in four other places:
- CvGameTextMgr::buildBuildingRequiresString(),
- CvPlayer::recalculateResourceConsumption(),
- CvPlayerAI::AI_bonusTrade(), and
- CvPlayerAI::AI_baseBonusVal().
- ======================================================
- for (iI = 0; iI < kBuilding.getPrereqOrBonuses(-1); iI++) // was "iI < GC.getNUM_BUILDING_PREREQ_OR_BONUSES()"
- {
- if (kBuilding.getPrereqOrBonuses(iI) != NO_BONUS)
- {
- bRequiresBonus = true;
- if (hasBonus((BonusTypes)kBuilding.getPrereqOrBonuses(iI)))
- {
- bNeedsBonus = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment