File: main.c

package info (click to toggle)
empire 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 460 kB
  • ctags: 558
  • sloc: ansic: 5,304; xml: 1,009; makefile: 92
file content (108 lines) | stat: -rw-r--r-- 2,363 bytes parent folder | download | duplicates (3)
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
/*
 *    Copyright (C) 1987, 1988 Chuck Simmons
 * 
 * See the file COPYING, distributed with empire, for restriction
 * and warranty information.
 */

/*
main.c -- parse command line for empire

options:

    -w water: percentage of map that is water.  Must be in the range
              10..90.  Default is 70.
	      
    -s smooth: amount of smoothing performed to generate map.  Must
	       be a nonnegative integer.  Default is 5.
	       
    -d delay:  number of milliseconds to delay between output.
               default is 2000 (2 seconds).

    -S saveinterval: sets turn interval between saves.
	       default is 10
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "empire.h"
#include "extern.h"

#define OPTFLAGS "w:s:d:S:f:"

int main(argc, argv)
int argc;
char *argv[];
{
    int c;
    extern char *optarg;
    extern int optind;
    int errflg = 0;
    int wflg, sflg, dflg, Sflg;
    int land;
	
    wflg = 70; /* set defaults */
    sflg = 5;
    dflg = 2000;
    Sflg = 10;
    savefile = "empsave.dat";

    /*
     * extract command line options
     */

    while ((c = getopt (argc, argv, OPTFLAGS)) != EOF) {
	switch (c) {
	case 'w':
	    wflg = atoi (optarg);
	    break;
	case 's':
	    sflg = atoi (optarg);
	    break;
	case 'd':
	    dflg = atoi (optarg);
	    break;
	case 'S':
	    Sflg = atoi (optarg);
	    break;
	case 'f':
	    savefile = optarg;
	    break;
	case '?': /* illegal option? */
	    errflg++;
	    break;
	}
    }
    if (errflg || (argc-optind) != 0) {
	(void) printf ("empire: usage: empire [-w water] [-s smooth] [-d delay]\n");
	exit (1);
    }

    if (wflg < 10 || wflg > 90) {
	(void) printf ("empire: -w argument must be in the range 0..90.\n");
	exit (1);
    }
    if (sflg < 0) {
	(void) printf ("empire: -s argument must be greater or equal to zero.\n");
	exit (1);
    }
	
    if (dflg < 0 || dflg > 30000) {
	(void) printf ("empire: -d argument must be in the range 0..30000.\n");
	exit (1);
    }

    SMOOTH = sflg;
    WATER_RATIO = wflg;
    delay_time = dflg;
    save_interval = Sflg;

    /* compute min distance between cities */
    land = MAP_SIZE * (100 - WATER_RATIO) / 100; /* available land */
    land /= NUM_CITY; /* land per city */
    MIN_CITY_DIST = isqrt (land); /* distance between cities */

    empire (); /* call main routine */
    return (0);
}