Skip to content

Commit

Permalink
Add town reputation improvements (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Aug 6, 2022
1 parent ef067cd commit 3592a72
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
70 changes: 66 additions & 4 deletions src/character_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ static void customKarmaFolderInit();
static void customKarmaFolderFree();
static int customKarmaFolderGetFrmId();

static void customTownReputationInit();
static void customTownReputationFree();

// 0x431C40
static int gCharacterEditorFrmIds[EDITOR_GRAPHIC_COUNT] = {
170,
Expand Down Expand Up @@ -792,6 +795,7 @@ struct CustomKarmaFolderDescription {
};

static std::vector<CustomKarmaFolderDescription> gCustomKarmaFolderDescriptions;
static std::vector<TownReputationEntry> gCustomTownReputationEntries;

// 0x431DF8
int characterEditorShow(bool isCreationMode)
Expand Down Expand Up @@ -1293,6 +1297,9 @@ static int characterEditorWindowInit()
// SFALL: Custom karma folder.
customKarmaFolderInit();

// SFALL: Custom town reputation.
customTownReputationInit();

soundContinueAll();

for (i = 0; i < EDITOR_GRAPHIC_COUNT; i++) {
Expand Down Expand Up @@ -1855,6 +1862,9 @@ static void characterEditorWindowFree()
// SFALL: Custom karma folder.
customKarmaFolderFree();

// SFALL: Custom town reputation.
customTownReputationFree();

messageListFree(&gCharacterEditorMessageList);

interfaceBarRefresh();
Expand Down Expand Up @@ -4516,8 +4526,9 @@ static int characterPrintToFile(const char* fileName)
}

bool hasTownReputationHeading = false;
for (int index = 0; index < TOWN_REPUTATION_COUNT; index++) {
const TownReputationEntry* pair = &(gTownReputationEntries[index]);
// SFALL
for (int index = 0; index < gCustomTownReputationEntries.size(); index++) {
const TownReputationEntry* pair = &(gCustomTownReputationEntries[index]);
if (_wmAreaIsKnown(pair->city)) {
if (!hasTownReputationHeading) {
fileWriteString("\n", stream);
Expand Down Expand Up @@ -5504,8 +5515,9 @@ static void characterEditorDrawKarmaFolder()
}

bool hasTownReputationHeading = false;
for (int index = 0; index < TOWN_REPUTATION_COUNT; index++) {
const TownReputationEntry* pair = &(gTownReputationEntries[index]);
// SFALL
for (int index = 0; index < gCustomTownReputationEntries.size(); index++) {
const TownReputationEntry* pair = &(gCustomTownReputationEntries[index]);
if (_wmAreaIsKnown(pair->city)) {
if (!hasTownReputationHeading) {
msg = getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 4000);
Expand Down Expand Up @@ -7162,3 +7174,53 @@ static int customKarmaFolderGetFrmId()
}
return gCustomKarmaFolderDescriptions.end()->frmId;
}

static void customTownReputationInit()
{
char* reputationList = NULL;
configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CITY_REPUTATION_LIST_KEY, &reputationList);
if (reputationList != NULL && *reputationList == '\0') {
reputationList = NULL;
}

char* curr = reputationList;
while (curr != NULL) {
char* next = strchr(curr, ',');
if (next != NULL) {
*next = '\0';
}

char* sep = strchr(curr, ':');
if (sep != NULL) {
*sep = '\0';

TownReputationEntry entry;
entry.city = atoi(curr);
entry.gvar = atoi(sep + 1);
gCustomTownReputationEntries.push_back(std::move(entry));

*sep = ':';
}

if (next != NULL) {
*next = ',';
curr = next + 1;
} else {
curr = NULL;
}
}

if (gCustomTownReputationEntries.empty()) {
gCustomTownReputationEntries.resize(TOWN_REPUTATION_COUNT);

for (int index = 0; index < TOWN_REPUTATION_COUNT; index++) {
gCustomTownReputationEntries[index].gvar = gTownReputationEntries[index].gvar;
gCustomTownReputationEntries[index].city = gTownReputationEntries[index].city;
}
}
}

static void customTownReputationFree()
{
gCustomTownReputationEntries.clear();
}
1 change: 1 addition & 0 deletions src/sfall_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define SFALL_CONFIG_PLASTIC_EXPLOSIVE_MIN_DAMAGE_KEY "PlasticExplosive_DmgMin"
#define SFALL_CONFIG_PLASTIC_EXPLOSIVE_MAX_DAMAGE_KEY "PlasticExplosive_DmgMax"
#define SFALL_CONFIG_EXPLOSION_EMITS_LIGHT_KEY "ExplosionsEmitLight"
#define SFALL_CONFIG_CITY_REPUTATION_LIST_KEY "CityRepsList"

#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_MULTIPLIER 1
#define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_DIVISOR 3
Expand Down

0 comments on commit 3592a72

Please sign in to comment.