Complete.Org: Mailing Lists: Archives: freeciv-dev: March 1999:
[Freeciv-Dev] patch: Railroad from Great Library
Home

[Freeciv-Dev] patch: Railroad from Great Library

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] patch: Railroad from Great Library
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Wed, 17 Mar 1999 23:28:31 +1100

Patrick Smith wrote:

> An unrelated question:  I notice that when one acquires railroads
> from the Great Library, railroads are not created in one's cities
> automatically.  Is this the intended behaviour?

I'd say a bug.  The code to gain tech (in various ways) 
is scattered around and rather ugly, with quite a bit of 
cut-and-pastage.  I've been meaning to clean it up for
ages (at least put it in some functions), but for lack of
round tuits...

I hesitate to do a significant cleanup now, since this is 
not a good time to make more changes than necessary.  
OTOH I don't want to add more messy code.

So here is a patch which does a clean but fairly minimal fix.  
It also fixes the similar case where one gets Railroad from 
a spy stealing tech.  (Won't usually happen, since Railroad 
is on path to Espionage, but could occur if, eg, Espionage 
was gained via conquering.)

Regards,
-- David
diff -u -r --exclude-from exclude freeciv-cvs/server/diplhand.c 
freeciv-mod/server/diplhand.c
--- freeciv-cvs/server/diplhand.c       Sat Feb 27 18:09:38 1999
+++ freeciv-mod/server/diplhand.c       Wed Mar 17 22:33:48 1999
@@ -134,15 +134,7 @@
          notify_player(pdest, "Game: You are taught the knowledge of %s",
                        advances[pclause->value].name);
          if (pclause->value==A_RAILROAD) {
-/*         struct city_list cl=pdest->cities; -- unused? */
-           struct genlist_iterator myiter;
-           genlist_iterator_init(&myiter, &pdest->cities.list, 0);
-           notify_player(pplayer, "Game: New hope sweeps like fire through the 
country as the discovery of railroad is announced.\n      Workers spontaneously 
gather and upgrade all cities with railroads.");
-           for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
-             struct city *pcity=(struct city *)ITERATOR_PTR(myiter);
-             map_set_special(pcity->x, pcity->y, S_RAILROAD);
-             send_tile_info(0, pcity->x, pcity->y, TILE_KNOWN);
-           }
+           upgrade_city_rails(pdest, 0);
          }
          gamelog(GAMELOG_TECH, "%s acquire %s (Treaty) from %s",
                   get_race_name_plural(pdest->race),
diff -u -r --exclude-from exclude freeciv-cvs/server/maphand.c 
freeciv-mod/server/maphand.c
--- freeciv-cvs/server/maphand.c        Thu Feb 11 18:05:55 1999
+++ freeciv-mod/server/maphand.c        Wed Mar 17 23:03:56 1999
@@ -22,6 +22,8 @@
 #include <stdlib.h>
 #include <log.h>
 #include <ctype.h>
+#include <plrhand.h>           /* notify_player */
+
 
 char terrain_chars[]="adfghjm prst";
 char dec2hex[]="0123456789abcdef";
@@ -248,6 +250,32 @@
 
   light_square(pplayer, x, y, 1);
   
+  connection_do_unbuffer(pplayer->conn);
+}
+
+/***************************************************************
+To be called when a player gains the Railroad tech for the first
+time.  Sends a message, and then upgrade all city squares to
+railroads.  "discovery" just affects the message: set to
+   1 if the tech is a "discovery",
+   0 if otherwise aquired (conquer/trade/GLib).        --dwp
+***************************************************************/
+void upgrade_city_rails(struct player *pplayer, int discovery)
+{
+  connection_do_buffer(pplayer->conn);
+
+  if (discovery) {
+    notify_player(pplayer, "Game: New hope sweeps like fire through the 
country as the discovery of railroad is announced.\n      Workers spontaneously 
gather and upgrade all cities with railroads.");
+  } else {
+    notify_player(pplayer, "Game: The people are pleased to hear that your 
scientists finally know about railroads.\n      Workers spontaneously gather 
and upgrade all cities with railroads.");
+  }
+  
+  city_list_iterate(pplayer->cities, pcity) {
+    map_set_special(pcity->x, pcity->y, S_RAILROAD);
+    send_tile_info(0, pcity->x, pcity->y, TILE_KNOWN);
+  }
+  city_list_iterate_end;
+
   connection_do_unbuffer(pplayer->conn);
 }
 
diff -u -r --exclude-from exclude freeciv-cvs/server/maphand.h 
freeciv-mod/server/maphand.h
--- freeciv-cvs/server/maphand.h        Fri Sep 18 09:16:39 1998
+++ freeciv-mod/server/maphand.h        Wed Mar 17 22:36:48 1999
@@ -28,6 +28,8 @@
 void send_map_info(struct player *dest);
 void global_warming(int effect);
 
+void upgrade_city_rails(struct player *pplayer, int discovery);
+
 void map_save(struct section_file *file);
 void map_startpos_load(struct section_file *file);
 void map_tiles_load(struct section_file *file);
diff -u -r --exclude-from exclude freeciv-cvs/server/plrhand.c 
freeciv-mod/server/plrhand.c
--- freeciv-cvs/server/plrhand.c        Sat Mar 13 22:48:05 1999
+++ freeciv-mod/server/plrhand.c        Wed Mar 17 23:04:23 1999
@@ -552,7 +552,10 @@
            && game.global_advances[i]>=2) {
          notify_player_ex(pplayer,0,0, E_TECH_GAIN, "Game: %s acquired from 
The Great Library!", advances[i].name);
          gamelog(GAMELOG_TECH,"%s discover %s 
(Library)",get_race_name_plural(pplayer->race),advances[i].name);
- 
+
+         if (i==A_RAILROAD) {
+           upgrade_city_rails(pplayer, 0);
+         }
          set_invention(pplayer, i, TECH_KNOWN);
          update_research(pplayer);     
          do_free_cost(pplayer);
@@ -702,15 +705,7 @@
   }
 
   if (old==A_RAILROAD) {
-/*    struct city_list cl=plr->cities; -- unused? */
-    struct genlist_iterator myiter;
-    genlist_iterator_init(&myiter, &plr->cities.list, 0);
-    notify_player(plr, "Game: New hope sweeps like fire through the country as 
the discovery of railroad is announced.\n      Workers spontaneously gather and 
upgrade all cities with railroads.");
-    for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
-      struct city *pcity=(struct city *)ITERATOR_PTR(myiter);
-      map_set_special(pcity->x, pcity->y, S_RAILROAD);
-      send_tile_info(0, pcity->x, pcity->y, TILE_KNOWN);
-    }
+    upgrade_city_rails(plr, 1);
   }
   return 1;
 }
diff -u -r --exclude-from exclude freeciv-cvs/server/unitfunc.c 
freeciv-mod/server/unitfunc.c
--- freeciv-cvs/server/unitfunc.c       Sat Mar 13 22:35:51 1999
+++ freeciv-mod/server/unitfunc.c       Wed Mar 17 22:34:54 1999
@@ -285,15 +285,7 @@
                   pplayer->name, unit_name(pdiplomat->type),
                   advances[i].name, pcity->name); 
   if (i==A_RAILROAD) {
-    /*    struct city_list cl=pplayer->cities;*/
-    struct genlist_iterator myiter;
-    genlist_iterator_init(&myiter, &pplayer->cities.list, 0);
-    notify_player(pplayer, "Game: The people are pleased to hear that your 
scientists finally know about railroads.\n      Workers spontaneously gather 
and upgrade all cities with railroads.", pcity->name);
-    for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
-      struct city *pcity1=(struct city *)ITERATOR_PTR(myiter);
-      map_set_special(pcity1->x, pcity1->y, S_RAILROAD);
-      send_tile_info(0, pcity1->x, pcity1->y, TILE_KNOWN);
-    }
+    upgrade_city_rails(pplayer, 0);
   }
   gamelog(GAMELOG_TECH,"%s steals %s from the %s",
           get_race_name_plural(pplayer->race),
@@ -1490,6 +1482,9 @@
                advances[i].name, target->name); 
   notify_player(target, "Game: %s discovered %s in the city.", pplayer->name, 
                advances[i].name); 
+  if (i==A_RAILROAD) {
+    upgrade_city_rails(pplayer, 0);
+  }
   if (pplayer->research.researching==i) {
     tec=pplayer->research.researched;
     if (!choose_goal_tech(pplayer))
diff -u -r --exclude-from exclude freeciv-cvs/server/unithand.c 
freeciv-mod/server/unithand.c
--- freeciv-cvs/server/unithand.c       Mon Mar 15 13:30:21 1999
+++ freeciv-mod/server/unithand.c       Wed Mar 17 22:33:32 1999
@@ -675,15 +675,7 @@
                         "Game: You gain knowledge about %s.", 
                         advances[pplayer->research.researching].name);
        if (pplayer->research.researching==A_RAILROAD) {
-/*         struct city_list cl=pplayer->cities;*/
-         struct genlist_iterator myiter;
-         genlist_iterator_init(&myiter, &pplayer->cities.list, 0);
-         notify_player(pplayer, "Game: New hope sweeps like fire through the 
country as the discovery of railroad is announced.\n      Workers spontaneously 
gather and upgrade all cities with railroads.");
-         for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
-           struct city *pcity=(struct city *)ITERATOR_PTR(myiter);
-           map_set_special(pcity->x, pcity->y, S_RAILROAD);
-           send_tile_info(0, pcity->x, pcity->y, TILE_KNOWN);
-         }
+        upgrade_city_rails(pplayer, 1);
        }
        set_invention(pplayer, pplayer->research.researching, TECH_KNOWN);
       }

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