On Thu, Jun 29, 2006 at 08:57:48AM -0700, Jimmy Huang wrote:
> Hopefully this will meet all the standards of netrek
> coding. 

Attached please find my revision of your changes.  I've pushed this
through to my repository.  If you get some spare time, compare your
patch to mine to see what I did.

> I tested it for 2-3 hours the other day. And although
> there's some room for improvement, I am happy with the
> changes I made. 

It helps to describe the testing you did in the long comment, as that
would help others to review the change and verify your testing was
appropriate.

-- 
James Cameron    mailto:quozl at us.netrek.org     http://quozl.netrek.org/
-------------- next part --------------

New patches:

[Newbie robots now declare war properly in pickup games
quozl at us.netrek.org**20060630011431
 
 	Derived from Jimmy Huang's patch of the same name.
 
 	* robotd/data.c: fixed comment misspelling in int delay.  delay
 	for declaring war.
 
 	* robotd/decide.c (decide): added some comments to help me follow
 	the code better
 
 	* robotd/main.c (main): fixed up indentation of variable
 	declarations. Added switchedteams variable. Modified main()
 	function so that when a team switch occurs, declare_intents() gets
 	called after choosing a new ship.
 
 	* robotd/robot.c (reset_r_info): added some commentary on the
 	declare_intents() call, which only gets something done only if
 	someone sends a reset command to the robot.
 
 	* robotd/robot.c (send_initial): removed commented code of
 	declare_intents(). This was a bug workaround, robot sends a dummy
 	packet so it doesn't get ghostbusted.  Doesn't seem needed
 	anymore.
 
 	* robotd/update_players.c (declare_intents): added commentary on
 	how this function is supposed to work. Function will now properly
 	declare war on the 2 teams with the most players that isn't the
 	same team as yourself. And then declares peace with everyone else.
 
] 
<
> {
hunk ./Vanilla/robotd/data.c 48
 int	override = 0;
 int	doreserved = 0;
 int	lastm;
-int	delay;			/* delay for decaring war */
+int	delay;			/* delay for declaring war */
 int	rdelay;			/* delay for refitting */
 int	mapmode = 1; 
 int	namemode = 1; 
hunk ./Vanilla/robotd/decide.c 37
    if(!inl){
       if((_state.warteam < 0 || _state.total_wenemies == 0) &&
 	 _state.total_enemies > 0){
+	 /* beginning of game, no enemies */
 	 declare_intents();
 	 return;
       }
hunk ./Vanilla/robotd/decide.c 45
    else if(status->tourn){
       if((_state.warteam < 0 || _state.total_wenemies == 0) &&
 	 _state.total_enemies > 0){
+	 /* beginning of game, no enemies */
 	 declare_intents();
 	 return;
       }
hunk ./Vanilla/robotd/main.c 42
    char          **argv;
 {
    int             intrupt(), noargs = 0;
-   int		   team = 1, s_type = CRUISER;
+   int             team = 1, s_type = CRUISER;
    int             usage = 0;
    int             err = 0;
    char           *name, *ptr, *cp, *rindex();
hunk ./Vanilla/robotd/main.c 47
    int             dcore(), resetRobot();
-   void		   reaper(int), kill_rwatch(int), exitRobot(int);
+   void            reaper(int), kill_rwatch(int), exitRobot(int);
    int             passive = 0;
    char           *defaultsFile = NULL;
hunk ./Vanilla/robotd/main.c 50
-   register       i;
-   int		  rwatch=0;
-   char		  password[64];
-   int		  timer2 = 0, tryudp=1;
-   char		  **_argv = argv;
-   int		  _argc = argc;
+   register        i;
+   int             rwatch=0;
+   static int      switchedteams=0;
+   char            password[64];
+   int             timer2 = 0, tryudp=1;
+   char          **_argv = argv;
+   int             _argc = argc;
 
    if(argc == 1)
       printUsage(argv[0]);
hunk ./Vanilla/robotd/main.c 404
 
    mprintf("team ...\n");
    if(!teamRequest(team, s_type)){
+      switchedteams = 1;
       mprintf("team or ship rejected.\n");
 
       /* if base destroyed */
hunk ./Vanilla/robotd/main.c 436
 	    timer2 = 0;
 	    _state.team = team;
 	    if (!teamRequest(team, s_type)){
-               mfprintf(stderr, "team or ship rejected.\n");
-               showteams();
+	       switchedteams = 1;
+	       mfprintf(stderr, "team or ship rejected.\n");
+	       showteams();
 	    }
 	    else 
 	       break;
hunk ./Vanilla/robotd/main.c 464
    if((_state.try_udp || tryudp) && commMode != COMM_UDP){
       sendUdpReq(COMM_UDP);
    }
+
+   if (switchedteams) {
+      switchedteams = 0;
+      declare_intents();
+   }
 
    input();
 }
hunk ./Vanilla/robotd/robot.c 2005
       strcpy(_state.ignore_e, ignore_e);
 
       bzero(&_timers, sizeof(_timers));
+
+      /* only happens when robot is dead or when someone sends a reset
+      command to the robot.  If robot is dead, declare_intents does
+      nothing. */
       declare_intents();
       req_cloak_off("reset");
       return 1;
hunk ./Vanilla/robotd/robot.c 2072
 
    sendUpdatePacket((int)(_state.timer_delay_ms * 100000.));
    init_comm();
-   /*
-   declare_intents();
-   */
 }
 
 ignore_edefault(s)
hunk ./Vanilla/robotd/update_players.c 1027
 }
 
 /* war & peace.  Done initially */
-/* BUGS */
 
hunk ./Vanilla/robotd/update_players.c 1028
+/* When you first enter the game 10 seconds in, the robot will declare
+   war on the top 2 teams with most players.  If the robot is a 3rd
+   team scummer, it works out quite nicely.
+
+   Will also declare war correctly when forced to join a different
+   team, say during timercide.  Then winners keep their old war
+   declarations (which is the right thing to do), as they don't get
+   forced to join a different team.
+
+   Doesn't work when you lose t-mode and people join back in on
+   different teams, as the function to check for this condition
+   doesn't exist, yet. */
 declare_intents()
 {
    register			i;
hunk ./Vanilla/robotd/update_players.c 1044
    register struct player	*j;
-   int				teams[16], maxt = 0;
+   int				teams[16], maxt=0, maxcount=0;
+   int				maxt2=0, maxcount2=0;
    int				newhostile, pl=0;
    extern char			*team_to_string();
 
hunk ./Vanilla/robotd/update_players.c 1068
       pl++;
    }
 
+   if (!pl) return;
+
    if(pl){
hunk ./Vanilla/robotd/update_players.c 1071
-      for(i=1; i< 9; i *= 2)
-	 if(teams[i] > maxt)
+      for(i=1; i< 9; i *= 2) {
+	 if(teams[i] > maxcount) {
 	    maxt = i;
hunk ./Vanilla/robotd/update_players.c 1074
+	    maxcount = teams[i];
+	 }
+      }
       mprintf("max team = %s\n", team_to_string(maxt));
hunk ./Vanilla/robotd/update_players.c 1078
+      for(i=1; i< 9; i *= 2) {
+	 if( (teams[i] > maxcount2) && (i != maxt) ) {
+	    maxt2 = i;
+	    maxcount2 = teams[i];
+	 }
+      }
+      mprintf("max team2 = %s\n", team_to_string(maxt2));
    }
hunk ./Vanilla/robotd/update_players.c 1086
-   /*
-   else
-      maxt = -1;
-      */
 
    /* peace */
    for(i=1; i< 9; i *= 2){
hunk ./Vanilla/robotd/update_players.c 1089
-      if(i == maxt) continue;
+      if(i == maxt || i == maxt2) continue;
       if((i & me->p_hostile) && !(i & me->p_swar)){
hunk ./Vanilla/robotd/update_players.c 1091
+	 /* is hostile to and not at war with */
 	 mprintf("declaring peace with %s\n", team_to_string(i));
 	 newhostile ^= i;
       }
hunk ./Vanilla/robotd/update_players.c 1099
    _state.warteam = maxt;
    
    /* war */
-   if(maxt != -1){
-      if(!((maxt & me->p_swar) || (maxt & me->p_hostile))){
+   if(maxt != 0) {
+      if(!((maxt & me->p_swar) && !(maxt & me->p_hostile))) {
 	 mprintf("declare war with %s\n", team_to_string(maxt));
hunk ./Vanilla/robotd/update_players.c 1102
-	 newhostile ^= maxt;
+	 newhostile |= maxt;
       }
    }
hunk ./Vanilla/robotd/update_players.c 1105
+
+   /* Being hostile to more teams is better than less teams. */
+   if(maxt2 != 0) {
+      if(!((maxt2 & me->p_swar) && !(maxt2 & me->p_hostile))) {
+	 mprintf("declare war with %s\n", team_to_string(maxt2));
+	 newhostile |= maxt2;
+      }
+   }
+
    if(newhostile != me->p_hostile)
       sendWarReq(newhostile);
 }
}

Context:

[continuum ban vote tweaks 2006-06
quozl at us.netrek.org**20060622015354
 Following review of continuum recording 2006-06-07-22-00:
 - require four votes to ban instead of two, to defeat ban scumming,
 - expire ban votes within two minutes instead of ten,
 - expire eject votes within five minutes instead of ten.
] 
[xtkill ship change fixes
williamb at its.caltech.edu**20060620005009
          * tools/xtkill.c: Adds the ability to set ship to galaxy class, removes unneccessary
            ship size change for ATT, and updates the list of valid ship types to include
            the super SC with 1 point torps (this was missing from list of valid ship types).
 M ./Vanilla/tools/xtkill.c -8 +5
] 
[newbie-observer-ports.dpatch
jimmyhua73 at yahoo.com**20060616103448
 
 	* docs/sample_ports added observer port definitions for
 	newbie server. Added commentary to make it easier to configure
 	the port configuration for a newbie server setup. 
 
] 
[Chaos mode starbase enhancements
williamb at its.caltech.edu**20060606200821
          * orbit.c, transwarp.c: Allows starbases to transwarp to and dock with other
            bases if chaos mode is activated.
] 
[Twarp message fix
williamb at its.caltech.edu**20060606200652
          * transwarp.c: Fixes outdated reference to transwarp hours.
] 
[ATT and invalid ship fixes
williamb at its.caltech.edu**20060603092650
       * getentry.c, main.c: allow listing of ATT on features screen, and allow player to select 
         ATT from entry window if ship is defined in sysdef as a valid ship.  Also fixes incorrect
         error message in the case of invalid ship type.
] 
[null-terminate-mapchars-indentfix
Stephen Thorne <stephen at thorne.id.au>**20060614103104] 
[null-terminate-mapchars
jimmyhua73 at yahoo.com**20060614105540
 
 	* robotd/struct.h modify mapchars to 3 characters to hold the NULL
 	at the end
 
 	* robotd/enter.c initialize final character to be NULL at the end
 	when the robot first enters the game. 
 
 
] 
[robotd-improved-army-tracking.dpatch
jimmyhua73 at yahoo.com**20060613104425
 
         * INSTALL.Newbie updated installation documentation to reflect
         changes in code. Also, CONFIRM=0 only works, CONFIRM=2 does not
         work.
 
         * INSTALL.Newbie added toggle robdc, assume robots don't carry.
         Also added lookahead=0 to emulate how robots were before Trent
         fixed the torp-dir bug.
 
         * robotd/data.c added extern int robdc (robots don't carry)
 
         * robotd/data.h extern int robdc defaults to not activated.
 
         * robotd/data.h added compiler define NO_PFORBIT, so robot
         doesn't depend on PFORBIT flag to determine if someone is picking
         armies or not.
 
         * robotd/dmessage.c added robdc in help. added robdc in messaging
         logic.
 
         * robotd/update_players.c commented out a continue; statement
         as the for loop gets exited too quickly sometimes.
 
         * robotd/update_players.c stale information of p->closest_pl is
         kept even when enemy becomes invisible. Will be used later.
 
         * robotd/update_players.c don't update last x or y if invisible.
 
         * robotd/update_players.c changes to check_orbit() function to
         make sure players is marked as orbiting a planet when cloaked near
         a planet, or invisible.
 
         * robotd/update_players.c changed some debug statements to make
         them more readable during a denemy debug session.
 
         * robotd/update_players.c army_check1() and army_check2() added
         logic so if robdc is activated, robot doesn't track fellow
         robot carriers.
 
         * robotd/update_players.c added some commentary so the army
         tracking code is more readble. Commented out a beam-down to
         friendly in favor of the more pessimistic possibility that
         the planet simply popped.
 
] 
[Cross-transwarp check
williamb at its.caltech.edu**20060608223709
     * transwarp.c: Prevent transwarping to a base that is already in transwarp.
] 
[post 2.11.1 release process notes
quozl at us.netrek.org**20060601040643] 
[include config.guess in make dist
quozl at us.netrek.org**20060601033548] 
[include config.sub in make dist
quozl at us.netrek.org**20060601033011] 
[TAG 2.11.1
quozl at us.netrek.org**20060601025406] 
Patch bundle hash:
8ecdd6780183d9777e3ff655913f26b794f0416b
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.us.netrek.org/pipermail/netrek-dev/attachments/20060630/f2f85b94/attachment.pgp