Author: cazfi Date: Sun Jan 4 19:48:17 2015 New Revision: 27517 URL: http://svn.gna.org/viewcvs/freeciv?rev=27517&view=rev Log: Save information about the open diplomacy meetings to the savegame. It's not loaded yet.
See patch #5614 Modified: trunk/ai/default/advdiplomacy.c trunk/common/diptreaty.c trunk/common/diptreaty.h trunk/server/diplhand.c trunk/server/diplhand.h trunk/server/savegame3.c Modified: trunk/ai/default/advdiplomacy.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/advdiplomacy.c?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/ai/default/advdiplomacy.c (original) +++ trunk/ai/default/advdiplomacy.c Sun Jan 4 19:48:17 2015 @@ -565,9 +565,6 @@ } DIPLO_LOG(ait, LOG_DIPL, pplayer, aplayer, "embassy clause worth %d", worth); - break; - - case CLAUSE_LAST: break; } /* end of switch */ @@ -1298,7 +1295,7 @@ "was unable to."); return; } - handle_diplomacy_cancel_pact(pplayer, player_number(target), CLAUSE_LAST); + handle_diplomacy_cancel_pact(pplayer, player_number(target), clause_type_invalid()); } /* Throw a tantrum */ Modified: trunk/common/diptreaty.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/diptreaty.c?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/common/diptreaty.c (original) +++ trunk/common/diptreaty.c Sun Jan 4 19:48:17 2015 @@ -147,7 +147,7 @@ enum diplstate_type ds = player_diplstate_get(ptreaty->plr0, ptreaty->plr1)->type; - if (type < 0 || type >= CLAUSE_LAST) { + if (!clause_type_is_valid(type)) { log_error("Illegal clause type encountered."); return FALSE; } Modified: trunk/common/diptreaty.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/diptreaty.h?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/common/diptreaty.h (original) +++ trunk/common/diptreaty.h Sun Jan 4 19:48:17 2015 @@ -19,11 +19,29 @@ #include "support.h" /* bool type */ -/* Used in the network protocol. */ -enum clause_type { CLAUSE_ADVANCE, CLAUSE_GOLD, CLAUSE_MAP, - CLAUSE_SEAMAP, CLAUSE_CITY, - CLAUSE_CEASEFIRE, CLAUSE_PEACE, CLAUSE_ALLIANCE, - CLAUSE_VISION, CLAUSE_EMBASSY, CLAUSE_LAST }; +/* Used in the network protocol */ +#define SPECENUM_NAME clause_type +#define SPECENUM_VALUE0 CLAUSE_ADVANCE +#define SPECENUM_VALUE0NAME "Advance" +#define SPECENUM_VALUE1 CLAUSE_GOLD +#define SPECENUM_VALUE1NAME "Gold" +#define SPECENUM_VALUE2 CLAUSE_MAP +#define SPECENUM_VALUE2NAME "Map" +#define SPECENUM_VALUE3 CLAUSE_SEAMAP +#define SPECENUM_VALUE3NAME "Seamap" +#define SPECENUM_VALUE4 CLAUSE_CITY +#define SPECENUM_VALUE4NAME "City" +#define SPECENUM_VALUE5 CLAUSE_CEASEFIRE +#define SPECENUM_VALUE5NAME "Ceasefire" +#define SPECENUM_VALUE6 CLAUSE_PEACE +#define SPECENUM_VALUE6NAME "Peace" +#define SPECENUM_VALUE7 CLAUSE_ALLIANCE +#define SPECENUM_VALUE7NAME "Alliance" +#define SPECENUM_VALUE8 CLAUSE_VISION +#define SPECENUM_VALUE8NAME "Vision" +#define SPECENUM_VALUE9 CLAUSE_EMBASSY +#define SPECENUM_VALUE9NAME "Embassy" +#include "specenum_gen.h" #define is_pact_clause(x) \ ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE)) Modified: trunk/server/diplhand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/diplhand.c?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/server/diplhand.c (original) +++ trunk/server/diplhand.c Sun Jan 4 19:48:17 2015 @@ -54,14 +54,6 @@ #include "script_server.h" #include "diplhand.h" - -#define SPECLIST_TAG treaty -#define SPECLIST_TYPE struct Treaty -#include "speclist.h" - -#define treaty_list_iterate(list, p) \ - TYPED_LIST_ITERATE(struct Treaty, list, p) -#define treaty_list_iterate_end LIST_ITERATE_END static struct treaty_list *treaties = NULL; @@ -614,9 +606,6 @@ * within radius of our own city. */ worker_refresh_required = TRUE; break; - case CLAUSE_LAST: - log_error("Received bad clause type"); - break; } } clause_list_iterate_end; @@ -894,3 +883,11 @@ FALSE); } players_iterate_end; } + +/************************************************************************** + Get treaty list +**************************************************************************/ +struct treaty_list *get_all_treaties(void) +{ + return treaties; +} Modified: trunk/server/diplhand.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/diplhand.h?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/server/diplhand.h (original) +++ trunk/server/diplhand.h Sun Jan 4 19:48:17 2015 @@ -21,6 +21,14 @@ struct packet_diplomacy_info; struct connection; +#define SPECLIST_TAG treaty +#define SPECLIST_TYPE struct Treaty +#include "speclist.h" + +#define treaty_list_iterate(list, p) \ + TYPED_LIST_ITERATE(struct Treaty, list, p) +#define treaty_list_iterate_end LIST_ITERATE_END + void establish_embassy(struct player *pplayer, struct player *aplayer); void diplhand_init(void); @@ -32,4 +40,7 @@ void send_diplomatic_meetings(struct connection *dest); void cancel_all_meetings(struct player *pplayer); void reject_all_treaties(struct player *pplayer); + +struct treaty_list *get_all_treaties(void); + #endif /* FC__DIPLHAND_H */ Modified: trunk/server/savegame3.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=27517&r1=27516&r2=27517&view=diff ============================================================================== --- trunk/server/savegame3.c (original) +++ trunk/server/savegame3.c Sun Jan 4 19:48:17 2015 @@ -445,6 +445,8 @@ static void sg_load_event_cache(struct loaddata *loading); static void sg_save_event_cache(struct savedata *saving); +static void sg_save_treaties(struct savedata *saving); + static void sg_load_mapimg(struct loaddata *loading); static void sg_save_mapimg(struct savedata *saving); @@ -615,6 +617,8 @@ sg_save_researches(saving); /* [event_cache] */ sg_save_event_cache(saving); + /* [treaty<i>] */ + sg_save_treaties(saving); /* [mapimg] */ sg_save_mapimg(saving); @@ -6500,6 +6504,41 @@ } /* ======================================================================= + * Load / save the open treaties + * ======================================================================= */ + +/**************************************************************************** + Save '[treaty_xxx]'. +****************************************************************************/ +static void sg_save_treaties(struct savedata *saving) +{ + struct treaty_list *treaties = get_all_treaties(); + int tidx = 0; + + treaty_list_iterate(treaties, ptr) { + char tpath[512]; + int cidx = 0; + + fc_snprintf(tpath, sizeof(tpath), "treaty%d", tidx++); + + secfile_insert_str(saving->file, player_name(ptr->plr0), "%s.plr0", tpath); + secfile_insert_str(saving->file, player_name(ptr->plr1), "%s.plr1", tpath); + secfile_insert_bool(saving->file, ptr->accept0, "%s.accept0", tpath); + secfile_insert_bool(saving->file, ptr->accept1, "%s.accept1", tpath); + + clause_list_iterate(ptr->clauses, pclaus) { + char cpath[512]; + + fc_snprintf(cpath, sizeof(cpath), "%s.clause%d", tpath, cidx++); + + secfile_insert_str(saving->file, clause_type_name(pclaus->type), "%s.type", tpath); + secfile_insert_str(saving->file, player_name(pclaus->from), "%s.from", tpath); + secfile_insert_int(saving->file, pclaus->value, "%s.value", tpath); + } clause_list_iterate_end; + } treaty_list_iterate_end; +} + +/* ======================================================================= * Load / save the mapimg definitions. * ======================================================================= */ _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits