Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11561) requirements for specialists
Home

[Freeciv-Dev] (PR#11561) requirements for specialists

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11561) requirements for specialists
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Dec 2004 01:21:54 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here's an updated patch.  As you can see it's quite small.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.452
diff -u -r1.452 packhand.c
--- client/packhand.c   17 Dec 2004 08:21:19 -0000      1.452
+++ client/packhand.c   17 Dec 2004 09:20:15 -0000
@@ -2581,7 +2581,7 @@
   game.rgame.num_specialist_types = packet->num_specialist_types;
   game.rgame.default_specialist = packet->default_specialist;
   specialist_type_iterate(sp) {
-    int *bonus = game.rgame.specialists[sp].bonus;
+    int *bonus = game.rgame.specialists[sp].bonus, j;
 
     sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
     sz_strlcpy(game.rgame.specialists[sp].short_name,
@@ -2590,6 +2590,16 @@
     output_type_iterate(o) {
       bonus[o] = packet->specialist_bonus[sp * O_COUNT + o];
     } output_type_iterate_end;
+
+    for (j = 0; j < MAX_NUM_REQS; j++) {
+      int index = sp * MAX_NUM_REQS + j;
+
+      game.rgame.specialists[sp].req[j]
+       = req_from_values(packet->specialist_req_type[index],
+                         packet->specialist_req_range[index],
+                         packet->specialist_req_survives[index],
+                         packet->specialist_req_value[index]);
+    }
   } specialist_type_iterate_end;
   tilespec_setup_specialist_types();
 
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.288
diff -u -r1.288 city.c
--- common/city.c       16 Dec 2004 23:00:12 -0000      1.288
+++ common/city.c       17 Dec 2004 09:20:16 -0000
@@ -530,7 +530,24 @@
 bool city_can_use_specialist(const struct city *pcity,
                             Specialist_type_id type)
 {
-  return pcity->size >= game.rgame.specialists[type].min_size;
+  int i;
+
+  if (pcity->size < game.rgame.specialists[type].min_size) {
+    return FALSE;
+  }
+
+  for (i = 0; i < MAX_NUM_REQS; i++) {
+    struct requirement *req = &game.rgame.specialists[type].req[i];
+
+    if (req->type == REQ_NONE) {
+      break; /* Short-circuit any more checks. */
+    } else if (!is_req_active(TARGET_CITY, city_owner(pcity), pcity,
+                             B_LAST, NULL, req)) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
 }
 
 /**************************************************************************
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.12
diff -u -r1.12 fc_types.h
--- common/fc_types.h   16 Dec 2004 20:37:49 -0000      1.12
+++ common/fc_types.h   17 Dec 2004 09:20:16 -0000
@@ -40,5 +40,6 @@
 struct unit;
 
 #define SP_MAX 20
+#define MAX_NUM_REQS 2
 
 #endif /* FC__FC_TYPES_H */
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.166
diff -u -r1.166 game.h
--- common/game.h       17 Dec 2004 00:14:15 -0000      1.166
+++ common/game.h       17 Dec 2004 09:20:16 -0000
@@ -193,8 +193,9 @@
     struct specialist {
       char name[MAX_LEN_NAME];
       char short_name[MAX_LEN_NAME];
-      int min_size;
       int bonus[O_MAX];
+      int min_size;
+      struct requirement req[MAX_NUM_REQS];
     } specialists[SP_MAX];
 #define SP_COUNT game.rgame.num_specialist_types
 #define DEFAULT_SPECIALIST game.rgame.default_specialist
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.82
diff -u -r1.82 packets.def
--- common/packets.def  17 Dec 2004 08:44:12 -0000      1.82
+++ common/packets.def  17 Dec 2004 09:20:16 -0000
@@ -971,6 +971,10 @@
   STRING specialist_short_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
   UINT8 specialist_min_size[SP_MAX:num_specialist_types];
   UINT8 specialist_bonus[SP_MAX * O_MAX];
+  UINT8 specialist_req_type[SP_MAX * MAX_NUM_REQS];
+  UINT8 specialist_req_range[SP_MAX * MAX_NUM_REQS];
+  UINT8 specialist_req_value[SP_MAX * MAX_NUM_REQS];
+  BOOL specialist_req_survives[SP_MAX * MAX_NUM_REQS];
   BOOL changable_tax;
   UINT8 forced_science;
   UINT8 forced_luxury;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.221
diff -u -r1.221 ruleset.c
--- server/ruleset.c    17 Dec 2004 08:48:55 -0000      1.221
+++ server/ruleset.c    17 Dec 2004 09:20:17 -0000
@@ -2524,7 +2524,7 @@
 
   for (i = 0; i < nval; i++) {
     const char *name = specialist_names[i], *short_name;
-    int *bonus = game.rgame.specialists[i].bonus;
+    int *bonus = game.rgame.specialists[i].bonus, j;
 
     sz_strlcpy(game.rgame.specialists[i].name, name);
     short_name
@@ -2543,6 +2543,34 @@
        && game.rgame.default_specialist == -1) {
       game.rgame.default_specialist = i;
     }
+
+    for (j = 0; j < MAX_NUM_REQS; j++) {
+      const char *type
+       = secfile_lookup_str_default(file, NULL, "specialist.%s_req%d.type",
+                                    name, j);
+      const char *range
+       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.range",
+                                    name, j);
+      bool survives
+       = secfile_lookup_bool_default(file, FALSE,
+                                     "specialist.%s_req%d.survives",
+                                     name, j);
+      const char *value
+       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.value",
+                                    name, j);
+      struct requirement req = req_from_str(type, range, survives, value);
+
+      if (req.type == REQ_LAST) {
+       freelog(LOG_ERROR,
+               /* TRANS: Obscure ruleset error */
+               _("Specialist %s has unknown req: "
+                 "\"%s\" \"%s\" \"%s\" %d (%s)"),
+               name, type, range, value, survives, filename);
+       req.type = REQ_NONE;
+      }
+
+      game.rgame.specialists[i].req[j] = req;
+    }
   }
   if (game.rgame.default_specialist == -1) {
     freelog(LOG_FATAL, "You must give a min_size of 0 for at least one "
@@ -3117,7 +3145,7 @@
   misc_p.num_specialist_types = SP_COUNT;
   misc_p.default_specialist = DEFAULT_SPECIALIST;
   specialist_type_iterate(sp) {
-    int *bonus = game.rgame.specialists[sp].bonus;
+    int *bonus = game.rgame.specialists[sp].bonus, j;
 
     sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
     sz_strlcpy(misc_p.specialist_short_name[sp],
@@ -3127,6 +3155,16 @@
     output_type_iterate(o) {
       misc_p.specialist_bonus[sp * O_COUNT + o] = bonus[o];
     } output_type_iterate_end;
+
+    for (j = 0; j < MAX_NUM_REQS; j++) {
+      int index = sp * MAX_NUM_REQS + j;
+
+      req_get_values(&game.rgame.specialists[sp].req[j],
+                    &misc_p.specialist_req_type[index],
+                    &misc_p.specialist_req_range[index],
+                    &misc_p.specialist_req_survives[index],
+                    &misc_p.specialist_req_value[index]);
+    }
   } specialist_type_iterate_end;
   misc_p.changable_tax = game.rgame.changable_tax;
   misc_p.forced_science = game.rgame.forced_science;

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