Guest User

packed array?

a guest
Jun 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. ======================================================
  2. CvBuildingInfo::getPrereqOrBonuses()
  3. ======================================================
  4. int CvBuildingInfo::getPrereqOrBonuses(int i) const    
  5. {
  6.     FAssertMsg(i < GC.getNUM_BUILDING_PREREQ_OR_BONUSES(), "Index out of bounds");
  7.     if (m_piPrereqOrBonuses)
  8.     {
  9.         int size = m_piPrereqOrBonuses[0];
  10.         if (i == -1)    return size;
  11.         if (i < size)   return m_piPrereqOrBonuses[i+1];
  12.         return -1;
  13.     }
  14.     return -1;
  15. }
  16.  
  17. ======================================================
  18. CvBuildingInfo::getCheckSum()
  19. ======================================================
  20.     if (m_piPrereqOrBonuses)    CheckSumI(iSum, m_piPrereqOrBonuses[0]+1, m_piPrereqOrBonuses);
  21.  
  22.  
  23. ======================================================
  24. CvBuildingInfo::read()
  25. ======================================================
  26.     if (pXML->TryMoveToXmlFirstChild(L"PrereqBonuses"))
  27.     {
  28.         iNumChildren = pXML->GetXmlChildrenNumber();
  29.         FAssertMsg((iNumChildren <= GC.getNUM_BUILDING_PREREQ_OR_BONUSES()),"Too many Prereq Or Bonuses for the building.");
  30.         int *tmp = new int[iNumChildren];
  31.         int iTotal = 0;
  32.         if (0 < iNumChildren)
  33.         {
  34.             if (pXML->GetChildXmlVal(szTextVal))
  35.             {
  36.                 for (j=0; j<iNumChildren; j++)
  37.                 {
  38.                     int eInfo = pXML->GetInfoClass(szTextVal);
  39.                     if (eInfo != -1)    tmp[iTotal++] = eInfo;
  40.                     if (!pXML->GetNextXmlVal(szTextVal))    break;
  41.                 }
  42.                 if (iTotal != 0)
  43.                 {
  44.                     m_piPrereqOrBonuses = new int[iTotal+1];
  45.                     m_piPrereqOrBonuses[0] = iTotal;
  46.                     for (j=0; j<iTotal; j++)    m_piPrereqOrBonuses[j+1] = tmp[j];
  47.                 }
  48.                 pXML->MoveToXmlParent();
  49.             }
  50.         }
  51.         else    SAFE_DELETE_ARRAY(m_piPrereqOrBonuses);
  52.         pXML->MoveToXmlParent();
  53.     }
  54.     else    SAFE_DELETE_ARRAY(m_piPrereqOrBonuses);
  55.  
  56. ======================================================
  57. CvBuildingInfo::CopyNonDefaults()
  58. ======================================================
  59.     int iTotalTheirs = pClassInfo->getPrereqOrBonuses(-1);
  60.     if (iTotalTheirs != -1)
  61.     {
  62.         int iTotalOurs = 0;
  63.         if (m_piPrereqOrBonuses)    iTotalOurs = m_piPrereqOrBonuses[0];
  64.         int* tmp = new int[iTotalTheirs+iTotalOurs+1];
  65.         tmp[0] = iTotalTheirs+iTotalOurs;
  66.         for (int j=0; j<iTotalTheirs; j++)
  67.             tmp[j+1] = pClassInfo->getPrereqOrBonuses(j);
  68.         for (int j=0; j<iTotalOurs; j++)
  69.             tmp[j+iTotalTheirs+1] = m_piPrereqOrBonuses[j+1];
  70.         m_piPrereqOrBonuses = tmp;
  71.     }
  72.  
  73. ======================================================
  74. CvCity::CanConstructInternal()
  75. This modification applies in four other places:
  76.     CvGameTextMgr::buildBuildingRequiresString(),
  77.     CvPlayer::recalculateResourceConsumption(),
  78.     CvPlayerAI::AI_bonusTrade(), and
  79.     CvPlayerAI::AI_baseBonusVal().
  80. ======================================================
  81.             for (iI = 0; iI < kBuilding.getPrereqOrBonuses(-1); iI++) // was "iI < GC.getNUM_BUILDING_PREREQ_OR_BONUSES()"
  82.             {
  83.                 if (kBuilding.getPrereqOrBonuses(iI) != NO_BONUS)
  84.                 {
  85.                     bRequiresBonus = true;
  86.  
  87.                     if (hasBonus((BonusTypes)kBuilding.getPrereqOrBonuses(iI)))
  88.                     {
  89.                         bNeedsBonus = false;
  90.                     }
  91.                 }
  92.             }
Advertisement
Add Comment
Please, Sign In to add comment