Index: common/diptreaty.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.c,v retrieving revision 1.8 diff -u -r1.8 diptreaty.c --- common/diptreaty.c 2001/01/26 17:03:08 1.8 +++ common/diptreaty.c 2001/09/19 14:34:17 @@ -20,6 +20,10 @@ #include "diptreaty.h" +#define SPECLIST_TAG clause +#define SPECLIST_TYPE struct Clause +#include "speclist_c.h" + /**************************************************************** ... *****************************************************************/ @@ -30,7 +34,7 @@ ptreaty->plr1=plr1; ptreaty->accept0=0; ptreaty->accept1=0; - genlist_init(&ptreaty->clauses); + clause_list_init(&ptreaty->clauses); } @@ -40,15 +44,10 @@ int remove_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val) { - struct genlist_iterator myiter; - - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); - - for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause=(struct Clause *)ITERATOR_PTR(myiter); + clause_list_iterate(ptreaty->clauses, pclause) { if(pclause->type==type && pclause->from==pfrom && pclause->value==val) { - genlist_unlink(&ptreaty->clauses, pclause); + clause_list_unlink(&ptreaty->clauses, pclause); free(pclause); ptreaty->accept0=0; @@ -56,7 +55,7 @@ return 1; } - } + } clause_list_iterate_end; return 0; } @@ -69,17 +68,13 @@ enum clause_type type, int val) { struct Clause *pclause; - struct genlist_iterator myiter; if (type == CLAUSE_ADVANCE && !tech_exists(val)) { freelog(LOG_ERROR, "Illegal tech value %i in clause.", val); return 0; } - - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); - for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause=(struct Clause *)ITERATOR_PTR(myiter); + clause_list_iterate(ptreaty->clauses, pclause) { if(pclause->type==type && pclause->from==pfrom && pclause->value==val) { @@ -102,7 +97,7 @@ pclause->value=val; return 1; } - } + } clause_list_iterate_end; pclause=fc_malloc(sizeof(struct Clause)); @@ -110,7 +105,7 @@ pclause->from=pfrom; pclause->value=val; - genlist_insert(&ptreaty->clauses, pclause, -1); + clause_list_insert_back(&ptreaty->clauses, pclause); ptreaty->accept0=0; ptreaty->accept1=0; Index: common/diptreaty.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.h,v retrieving revision 1.6 diff -u -r1.6 diptreaty.h --- common/diptreaty.h 2000/09/06 21:41:15 1.6 +++ common/diptreaty.h 2001/09/19 14:34:17 @@ -23,6 +23,16 @@ #define is_pact_clause(x) \ ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE)) +/* For when we need to iterate over treaties */ +struct Clause; +#define SPECLIST_TAG clause +#define SPECLIST_TYPE struct Clause +#include "speclist.h" + +#define clause_list_iterate(clauselist, pclause) \ + TYPED_LIST_ITERATE(struct Clause, clauselist, pclause) +#define clause_list_iterate_end LIST_ITERATE_END + struct Clause { enum clause_type type; struct player *from; @@ -32,7 +42,7 @@ struct Treaty { struct player *plr0, *plr1; int accept0, accept1; - struct genlist clauses; + struct clause_list clauses; }; void init_treaty(struct Treaty *ptreaty, Index: server/diplhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v retrieving revision 1.51 diff -u -r1.51 diplhand.c --- server/diplhand.c 2001/08/30 13:00:15 1.51 +++ server/diplhand.c 2001/09/19 14:34:17 @@ -131,14 +131,8 @@ /* Check that player who accepts can keep what (s)he promises. */ - struct genlist_iterator myiter; - - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); - - for (;ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause = (struct Clause *)ITERATOR_PTR(myiter); + clause_list_iterate(ptreaty->clauses, pclause) { struct city *pcity; - if (pclause->from == pplayer) { switch(pclause->type) { case CLAUSE_ADVANCE: @@ -188,7 +182,7 @@ ; /* nothing */ } } - } + } clause_list_iterate_end; } *giver_accept = ! *giver_accept; @@ -201,8 +195,6 @@ packet); if (ptreaty->accept0 && ptreaty->accept1) { - struct genlist_iterator myiter; - lsend_packet_diplomacy_info(&plr0->connections, PACKET_DIPLOMACY_CANCEL_MEETING, packet); @@ -212,10 +204,10 @@ notify_player(plr0, _("Game: A treaty containing %d clauses was agreed upon."), - genlist_size(&ptreaty->clauses)); + clause_list_size(&ptreaty->clauses)); notify_player(plr1, _("Game: A treaty containing %d clauses was agreed upon."), - genlist_size(&ptreaty->clauses)); + clause_list_size(&ptreaty->clauses)); gamelog(GAMELOG_TREATY, "%s and %s agree to a treaty", get_nation_name_plural(plr0->nation), get_nation_name_plural(plr1->nation)); @@ -223,9 +215,7 @@ /* Check that one who accepted treaty earlier still have everything (s)he promised to give. */ - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); - for(;ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause=(struct Clause *)ITERATOR_PTR(myiter); + clause_list_iterate(ptreaty->clauses, pclause) { struct city *pcity; if (pclause->from == other) { switch (pclause->type) { @@ -273,13 +263,10 @@ ; /* nothing */ } } - } - - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); + } clause_list_iterate_end; - for(;ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause=(struct Clause *)ITERATOR_PTR(myiter); - + clause_list_iterate(ptreaty->clauses, pclause) { + struct city *pcity; pgiver = pclause->from; pdest = (plr0==pgiver) ? plr1 : plr0; @@ -320,8 +307,8 @@ break; case CLAUSE_CITY: { - struct city *pcity = find_city_by_id(pclause->value); struct city *pnewcity = NULL; + pcity = find_city_by_id(pclause->value); if (!pcity) { freelog(LOG_NORMAL, @@ -384,7 +371,7 @@ break; } - } + } clause_list_iterate_end; cleanup: genlist_unlink(&treaties, ptreaty); free(ptreaty); @@ -574,7 +561,6 @@ } players_iterate(other_player) { if ( (ptreaty=find_treaty(pplayer, other_player))) { - struct genlist_iterator myiter; struct packet_diplomacy_info packet; packet.plrno0 = pplayer->player_no; @@ -582,18 +568,14 @@ send_packet_diplomacy_info(dest, PACKET_DIPLOMACY_INIT_MEETING, &packet); - genlist_iterator_init(&myiter, &ptreaty->clauses, 0); - - for(;ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) { - struct Clause *pclause=(struct Clause *)ITERATOR_PTR(myiter); - + clause_list_iterate(ptreaty->clauses, pclause) { packet.clause_type = pclause->type; packet.plrno_from = pclause->from->player_no; packet.value = pclause->value; send_packet_diplomacy_info(dest, PACKET_DIPLOMACY_CREATE_CLAUSE, &packet); - } + } clause_list_iterate_end; } } players_iterate_end; }