Пример #1
0
void CFactory::CreatePlayerUnit(int nType)
{
	PROFILE("CFactory::CreatePlayerUnit(int)");
	//static float xPos = 100;
	//static float yPos = 50;
	CUnit* unit = new CUnit(nType);

	// Use default shallow copy since no dynamic info in creation
	CUnit temp = CGame::GetInstance()->GetUnitInfo(nType);
	unit->SetAttackPower(temp.GetAttackPower());
	unit->SetAttackSpeed(temp.GetAttackSpeed());
	unit->SetMaxHP(temp.GetMaxHP());
	unit->SetCurrentHP(temp.GetMaxHP());
	unit->SetRange(temp.GetRange());
	unit->SetSpeed(temp.GetSpeed());
		
	unit->SetState(IDLE);
	unit->SetDirection(SOUTH_WEST);
	unit->SetIsPlayerUnit(true);
	unit->SetAttackSoundID(CGame::GetInstance()->GetAttackSound(unit->GetType()));
	// Register Events
	unit->SetDeathSoundID(CGame::GetInstance()->GetDeathSound(unit->GetType()));


	// Add to manager
	ObjectManager::GetInstance()->AddObject(unit);

	// Let it know we aren't hanging on to it
	unit->Release();
	STOP("CFactory::CreatePlayerUnit(int)");

}
Пример #2
0
void CFactory::CreateComputerUnit(int nType)
{
	PROFILE("CFactory::CreateComputerUnit(int)");
	//static float xPos = 100;
	//static float yPos = 50;
	CUnit* unit = new CUnit(nType);

	// Use default shallow copy since no dynamic info in creation
	CUnit temp = CGame::GetInstance()->GetCPUUnitInfo(nType);
	unit->SetAttackPower(temp.GetAttackPower());
	unit->SetAttackSpeed(temp.GetAttackSpeed());
	unit->SetMaxHP(temp.GetMaxHP());
	unit->SetCurrentHP(temp.GetMaxHP());
	unit->SetRange(temp.GetRange());
	unit->SetSpeed(temp.GetSpeed());

	unit->SetState(IDLE);
	unit->SetDirection(NORTH_WEST);
	unit->SetIsPlayerUnit(false);
	// Register Events
	unit->SetAttackSoundID(CGame::GetInstance()->GetAttackSound(unit->GetType()));
	unit->SetDeathSoundID(CGame::GetInstance()->GetDeathSound(unit->GetType()));

	switch(CGame::GetInstance()->GetSelectedCity()->GetID())
	{
		case KCITY1:

			break;
		case KCITY2:
			unit->SetAttackPower(unit->GetAttackPower()+2);
			break;
		case KCITY3:
			unit->SetAttackPower(unit->GetAttackPower()+2);
			unit->SetAttackSpeed(unit->GetAttackSpeed()-(unit->GetAttackSpeed()*.2f));
			unit->SetSpeed(unit->GetSpeed()-(unit->GetSpeed()*.5f));

			break;
		case XCITY1:

			break;
		case XCITY2:
			unit->SetAttackPower(unit->GetAttackPower()+2);

			break;
		case XCITY3:
			unit->SetAttackPower(unit->GetAttackPower()+2);
			unit->SetAttackSpeed(unit->GetAttackSpeed()-(unit->GetAttackSpeed()*.2f));
			unit->SetSpeed(unit->GetSpeed()-(unit->GetSpeed()*.5f));

			break;
		case JCITY1:

			break;
		case JCITY2:
			unit->SetAttackPower(unit->GetAttackPower()+2);

			break;
		case JCITY3:
			unit->SetAttackPower(unit->GetAttackPower()+2);
			unit->SetAttackSpeed(unit->GetAttackSpeed()-(unit->GetAttackSpeed()*.2f));
			unit->SetSpeed(unit->GetSpeed()-(unit->GetSpeed()*.5f));

			break;
	}



	// Add to manager
	ObjectManager::GetInstance()->AddObject(unit);

	// Let it know we aren't hanging on to it
	unit->Release();
	STOP("CFactory::CreateComputerUnit(int)");


}
void CGameManager::SaveGame(int nSlot)
{
	TiXmlDocument doc;
	TiXmlDeclaration* pDec = new TiXmlDeclaration("1.0", "utf-8", "");

	doc.LinkEndChild(pDec);

	TiXmlElement* pRoot = new TiXmlElement("Map");
	doc.LinkEndChild(pRoot);

	pRoot->SetAttribute("mapID", m_nCurrentLevel);
	pRoot->SetAttribute("phaseNumber", m_nPhaseCount);
	pRoot->SetAttribute("phase", m_nCurrentPhase);
	pRoot->SetAttribute("currPlayer", m_pCurrentPlayer->GetPlayerID());

	time_t now = time(0);
	struct tm tstruct;
	char buf[80];
	localtime_s(&tstruct, &now);

	strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

	std::string time = buf;

	pRoot->SetAttribute("date", time.c_str());

	/////////////////////////////////////////////////////////////////
	// BUG FIX
	// Reference Bug # BB-069
	// BUG FIX START
	/////////////////////////////////////////////////////////////////


	// Added tile resource data to save system
	for (int i = 0; i < CTileManager::GetInstance()->GetNumRows(); ++i)
	{
		for (int j = 0; j < CTileManager::GetInstance()->GetNumColumns(); ++j)
		{
			CTile* pTile = CTileManager::GetInstance()->GetTile(i, j);
			if (!pTile->GetIfResourceTile())
				continue;

			if (pTile->GetIfCaptured())
			{
				MapModification mapMod;
				mapMod.modType = SP_FAKEMAPMOD;
				mapMod.posX = i;
				mapMod.posY = j;
				mapMod.otherData = pTile->GetPlayerID();
				m_vMapMods.push_back(mapMod);
			}
		}
	}

	/////////////////////////////////////////////////////////////////
	// BUG FIX END  Reference # BB-069
	/////////////////////////////////////////////////////////////////

	TiXmlElement* pMapMods = new TiXmlElement("MapModifications");
	pMapMods->SetAttribute("numModifications", m_vMapMods.size());
	pRoot->LinkEndChild(pMapMods);



	for (unsigned int i = 0; i < m_vMapMods.size(); ++i)
	{
		TiXmlElement* pMapMod = new TiXmlElement("MapModification");
		pMapMod->SetAttribute("modType", m_vMapMods[i].modType);
		pMapMod->SetAttribute("modPosX", m_vMapMods[i].posX);
		pMapMod->SetAttribute("modPosY", m_vMapMods[i].posY);
		pMapMod->SetAttribute("modOtherData", m_vMapMods[i].otherData);
		pMapMods->LinkEndChild(pMapMod);
	}

	TiXmlElement* pPlayers = new TiXmlElement("Players");
	pRoot->LinkEndChild(pPlayers);

	for (int i = 0; i < 2; ++i)
	{
		TiXmlElement* pPlayer = new TiXmlElement("Player");
		pPlayers->LinkEndChild(pPlayer);
		pPlayer->SetAttribute("id", m_vPlayers[i]->GetPlayerID());
		pPlayer->SetAttribute("ai", (int)m_vPlayers[i]->GetAI());
		pPlayer->SetAttribute("AP", m_vPlayers[i]->GetAP());
		pPlayer->SetAttribute("wood", m_vPlayers[i]->GetWood());
		pPlayer->SetAttribute("metal", m_vPlayers[i]->GetMetal());
	
		// Game Stats!

		TiXmlElement* pStats = new TiXmlElement("Stats");
		pStats->SetAttribute("numStats", 17);

		TiXmlElement* pChampionDmgDone = new TiXmlElement("ChampionDamageDone");
		pChampionDmgDone->SetAttribute("value", m_vPlayers[i]->GetStats()->nChampionDamageDone);
		pStats->LinkEndChild(pChampionDmgDone);

		TiXmlElement* pChampionHealingDone = new TiXmlElement("ChampionHealingDone");
		pChampionHealingDone->SetAttribute("value", m_vPlayers[i]->GetStats()->nChampionHealingDone);
		pStats->LinkEndChild(pChampionHealingDone);

		TiXmlElement* pSwordsmanCreated = new TiXmlElement("SwordsmanCreated");
		pSwordsmanCreated->SetAttribute("value", m_vPlayers[i]->GetStats()->nSwordsmanCreated);
		pStats->LinkEndChild(pSwordsmanCreated);

		TiXmlElement* pArcherCreated = new TiXmlElement("ArcherCreated");
		pArcherCreated->SetAttribute("value", m_vPlayers[i]->GetStats()->nArcherCreated);
		pStats->LinkEndChild(pArcherCreated);

		TiXmlElement* pCalvaryCreated = new TiXmlElement("CalvaryCreated");
		pCalvaryCreated->SetAttribute("value", m_vPlayers[i]->GetStats()->nCalvaryCreated);
		pStats->LinkEndChild(pCalvaryCreated);

		TiXmlElement* pSwordsmanDmgDone = new TiXmlElement("SwordsmanDamageDone");
		pSwordsmanDmgDone->SetAttribute("value", m_vPlayers[i]->GetStats()->nSwordsmanDamageDone);
		pStats->LinkEndChild(pSwordsmanDmgDone);

		TiXmlElement* pArcherDmgDone = new TiXmlElement("ArcherDamageDone");
		pArcherDmgDone->SetAttribute("value", m_vPlayers[i]->GetStats()->nArcherDamageDone);
		pStats->LinkEndChild(pArcherDmgDone);

		TiXmlElement* pCalvaryDmgDone = new TiXmlElement("CalvaryDamageDone");
		pCalvaryDmgDone->SetAttribute("value", m_vPlayers[i]->GetStats()->nCalvaryDamageDone);
		pStats->LinkEndChild(pCalvaryDmgDone);

		TiXmlElement* pSwordsmanKilled = new TiXmlElement("SwordsmanKilled");
		pSwordsmanKilled->SetAttribute("value", m_vPlayers[i]->GetStats()->nSwordsmanKilled);
		pStats->LinkEndChild(pSwordsmanKilled);

		TiXmlElement* pArcherKilled = new TiXmlElement("ArcherKilled");
		pArcherKilled->SetAttribute("value", m_vPlayers[i]->GetStats()->nArcherKilled);
		pStats->LinkEndChild(pArcherKilled);

		TiXmlElement* pCalvaryKilled = new TiXmlElement("CalvaryKilled");
		pCalvaryKilled->SetAttribute("value", m_vPlayers[i]->GetStats()->nCavalryKilled);
		pStats->LinkEndChild(pCalvaryKilled);

		TiXmlElement* pWoodEarned = new TiXmlElement("WoodEarned");
		pWoodEarned->SetAttribute("value", m_vPlayers[i]->GetStats()->nPlayerWoodEarned);
		pStats->LinkEndChild(pWoodEarned);

		TiXmlElement* pMetalEarned = new TiXmlElement("MetalEarned");
		pMetalEarned->SetAttribute("value", m_vPlayers[i]->GetStats()->nPlayerMetalEarned);
		pStats->LinkEndChild(pMetalEarned);

		TiXmlElement* pWoodSpent = new TiXmlElement("WoodSpent");
		pWoodSpent->SetAttribute("value", m_vPlayers[i]->GetStats()->nPlayerWoodSpent);
		pStats->LinkEndChild(pWoodSpent);

		TiXmlElement* pMetalSpent = new TiXmlElement("MetalSpent");
		pMetalSpent->SetAttribute("value", m_vPlayers[i]->GetStats()->nPlayerMetalSpent);
		pStats->LinkEndChild(pMetalSpent);

		TiXmlElement* pAPSpent = new TiXmlElement("APSpent");
		pAPSpent->SetAttribute("value", m_vPlayers[i]->GetStats()->nPlayerAPSpent);
		pStats->LinkEndChild(pAPSpent);

		pPlayer->LinkEndChild(pStats);


		TiXmlElement* pChampion = new TiXmlElement("Champion");
		CHero* pHero = dynamic_cast<CHero*>(GetChampion(m_vPlayers[i]->GetPlayerID()));
		if (pHero == nullptr)
		{
			// Why are you here?
			MessageBoxA(0, "How did you get here? Why are you saving when hero is dead? Go away. Don't save after you won",
				"ERROR:", MB_OK);
			continue;
		}
		if (pHero->GetNumWaypoints() > 0)
		{
			pChampion->SetAttribute("posX", pHero->GetLastWaypoint().nPosX);
			pChampion->SetAttribute("posY", pHero->GetLastWaypoint().nPosY);
		}
		else
		{
			pChampion->SetAttribute("posX", pHero->GetPos().nPosX);
			pChampion->SetAttribute("posY", pHero->GetPos().nPosY);
		}

		pChampion->SetAttribute("health", pHero->GetHP());
		pChampion->SetAttribute("xp", m_vPlayers[i]->GetExp());
		pChampion->SetAttribute("facing", pHero->GetFacing());
		pChampion->SetAttribute("tilesMoved", pHero->GetTilesMoved());
		pChampion->SetAttribute("hasAttacked", (int)pHero->GetHasAttacked());
		// TODO: setup spell saving here

		TiXmlElement* pSpells = new TiXmlElement("Spells");
		pSpells->SetAttribute("numSpells", pHero->GetNumSpells());
		pChampion->LinkEndChild(pSpells);

		for (unsigned int n = 0; n < pHero->GetNumSpells(); ++n)
		{
			TiXmlElement* pSpell = new TiXmlElement("Spell");
			pSpell->SetAttribute("sType", pHero->GetSpell(n)->GetType());
			pSpell->SetAttribute("Cooldown", pHero->GetCooldown(n));
			pSpells->LinkEndChild(pSpell);
		}

		TiXmlElement* pBoughtSpells = new TiXmlElement("BoughtSpells");
		pBoughtSpells->SetAttribute("numBought", pHero->GetNumBought());
		pChampion->LinkEndChild(pBoughtSpells);

		for( int n = 0; n < pHero->GetNumBought(); n++ )
		{
			TiXmlElement* pBought = new TiXmlElement("Bought");
			pBought->SetAttribute("Type", pHero->GetBought(n)->GetType());
			pBoughtSpells->LinkEndChild(pBought);
		}

		TiXmlElement* pEffects = new TiXmlElement("Effects");
		pChampion->LinkEndChild(pEffects);
		pEffects->SetAttribute("numEffects", pHero->GetNumEffects());
		for (int x = 0; x < pHero->GetNumEffects(); ++x)
		{
			TiXmlElement* pEffect = new TiXmlElement("Effect");
			pEffect->SetAttribute("ability", pHero->GetEffect(x)->GetType());
			pEffects->LinkEndChild(pEffect);
		}

		pPlayer->LinkEndChild(pChampion);

		// Lets save the units!
		TiXmlElement* pUnits = new TiXmlElement("Units");
		pPlayer->LinkEndChild(pUnits);
		int nNumUnits = 0;

		for (decltype(m_vUnits.size()) j = 0; j < m_vUnits.size(); ++j)
		{
			// this is our unit, lets save it!
			if (m_vUnits[j]->GetPlayerID() == m_vPlayers[i]->GetPlayerID() && m_vUnits[j]->GetType() != UT_HERO)
			{
				TiXmlElement* pUnit = new TiXmlElement("Unit");
				CUnit* puni = m_vUnits[j];
				nNumUnits++;
				if (puni->GetNumWaypoints() > 0)
				{
					pUnit->SetAttribute("posX", puni->GetLastWaypoint().nPosX);
					pUnit->SetAttribute("posY", puni->GetLastWaypoint().nPosY);
				}
				else
				{
					pUnit->SetAttribute("posX", puni->GetPos().nPosX);
					pUnit->SetAttribute("posY", puni->GetPos().nPosY);
				}
				pUnit->SetAttribute("unitType", (int)puni->GetType());
				pUnit->SetAttribute("health", puni->GetHP());
				pUnit->SetAttribute("facing", puni->GetFacing());
				pUnit->SetAttribute("tilesMoved", puni->GetTilesMoved());
				pUnit->SetAttribute("hasAttacked", (int)puni->GetHasAttacked());

				// Effects/debuffs on the unit
				TiXmlElement* pEffects = new TiXmlElement("Effects");
				pUnit->LinkEndChild(pEffects);
				pEffects->SetAttribute("numEffects", puni->GetNumEffects());
				for (int n = 0; n < puni->GetNumEffects(); ++n)
				{
					TiXmlElement* pEffect = new TiXmlElement("Effect");
					pEffect->SetAttribute("ability", puni->GetEffect(n)->GetType());
					pEffects->LinkEndChild(pEffect);
				}

				pUnits->LinkEndChild(pUnit);
			}
		}

		pUnits->SetAttribute("numUnits", nNumUnits);
	}

	/////////////////////////////////////////////////////////////////
	// BUG FIX
	// Reference Bug # BB-018
	// BUG FIX START
	/////////////////////////////////////////////////////////////////

	// Updated to use appdata instead of relative pathing to avoid administrative rights issues
	wchar_t path[MAX_PATH];
	HRESULT hr = SHGetFolderPathW(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, path);

	std::wstring pathtowrite(path, path+ wcslen(path));
	
	pathtowrite += L"\\LeagueOfChampionCraft";
	CreateDirectory(pathtowrite.c_str(), 0);

	std::wostringstream woss;
	woss << "\\saveslot" << nSlot << ".xml";


	pathtowrite += woss.str();
	std::string stringpath(pathtowrite.begin(), pathtowrite.end());

	doc.SaveFile(stringpath.c_str());


	/////////////////////////////////////////////////////////////////
	// BUG FIX END  Reference # BB-018
	/////////////////////////////////////////////////////////////////

}