From: deragon@JETHRO.CS.NYU.EDU (John Deragon)
Newsgroups: alt.games.gb
Subject: patches for bid()
Date: 25 Dec 1992 03:25:21 -0600
Organization: UTexas Mail-to-News Gateway
NNTP-Posting-Host: cs.utexas.edu


	The following patch fixes two bugs in the bid function of GB5.2.

  o Checks to see if the bid and shipping costs exceed your current funds.
	(before it only checked for the bid > money not (bid + ship) > money)

  o Checks to see if you have outstanding bids and deducts that amount from
    your available funds.  (to prevent a player from bidding on all the lots
    when he only has the money to pay for some of them)

	I highly suggest installing this patch, as the latter of the two bugs 
	can cause core dumps.

	Seeker


-------- build.diffs created on Fri Dec 25 03:16:29 EST 1992 ----------
-------- on machine tensha.dev.rockcoast.com by johnd -----------------

*** /work/GB5.2/build.c	Fri Nov 27 14:02:57 1992
--- build.c	Fri Dec 25 03:06:35 1992
***************
*** 1747,1760 ****
      deductAPs(Playernum, Governor, APcount, snum, 0);
  }
  
! void bid(int Playernum, int Governor, int APcount)
  {
      racetype *Race;
      planettype *p;
      commodtype *c;
      shiptype *s;
      char commod;
      int i, item, bid0, lot, shipping, ok=0, sh;
      int minbid;
      double dist, rate;
      int snum, pnum;
--- 1747,1763 ----
      deductAPs(Playernum, Governor, APcount, snum, 0);
  }
  
! void
! bid(int Playernum, int Governor, int APcount)
  {
      racetype *Race;
      planettype *p;
      commodtype *c;
+     commodtype *cc;
      shiptype *s;
      char commod;
      int i, item, bid0, lot, shipping, ok=0, sh;
+ 	int u, shipcost = 0, money_owed = 0;
      int minbid;
      double dist, rate;
      int snum, pnum;
***************
*** 1825,1831 ****
  	    return;
  	}
  	getplanet(&p, snum, pnum);
! 
  	if(p->slaved_to && p->slaved_to!=Playernum) {
  	    sprintf(buf, "This planet is enslaved to player %d.\n", p->slaved_to);
  	    notify(Playernum, Governor, buf);
--- 1828,1836 ----
  	    return;
  	}
  	getplanet(&p, snum, pnum);
!     /*
! 	 * Cant bid from an enslaved planet 
! 	 */
  	if(p->slaved_to && p->slaved_to!=Playernum) {
  	    sprintf(buf, "This planet is enslaved to player %d.\n", p->slaved_to);
  	    notify(Playernum, Governor, buf);
***************
*** 1832,1859 ****
  	    free(p);
  	    return;
  	}
! /* check to see if there is an undamaged gov center or space port here */
      sh = p->ships;
!     while(sh && !ok) {
! 	(void)getship(&s, sh);
! 	if(s->alive && (s->owner==Playernum) && !s->damage &&
! 	   Shipdata[s->type][ABIL_PORT]) ok = 1;
! 	sh = s->nextship;
! 	free(s);
      }
      if(!ok) {
! 	notify(Playernum, Governor, "You don't have an undamaged space port or government center here.\n");
! 	free(p);
! 	return;
      }
  
  	lot = atoi(args[1]);
  	bid0 = atoi(args[2]);
  	if((lot<=0) || lot>Numcommods()) {
  	    notify(Playernum, Governor, "Illegal lot number.\n");
  	    free(p);
  	    return;
  	}
  	getcommod(&c, lot);
  	if(!c->owner) {
  	    notify(Playernum, Governor, "No such lot for sale.\n");
--- 1837,1875 ----
  	    free(p);
  	    return;
  	}
! 	/*
! 	 * check to see if there is an undamaged gov center 
! 	 * or space port here 
! 	 */
      sh = p->ships;
!     while (sh && !ok) {
! 		(void)getship(&s, sh);
! 		if (s->alive && (s->owner==Playernum) && !s->damage &&
! 		   Shipdata[s->type][ABIL_PORT]) 
! 				ok = 1;
! 		sh = s->nextship;
! 		free(s);
      }
+ 
      if(!ok) {
! 		notify(Playernum, Governor,
! 		 "You don't have an undamaged space port or government center here.\n");
! 		free(p);
! 		return;
      }
  
  	lot = atoi(args[1]);
  	bid0 = atoi(args[2]);
+ 
  	if((lot<=0) || lot>Numcommods()) {
  	    notify(Playernum, Governor, "Illegal lot number.\n");
  	    free(p);
  	    return;
  	}
+ 
+ 	/* 
+      * What the HELL does this do?! 
+      */
  	getcommod(&c, lot);
  	if(!c->owner) {
  	    notify(Playernum, Governor, "No such lot for sale.\n");
***************
*** 1861,1866 ****
--- 1877,1883 ----
  	    free(c);
  	    return;
  	}
+ /*	
  	if (c->owner == Playernum &&
  	    (c->star_from != Dir[Playernum-1][c->governor].snum ||
  	     c->planet_from != Dir[Playernum-1][c->governor].pnum)) {
***************
*** 1869,1876 ****
  	    free(c);
  	    return;
  	}
  	minbid = (int)((double)c->bid*(1.0+UP_BID));
! 	if(bid0 < minbid) {
  	    sprintf(buf, "You have to bid more than %d.\n", minbid);
  	    notify(Playernum, Governor, buf);
  	    free(p);
--- 1886,1894 ----
  	    free(c);
  	    return;
  	}
+ */
  	minbid = (int)((double)c->bid*(1.0+UP_BID));
! 	if(bid0 <= minbid) {
  	    sprintf(buf, "You have to bid more than %d.\n", minbid);
  	    notify(Playernum, Governor, buf);
  	    free(p);
***************
*** 1877,1882 ****
--- 1895,1904 ----
  	    free(c);
  	    return;
  	}
+ 
+ 	/* 
+      * Don't allow guests to screw things up 
+      */
  	Race = races[Playernum-1];
  	if(Race->Guest) {
  	    notify(Playernum, Governor, "Guest races cannot bid.\n");
***************
*** 1884,1889 ****
--- 1906,1914 ----
  	    free(c);
  	    return;
  	}
+     /*
+  	 * Make sure they have the bucks 
+      */
  	if(bid0 > Race->governor[Governor].money) {
  	    notify(Playernum, Governor, "Sorry, no buying on credit allowed.\n");
  	    free(p);
***************
*** 1890,1906 ****
  	    free(c);
  	    return;
  	}
! /* notify the previous bidder that he was just outbidded */
  	if(c->bidder) {
! 	    sprintf(buf, "The bid on lot #%d (%d %s) has been upped to %d by %s [%d].\n", lot, c->amount, Commod[c->type], bid0, Race->name, Playernum);
  	    notify((int)c->bidder, (int)c->bidder_gov, buf);
  	}
  	c->bid = bid0;
  	c->bidder = Playernum;
  	c->bidder_gov = Governor;
  	c->star_to = snum;
  	c->planet_to = pnum;
! 	shipping = shipping_cost((int)c->star_to, (int)c->star_from, &dist, (int)c->bid);
  
  	sprintf(buf, "There will be an additional %d charged to you for shipping costs.\n", shipping);
  	notify(Playernum, Governor, buf);
--- 1915,1973 ----
  	    free(c);
  	    return;
  	}
! 	/* 
! 	 * Make sure we check to see if we have enough for shipping costs 
!      * as well.    --JPD--
!      */
! 	shipcost = shipping_cost((int)c->star_to, (int)c->star_from, 
! 				&dist, (int)c->bid);
! 
! 	if ((bid0 + shipcost) > Race->governor[Governor].money) {
! 	  sprintf(buf, "The bid (%d) + shipping costs (%d) exceed your money (%d)\n", 	
! 		bid0, shipcost, Race->governor[Governor].money);
! 	    notify(Playernum, Governor, buf);
! 	    free(p);
! 	    free(c);
! 	    return;
! 	}
! 
! 	/* 
!      * Also make sure they have not bid on other things and trying to use 
!      * money earmarked for other lots --JPD--
!      */
! 
! 	for (u = 1; u <= Numcommods(); u++) {
! 		getcommod(&cc, u);
! 			if (cc->bidder == Playernum)
! 				money_owed += cc->bid;
! 	}
! 	free(cc);
! 	
! 	if (((bid0 + shipcost) + money_owed) > Race->governor[Governor].money) {
! 		notify(Playernum, Governor, "All your money is used in bids already!\n");
! 		free(p);
! 		free(c);
! 		return;
! 	}
! 
! 	/* 
! 	 * They passed the credit check, notify the previous bidder 
! 	 * that he was just outbidded 
! 	 */
  	if(c->bidder) {
! 	  sprintf(buf, "The bid on lot #%d (%d %s) has been upped to %d by %s [%d].\n", lot, c->amount, Commod[c->type], bid0, Race->name, Playernum);
  	    notify((int)c->bidder, (int)c->bidder_gov, buf);
  	}
+ 
+ 	/* 
+      * Set the commod structs to the new values 
+ 	 */
  	c->bid = bid0;
  	c->bidder = Playernum;
  	c->bidder_gov = Governor;
  	c->star_to = snum;
  	c->planet_to = pnum;
! 	shipping = shipcost;
  
  	sprintf(buf, "There will be an additional %d charged to you for shipping costs.\n", shipping);
  	notify(Playernum, Governor, buf);
Newsgroups: alt.games.gb