예제 #1
0
/////////////////////////////////////////////////////////////////////////////
// CbucketIGC
HRESULT         CbucketIGC::Initialize(ImissionIGC* pMission,
                                       Time         now,
                                       const void*  data,
                                       int          dataSize)
{
    assert (pMission);
    m_pMission = pMission;

	ZRetailAssert (data && (dataSize == sizeof(DataBucketIGC)));
    m_data = *((DataBucketIGC*)data);

    assert (m_data.side);
    m_data.side->AddRef();

    m_price = m_data.buyable->GetPrice();
    m_timeToBuild = m_data.buyable->GetTimeToBuild();

    //See if there is a predecessor bucket
    if (m_data.buyable->GetObjectType() == OT_development)
    {
        IdevelopmentIGC*    pdevelopment = (IdevelopmentIGC*)(m_data.buyable);
        if ((!pdevelopment->GetTechOnly()) && pdevelopment->GetEffectTechs().GetAllZero())
        {
            //A tech that affects only a side's global attributes.
            //Check for other buckets which do exactly the same thing
            Money                       price = pdevelopment->GetPrice();
            const GlobalAttributeSet&   gas = pdevelopment->GetGlobalAttributeSet();

            //Go backwards to get the last possible development
            for (BucketLinkIGC* pbl = m_data.side->GetBuckets()->last(); (pbl != NULL); pbl = pbl->txen())
            {
                IbucketIGC*     pbucket = pbl->data();
                IbuyableIGC*    pbuyable = pbucket->GetBuyable();
                if (pbuyable->GetObjectType() == OT_development)
                {
                    IdevelopmentIGC*    pd = (IdevelopmentIGC*)pbuyable;
                    if ((!pd->GetTechOnly()) && (pd->GetPrice() <= price) && pd->GetEffectTechs().GetAllZero())
                    {
                        //Look at that ... a equally or less expensive development that affects only global attributes
                        //do they affect the same global attributes the same way?
                        if (pd->GetGlobalAttributeSet() == gas)
                        {
                            pbucket->AddRef();
                            m_pbucketPredecessor = pbucket;
                            break;
                        }
                    }
                }
            }
        }

        if (pdevelopment->GetObjectID() != c_didTeamMoney)
        {
            m_price = (Money)(m_price * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentCost));
            m_timeToBuild = (DWORD)(m_timeToBuild * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentTime));
        }
    }

    m_data.side->AddBucket(this);

    assert (m_data.buyable);
    m_data.buyable->AddRef();

    m_lastUpdate = now;

    return S_OK;
}
예제 #2
0
void            CsideIGC::CreateBuckets(void)
{
#ifdef WIN
    assert(!m_buckets.first());
#else
    assert(m_buckets.empty());
#endif

    if (m_pMission->GetMissionParams()->bAllowDevelopments)
    {
        TechTreeBitMask     ttbmLocalUltimate;
        ttbmLocalUltimate.ClearAll();
        {
            //Resolve what the ultimate techs are for this civ ...
            m_ttbmUltimateTechs = m_data.ttbmDevelopmentTechs;

            {
#ifdef WIN
                //Start with their initial techs and add anything they could capture.
                for (PartTypeLinkIGC*   l = m_pMission->GetPartTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    m_ttbmUltimateTechs |= l->data()->GetEffectTechs();
                }
#else
                for( auto part : *(m_pMission->GetPartTypes()) )
                {
                  m_ttbmUltimateTechs |= part->GetEffectTechs();
                }
#endif
            }

            {
#ifdef WIN
                //Do the building techs ... assume they capture every type of building
                for (StationTypeLinkIGC*    l = m_pMission->GetStationTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    m_ttbmUltimateTechs |= l->data()->GetEffectTechs();
                    ttbmLocalUltimate |= l->data()->GetLocalTechs();
                }
#else
                for( auto st : *(m_pMission->GetStationTypes() ) )
                {
                    m_ttbmUltimateTechs |= st->GetEffectTechs();
                    ttbmLocalUltimate |= st->GetLocalTechs();
                }
#endif
            }

            {
                //Now add any techs they could buy (assuming they could build or
                //buy them) until we have a pass where we didn't add any.
                bool    continueF;
                do
                {
                    continueF = false;
                    {
#ifdef WIN
                        //Do the same for developments
                        for (DevelopmentLinkIGC*    l = m_pMission->GetDevelopments()->first();
                             (l != NULL);
                             l = l->next())
                        {
                            //Can we buy it?
                            if (l->data()->GetRequiredTechs() <= m_ttbmUltimateTechs)
                            {
                                //yes ... does it make a difference?
                                if (!(l->data()->GetEffectTechs() <= m_ttbmUltimateTechs))
                                {
                                    //yes ... 'buy it'
                                    m_ttbmUltimateTechs |= l->data()->GetEffectTechs();
                                    continueF = true;
                                }
                            }
                        }
#else
                        for( auto devel : *(m_pMission->GetDevelopments()) )
                        {
                            //Can we buy it?
                            if (devel->GetRequiredTechs() <= m_ttbmUltimateTechs)
                            {
                                //yes ... does it make a difference?
                                if (!(devel->GetEffectTechs() <= m_ttbmUltimateTechs))
                                {
                                    //yes ... 'buy it'
                                    m_ttbmUltimateTechs |= devel->GetEffectTechs();
                                    continueF = true;
                                }
                            }
                        }
#endif
                    }
                }
                while (continueF);
            }
        }

        {
#ifdef WIN
            //Add all developments that the side could, potentially, produce
            for (DevelopmentLinkIGC*    l = m_pMission->GetDevelopments()->first();
                 (l != NULL);
                 l = l->next())
            {
                IdevelopmentIGC*    d = l->data();
#else
            for( auto d : *(m_pMission->GetDevelopments()) )
            {
#endif
                //Only add the bucket if I'll be able to buy it eventually and it is not
                //obsolete.
                if ((d->GetObjectID() != c_didTeamMoney) && (d->GetRequiredTechs() <= m_ttbmUltimateTechs) && 
                    !d->IsObsolete(m_data.ttbmInitialTechs))
                {
                    //It is something we might be able to build and it will actually
                    //do something useful
                    DataBucketIGC   db = {d, this};
                    IbucketIGC*     b = (IbucketIGC*)(m_pMission->CreateObject(m_lastUpdate, OT_bucket, &db, sizeof(db)));
                    assert (b);

                    b->Release();   //Creating the bucket adds it to the side's list of buckets
                }
            }
        }

        {
            //Add All drone and station types that they might, theoretically, be able to produce
            ttbmLocalUltimate |= m_ttbmUltimateTechs;

            {
                //Add all developments that the side could, potentially, produce
#ifdef WIN
                for (DroneTypeLinkIGC*    l = m_pMission->GetDroneTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    IdroneTypeIGC*    d = l->data();
#else
                for( auto d : *(m_pMission->GetDroneTypes()) )
                {
#endif
                    if (d->GetRequiredTechs() <= ttbmLocalUltimate)
                    {
                        //It is something we might be able to build and it will actually
                        //do something useful
                        DataBucketIGC   db = {d, this};
                        IbucketIGC*     b = (IbucketIGC*)(m_pMission->CreateObject(m_lastUpdate, OT_bucket, &db, sizeof(db)));
                        assert (b);
                        b->Release();   //Creating the bucket adds it to the side's list of buckets
                    }
                }
            }

            {
                //Add all developments that the side could, potentially, produce
#ifdef WIN
                for (StationTypeLinkIGC*    l = m_pMission->GetStationTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    IstationTypeIGC*    s = l->data();
#else
                for( auto s : *(m_pMission->GetStationTypes() ) )
                {
#endif
                    if (s->GetRequiredTechs() <= ttbmLocalUltimate)
                    {
                        //It is something we might be able to build and it will actually
                        //do something useful
                        DataBucketIGC   db = {s, this};
                        IbucketIGC*     b = (IbucketIGC*)(m_pMission->CreateObject(m_lastUpdate, OT_bucket, &db, sizeof(db)));
                        assert (b);
                        b->Release();   //Creating the bucket adds it to the side's list of buckets
                    }
                }
            }

            //Add all hull and part types that cost money
            {
                /*
                for (HullTypeLinkIGC*    l = m_pMission->GetHullTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    IhullTypeIGC*    h = l->data();

                    if ((h->GetPrice() != 0) && (h->GetTimeToBuild() != 0) && 
                        (h->GetRequiredTechs() <= ttbmLocalUltimate))
                    {
                        //It is something we might be able to build and it will actually
                        //do something useful
                        DataBucketIGC   db = {h, this};
                        IbucketIGC*     b = (IbucketIGC*)(m_pMission->CreateObject(m_lastUpdate, OT_bucket, &db, sizeof(db)));
                        assert (b);
                        b->Release();   //Creating the bucket adds it to the side's list of buckets
                    }
                }
                */
            }

            {
                /*
                for (PartTypeLinkIGC*    l = m_pMission->GetPartTypes()->first();
                     (l != NULL);
                     l = l->next())
                {
                    IpartTypeIGC*    p = l->data();

                    if ((p->GetPrice() != 0) && (p->GetTimeToBuild() != 0) &&
                        (p->GetRequiredTechs() <= ttbmLocalUltimate))
                    {
                        //It is something we might be able to build and it will actually
                        //do something useful
                        DataBucketIGC   db = {p, this};
                        IbucketIGC*     b = (IbucketIGC*)(m_pMission->CreateObject(m_lastUpdate, OT_bucket, &db, sizeof(db)));
                        assert (b);

                        if (IlauncherTypeIGC::IsLauncherType(p->GetEquipmentType()))
                        {
                            b->SetPrice(b->GetPrice() * p->GetAmount(NULL));
                        }

                        b->Release();   //Creating the bucket adds it to the side's list of buckets
                    }
                }
                */
            }
        }
    }
}

long CsideIGC::GetProsperityPercentBought(void) const
{
  // Iterate through each bucket, looking for the prosperity development
  const BucketListIGC* pBuckets = GetBuckets();
#ifdef WIN
  for (BucketLinkIGC* it = pBuckets->first(); it; it = it->next())
  {
    IbucketIGC* pBucket = it->data();
#else
  for( auto pBucket : *(pBuckets) )
  {
#endif
    assert(pBucket);

    if (OT_development == pBucket->GetBucketType())
      if (c_didTeamMoney == pBucket->GetBuyable()->GetObjectID())
        return pBucket->GetPercentBought();
  }

  // Return zero if no prosperity development was found
  return 0;
}

long CsideIGC::GetProsperityPercentComplete(void) const
{
  // Iterate through each bucket, looking for the prosperity development
  const BucketListIGC* pBuckets = GetBuckets();
#ifdef WIN
  for (BucketLinkIGC* it = pBuckets->first(); it; it = it->next())
  {
    IbucketIGC* pBucket = it->data();
#else
  for( auto pBucket : *(pBuckets) )
  {
#endif
    assert(pBucket);

    if (OT_development == pBucket->GetBucketType())
      if (c_didTeamMoney == pBucket->GetBuyable()->GetObjectID())
        return pBucket->GetPercentComplete();
  }

  // Return zero if no prosperity development was found
  return 0;
}