コード例 #1
0
bool MkDataPack::operator == (const MkDataPack& source) const
{
	if (GetUnitCount() != source.GetUnitCount())
		return false;

	MkArray<MkHashStr> myOwn;
	GetUnitKeyList(myOwn);
	MK_INDEXING_LOOP(myOwn, i)
	{
		if (!source.IsValidKey(myOwn[i]))
			return false;
	}
	MK_INDEXING_LOOP(myOwn, i)
	{
		const MkHashStr& currKey = myOwn[i];
		if (!source.Equals(currKey, *m_UnitTable[currKey]))
			return false;
	}
	return true;
}
コード例 #2
0
ファイル: XAIGroup.cpp プロジェクト: rrti/ai-libs
bool XAIGroup::Update(bool incAge) {
	// note: uniform group, so all these are
	// equal to the values for the lead unit
	centerPos      =  ZeroVector;
	buildDist      =  1e9f;
	losDist        =  0.0f;
	minWeaponRange =  1e9f;
	maxWeaponRange =  0.0f;
	moveSpeed      =  1e9f;
	buildSpeed     =  0.0f;
	reclaimSpeed   =  0.0f;
	repairSpeed    =  0.0f;
	mtlCost        =  0.0f;
	nrgCost        =  0.0f;
	pathType       = -1;
	power          =  0.0f;

	isMobile   = true;
	isAttacker = false;
	isBuilder  = false;

	const MoveData* groupMoveData = 0;

	// note: groups are uniform, so we don't need to iterate
	// over all units to calculate the total buildSpeed etc.
	for (std::map<int, XAICUnit*>::iterator it = unitsByID.begin(); it != unitsByID.end(); it++) {
		const XAICUnit*   unit    = it->second;
		const XAIUnitDef* unitDef = unit->GetUnitDefPtr();

		assert(unit->GetUnitDefPtr() != 0);
		assert(unit->GetGroupPtr() == this);

		centerPos     += (unit->GetPos());
		buildSpeed    += unitDef->GetDef()->buildSpeed;
		reclaimSpeed  += unitDef->GetDef()->reclaimSpeed;
		repairSpeed   += unitDef->GetDef()->repairSpeed;
		buildDist      = std::min(unit->GetUnitDefPtr()->GetBuildDist(), buildDist);
		losDist        = std::max(unit->GetUnitDefPtr()->GetDef()->losRadius, losDist);
		minWeaponRange = std::min(unit->GetUnitDefPtr()->minWeaponRange, minWeaponRange);
		maxWeaponRange = std::max(unit->GetUnitDefPtr()->maxWeaponRange, maxWeaponRange);
		moveSpeed      = std::min(unit->GetUnitDefPtr()->GetMaxSpeed(), moveSpeed);
		mtlCost       += unitDef->GetDef()->metalCost;
		nrgCost       += unitDef->GetDef()->energyCost;
		power         += unitDef->GetPower();

		groupMoveData = unitDef->GetMoveData();

		isMobile   = (isMobile   && unitDef->isMobile  );
		isAttacker = (isAttacker || unitDef->isAttacker);
		isBuilder  = (isBuilder  || unitDef->isBuilder );
	}

	if (isMobile) {
		assert(moveSpeed > 0.0f);
	}
	if (groupMoveData != 0) {
		pathType = groupMoveData->pathType;
	}

	if (centerPos != ZeroVector) {
		centerPos /= GetUnitCount();
	}

	if (incAge) {
		age++;
	}

	// if true, group will be deleted by handler
	return (GetUnitCount() == 0);
}
コード例 #3
0
ファイル: javabind.cpp プロジェクト: Gepard/spring
	/*
	* Class:     aflobby_CUnitSyncJNIBindings
	* Method:    GetUnitCount
	* Signature: ()I
	*/
	JNIEXPORT jint JNICALL Java_aflobby_CUnitSyncJNIBindings_GetUnitCount
		(JNIEnv *env, jclass myobject){
			return GetUnitCount();
		}