Skip to content

Commit

Permalink
Merge pull request #9 from Alien-AV/master
Browse files Browse the repository at this point in the history
Adds windows support
  • Loading branch information
Whales committed Jul 2, 2011
2 parents d49d8c0 + cf8b5bf commit 2ab5333
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 185 deletions.
169 changes: 72 additions & 97 deletions game.cpp

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion game.h
Expand Up @@ -23,6 +23,40 @@
#define BULLET_SPEED 10000000
#define EXPLOSION_SPEED 70000000


#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Windows platforms. */

# ifdef __cplusplus
extern "C" {
# endif

struct timespec
{
time_t tv_sec;
long int tv_nsec;
};

# ifdef __cplusplus
}
# endif

enum { BILLION = 1000 * 1000 * 1000 };

# define WIN32_LEAN_AND_MEAN
# include <windows.h>

/* The Win32 function Sleep() has a resolution of about 15 ms and takes
at least 5 ms to execute. We use this function for longer time periods.
Additionally, we use busy-looping over short time periods, to get a
resolution of about 0.01 ms. In order to measure such short timespans,
we use the QueryPerformanceCounter() function. */

int
nanosleep (const struct timespec *requested_delay,
struct timespec *remaining_delay);
#endif

enum tut_type {
TUT_NULL,
TUT_BASIC, TUT_COMBAT,
Expand Down Expand Up @@ -157,7 +191,7 @@ class game
void wait(); // Long wait (player action) '^'
void open(); // Open a door 'o'
void close(); // Close a door 'c'
void smash(); // Smash terrain
void smash(); // Smash terrain
void craft(); // See crafting.cpp
void make_craft(recipe *making); // See crafting.cpp
void complete_craft(); // See crafting.cpp
Expand Down
20 changes: 3 additions & 17 deletions help.cpp
@@ -1,20 +1,6 @@
#include "game.h"
#include "keypress.h"

#ifndef LINE_XOXO
#define LINE_XOXO 4194424
#define LINE_OXOX 4194417
#define LINE_XXOO 4194413
#define LINE_OXXO 4194412
#define LINE_OOXX 4194411
#define LINE_XOOX 4194410
#define LINE_XXXO 4194420
#define LINE_XXOX 4194422
#define LINE_XOXX 4194421
#define LINE_OXXX 4194423
#define LINE_XXXX 4194414
#endif

void game::help()
{
char ch;
Expand Down Expand Up @@ -46,7 +32,7 @@ m: Survival tips\n\
5: Frequently Asked Questions (Some spoilers!)\n\
\n\
q: Return to game");

ch = getch();
switch (ch) {
case 'a':
Expand All @@ -67,7 +53,7 @@ setting makes some tasks easier. Firearms, medications, and a wide variety of\n\
tools are all available to help you survive.");
getch();
break;

case 'b':
case 'B':
erase();
Expand Down Expand Up @@ -492,7 +478,7 @@ F Forest - May be dense or sparse. Slow moving; foragable food.");
mvputch(3, 8, c_dkgray, LINE_XOXX);
mvputch(3, 9, c_dkgray, LINE_OXXX);
mvputch(3, 10, c_dkgray, LINE_XXXX);

mvprintz( 3, 12, c_dkgray, "\
Road - Safe from burrowing animals.");
mvprintz( 4, 0, c_dkgray, "\
Expand Down
9 changes: 9 additions & 0 deletions keypress.h
@@ -1,6 +1,15 @@
#ifndef _KEYPRESS_H_
#define _KEYPRESS_H_
#include <curses.h>

/* Fix the backspace key on Windows (by jaydg) */
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# if defined KEY_BACKSPACE
# undef KEY_BACKSPACE
# endif
# define KEY_BACKSPACE 8
#endif

// Simple text input--translates numpad to vikeys
long input();
// If ch is vikey, x & y are set to corresponding direction; ch=='y'->x=-1,y=-1
Expand Down
2 changes: 2 additions & 0 deletions main.cpp
Expand Up @@ -25,7 +25,9 @@ int main(int argc, char *argv[])
while (!g.do_turn());
erase();
endwin();
#if !(defined _WIN32 || defined __WIN32__) || defined __CYGWIN__
system("clear");
#endif
return 0;
}

27 changes: 7 additions & 20 deletions newcharacter.cpp
Expand Up @@ -5,19 +5,6 @@
#include "game.h"
#include <unistd.h>

// ncurses has not yet been initialized, so we need to define our line chars
#define LINE_XOXO 4194424
#define LINE_OXOX 4194417
#define LINE_XXOO 4194413
#define LINE_OXXO 4194412
#define LINE_OOXX 4194411
#define LINE_XOOX 4194410
#define LINE_XXXO 4194420
#define LINE_XXOX 4194422
#define LINE_XOXX 4194421
#define LINE_OXXX 4194423
#define LINE_XXXX 4194414

// Colors used in this file: (Most else defaults to c_ltgray)
#define COL_STAT_ACT c_ltred // Selected stat
#define COL_TR_GOOD c_green // Good trait descriptive text
Expand Down Expand Up @@ -188,7 +175,7 @@ bool player::create(game *g, character_type type)

if (tab < 0)
return false;

// Character is finalized. Now just set up HP, &c
for (int i = 0; i < num_hp_parts; i++) {
hp_max[i] = calc_HP(str_max, has_trait(PF_TOUGH));
Expand Down Expand Up @@ -281,8 +268,8 @@ void draw_tabs(WINDOW* w)
mvwputch(w, 1,57, c_ltgray, LINE_XOXO);
mvwputch(w, 1,73, c_ltgray, LINE_XOXO);
}



int set_stats(WINDOW* w, player *u, int &points)
{
Expand Down Expand Up @@ -389,7 +376,7 @@ int set_stats(WINDOW* w, player *u, int &points)
mvwprintz(w,11, 33, COL_STAT_ACT, " ");
break;
}

wrefresh(w);
ch = input();
if (ch == 'j' && sel < 4)
Expand Down Expand Up @@ -661,7 +648,7 @@ int set_skills(WINDOW* w, player *u, int &points)
mvwputch(w, 2,57, c_ltgray, LINE_XXOX);
mvwputch(w, 2,73, c_ltgray, LINE_XXOX);
mvwprintz(w,1,40, h_ltgray, " SKILLS ");

int cur_sk = 1;

do {
Expand Down Expand Up @@ -727,7 +714,7 @@ int set_skills(WINDOW* w, player *u, int &points)
}
}
}

wrefresh(w);
switch (input()) {
case 'j':
Expand Down Expand Up @@ -789,7 +776,7 @@ Gender: Male Female (Press spacebar to toggle)");
When your character is finished and you're ready to start playing, press '>'.");
mvwprintz(w,12, 2, c_ltgray, "\
To go back and review your character, press '<'.");

int line = 1;
bool noname = false;
long ch;
Expand Down
28 changes: 15 additions & 13 deletions output.cpp
Expand Up @@ -12,17 +12,19 @@
#include "rng.h"
#include "keypress.h"

#define LINE_XOXO 4194424
#define LINE_OXOX 4194417
#define LINE_XXOO 4194413
#define LINE_OXXO 4194412
#define LINE_OOXX 4194411
#define LINE_XOOX 4194410
#define LINE_XXXO 4194420
#define LINE_XXOX 4194422
#define LINE_XOXX 4194421
#define LINE_OXXX 4194423
#define LINE_XXXX 4194414
#ifndef LINE_XOXO
#define LINE_XOXO ACS_VLINE
#define LINE_OXOX ACS_HLINE
#define LINE_XXOO ACS_LLCORNER
#define LINE_OXXO ACS_ULCORNER
#define LINE_OOXX ACS_URCORNER
#define LINE_XOOX ACS_LRCORNER
#define LINE_XXXO ACS_RTEE
#define LINE_XXOX ACS_BTEE
#define LINE_XOXX ACS_LTEE
#define LINE_OXXX ACS_TTEE
#define LINE_XXXX ACS_PLUS
#endif

nc_color hilite(nc_color c)
{
Expand Down Expand Up @@ -446,7 +448,7 @@ void popup_top(const char *mes, ...)
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());

wrefresh(w);
char ch;
do
Expand Down Expand Up @@ -497,7 +499,7 @@ void popup(const char *mes, ...)
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());

wrefresh(w);
char ch;
do
Expand Down
24 changes: 13 additions & 11 deletions output.h
Expand Up @@ -7,17 +7,19 @@
#include <vector>

// LINE_NESW - X for on, O for off
#define LINE_XOXO 4194424
#define LINE_OXOX 4194417
#define LINE_XXOO 4194413
#define LINE_OXXO 4194412
#define LINE_OOXX 4194411
#define LINE_XOOX 4194410
#define LINE_XXXO 4194420
#define LINE_XXOX 4194422
#define LINE_XOXX 4194421
#define LINE_OXXX 4194423
#define LINE_XXXX 4194414
#ifndef LINE_XOXO
#define LINE_XOXO ACS_VLINE
#define LINE_OXOX ACS_HLINE
#define LINE_XXOO ACS_LLCORNER
#define LINE_OXXO ACS_ULCORNER
#define LINE_OOXX ACS_URCORNER
#define LINE_XOOX ACS_LRCORNER
#define LINE_XXXO ACS_RTEE
#define LINE_XXOX ACS_BTEE
#define LINE_XOXX ACS_LTEE
#define LINE_OXXX ACS_TTEE
#define LINE_XXXX ACS_PLUS
#endif

void mvputch(int y, int x, nc_color FG, long ch);
void wputch(WINDOW* w, nc_color FG, long ch);
Expand Down

0 comments on commit 2ab5333

Please sign in to comment.