コード例 #1
0
ファイル: production.cpp プロジェクト: daveinnes/game
void Production::buildUnit(char c) {
    if(mBuilt && !full() && canBuildUnit()) {
        mPendingUnit->subtractCost();
        mPendingUnit->addSupply();
        mUnits.push_back(mPendingUnit);
        mPendingUnit = nullptr;
    }
}
コード例 #2
0
void StructureAgent::computeActions()
{
	if (isAlive())
	{
		if (!unit->isIdle())
		{
			return;
		}

		if (UpgradesPlanner::getInstance()->checkUpgrade(this))
		{
			return;
		}

		if (BuildPlanner::isTerran())
		{
			//Check addons here
			if (isOfType(UnitTypes::Terran_Science_Facility))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Physics_Lab);
				}
			}
			if (isOfType(UnitTypes::Terran_Starport))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Control_Tower);
				}
			}
			if (isOfType(UnitTypes::Terran_Starport))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Control_Tower);
				}
			}
			if (isOfType(UnitTypes::Terran_Factory))
			{
				if (unit->getAddon() == NULL)
				{
					unit->buildAddon(UnitTypes::Terran_Machine_Shop);
				}
			}

			
			//scanner sweep on potential enemy locations(expansion sites) when having 200 energy
			if(isOfType(UnitTypes::Terran_Comsat_Station))
			{
				if(unit->getEnergy() == 200)
				{
					Broodwar->printf("200 energy reached for a comsat station, scanning with it...");
					vector<TilePosition> expSites = MalRilTilData::expansionPositions; //get expansion locations
					static int expSiteNr = 0;
					TilePosition scanPos = expSites.at(expSiteNr-- % expSites.size()); //next expansion site to scan
					
					//check for every unit if its in range of scan
					vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
					int scanRadius = 12 * 32; //in pixels (tank range = 12)
					for(int j = 0; j < (int)agents.size(); j++)
					{
						if(agents.at(j)->getUnit()->exists())
						{
							int dist = agents.at(j)->getUnit()->getDistance(Position(scanPos)); //distance(in pixels) between unit and scan position
							
							if(dist < scanRadius) //unit is within scanning radius, check next site
							{
								Broodwar->printf("Owned unit within scanning radius, checking next site...");
								scanPos = expSites.at(expSiteNr-- % expSites.size()); //get next expansion site
							}
						}
					}
					unit->useTech(TechTypes::Scanner_Sweep, Position(scanPos));
					Broodwar->printf("Scan used at: %d, %d", scanPos.x(), scanPos.y());
				}
			}

			/*If Comsat Station, check if we need to scan for enemy bases
			if (isOfType(UnitTypes::Terran_Comsat_Station))
			{
				TilePosition p = getNextScanLocation();
				if (p.x() != -1)
				{
					if (unit->getEnergy() >= 50)
					{
						//Broodwar->printf("Scanning (%d,%d)", p.x(), p.y());
						if (unit->useTech(TechTypes::Scanner_Sweep, Position(p)))
						{
							hasScanned.push_back(p);
							return;
						}
					}
				}
			}*/


			
		}

		if (!unit->isBeingConstructed() && unit->isIdle() && getUnit()->getType().canProduce())
		{
			//Iterate through all unit types
			for(set<UnitType>::iterator i=UnitTypes::allUnitTypes().begin();i!=UnitTypes::allUnitTypes().end();i++)
			{
				//Check if we can (and need) to build the unit
				if (canBuildUnit(*i))
				{
					//Build it!
					unit->train(*i);
				}
			}
		}
	}
}