Update of /cvsroot/netrek/server/Vanilla/ntserv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26876/ntserv

Modified Files:
	Makefile.in daemonII.c enter.c interface.c ntscmds.c orbit.c 
	redraw.c socket.c 
Added Files:
	bay.c 
Log Message:
bays

Index: redraw.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/redraw.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- redraw.c	21 Mar 2005 05:23:44 -0000	1.1
+++ redraw.c	10 Apr 2006 10:56:33 -0000	1.2
@@ -213,14 +213,12 @@
 #define NOOBSMASK	(PFSELFDEST|PFPLOCK|PFPLLOCK|PFOBSERV)
 	  me->p_flags = (pl->p_flags & ~NOOBSMASK) | (me->p_flags & NOOBSMASK);
 	  
-	  /* always cloaked, state of person watched will be obvious */
-	  /* me->p_flags |= PFCLOAK; */
 	  me->p_dir = pl->p_dir;
 	  me->p_tractor = pl->p_tractor;
-	  me->p_docked = pl->p_docked;
+	  me->p_dock_with = pl->p_dock_with;
+	  me->p_dock_bay = pl->p_dock_bay;
 	  me->p_planet = pl->p_planet;
 	  me->p_speed = pl->p_speed;
-	  /* me->p_kills = pl->p_kills;  Very bad: will confuse enemies */
 	}
 	return;
     }  /* end if I am locked onto a player */
@@ -439,10 +437,11 @@
 		      planets[me->p_planet].pl_armies);
 	    
 	} else if (me->p_flags & PFDOCK) {
-	    if (players[me->p_docked].p_armies == 0) {
+	    struct player *base = bay_owner(me);
+	    if (base->p_armies <= 0) {
 		txt = "Too few armies to beam up";
 		me->p_flags &= ~PFBEAMUP;
-	    } else if (me->p_armies == troop_capacity) {
+	    } else if (me->p_armies >= troop_capacity) {
 		txt = "No more room on board for armies";
 		me->p_flags &= ~PFBEAMUP;
 	    } else {
@@ -452,8 +451,8 @@
 			txt,
 			me->p_armies,
 			troop_capacity,
-			players[me->p_docked].p_name,
-			players[me->p_docked].p_armies);
+			base->p_name,
+			base->p_armies);
 	}
     }
 
@@ -475,13 +474,13 @@
 		      planets[me->p_planet].pl_armies);
 
 	} else if (me->p_flags & PFDOCK) {
-	    if (me->p_armies == 0) {
+	    struct player *base = bay_owner(me);
+	    if (me->p_armies <= 0) {
 		txt = "No more armies to beam down";
 		me->p_flags &= ~PFBEAMDOWN;
-	    } else if (players[me->p_docked].p_armies ==
-		players[me->p_docked].p_ship.s_maxarmies) {
-	      txt = "All troop bunkers are full";
-	      me->p_flags &= ~PFBEAMDOWN;
+	    } else if (base->p_armies >= base->p_ship.s_maxarmies) {
+	        txt = "All troop bunkers are full";
+	        me->p_flags &= ~PFBEAMDOWN;
 	    } else {
 	        txt = "Transfering ground units";
 	    }
@@ -489,8 +488,8 @@
 			txt,
 			me->p_armies,
 			troop_capacity,
-			players[me->p_docked].p_name,
-			players[me->p_docked].p_armies);
+			base->p_name,
+			base->p_armies);
 	}
     }
 

Index: ntscmds.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/ntscmds.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ntscmds.c	10 Apr 2006 04:24:51 -0000	1.4
+++ ntscmds.c	10 Apr 2006 10:56:32 -0000	1.5
@@ -297,8 +297,10 @@
   j->p_ship.s_type = STARBASE;
   j->p_whydead=KQUIT;
   j->p_explode=10;
+  /* note VICIOUS_EJECT prevents animation of ship explosion */
   j->p_status=PEXPLODE;
   j->p_whodead=me->p_no;
+  bay_release(j);
 }
 #endif /* ALLOW_EJECT */
 

Index: orbit.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/orbit.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- orbit.c	21 Mar 2005 10:17:17 -0000	1.2
+++ orbit.c	10 Apr 2006 10:56:32 -0000	1.3
@@ -29,27 +29,10 @@
 #define TRUE 1
 #endif
 
-/*
- * If there are bugs in this docking code and/or possibly other places
- * in the code, then conceivably a base my have p_docked < 4 while
- * all ports are non-VACANT.  That is inconsistent, and this code
- * will check for that eventuality on the fly.
- */
-#if 1
-#define RETURN_IF_VACANT(base, port)
-#else
-#define RETURN_IF_VACANT(base, port) \
-        if (base->p_port[port] != VACANT) { \
-	  ERROR(1, ("Starbase %d has no ports vacant but p_docked==%d\n", \
-		    base->p_id, base->p_docked)); \
-	  return FALSE; \
-	}
-#endif
-
 void de_lock(struct player *me)
 {
   me->p_flags   &= ~(PFPLOCK | PFPLLOCK | PFTRACT | PFPRESS);
- #ifdef SB_TRANSWARP
+#ifdef SB_TRANSWARP
   if (me->p_flags & PFTWARP){
     me->p_flags &= ~PFTWARP;
     me->p_flags |= PFREFITTING;
@@ -64,14 +47,14 @@
  * (If one or more of these is not true, various nasty things happen.)
  */ 
 
-#define DOCK_NO_BASE 0
-#define DOCK_FAILURE 1
-#define DOCK_SUCCESS 2
+#define DOCK_NO_BASE 0 /* no base is close enough */
+#define DOCK_FAILURE 1 /* dock failed due to some condition */
+#define DOCK_SUCCESS 2 /* dock was successful */
 
 static int dock(struct player *base)
 {
   LONG dx, dy;
-  int port_id;
+  int bay_no;
   u_char dir_from_base;
 
   /*
@@ -124,90 +107,28 @@
   }
   
   /*
-   * Make sure the base's docking ports are not already full: */
-  if (base->p_docked >= NUMPORTS) {
+   * Make sure the base's docking bays are not already full: */
+  bay_no = bay_closest(base, dx, dy);
+  if (bay_no == -1) {
     if (send_short)
       swarning(SBDOCKDENIED_TEXT, base->p_no, 0);
     else
-      new_warning(UNDEF, "Starbase %s: Permission to dock denied, all ports currently occupied.", base->p_name);
+      new_warning(UNDEF, "Starbase %s: Permission to dock denied, all bays currently occupied.", base->p_name);
     de_lock(me);
     return DOCK_FAILURE;
   }
 
   /*
-   * Dock on closest port.
-   * A starbase's ports are     3    0
-   * numbered as in this          ()
-   * picture:                   2    1                       */
-  if (dx > 0) {
-    /* We are to the left of the base: */
-    if (dy > 0) {
-      /* Above and to left of base: */
-      if (base->p_port[3] == VACANT)
-	port_id = 3;
-      else if (base->p_port[2] == VACANT)
-	port_id = 2;
-      else if (base->p_port[0] == VACANT) 
-	port_id = 0;
-      else {
-	RETURN_IF_VACANT(base, 1);
-	port_id = 1;
-      }
-    } else {
-      /* Below and to left of base: */
-      if (base->p_port[2] == VACANT)
-	port_id = 2;
-      else if (base->p_port[3] == VACANT)
-	port_id = 3;
-      else if (base->p_port[1] == VACANT) 
-	port_id = 1;
-      else {
-	RETURN_IF_VACANT(base, 0);
-	port_id = 0;
-      }
-    }
-  } else {
-    /* We are to the right of the base: */
-    if (dy > 0) {
-      /* Above and to right of base: */
-      if (base->p_port[0] == VACANT)
-	port_id = 0;
-      else if (base->p_port[1] == VACANT)
-	port_id = 1;
-      else if (base->p_port[3] == VACANT) 
-	port_id = 3;
-      else {
-	RETURN_IF_VACANT(base, 2);
-	port_id = 2;
-      }
-    } else {
-      /* Below and to right of base: */
-      if (base->p_port[1] == VACANT)
-	port_id = 1;
-      else if (base->p_port[2] == VACANT)
-	port_id = 2;
-      else if (base->p_port[0] == VACANT) 
-	port_id = 0;
-      else {
-	RETURN_IF_VACANT(base, 3);
-	port_id = 3;
-      }
-    }
-  }
-
-  /*
    * Adjust player structures of myself and the base. */
-  dir_from_base = ((port_id * 90 + 45) * 256) / 360;
-  me->p_flags   &= ~(PFPLOCK | PFPLLOCK | PFTRACT | PFPRESS);
-  me->p_flags   |= PFDOCK;
-  me->p_dir      = 64 + dir_from_base;
-  me->p_desdir   = me->p_dir;
-  me->p_x        = base->p_x + DOCKDIST * Cos[dir_from_base];
-  me->p_y        = base->p_y + DOCKDIST * Sin[dir_from_base];
-  me->p_speed    = 0;
-  me->p_desspeed = 0;
-  me->p_docked   = base->p_no;
-  me->p_port[0]  = port_id;
+  dir_from_base   = ((bay_no * 90 + 45) * 256) / 360;
+  me->p_flags    &= ~(PFPLOCK | PFPLLOCK | PFTRACT | PFPRESS);
+  me->p_flags    |= PFDOCK;
+  me->p_dir       = 64 + dir_from_base;
+  me->p_desdir    = me->p_dir;
+  me->p_x         = base->p_x + DOCKDIST * Cos[dir_from_base];
+  me->p_y         = base->p_y + DOCKDIST * Sin[dir_from_base];
+  me->p_speed     = 0;
+  me->p_desspeed  = 0;
 #ifdef SB_TRANSWARP
   if (me->p_flags & PFTWARP){
     me->p_flags &= ~PFTWARP;
@@ -216,15 +137,14 @@
   }
 #endif
 
-  base->p_docked++;
-  base->p_port[port_id] = me->p_no;
+  bay_claim(base, me, bay_no);
 
   /*
    * Notify player of success. */
   if (send_short)
-    swarning(ONEARG_TEXT, 2, port_id);
+    swarning(ONEARG_TEXT, 2, bay_no);
   else
-    new_warning(UNDEF,"Helmsman:  Docking manuever completed Captain.  All moorings secured at port %d.", port_id);
+    new_warning(UNDEF,"Helmsman:  Docking manuever completed Captain.  All moorings secured at bay %d.", bay_no);
   return DOCK_SUCCESS;
 }
 

Index: Makefile.in
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/Makefile.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.in	28 Sep 2005 12:14:05 -0000	1.3
+++ Makefile.in	10 Apr 2006 10:56:31 -0000	1.4
@@ -22,14 +22,14 @@
 	    startrobot.o  sysdefaults.o  timecheck.o  torp.o  util.o  \
 	    warning.o ping.o $(RANDOMO) getpath.o $(STRDUPO) features.o \
 	    distress.o transwarp.o gencmds.o ntscmds.o openmem.o feature.o \
-	    queue.o slotmaint.o rsa_key.o ltd_stats.o
+	    queue.o slotmaint.o rsa_key.o ltd_stats.o bay.o
 
 
 #	daemonII object files
 
 D_OBJS =    daemonII.o  sintab.o  sysdefaults.o  data.o  slotmaint.o \
 	    util.o  $(RANDOMO) getpath.o getship.o smessage.o  queue.o \
-	    wander2.o openmem.o solicit.o ltd_stats.o
+	    wander2.o openmem.o solicit.o ltd_stats.o bay.o
 
 #	Src files
 
@@ -48,7 +48,8 @@
             ${srcdir}/features.c ${srcdir}/distress.c ${srcdir}/transwarp.c \
             ${srcdir}/gencmds.c ${srcdir}/ntscmds.c ${srcdir}/openmem.c \
             ${srcdir}/feature.c ${srcdir}/queue.c ${srcdir}/slotmaint.c \
-            ${srcdir}/wander2.c ${srcdir}/sysdefaults.c ${srcdir}/rsa_key.c
+            ${srcdir}/wander2.c ${srcdir}/sysdefaults.c ${srcdir}/rsa_key.c \
+            ${srcdir}/bay.c
 
 SRC = 	    $(R_FILES)  data.h  defs.h planets.h  struct.h \
 	    packets.h  copyright.h

Index: enter.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/enter.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- enter.c	21 Mar 2005 10:17:17 -0000	1.2
+++ enter.c	10 Apr 2006 10:56:32 -0000	1.3
@@ -176,12 +176,10 @@
     me->p_lastseenby = VACANT;
     me->p_kills = 0.0;
     me->p_armies = 0;
-    me->p_docked = 0;
-    me->p_port[0] = VACANT;
-    me->p_port[1] = VACANT;
-    me->p_port[2] = VACANT;
-    me->p_port[3] = VACANT;
-/*    if (!keeppeace) me->p_hostile = (FED|ROM|KLI|ORI);*/
+    bay_init(me);
+    me->p_dock_with = 0;
+    me->p_dock_bay = 0;
+/*  if (!keeppeace) me->p_hostile = (FED|ROM|KLI|ORI); */
     if( !(me->p_flags & PFROBOT) && (me->p_team == NOBODY) ) {
       me->p_hostile = NOBODY;
       me->p_war = NOBODY;

--- NEW FILE: bay.c ---
#include "copyright.h"
#include "config.h"
#include <assert.h>
#include "defs.h"
#include "struct.h"
#include "data.h"

/* starbase bay functions */

/* convert a player number to a player struct pointer */
static struct player *p_no(int i)
{
  return &players[i];
}

/* convert a docked ship player to the base they are docked to */
struct player *bay_owner(struct player *me)
{
  assert(me->p_flags & PFDOCK);
  return p_no(me->p_dock_with);
}

/* check all bays for consistency, despite our best efforts it is
still possible for the bays to be inconsistent, an example is a
SIGKILL of ntserv */
void bay_consistency_check(struct player *base)
{
  int i;
  struct player *ship;

  for (i=0; i<NUMBAYS; i++) {
    if (base->p_bays[i] == VACANT) continue;
    ship = p_no(base->p_bays[i]);
    if (!(ship->p_flags & PFDOCK)) {
      /* ship isn't docked */
      base->p_bays[i] = VACANT;
      continue;
    }
    if (ship->p_dock_with != base->p_no) {
      /* ship is docked but not with this base */
      base->p_bays[i] = VACANT;
      continue;
    }
    if (ship->p_dock_bay != i) {
      /* ship is docked with this base but not on this bay */
      base->p_bays[i] = VACANT;
      continue;
    }
  }
}

/* claim a specific bay on a base for use by a docking ship */
void bay_claim(struct player *base, struct player *me, int bay_no)
{
  me->p_dock_with = base->p_no;
  me->p_dock_bay  = bay_no;
  base->p_bays[bay_no] = me->p_no;
}

/* release of a bay by a docked ship */
void bay_release(struct player *me)
{
  if (me->p_flags & PFDOCK) {
    struct player *base = p_no(me->p_dock_with);
    int bay = me->p_dock_bay;
    if (base->p_bays[bay] != VACANT) {
      base->p_bays[bay] = VACANT;
    }
    me->p_flags &= ~PFDOCK;
  }
}

/* release of all bays by a base */
void bay_release_all(struct player *base)
{
  int i;
  for (i=0; i<NUMBAYS; i++) 
    if (base->p_bays[i] != VACANT) {
      struct player *pl = p_no(base->p_bays[i]);
      base->p_bays[i] = VACANT;
      pl->p_flags &= ~PFDOCK;
    }
}

/* initialise all bays */
void bay_init(struct player *me)
{
  int i;
  for(i=0;i<NUMBAYS;i++)
    me->p_bays[i] = VACANT;
}

/*
 * Return closest bay according to position.
 * A starbase's bays are      3    0
 * numbered as in this          ()
 * picture:                   2    1                       */
int bay_closest(struct player *base, LONG dx, LONG dy)
{
  bay_consistency_check(base);
  if (dx > 0) {
    /* We are to the left of the base: */
    if (dy > 0) {
      /* Above and to left of base: */
      if (base->p_bays[3] == VACANT) return 3;
      else if (base->p_bays[2] == VACANT) return 2;
      else if (base->p_bays[0] == VACANT) return 0;
      else if (base->p_bays[1] == VACANT) return 1;
      else return -1;
    } else {
      /* Below and to left of base: */
      if (base->p_bays[2] == VACANT) return 2;
      else if (base->p_bays[3] == VACANT) return 3;
      else if (base->p_bays[1] == VACANT) return 1;
      else if (base->p_bays[0] == VACANT) return 0;
      else return -1;
    }
  } else {
    /* We are to the right of the base: */
    if (dy > 0) {
      /* Above and to right of base: */
      if (base->p_bays[0] == VACANT) return 0;
      else if (base->p_bays[1] == VACANT) return 1;
      else if (base->p_bays[3] == VACANT) return 3;
      else if (base->p_bays[2] == VACANT) return 2;
      else return -1;
    } else {
      /* Below and to right of base: */
      if (base->p_bays[1] == VACANT) return 1;
      else if (base->p_bays[2] == VACANT) return 2; /* inconsistent order */
      else if (base->p_bays[0] == VACANT) return 0;
      else if (base->p_bays[3] == VACANT) return 3;
      else return -1;
    }
  }
}

Index: daemonII.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/daemonII.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- daemonII.c	27 Sep 2005 12:26:37 -0000	1.3
+++ daemonII.c	10 Apr 2006 10:56:32 -0000	1.4
@@ -927,13 +927,9 @@
                     j->p_explode = 600/PLAYERFUSE; /* set ghost buster */
                 }
 
-                /* At this point, docked ships become removed. */
-                if (j->p_flags & PFDOCK) {
-                    players[j->p_docked].p_docked--;
-                    players[j->p_docked].p_port[j->p_port[0]] = VACANT;
-                    j->p_flags &= ~PFDOCK;
-                } 
+                bay_release(j);
                 if (j->p_ship.s_type == STARBASE) {
+                    bay_release_all(j);
                     if (((j->p_whydead == KSHIP) || 
                             (j->p_whydead == KTORP) ||
                             (j->p_whydead == KPHASER) || 
@@ -942,16 +938,9 @@
                             (j->p_whydead == KGENOCIDE)) && (status->tourn))
                     teams[j->p_team].s_turns=BUILD_SB_TIME; /* in defs.h */
                         /* 30 minute reconstruction period for new starbase */
-                    for (k=0; k<NUMPORTS; k++) 
-                        if(j->p_port[k] != VACANT) {
-                            players[j->p_port[k]].p_flags &= ~PFDOCK;
-                            j->p_port[k] = VACANT;
-                        }
-                    j->p_docked = 0;
                 }
                 /* And he is ejected from orbit. */
-                if (j->p_flags & PFORBIT)
-                  j->p_flags &= ~PFORBIT;
+                j->p_flags &= ~PFORBIT;
 
                 /* Fall through to alive so explosions move */
                         
@@ -1016,10 +1005,13 @@
 
                         /* Charge SB's for mass of docked vessels ... */
                         if (j->p_ship.s_type == STARBASE) {
-                            for (k=0; k<NUMPORTS; k++) 
-                                if(j->p_port[k] != VACANT) 
-                                    j->p_fuel -= players[j->p_port[k]].p_ship.s_warpcost * j->p_speed;
-                                    j->p_etemp += .7*(j->p_speed * j->p_docked);
+			    int bays = 0;
+                            for (k=0; k<NUMBAYS; k++)
+                                if(j->p_bays[k] != VACANT) {
+                                    j->p_fuel -= players[j->p_bays[k]].p_ship.s_warpcost * j->p_speed;
+				    bays++;
+                                }
+			    j->p_etemp += .7*(j->p_speed * bays);
                         }
                     }
 #ifdef SB_TRANSWARP
@@ -1328,11 +1320,11 @@
                   j->p_fuel += 6 * j->p_ship.s_recharge;
                 } else if ((j->p_flags & PFDOCK) && 
                            (j->p_fuel < j->p_ship.s_maxfuel) &&
-                           (players[j->p_docked].p_fuel > SBFUELMIN)) {
+                           (players[j->p_dock_with].p_fuel > SBFUELMIN)) {
                   int fc = MIN(10*j->p_ship.s_recharge,
                                j->p_ship.s_maxfuel - j->p_fuel);
                   j->p_fuel += fc;
-                  players[j->p_docked].p_fuel -= fc;
+                  players[j->p_dock_with].p_fuel -= fc;
                 }
 #else
                 /* Add fuel */
@@ -1341,9 +1333,9 @@
                     (!(planets[j->p_planet].pl_owner & j->p_war))) {
                   j->p_fuel += 8 * j->p_ship.s_recharge;
                 } else if ((j->p_flags & PFDOCK) && (j->p_fuel < j->p_ship.s_maxfuel)) {
-                  if (players[j->p_docked].p_fuel > SBFUELMIN) {
+                  if (players[j->p_dock_with].p_fuel > SBFUELMIN) {
                     j->p_fuel += 12*j->p_ship.s_recharge;
-                    players[j->p_docked].p_fuel -= 12*j->p_ship.s_recharge;
+                    players[j->p_dock_with].p_fuel -= 12*j->p_ship.s_recharge;
                   }
                 } else
                   j->p_fuel += 2 * j->p_ship.s_recharge;
@@ -1418,8 +1410,8 @@
 
                 /* Move Player in dock */
                 if (j->p_flags & PFDOCK) {
-                    j->p_x = players[j->p_docked].p_x + DOCKDIST*Cos[(j->p_port[0]*90+45)*255/360];
-                    j->p_y = players[j->p_docked].p_y + DOCKDIST*Sin[(j->p_port[0]*90+45)*255/360];
+                    j->p_x = players[j->p_dock_with].p_x + DOCKDIST*Cos[(j->p_dock_bay*90+45)*255/360];
+                    j->p_y = players[j->p_dock_with].p_y + DOCKDIST*Sin[(j->p_dock_bay*90+45)*255/360];
                 }
 
                 /* Set player's alert status */
@@ -2939,9 +2931,9 @@
                 if (l->pl_armies < 5)
                     continue;
             if (j->p_flags & PFDOCK)
-                if (players[j->p_docked].p_armies == 0)
+                if (players[j->p_dock_with].p_armies < 1)
                     continue;
-            if (j->p_armies == j->p_ship.s_maxarmies)
+            if (j->p_armies >= j->p_ship.s_maxarmies)
                 continue;
             /* XXX */
             if (j->p_ship.s_type == ASSAULT) {
@@ -2969,13 +2961,13 @@
                 }
 #endif
 	    } else if (j->p_flags & PFDOCK) {
-                players[j->p_docked].p_armies--;
-		army_track(AMT_TRANSUP, j, &players[j->p_docked], 1);
+                struct player *base = bay_owner(j);
+                base->p_armies--;
+		army_track(AMT_TRANSUP, j, base, 1);
 
 #ifdef LTD_STATS
-                /* j = player, j->pdocked = friendly SB */
                 if (status->tourn) {
-                    ltd_update_armies_carried(j, &players[j->p_docked]);
+                    ltd_update_armies_carried(j, base);
                 }
 #endif
  
@@ -3242,18 +3234,18 @@
 
                 }
             } else if (j->p_flags & PFDOCK) {
-                if (players[j->p_docked].p_team != j->p_team)
+                struct player *base = bay_owner(j);
+                if (base->p_team != j->p_team)
                     continue;
-		if (players[j->p_docked].p_armies
-		    == players[j->p_docked].p_ship.s_maxarmies) {
+		if (base->p_armies >= base->p_ship.s_maxarmies) {
                     continue;
                 } else {
-		    army_track(AMT_TRANSDOWN, j, &players[j->p_docked], 1);
+		    army_track(AMT_TRANSDOWN, j, base, 1);
                     j->p_armies--;
-                    players[j->p_docked].p_armies ++;
+                    base->p_armies ++;
 #ifdef LTD_STATS
                     if (status->tourn) {
-                        ltd_update_armies_ferried(j, &players[j->p_docked]);
+                        ltd_update_armies_ferried(j, base);
                     }
 #endif /* LTD_STATS */
                         

Index: socket.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/socket.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- socket.c	10 Apr 2006 04:24:51 -0000	1.4
+++ socket.c	10 Apr 2006 10:56:33 -0000	1.5
@@ -1213,12 +1213,8 @@
     if (packet->state) {
 	orbit();
     } else {
+	bay_release(me);
 	me->p_flags &= ~PFORBIT;
-	if (me->p_flags & PFDOCK) {
-	    players[me->p_docked].p_docked--;
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	    me->p_flags &= ~PFDOCK;
-	}
     }
 }
 
@@ -1402,21 +1398,15 @@
 	return;
     }
     if (target<0 || target>=MAXPLAYER || target==me->p_no) return;
-    player= &players[target];
+    player = &players[target];
     if (player->p_flags & PFCLOAK) return;
     if (hypot((double) me->p_x-player->p_x,
 	      (double) me->p_y-player->p_y) < 
 	((double) TRACTDIST) * me->p_ship.s_tractrng) {
-	if (player->p_flags & PFDOCK) {
-	    players[player->p_docked].p_port[player->p_port[0]] = VACANT;
-	    players[player->p_docked].p_docked--;
-	}
-	if (me->p_flags & PFDOCK) {
-	    players[me->p_docked].p_docked--;
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	}
-	player->p_flags &= ~(PFORBIT | PFDOCK);
-	me->p_flags &= ~(PFORBIT | PFDOCK);
+	bay_release(player);
+	bay_release(me);
+	player->p_flags &= ~PFORBIT;
+	me->p_flags &= ~PFORBIT;
 	me->p_tractor = target;
 	me->p_flags |= PFTRACT;
     } else {
@@ -1448,16 +1438,10 @@
     if (hypot((double) me->p_x-player->p_x,
 	      (double) me->p_y-player->p_y) < 
 	((double) TRACTDIST) * me->p_ship.s_tractrng) {
-	if (player->p_flags & PFDOCK) {
-	    players[player->p_docked].p_port[player->p_port[0]] = VACANT;
-	    players[player->p_docked].p_docked--;
-	}
-	if (me->p_flags & PFDOCK) {
-	    players[me->p_docked].p_docked--;
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	}
-	player->p_flags &= ~(PFORBIT | PFDOCK);
-	me->p_flags &= ~(PFORBIT | PFDOCK);
+	bay_release(player);
+	bay_release(me);
+	player->p_flags &= ~PFORBIT;
+	me->p_flags &= ~PFORBIT;
 	me->p_tractor = target;
 	me->p_flags |= (PFTRACT | PFPRESS);
     } else {
@@ -1736,16 +1720,12 @@
     int i;
 
     if (me->p_ship.s_type == STARBASE) {
-	me->p_docked = 0;
-	for (i=0; i<NUMPORTS; i++) {
-	    if (me->p_port[i] != VACANT)
-		players[me->p_port[i]].p_flags &= ~PFDOCK;
-	    me->p_port[i] = VACANT;  
-	}
-	if (packet->state) 
-	    me->p_flags |= PFDOCKOK;
-	else
-	    me->p_flags &= ~PFDOCKOK;
+        if (packet->state) {
+            me->p_flags |= PFDOCKOK;
+        } else {
+            me->p_flags &= ~PFDOCKOK;
+            bay_release_all(me);
+        }
     }
 }
 

Index: interface.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/interface.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- interface.c	22 Feb 2006 09:18:30 -0000	1.3
+++ interface.c	10 Apr 2006 10:56:32 -0000	1.4
@@ -29,21 +29,15 @@
 	speed=0;
     }
     me->p_desspeed = speed;
-    if (me->p_flags & PFDOCK) {
-	players[me->p_docked].p_docked--;
-	players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-    }
-    me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFDOCK | PFBEAMUP | PFBEAMDOWN);
+    bay_release(me);
+    me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
 }
 
 void set_course(u_char dir)
 {
     me->p_desdir = dir;
-    if (me->p_flags & PFDOCK) {
-	players[me->p_docked].p_docked--;
-	players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-    }
-    me->p_flags &= ~(PFBOMB | PFORBIT | PFDOCK | PFBEAMUP | PFBEAMDOWN);
+    bay_release(me);
+    me->p_flags &= ~(PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
 }
 
 void shield_up(void)
@@ -156,7 +150,7 @@
 	    return;
 	}
     } else if (me->p_flags & PFDOCK) {
-	if (me->p_team != players[me->p_docked].p_team) {
+	if (me->p_team != players[me->p_dock_with].p_team) {
             new_warning(46,"Comm Officer: We're not authorized to beam foriegn troops on board!");
 	    return;
 	}
@@ -185,7 +179,7 @@
 #endif
 
     if (me->p_flags & PFDOCK) {
-        if (me->p_team != players[me->p_docked].p_team) {
+        if (me->p_team != players[me->p_dock_with].p_team) {
             new_warning(48,"Comm Officer: Starbase refuses permission to beam our troops over.");
 	    return;
         }
@@ -312,16 +306,10 @@
     if (hypot((double) me->p_x-victim->p_x,
 	    (double) me->p_y-victim->p_y) < 
 	    ((double) TRACTDIST) * me->p_ship.s_tractrng) {
-	if (victim->p_flags & PFDOCK) {
-	    players[victim->p_docked].p_port[victim->p_port[0]] = VACANT;
-	    players[victim->p_docked].p_docked--;
-	}
-	if (me->p_flags & PFDOCK) {
-	    players[me->p_docked].p_docked--;
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	}
-	victim->p_flags &= ~(PFORBIT | PFDOCK);
-	me->p_flags &= ~(PFORBIT | PFDOCK);
+	bay_release(victim);
+	bay_release(me);
+	victim->p_flags &= ~PFORBIT;
+	me->p_flags &= ~PFORBIT;
 	me->p_tractor = player;
 	me->p_flags |= PFTRACT;
     } else {			/* out of range */
@@ -357,14 +345,8 @@
     if (hypot((double) me->p_x-victim->p_x,
 	      (double) me->p_y-victim->p_y) < 
 	((double) TRACTDIST) * me->p_ship.s_tractrng) {
-	if (victim->p_flags & PFDOCK) {
-	    players[victim->p_docked].p_port[victim->p_port[0]] = VACANT;
-	    players[victim->p_docked].p_docked--;
-	}
-	if (me->p_flags & PFDOCK) {
-	    players[me->p_docked].p_docked--;
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	}
+	bay_release(victim);
+	bay_release(me);
 	victim->p_flags &= ~(PFORBIT | PFDOCK);
 	me->p_flags &= ~(PFORBIT | PFDOCK);
 	me->p_tractor = target;
@@ -408,21 +390,18 @@
 	sendwarn("Orions", mask & ORI, ORI);
     }
     if (me->p_flags & PFDOCK) {
-	if (players[me->p_docked].p_team & mask) {
-	    players[me->p_docked].p_port[me->p_port[0]] = VACANT;
-	    players[me->p_docked].p_docked--;
-	    me->p_flags &= ~PFDOCK;
+	if (players[me->p_dock_with].p_team & mask) {
+	    /* release ship from starbase that is now hostile */
+	    bay_release(me);
 	}
-    } else if (me->p_ship.s_type == STARBASE) {
-	if (me->p_docked > 0) {
-	    for(i=0; i<NUMPORTS; i++) {
-		if (me->p_port[i] == VACANT)   /* isae -- Ted's fix */
-                  continue;
-		if (mask & players[me->p_port[i]].p_team) {
-		    players[me->p_port[i]].p_flags &= ~PFDOCK;
-		    me->p_docked--;
-		    me->p_port[i] = VACANT;
-		}
+    }
+    if (me->p_ship.s_type == STARBASE) {
+        for(i=0; i<NUMBAYS; i++) {
+	    if (me->p_bays[i] == VACANT)
+                continue;
+	    if (mask & players[me->p_bays[i]].p_team) {
+	        /* release docked ships that are now hostile */
+	        bay_release(&players[me->p_bays[i]]);
 	    }
 	}
     }
@@ -486,7 +465,7 @@
             new_warning(52,"Can only refit to starbase on your home planet.");
 	    return;
 	}
-	if (players[me->p_docked].p_team != me->p_team) {
+	if (players[me->p_dock_with].p_team != me->p_team) {
             new_warning(53,"You must dock YOUR starbase to apply for command reassignment!");
 	    return;
 	}
@@ -573,12 +552,7 @@
 	/* Reset kills to 0.0 */
 	me->p_kills=0;
 	/* bump all docked ships */
-	for (i=0; i<NUMPORTS; i++) 
-	   if (me->p_port[i] != VACANT) {
-		players[me->p_port[i]].p_flags &= ~PFDOCK;
-		me->p_docked--;
-		me->p_port[i] = VACANT;	
-	   }
+	bay_release_all(me);
 	me->p_flags |= PFDOCKOK;
     }	
 
@@ -622,8 +596,7 @@
     me->p_etime = 0;
     me->p_ship.s_type = type;
     if (type == STARBASE) {
-	me->p_docked = 0;
-	for (i=0; i<4; i++) me->p_port[i] = VACANT;
+	bay_init(me);
 	me->p_flags |= PFDOCKOK;
     }