Esempio n. 1
0
void SwgSnapshot::decodePersistedBuffs   (Archive::ReadIterator &data, DB::BufferString &dbString) const
{
	const unsigned version = 2;

	std::string packedValue;

	Archive::AutoDeltaMap<uint32, Buff::PackedBuff> temp;
	Archive::get(data,  temp);
	std::map<uint32, Buff::PackedBuff> const& rawMap = temp.getMap();

	FormattedString<200> formater;

	if(rawMap.empty())
	{
		packedValue = " ";
	}
	else
	{
		packedValue += formater.sprintf(versionFormat, version);

		for(std::map<uint32, Buff::PackedBuff>::const_iterator i = rawMap.begin(); i != rawMap.end(); ++i)
		{
			uint32 tempCrc = (*i).first;
			Buff::PackedBuff const & tempPacked = (*i).second;
			packedValue += formater.sprintf(versionTwoFormat, tempCrc, tempPacked.endtime, tempPacked.value, tempPacked.duration, tempPacked.caster.getValue(), tempPacked.stackCount);
		}
	}

	dbString.setValue(packedValue);
}
Esempio n. 2
0
// ----------------------------------------------------------------------
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
	}
}
Esempio n. 3
0
// ----------------------------------------------------------------------
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
}
// ----------------------------------------------------------------------
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
		}
	}
}
Esempio n. 5
0
// ----------------------------------------------------------------------
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
}
Esempio n. 6
0
//-----------------------------------------------------------------------------
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())));
}
// ----------------------------------------------------------------------
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
	}
}
// ----------------------------------------------------------------------
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
	}
}
Esempio n. 9
0
// ----------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------
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();
}
// ----------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------
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));
}