static char *rcsid = "$Header: /plaid/homes/zeus/Blind-2.47/cmds/RCS/a.c,v 2.47 1998/04/15 21:34:50 zeus Exp zeus $";

/*
 *
 * $Log: a.c,v $
 * Revision 2.47  1998/04/15 21:34:50  zeus
 * *** empty log message ***
 *
 * Revision 2.46  1997/04/18 12:13:15  zeus
 * Revision 2.44  1995/12/31  19:45:18  zeus
 * Revision 2.43  1995/03/20  01:43:09  zeus
 *
 */

#define NOTIMEB
 
#include "common.h"
#include "prototypes.h"
#include "cmds.h"
#include "cmds-g.h"
#include "enterturn-g.h"

extern player *players;
extern char err_tmp[];

void a_cmd_rcsid (void);

void
a_cmd_rcsid (void)
{
  printf ("%s\n",rcsid);
}

void
a_cmd (char *buf, player * P)
{
  player *P2;
  alliance *a;
  defensive *d,*d2;

  cmd_init(buf);
  P2 = ninputplayer ();
  if (P2)
  {				/* Valid command */
    if (P2 == P)		/* do this with everyone */
    {
      for (P2 = players; P2; P2 = P2->next)
	if (P2 != P)
	{
	  for (a = P->allies; a; a = a->next)
	    if (a->ally == P2)
	      break;
	  for (d = P->defend; d; d=d2)
          {
            d2 = d->next;
	    if (d->defend == P2)
	      removelist (&P->defend, d);
          }
	  if (!a)
	  {
	    a = alloc (sizeof (alliance));
	    a->ally = P2;
	    addlist (&P->allies, a);
	  }
	}			/* end of inner "if not self" test */
    }				/* end of outer "if not self" test */
    else /* only with player specified */
    {
      if (!known_empire(P,P2))
      {
        sprintf (err_tmp,"You haven't encountered %s yet (if they exist!)\n",P2->name);
        error(err_tmp);
        return;
      }
      for (a = P->allies; a; a = a->next)
	if (a->ally == P2)
	  break;
      for (d = P->defend; d; d=d2)
      {
        d2 = d->next;
	if (d->defend == P2)
	  removelist (&P->defend, d);
      }
      if (!a)
      {
	a = alloc (sizeof (alliance));
	a->ally = P2;
	addlist (&P->allies, a);
      }
    }
  }
  else /* Oops... */
  {
    error (err_tmp);
    return;
  }
  extra_token ();
}
