2 * Copyright (C) 1987, 1988 Chuck Simmons
4 * See the file COPYING, distributed with empire, for restriction
5 * and warranty information.
9 empire.c -- this file contains initialization code, the main command
10 parser, and the simple commands.
17 void c_examine(void), c_movie(void);
20 * 03a 01Apr88 aml .Hacked movement algorithms for computer.
21 * 02b 01Jun87 aml .First round of bug fixes.
22 * 02a 01Jan87 aml .Translated to C.
23 * 01b 27May85 cal .Fixed round number update bug. Made truename simple.
24 * 01a 01Sep83 cal .Taken from a Decus tape
30 void do_command(char);
31 void print_zoom(view_map_t *);
36 ttinit (); /* init tty */
37 rndini (); /* init random number generator */
39 clear_screen (); /* nothing on screen */
40 pos_str (7, 0, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988");
41 pos_str (8, 0, "詳細はEMPIRE.DOCを読むこと。\n");
44 if (!restore_game ()) /* try to restore previous game */
45 init_game (); /* otherwise init a new game */
47 /* Command loop starts here. */
49 for (;;) { /* until user quits */
50 if (automove) { /* don't ask for cmd in auto mode */
53 if (++turn % save_interval == 0)
57 prompt (""); /* blank top line */
60 order = get_chx (); /* get a command */
71 do_command(char orders)
73 void c_debug(char order), c_quit(void), c_sector(void), c_map(void);
80 case 'A': /* turn on auto move mode */
82 error ("オートモードに移行した。");
88 case 'C': /* give a city to the computer */
92 case 'D': /* display round number */
93 error ("ラウンド #%d", date);
96 case 'E': /* examine enemy map */
97 if (resigned) c_examine ();
98 else huh (); /* illegal command */
101 case 'F': /* print map to file */
105 case 'G': /* give one free enemy move */
110 help (help_cmd, cmd_lines);
113 case 'J': /* edit mode */
114 ncycle = cur_sector ();
115 if (ncycle == -1) ncycle = 0;
116 edit (sector_loc (ncycle));
125 case 'N': /* give enemy free moves */
126 ncycle = getint ("敵が行動するターン数: ");
131 case 'P': /* print a sector */
135 case '\026': /* some interrupt */
140 case 'R': /* restore game */
145 case 'S': /* save game */
149 case 'T': /* trace: toggle save_movie flag */
150 save_movie = !save_movie;
151 if (save_movie) comment ("画面の'empmovie.dat'への保存を開始する。");
152 else comment ("画面は保存されない。");
155 case 'W': /* watch movie */
156 if (resigned || debug) replay_movie ();
157 else error ("コンピュータが降伏するまでは観戦できない。");
160 case 'Z': /* print compressed map */
161 print_zoom (user_map);
164 case '\014': /* redraw the screen */
168 case '+': /* change debug state */
179 c_debug (orders); /* debug */
181 huh (); /* illegal command */
187 Give an unowned city (if any) to the computer. We make
188 a list of unowned cities, choose one at random, and mark
195 int unowned[NUM_CITY];
198 count = 0; /* nothing in list yet */
199 for (i = 0; i < NUM_CITY; i++) {
200 if (city[i].owner == UNOWNED) {
201 unowned[count] = i; /* remember this city */
206 error ("あなたの都市がない。");
207 ksend ("あなたの都市がない。");
211 i = unowned[i]; /* get city index */
212 city[i].owner = COMP;
213 city[i].prod = NOPIECE;
215 scan (comp_map, city[i].loc);
219 Debugging commands should be implemented here.
220 The order cannot be any legal command.
229 case '#' : c_examine (); break;
230 case '%' : c_movie (); break;
232 case '@': /* change trace state */
242 case '$': /* change print_debug state */
252 case '&': /* change print_vmap state */
253 print_vmap = get_chx();
256 default: huh (); break;
261 The quit command. Make sure the user really wants to quit.
267 if (getyn ("終了 - 本当によいか? ")) {
273 Print a sector. Read the sector number from the user
282 num = get_range ("セクター番号は? ", 0, NUM_SECTORS-1);
283 print_sector_u (num);
287 Print the map to a file. We ask for a filename, attempt to open the
288 file, and if successful, print out the user's information to the file.
289 We print the map sideways to make it easier for the user to print
298 char line[MAP_HEIGHT+2];
301 get_str (jnkbuf, STRSIZE);
303 f = fopen (jnkbuf, "w");
305 error ("ファイルをオープンできなかった。");
308 for (i = 0; i < MAP_WIDTH; i++) { /* for each column */
309 for (j = MAP_HEIGHT-1; j >= 0; j--) { /* for each row */
310 line[MAP_HEIGHT-1-j] = user_map[row_col_loc(j,i)].contents;
313 while (j >= 0 && line[j] == ' ') /* scan off trailing blanks */
317 line[++j] = 0; /* trailing null */
318 (void) fputs (line, f);
324 Allow user to examine the computer's map.
332 num = get_range ("セクター番号は? ", 0, NUM_SECTORS-1);
333 print_sector_c (num);
337 We give the computer lots of free moves and
338 Print a "zoomed" version of the computer's map.
346 print_zoom (comp_map);
349 if (date == 125) empend();