]> git.pond.sub.org Git - empserver/blob - src/lib/commands/swap.c
Update copyright notice.
[empserver] / src / lib / commands / swap.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  swap.c: Swap two sectors on the map
29  * 
30  *  Known contributors to this file:
31  *     Ken Stevens, 1995
32  */
33
34 #include <config.h>
35
36 #include <ctype.h>
37 #include "commands.h"
38
39 static void print_res(struct sctstr *);
40
41 /*
42  * Syntax: swap <SECT> <SECT>
43  */
44 int
45 swaps(void)
46 {
47     struct sctstr secta, sectb, tmp;
48     char buf[1024];
49     char *p;
50
51     if (!(p = getstarg(player->argp[1], "First sector : ", buf)) ||
52         !sarg_xy(p, &secta.sct_x, &secta.sct_y) ||
53         !getsect(secta.sct_x, secta.sct_y, &secta))
54         return RET_SYN;
55     print_res(&secta);
56     if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) ||
57         !sarg_xy(p, &sectb.sct_x, &sectb.sct_y) ||
58         !getsect(sectb.sct_x, sectb.sct_y, &sectb))
59         return RET_SYN;
60     print_res(&sectb);
61     if (!confirm ("Are you sure these are the two sectors you wish to swap? "))
62         return RET_FAIL;
63     tmp = secta;
64     /* change the location of secta to that of sectb */
65     secta.sct_x = sectb.sct_x;
66     secta.sct_y = sectb.sct_y;
67     secta.sct_dist_x = sectb.sct_x;
68     secta.sct_dist_y = sectb.sct_y;
69     secta.sct_coastal = sectb.sct_coastal;
70     /* change the location of sectb to where secta was */
71     sectb.sct_x = tmp.sct_x;
72     sectb.sct_y = tmp.sct_y;
73     sectb.sct_dist_x = tmp.sct_x;
74     sectb.sct_dist_y = tmp.sct_y;
75     sectb.sct_coastal = tmp.sct_coastal;
76     /* update coastal flag & put sectors */
77     putsect(&sectb);
78     set_coastal(&secta, sectb.sct_type, secta.sct_type);
79     putsect(&secta);
80     getsect(sectb.sct_x, sectb.sct_y, &sectb);
81     set_coastal(&sectb, secta.sct_type, sectb.sct_type);
82     putsect(&sectb);
83     pr("done\n");
84     return RET_OK;
85 }
86
87 static void
88 print_res(struct sctstr *sp)
89 {
90     pr("own   sect        eff  min gold fert oil uran\n");
91
92     pr("%3d ", sp->sct_own);
93
94     prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
95     pr(" %c", dchr[sp->sct_type].d_mnem);
96     if (sp->sct_newtype != sp->sct_type)
97         pr("%c", dchr[sp->sct_newtype].d_mnem);
98     else
99         pr(" ");
100     pr("%4d%%", sp->sct_effic);
101     pr(" %4d", sp->sct_min);
102     pr("%5d", sp->sct_gmin);
103     pr("%5d", sp->sct_fertil);
104     pr("%4d", sp->sct_oil);
105     pr("%5d", sp->sct_uran);
106     pr("\n");
107 }