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

/*

 * $Log: p.c,v $
 * Revision 2.47  1998/04/15 21:34:50  zeus
 * *** empty log message ***
 *
 * Revision 2.46  1997/04/18 12:13:56  zeus
 * *** empty log message ***
 *
 * Revision 2.45  1997/01/01  00:04:52  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 "enterturn-g.h"
#include "cmds.h"
#include "cmds-g.h"

extern char err_tmp[];

void p_cmd_rcsid (void);

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


void
p_cmd (char *buf, player * P)
{
  planet *p;
  int i;

#ifdef PARTTECH
  double dt, wt, st, ct;
  int s = 0;

#endif

  cmd_init(buf);
  p = ninputplanet (P);
  if (p)
  {
    if (p->owner == P)
    {

#ifdef PARTTECH
      char v[MAXTEXT];

#endif

      i = ninputproduction (P, p);

#ifdef PARTTECH
      if (abs (i) == PR_SHIP)
      {
	hstrncpy (v, next_token (),MAXTEXT);	/* Optional tech spec? */
	if ((v[0]) && ((v[0] != ';') && (v[0] != '#')))
	{
	  dt = get_tech (v, P->tech.drive);
	  if (dt == BADF)
	  {
	    error (err_tmp);
	    return;
	  }
	  if (dt > P->tech.drive)
	  {
	    error ("Drive tech out of range\n");
	    return;
	  }
	  hstrncpy (v, next_token (),MAXTEXT);
	  wt = get_tech (v, P->tech.guns);
	  if (wt == BADF)
	  {
	    error (err_tmp);
	    return;
	  }
	  if (wt > P->tech.guns)
	  {
	    error ("Weapons tech out of range\n");
	    return;
	  }
	  if (wt == MISSINGF)
	  {
	    error ("Missing Weapons tech spec\n");
	    return;
	  }
	  hstrncpy (v, next_token (),MAXTEXT);
	  st = get_tech (v, P->tech.shields);
	  if (st == BADF)
	  {
	    error (err_tmp);
	    return;
	  }
	  if (st > P->tech.shields)
	  {
	    error ("Shield tech out of range\n");
	    return;
	  }
	  if (st == MISSINGF)
	  {
	    error ("Missing Shields tech spec\n");
	    return;
	  }
	  hstrncpy (v, next_token (),MAXTEXT);
	  ct = get_tech (v, P->tech.cargo);
	  if (ct == BADF)
	  {
	    error (err_tmp);
	    return;
	  }
	  if (ct > P->tech.cargo)
	  {
	    error ("Cargo tech out of range\n");
	    return;
	  }
	  if (ct == MISSINGF)
	  {
	    error ("Missing Cargo tech spec\n");
	    return;
	  }
	  /* Set s (scrap flag) to 1, iff new tech spec, and ship
	     has that component */
	  if ((dt != p->drive) && (p->producingshiptype->drive > 0.0))
	    s = 1;
	  p->drive = dt;
	  if ((wt != p->guns) && (p->producingshiptype->guns > 0.0))
	    s = 1;
	  p->guns = wt;
	  if ((st != p->shields) && (p->producingshiptype->shields > 0.0))
	    s = 1;
	  p->shields = st;
	  if ((ct != p->cargo) && (p->producingshiptype->cargo > 0.0))
	    s = 1;
	  p->cargo = ct;
	  /* If new tech spec, need to scrap partial ship */
	  if (s)
	    i = PR_SHIP;
	}
      }
#endif

      if (i == PR_NOTHING)
      {
	error (err_tmp);
	return;
      }

      if (i >= 0)		/* This handles the P sys ship command every turn problem */
	setproduction (p, i);
      extra_token ();		/* Only check for extras if all went well */
    }
    else
    {
      /* don't own system, don't mention name or number, since we don't know */
      /* which they used. This can be abused */
      error ("You don't own that system.\n");
      return;
    }
  }
  else
    error (err_tmp);
}
