]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/swap.c
Update copyright notice
[empserver] / src / lib / commands / swap.c
index d8499d75876d816e8c0010406175c42e48623f5b..e8c9d854e9c61e4004b0a82699e4963c86c59cac 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  swap.c: Swap two sectors on the map
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  */
 
 #include <config.h>
 
-#include <stdio.h>
-#include <ctype.h>
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nat.h"
-#include "nsc.h"
-#include "file.h"
 #include "commands.h"
 
 static void print_res(struct sctstr *);
@@ -52,10 +43,9 @@ static void print_res(struct sctstr *);
 int
 swaps(void)
 {
-    struct sctstr secta, sectb;
-    coord x, y;
-    s_char buf[1024];
-    s_char *p;
+    struct sctstr secta, sectb, tmp;
+    char buf[1024];
+    char *p;
 
     if (!(p = getstarg(player->argp[1], "First sector : ", buf)) ||
        !sarg_xy(p, &secta.sct_x, &secta.sct_y) ||
@@ -69,20 +59,27 @@ swaps(void)
     print_res(&sectb);
     if (!confirm ("Are you sure these are the two sectors you wish to swap? "))
        return RET_FAIL;
-    /* save x and y from secta */
-    x = secta.sct_x;
-    y = secta.sct_y;
+    tmp = secta;
     /* change the location of secta to that of sectb */
     secta.sct_x = sectb.sct_x;
     secta.sct_y = sectb.sct_y;
+    ef_set_uid(EF_SECTOR, &secta, sectb.sct_uid);
     secta.sct_dist_x = sectb.sct_x;
     secta.sct_dist_y = sectb.sct_y;
+    secta.sct_coastal = sectb.sct_coastal;
     /* change the location of sectb to where secta was */
-    sectb.sct_x = x;
-    sectb.sct_y = y;
-    sectb.sct_dist_x = x;
-    sectb.sct_dist_y = y;
+    sectb.sct_x = tmp.sct_x;
+    sectb.sct_y = tmp.sct_y;
+    ef_set_uid(EF_SECTOR, &sectb, tmp.sct_uid);
+    sectb.sct_dist_x = tmp.sct_x;
+    sectb.sct_dist_y = tmp.sct_y;
+    sectb.sct_coastal = tmp.sct_coastal;
+    /* update coastal flag & put sectors */
+    putsect(&sectb);
+    set_coastal(&secta, sectb.sct_type, secta.sct_type);
     putsect(&secta);
+    getsect(sectb.sct_x, sectb.sct_y, &sectb);
+    set_coastal(&sectb, secta.sct_type, sectb.sct_type);
     putsect(&sectb);
     pr("done\n");
     return RET_OK;