1 /*
2 This file is part of "Avanor, the Land of Mystery" roguelike game
3 Home page: http://www.avanor.com/
4 Copyright (C) 2000-2003 Vadim Gaidukevich
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 #ifndef __GLOBAL_H
22 #define __GLOBAL_H
23 
24 #ifdef WIN32
25 #  define XWIN32
26 #else
27 #  ifdef GO32
28 #     define XDOS
29 #  else
30 #     define XLINUX
31 #  endif
32 #endif
33 //#define XDOS
34 
35 // Directory for common data files (game manual, hiscore, ...)
36 #ifndef DATA_DIR
37 #  define DATA_DIR "./"
38 #endif
39 
40 // Directory for private data files (user settings, saved games, ...)
41 #ifndef HOME_DIR
42 #  ifdef XLINUX
43 #    define HOME_DIR "~/.avanor/"
44 #  else
45 #    define HOME_DIR "./"
46 #  endif
47 #endif
48 
49 #include <stdlib.h>
50 #include <stdio.h>
51 
52 #ifdef XDOS
53 #  include <dos.h>
54 #  include <conio.h>
55 #endif // WIN32
56 
57 #ifdef XWIN32
58 #  include <conio.h>
59 #endif
60 
61 
62 #ifdef XLINUX
63 #  include <curses.h>
64 #  include <string.h>
65 #endif
66 
67 
68 #include <math.h>
69 #include <assert.h>
70 
71 extern long size_x;
72 extern long size_y;
73 
74 extern unsigned long total_cr;
75 extern unsigned long total_it;
76 extern unsigned long cr_kiled;
77 extern unsigned long cr_died;
78 
79 //global flags (users preferences)
80 extern int __animation_flag; //0 - none, other - delay miliseconds
81 
82 #ifndef M_E
83 	#define M_E 2.7182818284590452354
84 #endif
85 #ifndef M_PI
86 	#define M_PI 3.1415926535897932384
87 #endif
88 
89 enum xColor {
90 xBLACK = 0,
91 xBLUE, xGREEN, xCYAN, xRED, xMAGENTA, xBROWN, xLIGHTGRAY, xDARKGRAY,
92 xLIGHTBLUE, xLIGHTGREEN, xLIGHTCYAN, xLIGHTRED, xLIGHTMAGENTA, xYELLOW,
93 xWHITE = 15
94 };
95 
96 #define MSG_BLACK          "\x1F\x00"
97 #define MSG_BLUE           "\x1F\x01"
98 #define MSG_GREEN          "\x1F\x02"
99 #define MSG_CYAN           "\x1F\x03"
100 #define MSG_RED            "\x1F\x04"
101 #define MSG_MAGENTA        "\x1F\x05"
102 #define MSG_BROWN          "\x1F\x06"
103 #define MSG_LIGHTGRAY      "\x1F\x07"
104 #define MSG_DARKGRAY       "\x1F\x08"
105 #define MSG_LIGHTBLUE      "\x1F\x09"
106 #define MSG_LIGHTGREEN     "\x1F\x0A"
107 #define MSG_LIGHTCYAN      "\x1F\x0B"
108 #define MSG_LIGHTRED       "\x1F\x0C"
109 #define MSG_LIGHTMAGENTA   "\x1F\x0D"
110 #define MSG_YELLOW         "\x1F\x0E"
111 #define MSG_WHITE          "\x1F\x0F"
112 
113 //next table helps to convert dynamic xCOLOR to text const char *
114 //that allows to create construction such next
115 //vPutS(MSG_YELLOW "yellow" SCOLOR(vRand(15)) "random color");
116 
117 #define SCOLOR(x) color_convert_table[x]
118 extern const char* color_convert_table[];
119 
120 
121 
122 //typedef char V_BUFFER[80 * 25 * 2];
123 struct V_BUFFER
124 {
125 	char * buffer;
126 	V_BUFFER();
127 	~V_BUFFER();
128 };
129 
130 extern int tri_table[120][10][2]; //120 a*3, 10 - r, 2 (0 - x, 1 - y)
131 
132 #undef KEY_EXTENDED_CODE
133 #undef KEY_ESC
134 #undef KEY_UP
135 #undef KEY_DOWN
136 #undef KEY_LEFT
137 #undef KEY_RIGHT
138 #undef KEY_HOME
139 #undef KEY_END
140 #undef KEY_PGUP
141 #undef KEY_PGDOWN
142 #undef KEY_CENTER
143 
144 #undef KEY_ENTER
145 #undef KEY_BACKSPACE
146 
147 #undef KEY_CTRL_Z
148 #undef KEY_UNKNOWN
149 
150 #define KEY_EXTENDED_CODE 0x8000
151 #define KEY_ESC           (27)
152 #define KEY_UP            (KEY_EXTENDED_CODE | 72)
153 #define KEY_DOWN          (KEY_EXTENDED_CODE | 80)
154 #define KEY_LEFT          (KEY_EXTENDED_CODE | 75)
155 #define KEY_RIGHT         (KEY_EXTENDED_CODE | 77)
156 #define KEY_HOME          (KEY_EXTENDED_CODE | 71)
157 #define KEY_END           (KEY_EXTENDED_CODE | 79)
158 #define KEY_PGUP          (KEY_EXTENDED_CODE | 73)
159 #define KEY_PGDOWN        (KEY_EXTENDED_CODE | 81)
160 #define KEY_CENTER        (KEY_EXTENDED_CODE | 76)
161 
162 #define KEY_ENTER         13
163 #define KEY_BACKSPACE     9
164 
165 #define KEY_CTRL_Z		  26
166 #define KEY_CTRL_T		  20
167 #define KEY_CTRL_O		  15
168 
169 #define KEY_UNKNOWN       0xFFFF
170 
171 void vClrScr();
172 void vInit();
173 void vFinit();
174 void vRefresh();
175 void vPutCh(int x, int y, char ch);
176 void vPutCh(int x, int y, char ch, int attr);
177 char vTestCh(int x, int y);
178 void vPutS(const char * s);
179 void vFPutS(FILE * f, const char * s);
180 int vGetS(char * s, int buffer_size);
181 void vClrEol();
182 void vGotoXY(int x, int y);
183 void vXGotoXY(int x, int y);
184 void vGetCursorPos(int * x, int * y);
185 void vSetAttr(int color);
186 void vDelay(int n);
187 int  vKbhit();
188 int  vGetch();
189 int  vXGetch(char * ch_buf);
190 void vStore(V_BUFFER * buf);
191 void vRestore(V_BUFFER * buf);
192 void vHideCursor();
193 
194 void vRandSeed(unsigned long seed);
195 long vRand();
196 long vRand(unsigned long n);
197 
198 char *vMakePath(char *prefix, char *filename);
199 
200 #endif
201