本文整理汇总了C++中ActionType::mineralPrice方法的典型用法代码示例。如果您正苦于以下问题:C++ ActionType::mineralPrice方法的具体用法?C++ ActionType::mineralPrice怎么用?C++ ActionType::mineralPrice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActionType
的用法示例。
在下文中一共展示了ActionType::mineralPrice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: whenMineralsReady
// when will minerals be ready
const FrameCountType GameState::whenMineralsReady(const ActionType & action) const
{
if (_minerals >= action.mineralPrice())
{
return getCurrentFrame();
}
UnitCountType currentMineralWorkers = _units.getNumMineralWorkers();
UnitCountType currentGasWorkers = _units.getNumGasWorkers();
FrameCountType lastActionFinishFrame = _currentFrame;
FrameCountType addedTime = 0;
ResourceCountType addedMinerals = 0;
ResourceCountType difference = action.mineralPrice() - _minerals;
// loop through each action in progress, adding the minerals we would gather from each interval
for (size_t i(0); i<_units.getNumActionsInProgress(); ++i)
{
// the vector is sorted in descending order
size_t progressIndex = _units.getNumActionsInProgress() - i - 1;
// the time elapsed and the current minerals per frame
FrameCountType elapsed = _units.getFinishTimeByIndex(progressIndex) - lastActionFinishFrame;
ResourceCountType mineralsPerFrame = (currentMineralWorkers * Constants::MPWPF);
// the amount of minerals that would be added this time step
ResourceCountType tempAdd = elapsed * mineralsPerFrame;
// if this amount isn't enough, update the amount added for this interval
if (addedMinerals + tempAdd < difference)
{
addedMinerals += tempAdd;
addedTime += elapsed;
}
else
{
// otherwise we can just break out and update at the end
break;
}
// if it was a drone or extractor update the temp variables
const ActionType & actionPerformed = _units.getActionInProgressByIndex(progressIndex);
// finishing a building as terran gives you a mineral worker back
if (actionPerformed.isBuilding() && !actionPerformed.isAddon() && (getRace() == Races::Terran))
{
currentMineralWorkers++;
}
if (actionPerformed.isWorker())
{
currentMineralWorkers++;
}
else if (actionPerformed.isRefinery())
{
BOSS_ASSERT(currentMineralWorkers > 3, "Not enough mineral workers \n%s", toString().c_str());
currentMineralWorkers -= 3;
currentGasWorkers += 3;
}
// update the last action
lastActionFinishFrame = _units.getFinishTimeByIndex(progressIndex);
}
// if we still haven't added enough minerals, add more time
if (addedMinerals < difference)
{
BOSS_ASSERT(currentMineralWorkers > 0, "Shouldn't have 0 mineral workers");
FrameCountType finalTimeToAdd;
if (currentMineralWorkers != 0)
{
finalTimeToAdd = (difference - addedMinerals) / (currentMineralWorkers * Constants::MPWPF);
}
else
{
finalTimeToAdd = 1000000;
}
addedMinerals += finalTimeToAdd * currentMineralWorkers * Constants::MPWPF;
addedTime += finalTimeToAdd;
// the last operation could have added one frame too little due to integer division so we need to check
if (addedMinerals < difference)
{
addedTime += 1;
addedMinerals += currentMineralWorkers * Constants::MPWPF;
}
}
BOSS_ASSERT(addedMinerals >= difference, "Mineral prediction error");
// for some reason if i don't return +1, i mine 1 less mineral in the interval
return _currentFrame + addedTime;
}
示例2: canAffordMinerals
bool GameState::canAffordMinerals(const ActionType & action) const
{
return _minerals >= action.mineralPrice();
}
示例3: elapsed
// do an action, action must be legal for this not to break
std::vector<ActionType> GameState::doAction(const ActionType & action)
{
BOSS_ASSERT(action.getRace() == _race, "Race of action does not match race of the state");
_actionsPerformed.push_back(ActionPerformed());
_actionsPerformed[_actionsPerformed.size()-1].actionType = action;
BOSS_ASSERT(isLegal(action), "Trying to perform an illegal action: %s %s", action.getName().c_str(), getActionsPerformedString().c_str());
// set the actionPerformed
_actionPerformed = action;
_actionPerformedK = 1;
FrameCountType workerReadyTime = whenWorkerReady(action);
FrameCountType ffTime = whenCanPerform(action);
BOSS_ASSERT(ffTime >= 0 && ffTime < 1000000, "FFTime is very strange: %d", ffTime);
auto actionsFinished=fastForward(ffTime);
_actionsPerformed[_actionsPerformed.size()-1].actionQueuedFrame = _currentFrame;
_actionsPerformed[_actionsPerformed.size()-1].gasWhenQueued = _gas;
_actionsPerformed[_actionsPerformed.size()-1].mineralsWhenQueued = _minerals;
// how much time has elapsed since the last action was queued?
FrameCountType elapsed(_currentFrame - _lastActionFrame);
_lastActionFrame = _currentFrame;
BOSS_ASSERT(canAffordMinerals(action), "Minerals less than price: %ld < %d, ffTime=%d %s", _minerals, action.mineralPrice(), (int)elapsed, action.getName().c_str());
BOSS_ASSERT(canAffordGas(action), "Gas less than price: %ld < %d, ffTime=%d %s", _gas, action.gasPrice(), (int)elapsed, action.getName().c_str());
// modify our resources
_minerals -= action.mineralPrice();
_gas -= action.gasPrice();
// do race specific things here
if (getRace() == Races::Protoss)
{
_units.addActionInProgress(action, _currentFrame + action.buildTime());
}
else if (getRace() == Races::Terran)
{
if (action.isBuilding() && !action.isAddon())
{
if (getNumMineralWorkers() == 0)
{
std::cout << toString() << std::endl;
}
BOSS_ASSERT(getNumMineralWorkers() > 0, "Don't have any mineral workers to assign");
_units.setBuildingWorker();
}
_units.addActionInProgress(action, _currentFrame + action.buildTime());
}
else if (getRace() == Races::Zerg)
{
// zerg must subtract a larva if the action was unit creation
if (action.isUnit() && !action.isBuilding())
{
if (action.isMorphed())
{
_units.morphUnit(action.whatBuildsActionType(), action, _currentFrame + action.buildTime());
}
else
{
BOSS_ASSERT(getHatcheryData().numLarva() > 0, "We should have a larva to use");
_units.getHatcheryData().useLarva();
_units.addActionInProgress(action, _currentFrame + action.buildTime());
}
}
else if (action.isBuilding())
{
_units.morphUnit(action.whatBuildsActionType(), action, _currentFrame + action.buildTime());
}
else
{
// if it's not a unit or a building it's a tech so we queue it normally
_units.addActionInProgress(action, _currentFrame + action.buildTime());
}
}
return actionsFinished;
}