11
9
edit.c -- Routines to handle edit mode commands.
15
13
#include <string.h>
20
14
#include <curses.h>
22
16
#include "empire.h"
23
17
#include "extern.h"
25
void e_move(long *path_start, long loc);
26
extern int get_piece_name();
19
void e_move(loc_t *path_start, loc_t loc);
20
extern int get_piece_name(void);
23
edit(loc_t edit_cursor)
33
void e_leave(), e_print(), e_random();
34
void e_stasis(), e_end(), e_wake(), e_sleep();
35
void e_info(), e_prod(), e_help(), e_explore();
36
void e_fill(), e_land(), e_city_func(), e_transport();
37
void e_attack(), e_repair();
43
path_start = -1; /* not building a path yet */
45
for (;;) { /* until user gives command to leave */
46
display_loc_u (edit_cursor); /* position cursor */
47
e = e_cursor (&edit_cursor); /* handle cursor movement */
50
case 'B': /* change city production */
56
case 'G': /* explore */
57
e_explore (edit_cursor);
62
case 'I': /* directional stasis */
63
e_stasis (edit_cursor);
65
case 'K': /* wake up anything and everything */
68
case 'L': /* land plane */
71
case 'M': /* start move to location */
73
e_move (&path_start, edit_cursor);
75
case 'N': /* end move to location */
76
e_end (&path_start, edit_cursor, path_type);
78
case 'O': /* leave display mode */
81
case 'P': /* print new sector */
82
e_print (&edit_cursor);
84
case 'R': /* make piece move randomly */
85
e_random (edit_cursor);
88
e_sleep (edit_cursor);
90
case 'T': /* transport army */
91
e_transport (edit_cursor);
93
case 'U': /* repair ship */
94
e_repair (edit_cursor);
96
case 'V': /* set city function */
97
e_city_func (&path_start, edit_cursor, &path_type);
99
case 'Y': /* set army func to attack */
100
e_attack (edit_cursor);
102
case '?': /* request info */
103
e_info (edit_cursor);
105
case '\014': /* control-L */
108
default: /* bad command? */
26
void e_leave(), e_print(), e_random();
27
void e_stasis(), e_end(), e_wake(), e_sleep();
28
void e_info(), e_prod(), e_help(), e_explore();
29
void e_fill(), e_land(), e_city_func(), e_transport();
30
void e_attack(), e_repair();
36
path_start = -1; /* not building a path yet */
38
for (;;) { /* until user gives command to leave */
39
display_loc_u (edit_cursor); /* position cursor */
40
e = e_cursor (&edit_cursor); /* handle cursor movement */
43
case 'B': /* change city production */
49
case 'G': /* explore */
50
e_explore (edit_cursor);
55
case 'I': /* directional stasis */
56
e_stasis (edit_cursor);
58
case 'K': /* wake up anything and everything */
61
case 'L': /* land plane */
64
case 'M': /* start move to location */
66
e_move (&path_start, edit_cursor);
68
case 'N': /* end move to location */
69
e_end (&path_start, edit_cursor, path_type);
71
case 'O': /* leave display mode */
74
case 'P': /* print new sector */
75
e_print (&edit_cursor);
77
case 'R': /* make piece move randomly */
78
e_random (edit_cursor);
81
e_sleep (edit_cursor);
83
case 'T': /* transport army */
84
e_transport (edit_cursor);
86
case 'U': /* repair ship */
87
e_repair (edit_cursor);
89
case 'V': /* set city function */
90
e_city_func (&path_start, edit_cursor, &path_type);
92
case 'Y': /* set army func to attack */
93
e_attack (edit_cursor);
95
case '?': /* request info */
98
case '\014': /* control-L */
101
default: /* bad command? */
181
e_set_func (loc, func)
170
e_set_func(loc_t loc, long func)
186
obj = find_obj_at_loc (loc);
187
if (obj != NULL && obj->owner == USER) {
191
huh (); /* no object here */
173
obj = find_obj_at_loc (loc);
174
if (obj != NULL && obj->owner == USER) {
178
huh (); /* no object here */
194
181
/* Set the function of a city for some piece. */
197
e_set_city_func (cityp, type, func)
184
e_set_city_func(city_info_t *cityp, int type, long func)
202
cityp->func[type] = func;
186
cityp->func[type] = func;
341
309
static char dirs[] = "WEDCXZAQ";
350
if (!isupper (user_map[loc].contents)) huh (); /* no object here */
351
else if (user_map[loc].contents == 'X') huh ();
353
e = get_chx(); /* get a direction */
354
p = strchr (dirs, e);
314
if (!isupper (user_map[loc].contents))
315
huh (); /* no object here */
316
else if (user_map[loc].contents == 'X')
319
char e = get_chx(); /* get a direction */
320
char *p = strchr (dirs, e);
356
if (p == NULL) huh ();
357
else e_set_func (loc, (long)(MOVE_N - (p - dirs)));
325
e_set_func (loc, (long)(MOVE_N - (p - dirs)));
362
e_city_stasis (cityp, type)
330
e_city_stasis(city_info_t *cityp, int type)
369
e = get_chx(); /* get a direction */
370
p = strchr (dirs, e);
335
e = get_chx(); /* get a direction */
336
p = strchr (dirs, e);
372
if (p == NULL) huh ();
373
else e_set_city_func (cityp, type, (long)(MOVE_N - (p - dirs)));
341
e_set_city_func (cityp, type, (long)(MOVE_N - (p - dirs)));
411
e_city_func (path_start, loc, path_type)
376
e_city_func(loc_t *path_start, loc_t loc, int *path_type)
420
cityp = find_city (loc);
421
if (!cityp || cityp->owner != USER) {
426
type = get_piece_name();
427
if (type == NOPIECE) {
436
e_city_fill (cityp, type);
438
case 'G': /* explore */
439
e_city_explore (cityp, type);
441
case 'I': /* directional stasis */
442
e_city_stasis (cityp, type);
444
case 'K': /* turn off function */
445
e_city_wake (cityp, type);
447
case 'M': /* start move to location */
449
e_move (path_start, loc);
451
case 'R': /* make piece move randomly */
452
e_city_random (cityp, type);
454
case 'U': /* repair ship */
455
e_city_repair (cityp, type);
457
case 'Y': /* set army func to attack */
458
e_city_attack (cityp, type);
460
default: /* bad command? */
382
cityp = find_city (loc);
383
if (!cityp || cityp->owner != USER) {
388
type = get_piece_name();
389
if (type == NOPIECE) {
398
e_city_fill (cityp, type);
400
case 'G': /* explore */
401
e_city_explore (cityp, type);
403
case 'I': /* directional stasis */
404
e_city_stasis (cityp, type);
406
case 'K': /* turn off function */
407
e_city_wake (cityp, type);
409
case 'M': /* start move to location */
411
e_move (path_start, loc);
413
case 'R': /* make piece move randomly */
414
e_city_random (cityp, type);
416
case 'U': /* repair ship */
417
e_city_repair (cityp, type);
419
case 'Y': /* set army func to attack */
420
e_city_attack (cityp, type);
422
default: /* bad command? */
485
e_end (path_start, loc, path_type)
492
if (*path_start == -1) huh (); /* no path started? */
493
else if (path_type == NOPIECE) e_set_func (*path_start, loc);
495
cityp = find_city (*path_start);
497
e_set_city_func (cityp, path_type, loc);
445
e_end(loc_t *path_start, loc_t loc, int path_type)
447
if (*path_start == -1)
448
huh (); /* no path started? */
449
else if (path_type == NOPIECE)
450
e_set_func (*path_start, loc);
452
city_info_t *cityp = find_city (*path_start);
454
e_set_city_func (cityp, path_type, loc);
500
*path_start = -1; /* remember no path in progress */
457
*path_start = -1; /* remember no path in progress */
476
e_info(loc_t edit_cursor)
523
void e_city_info(), e_piece_info();
527
ab = user_map[edit_cursor].contents;
529
if (ab == 'O') e_city_info (edit_cursor);
530
else if (ab == 'X' && debug) e_city_info (edit_cursor);
531
else if ((ab >= 'A') && (ab <= 'T'))
532
e_piece_info (edit_cursor, ab);
533
else if ((ab >= 'a') && (ab <= 't') && (debug))
534
e_piece_info (edit_cursor, ab);
478
void e_city_info(loc_t), e_piece_info(loc_t edit_cursor, char ab);
482
ab = user_map[edit_cursor].contents;
485
e_city_info (edit_cursor);
486
else if (ab == 'X' && debug)
487
e_city_info (edit_cursor);
488
else if ((ab >= 'A') && (ab <= 'T'))
489
e_piece_info (edit_cursor, ab);
490
else if ((ab >= 'a') && (ab <= 't') && (debug))
491
e_piece_info (edit_cursor, ab);
565
e_city_info (edit_cursor)
521
e_city_info(loc_t edit_cursor)
571
char func_buf[STRSIZE];
572
char temp_buf[STRSIZE];
573
char junk_buf2[STRSIZE];
575
error (0,0,0,0,0,0,0,0,0); /* clear line */
577
f = 0; /* no fighters counted yet */
578
for (obj = map[edit_cursor].objp; obj != NULL;
579
obj = obj->loc_link.next)
580
if (obj->type == FIGHTER) f++;
582
s = 0; /* no ships counted yet */
583
for (obj = map[edit_cursor].objp; obj != NULL;
584
obj = obj->loc_link.next)
585
if (obj->type >= DESTROYER) s++;
587
if (f == 1 && s == 1)
588
(void) sprintf (jnkbuf, "1 fighter landed, 1 ship docked");
590
(void) sprintf (jnkbuf, "1 fighter landed, %d ships docked", s);
592
(void) sprintf (jnkbuf, "%d fighters landed, 1 ship docked", f);
593
else (void) sprintf (jnkbuf, "%d fighters landed, %d ships docked", f, s);
595
cityp = find_city (edit_cursor);
596
ASSERT (cityp != NULL);
598
*func_buf = 0; /* nothing in buffer */
599
for (s = 0; s < NUM_OBJECTS; s++) { /* for each piece */
600
if (cityp->func[s] < 0)
601
(void) sprintf (temp_buf, "%c:%s; ",
603
func_name[FUNCI(cityp->func[s])]);
604
else (void) sprintf (temp_buf, "%c: %ld;",
526
char func_buf[STRSIZE];
527
char temp_buf[STRSIZE];
528
char junk_buf2[STRSIZE];
530
error (""); /* clear line */
532
f = 0; /* no fighters counted yet */
533
for (obj = map[edit_cursor].objp; obj != NULL;
534
obj = obj->loc_link.next)
535
if (obj->type == FIGHTER) f++;
537
s = 0; /* no ships counted yet */
538
for (obj = map[edit_cursor].objp; obj != NULL;
539
obj = obj->loc_link.next)
540
if (obj->type >= DESTROYER) s++;
542
if (f == 1 && s == 1)
543
(void) sprintf (jnkbuf, "1 fighter landed, 1 ship docked");
545
(void) sprintf (jnkbuf, "1 fighter landed, %d ships docked", s);
547
(void) sprintf (jnkbuf, "%d fighters landed, 1 ship docked", f);
549
(void) sprintf (jnkbuf, "%d fighters landed, %d ships docked", f, s);
551
cityp = find_city (edit_cursor);
552
ASSERT (cityp != NULL);
554
*func_buf = 0; /* nothing in buffer */
555
for (s = 0; s < NUM_OBJECTS; s++) { /* for each piece */
556
if (cityp->func[s] < 0)
557
(void) sprintf (temp_buf, "%c:%s; ",
559
func_name[FUNCI(cityp->func[s])]);
560
else (void) sprintf (temp_buf, "%c: %d;",
562
loc_disp(cityp->func[s]));
608
(void) strcat (func_buf, temp_buf);
611
(void) sprintf (junk_buf2,
612
"City at location %ld will complete %s on round %ld",
614
piece_attr[(int)cityp->prod].article,
615
date + piece_attr[(int)cityp->prod].build_time - cityp->work);
617
info (junk_buf2, jnkbuf, func_buf);
564
(void) strcat (func_buf, temp_buf);
567
(void) sprintf (junk_buf2,
568
"City at location %d will complete %s on round %ld",
569
loc_disp(cityp->loc),
570
piece_attr[(int)cityp->prod].article,
571
date + piece_attr[(int)cityp->prod].build_time - cityp->work);
573
info (junk_buf2, jnkbuf, func_buf);