[Freeciv-Dev] (PR#9443) new function cm_count_specialist
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9443 >
This patch adds a new CM function cm_count_specialist. It parallels
cm_count_worker but isn't used as much.
One other piece of code in cma_core is changed so that counting of
specialists parallels the counting of workers.
The advantage of this is that the specialist types no longer have to be
hard-coded.
jason
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.57
diff -u -r1.57 cma_core.c
--- client/agents/cma_core.c 20 Jul 2004 09:35:51 -0000 1.57
+++ client/agents/cma_core.c 20 Jul 2004 16:14:35 -0000
@@ -133,7 +133,7 @@
static void get_current_as_result(struct city *pcity,
struct cm_result *result)
{
- int worker = 0;
+ int worker = 0, specialist = 0;
memset(result->worker_positions_used, 0,
sizeof(result->worker_positions_used));
@@ -148,11 +148,10 @@
specialist_type_iterate(sp) {
result->specialists[sp] = pcity->specialists[sp];
+ specialist += pcity->specialists[sp];
} specialist_type_iterate_end;
- assert(worker + result->specialists[SP_ELVIS]
- + result->specialists[SP_SCIENTIST]
- + result->specialists[SP_TAXMAN] == pcity->size);
+ assert(worker + specialist == pcity->size);
result->found_a_valid = TRUE;
@@ -195,7 +194,7 @@
static bool apply_result_on_server(struct city *pcity,
const struct cm_result *const result)
{
- int first_request_id = 0, last_request_id = 0, i, sp, worker;
+ int first_request_id = 0, last_request_id = 0, i, sp;
struct cm_result current_state;
bool success;
@@ -215,11 +214,8 @@
connection_do_buffer(&aconnection);
/* Do checks */
- worker = cm_count_worker(pcity, result);
- if (pcity->size !=
- (worker + result->specialists[SP_ELVIS]
- + result->specialists[SP_SCIENTIST]
- + result->specialists[SP_TAXMAN])) {
+ if (pcity->size != (cm_count_worker(pcity, result)
+ + cm_count_specialist(pcity, result))) {
cm_print_city(pcity);
cm_print_result(pcity, result);
assert(0);
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.36
diff -u -r1.36 cm.c
--- common/aicore/cm.c 18 Jul 2004 01:16:05 -0000 1.36
+++ common/aicore/cm.c 20 Jul 2004 16:14:35 -0000
@@ -250,6 +250,22 @@
}
/****************************************************************************
+ Returns the number of specialists of the given result. The given result
+ has to be a result for the given city.
+*****************************************************************************/
+int cm_count_specialist(const struct city *pcity,
+ const struct cm_result *result)
+{
+ int specialist = 0;
+
+ specialist_type_iterate(sp) {
+ specialist += result->specialists[sp];
+ } specialist_type_iterate_end;
+
+ return specialist;
+}
+
+/****************************************************************************
Returns the number of valid combinations which use the given number
of fields/tiles.
*****************************************************************************/
Index: common/aicore/cm.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.h,v
retrieving revision 1.8
diff -u -r1.8 cm.h
--- common/aicore/cm.h 18 Jul 2004 01:16:05 -0000 1.8
+++ common/aicore/cm.h 20 Jul 2004 16:14:35 -0000
@@ -94,6 +94,8 @@
const struct cm_result *result);
int cm_count_worker(const struct city * pcity,
const struct cm_result *result);
+int cm_count_specialist(const struct city *pcity,
+ const struct cm_result *result);
void cm_copy_result_from_city(const struct city *pcity,
struct cm_result *result);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9443) new function cm_count_specialist,
Jason Short <=
|
|