Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Halloween detection #173

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ CC = gcc
LINKS =-lncurses -lpanel
COMMON_FLAGS =-g -Wall -pedantic -Wextra -Werror \
-Wmissing-prototypes -Wstrict-prototypes $(INCLUDE)
CC_FLAGS =-std=c89 $(COMMON_FLAGS) $(INCLUDE)\
-D__NEED_USLEEP__
CC_FLAGS =-std=c89 $(COMMON_FLAGS) $(INCLUDE) $(EXTRA_FLAGS)
ID = uncrustify
ID_FLAGS =-c uncrustify.cfg

Expand Down Expand Up @@ -43,4 +42,4 @@ lint: $(SOURCES:.c=.c~uncrust) $(HEADERS:.h=.h~uncrust)
# Allow you to get a valid build without the -std=c89 standard
# (for local development)
cheat: CC_FLAGS = $(COMMON_FLAGS) $(INCLUDE)
cheat: $(EXEC)
cheat: $(EXEC)
2 changes: 2 additions & 0 deletions src/core/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define KEY_F(n) (KEY_F0 + (n))
#endif

#define COMMAND_CHAR 17

/* Normal movements */
#define KEY_MOVE_N 'j'
#define KEY_MOVE_N_BABBY 0x102
Expand Down
18 changes: 16 additions & 2 deletions src/core/demo.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <stdio.h>
#include <curses.h>
#include <unistd.h>
#include <stdlib.h>
#include "demo.h"
#include "args.h"
#include "controls.h"
#include "main.h"

static void demo_write_header(void);
static void demo_read_header(void);
Expand All @@ -12,7 +15,7 @@ static FILE* write_to = 0;

static int demo_speed = 300;

#ifdef __NEED_USLEEP__
#ifndef __HAS_USLEEP__
void usleep(long); /* needed because headers are big sad */
#endif

Expand All @@ -35,20 +38,31 @@ int demo_next(void)
static void demo_read_header()
{
int demo_version;
int halloween;
unsigned long s;
fread(&demo_version, sizeof(demo_version), 1, read_from);
fread(&s, sizeof(s), 1, read_from);
/* TODO: fail if demo version is wrong */
if (demo_version != DEMO_VERSION) {
fprintf(stderr, "File demo version (%d) does not match application version (%d)!\n", demo_version, DEMO_VERSION);
exit(1);
}
set_seed(s);
fread(&halloween, sizeof(halloween), 1, read_from);
fread(&halloween, sizeof(halloween), 1, read_from);
set_halloween(halloween);
}


static void demo_write_header(void)
{
unsigned long s = get_seed();
int demo_version = DEMO_VERSION;
int command_char = COMMAND_CHAR;
int one = is_halloween();
fwrite(&demo_version, sizeof(demo_version), 1, write_to);
fwrite(&s, sizeof(s), 1, write_to);
fwrite(&command_char, sizeof(command_char), 1, write_to);
fwrite(&one, sizeof(one), 1, write_to);
}

void demo_start(int mode, char* fname)
Expand Down
2 changes: 1 addition & 1 deletion src/core/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void demo_header(void);
#define DEMO_NONE 0
#define DEMO_REPLAY 1
#define DEMO_RECORD 2
#define DEMO_VERSION 0
#define DEMO_VERSION 1
#define DEMO_DEFAULT_FILE ".demo.hag"
/* TODO: do we need a demo_close? */
#endif
21 changes: 18 additions & 3 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <time.h>

#include "main.h"
#include "demo.h"
#include "args.h"
#include "player.h"
Expand All @@ -21,12 +23,12 @@
#include "enemy.h"
#include "gui.h"
#include "key.h"
#include "main.h"

#define W 60
#define H 13

int tick = 0;
int halloween = 0;



Expand All @@ -51,6 +53,11 @@ int main(int argc, char **argv)
enemy_t *at;
WINDOW *my_wins[3];
PANEL *my_panels[3];
time_t cur_time;
struct tm *tm;
cur_time = time(NULL);
tm = localtime(&cur_time);
halloween = tm->tm_mon == 9 && tm->tm_mday == 31;
parse_args(argc, argv);

floor_down();
Expand All @@ -60,8 +67,6 @@ int main(int argc, char **argv)
/* https://stackoverflow.com/questions/1022957/getting-terminal-width-in-c */
ioctl(0, TIOCGWINSZ, &w);



/* Initialize curses */
initscr();
cbreak();
Expand Down Expand Up @@ -335,3 +340,13 @@ void player_attacks(player_t *player, enemy_t *at)
}
}
}

int is_halloween(void)
{
return halloween;
}

void set_halloween(int h)
{
halloween = h;
}
3 changes: 3 additions & 0 deletions src/core/main.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#ifndef MAIN_H
#include "player.h"
extern int tick;
void player_attacks(player_t *player, enemy_t *at);
int is_halloween(void);
void set_halloween(int h);
#endif
25 changes: 13 additions & 12 deletions src/logic/enemy_rulebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ int snek = 0;
void generate_enemies()
{
called = 1;
book_length = 0;

/* rat */
rulebook[book_length].name = "rat";
rulebook[book_length].name = is_halloween() ? "spooky rat" : "rat";
rulebook[book_length].pic = 'r' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 30;
rulebook[book_length].base_sight_range = 10;
Expand All @@ -33,7 +34,7 @@ void generate_enemies()
book_length++;

/* kobold */
rulebook[book_length].name = "kobold";
rulebook[book_length].name = is_halloween() ? "spooky kobold" : "kobold";
rulebook[book_length].pic = 'k' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 50;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -46,7 +47,7 @@ void generate_enemies()
book_length++;

/* goblin */
rulebook[book_length].name = "goblin";
rulebook[book_length].name = is_halloween() ? "spooky goblin" : "goblin";
rulebook[book_length].pic = 'g' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 50;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -59,7 +60,7 @@ void generate_enemies()
book_length++;

/* snake */
rulebook[book_length].name = "snek";
rulebook[book_length].name = is_halloween() ? "spooky snek" : "snek";
rulebook[book_length].pic = 's' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 50;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -73,7 +74,7 @@ void generate_enemies()
book_length++;

/* slime */
rulebook[book_length].name = "slime";
rulebook[book_length].name = is_halloween() ? "spooky slime" : "slime";
rulebook[book_length].pic = 'm' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 75;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -86,7 +87,7 @@ void generate_enemies()
book_length++;

/* orc */
rulebook[book_length].name = "orc";
rulebook[book_length].name = is_halloween() ? "spooky orc" : "orc";
rulebook[book_length].pic = 'o' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 75;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -99,7 +100,7 @@ void generate_enemies()
book_length++;

/* wolf */
rulebook[book_length].name = "wolf";
rulebook[book_length].name = is_halloween() ? "spooky wolf" : "wolf";
rulebook[book_length].pic = 'w' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 50;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -112,7 +113,7 @@ void generate_enemies()
book_length++;

/* imp */
rulebook[book_length].name = "imp";
rulebook[book_length].name = is_halloween() ? "spooky imp" : "imp";
rulebook[book_length].pic = 'i' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 75;
rulebook[book_length].base_sight_range = 15;
Expand All @@ -125,7 +126,7 @@ void generate_enemies()
book_length++;

/* griffin */
rulebook[book_length].name = "griffin";
rulebook[book_length].name = is_halloween() ? "spooky griffin" : "griffin";
rulebook[book_length].pic = 'G' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 100;
rulebook[book_length].base_sight_range = 20;
Expand All @@ -138,7 +139,7 @@ void generate_enemies()
book_length++;

/* grue */
rulebook[book_length].name = "grue";
rulebook[book_length].name = is_halloween() ? "spooky grue" : "grue";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be spoopy instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

rulebook[book_length].pic = 'U' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 60;
rulebook[book_length].base_sight_range = 20;
Expand All @@ -151,7 +152,7 @@ void generate_enemies()
book_length++;

/* fake hag */
rulebook[book_length].name = "Hag";
rulebook[book_length].name = is_halloween() ? "Halloween Hag" : "Hag";
rulebook[book_length].pic = 'H' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 1;
rulebook[book_length].base_sight_range = 0;
Expand All @@ -165,7 +166,7 @@ void generate_enemies()
book_length++;

/* hag */
rulebook[book_length].name = "Hag";
rulebook[book_length].name = is_halloween() ? "Halloween Hag" : "Hag";
rulebook[book_length].pic = 'H' | A_BOLD | COLORS_RED;
rulebook[book_length].base_hp = 30;
rulebook[book_length].base_sight_range = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void set_scroll(int scroll)
}

void print_in_window(WINDOW * win, int starty, int startx, int width,
char *string, chtype color, bool mid)
char *string, chtype color, int mid)
{
int length;
int x;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
void init_wins(WINDOW ** wins, struct winsize w);
void win_show(WINDOW * win);
void print_in_window(WINDOW * win, int starty, int startx, int width,
char *string, chtype color, bool mid);
char *string, chtype color, int mid);
void print_stats(struct player *p, WINDOW * wins2, int floor_tick);
void print_action(void);
void add_action(char *s);
Expand Down