コード例 #1
0
ファイル: RAI.cpp プロジェクト: genxinzou/svn-spring-archive
void cRAI::UnitCreated(int unit)
{
	const UnitDef* ud=cb->GetUnitDef(unit);
	if( RAIDEBUGGING ) { *l<<"\nUnitCreated("<<unit; *l<<")["+ud->humanName+"]"; }
	Units.insert(iuPair(unit,UnitInfo(&UDH->UDR.find(ud->id)->second)));
	UnitInfo* U = &Units.find(unit)->second;
	float3 position = cb->GetUnitPos(unit);
	U->area = GetCurrentMapArea(U->udr,position);

	if( ud->speed == 0 )
	{
		for(map<int,UnitInfo*>::iterator i=UImmobile.begin(); i!=UImmobile.end(); i++ )
		{
			if( U->udr->WeaponGuardRange > 0 && i->second->udr->WeaponGuardRange == 0 && position.distance2D(cb->GetUnitPos(i->first)) < U->udr->WeaponGuardRange )
			{
				U->UDefending.insert(cRAI::iupPair(i->first,i->second));
				i->second->UDefences.insert(cRAI::iupPair(unit,U));
			}
			else if( U->udr->WeaponGuardRange == 0 && i->second->udr->WeaponGuardRange > 0 && position.distance2D(cb->GetUnitPos(i->first)) < i->second->udr->WeaponGuardRange )
			{
				U->UDefences.insert(cRAI::iupPair(i->first,i->second));
				i->second->UDefending.insert(cRAI::iupPair(unit,U));
			}
		}
		UImmobile.insert(iupPair(unit,U));
	}
	else
		UMobile.insert(iupPair(unit,U));

	B->UnitCreated(unit,U);
	B->BP->UResourceCreated(unit,U);
	if( RAIDEBUGGING ) *l<<"#";
}
コード例 #2
0
void UnitData::updateUnit(BWAPI::Unit * unit)
{
	if (!unit) { return; }
	
	// if the unit exists, update it
	if (unitMap.find(unit) != unitMap.end())
	{
		UnitInfo & ui = unitMap.find(unit)->second;

		ui.lastPosition = unit->getPosition();
		ui.lastHealth = unit->getHitPoints() + unit->getShields();
		ui.unitID = unit->getID();
		ui.type = unit->getType();

		return;
	}
	// otherwise create it
	else
	{
		// put the unit in the map
		numUnits[unit->getType().getID()]++;
		unitMap[unit] = UnitInfo(unit->getID(), unit, unit->getPosition(), unit->getType());
	}
}
コード例 #3
0
void InformationStorage::loadAll(string file)
{
	//Clear out the object types first
	terrainTypes.clear();
	buildingTypes.clear();
	unitTypes.clear();
	
	TiXmlDocument doc( file.c_str());
	if(doc.LoadFile())
	{
		TiXmlHandle hDoc(&doc);
		TiXmlElement* pElem;
		TiXmlHandle hRoot(0);
		pElem = hDoc.FirstChildElement().Element();
		hRoot=TiXmlHandle(pElem);


		//--------------------------------Load in Units----------------------

		TiXmlNode* pUnitNode=hRoot.FirstChild( "Units" ).FirstChild().ToNode();
		TiXmlNode* pUnitInfoNode;
		//For loop will cycle through each unit within the Units tag
		for( pUnitNode; pUnitNode; pUnitNode=pUnitNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			UnitInfo u = UnitInfo();
			u.load(pUnitNode);
			unitTypes[u.id] = u;
		}



		//----------------------Load in Terrain-------------------------------

		TiXmlNode* pTerrainNode=hRoot.FirstChild( "Terrain" ).FirstChild().ToNode();
		TiXmlNode* pTerrainInfoNode;
		//For loop will cycle through each unit within the Units tag
		for( pTerrainNode; pTerrainNode; pTerrainNode=pTerrainNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			TerrainInfo t = TerrainInfo();
			t.load(pTerrainNode);
			terrainTypes[t.id] = t;
		}


		//---------------------------------Load in Buildings--------------------------------------

		TiXmlNode* pBuildingNode=hRoot.FirstChild( "Buildings" ).FirstChild().ToNode();
		//TiXmlNode* pBuildingInfoNode;
		//TiXmlNode* pProductionIDNode;
		//For loop will cycle through each unit within the Units tag
		for( pBuildingNode; pBuildingNode; pBuildingNode=pBuildingNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			BuildingInfo b = BuildingInfo();
			b.load(pBuildingNode);
			buildingTypes[b.id] = b;
		}

		//-------------------------------Load in Commander Cards--------------------------------
		TiXmlNode* pCardNode = hRoot.FirstChild( "Cards" ).FirstChild().ToNode();
		for( pCardNode; pCardNode; pCardNode=pCardNode->NextSiblingElement())
		{
			CardInfo c = CardInfo();
			c.load(pCardNode);
			cardTypes[c.id] = c;
		}


	}
	else
	{
		//std::cout << "\nFailed to load the units\n";
	}

	DeveloperConsole::write("Buildings Loaded: ");
	DeveloperConsole::writeLine(buildingTypes.size());
	DeveloperConsole::write("Units Loaded: ");
	DeveloperConsole::writeLine(unitTypes.size());
	DeveloperConsole::write("Terrain Loaded: ");
	DeveloperConsole::writeLine(terrainTypes.size());
	

}