[Freeciv-Dev] (PR#13036) [PATCH] Parse and transmit 'negated' requiremen
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13036) [PATCH] Parse and transmit 'negated' requirement field |
From: |
"Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx> |
Date: |
Tue, 10 May 2005 17:12:20 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13036 >
Plus some cleanups.
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.511
diff -u -u -r1.511 packhand.c
--- client/packhand.c 10 May 2005 19:08:54 -0000 1.511
+++ client/packhand.c 11 May 2005 00:08:42 -0000
@@ -2144,8 +2144,7 @@
sz_strlcpy(b->graphic_str, p->graphic_str);
sz_strlcpy(b->graphic_alt, p->graphic_alt);
for (i = 0; i < MAX_NUM_REQS; i++) {
- b->req[i] = req_from_values(p->req_type[i], p->req_range[i],
- p->req_survives[i], p->req_value[i]);
+ b->req[i] = p->reqs[i];
}
b->obsolete_by = p->obsolete_by;
b->build_cost = p->build_cost;
@@ -2199,8 +2198,7 @@
gov->index = p->id;
for (j = 0; j < MAX_NUM_REQS; j++) {
- gov->req[j] = req_from_values(p->req_type[j], p->req_range[j],
- p->req_survives[j], p->req_value[j]);
+ gov->req[j] = p->reqs[j];
}
gov->unit_happy_cost_factor = p->unit_happy_cost_factor;
@@ -2402,10 +2400,7 @@
cs = &city_styles[id];
for (j = 0; j < MAX_NUM_REQS; j++) {
- cs->req[j] = req_from_values(packet->req_type[j],
- packet->req_range[j],
- packet->req_survives[j],
- packet->req_value[j]);
+ cs->req[j] = packet->reqs[j];
}
cs->replaced_by = packet->replaced_by;
@@ -2439,10 +2434,7 @@
for (j = 0; j < MAX_NUM_REQS; j++) {
int index = sp * MAX_NUM_REQS + j;
- s->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]);
+ s->req[j] = packet->specialist_reqs[index];
}
} specialist_type_iterate_end;
tileset_setup_specialist_types(tileset);
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.244
diff -u -u -r1.244 capstr.c
--- common/capstr.c 10 May 2005 17:27:09 -0000 1.244
+++ common/capstr.c 11 May 2005 00:08:42 -0000
@@ -82,7 +82,7 @@
* as long as possible. We want to maintain network compatibility with
* the stable branch for as long as possible.
*/
-#define CAPABILITY "+Freeciv.Devel.2005.May.10"
+#define CAPABILITY "+Freeciv.Devel.2005.May.11"
void init_our_capability(void)
{
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.17
diff -u -u -r1.17 dataio.c
--- common/dataio.c 28 Apr 2005 17:19:52 -0000 1.17
+++ common/dataio.c 11 May 2005 00:08:42 -0000
@@ -47,6 +47,7 @@
#include "log.h"
#include "mem.h"
#include "player.h"
+#include "requirements.h"
#include "support.h"
#include "tech.h"
#include "worklist.h"
@@ -712,3 +713,38 @@
dio_put_uint16(dout, pds->contact_turns_left);
dio_put_uint8(dout, pds->has_reason_to_cancel);
}
+
+/**************************************************************************
+ De-serialize a requirement.
+**************************************************************************/
+void dio_get_requirement(struct data_in *din, struct requirement *preq)
+{
+ int type, range, value;
+ bool survives, negated;
+
+ dio_get_uint8(din, &type);
+ dio_get_sint32(din, &value);
+ dio_get_uint8(din, &range);
+ dio_get_bool8(din, &survives);
+ dio_get_bool8(din, &negated);
+
+ *preq = req_from_values(type, range, survives, negated, value);
+}
+
+/**************************************************************************
+ Serialize a requirement.
+**************************************************************************/
+void dio_put_requirement(struct data_out *dout, const struct requirement *preq)
+{
+ int type, range, value;
+ bool survives, negated;
+
+ req_get_values(preq, &type, &range, &survives, &negated, &value);
+
+ dio_put_uint8(dout, type);
+ dio_put_sint32(dout, value);
+ dio_put_uint8(dout, range);
+ dio_put_bool8(dout, survives);
+ dio_put_bool8(dout, negated);
+}
+
Index: common/dataio.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.h,v
retrieving revision 1.8
diff -u -u -r1.8 dataio.h
--- common/dataio.h 28 Apr 2005 17:19:52 -0000 1.8
+++ common/dataio.h 11 May 2005 00:08:42 -0000
@@ -17,6 +17,7 @@
struct worklist;
struct player_diplstate;
+struct requirement;
struct data_in {
const void *src;
@@ -70,6 +71,7 @@
void dio_get_tech_list(struct data_in *din, int *dest);
void dio_get_worklist(struct data_in *din, struct worklist *pwl);
void dio_get_diplstate(struct data_in *din, struct player_diplstate *pds);
+void dio_get_requirement(struct data_in *din, struct requirement *preq);
void dio_get_uint8_vec8(struct data_in *din, int **values, int stop_value);
void dio_get_uint16_vec8(struct data_in *din, int **values, int stop_value);
@@ -98,6 +100,7 @@
void dio_put_worklist(struct data_out *dout, const struct worklist *pwl);
void dio_put_diplstate(struct data_out *dout,
const struct player_diplstate *pds);
+void dio_put_requirement(struct data_out *dout, const struct requirement
*preq);
void dio_put_uint8_vec8(struct data_out *dout, int *values, int stop_value);
void dio_put_uint16_vec8(struct data_out *dout, int *values, int stop_value);
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.42
diff -u -u -r1.42 effects.c
--- common/effects.c 10 May 2005 19:08:54 -0000 1.42
+++ common/effects.c 11 May 2005 00:08:42 -0000
@@ -414,7 +414,7 @@
struct requirement req, *preq;
req = req_from_values(packet->source_type, packet->range, packet->survives,
- packet->source_value);
+ packet->negated, packet->source_value);
preq = fc_malloc(sizeof(*preq));
*preq = req;
@@ -441,9 +441,9 @@
requirement_list_iterate(peffect->reqs, preq) {
struct packet_ruleset_effect_req packet;
int type, range, value;
- bool survives;
+ bool survives, negated;
- req_get_values(preq, &type, &range, &survives, &value);
+ req_get_values(preq, &type, &range, &survives, &negated, &value);
packet.effect_id = id;
packet.neg = FALSE;
packet.source_type = type;
@@ -457,9 +457,9 @@
requirement_list_iterate(peffect->nreqs, preq) {
struct packet_ruleset_effect_req packet;
int type, range, value;
- bool survives;
+ bool survives, negated;
- req_get_values(preq, &type, &range, &survives, &value);
+ req_get_values(preq, &type, &range, &survives, &negated, &value);
packet.effect_id = id;
packet.neg = TRUE;
packet.source_type = type;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.122
diff -u -u -r1.122 packets.def
--- common/packets.def 10 May 2005 19:08:54 -0000 1.122
+++ common/packets.def 11 May 2005 00:08:44 -0000
@@ -163,6 +163,7 @@
type BIT_STRING = bit_string(char)
type WORKLIST = worklist(struct worklist)
type TECH_LIST = tech_list(int)
+type REQUIREMENT = requirement(struct requirement)
# typedefs for enums
type CLAUSE = uint8(enum clause_type)
@@ -1051,10 +1052,7 @@
UINT8 req_array_size; # Another hack to get around limitations of packgen
STRING specialist_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
STRING specialist_short_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
- UINT8 specialist_req_type[SP_MAX * MAX_NUM_REQS:req_array_size];
- UINT8 specialist_req_range[SP_MAX * MAX_NUM_REQS:req_array_size];
- UINT32 specialist_req_value[SP_MAX * MAX_NUM_REQS:req_array_size];
- BOOL specialist_req_survives[SP_MAX * MAX_NUM_REQS:req_array_size];
+ REQUIREMENT specialist_reqs[SP_MAX * MAX_NUM_REQS:req_array_size];
TECH_LIST global_init_techs[MAX_NUM_TECH_LIST];
UINT8 trireme_loss_chance[MAX_VET_LEVELS];
UINT8 work_veteran_chance[MAX_VET_LEVELS];
@@ -1083,10 +1081,7 @@
PACKET_RULESET_GOVERNMENT=100;sc,lsend
GOVERNMENT id;
- UINT8 req_type[MAX_NUM_REQS];
- UINT8 req_range[MAX_NUM_REQS];
- UINT32 req_value[MAX_NUM_REQS];
- BOOL req_survives[MAX_NUM_REQS];
+ REQUIREMENT reqs[MAX_NUM_REQS];
UINT8 unit_happy_cost_factor;
UINT8 unit_upkeep_factor[O_MAX];
@@ -1164,10 +1159,7 @@
STRING name[MAX_LEN_NAME];
STRING citizens_graphic[MAX_LEN_NAME];
STRING citizens_graphic_alt[MAX_LEN_NAME];
- UINT8 req_type[MAX_NUM_REQS];
- UINT8 req_range[MAX_NUM_REQS];
- UINT32 req_value[MAX_NUM_REQS];
- BOOL req_survives[MAX_NUM_REQS];
+ REQUIREMENT reqs[MAX_NUM_REQS];
STRING graphic[MAX_LEN_NAME];
STRING graphic_alt[MAX_LEN_NAME];
SINT8 replaced_by;
@@ -1179,10 +1171,7 @@
STRING name[MAX_LEN_NAME];
STRING graphic_str[MAX_LEN_NAME];
STRING graphic_alt[MAX_LEN_NAME];
- UINT8 req_type[MAX_NUM_REQS];
- UINT8 req_range[MAX_NUM_REQS];
- UINT32 req_value[MAX_NUM_REQS];
- BOOL req_survives[MAX_NUM_REQS];
+ REQUIREMENT reqs[MAX_NUM_REQS];
TECH obsolete_by;
IMPROVEMENT replaced_by;
UINT16 build_cost;
@@ -1328,5 +1317,6 @@
REQ_RANGE range;
BOOL survives;
+ BOOL negated;
end
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.163
diff -u -u -r1.163 packets.h
--- common/packets.h 13 Sep 2004 15:54:51 -0000 1.163
+++ common/packets.h 11 May 2005 00:08:44 -0000
@@ -22,6 +22,7 @@
#include "improvement.h"
#include "map.h"
#include "player.h"
+#include "requirements.h"
#include "shared.h" /* MAX_LEN_NAME, MAX_LEN_ADDR */
#include "spaceship.h"
#include "unittype.h"
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.23
diff -u -u -r1.23 requirements.c
--- common/requirements.c 10 May 2005 19:08:55 -0000 1.23
+++ common/requirements.c 11 May 2005 00:08:46 -0000
@@ -238,7 +238,8 @@
is for serialization of req sources and is the opposite of
req_source_from_values().
**************************************************************************/
-void req_source_get_values(struct req_source *source, int *type, int *value)
+void req_source_get_values(const struct req_source *source,
+ int *type, int *value)
{
*type = source->type;
@@ -294,8 +295,8 @@
Pass this some values like "Building", "Factory".
****************************************************************************/
-struct requirement req_from_str(const char *type,
- const char *range, bool survives,
+struct requirement req_from_str(const char *type, const char *range,
+ bool survives, bool negated,
const char *value)
{
struct requirement req;
@@ -332,6 +333,7 @@
}
req.survives = survives;
+ req.negated = negated;
/* These checks match what combinations are supported inside
* is_req_active(). */
@@ -373,8 +375,10 @@
break;
}
if (invalid) {
- freelog(LOG_ERROR, "Invalid requirement %s | %s | %s | %s",
- type, range, survives ? "survives" : "", value);
+ freelog(LOG_ERROR, "Invalid requirement %s | %s | %s | %s | %s",
+ type, range,
+ survives ? "survives" : "",
+ negated ? "negated" : "", value);
req.source.type = REQ_LAST;
}
@@ -386,13 +390,15 @@
of req_get_values.
****************************************************************************/
struct requirement req_from_values(int type, int range,
- bool survives, int value)
+ bool survives, bool negated,
+ int value)
{
struct requirement req;
req.source = req_source_from_values(type, value);
req.range = range;
req.survives = survives;
+ req.negated = negated;
return req;
}
@@ -400,12 +406,27 @@
Return the value of a req as a serializable integer. This is the opposite
of req_set_value.
****************************************************************************/
-void req_get_values(struct requirement *req,
- int *type, int *range, bool *survives, int *value)
+void req_get_values(const struct requirement *req,
+ int *type, int *range,
+ bool *survives, bool *negated,
+ int *value)
{
req_source_get_values(&req->source, type, value);
*range = req->range;
*survives = req->survives;
+ *negated = req->negated;
+}
+
+/****************************************************************************
+ Returns TRUE if req1 and req2 are equal.
+****************************************************************************/
+bool are_requirements_equal(const struct requirement *req1,
+ const struct requirement *req2)
+{
+ return (are_req_sources_equal(&req1->source, &req2->source)
+ && req1->range == req2->range
+ && req1->survives == req2->survives
+ && req1->negated == req2->negated);
}
/****************************************************************************
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.17
diff -u -u -r1.17 requirements.h
--- common/requirements.h 10 May 2005 19:08:55 -0000 1.17
+++ common/requirements.h 11 May 2005 00:08:46 -0000
@@ -76,6 +76,7 @@
struct req_source source; /* requirement source */
enum req_range range; /* requirement range */
bool survives; /* set if destroyed sources satisfy the req*/
+ bool negated; /* set if the requirement is to be negated */
};
#define SPECLIST_TAG requirement
@@ -94,16 +95,22 @@
struct req_source req_source_from_str(const char *type, const char *value);
struct req_source req_source_from_values(int type, int value);
-void req_source_get_values(struct req_source *source, int *type, int *value);
+void req_source_get_values(const struct req_source *source,
+ int *type, int *value);
enum req_range req_range_from_str(const char *str);
struct requirement req_from_str(const char *type, const char *range,
- bool survives, const char *value);
+ bool survives, bool negated,
+ const char *value);
-void req_get_values(struct requirement *req,
- int *type, int *range, bool *survives, int *value);
+void req_get_values(const struct requirement *req, int *type,
+ int *range, bool *survives, bool *negated,
+ int *value);
struct requirement req_from_values(int type, int range,
- bool survives, int value);
+ bool survives, bool negated, int value);
+
+bool are_requirements_equal(const struct requirement *req1,
+ const struct requirement *req2);
bool is_req_active(const struct player *target_player,
const struct city *target_city,
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.259
diff -u -u -r1.259 ruleset.c
--- server/ruleset.c 10 May 2005 19:08:56 -0000 1.259
+++ server/ruleset.c 11 May 2005 00:08:47 -0000
@@ -241,7 +241,7 @@
sec, sub, j));
j++) {
char *range;
- bool survives;
+ bool survives, negated;
struct requirement req;
name = secfile_lookup_str(file, "%s.%s%d.name", sec, sub, j);
@@ -249,8 +249,10 @@
survives = secfile_lookup_bool_default(file, FALSE,
"%s.%s%d.survives", sec, sub, j);
+ negated = secfile_lookup_bool_default(file, FALSE,
+ "%s.%s%d.negated", sec, sub, j);
- req = req_from_str(type, range, survives, name);
+ req = req_from_str(type, range, survives, negated, name);
if (req.source.type == REQ_LAST) {
/* Error. Log it, clear the req and continue. */
freelog(LOG_ERROR,
@@ -2267,6 +2269,8 @@
const char *name = specialist_names[i], *short_name;
struct specialist *s = &specialists[i];
int j;
+ struct requirement_vector *reqs;
+ char sub[MAX_LEN_NAME + 4];
sz_strlcpy(s->name, name);
short_name
@@ -2274,32 +2278,19 @@
"specialist.%s_short_name", name);
sz_strlcpy(s->short_name, short_name);
- 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.name",
- name, j);
- struct requirement req = req_from_str(type, range, survives, value);
-
- if (req.source.type == REQ_LAST) {
- freelog(LOG_ERROR,
- "Specialist %s has unknown req: \"%s\" \"%s\" \"%s\" %d (%s)",
- name, type, range, value, survives, filename);
- req.source.type = REQ_NONE;
- }
+ my_snprintf(sub, sizeof(sub), "%s_req", name);
+ reqs = lookup_req_list(file, "specialist", sub);
+ for (j = 0; j < MAX_NUM_REQS; j++) {
+ struct requirement req = req_from_str(NULL, "", FALSE, FALSE, "");
s->req[j] = req;
}
+ j = 0;
+ requirement_vector_iterate(reqs, req) {
+ s->req[j++] = *req;
+ } requirement_vector_iterate_end;
+
if (s->req[0].source.type == REQ_NONE && DEFAULT_SPECIALIST == -1) {
DEFAULT_SPECIALIST = i;
}
@@ -2700,9 +2691,7 @@
sz_strlcpy(packet.graphic_str, b->graphic_str);
sz_strlcpy(packet.graphic_alt, b->graphic_alt);
for (j = 0; j < MAX_NUM_REQS; j++) {
- req_get_values(&b->req[j],
- &packet.req_type[j], &packet.req_range[j],
- &packet.req_survives[j], &packet.req_value[j]);
+ packet.reqs[j] = b->req[j];
}
packet.obsolete_by = b->obsolete_by;
packet.replaced_by = b->replaced_by;
@@ -2807,9 +2796,7 @@
gov.id = g->index;
for (j = 0; j < MAX_NUM_REQS; j++) {
- req_get_values(&g->req[j],
- &gov.req_type[j], &gov.req_range[j],
- &gov.req_survives[j], &gov.req_value[j]);
+ gov.reqs[j] = g->req[j];
}
gov.unit_happy_cost_factor = g->unit_happy_cost_factor;
@@ -2919,11 +2906,7 @@
city_p.replaced_by = city_styles[k].replaced_by;
for (j = 0; j < MAX_NUM_REQS; j++) {
- req_get_values(&city_styles[k].req[j],
- &city_p.req_type[j],
- &city_p.req_range[j],
- &city_p.req_survives[j],
- &city_p.req_value[j]);
+ city_p.reqs[j] = city_styles[k].req[j];
}
sz_strlcpy(city_p.name, city_styles[k].name_orig);
@@ -2959,11 +2942,7 @@
for (j = 0; j < MAX_NUM_REQS; j++) {
int index = sp * MAX_NUM_REQS + j;
- req_get_values(&s->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]);
+ misc_p.specialist_reqs[index] = s->req[j];
}
} specialist_type_iterate_end;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13036) [PATCH] Parse and transmit 'negated' requirement field,
Vasco Alexandre da Silva Costa <=
|
|