Skip to content

Commit

Permalink
Add static to all functions that should have it, and remove several u…
Browse files Browse the repository at this point in the history
…nused static functions (#593)

* Add `static` to all functions that should have it

* Remove several unused static functions
  • Loading branch information
nstoddard authored Oct 16, 2023
1 parent e4a15c9 commit 8137eaa
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 419 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include config.mk

cflags := -Isrc/brogue -Isrc/platform -Isrc/variants -std=c99 \
-Wall -Wpedantic -Werror=implicit -Wno-parentheses -Wno-unused-result \
-Wformat -Werror=format-security -Wformat-overflow=0
-Wformat -Werror=format-security -Wformat-overflow=0 -Wmissing-prototypes
libs := -lm
cppflags := -DDATADIR=$(DATADIR)

Expand Down
104 changes: 52 additions & 52 deletions src/brogue/Architect.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/brogue/Combat.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ boolean attackHit(creature *attacker, creature *defender) {
return rand_percent(hitProbability(attacker, defender));
}

void addMonsterToContiguousMonsterGrid(short x, short y, creature *monst, char grid[DCOLS][DROWS]) {
static void addMonsterToContiguousMonsterGrid(short x, short y, creature *monst, char grid[DCOLS][DROWS]) {
short newX, newY;
enum directions dir;
creature *tempMonst;
Expand All @@ -169,7 +169,7 @@ void addMonsterToContiguousMonsterGrid(short x, short y, creature *monst, char g
// group of monsters that the monster would not avoid.
// The contiguous group is supplemented with the given (x, y) coordinates, if any;
// this is so that jellies et al. can spawn behind the player in a hallway.
void splitMonster(creature *monst, pos loc) {
static void splitMonster(creature *monst, pos loc) {
char buf[DCOLS * 3];
char monstName[DCOLS];
char monsterGrid[DCOLS][DROWS], eligibleGrid[DCOLS][DROWS];
Expand Down Expand Up @@ -264,7 +264,7 @@ void splitMonster(creature *monst, pos loc) {
}
}

short alliedCloneCount(creature *monst) {
static short alliedCloneCount(creature *monst) {
short count = 0;
for (creatureIterator it = iterateCreatures(monsters); hasNextCreature(it);) {
creature *temp = nextCreature(&it);
Expand Down Expand Up @@ -354,7 +354,7 @@ void moralAttack(creature *attacker, creature *defender) {
}
}

boolean playerImmuneToMonster(creature *monst) {
static boolean playerImmuneToMonster(creature *monst) {
if (monst != &player
&& rogue.armor
&& (rogue.armor->flags & ITEM_RUNIC)
Expand All @@ -367,7 +367,7 @@ boolean playerImmuneToMonster(creature *monst) {
}
}

void specialHit(creature *attacker, creature *defender, short damage) {
static void specialHit(creature *attacker, creature *defender, short damage) {
short itemCandidates, randItemIndex, stolenQuantity;
item *theItem = NULL, *itemFromTopOfStack;
char buf[COLS], buf2[COLS], buf3[COLS];
Expand Down Expand Up @@ -483,7 +483,7 @@ void specialHit(creature *attacker, creature *defender, short damage) {
}
}

boolean forceWeaponHit(creature *defender, item *theItem) {
static boolean forceWeaponHit(creature *defender, item *theItem) {
short forceDamage;
char buf[DCOLS*3], buf2[COLS], monstName[DCOLS];
creature *otherMonster = NULL;
Expand Down Expand Up @@ -771,7 +771,7 @@ void magicWeaponHit(creature *defender, item *theItem, boolean backstabbed) {
}
}

void attackVerb(char returnString[DCOLS], creature *attacker, short hitPercentile) {
static void attackVerb(char returnString[DCOLS], creature *attacker, short hitPercentile) {
short verbCount, increment;

if (attacker != &player && (player.status[STATUS_HALLUCINATING] || !canSeeMonster(attacker))) {
Expand Down Expand Up @@ -966,7 +966,7 @@ void applyArmorRunicEffect(char returnString[DCOLS], creature *attacker, short *
}
}

void decrementWeaponAutoIDTimer() {
static void decrementWeaponAutoIDTimer() {
char buf[COLS*3], buf2[COLS*3];

if (rogue.weapon
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void flashMonster(creature *monst, const color *theColor, short strength) {
}
}

boolean canAbsorb(creature *ally, boolean ourBolts[], creature *prey, short **grid) {
static boolean canAbsorb(creature *ally, boolean ourBolts[], creature *prey, short **grid) {
short i;

if (ally->creatureState == MONSTER_ALLY
Expand Down Expand Up @@ -1375,7 +1375,7 @@ boolean canAbsorb(creature *ally, boolean ourBolts[], creature *prey, short **gr
return false;
}

boolean anyoneWantABite(creature *decedent) {
static boolean anyoneWantABite(creature *decedent) {
short candidates, randIndex, i;
short **grid;
boolean success = false;
Expand Down
43 changes: 5 additions & 38 deletions src/brogue/Grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,39 +155,6 @@ void drawCircleOnGrid(short **grid, short x, short y, short radius, short value)
}
}

void intersectGrids(short **onto, short **from) {
short i, j;
for(i = 0; i < DCOLS; i++) {
for(j = 0; j < DROWS; j++) {
if (onto[i][j] && from[i][j]) {
onto[i][j] = true;
} else {
onto[i][j] = false;
}
}
}
}

void uniteGrids(short **onto, short **from) {
short i, j;
for(i = 0; i < DCOLS; i++) {
for(j = 0; j < DROWS; j++) {
if (!onto[i][j] && from[i][j]) {
onto[i][j] = from[i][j];
}
}
}
}

void invertGrid(short **grid) {
short i, j;
for(i = 0; i < DCOLS; i++) {
for(j = 0; j < DROWS; j++) {
grid[i][j] = !grid[i][j];
}
}
}

// Fills grid locations with the given value if they match any terrain flags or map flags.
// Otherwise does not change the grid location.
void getTerrainGrid(short **grid, short value, unsigned long terrainFlags, unsigned long mapFlags) {
Expand All @@ -212,7 +179,7 @@ void getTMGrid(short **grid, short value, unsigned long TMflags) {
}
}

void getPassableArcGrid(short **grid, short minPassableArc, short maxPassableArc, short value) {
static void getPassableArcGrid(short **grid, short minPassableArc, short maxPassableArc, short value) {
short i, j, count;
for(i = 0; i < DCOLS; i++) {
for(j = 0; j < DROWS; j++) {
Expand All @@ -239,7 +206,7 @@ short validLocationCount(short **grid, short validValue) {
return count;
}

short leastPositiveValueInGrid(short **grid) {
static short leastPositiveValueInGrid(short **grid) {
short i, j, leastPositiveValue = 0;
for(i = 0; i < DCOLS; i++) {
for(j = 0; j < DROWS; j++) {
Expand Down Expand Up @@ -278,7 +245,7 @@ void randomLocationInGrid(short **grid, short *x, short *y, short validValue) {

// Finds the lowest positive number in a grid, chooses one location with that number randomly and returns it as (x, y).
// If there are no valid locations, returns (-1, -1).
void randomLeastPositiveLocationInGrid(short **grid, short *x, short *y, boolean deterministic) {
static void randomLeastPositiveLocationInGrid(short **grid, short *x, short *y, boolean deterministic) {
const short targetValue = leastPositiveValueInGrid(grid);
short locationCount;
short i, j, index;
Expand Down Expand Up @@ -394,7 +361,7 @@ boolean getQualifyingPathLocNear(short *retValX, short *retValY,
}
}

void cellularAutomataRound(short **grid, char birthParameters[9], char survivalParameters[9]) {
static void cellularAutomataRound(short **grid, char birthParameters[9], char survivalParameters[9]) {
short i, j, nbCount, newX, newY;
enum directions dir;
short **buffer2;
Expand Down Expand Up @@ -428,7 +395,7 @@ void cellularAutomataRound(short **grid, char birthParameters[9], char survivalP
}

// Marks a cell as being a member of blobNumber, then recursively iterates through the rest of the blob
short fillContiguousRegion(short **grid, short x, short y, short fillValue) {
static short fillContiguousRegion(short **grid, short x, short y, short fillValue) {
enum directions dir;
short newX, newY, numberOfCells = 1;

Expand Down
50 changes: 23 additions & 27 deletions src/brogue/IO.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void showCursor() {
}
}

pos getClosestValidLocationOnMap(short **map, short x, short y) {
static pos getClosestValidLocationOnMap(short **map, short x, short y) {
pos answer = INVALID_POS;

int closestDistance = 10000;
Expand All @@ -129,7 +129,7 @@ pos getClosestValidLocationOnMap(short **map, short x, short y) {
return answer;
}

void processSnapMap(short **map) {
static void processSnapMap(short **map) {
short **costMap;
enum directions dir;
short i, j, newX, newY;
Expand Down Expand Up @@ -165,7 +165,7 @@ void processSnapMap(short **map) {
// Returns the keystroke to effect the button's command, or -1 if canceled.
// Some buttons take effect in this function instead of returning a value,
// i.e. true colors mode and display stealth mode.
short actionMenu(short x, boolean playingBack) {
static short actionMenu(short x, boolean playingBack) {
short buttonCount;
short y;
boolean takeActionOurselves[ROWS] = {false};
Expand Down Expand Up @@ -430,7 +430,7 @@ short actionMenu(short x, boolean playingBack) {

#define MAX_MENU_BUTTON_COUNT 5

void initializeMenuButtons(buttonState *state, brogueButton buttons[5]) {
static void initializeMenuButtons(buttonState *state, brogueButton buttons[5]) {
short i, x, buttonCount;
char goldTextEscape[MAX_MENU_BUTTON_COUNT] = "";
char whiteTextEscape[MAX_MENU_BUTTON_COUNT] = "";
Expand Down Expand Up @@ -928,7 +928,7 @@ void storeColorComponents(char components[3], const color *theColor) {
components[2] = max(0, min(100, theColor->blue + rand_range(0, theColor->blueRand) + rand));
}

void bakeTerrainColors(color *foreColor, color *backColor, short x, short y) {
static void bakeTerrainColors(color *foreColor, color *backColor, short x, short y) {
const short *vals;
const short neutralColors[8] = {1000, 1000, 1000, 1000, 0, 0, 0, 0};
if (rogue.trueColorMode) {
Expand Down Expand Up @@ -1598,7 +1598,7 @@ void desaturate(color *baseColor, short weight) {
baseColor->rand += avg * weight / 3 / 100;
}

short randomizeByPercent(short input, short percent) {
static short randomizeByPercent(short input, short percent) {
return (rand_range(input * (100 - percent) / 100, input * (100 + percent) / 100));
}

Expand All @@ -1615,7 +1615,7 @@ void swapColors(color *color1, color *color2) {
}

// Assumes colors are pre-baked.
void blendAppearances(const color *fromForeColor, const color *fromBackColor, const enum displayGlyph fromChar,
static void blendAppearances(const color *fromForeColor, const color *fromBackColor, const enum displayGlyph fromChar,
const color *toForeColor, const color *toBackColor, const enum displayGlyph toChar,
color *retForeColor, color *retBackColor, enum displayGlyph *retChar,
const short percent) {
Expand Down Expand Up @@ -1742,7 +1742,7 @@ void hiliteCell(short x, short y, const color *hiliteColor, short hiliteStrength
restoreRNG;
}

short adjustedLightValue(short x) {
static short adjustedLightValue(short x) {
if (x <= LIGHT_SMOOTHING_THRESHOLD) {
return x;
} else {
Expand Down Expand Up @@ -2220,7 +2220,7 @@ void funkyFade(cellDisplayBuffer displayBuf[COLS][ROWS], const color *colorStart
restoreRNG;
}

void displayWaypoints() {
static void displayWaypoints() {
short i, j, w, lowestDistance;

for (i=0; i<DCOLS; i++) {
Expand All @@ -2239,7 +2239,7 @@ void displayWaypoints() {
temporaryMessage("Waypoints:", REQUIRE_ACKNOWLEDGMENT);
}

void displayMachines() {
static void displayMachines() {
short i, j;
color foreColor, backColor, machineColors[50];
enum displayGlyph dchar;
Expand Down Expand Up @@ -2325,7 +2325,7 @@ void displayLoops() {
waitForAcknowledgment();
}

void exploreKey(const boolean controlKey) {
static void exploreKey(const boolean controlKey) {
short x, y, finalX = 0, finalY = 0;
short **exploreMap;
enum directions dir;
Expand Down Expand Up @@ -2975,10 +2975,6 @@ boolean confirm(char *prompt, boolean alsoDuringPlayback) {
return retVal;
}

void clearMonsterFlashes() {

}

void displayMonsterFlashes(boolean flashingEnabled) {
short x[100], y[100], strength[100], count = 0;
const color *flashColor[100];
Expand Down Expand Up @@ -3012,7 +3008,7 @@ void displayMonsterFlashes(boolean flashingEnabled) {
restoreRNG;
}

void dequeueEvent() {
static void dequeueEvent() {
rogueEvent returnEvent;
nextBrogueEvent(&returnEvent, false, false, true);
}
Expand All @@ -3024,11 +3020,11 @@ void clearMessageArchive() {

// Get a pointer to the archivedMessage the given number of entries back in history.
// Pass zero to get the entry under messageArchivePosition.
archivedMessage *getArchivedMessage(short back) {
static archivedMessage *getArchivedMessage(short back) {
return &messageArchive[(messageArchivePosition + MESSAGE_ARCHIVE_ENTRIES - back) % MESSAGE_ARCHIVE_ENTRIES];
}

int formatCountedMessage(char *buffer, size_t size, archivedMessage *m) {
static int formatCountedMessage(char *buffer, size_t size, archivedMessage *m) {
int length;

if (m->count <= 1) {
Expand All @@ -3047,7 +3043,7 @@ int formatCountedMessage(char *buffer, size_t size, archivedMessage *m) {
// only one message is taken.
// If turnOutput is not null, it is filled with the player turn number shared
// by the chosen messages.
short foldMessages(char buffer[COLS*20], short offset, unsigned long *turnOutput) {
static short foldMessages(char buffer[COLS*20], short offset, unsigned long *turnOutput) {
short i, folded, messageLength, lineLength, length;
unsigned long turn;
char counted[COLS*2];
Expand Down Expand Up @@ -3103,7 +3099,7 @@ short foldMessages(char buffer[COLS*20], short offset, unsigned long *turnOutput
}

// Change the given newline-delimited sentences in-place to ensure proper writing.
void capitalizeAndPunctuateSentences(char *text, short length) {
static void capitalizeAndPunctuateSentences(char *text, short length) {
short i;
boolean newSentence;

Expand All @@ -3127,7 +3123,7 @@ void capitalizeAndPunctuateSentences(char *text, short length) {
}

// Copy \n-delimited lines to the given buffer. Carry colors across line breaks.
void splitLines(short lines, char wrapped[COLS*20], char buffer[][COLS*2], short bufferCursor) {
static void splitLines(short lines, char wrapped[COLS*20], char buffer[][COLS*2], short bufferCursor) {
short linesSeen;
char color[5], line[COLS*2];
char *start, *end;
Expand Down Expand Up @@ -3228,7 +3224,7 @@ void displayRecentMessages() {
// offset: index of oldest (visually highest) message to draw
// height: height in rows of the message archive display area
// rbuf: background display buffer to draw against
void drawMessageArchive(char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
static void drawMessageArchive(char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
int i, j, k, fadePercent;
cellDisplayBuffer dbuf[COLS][ROWS];

Expand Down Expand Up @@ -3260,7 +3256,7 @@ void drawMessageArchive(char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short leng
// offset: index of oldest (visually highest) message to draw in the fully expanded state
// height: height in rows of the message archive display area in the fully expanded state
// rbuf: background display buffer to draw against
void animateMessageArchive(boolean opening, char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
static void animateMessageArchive(boolean opening, char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
short i;
boolean fastForward;

Expand Down Expand Up @@ -3288,7 +3284,7 @@ void animateMessageArchive(boolean opening, char messages[MESSAGE_ARCHIVE_LINES]
// rbuf: background display buffer to draw against
//
// returns the new offset, which can change if the player scrolled around before closing
short scrollMessageArchive(char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
static short scrollMessageArchive(char messages[MESSAGE_ARCHIVE_LINES][COLS*2], short length, short offset, short height, cellDisplayBuffer rbuf[COLS][ROWS]) {
short lastOffset;
boolean exit;
rogueEvent theEvent;
Expand Down Expand Up @@ -3925,7 +3921,7 @@ void printString(const char *theString, short x, short y, const color *foreColor

// Inserts line breaks into really long words. Optionally adds a hyphen, but doesn't do anything
// clever regarding hyphen placement. Plays nicely with color escapes.
void breakUpLongWordsIn(char *sourceText, short width, boolean useHyphens) {
static void breakUpLongWordsIn(char *sourceText, short width, boolean useHyphens) {
char buf[TEXT_MAX_LENGTH] = "";
short i, m, nextChar, wordWidth;
//const short maxLength = useHyphens ? width - 1 : width;
Expand Down Expand Up @@ -4129,7 +4125,7 @@ void printHelpScreen() {
updateMessageDisplay();
}

void printDiscoveries(short category, short count, unsigned short itemCharacter, short x, short y, cellDisplayBuffer dbuf[COLS][ROWS]) {
static void printDiscoveries(short category, short count, unsigned short itemCharacter, short x, short y, cellDisplayBuffer dbuf[COLS][ROWS]) {
color goodColor, badColor;
const color *theColor;
char buf[COLS], buf2[COLS];
Expand Down Expand Up @@ -4410,7 +4406,7 @@ static short estimatedArmorValue() {
return max(0, retVal);
}

short creatureHealthChangePercent(creature *monst) {
static short creatureHealthChangePercent(creature *monst) {
if (monst->previousHealthPoints <= 0) {
return 0;
}
Expand Down
Loading

0 comments on commit 8137eaa

Please sign in to comment.