[Tux4kids-commits] r1380 - tuxmath/branches/lan/src

David Bruce dbruce-guest at alioth.debian.org
Wed Aug 5 22:06:54 UTC 2009


Author: dbruce-guest
Date: 2009-08-05 22:06:54 +0000 (Wed, 05 Aug 2009)
New Revision: 1380

Modified:
   tuxmath/branches/lan/src/game.c
Log:
some refinement of comet-adding code

Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c	2009-08-05 21:09:29 UTC (rev 1379)
+++ tuxmath/branches/lan/src/game.c	2009-08-05 22:06:54 UTC (rev 1380)
@@ -1662,8 +1662,8 @@
   /* ease of understanding, we should do it at the same place in the game */
   /* loop for the non-LAN (i.e. local MC_*() functions) game - DSB        */
   /* add more comets if needed: */
-  if (!Opts_HelpMode() && level_start_wait == 0)// &&
-//      (frame % 20) == 0)   /* NOTE - this interferes with LAN timing */
+  if (!Opts_HelpMode() && level_start_wait == 0) //&&
+     // (frame % 20) == 0)
   {
     /* num_attackers is how many comets are left in wave */
     if (num_attackers > 0)
@@ -2764,7 +2764,8 @@
     }
     else  /* non-living comet so we found a free slot: */
     {
-      found = i;      
+      found = i;
+      break;
     }
   }
 
@@ -2793,18 +2794,31 @@
    /* time we happen to need it to make a new comet. So I'm commenting out        */
    /* the 'say_to_server()' call as well - DSB                                     */
 #ifdef HAVE_LIBSDL_NET
-    for (comet_counter; comet_counter < TEST_COMETS; comet_counter++)
+    for (i = 0; i < TEST_COMETS; i++)
      {
-       if(comets_questions[comet_counter].question_id != -1)
+       if(comets_questions[comet_counter % TEST_COMETS].question_id != -1)
        {
-         copy_card(&(comets_questions[comet_counter]), &(comets[found].flashcard)); //will be replaced on set up of new system
+         copy_card(&(comets_questions[comet_counter % TEST_COMETS]), &(comets[found].flashcard)); //will be replaced on set up of new system
          comet_counter++;
          break;
        }
      }
-     if(comet_counter==TEST_COMETS)
-       comet_counter = 0;
+     if(comet_counter > TEST_COMETS)
+       comet_counter -= TEST_COMETS;
+     if(i == TEST_COMETS)
+       return 0;
+     
 #endif
+
+     /* Make sure question is "sane" before we add it: */
+     if( (comets[found].flashcard.answer > 999)
+       ||(comets[found].flashcard.answer < -999))
+     {
+       printf("Warning, card with invalid answer encountered: %d\n",
+              comets[found].flashcard.answer);
+       return 0;
+     }
+
      /* If we make it to here, create a new comet!*/
      comets[found].answer = comets[found].flashcard.answer;
      comets[found].alive = 1;
@@ -2844,14 +2858,15 @@
 #endif
      }
 
-  #ifdef TUXMATH_DEBUG
-      printf ("\nadd_comet(): formula string is: %s", comets[found].flashcard.formula_string);
-  #endif
+#ifdef TUXMATH_DEBUG
+      printf ("\nadd_comet(): formula string is: %s",
+              comets[found].flashcard.formula_string);
+      print_current_quests();
+#endif
 
      /* Record the time at which this comet was created */
      comets[found].time_started = SDL_GetTicks();
 //   }
-  print_current_quests();
   /* comet slot found and question found so return successfully: */
   return 1;
 }




More information about the Tux4kids-commits mailing list