コード例 #1
0
ファイル: Squad.cpp プロジェクト: Mesagoppinmypants/NGELinux
// ----------------------------------------------------------------------
void Squad::removeUnit(NetworkId const & unit)
{
	UnitMap::iterator iterUnitMap = m_unitMap->find(CachedNetworkId(unit));

	if (iterUnitMap != m_unitMap->end())
	{
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::removeUnit() className(%s) squadId(%d) unit(%s) squadSize(%d-1) leader(%s)", getClassName(), m_id, unit.getValueString().c_str(),  m_unitMap->size(), m_leader.getValueString().c_str()));

		bool const wasLeader = (iterUnitMap->first == m_leader);

		m_unitMap->erase(iterUnitMap);

		// See if we need to assign a new squad leader

		if (wasLeader)
		{
			bool const rebuildFormation = false;

		    if (!isEmpty())
			{
				IGNORE_RETURN(setLeader(m_unitMap->begin()->first, rebuildFormation));
			}
			else
			{
				IGNORE_RETURN(setLeader(NetworkId::cms_invalid, rebuildFormation));
			}
		}

		m_formation.markDirty();

		onRemoveUnit();
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("Squad::removeUnit() ERROR: className(%s) squadId(%d) Unable to find the unit(%s)", getClassName(), m_id, unit.getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}

//#ifdef _DEBUG
//	if (ConfigServerGame::isSpaceAiLoggingEnabled())
//	{
//		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::removeUnit() squadId(%d) newSize(%u)", m_id, m_unitMap->size()));
//		iterUnitMap = m_unitMap->begin();
//		int index = 1;
//
//		for (; iterUnitMap != m_unitMap->end(); ++iterUnitMap)
//		{
//			LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::removeUnit() squadId(%d) [%2d] unit(%s)", m_id, index, iterUnitMap->getValueString().c_str()));
//			++index;
//		}
//	}
//#endif // _DEBUG
}
コード例 #2
0
ファイル: Squad.cpp プロジェクト: Mesagoppinmypants/NGELinux
// ----------------------------------------------------------------------
void Squad::addUnit(NetworkId const & unit)
{
	// If this unit is the only unit in the squad, it is assigned as the squad leader

	UnitMap::const_iterator iterUnitMap = m_unitMap->find(CachedNetworkId(unit));

	if (iterUnitMap == m_unitMap->end())
	{
		bool const leader = m_unitMap->empty();

		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::addUnit() className(%s) squadId(%d) unit(%s) leader(%s) squadSize(%d+1)", getClassName(), m_id, unit.getValueString().c_str(), leader ? "yes" : "no", m_unitMap->size()));

		//-- Add the unit to the new squad

		IGNORE_RETURN(m_unitMap->insert(std::make_pair(CachedNetworkId(unit), &PersistentCrcString::empty)));

		if (leader)
		{
			bool const rebuildFormation = true;
			IGNORE_RETURN(setLeader(unit, rebuildFormation));
		}

		m_formation.markDirty();

		onAddUnit(unit);
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("Squad::addUnit() className(%s) squadId(%d) unit(%s) is already in the squad, not re-adding", getClassName(), m_id, unit.getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}

//#ifdef _DEBUG
//	if (ConfigServerGame::isSpaceAiLoggingEnabled())
//	{
//		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::addUnit() squadId(%d) newSize(%u)", m_id, m_unitMap->size()));
//		iterUnitMap = m_unitMap->begin();
//		int index = 1;
//
//		for (; iterUnitMap != m_unitMap->end(); ++iterUnitMap)
//		{
//			LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::addUnit() squadId(%d) [%2d] unit(%s)", m_id, index, iterUnitMap->getValueString().c_str()));
//			++index;
//		}
//	}
//#endif // _DEBUG
}
コード例 #3
0
ファイル: Squad.cpp プロジェクト: Mesagoppinmypants/NGELinux
// ----------------------------------------------------------------------
void Squad::calculateSquadPosition_w()
{
	if (m_squadPositionUpdateTimer.getElapsedRatio() > 0.0f)
	{
		// The position has already been calculated this frame
		return;
	}

	m_squadPositionUpdateTimer.reset();

	UnitMap::const_iterator iterUnitMap = getUnitMap().begin();

	m_squadPosition_w = Vector::zero;

	for (; iterUnitMap != getUnitMap().end(); ++iterUnitMap)
	{
		NetworkId const & unit = (*iterUnitMap).first;

		Object * const object = NetworkIdManager::getObjectById(unit);

		if (object != NULL)
		{
			m_squadPosition_w += object->getPosition_w();
		}
		else
		{
#ifdef _DEBUG
			FormattedString<1024> fs;
			char const * const text = fs.sprintf("Squad::calculateSquadPosition_w() unit(%s) did not resolve to a valid object", unit.getValueString().c_str());
			DEBUG_WARNING(true, (text));
			LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
		}
	}

	if (getUnitMap().size() > 1)
	{
		m_squadPosition_w /= static_cast<float>(getUnitMap().size());
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("Squad::calculateSquadPosition_w() Why is there a zero size squad?");
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}
}
コード例 #4
0
ファイル: Font.cpp プロジェクト: psde/gosu
 double factorAt(const FormattedString& fs, unsigned index) const
 {
     if (fs.entityAt(index))
         return 1;
     else
         return 0.5;
 }
コード例 #5
0
// ----------------------------------------------------------------------
void SpaceAttackSquad::onNewLeader(NetworkId const & /*oldLeader*/)
{
	AiShipController * const newLeaderAiShipController = AiShipController::getAiShipController(getLeader());

	if (newLeaderAiShipController != NULL)
	{
		m_leaderOffsetPosition_l = -newLeaderAiShipController->getFormationPosition_l();
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("SpaceAttackSquad::onNewLeader() ERROR: The new leader(%s) could not be resolved to an AiShipController.", getLeader().getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}
}
コード例 #6
0
// ----------------------------------------------------------------------
void SpaceAttackSquad::onSetUnitFormationPosition_l(NetworkId const & unit, Vector const & position_l)
{
	AiShipController * const aiShipController = AiShipController::getAiShipController(unit);

	if (aiShipController != NULL)
	{
		aiShipController->setAttackFormationPosition_l(position_l);
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("SpaceAttackSquad::onSetUnitFormationPosition_l() ERROR: Unable to resolve AiShipController for unit(%s)", unit.getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}
}
コード例 #7
0
// ----------------------------------------------------------------------
void SpaceAttackSquad::assignNewLeader()
{
	UnitMap const & unitMap = getUnitMap();
	UnitMap::const_iterator iterUnitMap = unitMap.begin();

	for (; iterUnitMap != unitMap.end(); ++iterUnitMap)
	{
		CachedNetworkId const & unit = iterUnitMap->first;
		Object * const unitObject = unit.getObject();
		ServerObject * const unitServerObject = (unitObject != NULL) ? unitObject->asServerObject() : NULL;
		ShipObject * const unitShipObject = (unitServerObject != NULL) ? unitServerObject->asShipObject() : NULL;

		if (unitShipObject != NULL)
		{
			if (unitShipObject->isComponentFunctional(ShipChassisSlotType::SCST_engine))
			{
				bool const rebuildFormation = false;

				if (!setLeader(unit, rebuildFormation))
				{
#ifdef _DEBUG
					FormattedString<1024> fs;
					char const * const text = fs.sprintf("SpaceAttackSquad::assignNewLeader() squadId(%d) ERROR: Failure to set the new squad leader(%s)", getId(), unit.getValueString().c_str());
					DEBUG_WARNING(true, (text));
					LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
				}
				else
				{
					break;
				}
			}
		}
		else
		{
#ifdef _DEBUG
			FormattedString<1024> fs;
			char const * const text = fs.sprintf("SpaceAttackSquad::assignNewLeader() ERROR: Could not convert unit(%s) to a ShipObject.", unit.getValueString().c_str());
			DEBUG_WARNING(true, (text));
			LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
		}
	}
}
コード例 #8
0
ファイル: Squad.cpp プロジェクト: Mesagoppinmypants/NGELinux
// ----------------------------------------------------------------------
bool Squad::setLeader(NetworkId const & unit, bool const rebuildFormation)
{
	LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("Squad::setLeader() className(%s) squadId(%d) unit(%s) rebuildFormation(%s)", getClassName(), m_id, unit.getValueString().c_str(), rebuildFormation ? "yes" : "no"));

	if (   isEmpty()
	    && (unit == NetworkId::cms_invalid))
	{
		m_leader = CachedNetworkId::cms_cachedInvalid;

		return true;
	}

	bool result = false;
	UnitMap::iterator iterUnitMap = m_unitMap->find(CachedNetworkId(unit));

	if (iterUnitMap != m_unitMap->end())
	{
		result = true;

		NetworkId oldLeader(m_leader);
		m_leader = CachedNetworkId(unit);
		onNewLeader(oldLeader);

		if (rebuildFormation)
		{
			m_formation.markDirty();
		}
	}
	else
	{
		m_leader = CachedNetworkId::cms_cachedInvalid;

#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("Squad::setLeader() ERROR: className(%s) Trying to set a leader(%s) who is not a member of the squad.", getClassName(), unit.getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}

	return result;
}
コード例 #9
0
// ----------------------------------------------------------------------
void SpaceAttackSquad::onAddUnit(NetworkId const & unit)
{
	AiShipController * const aiShipController = AiShipController::getAiShipController(unit);
	
	if (aiShipController != NULL)
	{
		aiShipController->setAttackSquad(this);
	}
	else
	{
#ifdef _DEBUG
		FormattedString<1024> fs;
		char const * const text = fs.sprintf("SpaceAttackSquad::onAddUnit() id(%d) ERROR: Trying to add a unit(%s) that can't resolve to an AiShipController.", getId(), unit.getValueString().c_str());
		DEBUG_WARNING(true, (text));
		LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
	}

	calculateAttackRanges();
}
コード例 #10
0
// ----------------------------------------------------------------------
bool SpaceAttackSquad::isAttacking() const
{
	Object * const leaderObject = getLeader().getObject();

	if (leaderObject != NULL)
	{
		AiShipController * const leaderAiShipController = AiShipController::asAiShipController(leaderObject->getController());

		return leaderAiShipController->isAttacking();
	}

#ifdef _DEBUG
	FormattedString<1024> fs;
	char const * const text = fs.sprintf("SpaceAttackSquad::isAttacking() ERROR: Why is the attack squad leader(%s) object NULL?", getLeader().getValueString().c_str());
	DEBUG_WARNING(true, (text));
	LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG

	return false;
}
コード例 #11
0
ファイル: ChatLogManager.cpp プロジェクト: grserver/infinity
//-----------------------------------------------------------------------------
void ChatLogManager::getReportHeader(Unicode::String & header, std::string const &reportingPlayer, NetworkId const &reportingPlayerNetworkId, std::string const &reportingPlayerStationName, uint32 reportingPlayerStationId, std::string const &harassingPlayer, NetworkId const &harassingPlayerNetworkId, std::string const &harassingPlayerStationName, uint32 harassingPlayerStationId)
{
    header.clear();
    header.append(Unicode::narrowToWide("\n\n//--------------------------------------------------------\n"));

    FormattedString<512> fs;

    // Reporting

    header.append(Unicode::narrowToWide(fs.sprintf("Reporting: %s (%s)", reportingPlayer.c_str(), reportingPlayerNetworkId.getValueString().c_str())));

    if (!reportingPlayerStationName.empty() || (reportingPlayerStationId > 0))
    {
        header.append(Unicode::narrowToWide(" Station ID:"));
        if (!reportingPlayerStationName.empty())
            header.append(Unicode::narrowToWide(fs.sprintf(" %s", reportingPlayerStationName.c_str())));
        if (reportingPlayerStationId > 0)
            header.append(Unicode::narrowToWide(fs.sprintf(" (%lu)", reportingPlayerStationId)));
    }

    header.append(Unicode::narrowToWide("\n"));

    // Harassing

    header.append(Unicode::narrowToWide(fs.sprintf("Harassing: %s (%s)", harassingPlayer.c_str(), harassingPlayerNetworkId.getValueString().c_str())));

    if (!harassingPlayerStationName.empty() || (harassingPlayerStationId > 0))
    {
        header.append(Unicode::narrowToWide(" Station ID:"));
        if (!harassingPlayerStationName.empty())
            header.append(Unicode::narrowToWide(fs.sprintf(" %s", harassingPlayerStationName.c_str())));
        if (harassingPlayerStationId > 0)
            header.append(Unicode::narrowToWide(fs.sprintf(" (%lu)", harassingPlayerStationId)));
    }

    header.append(Unicode::narrowToWide("\n"));

    // Creation time

    header.append(Unicode::narrowToWide(fs.sprintf("Log Creation Time: %s\n", getTimeString(Os::getRealSystemTime()).c_str())));

    // Time length

    header.append(Unicode::narrowToWide(fs.sprintf("Log Time Length: %d minutes\n", ConfigServerUtility::getChatLogMinutes())));
}
コード例 #12
0
// ----------------------------------------------------------------------
void SpaceAttackSquad::calculateAttackRanges()
{
	if (!isEmpty())
	{
		m_projectileAttackRange = FLT_MAX;
		m_weaponAttackRange = FLT_MAX;
	}

	UnitMap const & unitMap = getUnitMap();
	UnitMap::const_iterator iterUnitMap = unitMap.begin();

	for (; iterUnitMap != unitMap.end(); ++iterUnitMap)
	{
		CachedNetworkId const & unit = iterUnitMap->first;
		Object * const unitObject = unit.getObject();
		ServerObject * const unitServerObject = (unitObject != NULL) ? unitObject->asServerObject() : NULL;
		ShipObject * const unitShipObject = (unitServerObject != NULL) ? unitServerObject->asShipObject() : NULL;

		if (unitShipObject != NULL)
		{
			m_projectileAttackRange = std::min(m_projectileAttackRange, unitShipObject->getApproximateAttackRange());
			
			bool includeMissiles = true;
			m_weaponAttackRange = std::min(m_projectileAttackRange, unitShipObject->getApproximateAttackRange(includeMissiles));
		}
		else
		{
#ifdef _DEBUG
			FormattedString<1024> fs;
			char const * const text = fs.sprintf("SpaceAttackSquad::calculateProjectileAttackRange() ERROR: Could not convert unit(%s) to a ShipObject.", unit.getValueString().c_str());
			DEBUG_WARNING(true, (text));
			LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", (text));
#endif // _DEBUG
		}
	}

	LOGC(ConfigServerGame::isSpaceAiLoggingEnabled(), "space_debug_ai", ("SpaceAttackSquad::calculateProjectileAttackRange() m_projectileAttackRange(%.0f) m_weaponAttackRange(%.0f)", m_projectileAttackRange, m_weaponAttackRange));
}
コード例 #13
0
ファイル: Font.cpp プロジェクト: ChicoTeam/gosu
 double factorAt(const FormattedString& fs, unsigned index)
 {
     if (fs.entityAt(index))
         return 1;
     return charInfo(fs.charAt(index), fs.flagsAt(index)).factor;
 }