ftp.nice.ch/pub/next/games/strategic/NPipe.s.tar.gz#/NPipe/NCommon.c

This is NCommon.c in view mode; [Download] [Up]

#include <strings.h>

#import "NCommon.h"

/*----------------------------------------------------------------------*/
/* Purpose      : Function returns the direction in whihc the flow will */
/*                exit if it enters from a particular direction. This   */
/*                implies that if the return value is NOTVALID then the */
/*                water flow connot enter from that direction!          */
/*                                                                      */
/* Parameters   :  NPipe_t pipe       Pipe type to be tested.           */
/*                 Direction_t entry  Direction from which water flow   */
/*                                    will enter.                       */
/*                                                                      */ 
/* Return value :  Direction_t        Direction from which water flow   */
/*                                    will exit pipe.                   */
/*----------------------------------------------------------------------*/
Direction_t entry2exit( NPipe_t pipe, Direction_t entry)
{
    static Direction_t exit_direction[14][4] =
       {
          { INVALID_DIR, INVALID_DIR, INVALID_DIR, INVALID_DIR},  /* obstacle, no input , no exit */
          { INVALID_DIR, INVALID_DIR, INVALID_DIR, INVALID_DIR},  /* unassigned, no input , no exit */
          { INVALID_DIR, INVALID_DIR, INVALID_DIR, EAST},         /* source, no input , no exit     */
          { INVALID_DIR, SOUTH, INVALID_DIR, NORTH },             /* vertical pipe                  */
          { WEST, INVALID_DIR, EAST, INVALID_DIR },               /* horizontal pipe                */
          { SOUTH, INVALID_DIR, INVALID_DIR, EAST },              /* upper left                     */
          { INVALID_DIR, INVALID_DIR, SOUTH, WEST },
          { NORTH, EAST, INVALID_DIR, INVALID_DIR },
          { INVALID_DIR, WEST, NORTH, INVALID_DIR},               /* lower right                    */
          { WEST, SOUTH, EAST, NORTH },                           /* intersection                   */
          { INVALID_DIR, INVALID_DIR, INVALID_DIR, NORTH },
          { INVALID_DIR, SOUTH, INVALID_DIR, INVALID_DIR },
          { WEST, INVALID_DIR, INVALID_DIR, INVALID_DIR },
          { INVALID_DIR, INVALID_DIR, EAST, INVALID_DIR },
       };

   if( pipe < PIPE_UNASSIGNED || pipe > PIPE_HORIZONTAL_ONEWAY_RIGHT )
      return INVALID_DIR;
   if( entry < EAST || entry > SOUTH )
      return INVALID_DIR;
   return( exit_direction[(int)pipe][(int)entry] );
}





/*----------------------------------------------------------------------*/
/* Purpose      : Indicate the direction the water flow will enter the  */
/*                adjoining cell if it exits from a particular          */
/*                direction.                                            */
/*                                                                      */ 
/* Parameters   : Direction_t entry  Exit direction from current cell.  */
/*                                                                      */ 
/* Return value : Direction_t  Direction from which water flow will     */
/*                             enter new cell.                          */
/*----------------------------------------------------------------------*/
Direction_t exit2entry( Direction_t entry)
{
   static Direction_t entry_direction[] = { WEST, SOUTH, EAST, NORTH };
 
   if( entry < EAST || entry > SOUTH )
      return INVALID_DIR;
   return( entry_direction[entry] );
}


/*----------------------------------------------------------------------*/
/* Purpose      :                                                       */
/* Parameters   :                                                       */
/* Return value :                                                       */
/*----------------------------------------------------------------------*/
Rotation_t direction2rotation( NPipe_t pipe, Direction_t entry)
{
   static Rotation_t rotation[14][4] =
      {
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* obstacle, no input , no exit */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* unassigned, no input , no exit */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* source, no input , no exit     */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* vertical pipe                  */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* horizontal pipe                */
          { COUNTERCLOCKWISE, INVALID_ROT, INVALID_ROT, CLOCKWISE },  /* upper left                     */
          { INVALID_ROT, INVALID_ROT, CLOCKWISE, COUNTERCLOCKWISE },
          { CLOCKWISE, COUNTERCLOCKWISE, INVALID_ROT, INVALID_ROT },
          { INVALID_ROT, CLOCKWISE, COUNTERCLOCKWISE, INVALID_ROT },  /* lower right                    */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, INVALID_ROT },     /* intersection                   */
          { INVALID_ROT, INVALID_ROT, INVALID_ROT, NORTH },
          { INVALID_ROT, SOUTH, INVALID_ROT, INVALID_ROT },
          { WEST, INVALID_ROT, INVALID_ROT, INVALID_ROT },
          { INVALID_ROT, INVALID_ROT, EAST, INVALID_ROT },
      };
   if( pipe < PIPE_UNASSIGNED || pipe > PIPE_HORIZONTAL_ONEWAY_RIGHT )
      return INVALID_ROT;
   if( entry < EAST || entry > SOUTH )
      return INVALID_ROT;
   return( rotation[(int)pipe][(int)entry] );
}



These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.