Skip to content

Commit

Permalink
Moving out enum functions
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Oct 9, 2023
1 parent e56071d commit e8f80d0
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
#include "Engine/Objects/ObjectList.h"
#include "Engine/Objects/SpriteObject.h"
#include "Engine/Objects/NPC.h"
#include "Engine/Objects/CharacterFunctions.h"
#include "Engine/Party.h"
#include "Engine/SaveLoad.h"
#include "Engine/Spells/CastSpellInfo.h"
#include "Engine/Spells/Spells.h"
#include "Engine/Tables/ItemTable.h"
#include "Engine/Tables/FrameTableInc.h"
#include "Engine/Tables/AwardTable.h"
#include "Engine/Time.h"
#include "Engine/TurnEngine/TurnEngine.h"
#include "Engine/MapInfo.h"
Expand Down
5 changes: 2 additions & 3 deletions src/Engine/Localization.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <stdarg.h>
#include <vector>
#include "Localization.h"

#include "Engine/Engine.h"
#include "Engine/Localization.h"
#include "Engine/GameResourceManager.h"
#include "Engine/Objects/CharacterFunctions.h"

#include "Utility/String.h"

Expand Down
1 change: 1 addition & 0 deletions src/Engine/Localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Engine/Objects/NPCEnums.h"
#include "Engine/Objects/CharacterEnums.h"
#include "Engine/Spells/SpellEnums.h"
#include "Engine/PartyEnums.h"

#include "Utility/Workaround/ToUnderlying.h"
Expand Down
1 change: 1 addition & 0 deletions src/Engine/Objects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(ENGINE_OBJECTS_HEADERS
ObjectList.h
Character.h
CharacterEnums.h
CharacterFunctions.h
SpriteObject.h)

add_library(engine_objects STATIC ${ENGINE_OBJECTS_SOURCES} ${ENGINE_OBJECTS_HEADERS})
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Objects/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "Utility/Math/FixPoint.h"
#include "Utility/IndexedArray.h"

#include "CharacterFunctions.h"

static DecalBuilder *decal_builder = EngineIocContainer::ResolveDecalBuilder();
static SpellFxRenderer *spell_fx_renderer = EngineIocContainer::ResolveSpellFxRenderer();

Expand Down
160 changes: 0 additions & 160 deletions src/Engine/Objects/CharacterEnums.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#pragma once

#include <cassert>
#include <cstdint>

#include "Engine/Spells/SpellEnums.h"

#include "Utility/Workaround/ToUnderlying.h"
#include "Utility/Segment.h"

enum class Condition : uint32_t {
CONDITION_CURSED = 0,
CONDITION_WEAK = 1,
Expand Down Expand Up @@ -44,10 +38,6 @@ enum class CharacterSkillMastery {
};
using enum CharacterSkillMastery;

inline Segment<CharacterSkillMastery> SkillMasteries() {
return Segment(CHARACTER_SKILL_MASTERY_FIRST, CHARACTER_SKILL_MASTERY_LAST);
}

enum class CharacterBuff {
CHARACTER_BUFF_RESIST_AIR = 0,
CHARACTER_BUFF_BLESS = 1,
Expand Down Expand Up @@ -267,106 +257,6 @@ enum class CharacterSkillType : int8_t {
};
using enum CharacterSkillType;

inline Segment<CharacterSkillType> allSkills() {
return Segment(CHARACTER_SKILL_FIRST, CHARACTER_SKILL_LAST);
}

/**
* @return List of skills that are visible to the player and that are stored in a savegame.
*/
inline Segment<CharacterSkillType> allVisibleSkills() {
return Segment(CHARACTER_SKILL_FIRST_VISIBLE, CHARACTER_SKILL_LAST_VISIBLE);
}

/**
* @return List of skills that are drawn in the "Armor" section of the character
* screen's skills tab.
*/
inline std::initializer_list<CharacterSkillType> allArmorSkills() {
static constexpr std::initializer_list<CharacterSkillType> result = {
CHARACTER_SKILL_LEATHER, CHARACTER_SKILL_CHAIN, CHARACTER_SKILL_PLATE,
CHARACTER_SKILL_SHIELD, CHARACTER_SKILL_DODGE
};

return result;
}

/**
* @return List of skills that are drawn in the "Weapons" section of the character
* screen's skills tab.
*/
inline std::initializer_list<CharacterSkillType> allWeaponSkills() {
static constexpr std::initializer_list<CharacterSkillType> result = {
CHARACTER_SKILL_AXE, CHARACTER_SKILL_BOW, CHARACTER_SKILL_DAGGER,
CHARACTER_SKILL_MACE, CHARACTER_SKILL_SPEAR, CHARACTER_SKILL_STAFF,
CHARACTER_SKILL_SWORD, CHARACTER_SKILL_UNARMED, CHARACTER_SKILL_BLASTER
// CHARACTER_SKILL_CLUB is not displayed in skills.
};

return result;
}

/**
* @return List of skills that are drawn in the "Misc" section of the character
* screen's skills tab.
*/
inline std::initializer_list<CharacterSkillType> allMiscSkills() {
static constexpr std::initializer_list<CharacterSkillType> result = {
CHARACTER_SKILL_ALCHEMY, CHARACTER_SKILL_ARMSMASTER,
CHARACTER_SKILL_BODYBUILDING, CHARACTER_SKILL_ITEM_ID,
CHARACTER_SKILL_MONSTER_ID, CHARACTER_SKILL_LEARNING,
CHARACTER_SKILL_TRAP_DISARM, CHARACTER_SKILL_MEDITATION,
CHARACTER_SKILL_MERCHANT, CHARACTER_SKILL_PERCEPTION,
CHARACTER_SKILL_REPAIR, CHARACTER_SKILL_STEALING
};

return result;
}

/**
* @return List of skills that are drawn in the "Magic" section of the character
* screen's skills tab.
*/
inline std::initializer_list<CharacterSkillType> allMagicSkills() {
static constexpr std::initializer_list<CharacterSkillType> result = {
CHARACTER_SKILL_FIRE, CHARACTER_SKILL_AIR, CHARACTER_SKILL_WATER,
CHARACTER_SKILL_EARTH, CHARACTER_SKILL_SPIRIT, CHARACTER_SKILL_MIND,
CHARACTER_SKILL_BODY, CHARACTER_SKILL_LIGHT, CHARACTER_SKILL_DARK
};

return result;
}

inline CharacterSkillType skillForMagicSchool(MagicSchool school) {
switch (school) {
case MAGIC_SCHOOL_FIRE: return CHARACTER_SKILL_FIRE;
case MAGIC_SCHOOL_AIR: return CHARACTER_SKILL_AIR;
case MAGIC_SCHOOL_WATER: return CHARACTER_SKILL_WATER;
case MAGIC_SCHOOL_EARTH: return CHARACTER_SKILL_EARTH;
case MAGIC_SCHOOL_SPIRIT: return CHARACTER_SKILL_SPIRIT;
case MAGIC_SCHOOL_MIND: return CHARACTER_SKILL_MIND;
case MAGIC_SCHOOL_BODY: return CHARACTER_SKILL_BODY;
case MAGIC_SCHOOL_LIGHT: return CHARACTER_SKILL_LIGHT;
case MAGIC_SCHOOL_DARK: return CHARACTER_SKILL_DARK;
default:
assert(false);
return CHARACTER_SKILL_INVALID;
}
}

inline CharacterSkillType skillForSpell(SpellId spell) {
if (isRegularSpell(spell)) {
return skillForMagicSchool(magicSchoolForSpell(spell));
} else if (spell == SPELL_BOW_ARROW) {
return CHARACTER_SKILL_BOW;
} else if (spell == SPELL_LASER_PROJECTILE) {
return CHARACTER_SKILL_BLASTER;
} else {
assert(false && "Unknown spell");
return CHARACTER_SKILL_INVALID;
}
}

// TODO(pskelton): drop CHARACTER_ at start?
enum class CharacterClassType : uint8_t {
CHARACTER_CLASS_KNIGHT = 0,
Expand Down Expand Up @@ -411,48 +301,6 @@ enum class CharacterClassType : uint8_t {
};
using enum CharacterClassType;

inline CharacterClassType getTier1Class(CharacterClassType classType) {
return static_cast<CharacterClassType>(std::to_underlying(classType) & ~3);
}

inline CharacterClassType getTier2Class(CharacterClassType classType) {
return static_cast<CharacterClassType>((std::to_underlying(classType) & ~3) + 1);
}

inline CharacterClassType getTier3LightClass(CharacterClassType classType) {
return static_cast<CharacterClassType>((std::to_underlying(classType) & ~3) + 2);
}

inline CharacterClassType getTier3DarkClass(CharacterClassType classType) {
return static_cast<CharacterClassType>((std::to_underlying(classType) & ~3) + 3);
}

inline int getClassTier(CharacterClassType classType) {
int index = (std::to_underlying(classType) & 3);
return index == 3 ? 3 : index + 1;
}

/**
* Get priomotions of higher tier class relative to given one.
*
* Base class is of tier 1.
* After initial promotion class becomes tier 2.
* Tier 2 class is promoted through light or dark path to tier 3 class.
*
* @param classType Character class.
*/
inline Segment<CharacterClassType> getClassPromotions(CharacterClassType classType) {
int tier = getClassTier(classType);

if (tier == 1) {
return {getTier2Class(classType), getTier3DarkClass(classType)};
} else if (tier == 2) {
return {getTier3LightClass(classType), getTier3DarkClass(classType)};
} else {
return {}; // tier 3 max
}
}

// TODO(pskelton): drop CHARACTER_ at start?
enum class CharacterExpressionID : uint16_t {
CHARACTER_EXPRESSION_INVALID = 0,
Expand Down Expand Up @@ -584,11 +432,3 @@ enum class CharacterAttributeType {
CHARACTER_ATTRIBUTE_LAST_ENCHANTABLE = CHARACTER_ATTRIBUTE_SKILL_UNARMED
};
using enum CharacterAttributeType;

inline Segment<CharacterAttributeType> enchantableAttributes() {
return Segment(CHARACTER_ATTRIBUTE_FIRST_ENCHANTABLE, CHARACTER_ATTRIBUTE_LAST_ENCHANTABLE);
}

inline Segment<CharacterAttributeType> statAttributes() {
return Segment(CHARACTER_ATTRIBUTE_FIRST_STAT, CHARACTER_ATTRIBUTE_LAST_STAT);
}
Loading

0 comments on commit e8f80d0

Please sign in to comment.