]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/nav_util.c
Update copyright notice.
[empserver] / src / lib / update / nav_util.c
index cc30724b3698639db009699f779f0a442aadeff5..3e0ab507654aa1135efd695c8e32e92d29d483cc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -45,7 +45,6 @@
 #include "nsc.h"
 #include "nat.h"
 #include "path.h"
-#include "deity.h"
 #include "file.h"
 #include "item.h"
 #include "optlist.h"
@@ -85,31 +84,30 @@ check_nav(struct sctstr *sect)
 int
 load_it(register struct shpstr *sp, register struct sctstr *psect, int i)
 {
-    int comm, shipown, amount, ship_amt, sect_amt,
-       abs_max, max_amt, transfer;
-    s_char item;
+    int comm, shipown, amount, ship_amt, sect_amt;
+    int abs_max, max_amt, transfer;
     struct mchrstr *vship;
 
     amount = sp->shp_lend[i];
     shipown = sp->shp_own;
-    item = sp->shp_tend[i];    /* commodity */
-    comm = com_num(&item);
+    comm = sp->shp_tend[i];
+    if (CANT_HAPPEN((unsigned)comm > I_MAX))
+       return 0;
 
-    ship_amt = getvar(comm, (s_char *)sp, EF_SHIP);
-    sect_amt = getvar(comm, (s_char *)psect, EF_SECTOR);
+    ship_amt = sp->shp_item[comm];
+    sect_amt = psect->sct_item[comm];
 
     /* check for disloyal civilians */
-    if (psect->sct_oldown != shipown && comm == V_CIVIL) {
+    if (psect->sct_oldown != shipown && comm == I_CIVIL) {
        wu(0, shipown,
           "Ship #%d - unable to load disloyal civilians at %s.",
           sp->shp_uid, xyas(psect->sct_x, psect->sct_y, psect->sct_own));
        return 0;
     }
-    if (comm == V_CIVIL || comm == V_MILIT)
+    if (comm == I_CIVIL || comm == I_MILIT)
        sect_amt--;             /* leave 1 civ or mil to hold the sector. */
     vship = &mchr[(int)sp->shp_type];
-    abs_max = max_amt = (vl_find(comm, vship->m_vtype,
-                                vship->m_vamt, (int)vship->m_nv));
+    abs_max = max_amt = vship->m_item[comm];
 
     if (!abs_max)
        return 0;               /* can't load the ship, skip to the end. */
@@ -134,18 +132,16 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i)
        return 0;               /* nothing to move */
 
 
-    putvar(comm, ship_amt + transfer, (s_char *)sp, EF_SHIP);
-    if (comm == V_CIVIL || comm == V_MILIT)
+    sp->shp_item[comm] = ship_amt + transfer;
+    if (comm == I_CIVIL || comm == I_MILIT)
        sect_amt++;             /*adjustment */
-    putvar(comm, sect_amt - transfer, (s_char *)psect, EF_SECTOR);
+    psect->sct_item[comm] = sect_amt - transfer;
 
     /* deal with the plague */
-    if (getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_INFECT &&
-       getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY)
-       putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP);
-    if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT &&
-       getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_HEALTHY)
-       putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)psect, EF_SECTOR);
+    if (psect->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
+       sp->shp_pstage = PLG_EXPOSED;
+    if (sp->shp_pstage == PLG_INFECT && psect->sct_pstage == PLG_HEALTHY)
+       psect->sct_pstage = PLG_EXPOSED;
 
     return 1;                  /* we did someloading return 1 to keep */
     /* our loop happy in nav_ship()        */
@@ -164,17 +160,13 @@ void
 unload_it(register struct shpstr *sp)
 {
     struct sctstr *sectp;
-    s_char item;
     int i;
     int landowner;
     int shipown;
     int comm;
     int sect_amt;
     int ship_amt;
-    int abs_max = 99999;       /* max amount a sector can hold. */
     int max_amt;
-    int level;
-
 
     sectp = getsectp(sp->shp_x, sp->shp_y);
 
@@ -182,78 +174,44 @@ unload_it(register struct shpstr *sp)
     shipown = sp->shp_own;
 
     for (i = 0; i < TMAX; ++i) {
-       item = sp->shp_tend[i];
-       level = sp->shp_lend[i];
-
-       if (item == ' ' || level == 0)
+       if (sp->shp_tend[i] == I_NONE || sp->shp_lend[i] == 0)
            continue;
        if (landowner == 0)
            continue;
        if (sectp->sct_type != SCT_HARBR)
            continue;
 
-       comm = com_num(&item);
-       ship_amt = getvar(comm, (s_char *)sp, EF_SHIP);
-       sect_amt = getvar(comm, (s_char *)sectp, EF_SECTOR);
+       comm = sp->shp_tend[i];
+       if (CANT_HAPPEN((unsigned)comm > I_MAX))
+           continue;
+       ship_amt = sp->shp_item[comm];
+       sect_amt = sectp->sct_item[comm];
 
        /* check for disloyal civilians */
-       if (sectp->sct_oldown != shipown && comm == V_CIVIL) {
+       if (sectp->sct_oldown != shipown && comm == I_CIVIL) {
            wu(0, sp->shp_own,
               "Ship #%d - unable to unload civilians into a disloyal sector at %s.",
               sp->shp_uid, xyas(sectp->sct_x, sectp->sct_y,
                                 sectp->sct_own));
            continue;
        }
-       if (comm == V_CIVIL)
+       if (comm == I_CIVIL)
            ship_amt--;         /* This leaves 1 civs on board the ship */
 
-       if (sect_amt >= abs_max)
-           continue;           /* The sector is full. */
-
-       max_amt = min(ship_amt, abs_max - sect_amt);
-
+       max_amt = min(ship_amt, ITEM_MAX - sect_amt);
        if (max_amt <= 0)
            continue;
 
-       putvar(comm, ship_amt - max_amt, (s_char *)sp, EF_SHIP);
-       putvar(comm, sect_amt + max_amt, (s_char *)sectp, EF_SECTOR);
-
-       if (getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_INFECT &&
-           getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY)
-           putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP);
-
-       if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT &&
-           getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_HEALTHY)
-           putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sectp, EF_SECTOR);
+       sp->shp_item[comm] = ship_amt - max_amt;
+       sectp->sct_item[comm] = sect_amt + max_amt;
 
+       if (sectp->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
+           sp->shp_pstage = PLG_EXPOSED;
+       if (sp->shp_pstage == PLG_INFECT && sectp->sct_pstage == PLG_HEALTHY)
+           sectp->sct_pstage = PLG_EXPOSED;
     }
-
 }
 
-/* com_num
- * This small but useful bit of code runs through the list
- * of commodities and return the integer value of the 
- * commodity it finds if possible.  Very handy when using getvar().  
- * Basicly its a hacked version of whatitem.c found in the
- * /player directory.
- * new autonav code.
- * Chad Zabel 6/1/94
- */
-
-int
-com_num(s_char *ptr)
-{
-    struct ichrstr *ip;
-
-    for (ip = &ichr[1]; ip->i_mnem != 0; ip++) {
-       if (*ptr == ip->i_mnem)
-           return ip->i_vtype;
-    }
-    return 0;                  /*NOTREACHED*/
-}
-
-
-
 /* auto_fuel_ship 
  * Assume a check for fuel=0 has already been made and passed.  
  * Try to fill a ship using petro. and then oil.