Refactors constants out of Freebies.h.

This commit is contained in:
2023-04-25 13:38:54 -07:00
parent c3cd1e65ff
commit f35c0f21d0
4 changed files with 130 additions and 102 deletions

View File

@@ -218,7 +218,7 @@ void CGSpendDisciplinePoint(CharacterType& ch) {
int discipline_id = ChooseStringIdWithValues(labels, values, ms, prompt);
if (discipline_id != ms.cancel_item_id) {
ch.SetDisciplineValue(discipline_id, ch.GetDisciplineValue(discipline_id) + 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieDisciplineCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieDisciplineId));
}
}
@@ -264,7 +264,7 @@ void CGSpendAttributePoint(CharacterType& ch) {
}
GroupedStatReference ref = attribute_refs.at(id - 1);
ch.SetAttributeValue(ref.group_id, ref.item_id, ch.GetAttributeValue(ref.group_id, ref.item_id) + 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieAttributeCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieAttributeId));
}
void CGSpendAbilityPoint(CharacterType& ch) {
@@ -287,7 +287,7 @@ void CGSpendAbilityPoint(CharacterType& ch) {
ChooseStringId(labels, ms, "What " + ToLower(ability.singular) + " would you like to add 1 dot to?");
if (ability_id != ms.cancel_item_id) {
ch.SetAbilityValue(ability_group_id, ability_id, ch.GetAbilityValue(ability_group_id, ability_id) + 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieAbilityCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieAbilityId));
}
}
}
@@ -300,7 +300,7 @@ void CGSpendVirtuePoint(CharacterType& ch) {
int id = ChooseStringIdWithValues(GetVirtueLabels(), ch.GetVirtueValues(), ms, prompt);
if (id != ms.cancel_item_id) {
ch.SetVirtueValue(id, ch.GetVirtueValue(id) + 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieVirtueCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieVirtueId));
}
}
@@ -311,7 +311,7 @@ void CGSpendHumanityPoint(CharacterType& ch) {
ms.show_random = false;
if (ChooseYesOrNo(prompt)) {
ch.SetRoadValue(ch.GetRoadValue() - 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieHumanityCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieHumanityId));
}
}
@@ -324,7 +324,7 @@ void CGSpendBackgroundPoint(CharacterType& ch) {
int id = ChooseStringId(labels, ms, prompt);
if (id != ms.cancel_item_id) {
ch.SetBackgroundValue(id, ch.GetBackgroundValue(id) + 1);
ch.SetFreebiePoints(ch.GetFreebiePoints() - kFreebieBackgroundCost);
ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieBackgroundId));
}
}

View File

@@ -8,6 +8,86 @@ using std::ostream;
using std::vector;
} // End namespace
const int kFreebieDisciplineCost = 7;
const std::string kFreebieDisciplineName = "Discipline";
const std::string kFreebieDisciplineLabel = "Add a discipline dot 7 points";
const FreebieType kFreebieDiscipline = {
kFreebieDisciplineId, kFreebieDisciplineCost, kFreebieDisciplineName, kFreebieDisciplineLabel};
const int kFreebieAttributeCost = 5;
const std::string kFreebieAttributeName = "Attribute";
const std::string kFreebieAttributeLabel = "Add an attribute dot 5 points";
const FreebieType kFreebieAttribute = {
kFreebieAttributeId, kFreebieAttributeCost, kFreebieAttributeName, kFreebieAttributeLabel};
const int kFreebieAbilityCost = 2;
const std::string kFreebieAbilityName = "Ability";
const std::string kFreebieAbilityLabel = "Add an ability dot 2 points";
const FreebieType kFreebieAbility = {kFreebieAbilityId, kFreebieAbilityCost, kFreebieAbilityName, kFreebieAbilityLabel};
const int kFreebieVirtueCost = 2;
const std::string kFreebieVirtueName = "Virtue";
const std::string kFreebieVirtueLabel = "Add a virtue dot 2 points";
const FreebieType kFreebieVirtue = {kFreebieVirtueId, kFreebieVirtueCost, kFreebieVirtueName, kFreebieVirtueLabel};
const int kFreebieHumanityCost = 1;
const std::string kFreebieHumanityName = "Humanity";
const std::string kFreebieHumanityLabel = "Add a humanity dot 1 point";
const FreebieType kFreebieHumanity = {
kFreebieHumanityId, kFreebieHumanityCost, kFreebieHumanityName, kFreebieHumanityLabel};
const int kFreebieBackgroundCost = 1;
const std::string kFreebieBackgroundName = "Background";
const std::string kFreebieBackgroundLabel = "Add a background dot 1 point";
const FreebieType kFreebieBackground = {
kFreebieBackgroundId, kFreebieBackgroundCost, kFreebieBackgroundName, kFreebieBackgroundLabel};
const int kFreebieShowCharacterSheetCost = 0;
const std::string kFreebieShowCharacterSheetName = "Show character sheet";
const std::string kFreebieShowCharacterSheetLabel = "Show character sheet";
const FreebieType kFreebieShowCharacterSheet = {kFreebieShowCharacterSheetId,
kFreebieShowCharacterSheetCost,
kFreebieShowCharacterSheetName,
kFreebieShowCharacterSheetLabel};
const int kFreebieCosts[] = {
0,
kFreebieDisciplineCost,
kFreebieAttributeCost,
kFreebieAbilityCost,
kFreebieVirtueCost,
kFreebieHumanityCost,
kFreebieBackgroundCost,
kFreebieShowCharacterSheetCost,
};
const std::string kFreebieNames[] = {
"",
kFreebieDisciplineName,
kFreebieAttributeName,
kFreebieAbilityName,
kFreebieVirtueName,
kFreebieHumanityName,
kFreebieBackgroundName,
kFreebieShowCharacterSheetName,
};
const std::string kFreebieLabels[] = {
"",
kFreebieDisciplineLabel,
kFreebieAttributeLabel,
kFreebieAbilityLabel,
kFreebieVirtueLabel,
kFreebieHumanityLabel,
kFreebieBackgroundLabel,
kFreebieShowCharacterSheetLabel,
};
const FreebieType kFreebies[] = {
kFreebieUnknown,
kFreebieDiscipline,
kFreebieAttribute,
kFreebieAbility,
kFreebieVirtue,
kFreebieHumanity,
kFreebieBackground,
kFreebieShowCharacterSheet,
};
ostream& operator<<(ostream& os, const FreebieType& freebie) {
os << "Freebie: {id: " << freebie.id << ", cost: " << freebie.cost << ", name: \"" << freebie.name << "\", label: \""
<< freebie.label << "\"}";
@@ -56,4 +136,11 @@ vector<FreebieType> GetAvailableFreebies(int freebie_points) {
return freebies;
}
int GetFreebieCost(int id) {
if (id > 0 && id <= kFreebiesCount) {
return kFreebieCosts[id];
}
return 0;
}
} // End namespace SBF

View File

@@ -17,109 +17,13 @@ const int kFreebiesCount = 7;
const FreebieType kFreebieUnknown = {0, 0, "", ""};
const int kFreebieDisciplineId = 1;
const int kFreebieDisciplineCost = 7;
const std::string kFreebieDisciplineName = "Discipline";
const std::string kFreebieDisciplineLabel = "Add a discipline dot 7 points";
const FreebieType kFreebieDiscipline = {
kFreebieDisciplineId, kFreebieDisciplineCost, kFreebieDisciplineName, kFreebieDisciplineLabel};
const int kFreebieAttributeId = 2;
const int kFreebieAttributeCost = 5;
const std::string kFreebieAttributeName = "Attribute";
const std::string kFreebieAttributeLabel = "Add an attribute dot 5 points";
const FreebieType kFreebieAttribute = {
kFreebieAttributeId, kFreebieAttributeCost, kFreebieAttributeName, kFreebieAttributeLabel};
const int kFreebieAbilityId = 3;
const int kFreebieAbilityCost = 2;
const std::string kFreebieAbilityName = "Ability";
const std::string kFreebieAbilityLabel = "Add an ability dot 2 points";
const FreebieType kFreebieAbility = {kFreebieAbilityId, kFreebieAbilityCost, kFreebieAbilityName, kFreebieAbilityLabel};
const int kFreebieVirtueId = 4;
const int kFreebieVirtueCost = 2;
const std::string kFreebieVirtueName = "Virtue";
const std::string kFreebieVirtueLabel = "Add a virtue dot 2 points";
const FreebieType kFreebieVirtue = {kFreebieVirtueId, kFreebieVirtueCost, kFreebieVirtueName, kFreebieVirtueLabel};
// TODO: Make this configurable for VtDA
const int kFreebieHumanityId = 5;
const int kFreebieHumanityCost = 1;
const std::string kFreebieHumanityName = "Humanity";
const std::string kFreebieHumanityLabel = "Add a humanity dot 1 point";
const FreebieType kFreebieHumanity = {
kFreebieHumanityId, kFreebieHumanityCost, kFreebieHumanityName, kFreebieHumanityLabel};
const int kFreebieBackgroundId = 6;
const int kFreebieBackgroundCost = 1;
const std::string kFreebieBackgroundName = "Background";
const std::string kFreebieBackgroundLabel = "Add a background dot 1 point";
const FreebieType kFreebieBackground = {
kFreebieBackgroundId, kFreebieBackgroundCost, kFreebieBackgroundName, kFreebieBackgroundLabel};
const int kFreebieShowCharacterSheetId = 7;
const int kFreebieShowCharacterSheetCost = 0;
const std::string kFreebieShowCharacterSheetName = "Show character sheet";
const std::string kFreebieShowCharacterSheetLabel = "Show character sheet";
const FreebieType kFreebieShowCharacterSheet = {kFreebieShowCharacterSheetId,
kFreebieShowCharacterSheetCost,
kFreebieShowCharacterSheetName,
kFreebieShowCharacterSheetLabel};
const int kFreebieIds[] = {
0,
kFreebieDisciplineId,
kFreebieAttributeId,
kFreebieAbilityId,
kFreebieVirtueId,
kFreebieHumanityId,
kFreebieBackgroundId,
kFreebieShowCharacterSheetId,
};
const int kFreebieCosts[] = {
0,
kFreebieDisciplineCost,
kFreebieAttributeCost,
kFreebieAbilityCost,
kFreebieVirtueCost,
kFreebieHumanityCost,
kFreebieBackgroundCost,
kFreebieShowCharacterSheetCost,
};
const std::string kFreebieNames[] = {
"",
kFreebieDisciplineName,
kFreebieAttributeName,
kFreebieAbilityName,
kFreebieVirtueName,
kFreebieHumanityName,
kFreebieBackgroundName,
kFreebieShowCharacterSheetName,
};
const std::string kFreebieLabels[] = {
"",
kFreebieDisciplineLabel,
kFreebieAttributeLabel,
kFreebieAbilityLabel,
kFreebieVirtueLabel,
kFreebieHumanityLabel,
kFreebieBackgroundLabel,
kFreebieShowCharacterSheetLabel,
};
const FreebieType kFreebies[] = {
kFreebieUnknown,
kFreebieDiscipline,
kFreebieAttribute,
kFreebieAbility,
kFreebieVirtue,
kFreebieHumanity,
kFreebieBackground,
kFreebieShowCharacterSheet,
};
/// @brief Writes a freebie to an ostream.
/// @param os The ostream to write to.
@@ -151,6 +55,7 @@ void FillFreebies(std::vector<FreebieType>& freebies);
std::vector<FreebieType> GetFreebies();
std::vector<FreebieType> GetAvailableFreebies(int freebie_points);
int GetFreebieCost(int id);
} // End namespace SBF

View File

@@ -14,6 +14,42 @@ using namespace Test;
using namespace std;
} // End namespace
const int kFreebieDisciplineCost = 7;
const std::string kFreebieDisciplineName = "Discipline";
const std::string kFreebieDisciplineLabel = "Add a discipline dot 7 points";
const FreebieType kFreebieDiscipline = {
kFreebieDisciplineId, kFreebieDisciplineCost, kFreebieDisciplineName, kFreebieDisciplineLabel};
const int kFreebieAttributeCost = 5;
const std::string kFreebieAttributeName = "Attribute";
const std::string kFreebieAttributeLabel = "Add an attribute dot 5 points";
const FreebieType kFreebieAttribute = {
kFreebieAttributeId, kFreebieAttributeCost, kFreebieAttributeName, kFreebieAttributeLabel};
const int kFreebieAbilityCost = 2;
const std::string kFreebieAbilityName = "Ability";
const std::string kFreebieAbilityLabel = "Add an ability dot 2 points";
const FreebieType kFreebieAbility = {kFreebieAbilityId, kFreebieAbilityCost, kFreebieAbilityName, kFreebieAbilityLabel};
const int kFreebieVirtueCost = 2;
const std::string kFreebieVirtueName = "Virtue";
const std::string kFreebieVirtueLabel = "Add a virtue dot 2 points";
const FreebieType kFreebieVirtue = {kFreebieVirtueId, kFreebieVirtueCost, kFreebieVirtueName, kFreebieVirtueLabel};
const int kFreebieHumanityCost = 1;
const std::string kFreebieHumanityName = "Humanity";
const std::string kFreebieHumanityLabel = "Add a humanity dot 1 point";
const FreebieType kFreebieHumanity = {
kFreebieHumanityId, kFreebieHumanityCost, kFreebieHumanityName, kFreebieHumanityLabel};
const int kFreebieBackgroundCost = 1;
const std::string kFreebieBackgroundName = "Background";
const std::string kFreebieBackgroundLabel = "Add a background dot 1 point";
const FreebieType kFreebieBackground = {
kFreebieBackgroundId, kFreebieBackgroundCost, kFreebieBackgroundName, kFreebieBackgroundLabel};
const int kFreebieShowCharacterSheetCost = 0;
const std::string kFreebieShowCharacterSheetName = "Show character sheet";
const std::string kFreebieShowCharacterSheetLabel = "Show character sheet";
const FreebieType kFreebieShowCharacterSheet = {kFreebieShowCharacterSheetId,
kFreebieShowCharacterSheetCost,
kFreebieShowCharacterSheetName,
kFreebieShowCharacterSheetLabel};
TestResults test_FreebieType_operator_extract() {
auto fnToTest = [](const FreebieType& freebie) -> string {
ostringstream os;