Пример #1
0
bool City::expend_resource(Resource res, int amount)
{
  if (!has_resource(res, amount)) {
    return false;
  }
  resources[res] -= amount;
  return true;
}
Пример #2
0
bool City::expend_resource(Resource_amount res)
{
  if (!has_resource(res)) {
    return false;
  }
  resources[res.type] -= res.amount;
  return true;
}
Пример #3
0
bool City::has_resources(std::vector<Resource_amount> res_used)
{
  for (int i = 0; i < res_used.size(); i++) {
    if (!has_resource( res_used[i] )) {
      return false;
    }
  }
  return true;
}
Пример #4
0
bool GatherAbility::can_invoke(Unit &to_modify, const Command &cmd) {
	if (cmd.has_unit()) {
		Unit &target = *cmd.unit();
		return &to_modify != &target &&
		       to_modify.location &&
		       to_modify.has_attribute(attr_type::gatherer) &&
		       has_resource(target);
	}
	return false;
}
Пример #5
0
bool City::has_resources(std::map<Resource,int> res_used)
{
  for (std::map<Resource,int>::iterator it = res_used.begin();
       it != res_used.end();
       it++) {
    if (!has_resource(it->first, it->second)) {
      return false;
    }
  }
  return true;
}
Пример #6
0
bool AttackAbility::can_invoke(Unit &to_modify, const Command &cmd) {
	if (cmd.has_unit()) {
		Unit &target = *cmd.unit();
		bool target_is_resource = has_resource(target);
		return &to_modify != &target &&
		       to_modify.location &&
		       target.location &&
		       target.location->is_placed() &&
		       to_modify.has_attribute(attr_type::attack) &&
		       has_hitpoints(target) &&
		       (is_enemy(to_modify, target) || target_is_resource) &&
		       (cmd.has_flag(command_flag::attack_res) == target_is_resource);
	}
	return false;
}
Пример #7
0
bool City::has_resource(Resource_amount res)
{
  return has_resource(res.type, res.amount);
}