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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2728) Game ends after Tech is researched
From: "ue80@xxxxxxxxxxxxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Mon, 27 Jan 2003 14:13:14 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Mon, Jan 13, 2003 at 06:03:44PM -0800, Jason Short via RT wrote:
> 
> [ue80@xxxxxxxxxxxxxxxxxxxxx - Sun Jan  5 12:21:10 2003]:
> 
> > 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
> 
> Should this be a server option or part of the ruleset?  Doesn't this
> question come up for every new game option these days?
> 
> Aside from that, the only issue I have is that the tech string should
> only be looked up once - when the game starts (or when the ruleset is
> loaded).  So game.endtech should be a Tech_Type_Id.

Even if Per said thumbs down i updated it ...

Thomas
-- 
Thomas Strub  ***  eMail ue80@xxxxxxxxxxxxxxxxxxxxx
Wenn Du nicht programmieren kannst und Dir für Arbeit zu schade bist:
Werde Berater, Analyst oder organisiere Kongresse.

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.155
diff -u -r1.155 game.c
--- common/game.c       2003/01/09 02:36:37     1.155
+++ common/game.c       2003/01/27 22:09:25
@@ -656,6 +656,8 @@
   game.pingtimeout   = GAME_DEFAULT_PINGTIMEOUT;
   game.pingtime      = GAME_DEFAULT_PINGTIME;
   game.end_year      = GAME_DEFAULT_END_YEAR;
+  game.end_tech_id   = GAME_DEFAULT_END_TECH_ID;
+  sz_strlcpy(game.end_tech,"");
   game.year          = GAME_START_YEAR;
   game.turn          = 0;
   game.min_players   = GAME_DEFAULT_MIN_PLAYERS;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.118
diff -u -r1.118 game.h
--- common/game.h       2003/01/05 23:24:52     1.118
+++ common/game.h       2003/01/27 22:09:25
@@ -75,6 +75,8 @@
   int pingtime;
   time_t turn_start;
   int end_year;
+  char end_tech[MAX_LEN_NAME];
+  Tech_Type_id end_tech_id;
   int year;
   int turn;
   int researchcost; /* Multiplier on cost of new research */
@@ -289,6 +291,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_ID -1
 
 #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.105
diff -u -r1.105 savegame.c
--- server/savegame.c   2003/01/16 18:23:36     1.105
+++ server/savegame.c   2003/01/27 22:09:26
@@ -1774,6 +1774,10 @@
        secfile_lookup_int_default(file, 1, "game.timeoutcounter");
 
     game.end_year      = secfile_lookup_int(file, "game.end_year");
+    game.end_tech_id =
+       secfile_lookup_int_default(file, GAME_DEFAULT_END_TECH_ID,
+                                   "game.end_tech_id");
+    
     game.researchcost  = secfile_lookup_int_default(file, 0, 
"game.researchcost");
     if (game.researchcost == 0)
       game.researchcost = secfile_lookup_int(file, "game.techlevel");
@@ -2163,6 +2167,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_int(file, game.end_tech_id, "game.end_tech_id");
   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.112
diff -u -r1.112 srv_main.c
--- server/srv_main.c   2003/01/05 23:24:52     1.112
+++ server/srv_main.c   2003/01/27 22:09:27
@@ -204,6 +204,17 @@
     return TRUE;
   }
 
+  /* we end the game after someone has the tech from tech_end */
+  players_iterate(pplayer) {
+    /* tech??? */
+    if ((game.end_tech_id >= 0) && 
+       (base_total_bulbs_required(pplayer,game.end_tech_id) <= 0))
+    { 
+      freelog(LOG_ERROR,"Endyear: %d, %d",game.year, game.end_tech_id); 
+      return TRUE;
+    }
+  } players_iterate_end;
+
   /* count barbarians */
   players_iterate(pplayer) {
     if (is_barbarian(pplayer)) {
@@ -2111,6 +2122,16 @@
     } players_iterate_end;
   }
   
+  /* Because we can't lookup this before the game has been started we do it 
+   * here */
+  game.end_tech_id = find_tech_by_name(game.end_tech);
+  if (game.end_tech_id == 200) { 
+    game.end_tech_id = -1;
+  } 
+  if (game.end_tech_id > 0) {
+  sz_strlcpy(game.end_tech,get_tech_name(NULL,game.end_tech_id));
+  }
+
   /* We want to reset the timer as late as possible but before the info is
    * sent to the clients */
   game.turn_start = time(NULL);
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.270
diff -u -r1.270 stdinhand.c
--- server/stdinhand.c  2003/01/20 15:44:28     1.270
+++ server/stdinhand.c  2003/01/27 22:09:29
@@ -691,7 +691,11 @@
   GEN_INT("endyear", game.end_year, SSET_META, SSET_TO_CLIENT,
          N_("Year the game ends"), "", NULL, 
          GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR)
-
+/*
+  GEN_INT("endtechid", game.end_tech_id, SSET_META, SSET_TO_CLIENT,
+         N_("Tech with that the game ends"), "",  
+         NULL, 0, 200,GAME_DEFAULT_END_TECH_ID)
+*/
 #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,28 @@
 }
 
 /**************************************************************************
+This function gets the Name of a written tech.
+Only works after the game has been started.
+**************************************************************************/
+static void set_end_tech(struct connection *caller, char *arg)
+{
+  sz_strlcpy(game.end_tech, arg);
+  game.end_tech_id = find_tech_by_name(game.end_tech);
+  freelog(LOG_VERBOSE,"Endtech_id %d from %s",game.end_tech_id, game.end_tech);
+  if (game.end_tech_id == 200) { 
+    game.end_tech_id = -1;
+  } 
+  if (game.end_tech_id > 0) {
+  sz_strlcpy(game.end_tech,get_tech_name(NULL,game.end_tech_id));
+  cmd_reply(CMD_ENDTECH, caller, C_OK,
+             _("Endtech set to: %s."), game.end_tech);
+  } else {
+  cmd_reply(CMD_ENDTECH, caller, C_OK,
+              _("Error finding endtech: %s. (Could be because techs.ruleset 
isn't loaded already)"), game.end_tech);
+  }
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void create_ai_player(struct connection *caller, char *arg)
@@ -3195,6 +3228,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]