Exemplo n.º 1
0
const std::string GUI::getTextureFileName(const ActionType & type) const
{
	std::string filename = "units/" + type.getName() + ".png";

    if (type.isTech())
    {
        filename = "command_icons/" + type.getName() + ".png";
    }
    else if (type.isUpgrade())
    {
        filename = "command_icons/" + type.getName() + ".png";
    }

	for (size_t i(0); i<filename.size(); ++i)
	{
		if (filename[i] == ' ')
		{
			filename[i] = '_';
		}
	}

	return filename;
}
Exemplo n.º 2
0
bool GameState::whyIsNotLegal(const ActionType & action) const
{
    const size_t numRefineries  = _units.getNumTotal(ActionTypes::GetRefinery(getRace()));
    const size_t numDepots      = _units.getNumTotal(ActionTypes::GetResourceDepot(getRace()));
    const size_t refineriesInProgress = _units.getNumInProgress(ActionTypes::GetRefinery(getRace()));

    // we can never build a larva
    static const ActionType & Zerg_Larva = ActionTypes::GetActionType("Zerg_Larva");
    if (action == Zerg_Larva)
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Cannot build a Larva" << std::endl;
        return false;
    }

    // check if the tech requirements are met
    if (!_units.hasPrerequisites(action.getPrerequisites()))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Tech requirements not met" << std::endl;
        return false;
    }

    // if it's a unit and we are out of supply and aren't making an overlord, it's not legal
    if (!action.isMorphed() && ((_units.getCurrentSupply() + action.supplyRequired()) > (_units.getMaxSupply() + _units.getSupplyInProgress())))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Not enough supply to construct" << std::endl;
        return false;
    }

    // specific rule for never leaving 0 workers on minerals
    if (action.isRefinery() && (getNumMineralWorkers() <= 4))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Cannot leave 0 workers on minerals" << std::endl;
        return false;
    }

    // if it's a new building and no drones are available, it's not legal
    if (!action.isMorphed() && action.isBuilding() && (getNumMineralWorkers() <= 1) && (getNumBuildingWorkers() == 0))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No building worker available" << std::endl;
        return false;
    }

    // we can't build a building with our last worker
    if (!action.isMorphed() && action.isBuilding() && (getNumMineralWorkers() <= 1 + 3*refineriesInProgress) && (getNumBuildingWorkers() == 0))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't build with last worker" << std::endl;
        return false;
    }

    // if we have no gas income we can't make a gas unit
    if (!canAffordGas(action) && !_units.hasGasIncome())
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No gas income for gas unit" << std::endl;
        return false;
    }

    // if we have no mineral income we'll never have a minerla unit
    if (!canAffordMinerals(action) && !_units.hasMineralIncome())
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - No mineral income" << std::endl;
        return false;
    }

    // don't build more refineries than resource depots
    if (action.isRefinery() && (numRefineries >= numDepots))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't have more refineries than depots" << std::endl;
        return false;
    }

    // we don't need to go over the maximum supply limit with supply providers
    if (action.isSupplyProvider() && (_units.getMaxSupply() + _units.getSupplyInProgress() >= 400))
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't go over max supply bound with providers" << std::endl;
        return false;
    }

    if (action.isTech() && getUnitData().getNumTotal(action) > 0)
    {
        std::cout << "WhyNotLegal: " << action.getName() << " - Can't produce additional copy of tech" << std::endl;
        return false;
    }

    return true;
}
Exemplo n.º 3
0
bool GameState::isLegal(const ActionType & action) const
{
    const size_t numRefineries  = _units.getNumTotal(ActionTypes::GetRefinery(getRace()));
    const size_t numDepots      = _units.getNumTotal(ActionTypes::GetResourceDepot(getRace()));
    const size_t refineriesInProgress = _units.getNumInProgress(ActionTypes::GetRefinery(getRace()));

    // we can never build a larva
    static const ActionType & Zerg_Larva = ActionTypes::GetActionType("Zerg_Larva");
    if (action == Zerg_Larva)
    {
        return false;
    }

    // check if the tech requirements are met
    if (!_units.hasPrerequisites(action.getPrerequisites()))
    {
        return false;
    }
	
    // if it's a unit and we are out of supply and aren't making an overlord, it's not legal
	if (!action.isMorphed() && !action.isSupplyProvider() && ((_units.getCurrentSupply() + action.supplyRequired()) > (_units.getMaxSupply() + _units.getSupplyInProgress())))
    {
        return false;
    }

    // TODO: require an extra for refineries byt not buildings
    // rules for buildings which are built by workers
    if (action.isBuilding() && !action.isMorphed() && !action.isAddon())
    {
        // be very strict about when we can make refineries to ensure we have enough workers to go in gas
        if (action.isRefinery() && (getNumMineralWorkers() <= (4 + 3*refineriesInProgress)))
        {
            return false;
        }

        int workersPerRefinery = 3;
        int workersRequiredToBuild = getRace() == Races::Protoss ? 0 : 1;
        int buildingIsRefinery = action.isRefinery() ? 1 : 0;
        int candidateWorkers = getNumMineralWorkers() + _units.getNumInProgress(ActionTypes::GetWorker(getRace())) + getNumBuildingWorkers();
        int workersToBeUsed = workersRequiredToBuild + workersPerRefinery*(refineriesInProgress);

        if (candidateWorkers < workersToBeUsed)
        {
            return false;
        }
    }

    // if we have no gas income we can't make a gas unit
    if (!canAffordGas(action) && !_units.hasGasIncome())
    {
        return false;
    }

    // if we have no mineral income we'll never have a minerla unit
    if (!canAffordMinerals(action) && !_units.hasMineralIncome())
    {
        return false;
    }

    // don't build more refineries than resource depots
    if (action.isRefinery() && (numRefineries >= numDepots))
    {
        return false;
    }

    // we don't need to go over the maximum supply limit with supply providers
    if (action.isSupplyProvider() && (_units.getMaxSupply() + _units.getSupplyInProgress() > 400))
    {
        return false;
    }

    // can only build one of a tech type
    if (action.isTech() && getUnitData().getNumTotal(action) > 0)
    {
        return false;
    }

    // check to see if an addon can ever be built
    if (action.isAddon() && !_units.getBuildingData().canBuildEventually(action) && (_units.getNumInProgress(action.whatBuildsActionType()) == 0))
    {
        return false;
    }

    return true;
}