1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
/* $Id: empire.c,v 1.1.1.1 2000/10/04 02:28:49 weasel Exp $ - (c) Copyright 1987, 1988 Chuck Simmons */
/*
* Copyright (C) 1987, 1988 Chuck Simmons
*
* See the file COPYING, distributed with empire, for restriction
* and warranty information.
*/
/*
empire.c -- this file contains initialization code, the main command
parser, and the simple commands.
*/
#include <stdio.h>
#include <curses.h>
#include "empire.h"
#include "extern.h"
void c_examine(), c_movie();
void
empire () {
void do_command();
void print_zoom();
char order;
int turn = 0;
ttinit (); /* init tty */
rndini (); /* init random number generator */
clear_screen (); /* nothing on screen */
(void) move (7, 0);
ver ();
pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0);
(void) refresh ();
if (!restore_game ()) /* try to restore previous game */
init_game (); /* otherwise init a new game */
/* Command loop starts here. */
for (;;) { /* until user quits */
if (automove) { /* don't ask for cmd in auto mode */
user_move ();
comp_move (1);
if (++turn % save_interval == 0)
save_game ();
}
else {
prompt (0,0,0,0,0,0,0,0,0); /* blank top line */
(void) refresh ();
prompt ("Your orders? ",0,0,0,0,0,0,0,0);
order = get_chx (); /* get a command */
do_command (order);
}
}
}
/*
Execute a command.
*/
void
do_command (orders)
char orders;
{
void c_debug(), c_quit(), c_sector(), c_map();
void c_give();
char e;
int ncycle;
switch (orders) {
case 'A': /* turn on auto move mode */
automove = TRUE;
error ("Now in Auto-Mode",0,0,0,0,0,0,0,0);
user_move ();
comp_move (1);
save_game ();
break;
case 'C': /* give a city to the computer */
c_give ();
break;
case 'D': /* display round number */
error ("Round #%d", date,0,0,0,0,0,0,0);
break;
case 'E': /* examine enemy map */
if (resigned) c_examine ();
else huh (); /* illegal command */
break;
case 'F': /* print map to file */
c_map ();
break;
case 'G': /* give one free enemy move */
comp_move (1);
break;
case 'H': /* help */
help (help_cmd, cmd_lines);
break;
case 'J': /* edit mode */
ncycle = cur_sector ();
if (ncycle == -1) ncycle = 0;
edit (sector_loc (ncycle));
break;
case 'M': /* move */
user_move ();
comp_move (1);
save_game ();
break;
case 'N': /* give enemy free moves */
ncycle = getint ("Number of free enemy moves: ");
comp_move (ncycle);
save_game ();
break;
case 'P': /* print a sector */
c_sector ();
break;
case '\026': /* some interrupt */
case 'Q': /* quit */
c_quit ();
break;
case 'R': /* restore game */
clear_screen ();
e = restore_game ();
break;
case 'S': /* save game */
save_game ();
break;
case 'T': /* trace: toggle save_movie flag */
save_movie = !save_movie;
if (save_movie) comment ("Saving movie screens to 'empmovie.dat'.",0,0,0,0,0,0,0,0);
else comment ("No longer saving movie screens.",0,0,0,0,0,0,0,0);
break;
case 'W': /* watch movie */
if (resigned || debug) replay_movie ();
else error ("You cannot watch movie until computer resigns.",0,0,0,0,0,0,0,0);
break;
case 'Z': /* print compressed map */
(void) clear ();
print_zoom (user_map);
(void) refresh ();
break;
case '\014': /* redraw the screen */
redraw ();
break;
case '+': /* change debug state */
e = get_chx();
if ( e == '+' ) debug = TRUE;
else if ( e == '-' ) debug = FALSE;
else huh ();
break;
default:
if (debug) c_debug (orders); /* debug */
else huh (); /* illegal command */
break;
}
e = e; /* keep lint quiet */
}
/*
Give an unowned city (if any) to the computer. We make
a list of unowned cities, choose one at random, and mark
it as the computers.
*/
void
c_give () {
int unowned[NUM_CITY];
long i, count;
count = 0; /* nothing in list yet */
for (i = 0; i < NUM_CITY; i++) {
if (city[i].owner == UNOWNED) {
unowned[count] = i; /* remember this city */
count += 1;
}
}
if (count == 0) {
error ("There are no unowned cities.",0,0,0,0,0,0,0,0);
ksend ("There are no unowned cities.",0,0,0,0,0,0,0,0);
return;
}
i = irand (count);
i = unowned[i]; /* get city index */
city[i].owner = COMP;
city[i].prod = NOPIECE;
city[i].work = 0;
scan (comp_map, city[i].loc);
}
/*
Debugging commands should be implemented here.
The order cannot be any legal command.
*/
void
c_debug (order)
char order;
{
char e;
switch (order) {
case '#' : c_examine (); break;
case '%' : c_movie (); break;
case '@': /* change trace state */
e = get_chx();
if ( e == '+' ) trace_pmap = TRUE;
else if ( e == '-' ) trace_pmap = FALSE;
else huh ();
break;
case '$': /* change print_debug state */
e = get_chx();
if ( e == '+' ) print_debug = TRUE;
else if ( e == '-' ) print_debug = FALSE;
else huh ();
break;
case '&': /* change print_vmap state */
print_vmap = get_chx();
break;
default: huh (); break;
}
}
/*
The quit command. Make sure the user really wants to quit.
*/
void
c_quit () {
if (getyn ("QUIT - Are you sure? ")) {
empend ();
}
}
/*
Print a sector. Read the sector number from the user
and print it.
*/
void
c_sector () {
int num;
num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
print_sector_u (num);
}
/*
Print the map to a file. We ask for a filename, attempt to open the
file, and if successful, print out the user's information to the file.
We print the map sideways to make it easier for the user to print
out the map.
*/
void
c_map () {
FILE *f;
int i, j;
char line[MAP_HEIGHT+2];
prompt ("Filename? ",0,0,0,0,0,0,0,0);
get_str (jnkbuf, STRSIZE);
f = fopen (jnkbuf, "w");
if (f == NULL) {
error ("I can't open that file.",0,0,0,0,0,0,0,0);
return;
}
for (i = 0; i < MAP_WIDTH; i++) { /* for each column */
for (j = MAP_HEIGHT-1; j >= 0; j--) { /* for each row */
line[MAP_HEIGHT-1-j] = user_map[row_col_loc(j,i)].contents;
}
j = MAP_HEIGHT-1;
while (j >= 0 && line[j] == ' ') /* scan off trailing blanks */
j -= 1;
line[++j] = '\n';
line[++j] = 0; /* trailing null */
(void) fputs (line, f);
}
(void) fclose (f);
}
/*
Allow user to examine the computer's map.
*/
void
c_examine () {
int num;
num = get_range ("Sector number? ", 0, NUM_SECTORS-1);
print_sector_c (num);
}
/*
We give the computer lots of free moves and
Print a "zoomed" version of the computer's map.
*/
void
c_movie () {
(void) clear ();
for (;;) {
comp_move (1);
print_zoom (comp_map);
save_game ();
#ifdef PROFILE
if (date == 125) empend();
#endif
}
}
|