]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/unitsub.c
Update copyright notice
[empserver] / src / lib / subs / unitsub.c
index 283425a93d4d93d70f6fe63170633a2fed11bda4..a3e537bde4c0323f7608b520da6baeda31a9435b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2007
- *     Markus Armbruster, 2009-2011
+ *     Markus Armbruster, 2009-2013
  */
 
 #include <config.h>
@@ -77,7 +77,7 @@ unit_list(struct emp_qelem *unit_list)
        return;
 
     if (type == EF_LAND)
-       pr("lnd#     land type       x,y    a  eff  sh gun xl  mu tech retr\n");
+       pr("lnd#     land type       x,y    a  eff mil  sh gun xl ln  mu tech retr\n");
     else
        pr("shp#     ship type       x,y   fl  eff mil  sh gun pn he xl ln mob tech\n");
 
@@ -95,9 +95,10 @@ unit_list(struct emp_qelem *unit_list)
        pr("%1.1s", &unit->group);
        pr("%4d%%", unit->effic);
        if (type == EF_LAND) {
+           pr("%4d", lnd->lnd_item[I_MILIT]);
            pr("%4d", lnd->lnd_item[I_SHELL]);
            pr("%4d", lnd->lnd_item[I_GUN]);
-           pr("%3d", lnd_nxlight(lnd));
+           pr("%3d%3d", lnd_nxlight(lnd), lnd_nland(lnd));
        } else {
            pr("%4d", shp->shp_item[I_MILIT]);
            pr("%4d", shp->shp_item[I_SHELL]);
@@ -150,7 +151,7 @@ unit_put(struct emp_qelem *list, natid actor)
 }
 
 char *
-unit_path(int together, struct empobj *unit, char *buf)
+unit_path(int together, struct empobj *unit, char *buf, size_t bufsz)
 {
     coord destx;
     coord desty;
@@ -195,13 +196,13 @@ unit_path(int together, struct empobj *unit, char *buf)
            return NULL;
        }
     }
-    len = path_find_route(buf, sizeof(buf), unit->x, unit->y, destx, desty);
+    len = path_find_route(buf, bufsz, unit->x, unit->y, destx, desty);
     if (len == 0 || unit->ef_type == EF_LAND) {
-       if (len + 1 < sizeof(buf))
+       if (len + 1 < bufsz)
            strcpy(buf + len, "h");
        len++;
     }
-    if (len >= sizeof(buf)) {
+    if (len >= bufsz) {
        pr("Can't handle path to %s, it's too long, sorry\n",
           xyas(destx, desty, player->cnum));
        return NULL;
@@ -237,6 +238,21 @@ unit_view(struct emp_qelem *list)
     }
 }
 
+/*
+ * Teleport UNIT to X,Y.
+ * If UNIT's mission op-area is centered on it, keep it centered.
+ */
+void
+unit_teleport(struct empobj *unit, coord x, coord y)
+{
+    if (unit->opx == unit->x && unit->opy == unit->y) {
+       unit->opx = x;
+       unit->opy = y;
+    }
+    unit->x = x;
+    unit->y = y;
+}
+
 /*
  * Update cargo of CARRIER for movement or destruction.
  * If the carrier is destroyed, destroy its cargo (planes, land units,
@@ -256,17 +272,11 @@ unit_update_cargo(struct empobj *carrier)
     for (cargo_type = EF_PLANE; cargo_type <= EF_NUKE; cargo_type++) {
        snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid);
        while (nxtitem(&ni, &obj)) {
-           if (!carrier->own) {
+           if (carrier->own)
+               unit_teleport(&obj.gen, carrier->x, carrier->y);
+           else {
                mpr(obj.gen.own, "%s lost!\n", unit_nameof(&obj.gen));
                obj.gen.effic = 0;
-           } else {
-               /* mission op-area centered on the obj travels with it */
-               if (obj.gen.opx == obj.gen.x && obj.gen.opy == obj.gen.y) {
-                   obj.gen.opx = carrier->x;
-                   obj.gen.opy = carrier->y;
-               }
-               obj.gen.x = carrier->x;
-               obj.gen.y = carrier->y;
            }
            put_empobj(cargo_type, obj.gen.uid, &obj);
            n++;