コード例 #1
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
 int addHero(HeroProfile* h)
 {
     assert(globalHeroTable.count(h->tableId)==0 && "duplicate HeroProfile");
     globalHeroTable[h->tableId] = h;
     
     return globalHeroTable.size();
 }
コード例 #2
0
ファイル: restaurant.hpp プロジェクト: nozyh/topiclm
inline void Restaurant::FillInPredictivesNonGraphical(
    const std::vector<double>& parent_predictives,
    int type,
    int depth,
    const HPYParameter& hpy_parameter,
    std::vector<double>& predictives) const {
  for (size_t i = 0; i < parent_predictives.size(); ++i) {
    predictives[i] = parent_predictives[i];
  }
  for (auto floor_it = floor2c_t_.begin(); floor_it != floor2c_t_.end(); ++floor_it) {
    auto floor_id = (*floor_it).first;
    auto& c_t = (*floor_it).second;
    tmp_c_[floor_id] = c_t.first;
    predictives[floor_id] *=
        (hpy_parameter.concentration(depth, floor_id)
         + hpy_parameter.discount(depth, floor_id) * c_t.second)
        / (c_t.first + hpy_parameter.concentration(depth, floor_id));
  }
  auto type_it = type2internal_.find(type);
  if (type_it == type2internal_.end()) return;

  auto& sections = (*type_it).second.sections_;
  auto section_it = sections.begin();
  for (; section_it != sections.end(); ++section_it) {
    auto floor_id = (*section_it).first;
    auto& section = (*section_it).second;
    auto cw = section.customers;
    auto tw = section.tables;
    predictives[floor_id] +=
        (cw - hpy_parameter.discount(depth, floor_id) * tw)
        / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id));
  }
}
コード例 #3
0
ファイル: floor_sampler.cpp プロジェクト: nozyh/topiclm
void FloorSampler::TakeInSectionLL(
    const boost::container::flat_map<topic_t, std::pair<int, int> >& floor2c_t,
    int add_customers,
    int add_tables,
    int current_k,
    int depth) {
  int s = pdf_.size();
  auto it = floor2c_t.begin();
  int j = 0;
  if (!include_zero_) {
    j = 1;
    if (it != floor2c_t.end() && (*it).first == 0) ++it;
  }
  for (; j < s; ++j) {
    if (it == floor2c_t.end() || (*it).first > j) {
      assert(j != current_k); // current restaurant should never be empty
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, 0, 0);
    } else {
      assert((*it).first == j);
      int c = (*it).second.first;
      int t = (*it).second.second;
      if (j == current_k) {
        c -= add_customers;
        t -= add_tables;
      }
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, c, t);
      ++it;
    }
  }
}
コード例 #4
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer,
                             u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) {
    // Construct the binary path to the archive first
    FileSys::Path path =
        FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);

    auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData
                                                                  : ArchiveIdCode::ExtSaveData);

    if (archive == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get());

    ResultCode result = ext_savedata->Format(path, format_info);
    if (result.IsError())
        return result;

    if (!Memory::IsValidVirtualAddress(icon_buffer))
        return ResultCode(-1); // TODO(Subv): Find the right error code

    std::vector<u8> smdh_icon(icon_size);
    Memory::ReadBlock(icon_buffer, smdh_icon.data(), smdh_icon.size());
    ext_savedata->WriteIcon(path, smdh_icon.data(), smdh_icon.size());
    return RESULT_SUCCESS;
}
コード例 #5
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
	int addPSkill(SkillInfo* skill)
	{
		assert(globalSkillTable.count(skill->sid)==0 && "duplicate HeroProfile");
        globalSkillTable[skill->sid] = skill;
        
        return globalSkillTable.size();
	}
コード例 #6
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info,
                         const FileSys::Path& path) {
    auto archive_itr = id_code_map.find(id_code);
    if (archive_itr == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    return archive_itr->second->Format(path, format_info);
}
コード例 #7
0
ファイル: materials.cpp プロジェクト: thebracket/bgame
/*
 * Retrieve a material by tag
 */
boost::optional<std::size_t> get_material_by_tag(const std::string &tag) noexcept {
    boost::optional<std::size_t> result;

    auto finder = material_defs_idx.find(tag);
    if (finder != material_defs_idx.end()) {
        result = finder->second;
    }
    return result;
}
コード例 #8
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code,
                                                           FileSys::Path& archive_path) {
    auto archive = id_code_map.find(id_code);
    if (archive == id_code_map.end()) {
        return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
    }

    return archive->second->GetFormatInfo(archive_path);
}
コード例 #9
0
ファイル: workflow_system.cpp プロジェクト: thebracket/bgame
boost::optional<reaction_task_t> find_automatic_reaction_task(const settler_ai_t &ai) {
    if (automatic_reactions.empty()) return boost::optional<reaction_task_t>{};

    boost::optional<reaction_task_t> result;

    // Iterate through available reactions
    for (auto outerit=automatic_reactions.begin(); outerit != automatic_reactions.end(); ++outerit) {
        // Is the workshop busy?
        auto busy_finder = workshop_claimed.find(outerit->first);
        if (busy_finder == workshop_claimed.end()) {
            // Iterate available automatic reactions
            for (const std::string &reaction_name : outerit->second) {
                auto reaction = reaction_defs.find(reaction_name);
                if (reaction != reaction_defs.end()) {
                    // Is the settler allowed to do this?
                    int target_category = -1;
                    if (reaction->second.skill == "Carpentry") {
                        target_category = JOB_CARPENTRY;
                    } else if (reaction->second.skill == "Masonry") {
                        target_category = JOB_MASONRY;
                    }
                    if (target_category == -1 || ai.permitted_work[target_category]) {
                        // Are the inputs available?
                        bool available = true;
                        std::vector<std::pair<std::size_t,bool>> components;
                        for (auto &input : reaction->second.inputs) {
                            const int n_available = available_items_by_reaction_input(input);
                            if (n_available < input.quantity) {
                                available = false;
                            } else {
                                // Claim an item and push its # to the list
                                std::size_t item_id = claim_item_by_reaction_input(input);
                                components.push_back(std::make_pair(item_id,false));
                            }
                        }

                        if (available) {
                            // Components are available, build job and return it
                            result = reaction_task_t{outerit->first, reaction->second.name, reaction->second.tag, components};
                            workshop_claimed.insert(outerit->first);
                            return result;
                        } else {
                            for (auto comp : components) {
                                unclaim_by_id(comp.first);
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}
コード例 #10
0
ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
                                                                      FileSys::Path& path) {
    LOG_TRACE(Service_FS, "Opening FileSystem with type=%d", type);

    auto itr = filesystem_map.find(type);
    if (itr == filesystem_map.end()) {
        // TODO(bunnei): Find a better error code for this
        return ResultCode(-1);
    }

    return itr->second->Open(path);
}
コード例 #11
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
 std::vector<HeroProfile*> heroProfiles()
 {
     std::vector<HeroProfile*> profiles;
     profiles.reserve(globalHeroTable.size());
     
     transform(globalHeroTable.begin(), globalHeroTable.end(), back_inserter(profiles),
               [](boost::container::flat_map<int, HeroProfile*>::const_reference value){ return value.second; });
     
     std::sort(profiles.begin(), profiles.end(), [](HeroProfile* first, HeroProfile* second){
         return (first->tableId-9999.5)*(second->tableId-9999.5) < 0 ? first->tableId >= 10000 : first->tableId < second->tableId; });
     
     return profiles;
 }
コード例 #12
0
std::pair<double,double> FermiTable::calcAverageAtomicProperties
(const boost::container::flat_map<string,double>& tracers) const
{
  double total = 0;
  double aa = 0;
  double zz = 0;
  for(std::map<string,std::pair<double,double> >::const_iterator it=
	atomic_properties_.begin();
      it!=atomic_properties_.end();++it){
    assert(tracers.count(it->first)==1);
    const double mass_frac = tracers.find(it->first)->second;
    const double A = it->second.first;
    const double Z = it->second.second;
    total += mass_frac;
    aa += mass_frac/A;
    zz += mass_frac*Z/A;
  }
  return std::pair<double,double>(total/aa,zz/aa);
}
コード例 #13
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
    LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);

    auto itr = id_code_map.find(id_code);
    if (itr == id_code_map.end()) {
        // TODO: Verify error against hardware
        return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
                          ErrorLevel::Permanent);
    }

    CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));

    // This should never even happen in the first place with 64-bit handles,
    while (handle_map.count(next_handle) != 0) {
        ++next_handle;
    }
    handle_map.emplace(next_handle, std::move(res));
    return MakeResult<ArchiveHandle>(next_handle++);
}
コード例 #14
0
ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type) {
    auto result = filesystem_map.emplace(type, std::move(factory));

    bool inserted = result.second;
    ASSERT_MSG(inserted, "Tried to register more than one system with same id code");

    auto& filesystem = result.first->second;
    LOG_DEBUG(Service_FS, "Registered file system %s with id code 0x%08X",
              filesystem->GetName().c_str(), static_cast<u32>(type));
    return RESULT_SUCCESS;
}
コード例 #15
0
ファイル: inventory_system.cpp プロジェクト: thebracket/bgame
bool is_better_armor(const std::string &item_tag, boost::container::flat_map<item_location_t, float> &ac_by_loc) {
	auto finder = get_clothing_by_tag(item_tag);
	if (!finder) return false;

	const float item_ac = finder->armor_class;
	item_location_t loc = INVENTORY;
	if (finder->slot == "head") loc = HEAD;
	if (finder->slot == "torso") loc = TORSO;
	if (finder->slot == "legs") loc = LEGS;
	if (finder->slot == "shoes") loc = FEET;

	auto tester = ac_by_loc.find(loc);
	if (tester == ac_by_loc.end()) {
		return true;
	} else {
		if (item_ac > tester->second) return true;
	}

	return false;
}
コード例 #16
0
ファイル: util.hpp プロジェクト: nozyh/topiclm
void EraseAndShrink(boost::container::flat_map<Key, Value>& x, Key& k) {
  x.erase(k);
  // if (x.size() < x.capacity() / 4) {
  //   boost::container::flat_map<Key, Value> y;
  //   y.reserve(x.capacity() / 2);
  //   for (auto& datum : x) {
  //     y.insert(datum);
  //   }
  //   x.swap(y);
  // }
}
コード例 #17
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
// TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
// http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory,
                               ArchiveIdCode id_code) {
    auto result = id_code_map.emplace(id_code, std::move(factory));

    bool inserted = result.second;
    ASSERT_MSG(inserted, "Tried to register more than one archive with same id code");

    auto& archive = result.first->second;
    LOG_DEBUG(Service_FS, "Registered archive %s with id code 0x%08X", archive->GetName().c_str(),
              id_code);
    return RESULT_SUCCESS;
}
コード例 #18
0
int main() {
    std::cout << "Element size: " << sizeof(map_element) << std::endl;

    std::cout << "std::map: ";
    run_tests(packet_collector_thread_std_map);
    DataCounter.clear();

#ifndef __APPLE__
    std::cout << "tbb::concurrent_unordered_map: ";
    run_tests(packet_collector_thread_unordered_concurrent_map);
    DataCounterUnorderedConcurrent.clear();
#endif

    // Boost unordered map
    std::cout << "boost::unordered_map: ";
    run_tests(packet_collector_thread_boost_unordered_map);
    DataCounterBoostUnordered.clear();

    // Boost flat_map
    DataCounterBoostFlatMap.reserve( number_of_ips );
    std::cout << "boost::container::flat_map with preallocated elements: ";
    run_tests(packet_collector_thread_flat_map_preallocated);
    DataCounterBoostFlatMap.clear();

    std::cout << "std::unordered_map C++11: ";
    run_tests(packet_collector_thread_unordered_map);
    DataCounterUnordered.clear();

    // Preallocate hash buckets
    DataCounterUnorderedPreallocated.reserve( number_of_ips );
    std::cout << "std::unordered_map C++11 preallocated buckets: ";
    run_tests(packet_collector_thread_unordered_map_preallocated);
    DataCounterUnorderedPreallocated.clear();

    // Preallocate vector
    DataCounterVector.reserve( number_of_ips );
    std::cout << "std::vector preallocated: ";
    run_tests(packet_collector_thread_vector);
    DataCounterVector.clear();
}
コード例 #19
0
ファイル: restaurant.hpp プロジェクト: nozyh/topiclm
double Restaurant::predictive_probability(topic_t floor_id,
                                          int type,
                                          double parent_probability,
                                          double discount,
                                          double concentration) const {
  int cw = 0;
  int tw = 0;
  int c = 0;
  int t = 0;

  auto section_it = type2internal_.find(type);
  if (section_it != type2internal_.end()) {
    cw = (*section_it).second.customers(floor_id);
    tw = (*section_it).second.tables(floor_id);
  }
  auto floor_it = floor2c_t_.find(floor_id);
  if (floor_it != floor2c_t_.end()) {
    c = (*floor_it).second.first;
    t = (*floor_it).second.second;
  }
  return ComputePYPPredictive(cw, tw, c, t, parent_probability, discount, concentration);
}
コード例 #20
0
ファイル: workflow_system.cpp プロジェクト: thebracket/bgame
void workflow_system::update(const double duration_ms) {
    if (dirty) {
        automatic_reactions.clear();

        // Enumerate buildings and see which ones have reactions.
        each<position_t, building_t>([this] (entity_t &e, position_t &pos, building_t &b) {
            if (b.complete) {
                auto finder = reaction_building_defs.find(b.tag);
                if (finder != reaction_building_defs.end()) {
                    for (const std::string &reaction_name : finder->second) {
                        auto reactor = reaction_defs.find(reaction_name);
                        if (reactor != reaction_defs.end()) {

                            // Automatic reactions are added to the auto reactor list
                            if (reactor->second.automatic) {
                                auto automatic_finder = automatic_reactions.find(e.id);
                                if (automatic_finder == automatic_reactions.end()) {
                                    automatic_reactions[e.id] = std::vector<std::string>{ reaction_name };
                                } else {
                                    automatic_finder->second.push_back(reaction_name);
                                }
                            }
                        }
                    }
                }
            }
        });

        // Erase all completed jobs
        designations->build_orders.erase(
            std::remove_if(designations->build_orders.begin(),
                designations->build_orders.end(),
                [] (auto order_pair) { return order_pair.first == 0; }),
            designations->build_orders.end());

        // Not dirty anymore!
        dirty = false;
    }
}
コード例 #21
0
ファイル: materials.cpp プロジェクト: thebracket/bgame
/*
 * Linter for materials, used in raw loader.
 */
void sanity_check_materials() noexcept
{
    for (const auto &mat : material_defs) {
        if (mat.tag.empty()) std::cout << "WARNING: Empty material tag\n";
        if (mat.name.empty()) std::cout << "WARNING: Empty material name, tag: " << mat.tag << "\n";
        /*if (!mat.mines_to_tag.empty()) {
            auto finder = item_defs.find(mat.mines_to_tag);
            if (finder == item_defs.end()) std::cout << "WARNING: Unknown mining result " << mat.mines_to_tag << ", tag: " << mat.tag << "\n";
        }
        if (!mat.mines_to_tag_second.empty()) {
            auto finder = item_defs.find(mat.mines_to_tag_second);
            if (finder == item_defs.end()) std::cout << "WARNING: Unknown mining result " << mat.mines_to_tag_second << ", tag: " << mat.tag << "\n";
        }*/
        if (!mat.ore_materials.empty()) {
            for (const std::string &metal : mat.ore_materials) {
                auto finder = material_defs_idx.find(metal);
                if (finder == material_defs_idx.end()) {
                    std::cout << "WARNING: Substance " << mat.tag << " produces a non-existent ore: " << metal << "\n";
                }
            }
        }
    }
}
コード例 #22
0
namespace FileSystem {

/**
 * Map of registered file systems, identified by type. Once an file system is registered here, it
 * is never removed until UnregisterFileSystems is called.
 */
static boost::container::flat_map<Type, std::unique_ptr<FileSys::FileSystemFactory>> filesystem_map;

ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type) {
    auto result = filesystem_map.emplace(type, std::move(factory));

    bool inserted = result.second;
    ASSERT_MSG(inserted, "Tried to register more than one system with same id code");

    auto& filesystem = result.first->second;
    LOG_DEBUG(Service_FS, "Registered file system %s with id code 0x%08X",
              filesystem->GetName().c_str(), static_cast<u32>(type));
    return RESULT_SUCCESS;
}

ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
                                                                      FileSys::Path& path) {
    LOG_TRACE(Service_FS, "Opening FileSystem with type=%d", type);

    auto itr = filesystem_map.find(type);
    if (itr == filesystem_map.end()) {
        // TODO(bunnei): Find a better error code for this
        return ResultCode(-1);
    }

    return itr->second->Open(path);
}

void UnregisterFileSystems() {
    filesystem_map.clear();
}

void InstallInterfaces(SM::ServiceManager& service_manager) {
    UnregisterFileSystems();
    std::make_shared<FSP_SRV>()->InstallAsService(service_manager);
}

} // namespace FileSystem
コード例 #23
0
ファイル: archive.cpp プロジェクト: FenrisulfrX/citra
void UnregisterArchiveTypes() {
    id_code_map.clear();
}
コード例 #24
0
ファイル: restaurant.hpp プロジェクト: nozyh/topiclm
void Restaurant::FillInPredictives(const std::vector<double>& parent_predictives,
                                   int type,
                                   const LambdaManagerInterface& lmanager,
                                   int depth,
                                   const HPYParameter& hpy_parameter,
                                   std::vector<double>& predictives) const {
  auto floor_it = floor2c_t_.begin();
  auto type_it = type2internal_.find(type);
  predictives[0] = parent_predictives[0];
  if (floor2c_t_.empty()) {
    for (size_t i = 1; i < predictives.size(); ++i) {
      double lambda = lmanager.lambda(i, depth);
      predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0];
    }
    return;
  }
  if ((*floor_it).first == 0) {
    auto& c_t = (*floor_it).second;
    predictives[0] *= (hpy_parameter.concentration(depth, 0) + hpy_parameter.discount(depth, 0) * c_t.second) / (c_t.first + hpy_parameter.concentration(depth, 0));
    if (type_it != type2internal_.end()) {
      auto& sections = (*type_it).second.sections_;
      if (!sections.empty()) {
        auto section_begin = sections.begin();
        if ((*section_begin).first == 0) {
          int cw = (*section_begin).second.customers;
          int tw = (*section_begin).second.tables;
          predictives[0] += (cw - hpy_parameter.discount(depth, 0) * tw) / (c_t.first + hpy_parameter.concentration(depth, 0));
        }
      }
    }
  }
  for (size_t i = 1; i < predictives.size(); ++i) {
    double lambda = lmanager.lambda(i, depth);
    predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0];
  }
  if ((*floor_it).first == 0) {
    ++floor_it;
  }
  for (; floor_it != floor2c_t_.end(); ++floor_it) {
    auto floor_id = (*floor_it).first;
    auto& c_t = (*floor_it).second;
    tmp_c_[floor_id] = c_t.first;
    predictives[floor_id] *=
        (hpy_parameter.concentration(depth, floor_id)
         + hpy_parameter.discount(depth, floor_id) * c_t.second)
        / (c_t.first + hpy_parameter.concentration(depth, floor_id));
  }
  if (type_it == type2internal_.end()) return;
  auto& sections = (*type_it).second.sections_;

  auto section_it = sections.begin();
  if (section_it != sections.end() && (*section_it).first == 0) {
    ++section_it;
  }
  for (; section_it != sections.end(); ++section_it) {
    auto floor_id = (*section_it).first;
    auto& section = (*section_it).second;
    int cw = section.customers;
    int tw = section.tables;
    predictives[floor_id] +=
        (cw - hpy_parameter.discount(depth, floor_id) * tw)
        / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id));
  }
}
コード例 #25
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
namespace PH
{
    // Hero Profile
    int HeroProfile::getMaxStar() const
    {
        int maxStar = star;
        int transNum = transformTargetHeroId;
        
        for (;;)
        {
            if(transNum == -1)
                break;
            
            const HeroProfile& next = HPT(transNum);
            transNum = next.transformTargetHeroId;
            maxStar++;
        }
        return maxStar;
    }
    
    bool HeroProfile::isMat() const
    {
        return tableId < 10000;
    }
    
    int LevelStats::getOpLevel()
    {
        ////
        // ---------- Accounting after battle ----------
        ////
        float score =0.f;
        
        this->refMaxCombo   = std::max(this->refMaxCombo, 1);
        this->refAvgCombo   = std::max(this->refAvgCombo, 1);
        this->refRound      = std::max(this->refRound, 1);
        
        // A
        float tmp = this->maxCombo;
        tmp /= (float)this->refMaxCombo;
        tmp *= 12;
        tmp = std::min(30.f, tmp);
        score += tmp;
        
        // B
        tmp = (float)this->totalCombo;
        tmp /= (float)this->turnCount;
        tmp /= (float)this->refAvgCombo;
        tmp *= 15;
        tmp = std::min(30.f, tmp);
        score += tmp;
        
        // C
        float tmp2 = 0.f;
        for( auto val : this->roundPerLevel)
            tmp2 += val;
        tmp2 /= (float)this->roundPerLevel.size();
        tmp2 = std::max(1.f, tmp2);
        tmp = (float)this->refRound;
        tmp /= tmp2;
        tmp *= 25;
        tmp = std::min(60.f, tmp);
        score += tmp; 
        
        // D
        tmp = 4.f;
        tmp /= (this->reviveCount+4);
        tmp *= 40.f;
        tmp = std::min(40.f, tmp);
        score += tmp;
        
        int opLevel = 5;
        
        if(score > 61) opLevel = 4;
        if (score > 80) opLevel = 3;
        if (score > 100) opLevel = 2;
        if (score > 130) opLevel = 1;
        
        return opLevel;
        //return 1;
    }
    
    bool isIdChainInTeam(int id,
                         const std::vector<Hero*>& team)
    {
        for(int id2 = id; id2 != -1; id2 = HPT(id2).transformTargetHeroId)
        {
            for(Hero* h : team)
                if(h && h->heroId == id2)
                    return true;
        }
        return false;
    }
    
    bool isRelationActive(const HeroRelation& relation,
                          const std::vector<Hero*>& team)
    {
        for(int id : relation.withHeroes)
        {
            if(!isIdChainInTeam(id, team))
                return false;
        }
        
        return true;
    }

    Hero boostHeroStatsByRelations(const Hero& refH, const HeroList& team)
    {
        Hero h = refH;
        
        for(const HeroRelation& r: h.relations)
        {
            if(!isRelationActive(r, team))
                continue;
            
            for(auto& pair : r.effects)
            {
                RelationEffects effect;
                double val;
                boost::tie(effect, val) = pair;
                
                if(effect == HP)
                    h.health += refH.health * val;
                else if(effect == STRENGTH)
                    h.attack += refH.attack * val;
                else if(effect == REGEN)
                    h.regen += refH.regen * val;
                else
                    LOGD("Unknown relation effect %d", effect);
            }
        }
        return h;
    }
    
    //---------------
    // Hero
    //---------------
    Hero::Hero(std::string uid, int hid, int lvl, int ex) :id(uid), heroId(hid), level(lvl), exp(ex)
    {
        profile = &HPT(hid);
        
        eliteLevel = 0;
        health = profile->health.eval(level);
        attack = profile->attack.eval(level);
        regen  = profile->regen.eval(level);
        expCap = level > profile->maxLevel ? -1 : profile->exp.eval(level);
        maxEnergy = profile->activeSkillId != -1 ? AST(profile->activeSkillId).energy : 0;
        skillBonus = 0;
        trainPrice = lvl * 100;
    }
    
    static boost::container::flat_map<int, HeroProfile*> globalHeroTable;
	static boost::container::flat_map<int, SkillInfo*> globalSkillTable;
    
    const SkillInfo& AST(int i)
    {
        assert(globalSkillTable.count(i) && "Skill does not exist");
        return *globalSkillTable[i];
    }
    
    const SkillInfo& PST(int i)
    {
        assert(globalSkillTable.count(i) && "Skill does not exist");
        return *globalSkillTable[i];
    }
    
    const HeroProfile& HPT(int i)
    {
        assert(globalHeroTable.count(i) && "HeroProfile does not exist");
        return *globalHeroTable[i];     }
    
    int HPTN(const HeroProfile *profile)
    {
        std::vector<HeroProfile*> profiles = heroProfiles();
        for(int i = 0 ; i < profiles.size() ; i++)
        {
            if(profiles[i] && profiles[i]->tableId == profile->tableId)return i;
        }
        return -1;
    }
    
    std::vector<HeroProfile*> heroProfiles()
    {
        std::vector<HeroProfile*> profiles;
        profiles.reserve(globalHeroTable.size());
        
        transform(globalHeroTable.begin(), globalHeroTable.end(), back_inserter(profiles),
                  [](boost::container::flat_map<int, HeroProfile*>::const_reference value){ return value.second; });
        
        std::sort(profiles.begin(), profiles.end(), [](HeroProfile* first, HeroProfile* second){
            return (first->tableId-9999.5)*(second->tableId-9999.5) < 0 ? first->tableId >= 10000 : first->tableId < second->tableId; });
        
        return profiles;
    }
    
    int addHero(HeroProfile* h)
    {
        assert(globalHeroTable.count(h->tableId)==0 && "duplicate HeroProfile");
        globalHeroTable[h->tableId] = h;
        
        return globalHeroTable.size();
    }

	int addASkill(SkillInfo* skill)
	{
		assert(globalSkillTable.count(skill->sid)==0 && "duplicate HeroProfile");
        globalSkillTable[skill->sid] = skill;
        
        return globalSkillTable.size();
	}

	int addPSkill(SkillInfo* skill)
	{
		assert(globalSkillTable.count(skill->sid)==0 && "duplicate HeroProfile");
        globalSkillTable[skill->sid] = skill;
        
        return globalSkillTable.size();
	}
    
    
}
コード例 #26
0
void UnregisterFileSystems() {
    filesystem_map.clear();
}
コード例 #27
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
 const SkillInfo& PST(int i)
 {
     assert(globalSkillTable.count(i) && "Skill does not exist");
     return *globalSkillTable[i];
 }
コード例 #28
0
ファイル: HeroTable.cpp プロジェクト: 13609594236/ph-open
 const HeroProfile& HPT(int i)
 {
     assert(globalHeroTable.count(i) && "HeroProfile does not exist");
     return *globalHeroTable[i];     }