/* -------------------------------------------------------------------------------------------------------
© 1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
Sid Meier's Civilization V, Civ, Civilization, 2K Games, Firaxis Games, Take-Two Interactive Software
and their respective logos are all trademarks of Take-Two interactive Software, Inc.
All other marks and trademarks are the property of their respective owners.
All rights reserved.
------------------------------------------------------------------------------------------------------- */
#include "CvGameCoreDLLPCH.h"
#include "CvGameCoreDLLUtil.h"
#include "CvTechAI.h"
#include "CvFlavorManager.h"
#include "ICvDLLUserInterface.h"
#include "CvGameCoreUtils.h"
#include "CvCitySpecializationAI.h"
#include "CvGrandStrategyAI.h"
#include "CvInfosSerializationHelper.h"
#include "LintFree.h"
/// Constructor
CvTechEntry::CvTechEntry(void):
m_iAIWeight(0),
m_iAITradeModifier(0),
m_iResearchCost(0),
m_iAdvancedStartCost(0),
m_iEra(NO_ERA),
m_iFeatureProductionModifier(0),
m_iUnitFortificationModifier(0),
m_iUnitBaseHealModifier(0),
m_iWorkerSpeedModifier(0),
m_iFirstFreeUnitClass(NO_UNITCLASS),
m_iFirstFreeTechs(0),
m_iEmbarkedMoveChange(0),
m_iGridX(0),
m_iGridY(0),
m_bEndsGame(false),
m_bAllowsEmbarking(false),
m_bAllowsDefensiveEmbarking(false),
m_bEmbarkedAllWaterPassage(false),
m_bAllowsBarbarianBoats(false),
m_bRepeat(false),
m_bTrade(false),
m_bDisable(false),
m_bGoodyTech(false),
m_bExtraWaterSeeFrom(false),
m_bMapCentering(false),
m_bMapVisible(false),
m_bMapTrading(false),
m_bTechTrading(false),
m_bGoldTrading(false),
m_bAllowEmbassyTradingAllowed(false),
m_bOpenBordersTradingAllowed(false),
m_bDefensivePactTradingAllowed(false),
m_bResearchAgreementTradingAllowed(false),
m_bTradeAgreementTradingAllowed(false),
m_bPermanentAllianceTrading(false),
m_bBridgeBuilding(false),
m_bWaterWork(false),
m_piDomainExtraMoves(NULL),
m_piFlavorValue(NULL),
[COLOR='RED'] m_piYieldChangeTradeRoute(NULL)[/COLOR]
m_piPrereqOrTechs(NULL),
m_piPrereqAndTechs(NULL),
m_pabFreePromotion(NULL)
{
}
/// Destructor
CvTechEntry::~CvTechEntry(void)
{
SAFE_DELETE_ARRAY(m_piDomainExtraMoves);
SAFE_DELETE_ARRAY(m_piFlavorValue);
SAFE_DELETE_ARRAY(m_piPrereqOrTechs);
SAFE_DELETE_ARRAY(m_piPrereqAndTechs);
SAFE_DELETE_ARRAY(m_pabFreePromotion);
}
bool CvTechEntry::CacheResults(Database::Results& kResults, CvDatabaseUtility& kUtility)
{
if(!CvBaseInfo::CacheResults(kResults, kUtility))
return false;
//Basic Properties
m_iAIWeight = kResults.GetInt("AIWeight");
m_iAITradeModifier = kResults.GetInt("AITradeModifier");
m_iResearchCost = kResults.GetInt("Cost");
m_iAdvancedStartCost = kResults.GetInt("AdvancedStartCost");
m_iFeatureProductionModifier = kResults.GetInt("FeatureProductionModifier");
m_iUnitFortificationModifier = kResults.GetInt("UnitFortificationModifier");
m_iUnitBaseHealModifier = kResults.GetInt("UnitBaseHealModifier");
m_iWorkerSpeedModifier = kResults.GetInt("WorkerSpeedModifier");
m_iFirstFreeTechs = kResults.GetInt("FirstFreeTechs");
m_iEmbarkedMoveChange = kResults.GetInt("EmbarkedMoveChange");
m_bEndsGame = kResults.GetBool("EndsGame");
m_bAllowsEmbarking = kResults.GetBool("AllowsEmbarking");
m_bAllowsDefensiveEmbarking = kResults.GetBool("AllowsDefensiveEmbarking");
m_bEmbarkedAllWaterPassage = kResults.GetBool("EmbarkedAllWaterPassage");
m_bAllowsBarbarianBoats = kResults.GetBool("AllowsBarbarianBoats");
m_bRepeat = kResults.GetBool("Repeat");
m_bTrade = kResults.GetBool("Trade");
m_bDisable = kResults.GetBool("Disable");
m_bGoodyTech = kResults.GetBool("GoodyTech");
m_bExtraWaterSeeFrom = kResults.GetBool("ExtraWaterSeeFrom");
m_bMapCentering = kResults.GetBool("MapCentering");
m_bMapVisible = kResults.GetBool("MapVisible");
m_bMapTrading = kResults.GetBool("MapTrading");
m_bTechTrading = kResults.GetBool("TechTrading");
m_bGoldTrading = kResults.GetBool("GoldTrading");
m_bAllowEmbassyTradingAllowed = kResults.GetBool("AllowEmbassyTradingAllowed");
m_bOpenBordersTradingAllowed = kResults.GetBool("OpenBordersTradingAllowed");
m_bDefensivePactTradingAllowed = kResults.GetBool("DefensivePactTradingAllowed");
m_bResearchAgreementTradingAllowed = kResults.GetBool("ResearchAgreementTradingAllowed");
m_bTradeAgreementTradingAllowed = kResults.GetBool("TradeAgreementTradingAllowed");
m_bPermanentAllianceTrading = kResults.GetBool("PermanentAllianceTradingAllowed");
m_bBridgeBuilding = kResults.GetBool("BridgeBuilding");
m_bWaterWork = kResults.GetBool("WaterWork");
m_iGridX = kResults.GetInt("GridX");
m_iGridY = kResults.GetInt("GridY");
//References
const char* szTextVal = NULL;
szTextVal = kResults.GetText("Era");
m_iEra = GC.getInfoTypeForString(szTextVal, true);
szTextVal = kResults.GetText("FirstFreeUnitClass");
m_iFirstFreeUnitClass = GC.getInfoTypeForString(szTextVal, true);
szTextVal = kResults.GetText("Quote");
SetQuoteKey(szTextVal);
szTextVal = kResults.GetText("AudioIntro");
SetSound(szTextVal);
szTextVal = kResults.GetText("AudioIntroHeader");
SetSoundMP(szTextVal);
//Arrays
const char* szTechType = GetType();
kUtility.PopulateArrayByValue(m_piDomainExtraMoves, "Domains", "Technology_DomainExtraMoves", "DomainType", "TechType", szTechType, "Moves", 0, NUM_DOMAIN_TYPES);
kUtility.PopulateArrayByExistence(m_pabFreePromotion, "UnitPromotions", "Technology_FreePromotions", "PromotionType", "TechType", szTechType);
kUtility.SetFlavors(m_piFlavorValue, "Technology_Flavors", "TechType", szTechType);
const size_t TechnologiesCount = kUtility.MaxRows("Technologies");
//ORPrereqTechs
{
//PrereqTech array must be initialized to NO_TECH.
kUtility.InitializeArray(m_piPrereqOrTechs, TechnologiesCount, NO_TECH);
std::string strKey = "Technologies - Technology_ORPrereqTechs";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select Technologies.ID from Technology_ORPrereqTechs inner join Technologies on Technologies.Type = PrereqTech where TechType = ?;");
}
pResults->Bind(1, szTechType, -1, false);
int i = 0;
while(pResults->Step())
{
m_piPrereqOrTechs[i++] = pResults->GetInt(0);
}
pResults->Reset();
}
//PrereqTechs
{
//PrereqTech array must be initialized to NO_TECH.
kUtility.InitializeArray(m_piPrereqAndTechs, TechnologiesCount, NO_TECH);
std::string strKey = "Technologies - Technology_PrereqTechs";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select Technologies.ID from Technology_PrereqTechs inner join Technologies on Technologies.Type = PrereqTech where TechType = ?;");
}
pResults->Bind(1, szTechType, -1, false);
int i = 0;
while(pResults->Step())
{
m_piPrereqAndTechs[i++] = pResults->GetInt(0);
}
pResults->Reset();
}
return true;
}
/// Additional weight to having AI purchase this
int CvTechEntry::GetAIWeight() const
{
return m_iAIWeight;
}
/// Additional weight to having AI trade for this
int CvTechEntry::GetAITradeModifier() const
{
return m_iAITradeModifier;
}
/// Research/science points required to obtain tech
int CvTechEntry::GetResearchCost() const
{
return m_iResearchCost;
}
/// Cost if starting midway through game
int CvTechEntry::GetAdvancedStartCost() const
{
return m_iAdvancedStartCost;
}
/// Historical era within tech tree
int CvTechEntry::GetEra() const
{
return m_iEra;
}
/// Changes builder production
int CvTechEntry::GetFeatureProductionModifier() const
{
return m_iFeatureProductionModifier;
}
/// Changes combat bonus from fortification
int CvTechEntry::GetUnitFortificationModifier() const
{
return m_iUnitFortificationModifier;
}
/// Changes base unit healing rate
int CvTechEntry::GetUnitBaseHealModifier() const
{
return m_iUnitBaseHealModifier;
}
/// Improvement in worker speed
int CvTechEntry::GetWorkerSpeedModifier() const
{
return m_iWorkerSpeedModifier;
}
/// Free unit if first to discover this tech
int CvTechEntry::GetFirstFreeUnitClass() const
{
return m_iFirstFreeUnitClass;
}
/// Earn another tech for free if first to discover this one
int CvTechEntry::GetFirstFreeTechs() const
{
return m_iFirstFreeTechs;
}
/// Number of additional moves provided to land Units embarked on the water
int CvTechEntry::GetEmbarkedMoveChange() const
{
return m_iEmbarkedMoveChange;
}
/// X location on tech tree page
int CvTechEntry::GetGridX() const
{
return m_iGridX;
}
/// Y location on tech tree page
int CvTechEntry::GetGridY() const
{
return m_iGridY;
}
/// Does this Tech end the game?
bool CvTechEntry::IsEndsGame() const
{
return m_bEndsGame;
}
/// Unlocks the ability to embark land Units onto self-carried boats
bool CvTechEntry::IsAllowsEmbarking() const
{
return m_bAllowsEmbarking;
}
/// Allows embarked units to defend themselves
bool CvTechEntry::IsAllowsDefensiveEmbarking() const
{
return m_bAllowsDefensiveEmbarking;
}
/// Allows embarked Units to enter deep ocean
bool CvTechEntry::IsEmbarkedAllWaterPassage() const
{
return m_bEmbarkedAllWaterPassage;
}
/// Are the Barbarians allowed to have Boats yet?
bool CvTechEntry::IsAllowsBarbarianBoats() const
{
return m_bAllowsBarbarianBoats;
}
/// Can this be researched repeatedly (future tech)
bool CvTechEntry::IsRepeat() const
{
return m_bRepeat;
}
/// Is it tradeable?
bool CvTechEntry::IsTrade() const
{
return m_bTrade;
}
/// Currently disabled (not in game)?
bool CvTechEntry::IsDisable() const
{
return m_bDisable;
}
/// Can you receive it from a goody hut?
bool CvTechEntry::IsGoodyTech() const
{
return m_bGoodyTech;
}
/// Expand visibility over water?
bool CvTechEntry::IsExtraWaterSeeFrom() const
{
return m_bExtraWaterSeeFrom;
}
/// Does it center your mini-map in the overall world?
bool CvTechEntry::IsMapCentering() const
{
return m_bMapCentering;
}
/// Does this tech reveal the entire map?
bool CvTechEntry::IsMapVisible() const
{
return m_bMapVisible;
}
/// Does it enable world map trades?
bool CvTechEntry::IsMapTrading() const
{
return m_bMapTrading;
}
/// Does it enable technology trading?
bool CvTechEntry::IsTechTrading() const
{
return m_bTechTrading;
}
/// Does it enable gold trading?
bool CvTechEntry::IsGoldTrading() const
{
return m_bGoldTrading;
}
/// Can you permit allow embassy to be traded?
bool CvTechEntry::IsAllowEmbassyTradingAllowed() const
{
return m_bAllowEmbassyTradingAllowed;
}
/// Can you permit open borders?
bool CvTechEntry::IsOpenBordersTradingAllowed() const
{
return m_bOpenBordersTradingAllowed;
}
/// Can you form defensive treaties?
bool CvTechEntry::IsDefensivePactTradingAllowed() const
{
return m_bDefensivePactTradingAllowed;
}
/// Can you form Research Agreements?
bool CvTechEntry::IsResearchAgreementTradingAllowed() const
{
return m_bResearchAgreementTradingAllowed;
}
/// Can you form Trade Agreements?
bool CvTechEntry::IsTradeAgreementTradingAllowed() const
{
return m_bTradeAgreementTradingAllowed;
}
/// Can you form a permanent alliance?
bool CvTechEntry::IsPermanentAllianceTrading() const
{
return m_bPermanentAllianceTrading;
}
/// Are river crossings treated as bridges?
bool CvTechEntry::IsBridgeBuilding() const
{
return m_bBridgeBuilding;
}
/// Enable working of water tiles?
bool CvTechEntry::IsWaterWork() const
{
return m_bWaterWork;
}
/// Grants free promotion?
int CvTechEntry::IsFreePromotion(int i) const
{
return m_pabFreePromotion ? m_pabFreePromotion[i] : -1;
}
[COLOR='RED']///My New Acessor
int CvTechEntry::GetYieldChangeTradeRoute(int i) const {CvAssertMsg(i < NUM_YIELD_TYPES, "Index out of bounds");
CvAssertMsg(i > -1, "Index out of bounds");return m_piYieldChangeTradeRoute ? m_piYieldChangeTradeRoute[i] : -1;
}[/COLOR]