Author: cazfi Date: Fri Dec 12 21:34:06 2014 New Revision: 27279 URL: http://svn.gna.org/viewcvs/freeciv?rev=27279&view=rev Log: Made barbarian_type an specenum, use it as one, and store player barbarian type by name to the savegames.
See patch #5520 Modified: trunk/common/fc_types.h trunk/server/ruleset.c trunk/server/savecompat.c trunk/server/savecompat.h trunk/server/savegame.c trunk/server/savegame2.c trunk/tools/ruledit/rulesave.c Modified: trunk/common/fc_types.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_types.h?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/common/fc_types.h (original) +++ trunk/common/fc_types.h Fri Dec 12 21:34:06 2014 @@ -245,16 +245,17 @@ #define AI_LEVEL_DEFAULT AI_LEVEL_NOVICE -/* - * pplayer->ai.barbarian_type and nations use this enum. Note that the values - * have to stay since they are used in savegames. - */ -enum barbarian_type { - NOT_A_BARBARIAN = 0, - LAND_BARBARIAN = 1, - SEA_BARBARIAN = 2, - ANIMAL_BARBARIAN = 3 -}; +/* pplayer->ai.barbarian_type and nations use this enum. */ +#define SPECENUM_NAME barbarian_type +#define SPECENUM_VALUE0 NOT_A_BARBARIAN +#define SPECENUM_VALUE0NAME "None" +#define SPECENUM_VALUE1 LAND_BARBARIAN +#define SPECENUM_VALUE1NAME "Land" +#define SPECENUM_VALUE2 SEA_BARBARIAN +#define SPECENUM_VALUE2NAME "Sea" +#define SPECENUM_VALUE3 ANIMAL_BARBARIAN +#define SPECENUM_VALUE3NAME "Animal" +#include "specenum_gen.h" /* * Citytile requirement types. Modified: trunk/server/ruleset.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/server/ruleset.c (original) +++ trunk/server/ruleset.c Fri Dec 12 21:34:06 2014 @@ -4040,18 +4040,10 @@ /* Check barbarian type. Default is "None" meaning not a barbarian */ barb_type = secfile_lookup_str_default(file, "None", "%s.barbarian_type", sec_name); - if (fc_strcasecmp(barb_type, "None") == 0) { - pnation->barb_type = NOT_A_BARBARIAN; - } else if (fc_strcasecmp(barb_type, "Land") == 0) { - pnation->barb_type = LAND_BARBARIAN; - } else if (fc_strcasecmp(barb_type, "Sea") == 0) { - pnation->barb_type = SEA_BARBARIAN; - } else if (fc_strcasecmp(barb_type, "Animal") == 0) { - pnation->barb_type = ANIMAL_BARBARIAN; - } else { + pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp); + if (!barbarian_type_is_valid(pnation->barb_type)) { ruleset_error(LOG_ERROR, - "Nation %s, barbarian_type is \"%s\". Must be " - "\"None\" or \"Land\" or \"Sea\" or \"Animal\".", + "Nation %s, barbarian_type is invalid (\"%s\")", nation_rule_name(pnation), barb_type); ok = FALSE; break; Modified: trunk/server/savecompat.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/server/savecompat.c (original) +++ trunk/server/savecompat.c Fri Dec 12 21:34:06 2014 @@ -751,14 +751,25 @@ } } - /* Renamed 'capital' to 'got_first_city'. */ player_slots_iterate(pslot) { bool got_first_city; + int old_barb_type; + enum barbarian_type new_barb_type; + int plrno = player_slot_index(pslot); + + /* Renamed 'capital' to 'got_first_city'. */ if (secfile_lookup_bool(loading->file, &got_first_city, - "player%d.capital", player_slot_index(pslot))) { + "player%d.capital", plrno)) { secfile_insert_bool(loading->file, got_first_city, - "player%d.got_first_city", player_slot_index(pslot)); - } + "player%d.got_first_city", plrno); + } + + /* Convert numeric barbarian type to textual */ + old_barb_type = secfile_lookup_int_default(loading->file, 0, + "player%d.ai.is_barbarian", plrno); + new_barb_type = barb_type_convert(old_barb_type); + secfile_insert_str(loading->file, barbarian_type_name(new_barb_type), + "player%d.ai.barb_type", plrno); } player_slots_iterate_end; /* Units orders. */ @@ -960,3 +971,20 @@ return ai_level_invalid(); } + +/**************************************************************************** + Convert old barbarian type value to barbarian_type +****************************************************************************/ +enum barbarian_type barb_type_convert(int old_type) +{ + switch (old_type) { + case 0: + return NOT_A_BARBARIAN; + case 1: + return LAND_BARBARIAN; + case 2: + return SEA_BARBARIAN; + } + + return barbarian_type_invalid(); +} Modified: trunk/server/savecompat.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.h?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/server/savecompat.h (original) +++ trunk/server/savecompat.h Fri Dec 12 21:34:06 2014 @@ -149,5 +149,6 @@ const char *special_rule_name(enum tile_special_type type); enum ai_level ai_level_convert(int old_level); +enum barbarian_type barb_type_convert(int old_type); #endif /* FC__SAVECOMPAT_H */ Modified: trunk/server/savegame.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/server/savegame.c (original) +++ trunk/server/savegame.c Fri Dec 12 21:34:06 2014 @@ -1640,12 +1640,16 @@ struct research *research; struct nation_type *pnation; struct nation_style *style; + int old_barb_type; research = research_get(plr); - plr->ai_common.barbarian_type = secfile_lookup_int_default(file, 0, - "player%d.ai.is_barbarian", - plrno); + old_barb_type = secfile_lookup_int_default(file, 0, + "player%d.ai.is_barbarian", + plrno); + + plr->ai_common.barbarian_type = barb_type_convert(old_barb_type); + if (is_barbarian(plr)) { server.nbarbarians++; } Modified: trunk/server/savegame2.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/server/savegame2.c (original) +++ trunk/server/savegame2.c Fri Dec 12 21:34:06 2014 @@ -3673,6 +3673,7 @@ const char *string; struct government *gov; const char *level; + const char *barb_str; /* Check status and return if not OK (sg_success != TRUE). */ sg_check_ret(); @@ -3805,9 +3806,16 @@ plrno)); } - plr->ai_common.barbarian_type - = secfile_lookup_int_default(loading->file, 0, - "player%d.ai.is_barbarian", plrno); + barb_str = secfile_lookup_str_default(loading->file, "None", + "player%d.ai.barb_type", plrno); + plr->ai_common.barbarian_type = barbarian_type_by_name(barb_str, fc_strcasecmp); + + if (!barbarian_type_is_valid(plr->ai_common.barbarian_type)) { + log_sg("Player%d: Invalid barbarian type \"%s\". " + "Changed to \"None\".", plrno, barb_str); + plr->ai_common.barbarian_type = NOT_A_BARBARIAN; + } + if (is_barbarian(plr)) { server.nbarbarians++; } @@ -4135,8 +4143,8 @@ secfile_insert_str(saving->file, ai_level_name(plr->ai_common.skill_level), "player%d.ai.level", plrno); - secfile_insert_int(saving->file, plr->ai_common.barbarian_type, - "player%d.ai.is_barbarian", plrno); + secfile_insert_str(saving->file, barbarian_type_name(plr->ai_common.barbarian_type), + "player%d.ai.barb_type", plrno); secfile_insert_int(saving->file, plr->economic.gold, "player%d.gold", plrno); secfile_insert_int(saving->file, plr->economic.tax, Modified: trunk/tools/ruledit/rulesave.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/rulesave.c?rev=27279&r1=27278&r2=27279&view=diff ============================================================================== --- trunk/tools/ruledit/rulesave.c (original) +++ trunk/tools/ruledit/rulesave.c Fri Dec 12 21:34:06 2014 @@ -1120,7 +1120,6 @@ const char *list_items[max_items]; int set_count; int subsect_idx; - char *barb_str = NULL; fc_snprintf(path, sizeof(path), "nation_%d", sect_idx++); @@ -1176,23 +1175,9 @@ secfile_insert_bool(sfile, pnat->is_playable, "%s.is_playable", path); } - switch (pnat->barb_type) { - case NOT_A_BARBARIAN: - barb_str = NULL; - break; - case LAND_BARBARIAN: - barb_str = "Land"; - break; - case SEA_BARBARIAN: - barb_str = "Sea"; - break; - case ANIMAL_BARBARIAN: - barb_str = "Animal"; - break; - } - - if (barb_str != NULL) { - secfile_insert_str(sfile, barb_str, "%s.barbarian_type", path); + if (pnat->barb_type != NOT_A_BARBARIAN) { + secfile_insert_str(sfile, barbarian_type_name(pnat->barb_type), + "%s.barbarian_type", path); } if (strcmp(pnat->flag_graphic_str, "-")) { _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits