From: bharat@shadow.Eng.Sun.COM (Bharat Mediratta)
Newsgroups: rec.games.netrek
Subject: Re: Server Bug (PATCH)
Date: 26 Jan 1993 00:45:14 GMT
Organization: Sun Microsystems, Inc.
Distribution: world
Reply-To: bharat@shadow.Eng.Sun.COM
NNTP-Posting-Host: shadow

In article u00VAzA5yXIK@andrew.cmu.edu, gc2n+@andrew.cmu.edu (Greg K Chung) writes:
> 
> We recently found on bronco.ece (and therefore many other servers) a
> disturbing bug:
> 
> A SB, doing nothing, at 60K fuel.
> A BB, doing nothing, docks on the SB.  Nothing extraordinary happens.
> 
> BUT:  When the BB turns its shields on, even at full fuel, and still
> doing nothing (SB shields down, doing nothing) the SB LOSES FUEL.  
> 
> Given that the BB generates enough fuel for its own shields at warp 0,
> and the SB more then generates that much, how can the net effect be a
> LOSS of fuel?
> 
> This effect is probably prevalent elsewhere with regards to other
> ships.  Who knows. 
> 
> 
> Rear Admiral "#10 Base" Stiletto

Yes, I noticed this problem a while back and patched it on my
server.  The bug goes something like this:

	Instead of realizing that the fuel recharged by the ship
cancels the fuel lost in using shields, the daemon works by
a step by step algorithm that first USES the fuel and then replenishes
it.  Normally:

	1) ship uses X fuel for shields, torps, phasers, etc.
	2) ship regains Y fuel under normal recharge circumstances
	3) if ship has more than MAX fuel, it's limited to MAX

However, step two looks like this:

	1) Take fuel from a fuel planet or SB
	2) If we need more, take it from our normal recharge quota.

So what happens is that the ship loses fuel for the shields, and takes
it from the SB instead of from it's own recharge.  Here's the patch to
fix that:

--------- PATCH BEGINS -----------
in daemonII.c change:

                /* Add fuel */
                if ((j->p_flags & PFORBIT) &&
                    (planets[j->p_planet].pl_flags & PLFUEL) &&
                    (!(planets[j->p_planet].pl_owner 
                        & (j->p_swar | j->p_hostile)))) {
                            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) {
                        j->p_fuel += 12*j->p_ship.s_recharge;
                        players[j->p_docked].p_fuel -= 12*j->p_ship.s_recharge;
                    }
                } else
                    j->p_fuel += 2 * j->p_ship.s_recharge;

to:


                /* Add fuel */
                j->p_fuel += 2 * j->p_ship.s_recharge;
                        
                if ((j->p_flags & PFORBIT) &&
                        (planets[j->p_planet].pl_flags & PLFUEL) &&
                        (!(planets[j->p_planet].pl_owner 
                           & (j->p_swar | j->p_hostile)))) {
                    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) {
                                j->p_fuel += 12*j->p_ship.s_recharge;
                                players[j->p_docked].p_fuel -= 12*j->p_ship.s_recharge;
                        }
                }
---------- PATCH ENDS ---------------

I'd provide diffs, but my server has been hacked so much that it wouldn't help
much.

		-Bharat

P.S.	Tedd --  I think this solves the problem that we saw on vlsi the other
	day with two SB's docked on each other.


---
    /\        Bharat Mediratta
   \\ \       Graphics Continuation Group
  \ \\ /      
 / \/ / /     
/ /   \//\    SUN Microsystems, Inc.	
\//\   / /    Mailstop: MTV18-218
 / / /\ /     2550 Garcia Avenue, Building 18
  / \\ \      Mountain View, CA 94043
   \ \\       Phone:  (415)336-4347, FAX:(415)336-5471
    \/        Email:  bharat.mediratta@eng.sun.com