Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/robots



Date:	Monday June 21, 1999 @ 21:06
Author:	unbelver

Update of /home/netrek/cvsroot/Vanilla/robots
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv7875/robots

Modified Files:
	inl.c 
Log Message:

This is to add geno checking in the INL robot.

INL robot will now see geno correctly and end the game accordingly.

1 possible race condition.  If losing team has armies in flight and
drops army(ies) on the just neuted last planet before INL robot gets
its next time slice, robot will miss the geno.

Which begs the question that Cameron brought up:  If there are still
losing side armies in flight, is that really a geno?

--Carlos V.




****************************************

Index: Vanilla/robots/inl.c
diff -u Vanilla/robots/inl.c:1.19 Vanilla/robots/inl.c:1.20
--- Vanilla/robots/inl.c:1.19	Fri Jun 18 15:52:04 1999
+++ Vanilla/robots/inl.c	Mon Jun 21 21:06:24 1999
@@ -1,7 +1,7 @@
-/* 	$Id: inl.c,v 1.19 1999/06/18 20:52:04 unbelver Exp $	 */
+/* 	$Id: inl.c,v 1.20 1999/06/22 02:06:24 unbelver Exp $	 */
 
 #ifndef lint
-static char vcid[] = "$Id: inl.c,v 1.19 1999/06/18 20:52:04 unbelver Exp $";
+static char vcid[] = "$Id: inl.c,v 1.20 1999/06/22 02:06:24 unbelver Exp $";
 #endif /* lint */
 
 /*
@@ -80,6 +80,7 @@
 Inl_countdown inl_countdown =
 {0,{60,30,10,5,4,3,2,1,0,-1},8,0,PERSEC,NULL,""};
 
+int checkgeno();
 int end_tourney();
 Inl_countdown inl_game =
 {0,{2700,600,300,120,60,30,10,5,4,3,2,1,0,-1},12,0,PERSEC,end_tourney,""};
@@ -210,6 +211,153 @@
     }
 }
 
+typedef struct playerlist {
+    char name[NAME_LEN];
+    char mapchars[2];
+    int planets, armies;
+} Players;
+
+
+static void displayBest(FILE *conqfile, int team, int type)
+{
+    register int i,k,l;
+    register struct player *j;
+    int planets, armies;
+    Players winners[MAXPLAYER+1];
+    char buf[MSG_LEN];
+    int number;
+
+    number=0;
+    MZERO(winners, sizeof(Players) * (MAXPLAYER+1));
+    for (i = 0, j = &players[0]; i < MAXPLAYER; i++, j++) {
+        if (j->p_team != team || j->p_status == PFREE) continue;
+#ifdef GENO_COUNT
+        if (type==KWINNER) j->p_stats.st_genos++;
+#endif
+        if (type == KGENOCIDE) {
+            planets=j->p_genoplanets;
+            armies=j->p_genoarmsbomb;
+            j->p_genoplanets=0;
+            j->p_genoarmsbomb=0;
+        } else {
+            planets=j->p_planets;
+            armies=j->p_armsbomb;
+        }
+        for (k = 0; k < number; k++) {
+            if (30 * winners[k].planets + winners[k].armies < 
+                30 * planets + armies) {
+	      /* insert person at location k */
+                break;
+            }
+        }
+        for (l = number; l >= k; l--) {
+            winners[l+1] = winners[l];
+        }
+        number++;
+        winners[k].planets=planets;
+        winners[k].armies=armies;
+        STRNCPY(winners[k].mapchars, j->p_mapchars, 2);
+        STRNCPY(winners[k].name, j->p_name, NAME_LEN);
+        winners[k].name[NAME_LEN-1]=0;  /* `Just in case' paranoia */
+    }
+    for (k=0; k < number; k++) {
+      if (winners[k].planets != 0 || winners[k].armies != 0) {
+            sprintf(buf, "  %16s (%2.2s) with %d planets and %d armies.", 
+                winners[k].name, winners[k].mapchars, winners[k].planets, winners[k].armies);
+            pmessage(0, MALL | MCONQ, " ",buf);
+            fprintf(conqfile, "  %s\n", buf);
+      }
+    }
+    return;
+}
+
+
+static void genocideMessage(int loser, int winner)
+{
+    char buf[MSG_LEN];
+    FILE *conqfile;
+    time_t curtime;
+
+    conqfile=fopen(ConqFile, "a");
+
+    /* TC 10/90 */
+    time(&curtime);
+    strcpy(buf,"\nGenocide! ");
+    strcat(buf, ctime(&curtime));
+    fprintf(conqfile,"  %s\n",buf);
+
+    pmessage(0, MALL | MGENO, " ","%s",
+        "***********************************************************");
+    sprintf(buf, "%s has been genocided by %s.", inl_teams[loser].t_name,
+       inl_teams[winner].t_name);
+    pmessage(0, MALL | MGENO, " ","%s",buf);
+        
+    fprintf(conqfile, "  %s\n", buf);
+    sprintf(buf, "%s:", inl_teams[winner].t_name);
+    pmessage(0, MALL | MGENO, " ","%s",buf);
+    fprintf(conqfile, "  %s\n", buf);
+    displayBest(conqfile, inl_teams[winner].side, KGENOCIDE);
+    sprintf(buf, "%s:", inl_teams[loser].t_name);
+    pmessage(0, MALL | MGENO, " ","%s",buf);
+    fprintf(conqfile, "  %s\n", buf);
+    displayBest(conqfile, inl_teams[loser].side, KGENOCIDE);
+    pmessage(0, MALL | MGENO, " ","%s",
+        "***********************************************************");
+    fprintf(conqfile, "\n");
+    fclose(conqfile);
+}
+
+
+int 
+checkgeno()
+{
+    register int i;
+    register struct planet *l;
+    struct planet *homep = NULL;
+    struct player *j;
+    int loser, winner;
+
+    for (i = 0; i <= MAXTEAM; i++) /* maint: was "<" 6/22/92 TC */
+        teams[i].s_plcount = 0;
+
+    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
+        teams[l->pl_owner].s_plcount++; /* for now, recompute here */
+    }
+
+    if (teams[inl_teams[HOME].side].s_plcount == 0) 
+      {
+	loser = HOME;
+	winner = AWAY;
+      }
+    else if (teams[inl_teams[AWAY].side].s_plcount == 0)
+           {       
+	     loser = AWAY;
+	     winner = HOME;
+	   }
+         else
+           return 0;
+
+
+    /* Tell winning team what wonderful people they are (pat on the back!) */
+    genocideMessage(loser, winner);
+    /* Give more troops to winning team? */
+
+    /* kick out all the players on that team */
+    /* makes it easy for them to come in as a different team */
+    for (i = 0, j = &players[0]; i < MAXPLAYER; i++, j++) {
+      if (j->p_status == PALIVE && j->p_team == loser) {
+	j->p_status = PEXPLODE;
+	if (j->p_ship.s_type == STARBASE)
+	  j->p_explode = 2*SBEXPVIEWS/PLAYERFUSE;
+	else
+	  j->p_explode = 10/PLAYERFUSE;
+	j->p_whydead = KGENOCIDE;
+	j->p_whodead = inl_teams[winner].captain;
+      }
+    }
+    return 1;
+}
+
 void
 inlmove()
 {
@@ -277,6 +425,9 @@
   if (!(inl_stat.game_ticks % TIMEFUSE))
     countdown(inl_stat.game_ticks, &inl_game);
 
+  /* check for geno and end game if there is */
+  if (checkgeno()) end_tourney();
+
 #ifdef INLDEBUG
   ERROR(2,("	game ticks = %d\n", inl_stat.game_ticks));
 #endif
@@ -666,7 +817,7 @@
   inl_teams[AWAY].planets = 10;
 
   /* Set player queues back to standard starting teams */
-  if (!is_end_tourney) {
+  if (is_end_tourney) {
     queues[QU_HOME].tournmask = FED;
     queues[QU_AWAY].tournmask = ROM;
     queues[QU_HOME_OBS].tournmask = FED;