1 /*
2 * nazghul - an old-school RPG engine
3 * Copyright (C) 2002, 2003 Gordon McNutt
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 * Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Gordon McNutt
20 * gmcnutt@users.sourceforge.net
21 */
22
23 #include "dimensions.h"
24 #include "common.h" /* for MOON_WINDOW_W */
25 #include "cfg.h"
26
27 #include <string.h>
28
29 int STATUS_MAX_MSG_SZ;
30 int SCREEN_W;
31 int SCREEN_H;
32 int CONSOLE_MAX_MSG_SZ;
33 int MAP_TILE_W;
34 int MAP_TILE_H;
35 int MAP_X;
36 int MAP_Y;
37 int MAP_W;
38 int MAP_H;
39 int CMD_X;
40 int CMD_Y;
41 int CMD_W;
42 int CMD_H;
43 int STAT_X;
44 int STAT_Y;
45 int STAT_W;
46 int STAT_H;
47 int STAT_H_MAX;
48 int FOOGOD_X;
49 int FOOGOD_Y;
50 int FOOGOD_W;
51 int FOOGOD_H;
52 int WIND_X;
53 int WIND_Y;
54 int WIND_W;
55 int WIND_H;
56 int CONS_X;
57 int CONS_Y;
58 int CONS_W;
59 int CONS_H;
60 int CONS_LINES;
61 int SKY_X;
62 int SKY_Y;
63 int SKY_W;
64 int SKY_H;
65 int SKY_SPRITE_W;
66
67 /* dimensions_get_map_size -- figure out the biggest map window that will
68 * satisfy the screen dimensions. */
dimensions_get_map_size(char * dimstr)69 static int dimensions_get_map_size(char *dimstr)
70 {
71 struct dimstr2mapsz {
72 const char *dimstr;
73 int map_sz;
74 };
75 # define ADD_SCREEN_DIM(dim,mapw) { (dim), (mapw) },
76 struct dimstr2mapsz tbl[] = {
77 # include "screen_dims.h"
78 };
79
80 int i;
81
82 if (!dimstr) {
83 warn("warn: NULL dimensions");
84 return -1;
85 }
86
87 for (i = 0; i < array_sz(tbl); i++) {
88 if (! strcmp(tbl[i].dimstr, dimstr)) {
89 return tbl[i].map_sz;
90 }
91 }
92
93 warn("warn: screen res %s not found in table\n", dimstr);
94 return -1;
95 }
96
dimensions_init()97 int dimensions_init()
98 {
99 int map_size = dimensions_get_map_size(cfg_get("screen-dims"));
100 if (map_size < 0)
101 return -1;
102
103 MAP_TILE_W = map_size;
104 MAP_TILE_H = map_size;
105
106 MAP_X = BORDER_W;
107 MAP_Y = BORDER_H;
108 MAP_W = (TILE_W * MAP_TILE_W);
109 MAP_H = (TILE_H * MAP_TILE_H);
110
111 CMD_X = MAP_X;
112 CMD_Y = (MAP_Y + MAP_H + BORDER_H);
113 CMD_W = MAP_W;
114 CMD_H = ASCII_H;
115
116 SCREEN_H = (BORDER_H * 3 + MAP_H + CMD_H);
117
118 STATUS_MAX_MSG_SZ = 128;
119 STAT_X = (MAP_X + MAP_W + BORDER_W);
120 STAT_Y = BORDER_H;
121 STAT_W = (/*BORDER_W * 2*/ + ASCII_W * STAT_CHARS_PER_LINE);
122 STAT_H = (3 * TILE_H);
123 STAT_H_MAX = (16 * TILE_H);
124
125 CONS_X = STAT_X;
126 CONS_Y = (FOOGOD_Y + FOOGOD_H + BORDER_H);
127 CONS_W = STAT_W;
128 CONS_H = (SCREEN_H - BORDER_H - CONS_Y);
129 CONS_LINES = (CONS_H / ASCII_H);
130
131 CONSOLE_MAX_MSG_SZ = (CONS_W / ASCII_W);
132
133 FOOGOD_X = STAT_X;
134 FOOGOD_Y = (STAT_Y + STAT_H + BORDER_H);
135 FOOGOD_W = STAT_W;
136 FOOGOD_H = (2 * ASCII_H);
137
138 WIND_W = (strlen("wind:northeast") * ASCII_W);
139 WIND_H = BORDER_H;
140 WIND_X = (BORDER_W + (MAP_W - WIND_W) / 2);
141 WIND_Y = (MAP_Y + MAP_H);
142
143 SKY_W = MOON_WINDOW_W;
144 SKY_H = BORDER_H;
145 SKY_X = (MAP_X + (MAP_W - SKY_W) / 2);
146 SKY_Y = 0;
147 SKY_SPRITE_W = (TILE_W/2);
148
149 SCREEN_W = (BORDER_W * 3 + MAP_W + CONS_W);
150
151 return 0;
152 }
153