2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * swap.c: Swap two sectors on the map
29 * Known contributors to this file:
31 * Markus Armbruster, 2006-2013
38 static void print_res(struct sctstr *);
41 * Syntax: swap <SECT> <SECT>
46 struct sctstr secta, sectb, tmp;
52 if (!(p = getstarg(player->argp[1], "First sector : ", buf)) ||
53 !sarg_xy(p, §a.sct_x, §a.sct_y) ||
54 !getsect(secta.sct_x, secta.sct_y, §a))
57 if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) ||
58 !sarg_xy(p, §b.sct_x, §b.sct_y) ||
59 !getsect(sectb.sct_x, sectb.sct_y, §b))
62 if (!confirm("Are you sure these are the two sectors you wish to swap? "))
64 if (!check_sect_ok(§a) || !check_sect_ok(§b))
66 for (i = 0; i <= (secta.sct_own != sectb.sct_own); i++) {
67 to = i == 0 ? secta.sct_own : sectb.sct_own;
68 if (to && to != player->cnum)
70 "Sector %s swapped with %s by an act of %s!\n",
71 xyas(secta.sct_x, secta.sct_y, to),
72 xyas(sectb.sct_x, sectb.sct_y, to),
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 ef_set_uid(EF_SECTOR, §a, sectb.sct_uid);
80 secta.sct_dist_x = sectb.sct_x;
81 secta.sct_dist_y = sectb.sct_y;
82 secta.sct_coastal = sectb.sct_coastal;
83 /* change the location of sectb to where secta was */
84 sectb.sct_x = tmp.sct_x;
85 sectb.sct_y = tmp.sct_y;
86 ef_set_uid(EF_SECTOR, §b, tmp.sct_uid);
87 sectb.sct_dist_x = tmp.sct_x;
88 sectb.sct_dist_y = tmp.sct_y;
89 sectb.sct_coastal = tmp.sct_coastal;
90 /* update coastal flag & put sectors */
92 set_coastal(§a, sectb.sct_type, secta.sct_type);
94 getsect(sectb.sct_x, sectb.sct_y, §b);
95 set_coastal(§b, secta.sct_type, sectb.sct_type);
102 print_res(struct sctstr *sp)
104 pr("own sect eff min gold fert oil uran\n");
106 pr("%3d ", sp->sct_own);
108 prxy("%4d,%-4d", sp->sct_x, sp->sct_y);
109 pr(" %c", dchr[sp->sct_type].d_mnem);
110 if (sp->sct_newtype != sp->sct_type)
111 pr("%c", dchr[sp->sct_newtype].d_mnem);
114 pr("%4d%%", sp->sct_effic);
115 pr(" %4d", sp->sct_min);
116 pr("%5d", sp->sct_gmin);
117 pr("%5d", sp->sct_fertil);
118 pr("%4d", sp->sct_oil);
119 pr("%5d", sp->sct_uran);