Ejemplo n.º 1
0
void CRandomEventCtrl::CalcExploreEvent(const CPoint &ko, CMajor *pRace, CShipMap* ships) const
{
	if (!IsActivated())
		return;

	if(rand() % 99 >= static_cast<int>(m_uiGlobalProb))
		return; //Es findet kein Ereignis statt

	CBotEDoc* pDoc = resources::pDoc;
	AssertBotE(pDoc);

	//ko=Koordinate wo es passiert, pRace = die Rasse der es passiert
	int eventnumber=rand()%2;
	CString sMessageText = "";
	EMPIRE_NEWS_TYPE::Typ typ = EMPIRE_NEWS_TYPE::NO_TYPE;

	if (eventnumber == ALIENTEC)
	{
		// Forschung insgesamt um (50 bis 150) * Anzahl Systeme erhöhen
		int nSystemCount = pRace->GetEmpire()->GetSystemList()->GetSize();
		int nAdd = (50 + rand()%101) * nSystemCount;
		pRace->GetEmpire()->AddFP(nAdd);

		const CString& sSectorName = pDoc->GetSystem(ko.x, ko.y).CoordsName(true);

		sMessageText = CLoc::GetString("ALIENTEC",false,sSectorName);
		typ = EMPIRE_NEWS_TYPE::RESEARCH;

		if (pRace->IsHumanPlayer())
		{
			const boost::shared_ptr<CEventRandom> EmpireEvent = boost::make_shared<CEventRandom>(
				pRace->GetRaceID(),"alientech",CLoc::GetString("ALIENTECHEADLINE"),CLoc::GetString("ALIENTECLONG",false,sSectorName));
			pRace->GetEmpire()->PushEvent(EmpireEvent);
		}
	}
	else if(eventnumber == EVENTSHIPXP)
	{
		for (CShipMap::iterator i = ships->begin(); i != ships->end(); ++i)
		{
			if (i->second->OwnerID() == pRace->GetRaceID() && i->second->GetCo()==ko)
			{
				const int additional_experience = rand() % 401 + 50;
				i->second->SetCrewExperiance(additional_experience);
			}
		}

		sMessageText = CLoc::GetString("EVENTSHIPXP",false,pDoc->GetSystem(ko.x, ko.y).CoordsName(true));
		typ = EMPIRE_NEWS_TYPE::MILITARY;
	}

	if (!sMessageText.IsEmpty())
	{
		CEmpireNews message;
		message.CreateNews(sMessageText,typ,"",ko);//Nachricht erstellen
		pRace->GetEmpire()->AddMsg(message);

		resources::pClientWorker->SetToEmpireViewFor(*pRace);
	}
}
Ejemplo n.º 2
0
bool CRandomEventCtrl::SystemEvent(const CPoint &ko, CMajor* pRace)
{
	CBotEDoc* pDoc = resources::pDoc;
	AssertBotE(pDoc);
	//ko= Systemkoordinate
	CString sMsgText;//Nachrichtentext
	int nEventNumber=rand()% (SYSTEMEVENTDEMOGRAPHIC + 1);

	if(nEventNumber==SYSTEMEVENTMORALBOOST)//If abfrage mit allen möglichen Randomevents; evtl. hier bedingungen einfügen
	{
		sMsgText=CLoc::GetString("SYSTEMEVENTMORALBOOST",false,pDoc->GetSystem(ko.x, ko.y).GetName());
		pDoc->GetSystem(ko.x, ko.y).SetMoral(10);
	}
	else if(nEventNumber==SYSTEMEVENTMORALMALUS)
	{
		sMsgText=CLoc::GetString("SYSTEMEVENTMORALMALUS",false,pDoc->GetSystem(ko.x, ko.y).GetName());
		pDoc->GetSystem(ko.x, ko.y).SetMoral(-10);
	}
	else if(nEventNumber==SYSTEMEVENTPLANETMOVEMENT)//Planetenveränderung
		pDoc->GetSystem(ko.x, ko.y).SystemEventPlanetMovement(sMsgText);
	else if(nEventNumber==SYSTEMEVENTDEMOGRAPHIC)
		pDoc->GetSystem(ko.x, ko.y).SystemEventDemographic(sMsgText, *pRace);
	if(!sMsgText.IsEmpty())
	{
		CEmpireNews message;
		message.CreateNews(sMsgText,EMPIRE_NEWS_TYPE::SOMETHING,"",ko);//Nachricht über Randomevent erstellen
		pRace->GetEmpire()->AddMsg(message);
		resources::pClientWorker->SetToEmpireViewFor(*pRace);
	}
	return !sMsgText.IsEmpty();
}
/// Funktion überprüft ob das in der Designansicht angeklickte Schiff in einem unserer Systeme gerade gebaut wird
/// Man benötigt diesen Check da man keine Schiffe ändern kann, welche gerade gebaut werden.
/// @param pShipInfo Zeiger des zu prüfenden Schiffes aus der Schiffsliste
/// @return CString mit dem Namen des Systems, wird das Schiff nirgends gebaut ist der String leer
CString CShipDesignMenuView::CheckIfShipIsBuilding(const CShipInfo* pShipInfo) const
{
	if (!pShipInfo)
		return "";

	CBotEDoc* pDoc = resources::pDoc;
	ASSERT(pDoc);

	CMajor* pMajor = m_pPlayersRace;
	ASSERT(pMajor);
	if (!pMajor)
		return "";

	USHORT ID = pShipInfo->GetID();
	// alle eigenen Systeme durchgehen und schauen, ob an erster Stelle in der Bauliste so ein Schiff steht
	for (int y = 0; y < STARMAP_SECTORS_VCOUNT; y++)
		for (int x = 0; x < STARMAP_SECTORS_HCOUNT; x++)
			if (pDoc->GetSystem(x,y).GetOwnerOfSystem() == pMajor->GetRaceID())
				for (int i = 0; i < ALE; i++)
					if (pDoc->GetSystem(x,y).GetAssemblyList()->GetAssemblyListEntry(i) == ID)
						return pDoc->GetSector(x,y).GetName();

	return "";
}
Ejemplo n.º 4
0
void CRandomEventCtrl::CalcShipEvents() const
{
	if (!IsActivated())
		return;

	CBotEDoc* pDoc = resources::pDoc;
	AssertBotE(pDoc);

	// Hüllenvirus
	for (int x = 0; x < STARMAP_SECTORS_HCOUNT; x++)
	{
		for (int y = 0; y < STARMAP_SECTORS_VCOUNT; y++)
		{
			// 0.1% Wahrscheinlichkeit für einen Hüllenvirus pro Sektor
			if (rand()%1000 != 0)
				continue;

			// gibt es keine Schiffe im Sektor, dann macht ein Hüllenvirus auch nichts
			CSector* pSector = &(pDoc->GetSystem(x, y));
			if (!pSector->GetIsShipInSector())
				continue;

			// allen Schiffe im Sektor die Hülle auf 1 reduzieren (außer Aliens)
			for (CShipMap::iterator i = pDoc->m_ShipMap.begin(); i != pDoc->m_ShipMap.end(); ++i)
			{
				if (i->second->IsAlien())
					continue;

				if (i->second->GetCo() != pSector->GetCo())
					continue;

				int nCurrentHull = i->second->GetHull()->GetCurrentHull();
				i->second->GetHull()->SetCurrentHull(-(nCurrentHull - 1), true);

				// allen Schiffen in der Flotte ebenfalls die Hülle auf 1 setzen
				for (CShips::iterator j = i->second->begin(); j != i->second->end(); ++j)
				{
					nCurrentHull = j->second->GetHull()->GetCurrentHull();
					j->second->GetHull()->SetCurrentHull(-(nCurrentHull - 1), true);
				}
			}

			// Nachrichten an alle Major welche Schiffe in diesem Sektor hatten
			const std::map<CString, CMajor*>* pmMajors = pDoc->GetRaceCtrl()->GetMajors();
			for (map<CString, CMajor*>::const_iterator it = pmMajors->begin(); it != pmMajors->end(); ++it)
			{
				if (!pSector->GetOwnerOfShip(it->first, true))
					continue;

				CMajor* pMajor = it->second;
				if (!pMajor)
					continue;

				const CString& sSectorName = pSector->CoordsName(true);

				CString sMessageText = CLoc::GetString("EVENTHULLVIRUS", false, sSectorName);
				CEmpireNews message;
				message.CreateNews(sMessageText,EMPIRE_NEWS_TYPE::MILITARY,pSector->GetName(),pSector->GetCo());
				pMajor->GetEmpire()->AddMsg(message);

				if (pMajor->IsHumanPlayer())
				{
					resources::pClientWorker->SetToEmpireViewFor(*pMajor);
					pMajor->GetEmpire()->PushEvent(boost::make_shared<CEventRandom>(pMajor->GetRaceID(), "HullVirus", sMessageText, ""));
				}
			}
		}
	}
}