]> 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-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 <stdio.h>
35 #include <ctype.h>
36 #include "misc.h"
37 #include "player.h"
38 #include "var.h"
39 #include "xy.h"
40 #include "sect.h"
41 #include "nat.h"
42 #include "news.h"
43 #include "nsc.h"
44 #include "item.h"
45 #include "file.h"
46 #include "commands.h"
47
48 static void print_res(struct sctstr *);
49
50 /*
51  * Syntax: swap <SECT> <SECT>
52  */
53 int
54 swaps(void)
55 {
56     struct sctstr secta, sectb;
57     coord x, y;
58     s_char buf[1024];
59     s_char *p;
60
61     if (!(p = getstarg(player->argp[1], "First sector : ", buf)) ||
62         !sarg_xy(p, &secta.sct_x, &secta.sct_y) ||
63         !getsect(secta.sct_x, secta.sct_y, &secta))
64         return RET_SYN;
65     print_res(&secta);
66     if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) ||
67         !sarg_xy(p, &sectb.sct_x, &sectb.sct_y) ||
68         !getsect(sectb.sct_x, sectb.sct_y, &sectb))
69         return RET_SYN;
70     print_res(&sectb);
71     if (!confirm ("Are you sure these are the two sectors you wish to swap? "))
72         return RET_FAIL;
73     /* save x and y from secta */
74     x = secta.sct_x;
75     y = secta.sct_y;
76     /* change the location of secta to that of sectb */
77     secta.sct_x = sectb.sct_x;
78     secta.sct_y = sectb.sct_y;
79     secta.sct_dist_x = sectb.sct_x;
80     secta.sct_dist_y = sectb.sct_y;
81     /* change the location of sectb to where secta was */
82     sectb.sct_x = x;
83     sectb.sct_y = y;
84     sectb.sct_dist_x = x;
85     sectb.sct_dist_y = y;
86     putsect(&secta);
87     putsect(&sectb);
88     pr("done\n");
89     return RET_OK;
90 }
91
92 static void
93 print_res(struct sctstr *sp)
94 {
95     pr("own   sect        eff  min gold fert oil uran\n");
96
97     pr("%3d ", sp->sct_own);
98
99     prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
100     pr(" %c", dchr[sp->sct_type].d_mnem);
101     if (sp->sct_newtype != sp->sct_type)
102         pr("%c", dchr[sp->sct_newtype].d_mnem);
103     else
104         pr(" ");
105     pr("%4d%%", sp->sct_effic);
106     pr(" %4d", sp->sct_min);
107     pr("%5d", sp->sct_gmin);
108     pr("%5d", sp->sct_fertil);
109     pr("%4d", sp->sct_oil);
110     pr("%5d", sp->sct_uran);
111     pr("\n");
112 }