Refactors constants out of Attributes.h.

This commit is contained in:
2023-04-25 12:44:21 -07:00
parent d1314e16a4
commit 34678d9af6
4 changed files with 128 additions and 117 deletions

View File

@@ -10,6 +10,78 @@ using std::string;
using std::vector;
} // End namespace
const int kPhysicalAttributesCount = 3;
const int kSocialAttributesCount = 3;
const int kMentalAttributesCount = 3;
const int kAttributeGroupsCount = 3;
const std::string kPhysicalAttributeStrengthLabel = "Strength";
const std::string kPhysicalAttributeStrengthAbbreviation = "Str.";
const std::string kPhysicalAttributeDexterityLabel = "Dexterity";
const std::string kPhysicalAttributeDexterityAbbreviation = "Dex.";
const std::string kPhysicalAttributeStaminaLabel = "Stamina";
const std::string kPhysicalAttributeStaminaAbbreviation = "Sta.";
const std::string kPhysicalAttributeLabels[] = {
"",
kPhysicalAttributeStrengthLabel,
kPhysicalAttributeDexterityLabel,
kPhysicalAttributeStaminaLabel,
};
const std::string kPhysicalAttributeLabelAbbreviations[] = {
"",
kPhysicalAttributeStrengthAbbreviation,
kPhysicalAttributeDexterityAbbreviation,
kPhysicalAttributeStaminaAbbreviation,
};
const std::string kSocialAttributeCharismaLabel = "Charisma";
const std::string kSocialAttributeCharismaAbbreviation = "Cha.";
const std::string kSocialAttributeManipulationLabel = "Manipulation";
const std::string kSocialAttributeManipulationAbbreviation = "Man.";
const std::string kSocialAttributeAppearanceLabel = "Appearance";
const std::string kSocialAttributeAppearanceAbbreviation = "App.";
const std::string kSocialAttributeLabels[] = {
"",
kSocialAttributeCharismaLabel,
kSocialAttributeManipulationLabel,
kSocialAttributeAppearanceLabel,
};
const std::string kSocialAttributeLabelAbbreviations[] = {
"",
kSocialAttributeCharismaAbbreviation,
kSocialAttributeManipulationAbbreviation,
kSocialAttributeAppearanceAbbreviation,
};
const std::string kMentalAttributeIntelligenceLabel = "Intelligence";
const std::string kMentalAttributeIntelligenceAbbreviation = "Int.";
const std::string kMentalAttributePerceptionLabel = "Perception";
const std::string kMentalAttributePerceptionAbbreviation = "Per.";
const std::string kMentalAttributeWitsLabel = "Wits";
const std::string kMentalAttributeWitsAbbreviation = "Wits";
const std::string kMentalAttributeLabels[] = {
"",
kMentalAttributeIntelligenceLabel,
kMentalAttributePerceptionLabel,
kMentalAttributeWitsLabel,
};
const std::string kMentalAttributeLabelAbbreviations[] = {
"",
kMentalAttributeIntelligenceAbbreviation,
kMentalAttributePerceptionAbbreviation,
kMentalAttributeWitsAbbreviation,
};
const std::string kAttributeGroupPhysicalLabel = "Physical";
const std::string kAttributeGroupSocialLabel = "Social";
const std::string kAttributeGroupMentalLabel = "Mental";
const std::string kAttributeGroups[] = {
"",
kAttributeGroupPhysicalLabel,
kAttributeGroupSocialLabel,
kAttributeGroupMentalLabel,
};
string GetAttributeGroupLabel(int attributeGroupId) {
if (attributeGroupId > 0 && attributeGroupId <= kAttributeGroupsCount) {
return kAttributeGroups[attributeGroupId];
@@ -156,4 +228,50 @@ void FillMentalAttributeLabels(std::vector<std::string>& labels) {
}
}
void FillAttributeLabelsInGroup(std::vector<string> labels, int group_id) {
labels.clear();
switch (group_id) {
case kAttributeGroupPhysicalId:
for (int id = 0; id <= kPhysicalAttributesCount; id++) {
labels.push_back(kPhysicalAttributeLabels[id]);
}
break;
case kAttributeGroupSocialId:
for (int id = 0; id <= kSocialAttributesCount; id++) {
labels.push_back(kSocialAttributeLabels[id]);
}
break;
case kAttributeGroupMentalId:
for (int id = 0; id <= kMentalAttributesCount; id++) {
labels.push_back(kMentalAttributeLabels[id]);
}
break;
}
}
void FillAttributeAbbreviationsInGroup(std::vector<string> abbreviations, int group_id) {
abbreviations.clear();
switch (group_id) {
case kAttributeGroupPhysicalId:
for (int id = 0; id <= kPhysicalAttributesCount; id++) {
abbreviations.push_back(kPhysicalAttributeLabelAbbreviations[id]);
}
break;
case kAttributeGroupSocialId:
for (int id = 0; id <= kSocialAttributesCount; id++) {
abbreviations.push_back(kSocialAttributeLabelAbbreviations[id]);
}
break;
case kAttributeGroupMentalId:
for (int id = 0; id <= kMentalAttributesCount; id++) {
abbreviations.push_back(kMentalAttributeLabelAbbreviations[id]);
}
break;
}
}
int GetNumAttributeGroups() {
return kAttributeGroupsCount;
}
} // End namespace SBF

View File

@@ -16,87 +16,20 @@
*/
namespace SBF {
const int kPhysicalAttributeStrengthId = 1;
const std::string kPhysicalAttributeStrengthLabel = "Strength";
const std::string kPhysicalAttributeStrengthAbbreviation = "Str.";
const int kPhysicalAttributeDexterityId = 2;
const std::string kPhysicalAttributeDexterityLabel = "Dexterity";
const std::string kPhysicalAttributeDexterityAbbreviation = "Dex.";
const int kPhysicalAttributeStaminaId = 3;
const std::string kPhysicalAttributeStaminaLabel = "Stamina";
const std::string kPhysicalAttributeStaminaAbbreviation = "Sta.";
const int kPhysicalAttributesCount = 3;
const std::string kPhysicalAttributeLabels[] = {
"",
kPhysicalAttributeStrengthLabel,
kPhysicalAttributeDexterityLabel,
kPhysicalAttributeStaminaLabel,
};
const std::string kPhysicalAttributeLabelAbbreviations[] = {
"",
kPhysicalAttributeStrengthAbbreviation,
kPhysicalAttributeDexterityAbbreviation,
kPhysicalAttributeStaminaAbbreviation,
};
const int kSocialAttributeCharismaId = 1;
const std::string kSocialAttributeCharismaLabel = "Charisma";
const std::string kSocialAttributeCharismaAbbreviation = "Cha.";
const int kSocialAttributeManipulationId = 2;
const std::string kSocialAttributeManipulationLabel = "Manipulation";
const std::string kSocialAttributeManipulationAbbreviation = "Man.";
const int kSocialAttributeAppearanceId = 3;
const std::string kSocialAttributeAppearanceLabel = "Appearance";
const std::string kSocialAttributeAppearanceAbbreviation = "App.";
const int kSocialAttributesCount = 3;
const std::string kSocialAttributeLabels[] = {
"",
kSocialAttributeCharismaLabel,
kSocialAttributeManipulationLabel,
kSocialAttributeAppearanceLabel,
};
const std::string kSocialAttributeLabelAbbreviations[] = {
"",
kSocialAttributeCharismaAbbreviation,
kSocialAttributeManipulationAbbreviation,
kSocialAttributeAppearanceAbbreviation,
};
const int kMentalAttributeIntelligenceId = 1;
const std::string kMentalAttributeIntelligenceLabel = "Intelligence";
const std::string kMentalAttributeIntelligenceAbbreviation = "Int.";
const int kMentalAttributePerceptionId = 2;
const std::string kMentalAttributePerceptionLabel = "Perception";
const std::string kMentalAttributePerceptionAbbreviation = "Per.";
const int kMentalAttributeWitsId = 3;
const std::string kMentalAttributeWitsLabel = "Wits";
const std::string kMentalAttributeWitsAbbreviation = "Wits";
const int kMentalAttributesCount = 3;
const std::string kMentalAttributeLabels[] = {
"",
kMentalAttributeIntelligenceLabel,
kMentalAttributePerceptionLabel,
kMentalAttributeWitsLabel,
};
const std::string kMentalAttributeLabelAbbreviations[] = {
"",
kMentalAttributeIntelligenceAbbreviation,
kMentalAttributePerceptionAbbreviation,
kMentalAttributeWitsAbbreviation,
};
const int kAttributeGroupPhysicalId = 1;
const std::string kAttributeGroupPhysicalLabel = "Physical";
const int kAttributeGroupSocialId = 2;
const std::string kAttributeGroupSocialLabel = "Social";
const int kAttributeGroupMentalId = 3;
const std::string kAttributeGroupMentalLabel = "Mental";
const int kAttributeGroupsCount = 3;
const std::string kAttributeGroups[] = {
"",
kAttributeGroupPhysicalLabel,
kAttributeGroupSocialLabel,
kAttributeGroupMentalLabel,
};
/// @brief Gets the label for the attribute group with the specified id.
/// @param attribute_group_id The id of the attribute group to return the label for.
@@ -130,6 +63,8 @@ std::string GetPhysicalAttributeLabelAbbreviation(int attribute_id);
/// @return The number of attributes in the specified group or 0 if the id is invalid.
int GetNumAttributesInGroup(int attribute_group_id);
int GetNumAttributeGroups();
/// @brief Gets the label for the social attribute with a specific id.
/// @param attribute_id The id of the social attribute to get the label for.
/// @return The label of the specified attribute or an empty string if the id is invalid.

View File

@@ -51,7 +51,7 @@ CharacterType::CharacterType() {
}
// Attributes
for (int group_id = 1; group_id <= kAttributeGroupsCount; group_id++) {
for (int group_id = 1; group_id <= GetNumAttributeGroups(); group_id++) {
const int numAttributes = GetNumAttributesInGroup(group_id);
for (int id = 1; id <= numAttributes; id++) {
SetAttributeValue(group_id, id, 1);
@@ -279,48 +279,6 @@ vector<int> CharacterType::GetAttributeValuesInGroup(int group_id) const {
return values;
}
void FillAttributeLabelsInGroup(std::vector<string> labels, int group_id) {
labels.clear();
switch (group_id) {
case kAttributeGroupPhysicalId:
for (int id = 0; id <= kPhysicalAttributesCount; id++) {
labels.push_back(kPhysicalAttributeLabels[id]);
}
break;
case kAttributeGroupSocialId:
for (int id = 0; id <= kSocialAttributesCount; id++) {
labels.push_back(kSocialAttributeLabels[id]);
}
break;
case kAttributeGroupMentalId:
for (int id = 0; id <= kMentalAttributesCount; id++) {
labels.push_back(kMentalAttributeLabels[id]);
}
break;
}
}
void FillAttributeAbbreviationsInGroup(std::vector<string> abbreviations, int group_id) {
abbreviations.clear();
switch (group_id) {
case kAttributeGroupPhysicalId:
for (int id = 0; id <= kPhysicalAttributesCount; id++) {
abbreviations.push_back(kPhysicalAttributeLabelAbbreviations[id]);
}
break;
case kAttributeGroupSocialId:
for (int id = 0; id <= kSocialAttributesCount; id++) {
abbreviations.push_back(kSocialAttributeLabelAbbreviations[id]);
}
break;
case kAttributeGroupMentalId:
for (int id = 0; id <= kMentalAttributesCount; id++) {
abbreviations.push_back(kMentalAttributeLabelAbbreviations[id]);
}
break;
}
}
void CharacterType::SetPhysicalAttributeValue(int id, int value) {
switch (id) {
case kPhysicalAttributeDexterityId:

View File

@@ -66,18 +66,18 @@ void CGGetAttributes(CharacterType& ch) {
MenuStyle ms_without_values;
MenuStyle ms_with_values;
// indexed by group_id - 1 holds the rank_id
vector<int> attribute_ranks(kAttributeGroupsCount);
vector<int> attribute_ranks(GetNumAttributeGroups());
// Attribute groups menu (physical/social/mental)
vector<MenuItem> attribute_groups_menu_items;
for (size_t i = 1; i <= kAttributeGroupsCount; i++) {
for (size_t i = 1; i <= GetNumAttributeGroups(); i++) {
attribute_groups_menu_items.push_back(MenuItem(GetAttributeGroupLabel(i), i));
}
// Choose attribute group priorities.
int group_sum = 0;
int rank_sum = 1;
for (size_t i = 1; i < kAttributeGroupsCount; i++) {
for (size_t i = 1; i < GetNumAttributeGroups(); i++) {
int next_group_id = ChooseMenuItemId(attribute_groups_menu_items,
ms_without_values,
"Choose your " + ToLower(GetRank(i).label) + " attribute?",
@@ -92,10 +92,10 @@ void CGGetAttributes(CharacterType& ch) {
// General formula for last choice given 1 to count based indexing is this. (Sum from 1 to count) - (Sum of all
// previous choice IDs). Sum(1..AllAttributesCount)-Sum(Choice[1..Choice[AllAttributesCount-1]).
int last_group = rank_sum - group_sum;
attribute_ranks[last_group - 1] = kAttributeGroupsCount;
attribute_ranks[last_group - 1] = GetNumAttributeGroups();
// Spend attribute points
for (int group_id = 1; group_id <= kAttributeGroupsCount; group_id++) {
for (int group_id = 1; group_id <= GetNumAttributeGroups(); group_id++) {
int group_index = group_id - 1;
vector<string> attribute_labels = GetAttributeLabelsInGroup(group_id);
int rank_id = attribute_ranks.at(group_index);
@@ -232,7 +232,7 @@ void CGSpendAttributePoint(CharacterType& ch) {
ms.show_cancel = true;
int num_attributes = 0;
vector<int> num_attributes_in_group;
for (int group_id = 1; group_id <= kAttributeGroupsCount; group_id++) {
for (int group_id = 1; group_id <= GetNumAttributeGroups(); group_id++) {
int count = GetNumAttributesInGroup(group_id);
num_attributes_in_group.push_back(count);
num_attributes += count;
@@ -243,7 +243,7 @@ void CGSpendAttributePoint(CharacterType& ch) {
vector<int> values;
int attribute_id = 1;
for (int attribute_group_id = 1; attribute_group_id <= kAttributeGroupsCount; attribute_group_id++) {
for (int attribute_group_id = 1; attribute_group_id <= GetNumAttributeGroups(); attribute_group_id++) {
int attribute_group_index = attribute_group_id - 1;
for (int id = 1; id <= num_attributes_in_group.at(attribute_group_index); id++) {
GroupedStatReference attribute_ref = {attribute_id, attribute_group_id, id};