Exemplo n.º 1
0
void BaseInfo::AddBuilding(Unit* building)
{
	UnitDef* d = building->GetDef();
	//check for builder units
	if(d->GetSpeed() > 0)
	{
		delete d;
		d = NULL;
		return;
	}
	delete d;
	d = NULL;
	//ai->utility->Log(ALL, MISC, "Adding base unit...");
	map<int, UnitInformationContainer> units = quadTree->GetUnits();

	if ( units.find(building->GetUnitId()) == units.end())
	{
		quadTree->InsertUnit(building->GetUnitId(), building->GetPos());

		buildingCount++;
		if(building->GetDef()->IsBuilder())
		{
			productionBuildings++;
		}
		else
		{
			resourceBuildings++;
		}

		ai->knowledge->mapInfo->pathfindingMap->AddBuilding( building );

	}
}
Exemplo n.º 2
0
void ArmyInfo::RemoveUnit(int unit)
{
	//if (unitCount==0)
	//{
	//	return;
	//}
	bool removed = quadTree->RemoveUnit( unit);
	if (removed)
	{
		Unit* u = Unit::GetInstance(ai->callback, unit);
		unitCount--;
		UnitDef *unitDef = u->GetDef();
		if(unitDef != NULL)
		{

			if(unitDef->GetSpeed() > 0)
			{
				aggressive--;
				aggressiveDps -= ai->utility->GetDpsFromUnitDef(unitDef);
			}
			else
			{
				defensive--;
				defensiveDps -= ai->utility->GetDpsFromUnitDef(unitDef);
			}
		}
		delete unitDef;
		unitDef = NULL;
		delete u;
		u = NULL;
	}	
}
Exemplo n.º 3
0
//updates the position of the unit in the QuadTree.
void ArmyInfo::UpdateUnit(Unit* unit)
{
	UnitDef* unitDef = unit->GetDef();
	vector<WeaponMount*> wpmt = unitDef->GetWeaponMounts();
	if ( wpmt.size() == 0 )
	{
		delete unitDef;
		unitDef = NULL;
		return;
	}
	wpmt.clear();
	
	SAIFloat3 new_pos = unit->GetPos();
	int i = quadTree->UpdateUnit( unit->GetUnitId(), unit->GetPos() );
	unitCount += i;
	if (unitDef == NULL) {
		return;//we dont know this unit?!
	}
	knownUnitDefs[unit->GetUnitId()] = unitDef;
	

	if(i != 0)
	{
		if(unitDef->GetSpeed() > 0)
		{
			aggressive += i;
			aggressiveDps += ai->utility->GetDpsFromUnitDef(unitDef);
		}
		else
		{
			defensive += i;
			defensiveDps += ai->utility->GetDpsFromUnitDef(unitDef);
		}
	}
	delete unitDef;
	unitDef = NULL;
}