Implement basic type library.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
32
src/Library/TypeLibrary.cpp
Normal file
32
src/Library/TypeLibrary.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "TypeLibrary.hpp"
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const std::vector<uint8_t> &defensive) const {
|
||||
auto eff = 1;
|
||||
for (auto def: defensive){
|
||||
eff *= GetSingleEffectiveness(attacking, def);
|
||||
}
|
||||
return eff;
|
||||
}
|
||||
|
||||
float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
|
||||
return _effectiveness[attacking][defensive];
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::GetTypeId(const std::string &s) const {
|
||||
return _types.at(s);
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const std::string& typeName) {
|
||||
_types.insert({typeName, _types.size()});
|
||||
_effectiveness.resize(_types.size());
|
||||
for (auto & eff : _effectiveness){
|
||||
eff.resize(_types.size(), 1);
|
||||
}
|
||||
return _types.size() - 1;
|
||||
}
|
||||
|
||||
void TypeLibrary::SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness) {
|
||||
_effectiveness[attacking][defensive] = effectiveness;
|
||||
}
|
||||
Reference in New Issue
Block a user