src/lib/commands/swap.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  swap.c: Swap two sectors on the map
00029  * 
00030  *  Known contributors to this file:
00031  *     Ken Stevens, 1995
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 
00038 static void print_res(struct sctstr *);
00039 
00040 /*
00041  * Syntax: swap <SECT> <SECT>
00042  */
00043 int
00044 swaps(void)
00045 {
00046     struct sctstr secta, sectb, tmp;
00047     char buf[1024];
00048     char *p;
00049 
00050     if (!(p = getstarg(player->argp[1], "First sector : ", buf)) ||
00051         !sarg_xy(p, &secta.sct_x, &secta.sct_y) ||
00052         !getsect(secta.sct_x, secta.sct_y, &secta))
00053         return RET_SYN;
00054     print_res(&secta);
00055     if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) ||
00056         !sarg_xy(p, &sectb.sct_x, &sectb.sct_y) ||
00057         !getsect(sectb.sct_x, sectb.sct_y, &sectb))
00058         return RET_SYN;
00059     print_res(&sectb);
00060     if (!confirm ("Are you sure these are the two sectors you wish to swap? "))
00061         return RET_FAIL;
00062     tmp = secta;
00063     /* change the location of secta to that of sectb */
00064     secta.sct_x = sectb.sct_x;
00065     secta.sct_y = sectb.sct_y;
00066     secta.sct_dist_x = sectb.sct_x;
00067     secta.sct_dist_y = sectb.sct_y;
00068     secta.sct_coastal = sectb.sct_coastal;
00069     /* change the location of sectb to where secta was */
00070     sectb.sct_x = tmp.sct_x;
00071     sectb.sct_y = tmp.sct_y;
00072     sectb.sct_dist_x = tmp.sct_x;
00073     sectb.sct_dist_y = tmp.sct_y;
00074     sectb.sct_coastal = tmp.sct_coastal;
00075     /* update coastal flag & put sectors */
00076     putsect(&sectb);
00077     set_coastal(&secta, sectb.sct_type, secta.sct_type);
00078     putsect(&secta);
00079     getsect(sectb.sct_x, sectb.sct_y, &sectb);
00080     set_coastal(&sectb, secta.sct_type, sectb.sct_type);
00081     putsect(&sectb);
00082     pr("done\n");
00083     return RET_OK;
00084 }
00085 
00086 static void
00087 print_res(struct sctstr *sp)
00088 {
00089     pr("own   sect        eff  min gold fert oil uran\n");
00090 
00091     pr("%3d ", sp->sct_own);
00092 
00093     prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum);
00094     pr(" %c", dchr[sp->sct_type].d_mnem);
00095     if (sp->sct_newtype != sp->sct_type)
00096         pr("%c", dchr[sp->sct_newtype].d_mnem);
00097     else
00098         pr(" ");
00099     pr("%4d%%", sp->sct_effic);
00100     pr(" %4d", sp->sct_min);
00101     pr("%5d", sp->sct_gmin);
00102     pr("%5d", sp->sct_fertil);
00103     pr("%4d", sp->sct_oil);
00104     pr("%5d", sp->sct_uran);
00105     pr("\n");
00106 }

Generated on Fri Mar 28 11:01:13 2008 for empserver by  doxygen 1.5.2