diff -r -c xpilot-4.U.3/Local.config xpilot-VAKK1/Local.config
*** xpilot-4.U.3/Local.config	Tue Apr  6 14:16:40 1999
--- xpilot-VAKK1/Local.config	Tue Apr  6 14:25:24 1999
***************
*** 175,182 ****
        VERSION_MINOR = U
   VERSION_PATCHLEVEL = 3
      VERSION_WINDOWS = 13
!      VERSION_STATUS =
!         RELEASEDATE = Mar 21th, 1999
  
  
  /*
--- 175,182 ----
        VERSION_MINOR = U
   VERSION_PATCHLEVEL = 3
      VERSION_WINDOWS = 13
!      VERSION_STATUS = VAKK Cup 1999
!         RELEASEDATE = Apr 6th, 1999
  
  
  /*
diff -r -c xpilot-4.U.3/src/server/cmdline.c xpilot-VAKK1/src/server/cmdline.c
*** xpilot-4.U.3/src/server/cmdline.c	Tue Apr  6 14:16:40 1999
--- xpilot-VAKK1/src/server/cmdline.c	Tue Apr  6 14:18:14 1999
***************
*** 2291,2297 ****
      {
          "wreckage",
  	"wreckage",
! 	"true",
  	&useWreckage,
  	valBool,
  	tuner_dummy,
--- 2291,2300 ----
      {
          "wreckage",
  	"wreckage",
!     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
! 	"false",
! 	/* "true", */
!     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  	&useWreckage,
  	valBool,
  	tuner_dummy,
diff -r -c xpilot-4.U.3/src/server/global.h xpilot-VAKK1/src/server/global.h
*** xpilot-4.U.3/src/server/global.h	Tue Apr  6 14:16:40 1999
--- xpilot-VAKK1/src/server/global.h	Tue Apr  6 14:18:14 1999
***************
*** 253,257 ****
--- 253,273 ----
  extern int              numberOfRounds;
  #endif
  
+ /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
+ typedef struct RoundInfo {
+   int ballTime;		/* Frames for ball run - 0 if no ball run */
+   int ballPlayer;	/* Who got the ball? */
+ } RoundInfo;
+ 
+ extern char *scoreFileName;
+ extern FILE *scoreFile;
+ extern RoundInfo roundInfo;
+ 
+ void CreateScoreFile();
+ void CloseScoreFile();
+ 
+ /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
  #endif /* GLOBAL_H */
  
diff -r -c xpilot-4.U.3/src/server/netserver.c xpilot-VAKK1/src/server/netserver.c
*** xpilot-4.U.3/src/server/netserver.c	Tue Apr  6 14:16:40 1999
--- xpilot-VAKK1/src/server/netserver.c	Tue Apr  6 14:18:14 1999
***************
*** 2766,2771 ****
--- 2766,2775 ----
        break;
        
      case TEAM_CMD:
+       /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+       if (scoreFile != NULL)
+ 	fprintf(scoreFile, "Team swapped by %s.\n", pl->name);
+       /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
        Swap_team(plind,args);
        return;
        
***************
*** 2808,2813 ****
--- 2812,2824 ----
        break;
  
      case RESET_CMD:
+       /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+       if (scoreFile != NULL)
+ 	fprintf(scoreFile, "Reset by %s.\n", pl->name);
+       CloseScoreFile();
+       CreateScoreFile();
+       /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
        if (args && !strcasecmp(args,"all")) {
  	for (i=NumPlayers-1;i>=0;i--)
  	  Players[i]->score=0;
***************
*** 2867,2872 ****
--- 2878,2888 ----
  	if (!strcasecmp(args,"password"))
  	  sprintf(msg,"Operation successful.");
  	else {
+ 	  /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 	  if (scoreFile != NULL)
+ 	    fprintf(scoreFile, "Option %s set to %s by %s.\n", 
+ 		    args, cmd, pl->name);
+ 	  /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  	  sprintf(msg," < Option %s set to %s by %s. >",
  		  args,cmd,pl->name);
  	  Set_message(msg);
diff -r -c xpilot-4.U.3/src/server/player.c xpilot-VAKK1/src/server/player.c
*** xpilot-4.U.3/src/server/player.c	Tue Apr  6 14:16:41 1999
--- xpilot-VAKK1/src/server/player.c	Tue Apr  6 14:18:14 1999
***************
*** 591,596 ****
--- 591,600 ----
      int			i, j;
      char		msg[MSG_LEN];
  
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     roundInfo.ballTime = 0;
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
      updateScores = true;
  
      for (i = 0; i < NumPlayers; i++) {
***************
*** 893,898 ****
--- 897,909 ----
    return;
  }
  
+ /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ int compare_players(const void *a, const void *b)
+ {
+     return Players[*(int*)b]->score - Players[*(int*)a]->score;
+ }
+ /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
  void Team_game_over(int winning_team, const char *reason)
  {
      int			i, j;
***************
*** 901,906 ****
--- 912,943 ----
      int			*best_players;
      DFLOAT		best_ratio;
      char		msg[MSG_LEN];
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     int			p;
+     int			team;
+     int			*sorted_players;
+     int			*team_score;
+     int			max_team_num;
+ 
+     if (!(sorted_players = (int *)malloc(NumPlayers * sizeof(int)))) {
+ 	error("no mem");
+ 	End_game();
+     }
+     max_team_num = 0;
+     for (i = 0; i < NumPlayers; i++) {
+ 	if (Players[i]->team > max_team_num)
+ 	    max_team_num = Players[i]->team;
+ 	sorted_players[i] = i;
+     }
+     if (!(team_score = (int *)malloc((max_team_num + 1) * sizeof(int)))) {
+ 	error("no mem");
+ 	End_game();
+     }
+     for (i = 0; i <= max_team_num; i++)
+ 	team_score[i] = INT_MAX;
+ 
+     fprintf(scoreFile, "\nRound %d\n", roundCounter);
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  
      if (!(best_players = (int *)malloc(NumPlayers * sizeof(int)))) {
  	error("no mem");
***************
*** 914,925 ****
--- 951,969 ----
  				&best_ratio,
  				best_players);
  
+ 
      /* Print out the results of the round */
      if (winning_team != -1) {
+ 	/* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 	fprintf(scoreFile, "Team %d won the round.\n", winning_team);
+ 	/* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  	sprintf(msg, " < Team %d has won the game%s! >", winning_team,
  		reason);
  	sound_play_all(TEAM_WIN_SOUND);
      } else {
+ 	/* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 	fprintf(scoreFile, "Draw.\n", winning_team);
+ 	/* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  	sprintf(msg, " < We have a draw%s! >", reason);
  	sound_play_all(TEAM_DRAW_SOUND);
      }
***************
*** 955,960 ****
--- 999,1037 ----
  	    }
  	}
      }
+ 
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     qsort(sorted_players, NumPlayers, sizeof(int), compare_players);
+ 
+     fprintf(scoreFile, "Team\tScore\tRatio\tName\n");
+     for (i = 0; i < NumPlayers; i++) {
+ 	p = sorted_players[i];
+ 	fprintf(scoreFile, "%d\t%d\t%d/%d\t%s", 
+ 		Players[p]->team,
+ 		Players[p]->score,
+ 		Players[p]->kills,
+ 		Players[p]->deaths,
+ 		Players[p]->name);
+ 	if (roundInfo.ballTime != 0 && roundInfo.ballPlayer == p)
+ 	    fprintf(scoreFile, " (ball in %d frames)", roundInfo.ballTime);
+ 	for (j = 0; j < num_best_players; j++)
+ 	  if (best_players[j] == p)
+ 	    fputs(" (deadliest)", scoreFile);
+ 
+ 	fputc('\n', scoreFile);
+ 	team = Players[p]->team;
+ 	if (team_score[team] == INT_MAX)
+ 	  team_score[team] = 0;
+ 	team_score[team] += Players[p]->score;
+     }
+ 
+     for (i = 0; i <= max_team_num; i++) {
+       if (team_score[i] != INT_MAX)
+ 	fprintf(scoreFile, "Team %d: %d\n", i, team_score[i]);
+     }
+ 
+     fflush(scoreFile);
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  
      Reset_all_players();
  
diff -r -c xpilot-4.U.3/src/server/server.c xpilot-VAKK1/src/server/server.c
*** xpilot-4.U.3/src/server/server.c	Tue Apr  6 14:16:41 1999
--- xpilot-VAKK1/src/server/server.c	Tue Apr  6 14:28:43 1999
***************
*** 112,121 ****
--- 112,175 ----
  extern int		login_in_progress;
  extern int		NumQueuedPlayers;
  
+ /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ char *scoreFileName = NULL;
+ FILE *scoreFile = NULL;
+ RoundInfo roundInfo = { 0, 0 };
+ /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
  static void Check_server_versions(void);
  extern void Main_loop(void);
  static void Handle_signal(int sig_no);
  
+ /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ void CreateScoreFile() 
+ {
+     if (scoreFileName != NULL) {
+ 	error("scoreFileName was not NULL");
+ 	End_game();
+     }
+     if (scoreFile != NULL) {
+ 	error("scoreFile was not NULL");
+ 	End_game();
+     }
+ 
+     scoreFileName = tempnam(NULL, "vakk-");
+     if (scoreFileName == NULL) {
+ 	error("tempnam() failed, could not create scoreFileName");
+ 	End_game();
+     }
+     scoreFile = fopen(scoreFileName, "w");
+     if (scoreFile == NULL) {
+         error("fopen() failed, could not open scoreFile");
+ 	End_game();
+     }
+     xpprintf("Score file is \"%s\".\n", scoreFileName);
+ 
+     fputs("1) Fill the names of the teams below.\n", scoreFile);
+     fputs("2) Send this file to <thirsima@cc.hut.fi> with subject VAKK-RESULT\n", scoreFile);
+     fputs("3) Copy this file in a safe place.  Do not delete it after sending.\n", scoreFile);
+     
+     fputs("\nTeam 2 name: \n", scoreFile);
+     fputs("Team 4 name: \n", scoreFile);
+     fputs("\nDO NOT CHANGE ANYTHING AFTER THIS LINE\n", scoreFile);
+     
+ }
+ 
+ void CloseScoreFile()
+ {
+     if (scoreFile != NULL) {
+ 	fclose(scoreFile);
+ 	scoreFile = NULL;
+     }
+     if (scoreFileName != NULL) {
+ 	free(scoreFileName);
+ 	scoreFileName = NULL;
+     }
+ }
+ /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
+ 
  int main(int argc, char **argv)
  {
  
***************
*** 135,140 ****
--- 189,198 ----
  	      "for details see the\n"
  	   "  provided LICENSE file.\n\n");
  
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     xpprintf("This server is patched for VAKK Cup 1999.\n\n");
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
  #ifdef SUNCMW
      cmw_priv_init();
  #endif /* SUNCMW */
***************
*** 148,153 ****
--- 206,215 ----
      Find_base_direction();
      Walls_init();
  
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     CreateScoreFile();
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
      /* Allocate memory for players, shots and messages */
      Alloc_players(World.NumBases + MAX_PSEUDO_PLAYERS);
      Alloc_shots(MAX_TOTAL_SHOTS);
***************
*** 704,709 ****
--- 766,782 ----
  	Set_message(msg);
  	xpprintf("%s\n", msg);
      }
+     /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+     fputs("Game over.\n", scoreFile);
+     sprintf(msg, "Score file is \"%s\".", scoreFileName);
+     Set_message(msg);
+     xpprintf("%s\n", msg);
+     sprintf(msg, "Fill the team names in the score file before sending!", 
+ 	    scoreFileName);
+     Set_message(msg);
+     xpprintf("%s\n", msg);
+     CloseScoreFile();
+     /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
  }
  
  
diff -r -c xpilot-4.U.3/src/server/walls.c xpilot-VAKK1/src/server/walls.c
*** xpilot-4.U.3/src/server/walls.c	Tue Apr  6 14:16:41 1999
--- xpilot-VAKK1/src/server/walls.c	Tue Apr  6 14:18:15 1999
***************
*** 1003,1008 ****
--- 1003,1014 ----
  		    sprintf(msg," < The ball was loose %d frames >",
  			    LONG_MAX - mi->obj->life);
  		    Set_message(msg);
+ 
+ 		    /* BEGIN - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 		    roundInfo.ballTime = LONG_MAX - mi->obj->life;
+ 		    roundInfo.ballPlayer = GetInd[mi->obj->owner];
+ 		    /* END - VAKK Cup 1999 <thirsima@cc.hut.fi> */
+ 
  		    if (Punish_team(GetInd[mi->obj->owner],
  				    mi->obj->treasure, ms->treasure))
  			CLR_BIT(mi->obj->status, RECREATE);
