Skip to content

Commit

Permalink
Support human enemy in EntityDefinitionLibrary.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Dec 31, 2024
1 parent edd60e8 commit b83f583
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
45 changes: 36 additions & 9 deletions OpenTESArena/src/Entities/EntityDefinitionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../Assets/ArenaAnimUtils.h"
#include "../Assets/ArenaTypes.h"
#include "../Assets/ExeData.h"
#include "../Stats/CharacterClassLibrary.h"
#include "../World/ArenaClimateUtils.h"

#include "components/debug/Debug.h"
Expand All @@ -18,16 +19,16 @@ void CreatureEntityDefinitionKey::init(int creatureIndex, bool isFinalBoss)
this->isFinalBoss = isFinalBoss;
}

/*bool EntityDefinitionLibrary::Key::HumanEnemyKey::operator==(const HumanEnemyKey &other) const
bool HumanEnemyEntityDefinitionKey::operator==(const HumanEnemyEntityDefinitionKey &other) const
{
return (this->male == other.male) && (this->charClassID == other.charClassID);
}

void EntityDefinitionLibrary::Key::HumanEnemyKey::init(bool male, int charClassID)
void HumanEnemyEntityDefinitionKey::init(bool male, int charClassID)
{
this->male = male;
this->charClassID = charClassID;
}*/
}

bool CitizenEntityDefinitionKey::operator==(const CitizenEntityDefinitionKey &other) const
{
Expand Down Expand Up @@ -56,10 +57,10 @@ bool EntityDefinitionKey::operator==(const EntityDefinitionKey &other) const
{
return this->creature == other.creature;
}
/*else if (this->type == Key::Type::HumanEnemy)
else if (this->type == EntityDefinitionKeyType::HumanEnemy)
{
return this->humanEnemy == other.humanEnemy;
}*/
}
else if (this->type == EntityDefinitionKeyType::Citizen)
{
return this->citizen == other.citizen;
Expand All @@ -81,11 +82,11 @@ void EntityDefinitionKey::initCreature(int creatureIndex, bool isFinalBoss)
this->creature.init(creatureIndex, isFinalBoss);
}

/*void EntityDefinitionLibrary::Key::initHumanEnemy(bool male, int charClassID)
void EntityDefinitionKey::initHumanEnemy(bool male, int charClassID)
{
this->init(Key::Type::HumanEnemy);
this->init(EntityDefinitionKeyType::HumanEnemy);
this->humanEnemy.init(male, charClassID);
}*/
}

void EntityDefinitionKey::initCitizen(bool male, ArenaTypes::ClimateType climateType)
{
Expand All @@ -110,7 +111,7 @@ int EntityDefinitionLibrary::findDefIndex(const EntityDefinitionKey &key) const
return NO_INDEX;
}

void EntityDefinitionLibrary::init(const ExeData &exeData, const EntityAnimationLibrary &entityAnimLibrary)
void EntityDefinitionLibrary::init(const ExeData &exeData, const CharacterClassLibrary &charClassLibrary, const EntityAnimationLibrary &entityAnimLibrary)
{
// This init method assumes that all creatures, human enemies, and citizens are known
// in advance of loading any levels, and any code that relies on those definitions can
Expand All @@ -134,6 +135,23 @@ void EntityDefinitionLibrary::init(const ExeData &exeData, const EntityAnimation
this->addDefinition(std::move(key), std::move(entityDef));
};

auto addHumanEnemyDef = [this, &exeData, &entityAnimLibrary](bool male, int charClassID)
{
HumanEnemyEntityAnimationKey animKey;
animKey.init(male, charClassID);

const EntityAnimationDefinitionID animDefID = entityAnimLibrary.getHumanEnemyAnimDefID(animKey);
EntityAnimationDefinition animDef = entityAnimLibrary.getDefinition(animDefID); // @todo: make const ref and give anim def ID to EntityDefinition instead

EntityDefinitionKey key;
key.initHumanEnemy(male, charClassID);

EntityDefinition entityDef;
entityDef.initEnemyHuman(male, charClassID, std::move(animDef));

this->addDefinition(std::move(key), std::move(entityDef));
};

auto addCitizenDef = [this, &exeData, &entityAnimLibrary](ArenaTypes::ClimateType climateType, bool male)
{
CitizenEntityAnimationKey animKey;
Expand Down Expand Up @@ -163,6 +181,15 @@ void EntityDefinitionLibrary::init(const ExeData &exeData, const EntityAnimation
const int finalBossID = ArenaAnimUtils::FinalBossCreatureID;
addCreatureDef(finalBossID, true);

// Iterate all human enemies.
const int charClassCount = charClassLibrary.getDefinitionCount();
for (int i = 0; i < charClassCount; i++)
{
const int charClassID = i;
addHumanEnemyDef(true, charClassID);
addHumanEnemyDef(false, charClassID);
}

// Iterate all climate type + gender combinations.
for (int i = 0; i < ArenaClimateUtils::getClimateTypeCount(); i++)
{
Expand Down
14 changes: 7 additions & 7 deletions OpenTESArena/src/Entities/EntityDefinitionLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TextureManager;
enum class EntityDefinitionKeyType
{
Creature,
//HumanEnemy, // Not supported due to dependence on .INF file's corpse texture.
HumanEnemy,
Citizen
};

Expand All @@ -30,15 +30,15 @@ struct CreatureEntityDefinitionKey
void init(int creatureIndex, bool isFinalBoss);
};

/*struct HumanEnemyKey
struct HumanEnemyEntityDefinitionKey
{
bool male;
int charClassID;

bool operator==(const HumanEnemyKey &other) const;
bool operator==(const HumanEnemyEntityDefinitionKey &other) const;

void init(bool male, int charClassID);
};*/
};

struct CitizenEntityDefinitionKey
{
Expand All @@ -57,7 +57,7 @@ struct EntityDefinitionKey
union
{
CreatureEntityDefinitionKey creature;
//HumanEnemyKey humanEnemy;
HumanEnemyEntityDefinitionKey humanEnemy;
CitizenEntityDefinitionKey citizen;
};

Expand All @@ -68,7 +68,7 @@ struct EntityDefinitionKey
bool operator==(const EntityDefinitionKey &other) const;

void initCreature(int creatureIndex, bool isFinalBoss);
//void initHumanEnemy(bool male, int charClassID);
void initHumanEnemy(bool male, int charClassID);
void initCitizen(bool male, ArenaTypes::ClimateType climateType);
};

Expand Down Expand Up @@ -107,7 +107,7 @@ class EntityDefinitionLibrary : public Singleton<EntityDefinitionLibrary>
}
}

void init(const ExeData &exeData, const EntityAnimationLibrary &entityAnimLibrary);
void init(const ExeData &exeData, const CharacterClassLibrary &charClassLibrary, const EntityAnimationLibrary &entityAnimLibrary);

// Gets the number of entity definitions. This is useful for the currently-active entity
// manager that needs to start its definition IDs at the end of these.
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ bool Game::init()

EntityAnimationLibrary &entityAnimLibrary = EntityAnimationLibrary::getInstance();
entityAnimLibrary.init(binaryAssetLibrary, charClassLibrary, this->textureManager);
EntityDefinitionLibrary::getInstance().init(exeData, entityAnimLibrary);
EntityDefinitionLibrary::getInstance().init(exeData, charClassLibrary, entityAnimLibrary);

this->sceneManager.init(this->textureManager, this->renderer);
this->sceneManager.renderVoxelChunkManager.init(this->renderer);
Expand Down

0 comments on commit b83f583

Please sign in to comment.