Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2728) Game ends after Tech is researched
Home

[Freeciv-Dev] (PR#2728) Game ends after Tech is researched

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2728) Game ends after Tech is researched
From: "ue80@xxxxxxxxxxxxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 5 Jan 2003 04:21:10 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Hi,

i've written a small patch that the game ends after a given tech is
researched. 

I wanted to do it:
set endtech "The Republic" but i didn't know how to get the space in.

So the commando is:
endtech The Republic

If its written wrong game will end at endyear otherwise it will end the
turn after the tech is researched with "Endyear YYYY"

Perhaps its useful for someone.
I used it to find the cases where AI needs to much time to get Rep.

Thomas
-- 
Thomas Strub  ***  eMail ue80@xxxxxxxxxxxxxxxxxxxxx
Nur weil das Aufzeichnen, Kopieren und Schnüffeln bei elektronischem 
Datenverkehr leichter als bei der klassischen Post ist, darf man es nicht
einfach tun.

Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.117
diff -u -r1.117 game.h
--- common/game.h       2002/12/18 17:36:19     1.117
+++ common/game.h       2003/01/04 15:51:19
@@ -75,6 +75,7 @@
   int pingtime;
   time_t turn_start;
   int end_year;
+  char end_tech[MAX_LEN_NAME];
   int year;
   int turn;
   int researchcost; /* Multiplier on cost of new research */
@@ -293,6 +294,8 @@
 #define GAME_DEFAULT_END_YEAR    2000
 #define GAME_MIN_END_YEAR        GAME_START_YEAR
 #define GAME_MAX_END_YEAR        5000
+
+#define GAME_DEFAULT_END_TECH " "
 
 #define GAME_DEFAULT_MIN_PLAYERS     1
 #define GAME_MIN_MIN_PLAYERS         1
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.101
diff -u -r1.101 savegame.c
--- server/savegame.c   2002/12/11 10:39:43     1.101
+++ server/savegame.c   2003/01/04 15:51:20
@@ -1762,6 +1762,10 @@
        secfile_lookup_int_default(file, 1, "game.timeoutcounter");
 
     game.end_year      = secfile_lookup_int(file, "game.end_year");
+    sz_strlcpy(game.end_tech,
+       secfile_lookup_str_default(file, GAME_DEFAULT_END_TECH,
+                                   "game.end_tech"));
+    
     game.researchcost  = secfile_lookup_int_default(file, 0, 
"game.researchcost");
     if (game.researchcost == 0)
       game.researchcost = secfile_lookup_int(file, "game.techlevel");
@@ -2153,6 +2157,7 @@
   secfile_insert_int(file, game.timeoutincmult, "game.timeoutincmult"); 
   secfile_insert_int(file, game.timeoutcounter, "game.timeoutcounter"); 
   secfile_insert_int(file, game.end_year, "game.end_year");
+  secfile_insert_str(file, game.end_tech, "game.end_tech");
   secfile_insert_int(file, game.year, "game.year");
   secfile_insert_int(file, game.turn, "game.turn");
   secfile_insert_int(file, game.researchcost, "game.researchcost");
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.110
diff -u -r1.110 srv_main.c
--- server/srv_main.c   2002/12/18 17:36:20     1.110
+++ server/srv_main.c   2003/01/04 15:51:21
@@ -195,7 +195,12 @@
   int barbs = 0, alive = 0;
   bool all_allied;
   struct player *victor = NULL;
+  Tech_Type_id tech_id;
+  
+  /* sz_strlcpy(game.end_tech, "The Republic"); */
 
+  tech_id = find_tech_by_name(game.end_tech);
+
   /* quit if we are past the year limit */
   if (game.year > game.end_year) {
     notify_conn(&game.est_connections, 
@@ -203,6 +208,17 @@
     gamelog(GAMELOG_NORMAL, _("Game ended in a draw as end year exceeded"));
     return TRUE;
   }
+
+  /* we end the game after someone has the tech from tech_end */
+  players_iterate(pplayer) {
+    /* tech??? */
+    if (base_total_bulbs_required(pplayer,tech_id) <= 0)
+    { 
+      freelog(LOG_ERROR,"Endyear: %d",game.year); 
+      return TRUE;
+    }
+  } players_iterate_end;
+  
 
   /* count barbarians */
   players_iterate(pplayer) {
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.269
diff -u -r1.269 stdinhand.c
--- server/stdinhand.c  2002/12/21 09:45:42     1.269
+++ server/stdinhand.c  2003/01/04 15:51:23
@@ -692,6 +692,10 @@
          N_("Year the game ends"), "", NULL, 
          GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR)
 
+/*  GEN_STRING("endtech", game.end_tech, SSET_META, SSET_TO_CLIENT,
+         N_("Tech with that the game ends"), "",  
+         NULL, GAME_DEFAULT_END_TECH)
+*/
 #ifndef NDEBUG
   GEN_INT( "timeout", game.timeout, SSET_META, SSET_TO_CLIENT,
           N_("Maximum seconds per turn"),
@@ -959,6 +963,7 @@
   CMD_METAINFO,
   CMD_METACONN,
   CMD_METASERVER,
+  CMD_ENDTECH,
   CMD_AITOGGLE,
   CMD_CREATE,
   CMD_EASY,
@@ -1124,6 +1129,12 @@
    N_("metaserver <address>"),
    N_("Set address for metaserver to report to."), NULL
   },
+  {"endtech",ALLOW_CTRL,
+   /* TRANS: translate text between <> only */
+   N_("endtech techname"),
+   N_("Set the tech with that the game will end.\n" 
+      "It must be written like the Rulesettechname."), NULL
+  },  
   {"aitoggle", ALLOW_CTRL,
    /* TRANS: translate text between <> only */
    N_("aitoggle <player-name>"),
@@ -1740,6 +1751,16 @@
 }
 
 /**************************************************************************
+This function gets the Name of a writen tech.
+**************************************************************************/
+static void set_end_tech(struct connection *caller, char *arg)
+{
+  sz_strlcpy(game.end_tech, arg);
+  cmd_reply(CMD_ENDTECH, caller, C_OK,
+             _("Endtech set to: %s."), game.end_tech);
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void create_ai_player(struct connection *caller, char *arg)
@@ -3195,6 +3216,9 @@
     break;
   case CMD_LIST:
     show_list(caller, arg);
+    break;
+  case CMD_ENDTECH:
+    set_end_tech(caller, arg);
     break;
   case CMD_AITOGGLE:
     toggle_ai_player(caller,arg);

[Prev in Thread] Current Thread [Next in Thread]