Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] (PR#13308) global_advances array
Home

[Freeciv-Dev] (PR#13308) global_advances array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13308) global_advances array
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 21 Jun 2005 23:59:50 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13308 >

Currently it holds information about how many players has researched a tech.
There are two problems with it:
- It is sent to the client
The client needs only boolean value: if there is a civilization knowing
a tech. More info allows only cheating

- It is/will be hard to update with team research

The attached patch changes the type of the array to bool.
The only place where we really needed integer value was in
do_tech_parasite_effect(). I changed this function to count players each
time it is called.

--
mateusz
? core.22373
? core.23940
? core.26863
? core.26869
? core.26873
? shared.c
? data/ft
? po/pl.back
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.227
diff -u -r1.227 aicity.c
--- ai/aicity.c 21 Jun 2005 16:20:59 -0000      1.227
+++ ai/aicity.c 22 Jun 2005 06:57:47 -0000
@@ -884,7 +884,7 @@
   for(i = 0; i < num_role_units(L_BARBARIAN_BUILD_TECH); i++) {
     Unit_type_id iunit = get_role_unit(L_BARBARIAN_BUILD_TECH, i);
 
-    if (game.info.global_advances[get_unit_type(iunit)->tech_requirement] != 0
+    if (game.info.global_advances[get_unit_type(iunit)->tech_requirement]
        && get_unit_type(iunit)->attack_strength > bestattack) {
       bestunit = iunit;
       bestattack = get_unit_type(iunit)->attack_strength;
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.220
diff -u -r1.220 game.c
--- common/game.c       21 Jun 2005 16:21:01 -0000      1.220
+++ common/game.c       22 Jun 2005 06:57:59 -0000
@@ -287,7 +287,7 @@
   for(i=0; i<MAX_NUM_PLAYERS+MAX_NUM_BARBARIANS; i++)
     player_init(&game.players[i]);
   for (i=0; i<A_LAST; i++)      /* game.num_tech_types = 0 here */
-    game.info.global_advances[i]=0;
+    game.info.global_advances[i]=FALSE;
   for (i=0; i<B_LAST; i++)      /* game.num_impr_types = 0 here */
     game.info.great_wonders[i]=0;
   game.info.player_idx = 0;
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.64
diff -u -r1.64 improvement.c
--- common/improvement.c        14 May 2005 15:34:41 -0000      1.64
+++ common/improvement.c        22 Jun 2005 06:58:04 -0000
@@ -282,7 +282,7 @@
   if (is_great_wonder(id)) {
     /* a great wonder is obsolete, as soon as *any* player researched the
        obsolete tech */
-   return game.info.global_advances[impr->obsolete_by] != 0;
+   return game.info.global_advances[impr->obsolete_by];
   }
 
   return (get_invention(pplayer, impr->obsolete_by) == TECH_KNOWN);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.136
diff -u -r1.136 packets.def
--- common/packets.def  14 Jun 2005 18:49:08 -0000      1.136
+++ common/packets.def  22 Jun 2005 06:58:09 -0000
@@ -432,7 +432,9 @@
   UINT8 save_compress_level;
 
   STRING start_units[MAX_LEN_STARTUNIT];
-  UINT8 global_advances[A_LAST]; diff
+  
+  /* True if at least one civilization has researched a tech */
+  BOOL global_advances[A_LAST]; diff
   UINT16 great_wonders[B_LAST]; diff
 end
 
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.27
diff -u -r1.27 requirements.c
--- common/requirements.c       7 Jun 2005 06:17:12 -0000       1.27
+++ common/requirements.c       22 Jun 2005 06:58:16 -0000
@@ -614,7 +614,7 @@
     return (target_player
            && get_invention(target_player, tech) == TECH_KNOWN);
   case REQ_RANGE_WORLD:
-    return game.info.global_advances[tech] > 0;
+    return game.info.global_advances[tech];
   case REQ_RANGE_LOCAL:
   case REQ_RANGE_ADJACENT:
   case REQ_RANGE_CITY:
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.94
diff -u -r1.94 tech.c
--- common/tech.c       21 Jun 2005 16:21:01 -0000      1.94
+++ common/tech.c       22 Jun 2005 06:58:16 -0000
@@ -74,7 +74,7 @@
   research->inventions[tech].state = value;
 
   if (value == TECH_KNOWN) {
-    game.info.global_advances[tech]++;
+    game.info.global_advances[tech] = TRUE;
   }
 }
 
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.390
diff -u -r1.390 plrhand.c
--- server/plrhand.c    21 Jun 2005 16:21:02 -0000      1.390
+++ server/plrhand.c    22 Jun 2005 06:58:43 -0000
@@ -160,24 +160,31 @@
 
     tech_type_iterate(i) {
       if (get_invention(pplayer, i) != TECH_KNOWN
-         && tech_is_available(pplayer, i)
-         && game.info.global_advances[i] >= mod) {
-       notify_player_ex(pplayer, NULL, E_TECH_GAIN,
-                        _("%s acquired from %s!"),
-                        get_tech_name(pplayer, i), buf);
-       script_signal_emit("tech_researched", 3,
-                          API_TYPE_TECH_TYPE, &advances[i],
-                          API_TYPE_PLAYER, pplayer,
-                          API_TYPE_STRING, "stolen");
-        gamelog(GAMELOG_TECH, pplayer, NULL, i, "steal");
-       notify_embassies(pplayer, NULL,
-                        _("The %s have acquired %s from %s."),
-                        get_nation_name_plural(pplayer->nation),
-                        get_tech_name(pplayer, i), buf);
-
-       do_free_cost(pplayer);
-       found_new_tech(pplayer, i, FALSE, TRUE, A_NONE);
-       break;
+         && tech_is_available(pplayer, i)) {
+       int num_players = 0;
+       players_iterate(aplayer) {
+         if (get_invention(aplayer, i) == TECH_KNOWN) {
+           num_players++;
+         }
+       } players_iterate_end;
+       if (num_players >= mod) {
+         notify_player_ex(pplayer, NULL, E_TECH_GAIN,
+                          _("%s acquired from %s!"),
+                          get_tech_name(pplayer, i), buf);
+         script_signal_emit("tech_researched", 3,
+                            API_TYPE_TECH_TYPE, &advances[i],
+                            API_TYPE_PLAYER, pplayer,
+                            API_TYPE_STRING, "stolen");
+          gamelog(GAMELOG_TECH, pplayer, NULL, i, "steal");
+         notify_embassies(pplayer, NULL,
+                          _("The %s have acquired %s from %s."),
+                          get_nation_name_plural(pplayer->nation),
+                          get_tech_name(pplayer, i), buf);
+
+         do_free_cost(pplayer);
+         found_new_tech(pplayer, i, FALSE, TRUE, A_NONE);
+         break;
+       }
       }
     } tech_type_iterate_end;
   }
@@ -305,7 +312,7 @@
   research->got_tech = TRUE;
   research->changed_from = -1;
   research->techs_researched++;
-  was_first = (game.info.global_advances[tech_found] == 0);
+  was_first = (!game.info.global_advances[tech_found]);
 
   if (was_first) {
     /* We used to have a gamelog() for first-researched, but not anymore. */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13308) global_advances array, Mateusz Stefek <=