示例#1
0
void BaseInfo::RemoveBuilding(int building)
{
	if (buildingCount==0)
	{
		return;
	}
	Unit *buildingU = Unit::GetInstance(ai->callback, building);
	UnitDef *def = quadTree->GetUnitDef(building);
	//remove unit from quadtree, using pos
	if(def != NULL)
	{
		buildingCount--;

		if(def->IsBuilder())
		{
			productionBuildings--;
		}
		else
		{
			resourceBuildings--;
		}

		ai->knowledge->mapInfo->pathfindingMap->RemoveBuilding( buildingU );
	}
	else
		ai->utility->Log(ALL,KNOWLEDGE,"RemoveBuilding: We are trying to remove a seen building with no unitdef"); 

	quadTree->RemoveUnit( building );
	delete buildingU;
	buildingU = NULL;
	delete def;
	def = NULL;
}
SAIFloat3 ConstructionUnitGroup::FindGoodBuildSite(SAIFloat3 builderPos, UnitDef* building, float radius)
{
	SAIFloat3 bestBuildSpot=builderPos;
	float bestDistance = radius*radius+1;
	bool foundBuildSite = false;
	Map *map = ai->callback->GetMap();
	
	vector<Unit*> nearByBuildings = ai->knowledge->selfInfo->baseInfo->GetUnitsInRange(builderPos, radius);
	vector<Unit*>::iterator it;
	for(it = nearByBuildings.begin(); it != nearByBuildings.end(); it++)
	{
		UnitDef* ud = (*it)->GetDef();
		if(!ud->IsBuilder())
		{
			SAIFloat3 unitPos = (*it)->GetPos();
			float muls[][2] = {{-1,0},{1,0},{0,-1},{0,1}};//left, right, up, down
			for(int i=0; i<4;i++)
			{
				SAIFloat3 newPos = unitPos;
				newPos.x += muls[i][0]*((ud->GetXSize()*8/2)+(building->GetXSize()*8/2));
				newPos.z += muls[i][1]*((ud->GetZSize()*8/2)+(building->GetZSize()*8/2));
				float newDist = ai->utility->EuclideanDistance(builderPos,newPos);
				
				if(newDist < bestDistance
					&&  map->IsPossibleToBuildAt(*building, newPos, 0)
					&& !IsMetalExtracitonSite(building, newPos)
					&& !BuildBlocksSelf(building, newPos, 0) )
				{
					//TODO: test if it is blocking a contruction yard
					bestBuildSpot = newPos;
					bestDistance = newDist;
					foundBuildSite = true;
				}
			}
		}
		delete (*it);
		delete ud;
	}
	delete map;
	if (!foundBuildSite)
	{
		//We didn't find a good BuildSite (e.g. no non-builder buildings)
		bestBuildSpot = FindClosestNonConflictingBuildSite(building, builderPos, radius, 0, 0);
	}

	return bestBuildSpot;
}
示例#3
0
bool GroupController::UnitIdle( Unit* unit )
{
	bool allIdle = false;
	ai->utility->Log(ALL, MISC, "GroupController::UnitIdle()");
	UnitDef *def = unit->GetDef();
	if ( def->IsBuilder() )
	{
		ConstructionGroupMgr->UnitIdle( unit );
		return false;//TODO: CORRECT THIS
	}
	else
	{
		allIdle = MilitaryGroupMgr->UnitIdle(unit);
	}
	delete def;
	return allIdle;
}
示例#4
0
void GroupController::AddUnit(Unit *unit)
{
	UnitDef* d = unit->GetDef();
	if ( d->IsBuilder() )
	{
		ConstructionGroupMgr->AddUnit( unit );
	}
	else if ( d->IsAbleToAttack() )
	{

		if ( d->IsCommander() ) 
		{
			delete d;
			return;
		}
		MilitaryGroupMgr->AddUnit( unit );
	}
	delete d;
}