Skip to content

Commit

Permalink
feat: 1.1.4 - Add Gamestate (#18)
Browse files Browse the repository at this point in the history
- Adds `Gamestate`, already passed to `turnOP()` and ready to hold more
status as needed.
- Finally makes `log_tag()` variadic, thus dropping a multitude of `sprintf()`
calls. Some are still needed for notifications (not variadic yet), some are still left to remove.
- Bumps `koliseo` to `0.1.19`.
- Fixes a couple instances of the usual memleak where `menu_items` was
not being freed.
  • Loading branch information
jgabaut authored Sep 6, 2023
1 parent b745985 commit 26fafa0
Show file tree
Hide file tree
Showing 21 changed files with 1,241 additions and 1,696 deletions.
10 changes: 7 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,32 @@ endif
AM_CFLAGS = $(HELAPORDO_CFLAGS) -Werror -Wpedantic -Wall -DKOLISEO_HAS_CURSES

./src/anvil__helapordo.c:
@echo -en "Generating C anvil__helapordo for $(VERSION):\n"
@echo -en "Generating C anvil__helapordo for $(VERSION): "
-./anvil -G ./src $(VERSION)
@echo -e "\033[1;33mDone.\e[0m"

./koliseo/src/koliseo.o:
@echo -en "Building Koliseo with curses:\n"
@echo -en "Building Koliseo with curses: "
gcc -c ./koliseo/src/koliseo.c -DKOLISEO_HAS_CURSES -o ./koliseo/src/koliseo.o
@echo -e "\033[1;33mDone.\e[0m"

./src/palette.c:
@echo -en "\033[1;34m[Makefile]\e[0m Using python to generate C palette files from \033[1;35m[$(PALETTE_PATH)]:\e[0m "
python ./sprites4curses/scripts/palette.py C-impl $(PALETTE_PATH) .. > ./src/palette.c
python ./sprites4curses/scripts/palette.py C-header $(PALETTE_PATH) .. > ./src/palette.h
@echo -e "Done."
@echo -e "\033[1;33mDone.\e[0m"

# Build rule for object files
%.o: %.c
@echo -en "[ $< ] ->\033[1;34m [ $@ ]:\e[0m "
$(CC) -c $(CFLAGS) $(AM_CFLAGS) $< -o $@
@echo -e "\033[1;33mDone.\e[0m"

# Build rule for the final binary
$(TARGET): $(helapordo_SOURCES:.c=.o)
@echo -en "\033[1;34mBuilding [\033[1;35m $@ \033[1;34m]:\e[0m "
$(CC) $(CFLAGS) $(AM_CFLAGS) $(helapordo_SOURCES:.c=.o) -o $@ $(LDADD) $(AM_LDFLAGS)
@echo -e "\033[1;33mDone.\e[0m"

# Targets for additional rules
versioncheck:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@

- `apple-arm64`

📦 v1.1.3 02/09/2023
📦 v1.1.4 06/09/2023
https://github.com/jgabaut/helapordo/releases
1 change: 1 addition & 0 deletions bin/stego.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ kazoj# tests folder name
1.1.1# Palette is compiled
1.1.2# Define HLP_Region_Type, bump Koliseo to 0.1.17 - Deprecated
1.1.3# Fix enum conversion warn, bump Koliseo to 0.1.18
1.1.4# Add Gamestate, variadic log_tag()
5 changes: 5 additions & 0 deletions bin/v1.1.4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir
#we also keep specific dependencies...
*
!.gitignore
!static
1 change: 1 addition & 0 deletions bin/v1.1.4/static
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define the package name and version
AC_INIT([helapordo], [1.1.3], [[email protected]])
AC_INIT([helapordo], [1.1.4], [[email protected]])

# Verify automake version and enable foreign option
AM_INIT_AUTOMAKE([foreign -Wall])
Expand Down Expand Up @@ -32,7 +32,7 @@ fi
# Set a default version number if not specified externally
AC_ARG_VAR([VERSION], [Version number])
if test -z "$VERSION"; then
VERSION="1.1.3"
VERSION="1.1.4"
fi

# Output variables to the config.h header
Expand Down
2 changes: 1 addition & 1 deletion docs/helapordo.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "helapordo"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "1.1.3"
PROJECT_NUMBER = "1.1.4"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion kazoj/bone/const.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void fail(char* msg, int ex, int val) {

int main(void) {
int check = -1;
if ( ! (( check = strcmp(VERSION, "1.1.3") ) == 0)) {
if ( ! (( check = strcmp(VERSION, "1.1.4") ) == 0)) {
fail("VERSION",0,check);
};
if ( ! (TURNOP_MAX == 15) ) {
Expand Down
2 changes: 1 addition & 1 deletion koliseo
65 changes: 21 additions & 44 deletions src/floors.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ void display_explored_layout(Floor* floor, WINDOW* win) {
*/
void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clean) {
int unique_steps = 0;
char msg[500];
int directions[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int max_area_ratio = 80;
int min_area_ratio = 45;
Expand All @@ -282,14 +281,11 @@ void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clea
log_tag("debug_log.txt","[FLOOR]","Retrying same direction!");
dir = lastdir > 0 ? lastdir : (rand() % 4);
}
sprintf(msg,"dir is [%i]", dir);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","dir is [%i]", dir);
while (dir == lastdir && did_bonk) {
sprintf(msg,"dir [%i] == [%i] lastdir!! Won't bonk again.",dir,lastdir);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","dir [%i] == [%i] lastdir!! Won't bonk again.",dir,lastdir);
dir = rand() % 4;
sprintf(msg,"newdir is [%i]", dir);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","newdir is [%i]", dir);
}
int new_x = -1;
int new_y = -1;
Expand All @@ -306,8 +302,7 @@ void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clea
} else if (floor->floor_layout[new_x][new_y] == 1){
log_tag("debug_log.txt","[FLOOR]","This was not a new cell.");
} else {
sprintf(msg,"Unexpected value in floor->floor_layout[%i][%i]: [%i].",new_x,new_y,floor->floor_layout[new_x][new_y]);
log_tag("debug_log.txt","[ERROR]",msg);
log_tag("debug_log.txt","[ERROR]","Unexpected value in floor->floor_layout[%i][%i]: [%i].",new_x,new_y,floor->floor_layout[new_x][new_y]);
exit(EXIT_FAILURE);
}
x = new_x;
Expand All @@ -322,19 +317,16 @@ void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clea
}
}

sprintf(msg,"floor_random_walk(): walked [%i] steps, [%i] unique.",walked_steps,unique_steps);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","floor_random_walk(): walked [%i] steps, [%i] unique.",walked_steps,unique_steps);
if ( ( unique_steps <= (steps/100 * min_area_ratio) || unique_steps >= (steps/100 * max_area_ratio)) && (do_layout_clean) ) {
sprintf(msg,"floor_random_walk(): area too small, walked [%i] unique steps, will retry. Calling init_floor_layout().", unique_steps);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","floor_random_walk(): area too small, walked [%i] unique steps, will retry. Calling init_floor_layout().", unique_steps);
init_floor_layout(floor);
floor->floor_layout[FLOOR_MAX_COLS/2][FLOOR_MAX_COLS/2] = 1;
}
} while ( (unique_steps <= (steps/100 * min_area_ratio) || unique_steps >= (steps/100 * max_area_ratio)) && (do_layout_clean));

floor->area += unique_steps;
sprintf(msg,"floor_random_walk(): added [%i] to floor->area. New value: [%i].", unique_steps, floor->area);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","floor_random_walk(): added [%i] to floor->area. New value: [%i].", unique_steps, floor->area);
}

/**
Expand All @@ -343,7 +335,6 @@ void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clea
* @see floorClass
*/
void floor_set_room_types(Floor* floor) {
char msg[500];

int placed_rooms = 0;
// Assume the center room is the HOME room
Expand Down Expand Up @@ -391,9 +382,8 @@ void floor_set_room_types(Floor* floor) {
}
}
}
sprintf(msg,"floor_set_room_types(): (max/min) x [%i/%i] y [%i/%i].",max_x,min_x,max_y,min_y);

log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","floor_set_room_types(): (max/min) x [%i/%i] y [%i/%i].",max_x,min_x,max_y,min_y);

int shop_x = 0;
int shop_y = 0;
Expand Down Expand Up @@ -563,7 +553,6 @@ void draw_floor_view(Floor* floor, int current_x, int current_y, WINDOW* win) {
* @see floorClass
*/
void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner_x, int drawcorner_y, int x_size, int y_size, int recurse) {
char msg[200];
if (win == NULL) {
log_tag("debug_log.txt","[ERROR]","draw_cell(): win was NULL.");
exit(EXIT_FAILURE);
Expand All @@ -576,10 +565,8 @@ void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner

if (floor->floor_layout[cell_x][cell_y] == 0) {
if (floor->roomclass_layout[cell_x][cell_y] != WALL) {
sprintf(msg,"draw_cell(): floor->floor_layout[%i][%i] was (%i).",cell_x,cell_y,floor->floor_layout[cell_x][cell_y]);
log_tag("debug_log.txt","[DEBUG]",msg);
sprintf(msg,"draw_cell(): floor->roomclass_layout[%i][%i] was (%s).",cell_x,cell_y,stringFromRoom(floor->roomclass_layout[cell_x][cell_y]));
log_tag("debug_log.txt","[DEBUG]",msg);
log_tag("debug_log.txt","[DEBUG]","draw_cell(): floor->floor_layout[%i][%i] was (%i).",cell_x,cell_y,floor->floor_layout[cell_x][cell_y]);
log_tag("debug_log.txt","[DEBUG]","draw_cell(): floor->roomclass_layout[%i][%i] was (%s).",cell_x,cell_y,stringFromRoom(floor->roomclass_layout[cell_x][cell_y]));
}
for (int i = 0; i < xSize; i++) {
for (int j = 0; j < ySize; j++) {
Expand Down Expand Up @@ -637,8 +624,7 @@ void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner
}
break;
default: {
sprintf(msg,"draw_cell(): tried drawing an invalid cell for floor->roomclass_layout[%i][%i].",cell_x,cell_y);
log_tag("debug_log.txt","[ERROR]",msg);
log_tag("debug_log.txt","[ERROR]","draw_cell(): tried drawing an invalid cell for floor->roomclass_layout[%i][%i].",cell_x,cell_y);
ch = '?';
isColored = S4C_DARK_GREEN;
}
Expand All @@ -654,10 +640,8 @@ void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner
if (recurse > 0 && cell_y < FLOOR_MAX_ROWS-1) draw_cell(floor,cell_x,cell_y+1,win,drawcorner_x,drawcorner_y+3,x_size,y_size, recurse-1);
if (recurse > 0 && cell_y > 0) draw_cell(floor,cell_x,cell_y-1,win,drawcorner_x,drawcorner_y-3,x_size,y_size, recurse-1);
} else {
sprintf(msg,"draw_cell(): floor->floor_layout[%i][%i] was (%i).",cell_x,cell_y,floor->floor_layout[cell_x][cell_y]);
log_tag("debug_log.txt","[ERROR]",msg);
sprintf(msg,"draw_cell(): floor->roomclass_layout[%i][%i] was (%s).",cell_x,cell_y,stringFromRoom(floor->roomclass_layout[cell_x][cell_y]));
log_tag("debug_log.txt","[ERROR]",msg);
log_tag("debug_log.txt","[ERROR]","draw_cell(): floor->floor_layout[%i][%i] was (%i).",cell_x,cell_y,floor->floor_layout[cell_x][cell_y]);
log_tag("debug_log.txt","[ERROR]","draw_cell(): floor->roomclass_layout[%i][%i] was (%s).",cell_x,cell_y,stringFromRoom(floor->roomclass_layout[cell_x][cell_y]));
exit(EXIT_FAILURE);
}
}
Expand All @@ -669,12 +653,11 @@ void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner
* @see Floor
* @see floorClass
*/
void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path* path, Fighter* player, Room* room, loadInfo* load_info, Koliseo* kls, Koliseo_Temp* t_kls) {
void move_update(Gamestate* gamestate, Floor* floor, int* current_x, int* current_y, WINDOW* win, Path* path, Fighter* player, Room* room, loadInfo* load_info, Koliseo* kls, Koliseo_Temp* t_kls) {
if (win == NULL) {
log_tag("debug_log.txt","[ERROR]","move_update(): win was NULL.");
exit(EXIT_FAILURE);
}
char msg[500];

int picked = 0;
int c = -1;
Expand All @@ -686,7 +669,7 @@ void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path
switch(c) {
case 'm': {
picked = 0;
handleRogueMenu(path,player,room,load_info,kls,t_kls);
handleRogueMenu(gamestate,path,player,room,load_info,kls,t_kls);
//Draw current FOV
draw_floor_view(floor, *current_x, *current_y, win);
continue;
Expand All @@ -713,8 +696,7 @@ void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path
}
break;
default: {
sprintf(msg,"move_update(): Player char (%c)was not accounted for. Target (x=%i,y=%i) class (%s).",c,target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","move_update(): Player char (%c)was not accounted for. Target (x=%i,y=%i) class (%s).",c,target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
picked = 0;
continue;
}
Expand All @@ -727,15 +709,11 @@ void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path
if (floor->explored_matrix[target_x][target_y] == 0) {
floor->explored_matrix[target_x][target_y] = 1;
(floor->explored_area)++;
sprintf(msg,"move_update(): target x[%i],y[%i] was not walked before. Class: (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]",msg);
sprintf(msg,"move_update(): explored area [%i].",floor->explored_area);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","move_update(): target x[%i],y[%i] was not walked before. Class: (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]","move_update(): explored area [%i].",floor->explored_area);
} else {
sprintf(msg,"move_update(): target x[%i],y[%i] was walked before. Class: (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]",msg);
sprintf(msg,"move_update(): explored area [%i], tot area [%i].",floor->explored_area,floor->area);
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","move_update(): target x[%i],y[%i] was walked before. Class: (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]","move_update(): explored area [%i], tot area [%i].",floor->explored_area,floor->area);
}
*current_x = target_x;
*current_y = target_y;
Expand All @@ -749,8 +727,7 @@ void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path

switch (floor->roomclass_layout[target_x][target_y]) {
default: {
sprintf(msg,"move_update(): target x[%i],y[%i] was of class (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));
log_tag("debug_log.txt","[FLOOR]",msg);
log_tag("debug_log.txt","[FLOOR]","move_update(): target x[%i],y[%i] was of class (%s).",target_x,target_y,stringFromRoom(floor->roomclass_layout[target_x][target_y]));

}

Expand Down
2 changes: 1 addition & 1 deletion src/floors.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void display_roomclass_layout(Floor* floor, WINDOW* win);
void draw_cell(Floor* floor, int cell_x, int cell_y, WINDOW* win, int drawcorner_x, int drawcorner_y, int x_size, int y_size, int recurse);
void draw_floor_view(Floor* floor, int current_x, int current_y, WINDOW* win);

void move_update(Floor* floor, int* current_x, int* current_y, WINDOW* win, Path* path, Fighter* player, Room* room, loadInfo* load_info, Koliseo* kls, Koliseo_Temp* t_kls);
void move_update(Gamestate* gamestate, Floor* floor, int* current_x, int* current_y, WINDOW* win, Path* path, Fighter* player, Room* room, loadInfo* load_info, Koliseo* kls, Koliseo_Temp* t_kls);

void floor_random_walk(Floor* floor, int x, int y, int steps, int do_layout_clean);
void floor_set_room_types(Floor* floor);
Expand Down
1 change: 1 addition & 0 deletions src/game_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ char* hlp_regiontype_strings[HLP_MAX_INDEX+1] = {
"HLP_Room_desc",
"HLP_countStats",
"HLP_Saveslot",
"HLP_Gamestate",
"HLP_loadInfo",
};

Expand Down
31 changes: 29 additions & 2 deletions src/game_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef enum HLP_Region_Type {
HR_Room_desc,
HR_countStats,
HR_Saveslot,
HR_Gamestate,
HR_loadInfo,
} HLP_Region_Type;

Expand Down Expand Up @@ -112,12 +113,12 @@ extern int GS_AUTOSAVE_ON;
/**
* Current patch release.
*/
#define HELAPORDO_PATCH_VERSION 3
#define HELAPORDO_PATCH_VERSION 4

/**
* Current version string identifier, with MAJOR.MINOR.PATCH format.
*/
#define VERSION "1.1.3"
#define VERSION "1.1.4"

/**
* Default savepath.
Expand Down Expand Up @@ -1534,6 +1535,31 @@ typedef struct loadInfo {

} loadInfo;

/**
* Holds arguments for a game.
* @see countStats
* @see roomClass
* @see Wincon
* @see Path
*/
typedef struct {

countStats* stats; /**< Keeps track of stats for the game.*/

int current_fighters; /**< Keeps track of Fighter number for the game.*/
roomClass current_roomtype; /**< Keeps track of current room type.*/
int current_room_index; /**< Keeps track of current room index.*/

int current_enemy_index; /**< Keeps track of current enemy index.*/
Wincon* wincon; /**< Keeps track of current Wincon.*/

Path* path; /**< Keeps track of current Path.*/

Fighter* player; /**< Keeps track of current Player.*/

Gamemode gamemode; /**< Keeps track of current Gamemode.*/
} Gamestate;

/**
* The different kinds of turnOption.
* @see getTurnChoice()
Expand Down Expand Up @@ -1659,6 +1685,7 @@ typedef struct {
FILE* save_file; /**< Pointer to savefile for OP*/
WINDOW* notify_win; /**< Pointer to notification window for OP*/
Koliseo_Temp* t_kls; /**< Pointer to Koliseo_Temp for OP*/
Gamestate* gmst; /**< Pointer to Gamestate for OP*/
} turnOP_args;

/**
Expand Down
Loading

0 comments on commit 26fafa0

Please sign in to comment.