File diff r7762:f53dd1eec4cf → r7763:878d494b5f57
src/command.cpp
Show inline comments
 
@@ -668,43 +668,31 @@ callb_err:
 
CommandCost CommandCost::AddCost(CommandCost ret)
 
{
 
	this->AddCost(ret.cost);
 
	if (this->success && !ret.success) {
 
		this->message = ret.message;
 
		this->success = false;
 
	}
 
	return *this;
 
}
 

	
 
CommandCost CommandCost::AddCost(Money cost)
 
{
 
	/* Overflow protection */
 
	if (cost < 0 && (this->cost + cost) > this->cost) {
 
		this->cost = INT64_MIN;
 
	} else if (cost > 0 && (this->cost + cost) < this->cost) {
 
		this->cost = INT64_MAX;
 
	} else  {
 
		this->cost += cost;
 
	}
 
	this->cost += cost;
 
	return *this;
 
}
 

	
 
CommandCost CommandCost::MultiplyCost(int factor)
 
{
 
	/* Overflow protection */
 
	if (factor != 0 && (INT64_MAX / myabs(factor)) < myabs(this->cost)) {
 
		this->cost = (this->cost < 0 == factor < 0) ? INT64_MAX : INT64_MIN;
 
	} else {
 
		this->cost *= factor;
 
	}
 
	this->cost *= factor;
 
	return *this;
 
}
 

	
 
Money CommandCost::GetCost() const
 
{
 
	return this->cost;
 
}
 

	
 
void CommandCost::SetGlobalErrorMessage() const
 
{
 
	extern StringID _error_message;
 
	if (this->message != INVALID_STRING_ID) _error_message = this->message;